satellitetools.aws

Module to get Sentinel-2 data from AWS Open data registry, where Sentinel-2 (level 2A) data is available as cloud-optimized geotiffs (https://registry.opendata.aws/sentinel-2-l2a-cogs/).

@author: Olli Nevalainen (Finnish Meteorological Institute)

Attributes

logger

BUFFER_MULTIPLIER

Classes

StrEnum

str(object='') -> str

EarthSearchCollection

Enum where members are also (and must be) strings

EarthSearch

Class to handle search for items in EarthSearch.

AWSSentinel2DataCollection

Class to handle Sentinel-2 data from AWS Open data registry.

AWSSentinel2Metadata

Class to handle Sentinel-2 metadata from AWS Open data registry.

AWSSentinel2Item

Class to handle Sentinel-2 item from AWS Open data registry.

Functions

remove_duplicate_items(→ List[pystac.item.Item])

Remove duplicate items from list of items.

get_xml_metadata(→ Dict)

Get XML metadata for Sentinel-2 item.

get_observation_geometry(...)

Get observation geometry for Sentinel-2 item.

_get_s2_data_single(s2_item, aoi, bands, target_resolution)

_get_scl_data_single(s2_item, aoi, target_resolution)

_multiprocess_get_item_s2_data(→ List[AWSSentinel2Item])

_multiprocess_get_scl_data(→ List[AWSSentinel2Item])

split_time_range(→ List[Tuple[pandas.Timestamp, ...)

Split time range to half year time ranges.

search_s2_cogs(→ List[pystac.item.Item])

Search for Sentinel-2 items from AWS Open data registry.

cog_get_s2_quality_info(→ pandas.DataFrame)

Get quality information for Sentinel-2 items.

cog_get_s2_band_data(→ pandas.DataFrame)

Get Sentinel-2 data.

Module Contents

class satellitetools.aws.StrEnum[source]

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

Initialize self. See help(type(self)) for accurate signature.

satellitetools.aws.logger[source]
satellitetools.aws.BUFFER_MULTIPLIER = 8[source]
class satellitetools.aws.EarthSearchCollection[source]

Bases: enum.StrEnum

Enum where members are also (and must be) strings

Initialize self. See help(type(self)) for accurate signature.

SENTINEL2_C1_L2A = 'sentinel-2-c1-l2a'[source]
SENTINEL2_L2A = 'sentinel-2-l2a'[source]
class satellitetools.aws.EarthSearch(datestart: str | pandas.Timestamp | datetime.datetime, dateend: str | pandas.Timestamp | datetime.datetime, bbox: List[float], collection: EarthSearchCollection)[source]

Class to handle search for items in EarthSearch.

Attributes:

datestart: Union[str, pd.Timestamp, datetime.datetime]

Start date for search

dateend: Union[str, pd.Timestamp, datetime.datetime]

End date for search

bbox: List[float]

Bounding box coordinates [minx, miny, maxx, maxy]

collection: EarthSearchCollection

Collection to search

limit: int

Limit for search results

Note:

EarthSearch API documentation at: https://earth-search.aws.element84.com/v1/api.html#tag/Item-Search/operation/getItemSearch

Initialize EarthSearch object.

Parameters:

datestart: Union[str, pd.Timestamp, datetime.datetime]

Start date for search

dateend: Union[str, pd.Timestamp, datetime.datetime]

End date for search

bbox: List[float]

Bounding box coordinates [minx, miny, maxx, maxy]

collection: EarthSearchCollection

Collection to search

EARTH_SEARCH_ENDPOINT = 'https://earth-search.aws.element84.com/v1'[source]
DEFAULT_REQUEST_LIMIT = 10000[source]
datestart[source]
dateend[source]
bbox[source]
collection[source]
limit = 10000[source]
search_collection(datestart: pandas.Timestamp, dateend: pandas.Timestamp, collection: EarthSearchCollection) List[pystac.item.Item][source]

Search for items in EarthSearch collection.

Parameters:

datestart: pd.Timestamp

Start date for search

dateend: pd.Timestamp

End date for search

collection: EarthSearchCollection

Collection to search

Returns:

all_items: List[Item]

List of items

get_items() List[pystac.item.Item][source]

Get items from EarthSearch.

Returns:

all_items: List[Item]

List of items

satellitetools.aws.remove_duplicate_items(items) List[pystac.item.Item][source]

Remove duplicate items from list of items.

Parameters:

items: List[Item]

List of items

Returns:

filtered_items: List[Item]

Filtered list of items

class satellitetools.aws.AWSSentinel2DataCollection(aoi: satellitetools.common.classes.AOI, req_params: satellitetools.common.sentinel2.Sentinel2RequestParams, multiprocessing: int | None = None)[source]

Bases: satellitetools.common.sentinel2.Sentinel2DataCollection

Class to handle Sentinel-2 data from AWS Open data registry.

Attributes:

aoi: AOI

Area of interest

req_params: Sentinel2RequestParams

Request parameters

s2_items: List[AWSSentinel2Item]

List of Sentinel-2 items

multiprocessing: Optional[int]

Number of processes to use in multiprocessing

Initialize AWSSentinel2DataCollection object.

Parameters:

aoi: AOI

Area of interest

req_params: Sentinel2RequestParams

Request parameters

multiprocessing: Optional[int]

Number of processes to use in multiprocessing

s2_items: List[AWSSentinel2Item] = None[source]
multiprocessing = None[source]
search_s2_items()[source]

Search for Sentinel-2 items from AWS Open data registry.

get_quality_info()[source]

Get quality information for Sentinel-2 items.

get_s2_data()[source]

Get Sentinel-2 data.

class satellitetools.aws.AWSSentinel2Metadata(item: pystac.item.Item)[source]

Bases: satellitetools.common.sentinel2.Sentinel2Metadata

Class to handle Sentinel-2 metadata from AWS Open data registry.

Attributes:

profiles: Dict[S2Band, dict]

Dictionary to store all profiles for bands

Initialize AWSSentinel2Metadata object.

Parameters:

item: Item

Item object from pystac_client

profiles: Dict[satellitetools.common.sentinel2.S2Band, dict][source]
get_observation_geometry(item: pystac.item.Item)[source]

Get observation geometry for Sentinel-2 item.

Parameters:

item: Item

Item object from pystac_client

get_reference_band(target_resolution: float) satellitetools.common.sentinel2.S2Band[source]
class satellitetools.aws.AWSSentinel2Item(item: pystac.item.Item)[source]

Bases: satellitetools.common.sentinel2.Sentinel2Item

Class to handle Sentinel-2 item from AWS Open data registry.

Attributes:

source_item: Item

Item object from pystac_client

Initialize AWSSentinel2Item object.

Parameters:

item: Item

Item object from pystac_client

source_item[source]
get_observation_geometry()[source]

Get observation geometry for Sentinel-2 item.

get_band_data(aoi: satellitetools.common.classes.AOI, band: satellitetools.common.sentinel2.S2Band)[source]

Get band data for Sentinel-2 item.

Parameters:

aoi: AOI

Area of interest

band: S2Band

Sentinel-2 band

get_item_data(aoi: satellitetools.common.classes.AOI, bands: List[satellitetools.common.sentinel2.S2Band], target_resolution: float)[source]

Get data for all bands for Sentinel-2 item.

Parameters:

aoi: AOI

Area of interest

bands: List[S2Band]

List of Sentinel-2 bands

target_resolution: float

Target resolution

add_class_percentages()[source]

Add class percentages for Sentinel-2 item.

Class percentages are calculated based on the SCL band data.

create_coordinates(band: satellitetools.common.sentinel2.S2Band)[source]

Create coordinates for Sentinel-2 item.

Parameters:

band: S2Band

Sentinel-2 band

satellitetools.aws.get_xml_metadata(item: pystac.item.Item) Dict[source]

Get XML metadata for Sentinel-2 item.

Parameters:

item: Item

Item object from pystac_client

Returns:

metadata: Dict

XML metadata

satellitetools.aws.get_observation_geometry(item: pystac.item.Item) satellitetools.common.sentinel2.Sentinel2ObservationGeometry[source]

Get observation geometry for Sentinel-2 item.

Parameters:

item: Item

Item object from pystac_client

Returns:

observation_geometry: Sentinel2ObservationGeometry

Observation geometry

satellitetools.aws._get_s2_data_single(s2_item: AWSSentinel2Item, aoi: satellitetools.common.classes.AOI, bands: List[satellitetools.common.sentinel2.S2Band], target_resolution: float)[source]
satellitetools.aws._get_scl_data_single(s2_item: AWSSentinel2Item, aoi: satellitetools.common.classes.AOI, target_resolution: float)[source]
satellitetools.aws._multiprocess_get_item_s2_data(s2_items: List[AWSSentinel2Item], aoi: satellitetools.common.classes.AOI, bands: List[satellitetools.common.sentinel2.S2Band], target_resolution: float, processes: int) List[AWSSentinel2Item][source]
satellitetools.aws._multiprocess_get_scl_data(s2_items: List[AWSSentinel2Item], aoi: satellitetools.common.classes.AOI, target_resolution: float, processes: int) List[AWSSentinel2Item][source]
satellitetools.aws.split_time_range(datestart: pandas.Timestamp, dateend: pandas.Timestamp) List[Tuple[pandas.Timestamp, pandas.Timestamp]][source]

Split time range to half year time ranges.

Parameters:

datestart: pd.Timestamp

Start date

dateend: pd.Timestamp

End date

Returns:

time_ranges: List[Tuple[pd.Timestamp, pd.Timestamp]]

List of time ranges

satellitetools.aws.search_s2_cogs(aoi: satellitetools.common.classes.AOI, req_params: satellitetools.common.sentinel2.Sentinel2RequestParams) List[pystac.item.Item][source]

Search for Sentinel-2 items from AWS Open data registry.

Parameters:

aoi: AOI

Area of interest

req_params: Sentinel2RequestParams

Request parameters

Returns:

items: List[Item]

List of Sentinel-2 items

satellitetools.aws.cog_get_s2_quality_info(aoi: satellitetools.common.classes.AOI, req_params: satellitetools.common.sentinel2.Sentinel2RequestParams, items: List[pystac.item.Item]) pandas.DataFrame[source]

Get quality information for Sentinel-2 items.

Parameters:

aoi: AOI

Area of interest

req_params: Sentinel2RequestParams

Request parameters

items: List[Item]

List of Sentinel-2 items

Returns:

qi_df: pd.DataFrame

Quality information dataframe

satellitetools.aws.cog_get_s2_band_data(aoi: satellitetools.common.classes.AOI, req_params: satellitetools.common.sentinel2.Sentinel2RequestParams, items: List[pystac.item.Item], qi_df: pandas.DataFrame) pandas.DataFrame[source]

Get Sentinel-2 data.

Parameters:

aoi: AOI

Area of interest

req_params: Sentinel2RequestParams

Request parameters

items: List[Item]

List of Sentinel-2 items

qi_df: pd.DataFrame

Quality information dataframe

Returns:

xr_dataset: pd.DataFrame

Sentinel-2 data as xarray dataset