satellitetools.common.sentinel2 =============================== .. py:module:: satellitetools.common.sentinel2 .. autoapi-nested-parse:: Classes for handling Sentinel-2 data. @author: Olli Nevalainen (Finnish Meteorological Institute) Attributes ---------- .. autoapisummary:: satellitetools.common.sentinel2.logger satellitetools.common.sentinel2.S2_REFL_TRANS satellitetools.common.sentinel2.SCL_NODATA satellitetools.common.sentinel2.SPECTRAL_BAND_NO_DATA satellitetools.common.sentinel2.S2_BANDS_GEE satellitetools.common.sentinel2.S2_BANDS_10_20_GEE satellitetools.common.sentinel2.S2_BANDS_COG satellitetools.common.sentinel2.S2_BANDS_10_20_COG satellitetools.common.sentinel2.S2_BANDS_AWS_TO_GEE satellitetools.common.sentinel2.S2_BANDS_GEE_TO_AWS satellitetools.common.sentinel2.S2_SCL_CLASSES satellitetools.common.sentinel2.S2_FILTER1 satellitetools.common.sentinel2.S2_FILTER2 Classes ------- .. autoapisummary:: satellitetools.common.sentinel2.StrEnum satellitetools.common.sentinel2.S2Band satellitetools.common.sentinel2.SCLClass satellitetools.common.sentinel2.Sentinel2RequestParams satellitetools.common.sentinel2.Sentinel2Metadata satellitetools.common.sentinel2.Sentinel2ObservationGeometry satellitetools.common.sentinel2.Coordinates satellitetools.common.sentinel2.Sentinel2Item satellitetools.common.sentinel2.Sentinel2DataCollection Functions --------- .. autoapisummary:: satellitetools.common.sentinel2.filter_s2_qi_dataframe satellitetools.common.sentinel2.most_common Module Contents --------------- .. py:class:: StrEnum Bases: :py:obj:`str`, :py:obj:`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. .. py:data:: logger .. py:data:: S2_REFL_TRANS :value: 10000 .. py:data:: SCL_NODATA :value: 99 .. py:data:: SPECTRAL_BAND_NO_DATA .. py:class:: S2Band Bases: :py:obj:`enum.StrEnum` Sentinel-2 bands. Initialize self. See help(type(self)) for accurate signature. .. py:attribute:: B1 :value: 'B1' .. py:attribute:: B2 :value: 'B2' .. py:attribute:: B3 :value: 'B3' .. py:attribute:: B4 :value: 'B4' .. py:attribute:: B5 :value: 'B5' .. py:attribute:: B6 :value: 'B6' .. py:attribute:: B7 :value: 'B7' .. py:attribute:: B8 :value: 'B8' .. py:attribute:: B8A :value: 'B8A' .. py:attribute:: B9 :value: 'B9' .. py:attribute:: B11 :value: 'B11' .. py:attribute:: B12 :value: 'B12' .. py:attribute:: AOT :value: 'AOT' .. py:attribute:: WVP :value: 'WVP' .. py:attribute:: SCL :value: 'SCL' .. py:method:: to_aws() -> str Convert band name to AWS band name. Returns: ---------------- str Band name in AWS. .. py:method:: to_gee() -> str Convert band name to GEE band name. Returns: ---------------- str Band name in GEE. .. py:method:: get_10m_to_20m_bands() -> List[S2Band] :classmethod: Get 10-20 m bands for the band. Returns: ---------------- List[S2Band] List of 10-20 m bands. .. py:method:: get_all_bands() -> List[S2Band] :classmethod: Get all bands for the band. Returns: ---------------- List[S2Band] List of all bands. .. py:class:: SCLClass(*args, **kwds) Bases: :py:obj:`enum.Enum` Sentinel-2 Scene Classification Layer (SCL) classes. .. py:attribute:: NODATA :value: 0 .. py:attribute:: SATURATED_DEFECTIVE :value: 1 .. py:attribute:: DARK_FEATURE_SHADOW :value: 2 .. py:attribute:: CLOUD_SHADOW :value: 3 .. py:attribute:: VEGETATION :value: 4 .. py:attribute:: NOT_VEGETATED :value: 5 .. py:attribute:: WATER :value: 6 .. py:attribute:: UNCLASSIFIED :value: 7 .. py:attribute:: CLOUD_MEDIUM_PROBA :value: 8 .. py:attribute:: CLOUD_HIGH_PROBA :value: 9 .. py:attribute:: THIN_CIRRUS :value: 10 .. py:attribute:: SNOW_ICE :value: 11 .. py:data:: S2_BANDS_GEE :value: ['B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B9', 'B11', 'B12', 'AOT', 'WVP', 'SCL'] .. py:data:: S2_BANDS_10_20_GEE :value: ['B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B8A', 'B11', 'B12'] .. py:data:: S2_BANDS_COG :value: ['coastal', 'blue', 'green', 'red', 'rededge1', 'rededge2', 'rededge3', 'nir', 'nir08', 'nir09',... .. py:data:: S2_BANDS_10_20_COG :value: ['blue', 'green', 'red', 'rededge1', 'rededge2', 'rededge3', 'nir08', 'swir16', 'swir22'] .. py:data:: S2_BANDS_AWS_TO_GEE .. py:data:: S2_BANDS_GEE_TO_AWS .. py:data:: S2_SCL_CLASSES .. py:data:: S2_FILTER1 .. py:data:: S2_FILTER2 .. py:class:: Sentinel2RequestParams(datestart: str, dateend: str, datasource: satellitetools.common.classes.DataSource, bands: List[S2Band] = None, target_gsd: float = 20, qi_evaluation_scale: float = 20) S2 data request paramaters. Attributes: ---------------- datestart : str Start date of the data request. dateend : str End date of the data request. datasource : DataSource Data source for the request. bands : List[S2Band] List of Sentinel-2 bands to request. target_gsd : float Target ground sampling distance (GSD) in meters. qi_evaluation_scale : float Quality indicator evaluation scale. Initialize the Sentinel2RequestParams class. Parameters: ---------------- datestart : str Start date of the data request. dateend : str End date of the data request. datasource : DataSource Data source for the request. bands : List[S2Band] List of Sentinel-2 bands to request. target_gsd : float Target ground sampling distance (GSD) in meters. qi_evaluation_scale : float Quality indicator evaluation scale. .. py:attribute:: datestart .. py:attribute:: dateend .. py:attribute:: datasource .. py:attribute:: target_gsd :value: 20 .. py:attribute:: qi_evaluation_scale :value: 20 .. py:method:: __repr__() -> str .. py:class:: Sentinel2Metadata(acquisition_time: pandas.Timestamp, tileid: str, assetid: str, productid: str, projection: str, datasource: satellitetools.common.classes.DataSource, observation_geometry: Optional[Sentinel2ObservationGeometry] = None, class_percentages: Optional[Dict[SCLClass, float]] = None) Sentinel-2 metadata class. Attributes: ---------------- acquisition_time : pd.Timestamp Acquisition time of the image. tileid : str Sentinel-2 tile ID. assetid : str Asset ID of the image. productid : str Product ID of the image. projection : str Projection of the image. datasource : DataSource Data source of the image. observation_geometry : Optional[Sentinel2ObservationGeometry] Observation geometry of the image. class_percentages : Optional[Dict[SCLClass, float]] Class percentages of the image. Initialize the Sentinel2Metadata class. Parameters: ---------------- acquisition_time : pd.Timestamp Acquisition time of the image. tileid : str Sentinel-2 tile ID. assetid : str Asset ID of the image. productid : str Product ID of the image. projection : str Projection of the image. datasource : DataSource Data source of the image. .. py:attribute:: acquisition_time .. py:attribute:: tileid .. py:attribute:: assetid .. py:attribute:: productid .. py:attribute:: projection .. py:attribute:: datasource .. py:attribute:: observation_geometry :value: None .. py:attribute:: class_percentages :value: None .. py:method:: __repr__() -> str .. py:class:: Sentinel2ObservationGeometry Sentinel-2 observation geometry class. Attributes: ---------------- sun_azimuth : float Sun azimuth angle. sun_zenith : float Sun zenith angle. view_azimuth : float View azimuth angle. view_zenith : float View zenith angle. .. py:attribute:: sun_azimuth :type: float .. py:attribute:: sun_zenith :type: float .. py:attribute:: view_azimuth :type: float .. py:attribute:: view_zenith :type: float .. py:class:: Coordinates Coordinates class. Attributes: ---------------- x : list[float] List of x coordinates. y : list[float] List of y coordinates. .. py:attribute:: x :type: list[float] .. py:attribute:: y :type: list[float] .. py:class:: Sentinel2Item(metadata: Sentinel2Metadata, data: Optional[Dict[S2Band, numpy.ndarray]] = None) Sentinel-2 data item class. Attributes: ---------------- metadata : Sentinel2Metadata Metadata of the data item. data : Optional[Dict[S2Band, np.ndarray]] Data of the data item. coordinates : Dict[S2Band, Coordinates] Coordinates of the data item. Initialize the Sentinel2Item class. Parameters: ---------------- metadata : Sentinel2Metadata Metadata of the data item. data : Optional[Dict[S2Band, np.ndarray]] Data of the data item. .. py:attribute:: metadata .. py:attribute:: data .. py:attribute:: coordinates :type: Dict[S2Band, Coordinates] .. py:method:: __repr__() .. py:method:: set_coordinates(band: S2Band, xs: list, ys: list) Set coordinates for the data item. Parameters: ---------------- band : S2Band Sentinel-2 band. xs : list List of x coordinates. ys : list List of y coordinates. .. py:class:: Sentinel2DataCollection(aoi: satellitetools.common.classes.AOI, req_params: Sentinel2RequestParams) Sentinel-2 data collection class. Attributes: ---------------- aoi : AOI Area of interest. req_params : Sentinel2RequestParams Request parameters. quality_information : pd.DataFrame Quality information. xr_dataset : xr.Dataset Xarray dataset. s2_items : List[Sentinel2Item] List of Sentinel-2 items. Initialize the Sentinel2DataCollection class. Parameters: ---------------- aoi : AOI Area of interest. req_params : Sentinel2RequestParams Request parameters. .. py:attribute:: aoi .. py:attribute:: req_params .. py:attribute:: quality_information :type: pandas.DataFrame :value: None .. py:attribute:: xr_dataset :type: xarray.Dataset :value: None .. py:attribute:: s2_items :type: List[Sentinel2Item] :value: None .. py:method:: __repr__() .. py:method:: check_s2_items_exist() -> bool .. py:method:: create_quality_information() Create quality information dataframe. .. py:method:: filter_s2_items_by_tile(tileid: Optional[str] = None) Filter S2 items by tile. Parameters: ---------------- tileid : str Tile ID. .. py:method:: filter_s2_items_by_quality_information(qi_threshold: float = 0, qi_filter: List[SCLClass] = S2_FILTER1) Filter S2 items based on quality information. Parameters: ---------------- qi_threshold : float Quality indicator threshold. qi_filter : List[SCLClass] Quality indicator filter. .. py:method:: filter_s2_items(qi_threshold: float = 0, qi_filter: List[SCLClass] = S2_FILTER1) Filter S2 items based on quality information. Parameters: ---------------- qi_threshold : float Quality indicator threshold. qi_filter : List[SCLClass] Quality indicator filter. .. py:method:: sort_s2_items() Sort S2 items by acquisition time. .. py:method:: data_to_xarray() Convert data to xarray dataset. .. py:function:: filter_s2_qi_dataframe(s2_qi_dataframe: pandas.DataFrame, qi_thresh: float, s2_filter: List[SCLClass] = S2_FILTER1) -> pandas.DataFrame Filter qi dataframe. Parameters: ---------------- s2_qi_dataframe : pd.DataFrame Quality information dataframe. qi_thresh : float Quality indicator threshold. s2_filter : List[SCLClass] Quality indicator filter. Returns: ---------------- pd.DataFrame Filtered quality information dataframe. .. py:function:: most_common(lst: list[str]) -> str