EOX GitLab Instance

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

Cleanup

parent 217c6fee
No related branches found
No related tags found
3 merge requests!36Staging to master to prepare 1.0.0 release,!32Registrar modularization,!27Registrar modularization
......@@ -111,9 +111,7 @@ class EOxServerBackend(Backend):
raster_item = item.raster_files.get(raster_identifier)
raster_item = '/'.join(raster_item.split('/')[1:])
logger.info(f"Adding browse {browse_type_name or 'default'} {raster_item} to product")
logger.info(f'{storage + [raster_item]}')
BrowseRegistrator().register(
product.identifier,
......
import re
from os.path import join
import logging
from .xml import read_xml, parse_metadata_schema, Parameter
from .context import Context
from .source import Source
from .exceptions import RegistrationError
class RegistrationScheme:
def __init__(self, source, path):
self.source = source
self.path = path
logger = logging.getLogger(__name__)
class RegistrationScheme:
def get_context(self):
raise NotImplementedError
def parse_datetime(value):
return value
def pairwise(iterable):
"s -> (s0,s1), (s2,s3), (s4, s5), ..."
a = iter(iterable)
return zip(a, a)
def parse_footprint(value):
coord_list = ','.join(
f'{x} {y}'
for y, x in pairwise(value.split())
)
return f'POLYGON(({coord_list}))'
class Sentinel2RegistrationScheme(RegistrationScheme):
......@@ -23,10 +38,11 @@ class Sentinel2RegistrationScheme(RegistrationScheme):
'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()'),
'footprint': Parameter('/n1:Level-2A_User_Product/n1:Geometric_Info/Product_Footprint/Product_Footprint/Global_Footprint/EXT_POS_LIST/text()', False, parse_footprint),
'level': Parameter('/n1:Level-2A_User_Product/n1:General_Info/Product_Info/PROCESSING_LEVEL/text()'),
'type': Parameter('/n1:Level-2A_User_Product/n1:General_Info/Product_Info/PRODUCT_TYPE/text()'),
'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'),
'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),
}
......@@ -35,9 +51,9 @@ class Sentinel2RegistrationScheme(RegistrationScheme):
'n1': "https://psd-14.sentinel2.eo.esa.int/PSD/User_Product_Level-2A.xsd"
}
def get_context(self):
metadata_file = join(self.path, 'MTD_TL.xml')
mtd_tree = read_xml(self.source, metadata_file)
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
......@@ -45,18 +61,23 @@ class Sentinel2RegistrationScheme(RegistrationScheme):
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(self.path, image_file_path)}.jp2'
band_re.match(image_file_path).groups()[0]: f'{join(path, image_file_path)}.jp2'
for image_file_path in metadata['image_file_paths']
}
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]: mask_file_path
mask_type_re.match(mask_file_path).groups[0]: join(path, mask_file_path)
for mask_file_path in metadata['mask_file_paths']
}
logger.info(f'{mask_files} {metadata["mask_file_paths"]}')
return Context(
identifier=metadata['identifier'],
path=path,
product_type=metadata['type'],
product_level=metadata['level'],
raster_files=raster_files,
mask_files=mask_files,
metadata_files=[metadata_file],
......@@ -65,6 +86,7 @@ class Sentinel2RegistrationScheme(RegistrationScheme):
'end_time': metadata['end_time'],
'generation_time': metadata['generation_time'],
'cloud_cover': metadata['cloud_cover'],
'footprint': metadata['footprint'],
}
)
......
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