Skip to main content

Lightweight reader for raster files

Project description

georeader

Read data from rasters: very few dependencies, reads from cloud storage and lazy loading.

Install

# Install with minimal requirements (only rasterio, numpy as shapely)
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

# 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 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:

from rasterio.plot import show
show(data_memory.values/3500, transform=data_memory.transform)
awesome georeader

Saving the GeoTensor as a COG GeoTIFF:

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:

Other:

Citation

If you find this code useful please cite:

@software{georeader,
  author = {Mateo-García, Gonzalo},
  month = {11},
  title = {{georeader}},
  url = {https://github.com/spaceml-org/georeader},
  version = {0.0.1},
  year = {2022}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

georeader-spaceml-1.0.1.tar.gz (78.6 kB view details)

Uploaded Source

Built Distribution

georeader_spaceml-1.0.1-py3-none-any.whl (83.6 kB view details)

Uploaded Python 3

File details

Details for the file georeader-spaceml-1.0.1.tar.gz.

File metadata

  • Download URL: georeader-spaceml-1.0.1.tar.gz
  • Upload date:
  • Size: 78.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for georeader-spaceml-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bd729999214b4e0fe457e5148c083bf8642d62735b099fe4aa24bba3488e70b2
MD5 1d6ab1e3b7fe191b72e6056a7091d396
BLAKE2b-256 35afa9a02871872856c65c45ca144f232fa0c4b0cbad7d0aca0016d016b3547f

See more details on using hashes here.

Provenance

File details

Details for the file georeader_spaceml-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for georeader_spaceml-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d043ccf24fa232e912408a8d87c4aa6e7fdc194fb12b15e7cd654a79c77068fc
MD5 882c726d271f0e6b5c336d3143f37c89
BLAKE2b-256 ad756bdb048ee6f47bbf038819221c314ec44f0228fc687349a5c13836b34bda

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page