satellitetools.common.sentinel2

Classes for handling Sentinel-2 data.

@author: Olli Nevalainen (Finnish Meteorological Institute)

Attributes

logger

S2_REFL_TRANS

SCL_NODATA

SPECTRAL_BAND_NO_DATA

S2_BANDS_GEE

S2_BANDS_10_20_GEE

S2_BANDS_COG

S2_BANDS_10_20_COG

S2_BANDS_AWS_TO_GEE

S2_BANDS_GEE_TO_AWS

S2_SCL_CLASSES

S2_FILTER1

S2_FILTER2

Classes

StrEnum

str(object='') -> str

S2Band

Sentinel-2 bands.

SCLClass

Sentinel-2 Scene Classification Layer (SCL) classes.

Sentinel2RequestParams

S2 data request paramaters.

Sentinel2Metadata

Sentinel-2 metadata class.

Sentinel2ObservationGeometry

Sentinel-2 observation geometry class.

Coordinates

Coordinates class.

Sentinel2Item

Sentinel-2 data item class.

Sentinel2DataCollection

Sentinel-2 data collection class.

Functions

filter_s2_qi_dataframe(→ pandas.DataFrame)

Filter qi dataframe.

most_common(→ str)

Module Contents

class satellitetools.common.sentinel2.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.common.sentinel2.logger[source]
satellitetools.common.sentinel2.S2_REFL_TRANS = 10000[source]
satellitetools.common.sentinel2.SCL_NODATA = 99[source]
satellitetools.common.sentinel2.SPECTRAL_BAND_NO_DATA[source]
class satellitetools.common.sentinel2.S2Band[source]

Bases: enum.StrEnum

Sentinel-2 bands.

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

B1 = 'B1'[source]
B2 = 'B2'[source]
B3 = 'B3'[source]
B4 = 'B4'[source]
B5 = 'B5'[source]
B6 = 'B6'[source]
B7 = 'B7'[source]
B8 = 'B8'[source]
B8A = 'B8A'[source]
B9 = 'B9'[source]
B11 = 'B11'[source]
B12 = 'B12'[source]
AOT = 'AOT'[source]
WVP = 'WVP'[source]
SCL = 'SCL'[source]
to_aws() str[source]

Convert band name to AWS band name. Returns: —————- str

Band name in AWS.

to_gee() str[source]

Convert band name to GEE band name.

Returns:

str

Band name in GEE.

classmethod get_10m_to_20m_bands() List[S2Band][source]

Get 10-20 m bands for the band.

Returns:

List[S2Band]

List of 10-20 m bands.

classmethod get_all_bands() List[S2Band][source]

Get all bands for the band.

Returns:

List[S2Band]

List of all bands.

class satellitetools.common.sentinel2.SCLClass(*args, **kwds)[source]

Bases: enum.Enum

Sentinel-2 Scene Classification Layer (SCL) classes.

