From 3d49c6c7bc2d2020c79946555f540ac7c9949e7a Mon Sep 17 00:00:00 2001 From: Lubomir Dolezal Date: Thu, 18 Jul 2024 13:29:19 +0200 Subject: [PATCH] prefix "eodash:" for client-only custom fields --- src/eodash_catalog/generate_indicators.py | 52 +++++++++++------------ src/eodash_catalog/stac_handling.py | 4 +- tests/test_generate.py | 4 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/eodash_catalog/generate_indicators.py b/src/eodash_catalog/generate_indicators.py index 405e18b..fd157a0 100644 --- a/src/eodash_catalog/generate_indicators.py +++ b/src/eodash_catalog/generate_indicators.py @@ -196,64 +196,64 @@ def process_collection_file( with open(file_path) as f: collection_config: dict = yaml.load(f, Loader=SafeLoader) if "Resources" in collection_config: - for resource in collection_config["Resources"]: + for endpoint_config in collection_config["Resources"]: collection = None - if resource["Name"] == "Sentinel Hub": + if endpoint_config["Name"] == "Sentinel Hub": collection = handle_SH_endpoint( - catalog_config, resource, collection_config, catalog, options + catalog_config, endpoint_config, collection_config, catalog, options ) - elif resource["Name"] == "Sentinel Hub WMS": + elif endpoint_config["Name"] == "Sentinel Hub WMS": collection = handle_SH_WMS_endpoint( - catalog_config, resource, collection_config, catalog + catalog_config, endpoint_config, collection_config, catalog ) - elif resource["Name"] == "GeoDB": + elif endpoint_config["Name"] == "GeoDB": collection = handle_GeoDB_endpoint( - catalog_config, resource, collection_config, catalog + catalog_config, endpoint_config, collection_config, catalog ) - elif resource["Name"] == "VEDA": + elif endpoint_config["Name"] == "VEDA": collection = handle_VEDA_endpoint( - catalog_config, resource, collection_config, catalog, options + catalog_config, endpoint_config, collection_config, catalog, options ) - elif resource["Name"] == "marinedatastore": + elif endpoint_config["Name"] == "marinedatastore": collection = handle_WMS_endpoint( - catalog_config, resource, collection_config, catalog, wmts=True + catalog_config, endpoint_config, collection_config, catalog, wmts=True ) - elif resource["Name"] == "xcube": + elif endpoint_config["Name"] == "xcube": collection = handle_xcube_endpoint( - catalog_config, resource, collection_config, catalog + catalog_config, endpoint_config, collection_config, catalog ) - elif resource["Name"] == "WMS": + elif endpoint_config["Name"] == "WMS": collection = handle_WMS_endpoint( - catalog_config, resource, collection_config, catalog + catalog_config, endpoint_config, collection_config, catalog ) - elif resource["Name"] == "JAXA_WMTS_PALSAR": + elif endpoint_config["Name"] == "JAXA_WMTS_PALSAR": # somewhat one off creation of individual WMTS layers as individual items collection = handle_WMS_endpoint( - catalog_config, resource, collection_config, catalog, wmts=True + catalog_config, endpoint_config, collection_config, catalog, wmts=True ) - elif resource["Name"] == "Collection-only": + elif endpoint_config["Name"] == "Collection-only": collection = handle_collection_only( - catalog_config, resource, collection_config, catalog + catalog_config, endpoint_config, collection_config, catalog ) - elif resource["Name"] == "Custom-Endpoint": + elif endpoint_config["Name"] == "Custom-Endpoint": collection = handle_custom_endpoint( catalog_config, - resource, + endpoint_config, collection_config, catalog, ) - elif resource["Name"] in ["COG source", "GeoJSON source"]: + elif endpoint_config["Name"] in ["COG source", "GeoJSON source"]: collection = handle_raw_source( - catalog_config, resource, collection_config, catalog + catalog_config, endpoint_config, collection_config, catalog ) else: raise ValueError("Type of Resource is not supported") if collection: add_single_item_if_collection_empty(collection) - add_projection_info(resource, collection) - add_to_catalog(collection, catalog, resource, collection_config) + add_projection_info(endpoint_config, collection) + add_to_catalog(collection, catalog, endpoint_config, collection_config) else: - raise Exception(f"No collection was generated for resource {resource}") + raise Exception(f"No collection was generated for resource {endpoint_config}") elif "Subcollections" in collection_config: # if no endpoint is specified we check for definition of subcollections parent_collection = get_or_create_collection( diff --git a/src/eodash_catalog/stac_handling.py b/src/eodash_catalog/stac_handling.py index 5f558e8..02470ca 100644 --- a/src/eodash_catalog/stac_handling.py +++ b/src/eodash_catalog/stac_handling.py @@ -379,7 +379,7 @@ def add_extra_fields(stac_object: Collection | Catalog | Link, collection_config if "Other" in collection_config["DataSource"]: stac_object.extra_fields["otherSources"] = collection_config["DataSource"]["Other"] if "MapProjection" in collection_config: - stac_object.extra_fields["mapProjection"] = collection_config["MapProjection"] + stac_object.extra_fields["eodash:mapProjection"] = collection_config["MapProjection"] def get_collection_times_from_config(endpoint_config: dict) -> list[str]: @@ -416,6 +416,6 @@ def add_projection_info( # so we are taking over the DataProjection as is and deal with it in the eodash client # in a non-standard compliant way # https://github.com/proj4js/proj4js/issues/400 - stac_object.extra_fields["proj4_def"] = proj + stac_object.extra_fields["eodash:proj4_def"] = proj else: raise Exception(f"Incorrect type of proj definition {proj}") diff --git a/tests/test_generate.py b/tests/test_generate.py index 247627a..e371af7 100644 --- a/tests/test_generate.py +++ b/tests/test_generate.py @@ -100,7 +100,7 @@ def test_indicator_map_projection_added(catalog_output_folder): with open(os.path.join(root_collection_path, "collection.json")) as fp: indicator_json = json.load(fp) # test that collection has map projection defined - assert indicator_json["mapProjection"] == 3035 + assert indicator_json["eodash:mapProjection"] == 3035 def test_baselayers_and_overlays_added(catalog_output_folder): @@ -184,4 +184,4 @@ def test_baselayer_with_custom_projection_added(catalog_output_folder): # overwrites default_baselayers, so there is just 1 assert len(baselayer_links) == 1 # test that custom proj4 definition is added to link - assert baselayer_links[0]["proj4_def"]["name"] == "ORTHO:680500" + assert baselayer_links[0]["eodash:proj4_def"]["name"] == "ORTHO:680500"