Skip to content

Commit

Permalink
get the licences from get_licences
Browse files Browse the repository at this point in the history
  • Loading branch information
garciampred committed Dec 9, 2024
1 parent 612c2b1 commit 19cc038
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions cads_adaptors/adaptors/cadsobs/adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ def _retrieve(self, request):
service_definition = cadsobs_client.get_service_definition(dataset_name)
field_attributes = cdm_lite_variables_dict["attributes"]
global_attributes = service_definition["global_attributes"]
# Get licences from the config passed to the adaptor
global_attributes.update(
dict(licence_list=self.get_licences(self.mapped_request))
)
self.context.debug(
f"The following objects are going to be filtered: {object_urls}"
)
Expand Down
15 changes: 9 additions & 6 deletions cads_adaptors/adaptors/cadsobs/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ def get_csv_header(
########################################################################################
# This file contains data retrieved from the CDS https://cds.climate.copernicus.eu/cdsapp#!/dataset/{dataset}
# This is a C3S product under the following licences:
# - licence-to-use-copernicus-products
# - woudc-data-policy
{licence_list}
# This is a CSV file following the CDS convention cdm-obs
# Data source: {dataset_source}
# Version:
# Time extent: {time_start} - {time_end}
# Geographic area (minlat/maxlat/minlon/maxlon): {area}
# Variables selected and units
# Variables selected and units:
{varstr}
# Uncertainty legend
# Uncertainty legend:
{uncertainty_str}
########################################################################################
"""
Expand Down Expand Up @@ -80,7 +78,7 @@ def get_csv_header(
varstr = "\n".join([f"# {v} [{u}]" for v, u in vars_and_units])
# Uncertainty documentation
uncertainty_vars = [
v for v in cdm_lite_dataset.data_vars if "uncertainty_value" in v
str(v) for v in cdm_lite_dataset.data_vars if "uncertainty_value" in str(v)
]
if len(uncertainty_vars) > 0:
unc_vars_and_names = [
Expand All @@ -89,6 +87,10 @@ def get_csv_header(
uncertainty_str = "\n".join([f"# {u} {n}" for u, n in unc_vars_and_names])
else:
uncertainty_str = "No uncertainty columns available for this dataset."
# List of licences
licence_list_str = "\n".join(
f"# {licence}" for licence in cdm_lite_dataset.attrs["licence_list"]
)
# Render the header
header_params = dict(
dataset=retrieve_args.dataset,
Expand All @@ -98,6 +100,7 @@ def get_csv_header(
time_end=time_end,
varstr=varstr,
uncertainty_str=uncertainty_str,
licence_list=licence_list_str,
)
header = template.format(**header_params)
return header
Expand Down
1 change: 1 addition & 0 deletions tests/test_cadsobs_adaptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def _send_request(self, endpoint, method, payload):
"rename": {"time_aggregation": "dataset_source", "variable": "variables"},
"force": {},
},
"licences": ["licence-to-use-copernicus-products", "uscrn-data-policy"],
}


Expand Down

0 comments on commit 19cc038

Please sign in to comment.