NODATA = 0[source]
SATURATED_DEFECTIVE = 1[source]
DARK_FEATURE_SHADOW = 2[source]
CLOUD_SHADOW = 3[source]
VEGETATION = 4[source]
NOT_VEGETATED = 5[source]
WATER = 6[source]
UNCLASSIFIED = 7[source]
CLOUD_MEDIUM_PROBA = 8[source]
CLOUD_HIGH_PROBA = 9[source]
THIN_CIRRUS = 10[source]
SNOW_ICE = 11[source]
satellitetools.common.sentinel2.S2_BANDS_GEE = ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B9', 'B11', 'B12', 'AOT', 'WVP', 'SCL'][source]
satellitetools.common.sentinel2.S2_BANDS_10_20_GEE = ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B11', 'B12'][source]
satellitetools.common.sentinel2.S2_BANDS_COG = ['coastal', 'blue', 'green', 'red', 'rededge1', 'rededge2', 'rededge3', 'nir', 'nir08', 'nir09',...[source]
satellitetools.common.sentinel2.S2_BANDS_10_20_COG = ['blue', 'green', 'red', 'rededge1', 'rededge2', 'rededge3', 'nir08', 'swir16', 'swir22'][source]
satellitetools.common.sentinel2.S2_BANDS_AWS_TO_GEE[source]
satellitetools.common.sentinel2.S2_BANDS_GEE_TO_AWS[source]
satellitetools.common.sentinel2.S2_SCL_CLASSES[source]
satellitetools.common.sentinel2.S2_FILTER1[source]
satellitetools.common.sentinel2.S2_FILTER2[source]
class satellitetools.common.sentinel2.Sentinel2RequestParams(datestart: str, dateend: str, datasource: satellitetools.common.classes.DataSource, bands: List[S2Band] = None, target_gsd: float = 20, qi_evaluation_scale: float = 20)[source]

S2 data request paramaters.

Attributes:

datestartstr

Start date of the data request.

dateendstr

End date of the data request.

datasourceDataSource

Data source for the request.

bandsList[S2Band]

List of Sentinel-2 bands to request.

target_gsdfloat

Target ground sampling distance (GSD) in meters.

qi_evaluation_scalefloat

Quality indicator evaluation scale.

Initialize the Sentinel2RequestParams class.

Parameters:

datestartstr

Start date of the data request.

dateendstr

End date of the data request.

datasourceDataSource

Data source for the request.

bandsList[S2Band]

List of Sentinel-2 bands to request.

target_gsdfloat

Target ground sampling distance (GSD) in meters.

qi_evaluation_scalefloat

Quality indicator evaluation scale.

datestart[source]
dateend[source]
datasource[source]
target_gsd = 20[source]
qi_evaluation_scale = 20[source]
__repr__() str[source]
class satellitetools.common.sentinel2.Sentinel2Metadata(acquisition_time: pandas.Timestamp, tileid: str, assetid: str, productid: str, projection: str, datasource: satellitetools.common.classes.DataSource, observation_geometry: Sentinel2ObservationGeometry | None = None, class_percentages: Dict[SCLClass, float] | None = None)[source]

Sentinel-2 metadata class.

Attributes:

acquisition_timepd.Timestamp

Acquisition time of the image.

tileidstr

Sentinel-2 tile ID.

assetidstr

Asset ID of the image.

productidstr

Product ID of the image.

projectionstr

Projection of the image.

datasourceDataSource

Data source of the image.

observation_geometryOptional[Sentinel2ObservationGeometry]

Observation geometry of the image.

class_percentagesOptional[Dict[SCLClass, float]]

Class percentages of the image.

Initialize the Sentinel2Metadata class.

Parameters:

acquisition_timepd.Timestamp

Acquisition time of the image.

tileidstr

Sentinel-2 tile ID.

assetidstr

Asset ID of the image.

productidstr

Product ID of the image.

projectionstr

Projection of the image.

datasourceDataSource

Data source of the image.

acquisition_time[source]
tileid[source]
assetid[source]
productid[source]
projection[source]
datasource[source]
observation_geometry = None[source]
class_percentages = None[source]
__repr__() str[source]
class satellitetools.common.sentinel2.Sentinel2ObservationGeometry[source]

Sentinel-2 observation geometry class.

Attributes:

sun_azimuthfloat

Sun azimuth angle.

sun_zenithfloat

Sun zenith angle.

view_azimuthfloat

View azimuth angle.

view_zenithfloat

View zenith angle.

sun_azimuth: float[source]
sun_zenith: float[source]
view_azimuth: float[source]
view_zenith: float[source]
class satellitetools.common.sentinel2.Coordinates[source]

Coordinates class.

Attributes:

xlist[float]

List of x coordinates.

ylist[float]

List of y coordinates.

x: list[float][source]
y: list[float][source]
class satellitetools.common.sentinel2.Sentinel2Item(metadata: Sentinel2Metadata, data: Dict[S2Band, numpy.ndarray] | None = None)[source]

Sentinel-2 data item class.

Attributes:

metadataSentinel2Metadata

Metadata of the data item.

dataOptional[Dict[S2Band, np.ndarray]]

Data of the data item.

coordinatesDict[S2Band, Coordinates]

Coordinates of the data item.

Initialize the Sentinel2Item class.

Parameters:

metadataSentinel2Metadata

Metadata of the data item.

dataOptional[Dict[S2Band, np.ndarray]]

Data of the data item.

metadata[source]
data[source]
coordinates: Dict[S2Band, Coordinates][source]
__repr__()[source]
set_coordinates(band: S2Band, xs: list, ys: list)[source]

Set coordinates for the data item.

Parameters:

bandS2Band

Sentinel-2 band.

xslist

List of x coordinates.

yslist

List of y coordinates.

class satellitetools.common.sentinel2.Sentinel2DataCollection(aoi: satellitetools.common.classes.AOI, req_params: Sentinel2RequestParams)[source]

Sentinel-2 data collection class.

Attributes:

aoiAOI

Area of interest.

req_paramsSentinel2RequestParams

Request parameters.

quality_informationpd.DataFrame

Quality information.

xr_datasetxr.Dataset

Xarray dataset.

s2_itemsList[Sentinel2Item]

List of Sentinel-2 items.

Initialize the Sentinel2DataCollection class.

Parameters:

aoiAOI

Area of interest.

req_paramsSentinel2RequestParams

Request parameters.

aoi[source]
req_params[source]
quality_information: pandas.DataFrame = None[source]
xr_dataset: xarray.Dataset = None[source]
s2_items: List[Sentinel2Item] = None[source]
__repr__()[source]
check_s2_items_exist() bool[source]
create_quality_information()[source]

Create quality information dataframe.

filter_s2_items_by_tile(tileid: str | None = None)[source]

Filter S2 items by tile.

Parameters:

tileidstr

Tile ID.

filter_s2_items_by_quality_information(qi_threshold: float = 0, qi_filter: List[SCLClass] = S2_FILTER1)[source]

Filter S2 items based on quality information.

Parameters:

qi_thresholdfloat

Quality indicator threshold.

qi_filterList[SCLClass]

Quality indicator filter.

filter_s2_items(qi_threshold: float = 0, qi_filter: List[SCLClass] = S2_FILTER1)[source]

Filter S2 items based on quality information.

Parameters:

qi_thresholdfloat

Quality indicator threshold.

qi_filterList[SCLClass]

Quality indicator filter.

sort_s2_items()[source]

Sort S2 items by acquisition time.

data_to_xarray()[source]

Convert data to xarray dataset.

satellitetools.common.sentinel2.filter_s2_qi_dataframe(s2_qi_dataframe: pandas.DataFrame, qi_thresh: float, s2_filter: List[SCLClass] = S2_FILTER1) pandas.DataFrame[source]

Filter qi dataframe.

Parameters:

s2_qi_dataframepd.DataFrame

Quality information dataframe.

qi_threshfloat

Quality indicator threshold.

s2_filterList[SCLClass]

Quality indicator filter.

Returns:

pd.DataFrame

Filtered quality information dataframe.

satellitetools.common.sentinel2.most_common(lst: list[str]) str[source]