pycontrails.datalib.sentinel¶
Support for Sentinel-2 imagery retrieval through Google Cloud Platform.
Module Attributes
BigQuery table with imagery metadata |
|
Default columns to include in queries |
|
Default spatial extent for queries |
|
Default Sentinel channels to use if none are specified. |
|
Strip this prefix from GCP URLs when caching Sentinel files locally |
Functions
|
Extract artifacts for visualizing Sentinel data with the given color scheme. |
|
Find Sentinel-2 imagery intersecting with flight track. |
|
Find Sentinel-2 imagery within spatiotemporal region of interest. |
|
Compute 3d RGB array for the true color scheme. |
Classes
|
Support for Sentinel-2 data handling. |
- pycontrails.datalib.sentinel.BQ_DEFAULT_COLUMNS = ['base_url', 'granule_id', 'sensing_time']¶
Default columns to include in queries
- pycontrails.datalib.sentinel.BQ_DEFAULT_EXTENT = '{"type": "Polygon", "coordinates": [[[-180, -90], [180, -90], [180, 90], [-180, 90], [-180, -90]]]}'¶
Default spatial extent for queries
- pycontrails.datalib.sentinel.BQ_TABLE = 'bigquery-public-data.cloud_storage_geo_index.sentinel_2_index'¶
BigQuery table with imagery metadata
- pycontrails.datalib.sentinel.DEFAULT_BANDS = ['B02', 'B03', 'B04']¶
Default Sentinel channels to use if none are specified. These are visible bands for producing a true color composite.
- pycontrails.datalib.sentinel.GCP_STRIP_PREFIX = 'gs://gcp-public-data-sentinel-2/'¶
Strip this prefix from GCP URLs when caching Sentinel files locally
- class pycontrails.datalib.sentinel.Sentinel(base_url, granule_id, bands=None, cachestore=None)¶
Bases:
object
Support for Sentinel-2 data handling.
This class uses the PROJ coordinate transformation software through the pyproj python interface. pyproj is installed as part of the
sat
set of optional dependencies (pip install pycontrails[sat]
), but PROJ must be installed manually.- Parameters:
base_url (
str
) – Base URL of Sentinel-2 scene. To find URLs for Sentinel-2 scenes at specific locations and times, seequery()
andintersect()
.granule_id (
str
) – Granule ID of Sentinel-2 scene. To find URLs for Sentinel-2 scenes at specific locations and times, seequery()
andintersect()
.bands (
str | set[str] | None
) – Set of bands to retrieve. The 13 possible bands are represented by the string “B01” to “B12” plus “B8A”. For the true color scheme, setbands=("B02", "B03", "B04")
. By default, bands for the true color scheme are used. Bands must share a common resolution. The resolutions of each band are:B02-B04, B08: 10 m
B05-B07, B8A, B11, B12: 20 m
B01, B09, B10: 60 m
cachestore (
cache.CacheStore
, optional) – Cache store for Landsat data. If None, aDiskCacheStore
is used.
- get(reflective='reflectance')¶
Retrieve Sentinel-2 imagery.
- Parameters:
reflective (str =
{"raw", "reflectance"}
, optional) – Whether to return raw values or rescaled reflectances for reflective bands. By default, return reflectances.- Returns:
xarray.DataArray
– DataArray of Sentinel-2 data.
- pycontrails.datalib.sentinel.extract_sentinel_visualization(ds, color_scheme='true')¶
Extract artifacts for visualizing Sentinel data with the given color scheme.
- Parameters:
ds (
xarray.Dataset
) – Dataset of Sentinel data as returned bySentinel.get()
.color_scheme (str =
{"true"}
) – Color scheme to use for visualization. The true color scheme (the only option currently implemented) requires bands B02, B03, and B04.
- Returns:
rgb (
npt.NDArray[np.float32]
) – 3D RGB array of shape(height, width, 3)
.src_crs (
pyproj.CRS
) – Imagery projectionsrc_extent (
tuple[float,float,float,float]
) – Imagery extent in projected coordinates
- pycontrails.datalib.sentinel.intersect(flight, columns=None)¶
Find Sentinel-2 imagery intersecting with flight track.
This function will return all scenes with a bounding box that includes flight waypoints both before and after the sensing time.
This function requires access to the Google BigQuery API and uses the BigQuery python library.
- Parameters:
flight (
Flight
) – Flight for intersectioncolumns (
list[str]
,optional.
) – Columns to return from Google BigQuery table. By default, returns imagery base URL, granule ID, and sensing time.
- Returns:
pandas.DataFrame
– Query results in pandas DataFrame
See also
search.intersect()
- pycontrails.datalib.sentinel.query(start_time, end_time, extent=None, columns=None)¶
Find Sentinel-2 imagery within spatiotemporal region of interest.
This function requires access to the Google BigQuery API and uses the BigQuery python library.
- Parameters:
start_time (
numpy.datetime64
) – Start of time period for searchend_time (
numpy.datetime64
) – End of time period for searchextent (
str
, optional) – Spatial region of interest as a GeoJSON string. If not provided, defaults to a global extent.columns (
list[str]
, optional) – Columns to return from Google BigQuery table. By default, returns imagery base URL, granule ID, and sensing time.
- Returns:
pandas.DataFrame
– Query results in pandas DataFrame
See also
search.query()
- pycontrails.datalib.sentinel.to_true_color(ds)¶
Compute 3d RGB array for the true color scheme.
- Parameters:
ds (
xarray.Dataset
) – DataArray of Sentinel data with bands B02, B03, and B04.- Returns:
numpy.ndarray
– 3d RGB array with true color scheme.src_crs (
pyproj.CRS
) – Imagery projection