EOX GitLab Instance

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

Fixing Sentinel-2 registration schema

parent a6385847
No related branches found
No related tags found
1 merge request!61Staging to master 1.3.0
...@@ -12,6 +12,7 @@ from .exceptions import RegistrationError ...@@ -12,6 +12,7 @@ from .exceptions import RegistrationError
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class RegistrationScheme: class RegistrationScheme:
def get_context(self) -> List[Context]: def get_context(self) -> List[Context]:
raise NotImplementedError raise NotImplementedError
...@@ -36,8 +37,7 @@ def parse_footprint(value): ...@@ -36,8 +37,7 @@ def parse_footprint(value):
class Sentinel2RegistrationScheme(RegistrationScheme): class Sentinel2RegistrationScheme(RegistrationScheme):
name = 'sentinel-2-l2a' name = 'sentinel-2'
MTD_SCHEMAS = { MTD_SCHEMAS = {
'MSIL1C': { 'MSIL1C': {
...@@ -94,19 +94,19 @@ class Sentinel2RegistrationScheme(RegistrationScheme): ...@@ -94,19 +94,19 @@ class Sentinel2RegistrationScheme(RegistrationScheme):
def get_context(self, source: Source, path: str) -> List[Context]: def get_context(self, source: Source, path: str) -> List[Context]:
try: try:
metadata_file = join(path, 'MTD_MSIL2A.xml') metadata_file = join(path, 'MTD_MSIL2A.xml')
mtd_schema = MTD_SCHEMAS['MSIL2A'] tree = read_xml(source, metadata_file)
mtd_namespaces = MTD_NAMESPACES['MSIL2A'] mtd_schema = self.MTD_SCHEMAS['MSIL2A']
mtd_tl_schema = MTD_TL_SCHEMAS['MSIL2A'] mtd_namespaces = self.MTD_NAMESPACES['MSIL2A']
mtd_tl_namespaces = MTD_TL_NAMESPACES['MSIL2A'] mtd_tl_schema = self.MTD_TL_SCHEMAS['MSIL2A']
mtd_tl_namespaces = self.MTD_TL_NAMESPACES['MSIL2A']
except: except Exception:
metadata_file = join(path, 'MTD_MSIL1C.xml') metadata_file = join(path, 'MTD_MSIL1C.xml')
mtd_schema = MTD_SCHEMAS['MSIL1C'] tree = read_xml(source, metadata_file)
mtd_namespaces = MTD_NAMESPACES['MSIL1C'] mtd_schema = self.MTD_SCHEMAS['MSIL1C']
mtd_tl_schema = MTD_TL_SCHEMAS['MSIL1C'] mtd_namespaces = self.MTD_NAMESPACES['MSIL1C']
mtd_tl_namespaces = MTD_TL_NAMESPACES['MSIL1C'] mtd_tl_schema = self.MTD_TL_SCHEMAS['MSIL1C']
mtd_tl_namespaces = self.MTD_TL_NAMESPACES['MSIL1C']
tree = read_xml(source, metadata_file)
# get product metadata # get product metadata
metadata = parse_metadata_schema(tree, mtd_schema, mtd_namespaces) metadata = parse_metadata_schema(tree, mtd_schema, mtd_namespaces)
...@@ -204,7 +204,9 @@ class GSCRegistrationScheme(RegistrationScheme): ...@@ -204,7 +204,9 @@ class GSCRegistrationScheme(RegistrationScheme):
metadata_file = gsc_filenames[0] metadata_file = gsc_filenames[0]
tree = read_xml(source, metadata_file) tree = read_xml(source, metadata_file)
metadata = parse_metadata_schema(tree, self.GSC_SCHEMA, tree.getroot().nsmap) metadata = parse_metadata_schema(
tree, self.GSC_SCHEMA, tree.getroot().nsmap
)
tiff_files = { tiff_files = {
metadata['type']: source.list_files(path, ['*.tif', '*.TIF']) metadata['type']: source.list_files(path, ['*.tif', '*.TIF'])
...@@ -294,6 +296,7 @@ REGISTRATION_SCHEMES = { ...@@ -294,6 +296,7 @@ REGISTRATION_SCHEMES = {
'stac-item': STACCollectionScheme, 'stac-item': STACCollectionScheme,
} }
def get_scheme(config: dict, path: str) -> RegistrationScheme: def get_scheme(config: dict, path: str) -> RegistrationScheme:
cfg_schemes = config['schemes'] cfg_schemes = config['schemes']
...@@ -305,10 +308,11 @@ def get_scheme(config: dict, path: str) -> RegistrationScheme: ...@@ -305,10 +308,11 @@ def get_scheme(config: dict, path: str) -> RegistrationScheme:
break break
else: else:
# no source found # no source found
raise RegistrationError(f'Could not find a suitable scheme for the path {path}') raise RegistrationError(
f'Could not find a suitable scheme for the path {path}'
)
return REGISTRATION_SCHEMES[cfg_scheme['type']]( return REGISTRATION_SCHEMES[cfg_scheme['type']](
*cfg_scheme.get('args', []), *cfg_scheme.get('args', []),
**cfg_scheme.get('kwargs', {}), **cfg_scheme.get('kwargs', {}),
) )
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