# georeader
[![Article DOI:10.1038/s41598-023-47595-7](https://img.shields.io/badge/Article%20DOI-10.1038%2Fs41598.023.47595.7-blue)](https://doi.org/10.1038/s41598-023-47595-7) [![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/spaceml-org/georeader?sort=semver)](https://github.com/spaceml-org/georeader/releases) [![PyPI](https://img.shields.io/pypi/v/georeader-spaceml)](https://pypi.org/project/georeader-spaceml/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/georeader-spaceml)](https://pypi.org/project/georeader-spaceml/) [![PyPI - License](https://img.shields.io/pypi/l/georeader-spaceml)](https://github.com/spaceml-org/georeader/blob/main/LICENSE)
**georeader** is a package to process raster data from different satellite missions. **georeader** makes easy to [read specific areas of your image](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_S2_SAFE_from_bucket.ipynb), to [reproject images from different satellites to a common grid](https://github.com/spaceml-org/georeader/blob/main/notebooks/reading_overlapping_sentinel2_aviris.ipynb) and to go from vector to raster formats ([`vectorize`](https://github.com/spaceml-org/georeader/blob/main/georeader/vectorize.py) and [`rasterize`](https://github.com/spaceml-org/georeader/blob/main/georeader/rasterize.py)). **georeader** is mainly used to process satellite data for scientific usage, to create ML-ready datasets and to implement [end-to-end operational inference pipelines](https://spaceml-org.github.io/ml4floods/content/ml4ops/HOWTO_postprocess_inference.html).
## Install
The core package has [very few dependencies](https://github.com/spaceml-org/georeader/blob/main/requirements.txt); it is build on top of the geospatial libraries `rasterio`, `shapely` and `geopandas`.
```bash
# From pip
pip install georeader-spaceml
# From GitHub
pip install git+https://github.com/spaceml-org/georeader#egg=georeader
# Install with Google dependencies (to read objects from Google Cloud Storage or Google Earth Engine)
pip install git+https://github.com/spaceml-org/georeader#egg=georeader[google]
# Install with Planetary Computer requirements
pip install git+https://github.com/spaceml-org/georeader#egg=georeader[microsoftplanetary]
```
## Getting started
> Read from a Sentinel-2 image a fixed size subimage on an specific `lon,lat` location (directly from the [S2 public Google Cloud bucket](https://cloud.google.com/storage/docs/public-datasets/sentinel-2?hl=es-419)):
```python
# This snippet requires:
# pip install fsspec gcsfs google-cloud-storage
import os
os.environ["GS_NO_SIGN_REQUEST"] = "YES"
from georeader.readers import S2_SAFE_reader
from georeader import read
cords_read = (-104.394, 32.026) # long, lat
crs_cords = "EPSG:4326"
s2_safe_path = S2_SAFE_reader.s2_public_bucket_path("S2B_MSIL1C_20191008T173219_N0208_R055_T13SER_20191008T204555.SAFE")
s2obj = S2_SAFE_reader.s2loader(s2_safe_path,
out_res=10, bands=["B04","B03","B02"])
# copy to local avoids http errors specially when not using a Google Cloud project.
# This will only copy the bands set up above B04, B03 and B02
s2obj = s2obj.cache_product_to_local_dir(".")
# See also read.read_from_bounds, read.read_from_polygon for different ways of croping an image
data = read.read_from_center_coords(s2obj,cords_read, shape=(2040, 4040),
crs_center_coords=crs_cords)
data_memory = data.load() # this loads the data to memory
data_memory # GeoTensor object
```
```
>> Transform: | 10.00, 0.00, 537020.00|
| 0.00,-10.00, 3553680.00|
| 0.00, 0.00, 1.00|
Shape: (3, 2040, 4040)
Resolution: (10.0, 10.0)
Bounds: (537020.0, 3533280.0, 577420.0, 3553680.0)
CRS: EPSG:32613
fill_value_default: 0
```
In the `.values` attribute we have the plain numpy array that we can plot with `show`:
```python
from rasterio.plot import show
show(data_memory.values/3500, transform=data_memory.transform)
```
<img src="https://raw.githubusercontent.com/spaceml-org/georeader/main/notebooks/images/sample_read.png" alt="awesome georeader" width="50%">
Saving the `GeoTensor` as a COG GeoTIFF:
```python
from georeader.save import save_cog
# Supports writing in bucket location (e.g. gs://bucket-name/s2_crop.tif)
save_cog(data_memory, "s2_crop.tif", descriptions=s2obj.bands)
```
## Tutorials
Sentinel-2:
* [Reading Sentinel-2 images from the public Google bucket](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_S2_SAFE_from_bucket.ipynb)
* [Explore metadata of Sentinel-2 object](https://github.com/spaceml-org/georeader/blob/main/notebooks/Sentinel-2/explore_metadata_s2.ipynb)
* [Query Sentinel-2 images over a location and time span, mosaic and plot them](https://github.com/spaceml-org/georeader/blob/main/notebooks/Sentinel-2/query_mosaic_s2_images.ipynb)
Other:
* [Tutorial to read overlapping tiles from a GeoTIFF and a Sentinel-2 image](https://github.com/spaceml-org/georeader/blob/main/notebooks/reading_overlapping_sentinel2_aviris.ipynb)
* [Example of reading a Proba-V image overlapping with Sentinel-2 forcing same resolution](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_overlapping_probav_and_sentinel2.ipynb)
* [Work with EMIT images](https://github.com/spaceml-org/georeader/blob/main/notebooks/emit_explore.ipynb)
* [Read overlapping images of PRISMA and EMIT](https://github.com/spaceml-org/georeader/blob/main/notebooks/simultaneous_prisma_emit.ipynb)
* [Read high resolution tile layers](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_from_tileserver.ipynb)
Used in other projects:
* [georeader with ml4floods to automatically download and produce flood extent maps: the Kherson Dam Break example](https://spaceml-org.github.io/ml4floods/content/ml4ops/HOWTO_postprocess_inference.html)
* [georeader with STARCOP to simulate Sentinel-2 from AVIRIS images](https://github.com/spaceml-org/STARCOP/blob/main/notebooks/simulate_aviris_2_sentinel2.ipynb)
* [georeader with STARCOP to run plume detection in EMIT images](https://github.com/spaceml-org/STARCOP/blob/main/notebooks/inference_on_raw_EMIT_nc_file.ipynb)
## Citation
If you find this code useful please cite:
```
@article{portales-julia_global_2023,
title = {Global flood extent segmentation in optical satellite images},
volume = {13},
issn = {2045-2322},
doi = {10.1038/s41598-023-47595-7},
number = {1},
urldate = {2023-11-30},
journal = {Scientific Reports},
author = {Portalés-Julià, Enrique and Mateo-García, Gonzalo and Purcell, Cormac and Gómez-Chova, Luis},
month = nov,
year = {2023},
pages = {20316},
}
@article{ruzicka_starcop_2023,
title = {Semantic segmentation of methane plumes with hyperspectral machine learning models},
volume = {13},
issn = {2045-2322},
url = {https://www.nature.com/articles/s41598-023-44918-6},
doi = {10.1038/s41598-023-44918-6},
number = {1},
journal = {Scientific Reports},
author = {Růžička, Vít and Mateo-Garcia, Gonzalo and Gómez-Chova, Luis and Vaughan, Anna, and Guanter, Luis and Markham, Andrew},
month = nov,
year = {2023},
pages = {19999},
}
```
Raw data
{
"_id": null,
"home_page": "https://github.com/spaceml-org/georeader",
"name": "georeader-spaceml",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "raster reading,rasterio",
"author": "Gonzalo Mateo-Garcia",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/32/50/56ee62229b0d1163d9b8ffb24af1815bc08c9d7e37c506f913460a5e259a/georeader-spaceml-1.0.24.tar.gz",
"platform": null,
"description": "# georeader\n[![Article DOI:10.1038/s41598-023-47595-7](https://img.shields.io/badge/Article%20DOI-10.1038%2Fs41598.023.47595.7-blue)](https://doi.org/10.1038/s41598-023-47595-7) [![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/spaceml-org/georeader?sort=semver)](https://github.com/spaceml-org/georeader/releases) [![PyPI](https://img.shields.io/pypi/v/georeader-spaceml)](https://pypi.org/project/georeader-spaceml/) [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/georeader-spaceml)](https://pypi.org/project/georeader-spaceml/) [![PyPI - License](https://img.shields.io/pypi/l/georeader-spaceml)](https://github.com/spaceml-org/georeader/blob/main/LICENSE)\n\n**georeader** is a package to process raster data from different satellite missions. **georeader** makes easy to [read specific areas of your image](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_S2_SAFE_from_bucket.ipynb), to [reproject images from different satellites to a common grid](https://github.com/spaceml-org/georeader/blob/main/notebooks/reading_overlapping_sentinel2_aviris.ipynb) and to go from vector to raster formats ([`vectorize`](https://github.com/spaceml-org/georeader/blob/main/georeader/vectorize.py) and [`rasterize`](https://github.com/spaceml-org/georeader/blob/main/georeader/rasterize.py)). **georeader** is mainly used to process satellite data for scientific usage, to create ML-ready datasets and to implement [end-to-end operational inference pipelines](https://spaceml-org.github.io/ml4floods/content/ml4ops/HOWTO_postprocess_inference.html). \n\n## Install\nThe core package has [very few dependencies](https://github.com/spaceml-org/georeader/blob/main/requirements.txt); it is build on top of the geospatial libraries `rasterio`, `shapely` and `geopandas`.\n\n```bash\n# From pip\npip install georeader-spaceml\n\n# From GitHub\npip install git+https://github.com/spaceml-org/georeader#egg=georeader\n\n# Install with Google dependencies (to read objects from Google Cloud Storage or Google Earth Engine)\npip install git+https://github.com/spaceml-org/georeader#egg=georeader[google]\n\n# Install with Planetary Computer requirements\npip install git+https://github.com/spaceml-org/georeader#egg=georeader[microsoftplanetary]\n```\n\n## Getting started\n\n> Read from a Sentinel-2 image a fixed size subimage on an specific `lon,lat` location (directly from the [S2 public Google Cloud bucket](https://cloud.google.com/storage/docs/public-datasets/sentinel-2?hl=es-419)):\n \n```python\n# This snippet requires:\n# pip install fsspec gcsfs google-cloud-storage\nimport os\nos.environ[\"GS_NO_SIGN_REQUEST\"] = \"YES\"\n\nfrom georeader.readers import S2_SAFE_reader\nfrom georeader import read\n\ncords_read = (-104.394, 32.026) # long, lat\ncrs_cords = \"EPSG:4326\"\ns2_safe_path = S2_SAFE_reader.s2_public_bucket_path(\"S2B_MSIL1C_20191008T173219_N0208_R055_T13SER_20191008T204555.SAFE\")\ns2obj = S2_SAFE_reader.s2loader(s2_safe_path, \n out_res=10, bands=[\"B04\",\"B03\",\"B02\"])\n\n# copy to local avoids http errors specially when not using a Google Cloud project.\n# This will only copy the bands set up above B04, B03 and B02\ns2obj = s2obj.cache_product_to_local_dir(\".\")\n\n# See also read.read_from_bounds, read.read_from_polygon for different ways of croping an image\ndata = read.read_from_center_coords(s2obj,cords_read, shape=(2040, 4040),\n crs_center_coords=crs_cords)\n\ndata_memory = data.load() # this loads the data to memory\n\ndata_memory # GeoTensor object\n\n```\n```\n>> Transform: | 10.00, 0.00, 537020.00|\n| 0.00,-10.00, 3553680.00|\n| 0.00, 0.00, 1.00|\n Shape: (3, 2040, 4040)\n Resolution: (10.0, 10.0)\n Bounds: (537020.0, 3533280.0, 577420.0, 3553680.0)\n CRS: EPSG:32613\n fill_value_default: 0\n```\n\nIn the `.values` attribute we have the plain numpy array that we can plot with `show`:\n\n```python\nfrom rasterio.plot import show\nshow(data_memory.values/3500, transform=data_memory.transform)\n\n```\n<img src=\"https://raw.githubusercontent.com/spaceml-org/georeader/main/notebooks/images/sample_read.png\" alt=\"awesome georeader\" width=\"50%\">\n\n\nSaving the `GeoTensor` as a COG GeoTIFF: \n\n```python\nfrom georeader.save import save_cog\n\n# Supports writing in bucket location (e.g. gs://bucket-name/s2_crop.tif)\nsave_cog(data_memory, \"s2_crop.tif\", descriptions=s2obj.bands)\n```\n\n## Tutorials\n\nSentinel-2:\n* [Reading Sentinel-2 images from the public Google bucket](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_S2_SAFE_from_bucket.ipynb)\n* [Explore metadata of Sentinel-2 object](https://github.com/spaceml-org/georeader/blob/main/notebooks/Sentinel-2/explore_metadata_s2.ipynb)\n* [Query Sentinel-2 images over a location and time span, mosaic and plot them](https://github.com/spaceml-org/georeader/blob/main/notebooks/Sentinel-2/query_mosaic_s2_images.ipynb)\n\nOther:\n* [Tutorial to read overlapping tiles from a GeoTIFF and a Sentinel-2 image](https://github.com/spaceml-org/georeader/blob/main/notebooks/reading_overlapping_sentinel2_aviris.ipynb)\n* [Example of reading a Proba-V image overlapping with Sentinel-2 forcing same resolution](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_overlapping_probav_and_sentinel2.ipynb)\n* [Work with EMIT images](https://github.com/spaceml-org/georeader/blob/main/notebooks/emit_explore.ipynb)\n* [Read overlapping images of PRISMA and EMIT](https://github.com/spaceml-org/georeader/blob/main/notebooks/simultaneous_prisma_emit.ipynb)\n* [Read high resolution tile layers](https://github.com/spaceml-org/georeader/blob/main/notebooks/read_from_tileserver.ipynb)\n\nUsed in other projects:\n* [georeader with ml4floods to automatically download and produce flood extent maps: the Kherson Dam Break example](https://spaceml-org.github.io/ml4floods/content/ml4ops/HOWTO_postprocess_inference.html)\n* [georeader with STARCOP to simulate Sentinel-2 from AVIRIS images](https://github.com/spaceml-org/STARCOP/blob/main/notebooks/simulate_aviris_2_sentinel2.ipynb)\n* [georeader with STARCOP to run plume detection in EMIT images](https://github.com/spaceml-org/STARCOP/blob/main/notebooks/inference_on_raw_EMIT_nc_file.ipynb)\n\n\n## Citation\n\nIf you find this code useful please cite:\n```\n@article{portales-julia_global_2023,\n\ttitle = {Global flood extent segmentation in optical satellite images},\n\tvolume = {13},\n\tissn = {2045-2322},\n\tdoi = {10.1038/s41598-023-47595-7},\n\tnumber = {1},\n\turldate = {2023-11-30},\n\tjournal = {Scientific Reports},\n\tauthor = {Portal\u00e9s-Juli\u00e0, Enrique and Mateo-Garc\u00eda, Gonzalo and Purcell, Cormac and G\u00f3mez-Chova, Luis},\n\tmonth = nov,\n\tyear = {2023},\n\tpages = {20316},\n}\n@article{ruzicka_starcop_2023,\n\ttitle = {Semantic segmentation of methane plumes with hyperspectral machine learning models},\n\tvolume = {13},\n\tissn = {2045-2322},\n\turl = {https://www.nature.com/articles/s41598-023-44918-6},\n\tdoi = {10.1038/s41598-023-44918-6},\n\tnumber = {1},\n\tjournal = {Scientific Reports},\n\tauthor = {R\u016f\u017ei\u010dka, V\u00edt and Mateo-Garcia, Gonzalo and G\u00f3mez-Chova, Luis and Vaughan, Anna, and Guanter, Luis and Markham, Andrew},\n\tmonth = nov,\n\tyear = {2023},\n\tpages = {19999},\n}\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "Lightweight reader for raster files",
"version": "1.0.24",
"project_urls": {
"Homepage": "https://github.com/spaceml-org/georeader"
},
"split_keywords": [
"raster reading",
"rasterio"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9da0ab701c68deda79479eccae69bc2895c0aa66b54e91abc4f484f76eda43b4",
"md5": "a2b1350a84b063e09519fdd1f789c9da",
"sha256": "5aa71e39f3eaa0fbea99589311b72be995c7a3094424cbb5cc64609c063d701a"
},
"downloads": -1,
"filename": "georeader_spaceml-1.0.24-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a2b1350a84b063e09519fdd1f789c9da",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 144984,
"upload_time": "2024-03-01T21:45:35",
"upload_time_iso_8601": "2024-03-01T21:45:35.544004Z",
"url": "https://files.pythonhosted.org/packages/9d/a0/ab701c68deda79479eccae69bc2895c0aa66b54e91abc4f484f76eda43b4/georeader_spaceml-1.0.24-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "325056ee62229b0d1163d9b8ffb24af1815bc08c9d7e37c506f913460a5e259a",
"md5": "0487c98aed3d5886bf4a5c8dc055dbc3",
"sha256": "17d83ac76d34cfb533d38478eadc47c684150537dbd138e99175572189961961"
},
"downloads": -1,
"filename": "georeader-spaceml-1.0.24.tar.gz",
"has_sig": false,
"md5_digest": "0487c98aed3d5886bf4a5c8dc055dbc3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 141304,
"upload_time": "2024-03-01T21:45:37",
"upload_time_iso_8601": "2024-03-01T21:45:37.398240Z",
"url": "https://files.pythonhosted.org/packages/32/50/56ee62229b0d1163d9b8ffb24af1815bc08c9d7e37c506f913460a5e259a/georeader-spaceml-1.0.24.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-01 21:45:37",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "spaceml-org",
"github_project": "georeader",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "georeader-spaceml"
}