diff --git a/.gitignore b/.gitignore index b6e4761..1008373 100644 --- a/.gitignore +++ b/.gitignore @@ -114,6 +114,9 @@ venv.bak/ .spyderproject .spyproject +# PyCharm +.idea + # Rope project settings .ropeproject diff --git a/edr_data_interface/abstract/admin.py b/edr_data_interface/abstract/admin.py new file mode 100644 index 0000000..d59f563 --- /dev/null +++ b/edr_data_interface/abstract/admin.py @@ -0,0 +1,58 @@ +from .core import Interface + + +class RefreshCollections(Interface): + def __init__(self, supported_data_queries) -> None: + self.supported_data_queries = supported_data_queries + self.temporal_extent = False + self.vertical_extent = False + + self._get_temporal_extent() + self._get_vertical_extent() + + def _get_temporal_extent(self): + """ + Determine if the collection's data has a temporal extent. + + Must set `self.temporal_extent`, and also determine `interval`, `trs` and `name` + for the temporal extent JSON response. The `trs` variable must be provided + as well-known text (WKT). + + """ + self.temporal_extent = False + + def _get_vertical_extent(self): + """ + Determine if the collection's data has a vertical extent. + + Must set `self.vertical_extent`, and also determine `interval`, `vrs` and `name` + for the vertical extent JSON response. The `vrs` variable must be provided + as well-known text (WKT). + + """ + self.vertical_extent = False + + def has_temporal_extent(self): + """Define if the collection has a temporal extent.""" + return self.temporal_extent + + def has_vertical_extent(self): + """Define if the collection has a vertical extent.""" + return self.vertical_extent + + def get_parameters(self, collection_id): + """ + Return metadata for all the parameters (~physical quantities) + associated with the collection specified by its ID `collection_id`. + + """ + raise NotImplementedError + + def make_collection(self, name): + raise NotImplementedError + + def make_collections(self): + raise NotImplementedError + + def data(self): + return self.make_collections() \ No newline at end of file diff --git a/edr_data_interface/concrete/caf/__init__.py b/edr_data_interface/concrete/caf/__init__.py new file mode 100644 index 0000000..1b96992 --- /dev/null +++ b/edr_data_interface/concrete/caf/__init__.py @@ -0,0 +1 @@ +from .admin import RefreshCollections \ No newline at end of file diff --git a/edr_data_interface/concrete/caf/admin.py b/edr_data_interface/concrete/caf/admin.py new file mode 100644 index 0000000..ec17ea3 --- /dev/null +++ b/edr_data_interface/concrete/caf/admin.py @@ -0,0 +1,21 @@ +from typing import List + +from clean_air.data.storage import S3FSMetadataStore +from clean_air.models import Metadata + +from ...abstract.admin import RefreshCollections + + +class RefreshCollections(RefreshCollections): + def __init__(self): + self.metadata_store = S3FSMetadataStore + + def collection(self, name) -> Metadata: + return self.metadata_store.get(name) + + def collections(self) -> List: + collections_metadata: List[Metadata] = [] + for collection_name in self.metadata_store.available_datasets(): + collection_metadata = self.collection(collection_name) + collections_metadata.append(collection_metadata) + return collections_metadata \ No newline at end of file diff --git a/edr_data_interface/concrete/dummy/__init__.py b/edr_data_interface/concrete/dummy/__init__.py index 3fdc92d..f5be4c9 100644 --- a/edr_data_interface/concrete/dummy/__init__.py +++ b/edr_data_interface/concrete/dummy/__init__.py @@ -1 +1,2 @@ +from .admin import RefreshCollections from .capabilities import API, Capabilities, Conformance \ No newline at end of file diff --git a/edr_data_interface/concrete/dummy/admin.py b/edr_data_interface/concrete/dummy/admin.py new file mode 100644 index 0000000..f03a6ff --- /dev/null +++ b/edr_data_interface/concrete/dummy/admin.py @@ -0,0 +1,126 @@ +from collections import namedtuple +from collections import namedtuple +from typing import Dict, List + +from ...abstract.admin import RefreshCollections + + +PARAMS = { + "a": [ + "xxxxa", + "A dummy parameter A with certain characteristics", + "Dummy ratio", + "0.5", + "http://www.example.com/define/dummy_ratio", + "http://www.example.com/define/property/a", + "A dummy parameter A", + ], + "b": [ + "xxxxb", + "A dummy parameter B with special characteristics", + "Dummy value", + "1000", + "http://www.example.com/define/dummy_value", + "http://www.example.com/define/property/b", + "A dummy parameter B", + ], + "c": [ + "xxxxc", + "A dummy parameter C with specific characteristics", + "Dummy constant", + "1", + "http://www.example.com/define/dummy_constant", + "http://www.example.com/define/property/c", + "A dummy parameter C", + ], +} + +PARAMS_LOOKUP = { + "00001": ["a", "c"], + "00002": ["a", "b", "c"], +} + +SAMPLES: Dict = { + "00001": [ + "00001", + "One", + "The first item", + "CRS84", + "WGS 1984", + [-180, -90, 180, 90], + ["Example", "Dummy"], + ], + "00002": [ + "00002", + "Two", + "The second item", + "EPSG4326", + "EPSG4326", + [-180, -90, 180, 90], + ["Example", "Dummy"], + ], +} + +FIELDS: List[str] = [ + "id", + "name", + "description", + "crs", + "crs_name", + "bbox", + "keywords", +] + +PARAM_FIELDS = [ + "name", + "id", + "description", + "unit_label", + "unit_value", + "unit_defn", + "property_id", + "property_label" +] + +param = namedtuple("param", PARAM_FIELDS) + + +class RefreshCollections(RefreshCollections): + def __init__(self, supported_data_queries) -> None: + super().__init__(supported_data_queries) + self.collection = namedtuple("collection", FIELDS) + + def _get_temporal_extent(self): + this_extent = True + if this_extent: + FIELDS.extend(["temporal_interval", "trs", "temporal_name"]) + SAMPLES["00001"].extend(["today", "TIMECRS", "Dummy temporal extent"]) + SAMPLES["00002"].extend(["today/tomorrow", "TIMECRS", "Dummy temporal extent"]) + self.temporal_extent = this_extent + + def _get_vertical_extent(self): + this_extent = True + if this_extent: + FIELDS.extend(["vertical_interval", "vrs", "vertical_name"]) + SAMPLES["00001"].extend([[2], "VERTCS", "Dummy vertical extent"]) + SAMPLES["00002"].extend([[2, 10], "VERTCS", "Dummy vertical extent"]) + self.vertical_extent = this_extent + + def get_parameters(self, collection_id): + param_names = PARAMS_LOOKUP[collection_id] + params = {} + for name in param_names: + param_metadata = PARAMS[name] + params[name] = param(name, *param_metadata) + return params + + def make_collection(self, name): + sample = SAMPLES[name] + return self.collection(*sample) + + def make_collections(self) -> List: + collections: List = [] + for name in SAMPLES.keys(): + collection = self.make_collection(name) + collections.append(collection) + return collections \ No newline at end of file