changeset 1:67a7303bc5c9 draft default tip

planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/cads commit 7cb1c1196b3e8998743e3b4b949290e95c5d3be1
author climate
date Fri, 06 Mar 2026 13:39:23 +0000
parents b768e517a7d0
children
files cads.sh cads.xml cads_retrieve.py test-data/req-timeseries.txt test-data/req.txt
diffstat 5 files changed, 99 insertions(+), 98 deletions(-) [+]
line wrap: on
line diff
--- a/cads.sh	Sat Jun 19 18:35:50 2021 +0000
+++ b/cads.sh	Fri Mar 06 13:39:23 2026 +0000
@@ -1,19 +1,19 @@
 #!/usr/bin/env bash
 
-if [ -f download.tar.gz ]; then
-   tar zxvf  download.tar.gz
+if [ -f *.tar.gz ]; then
+   tar zxvf  *.tar.gz
    cat *.grib > tmp.grib
    cdo setgridtype,regular tmp.grib tmpg.grib
    cdo -f nc -t ecmwf copy tmpg.grib tmp.nc
-elif [ -f download.zip ]; then
-   unzip download.zip
+elif [ -f *.zip ]; then
+   unzip *.zip
    cat *.grib > tmp.grib
    cdo setgridtype,regular tmp.grib tmpg.grib
    cdo -f nc -t ecmwf copy tmpg.grib tmp.nc
-elif [ -f download.grib ]; then
-   cdo -f nc -t ecmwf copy download.grib tmp.nc
-elif [ -f download.nc ]; then
-   mv download.nc tmp.nc
+elif [ -f *.grib ]; then
+   cdo -f nc -t ecmwf copy *.grib tmp.nc
+elif [ -f *.nc ]; then
+   mv *.nc tmp.nc
 else
    echo "No data found! Check your request and/or credentials."
 fi
--- a/cads.xml	Sat Jun 19 18:35:50 2021 +0000
+++ b/cads.xml	Fri Mar 06 13:39:23 2026 +0000
@@ -1,22 +1,30 @@
-<tool id="cads" name="Copernicus Atmosphere Data Store" version="0.1.0" profile="20.05">
+<tool id="cads" name="Copernicus Atmosphere Data Store" version="0.1.1" profile="25.1">
     <description>for retrieving data from the Atmosphere Monitoring Service</description>
+	<edam_topics>
+      <edam_topic>topic_3855</edam_topic>
+      <edam_topic>topic_3318</edam_topic>
+    </edam_topics>
+    <edam_operations>
+      <edam_operation>operation_2422</edam_operation>
+      <edam_operation>operation_3357</edam_operation>
+      <edam_operation>operation_0335</edam_operation>
+    </edam_operations>
     <requirements>
-        <requirement type="package" version="3">python</requirement>
-        <requirement type="package" version="0.5.1">cdsapi</requirement>
-        <requirement type="package" version="1.9.9">cdo</requirement>
+		<requirement type="package" version="3.8">python</requirement>
+		<requirement type="package" version="0.7.3">cdsapi</requirement>
+		<requirement type="package" version="2.4.4">cdo</requirement>
         <requirement type="package" version="1.34">tar</requirement>
         <requirement type="package" version="6.0">unzip</requirement>
+	    <credentials name="cads_apikey" version="1.0" label="CADS API key" description="Credential for accessing Copernicus atmosphere Data Store API.">
+            <secret name="key" inject_as_env="CADS_API_KEY" optional="false" label="CADS API key" description="Your Copernicus atmosphere Data Store API key."/>
+        </credentials>
     </requirements>
