eodal.metadata.sentinel2.parsing module

This module contains functions to extract relevant scene-specific Sentinel-2 metadata supporting L1C and L2A (sen2core-derived) processing levels

Copyright (C) 2022 Lukas Valentin Graf

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

eodal.metadata.sentinel2.parsing.get_scene_footprint(sensor_data: dict) str[source]

get the footprint (geometry) of a scene by calculating its extent using the original UTM coordinates of the scene. The obtained footprint is then converted to WGS84 geographic coordinates and returned as Extended Well-Known-Text (EWKT) string.

Parameters:

sensor_data – dict with ULX, ULY, NROWS_10m, NCOLS_10m, EPSG entries obtained from the MTD_TL.xml file

Return wkt:

extended well-known-text representation of the scene footprint

eodal.metadata.sentinel2.parsing.loop_s2_archive(in_dir: Path, extract_datastrip: bool | None = False, get_newest_datasets: bool | None = False, last_execution_date: date | None = None) Tuple[DataFrame][source]

wrapper function to loop over an entire archive (i.e., collection) of Sentinel-2 mapper in either L1C or L2A processing level or a mixture thereof.

The function returns a pandas dataframe for all found entries in the archive (i.e., directory). Each row in the dataframe denotes one scene.

Parameters:
  • in_dir – directory containing the Sentinel-2 data (L1C and/or L2A processing level). Sentinel-2 mapper are assumed to follow ESA’s .SAFE naming convention and structure

  • extract_datastrip – If True reads also metadata from the datastrip xml file (MTD_DS.xml)

  • get_newest_datasets – if set to True only datasets newer than a user-defined time stamp will be considered for ingestion into the database. This is particularly useful for updating the database after new mapper have been downloaded or processed.

  • last_execution_date – if get_newest_datasets is True this variable needs to be set. All datasets younger than that date will be considered for ingestion into the database.

Returns:

dataframe with metadata of all mapper handled by the function call

eodal.metadata.sentinel2.parsing.parse_MTD_DS(in_file: Path) Dict[str, Any][source]

Parses the MTD_DS.xml located in tghe /DATASTRIP folder in each .SAFE dataset. The xml contains the noise model parameters alpha and beta as well as physical gain factors required to calculate the radiometric uncertainty of the Level-1C data. The extraction of this data is therefore optional.

Parameters:

in_file – filepath of the scene metadata xml (MTD_DS.xml)

Return metadata:

dictionary with extracted noise model parameters, alpha and beta, per spectral band of MSI

eodal.metadata.sentinel2.parsing.parse_MTD_MSI(in_file: str) Dict[str, Any][source]

parses the MTD_MSIL1C or MTD_MSIL2A metadata file that is delivered with ESA Sentinel-2 L1C and L2A products, respectively.

The file is usually placed directly in the .SAFE root folder of an unzipped Sentinel-2 L1C or L2A scene.

The extracted metadata is returned as a dict.

Parameters:

in_file – filepath of the scene metadata xml (MTD_MSI2A.xml or MTD_MSIL1C.xml)

eodal.metadata.sentinel2.parsing.parse_MTD_TL(in_file: Path) Dict[str, Any][source]

Parses the MTD_TL.xml metadata file provided by ESA.This metadata XML is usually placed in the GRANULE subfolder of a ESA-derived S2 product and named ‘MTD_TL.xml’.

The ‘MTD_TL.xml’ is available for both processing levels (i.e., L1C and L2A). The function is able to handle both processing sources and returns some entries available in L2A processing level, only, as None type objects.

The function extracts the most important metadata from the XML and returns a dict with those extracted entries.

Parameters:

in_file – filepath of the scene metadata xml 8MTD_TL.xml)

Return metadata:

dict with extracted metadata entries

eodal.metadata.sentinel2.parsing.parse_s2_scene_metadata(in_dir: Path, extract_datastrip: bool | None = False) Tuple[Dict[str, Any]][source]

wrapper function to extract metadata from ESA Sentinel-2 mapper. It returns a dict with the metadata most important to characterize a given Sentinel-2 scene (mtd_msi). Optionally, some information about the datastrip can be extracted as well (MTD_DS.xml); this information is required for the uncertainty modelling and therefore not extracted by default.

The function works on both, L1C and L2A (sen2cor-based) processing levels. The amount of metadata, however, is reduced in the case of L1C since no scene classification information is available.

NOTE: In order to identify mapper and their processing level correctly, L2A mapper must have ‘_MSIL2A_’ occuring somewhere in the filepath. For L1C, it must be ‘_MSIL1C_’.

Parameters:
  • in_dir – directory containing the L1C or L2A Sentinel-2 scene

  • extract_datastrip – If True reads also metadata from the datastrip xml file (MTD_DS.xml)

Return mtd_msi:

dict with extracted metadata items