Skip to content

Commit

Permalink
chore: multiple products for a dataset in the mapping (#247)
Browse files Browse the repository at this point in the history
allow a dataset to be in several products (they are now comma separated in the mapping)
  • Loading branch information
renaudjester authored Dec 10, 2024
1 parent 38021d2 commit 2fc0b30
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions copernicusmarine/catalogue_parser/catalogue_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,34 @@ def get_dataset_metadata(
dataset_product_mapping_url = (
f"{root_url}/dataset_product_id_mapping.json"
)
product_id = connection.get_json_file(dataset_product_mapping_url).get(
dataset_id
)
if not product_id:
product_ids = connection.get_json_file(
dataset_product_mapping_url
).get(dataset_id)
if not product_ids:
raise DatasetNotFound(dataset_id)
url = f"{stac_url}/{product_id}/product.stac.json"
product_json = connection.get_json_file(url)
product_collection = pystac.Collection.from_dict(product_json)
product_datasets_metadata_links = product_collection.get_item_links()
datasets_metadata_links = [
dataset_metadata_link
for dataset_metadata_link in product_datasets_metadata_links
if dataset_id in dataset_metadata_link.href
]
if not datasets_metadata_links:
return None
dataset_jsons: list[dict] = [
connection.get_json_file(f"{stac_url}/{product_id}/{link.href}")
for link in datasets_metadata_links
]
dataset_jsons: list[dict] = []
for product_id in product_ids.split(","):
url = f"{stac_url}/{product_id}/product.stac.json"
product_json = connection.get_json_file(url)
product_collection = pystac.Collection.from_dict(product_json)
product_datasets_metadata_links = (
product_collection.get_item_links()
)
datasets_metadata_links = [
dataset_metadata_link
for dataset_metadata_link in product_datasets_metadata_links
if dataset_id in dataset_metadata_link.href
]
if not datasets_metadata_links:
continue
dataset_jsons.extend(
[
connection.get_json_file(
f"{stac_url}/{product_id}/{link.href}"
)
for link in datasets_metadata_links
]
)

dataset_items = [
dataset_item
Expand Down

0 comments on commit 2fc0b30

Please sign in to comment.