-    <command detect_errors="exit_code"><![CDATA[
+	<required_files>
+        <include path="cads_retrieve.py" />
+        <include path="cads.sh" />
+    </required_files>
+	<command detect_errors="exit_code"><![CDATA[
         export HOME=`pwd`  &&
-        #set $cads_apikey = $__user__.extra_preferences.get('cads_account|cads_apikey', "")
-        #if $cads_apikey == ''
-            echo 'Error. Set your CADS credentials via: User -> Preferences -> Manage Information'  &&
-            echo 'Will try to use tool adsapirc file (used for testing)' &&
-            cp '$__tool_directory__/adsapirc.cfg' .cdsapirc &&
-        #else
-            cp '$cads_key_file' .cdsapirc &&
-        #end if
 
         python3 '$__tool_directory__/cads_retrieve.py' 
         #if str($is_file.has_req).strip() == 'yes'
@@ -29,14 +37,9 @@
         echo "Data retrieval from Copernicus Atmosphere Data Store is done"
     ]]></command>
     <configfiles>
-        <configfile name="cads_key_file"><![CDATA[
-#set $cads_apikey = $__user__.extra_preferences.get('cads_account|cads_apikey', "")
-         url: https://ads.atmosphere.copernicus.eu/api/v2
-         key: $cads_apikey
-        ]]></configfile>
         <configfile name="req_from_paste"><![CDATA[
        #if str($is_file.has_req).strip() == 'no'
-$is_file.api_req_text
+			$is_file.api_req_text
        #end if
         ]]></configfile>
     </configfiles>
@@ -55,25 +58,27 @@
         </conditional>
     </inputs>
     <outputs>
-        <data name="request" format="txt" from_work_dir="request.txt"/>
-        <data name="ofilename" format="netcdf" from_work_dir="tmp.nc"/>
+        <data name="request" format="txt" from_work_dir="request.txt" label="Request"/>
+        <data name="filename" format="netcdf" from_work_dir="tmp.nc" label="Netcdf file"/>
     </outputs>
     <tests>
-        <test>
+        <test expect_failure="true">
             <conditional name="is_file">
                 <param name="has_req" value="yes" />
                 <param name="api_req_file" ftype="txt" value="req.txt" />
             </conditional>
-            <output name="request" value="req_out.txt" compare="sim_size" delta="10"/>
-            <output name="ofilename" ftype="netcdf" value="output.nc" compare="sim_size" delta="100"/>
+            <assert_stderr>
+                <has_text text="CADS retrieval failed, make sure you filled in your CADS API Key"/>
+            </assert_stderr>
         </test>
-        <test>
+        <test expect_failure="true">
             <conditional name="is_file">
                 <param name="has_req" value="yes" />
                 <param name="api_req_file" ftype="txt" value="req-timeseries.txt" />
             </conditional>
-            <output name="request" value="timeseries_out.txt" compare="sim_size" delta="10"/>
-            <output name="ofilename" ftype="netcdf" value="timeseries.nc" compare="sim_size" delta="100"/>
+            <assert_stderr>
+                <has_text text="CADS retrieval failed, make sure you filled in your CADS API Key"/>
+            </assert_stderr>
         </test>
     </tests>
     <help><![CDATA[
@@ -84,10 +89,10 @@
 This tool is a wrapper to retrieve data from the Copernicus Atmosphere Data Store.
 
 - It allows to retrieve data from the Copernicus Atmosphere Monitoring Service.
-- Any user willing to use this tool needs to `create a new account <https://ads.atmosphere.copernicus.eu/user/register?destination=/api-how-to|>`_.
-- Set your CADS API Key via: User -> Preferences -> Manage Information"
-- Documentation on where to get the CDS API key can be found `here <https://cds.climate.copernicus.eu/api-how-to>`_.
-- Compose your request directly on Copernicus Atmosphere Data Store and copy/paste it in the input field "Request" or save it in a file.
+- Any user willing to use this tool needs to `create a new account here <https://ads.atmosphere.copernicus.eu/>`_.
+- Set your CADS API Key in the credentials
+- Your CADS API key can be found `here <https://ads.atmosphere.copernicus.eu/profile>`_.
+- Compose your request directly on Copernicus Atmosphere Data Store and copy/paste it in the input field "Request" or save it in a file mor information on how to proceed in the `documentation <https://ads.atmosphere.copernicus.eu/user-guide>` .
 - Be aware that for being able to download dataset from ADS, users also need to agree to their term of use (Licence to use Copernicus Products) on the ADS website.
 
 License:
@@ -98,14 +103,6 @@
 that may be made of the Copernicus information or data it contains.
     ]]></help>
     <citations>
+	    <citation type="bibtex">@misc{CADS,author={Copernicus Atmosphere Data Store}}</citation>
     </citations>
-    <edam_topics>
-      <edam_topic>topic_3855</edam_topic>
-      <edam_topic>topic_3318</edam_topic>
-    </edam_topics>
-    <edam_operations>
-      <edam_operation>operation_2422</edam_operation>
-      <edam_operation>operation_3357</edam_operation>
-      <edam_operation>operation_0335</edam_operation>
-    </edam_operations>
 </tool>
--- a/cads_retrieve.py	Sat Jun 19 18:35:50 2021 +0000
+++ b/cads_retrieve.py	Fri Mar 06 13:39:23 2026 +0000
@@ -1,6 +1,7 @@
 import argparse
 import ast
-from os import environ, path
+import sys
+from os import environ
 
 import cdsapi
 
@@ -31,26 +32,35 @@
         req = req.replace(value, key)
 
 print("req = ", req)
-c3s_type = req.split('c.retrieve')[1].split('(')[1].split(',')[0].strip(' "\'\t\r\n')
 
-c3s_req = '{' + req.split('{', 1)[1].rsplit('}', 1)[0].replace('\n', '') + '}'
+c3s_type = req.split('dataset')[1].split('=')[1].split('\n')[0].strip(' "\'\t\r\n')
+c3s_req = '{' + req.split('request', 1)[1].split('{', 1)[1].rsplit('}', 1)[0].replace('\n', '') + '}'
 c3s_req_dict = ast.literal_eval(c3s_req)
 
-c3s_output = req.rsplit('}', 1)[1].split(',')[1].split(')')[0].strip(' "\'\t\r\n')
-
-with open(args.output, "w") as f:
-    f.write(f'dataset to retrieve: {c3s_type}\nrequest: {c3s_req}\noutput filename: {c3s_output}')
-
 print("start retrieving data...")
 
-cdapi_file = path.join(environ.get('HOME'), '.cdsapirc')
+api_key = environ.get("CADS_API_KEY")
 
-if path.isfile(cdapi_file):
-    c = cdsapi.Client()
+if not api_key:
+    sys.stderr.write(
+        "CADS retrieval failed, make sure you filled in your CADS API Key\n"
+    )
+    sys.exit(1)
 
-    c.retrieve(
-        c3s_type,
-        c3s_req_dict,
-        c3s_output)
+try:
+    c = cdsapi.Client(
+        url="https://ads.atmosphere.copernicus.eu/api",
+        key=api_key
+    )
+
+    result = c.retrieve(c3s_type, c3s_req_dict)
+    c3s_output = result.download()
 
     print("data retrieval successful")
+except Exception:
+    raise RuntimeError(
+        "CADS retrieval failed, make sure you filled in your CADS API Key"
+    )
+
+with open(args.output, "w") as f:
+    f.write(f'dataset to retrieve: {c3s_type}\nrequest: {c3s_req}\noutput filename: {c3s_output}')
--- a/test-data/req-timeseries.txt	Sat Jun 19 18:35:50 2021 +0000
+++ b/test-data/req-timeseries.txt	Fri Mar 06 13:39:23 2026 +0000
@@ -1,19 +1,15 @@
 import cdsapi
-  
-c = cdsapi.Client()
 
-c.retrieve(
-    'cams-solar-radiation-timeseries',
-    {
-        'sky_type': 'clear',
-        'location': {
-            'latitude': 60,
-            'longitude': 11,
-        },
-        'altitude': '-999.',
-        'date': '2021-06-17/2021-06-17',
-        'time_step': '15minute',
-        'time_reference': 'universal_time',
-        'format': 'netcdf',
-    },
-    'download.nc')
+dataset = "cams-solar-radiation-timeseries"
+request = {
+    "sky_type": "clear",
+    "location": {"longitude": 11, "latitude": 60},
+    "altitude": ["-999"],
+    "date": ["2026-03-04/2026-03-04"],
+    "time_step": "15minute",
+    "time_reference": "universal_time",
+    "data_format": "netcdf"
+}
+
+client = cdsapi.Client()
+client.retrieve(dataset, request).download()
--- a/test-data/req.txt	Sat Jun 19 18:35:50 2021 +0000
+++ b/test-data/req.txt	Fri Mar 06 13:39:23 2026 +0000
@@ -1,21 +1,19 @@
 import cdsapi
 
-c = cdsapi.Client()
+dataset = "cams-global-reanalysis-eac4"
+request = {
+    "variable": [
+        "total_column_carbon_monoxide",
+        "total_column_nitric_acid"
+    ],
+    "date": ["2025-08-01/2025-08-31"],
+    "time": [
+        "00:00", "03:00", "06:00",
+        "09:00", "12:00", "15:00",
+        "18:00", "21:00"
+    ],
+    "data_format": "grib"
+}
 
-c.retrieve(
-    'cams-europe-air-quality-forecasts',
-    {
-        'variable': 'nitrogen_dioxide',
-        'model': 'ensemble',
-        'level': '0',
-        'date': '2021-06-16/2021-06-16',
-        'type': 'analysis',
-        'time': '00:00',
-        'leadtime_hour': '0',
-        'format': 'netcdf',
-        'area': [
-            59.96, 10.66, 59.87,
-            10.9,
-        ],
-    },
-    'download.nc')
+client = cdsapi.Client()
+client.retrieve(dataset, request).download()