EOX GitLab Instance

Skip to content
Snippets Groups Projects
Commit 1d9a5ff9 authored by Fabian Schindler's avatar Fabian Schindler
Browse files

Fixing S2 metadata retrieval

Getting masks from granule metadata
parent b8866e1d
No related branches found
No related tags found
3 merge requests!36Staging to master to prepare 1.0.0 release,!32Registrar modularization,!27Registrar modularization
......@@ -34,7 +34,7 @@ def parse_footprint(value):
class Sentinel2RegistrationScheme(RegistrationScheme):
MTD_TL_SCHEMA = {
MTD_MSIL2A_SCHEMA = {
'begin_time': Parameter('/n1:Level-2A_User_Product/n1:General_Info/Product_Info/PRODUCT_START_TIME/text()', False, parse_datetime),
'end_time': Parameter('/n1:Level-2A_User_Product/n1:General_Info/Product_Info/PRODUCT_STOP_TIME/text()', False, parse_datetime),
'identifier': Parameter('/n1:Level-2A_User_Product/n1:General_Info/Product_Info/PRODUCT_URI/text()'),
......@@ -44,35 +44,46 @@ class Sentinel2RegistrationScheme(RegistrationScheme):
'generation_time': Parameter('/n1:Level-2A_User_Product/n1:General_Info/Product_Info/GENERATION_TIME/text()', False, parse_datetime),
'cloud_cover': Parameter('/n1:Level-2A_User_Product/n1:Quality_Indicators_Info/Cloud_Coverage_Assessment/text()'),
'image_file_paths': Parameter('/n1:Level-2A_User_Product/n1:General_Info/Product_Info/Product_Organisation/Granule_List/Granule/IMAGE_FILE/text()', True),
'mask_file_paths': Parameter('/n1:Level-2A_Tile_ID/n1:Quality_Indicators_Info/Pixel_Level_QI/MASK_FILENAME', True),
}
S2_NAMESPACES = {
MTD_TL_SCHEMA = {
'mask_file_paths': Parameter('/n1:Level-2A_Tile_ID/n1:Quality_Indicators_Info/Pixel_Level_QI/MASK_FILENAME/text()', True),
}
MTD_MSIL2A_NAMESPACES = {
'n1': "https://psd-14.sentinel2.eo.esa.int/PSD/User_Product_Level-2A.xsd"
}
MTD_TL_NAMESPACES = {
'n1': 'https://psd-14.sentinel2.eo.esa.int/PSD/S2_PDI_Level-2A_Tile_Metadata.xsd'
}
def get_context(self, source: Source, path: str):
metadata_file = join(path, 'MTD_MSIL2A.xml')
mtd_tree = read_xml(source, metadata_file)
# get MTD metadata
tree = read_xml(source, metadata_file)
metadata = parse_metadata_schema(mtd_tree, self.MTD_TL_SCHEMA, self.S2_NAMESPACES)
# get product metadata
metadata = parse_metadata_schema(tree, self.MTD_MSIL2A_SCHEMA, self.MTD_MSIL2A_NAMESPACES)
band_re = re.compile(r'.*([A-Z0-9]{3})_([0-9]{2}m)$')
band_re = re.compile(r'.*([A-Z0-9]{3}_[0-9]{2}m)$')
raster_files = {
band_re.match(image_file_path).groups()[0]: f'{join(path, image_file_path)}.jp2'
for image_file_path in metadata['image_file_paths']
}
# get granule metadata
mtd_files = source.list_files(join(path, 'GRANULE'), '*/MTD_TL.xml')
logger.info(f'{mtd_files}')
tl_tree = read_xml(source, mtd_files[0])
tile_metadata = parse_metadata_schema(tl_tree, self.MTD_TL_SCHEMA, self.MTD_TL_NAMESPACES)
mask_type_re = re.compile(r'.*/MSK_([A-Z]*)_([A-Z0-9]{3}).[a-z0-9]+$')
mask_files = {
mask_type_re.match(mask_file_path).groups[0]: join(path, mask_file_path)
for mask_file_path in metadata['mask_file_paths']
mask_type_re.match(mask_file_path).groups()[0]: join(path, mask_file_path)
for mask_file_path in tile_metadata['mask_file_paths']
if mask_type_re.match(mask_file_path) is not None
}
logger.info(f'{mask_files} {metadata["mask_file_paths"]}')
return Context(
identifier=metadata['identifier'],
path=path,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment