remote-sensing-processor


Nameremote-sensing-processor JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/simonreise/remote-sensing-processor
SummaryRSP is a tool for geospatial raster data processing
upload_time2023-08-18 21:07:41
maintainer
docs_urlNone
authorMikhail Moskovchenko
requires_python>=3.8
license
keywords remote sensing landsat sentinel gdal rasterio
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            
![image](logo_wide.png)

----

![AppVeyor](https://img.shields.io/appveyor/build/simonreise/remote-sensing-processor)
![PyPI](https://img.shields.io/pypi/v/remote-sensing-processor)
![Conda](https://img.shields.io/conda/v/moskovchenkomike/remote-sensing-processor)

RSP is a tool for geospatial raster data processing.

RSP can preprocess Sentinel-2 and Landsat imagery, create raster mosaics, calculate vegetation indices and perform image segmentation tasks.

Read the documentation for more details: https://remote-sensing-processor.readthedocs.io

## Example

Here is an example of some features that RSP provides. Sentinel-2 images are being preprocessed and merged into a mosaic, NDVI of that Sentinel-2 mosaic is calculated. Landcover images are merged into mosaic at the same resolution and projection as Sentinel-2 data. Then Sentinel-2 and landcover data is divided into tiles and UperNet model that predicts landcover based on Sentinel-2 data is trained. This model is used to create landcover map. 
```
from glob import glob
import remote_sensing_processor as rsp


# getting a list of sentinel-2 images
sentinel2_imgs = glob('/home/rsp_test/sentinels/*.zip')

# preprocessing sentinel-2 images
# it includes converting L1 products to L2, superresolution for 20 and 60m bands and cloud masking
output_sentinels = rsp.sentinel2(sentinel2_imgs)

# merging sentinel-2 images into one mosaic 
# in order from images with most nodata values on bottom to images with less nodata on top,
# clipping it to the area of interest and reprojecting to the proj we need
border = '/home/rsp_test/border.gpkg'
mosaic_sentinel = rsp.mosaic(output_sentinels, '/home/rsp_test/mosaics/sentinel/', clipper = border, projection = 'EPSG:4326', nodata_order = True)

# applying min/max normalization to sentinel-2 mosaics (sentinel-2 reflectance values are from 0 to 10 000)
for band in mosaic_sentinel:
	rsp.normalize(band, band, 0, 10000)

# calculating NDVI for sentinel-2 mosaic
ndvi = rsp.calculate_index('NDVI', '/home/rsp_test/mosaics/sentinel/')

# merging landcover files into mosaic 
# and bringing it to resolution and projection of a reference file (one of sentinel mosaic bands)
lcs = glob('/home/rsp_test/landcover/*.tif')
mosaic_landcover = rsp.mosaic(lcs, '/home/rsp_test/mosaics/landcover/', clipper = border, reference_raster = '/home/rsp_test/mosaics/sentinel/B1.tif', nodata = -1)

# cutting sentinel (x) and landcover (y) data to 256x256 px tiles, 
# with random shuffling samples, splitting data into train,
# validation and test subsets in proportion 3 to 1 to 1
# and ignoring tiles with only nodata values
x = mosaic_sentinel
y = mosaic_landcover[0]
x_i, y_i, tiles, samples, classification, num_classes, classes, x_nodata, y_nodata = rsp.segmentation.generate_tiles(x, y, tile_size = 256, shuffle = True, split = [3, 1, 1])
x_train = x_i[0]
x_val = x_i[1]
x_test = x_i[2]
y_train = y_i[0]
y_val = y_i[1]
y_test = y_i[2]
x_train = x_i[0]

# training UperNet that predicts landcover class based on sentinel imagery
model = rsp.segmentation.train(x_train, y_train, x_val, y_val, model = 'UperNet', backbone = 'ConvNeXTV2', model_file = '/home/rsp_test/model/upernet.ckpt', epochs = 10, classification = classification, num_classes = num_classes, x_nodata = x_nodata, y_nodata = y_nodata)

# testing model
rsp.segmentation.test(x_test, y_test, model = model)

# mapping landcover based on predictions of our UperNet
y_reference = '/home/rsp_test/mosaics/landcover/landcover01_mosaic.tif'
output_map = '/home/rsp_test/prediction.tif'
rsp.segmentation.generate_map([x_train, x_val, x_test], y_reference, model, output_map, tiles = tiles, samples = samples)
```

## Requirements
To run RSP you need these packages to be installed:
- Python >= 3.8
- Numpy
- GDAL
- Rasterio
- Pyproj
- Shapely
- Fiona
- Geopandas
- Scikit-learn
- Pytorch >= 1.10
- Torchvision >= 0.10
- Lightning
- Transformers

If you have a GPU that supports CUDA we strongly recommend you to install Pytorch version that is built with CUDA support before installing RSP. You can find out how to do it on [Pytorch official site](https://pytorch.org/get-started/locally/).

Also you need a Sen2Cor to be installed to process Sentinel-2 data. Required version is 2.11 for Windows and Linux and 2.9 for Mac OS. You should install it via SNAP plugin installer. [Here](http://wiki.awf.forst.uni-goettingen.de/wiki/index.php/Installation_of_SNAP) is the instruction how you can do it.

## Installation

From PyPI:
```
pip install remote-sensing-processor
```
From Conda:
```
conda install -c moskovchenkomike remote-sensing-processor
```
From source:
```
git clone https://github.com/simonreise/remote-sensing-processor
cd remote-sensing-processor
pip install .
```


## License
See [LICENSE](LICENSE).

## Thanks to
RSP uses code from some other projects.

Sentinel-2 superresolution is based on [s2-superresolution] by UP42, which is based on [DSen-2] by lanha.

Sentinel-2 atmospheric correction is performed with [Sen2Cor].

Landsat processing module uses code from [Semi-Automatic Classification Plugin](https://fromgistors.blogspot.com/p/semi-automatic-classification-plugin.html).



   [s2-superresolution]: <https://github.com/up42/s2-superresolution>
   [DSen-2]: <https://github.com/lanha/DSen2>
   [Sen2Cor]: <https://step.esa.int/main/snap-supported-plugins/sen2cor/>
   
   


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/simonreise/remote-sensing-processor",
    "name": "remote-sensing-processor",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "remote sensing,landsat,sentinel,gdal,rasterio",
    "author": "Mikhail Moskovchenko",
    "author_email": "moskovchenkomike@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3f/6c/04ca72e9cff87a0dbe37deac1bfe63e049010aaf8592241f308179132e36/remote-sensing-processor-0.2.1.tar.gz",
    "platform": null,
    "description": "\r\n![image](logo_wide.png)\r\n\r\n----\r\n\r\n![AppVeyor](https://img.shields.io/appveyor/build/simonreise/remote-sensing-processor)\r\n![PyPI](https://img.shields.io/pypi/v/remote-sensing-processor)\r\n![Conda](https://img.shields.io/conda/v/moskovchenkomike/remote-sensing-processor)\r\n\r\nRSP is a tool for geospatial raster data processing.\r\n\r\nRSP can preprocess Sentinel-2 and Landsat imagery, create raster mosaics, calculate vegetation indices and perform image segmentation tasks.\r\n\r\nRead the documentation for more details: https://remote-sensing-processor.readthedocs.io\r\n\r\n## Example\r\n\r\nHere is an example of some features that RSP provides. Sentinel-2 images are being preprocessed and merged into a mosaic, NDVI of that Sentinel-2 mosaic is calculated. Landcover images are merged into mosaic at the same resolution and projection as Sentinel-2 data. Then Sentinel-2 and landcover data is divided into tiles and UperNet model that predicts landcover based on Sentinel-2 data is trained. This model is used to create landcover map. \r\n```\r\nfrom glob import glob\r\nimport remote_sensing_processor as rsp\r\n\r\n\r\n# getting a list of sentinel-2 images\r\nsentinel2_imgs = glob('/home/rsp_test/sentinels/*.zip')\r\n\r\n# preprocessing sentinel-2 images\r\n# it includes converting L1 products to L2, superresolution for 20 and 60m bands and cloud masking\r\noutput_sentinels = rsp.sentinel2(sentinel2_imgs)\r\n\r\n# merging sentinel-2 images into one mosaic \r\n# in order from images with most nodata values on bottom to images with less nodata on top,\r\n# clipping it to the area of interest and reprojecting to the proj we need\r\nborder = '/home/rsp_test/border.gpkg'\r\nmosaic_sentinel = rsp.mosaic(output_sentinels, '/home/rsp_test/mosaics/sentinel/', clipper = border, projection = 'EPSG:4326', nodata_order = True)\r\n\r\n# applying min/max normalization to sentinel-2 mosaics (sentinel-2 reflectance values are from 0 to 10 000)\r\nfor band in mosaic_sentinel:\r\n\trsp.normalize(band, band, 0, 10000)\r\n\r\n# calculating NDVI for sentinel-2 mosaic\r\nndvi = rsp.calculate_index('NDVI', '/home/rsp_test/mosaics/sentinel/')\r\n\r\n# merging landcover files into mosaic \r\n# and bringing it to resolution and projection of a reference file (one of sentinel mosaic bands)\r\nlcs = glob('/home/rsp_test/landcover/*.tif')\r\nmosaic_landcover = rsp.mosaic(lcs, '/home/rsp_test/mosaics/landcover/', clipper = border, reference_raster = '/home/rsp_test/mosaics/sentinel/B1.tif', nodata = -1)\r\n\r\n# cutting sentinel (x) and landcover (y) data to 256x256 px tiles, \r\n# with random shuffling samples, splitting data into train,\r\n# validation and test subsets in proportion 3 to 1 to 1\r\n# and ignoring tiles with only nodata values\r\nx = mosaic_sentinel\r\ny = mosaic_landcover[0]\r\nx_i, y_i, tiles, samples, classification, num_classes, classes, x_nodata, y_nodata = rsp.segmentation.generate_tiles(x, y, tile_size = 256, shuffle = True, split = [3, 1, 1])\r\nx_train = x_i[0]\r\nx_val = x_i[1]\r\nx_test = x_i[2]\r\ny_train = y_i[0]\r\ny_val = y_i[1]\r\ny_test = y_i[2]\r\nx_train = x_i[0]\r\n\r\n# training UperNet that predicts landcover class based on sentinel imagery\r\nmodel = rsp.segmentation.train(x_train, y_train, x_val, y_val, model = 'UperNet', backbone = 'ConvNeXTV2', model_file = '/home/rsp_test/model/upernet.ckpt', epochs = 10, classification = classification, num_classes = num_classes, x_nodata = x_nodata, y_nodata = y_nodata)\r\n\r\n# testing model\r\nrsp.segmentation.test(x_test, y_test, model = model)\r\n\r\n# mapping landcover based on predictions of our UperNet\r\ny_reference = '/home/rsp_test/mosaics/landcover/landcover01_mosaic.tif'\r\noutput_map = '/home/rsp_test/prediction.tif'\r\nrsp.segmentation.generate_map([x_train, x_val, x_test], y_reference, model, output_map, tiles = tiles, samples = samples)\r\n```\r\n\r\n## Requirements\r\nTo run RSP you need these packages to be installed:\r\n- Python >= 3.8\r\n- Numpy\r\n- GDAL\r\n- Rasterio\r\n- Pyproj\r\n- Shapely\r\n- Fiona\r\n- Geopandas\r\n- Scikit-learn\r\n- Pytorch >= 1.10\r\n- Torchvision >= 0.10\r\n- Lightning\r\n- Transformers\r\n\r\nIf you have a GPU that supports CUDA we strongly recommend you to install Pytorch version that is built with CUDA support before installing RSP. You can find out how to do it on [Pytorch official site](https://pytorch.org/get-started/locally/).\r\n\r\nAlso you need a Sen2Cor to be installed to process Sentinel-2 data. Required version is 2.11 for Windows and Linux and 2.9 for Mac OS. You should install it via SNAP plugin installer. [Here](http://wiki.awf.forst.uni-goettingen.de/wiki/index.php/Installation_of_SNAP) is the instruction how you can do it.\r\n\r\n## Installation\r\n\r\nFrom PyPI:\r\n```\r\npip install remote-sensing-processor\r\n```\r\nFrom Conda:\r\n```\r\nconda install -c moskovchenkomike remote-sensing-processor\r\n```\r\nFrom source:\r\n```\r\ngit clone https://github.com/simonreise/remote-sensing-processor\r\ncd remote-sensing-processor\r\npip install .\r\n```\r\n\r\n\r\n## License\r\nSee [LICENSE](LICENSE).\r\n\r\n## Thanks to\r\nRSP uses code from some other projects.\r\n\r\nSentinel-2 superresolution is based on [s2-superresolution] by UP42, which is based on [DSen-2] by lanha.\r\n\r\nSentinel-2 atmospheric correction is performed with [Sen2Cor].\r\n\r\nLandsat processing module uses code from [Semi-Automatic Classification Plugin](https://fromgistors.blogspot.com/p/semi-automatic-classification-plugin.html).\r\n\r\n\r\n\r\n   [s2-superresolution]: <https://github.com/up42/s2-superresolution>\r\n   [DSen-2]: <https://github.com/lanha/DSen2>\r\n   [Sen2Cor]: <https://step.esa.int/main/snap-supported-plugins/sen2cor/>\r\n   \r\n   \r\n\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "RSP is a tool for geospatial raster data processing",
    "version": "0.2.1",
    "project_urls": {
        "Bug Tracker": "https://github.com/simonreise/remote-sensing-processor/issues",
        "Documentation": "https://remote-sensing-processor.readthedocs.io",
        "Homepage": "https://github.com/simonreise/remote-sensing-processor",
        "Source": "https://github.com/simonreise/remote-sensing-processor"
    },
    "split_keywords": [
        "remote sensing",
        "landsat",
        "sentinel",
        "gdal",
        "rasterio"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b0d810d34ba746ecac49e954587b81a9da7098919a23cc27af4eb7591630568",
                "md5": "223ade6150312928a9b878bd973bfe30",
                "sha256": "17a87e9196e2a672768a6525182bc198a3b0cfa7df3102140ddc757eeb75cf51"
            },
            "downloads": -1,
            "filename": "remote_sensing_processor-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "223ade6150312928a9b878bd973bfe30",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 26629627,
            "upload_time": "2023-08-18T21:06:46",
            "upload_time_iso_8601": "2023-08-18T21:06:46.522004Z",
            "url": "https://files.pythonhosted.org/packages/5b/0d/810d34ba746ecac49e954587b81a9da7098919a23cc27af4eb7591630568/remote_sensing_processor-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f6c04ca72e9cff87a0dbe37deac1bfe63e049010aaf8592241f308179132e36",
                "md5": "54b7e58b9838b0f87419ea17f224e9ba",
                "sha256": "b1eb9d7d6560ff93629c4a2139dc10b63675babf0f8c34045eaa39bbec8c3ad6"
            },
            "downloads": -1,
            "filename": "remote-sensing-processor-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "54b7e58b9838b0f87419ea17f224e9ba",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 26745041,
            "upload_time": "2023-08-18T21:07:41",
            "upload_time_iso_8601": "2023-08-18T21:07:41.311741Z",
            "url": "https://files.pythonhosted.org/packages/3f/6c/04ca72e9cff87a0dbe37deac1bfe63e049010aaf8592241f308179132e36/remote-sensing-processor-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-18 21:07:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "simonreise",
    "github_project": "remote-sensing-processor",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "appveyor": true,
    "tox": true,
    "lcname": "remote-sensing-processor"
}
        
Elapsed time: 0.10228s