EOX GitLab Instance

Skip to content
Snippets Groups Projects

Single-file data updates

Merged Nikola Jankovic requested to merge fusion into staging
2 files
+ 17
18
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 48
3
import re
from os.path import join, normpath, dirname
import logging
from typing import List
from typing import List, Tuple
from datetime import datetime
from .xml import read_xml, parse_metadata_schema, Parameter
from .json import read_json
from .context import Context
from .source import Source
from .exceptions import RegistrationError
from .utils import isoformat
logger = logging.getLogger(__name__)
class RegistrationScheme:
def get_context(self) -> List[Context]:
def get_context(self, source: Source, path: str) -> List[Context]:
raise NotImplementedError
@@ -290,10 +291,54 @@ class STACCollectionScheme(RegistrationScheme):
return {}
class SingleFileRegistrationScheme(RegistrationScheme):
name = "single-file"
def __init__(self, footprint: str, product_type: str, level: str, date_format: str):
self.footprint = footprint
self.product_type = product_type
self.level = level
self.date_format = date_format
def get_context(self, source: Source, path: str) -> List[Context]:
begin_time, end_time = self._get_datetimes(path)
identifier = self._get_identifier(path, begin_time, end_time)
return [
Context(
identifier=identifier,
path=path,
scheme=self.name,
product_type=self.product_type,
product_level=self.level,
raster_files={self.name: path},
mask_files={},
metadata_files=[],
metadata={
"begin_time": isoformat(begin_time),
"end_time": isoformat(end_time),
"footprint": self.footprint,
}
)
]
def _get_identifier(self, path: str, begin_time: datetime, end_time: datetime) -> str:
return f"{self.product_type}_{isoformat(begin_time)}_{isoformat(end_time)}"
def _get_datetimes(self, path: str) -> Tuple[datetime, datetime]:
dt = path.split("/")[-1].split(".")[0]
begin = datetime.strptime(dt, self.date_format)
end = begin.replace(hour=23, minute=59, second=59)
return begin, end
REGISTRATION_SCHEMES = {
'gsc': GSCRegistrationScheme,
'sentinel-2': Sentinel2RegistrationScheme,
'stac-item': STACCollectionScheme,
'single-file': SingleFileRegistrationScheme,
}
Loading