Repository 'cds_essential_variability'
hg clone https://toolshed.g2.bx.psu.edu/repos/climate/cds_essential_variability

Changeset 5:ee42b7a33dc7 (2021-06-08)
Previous changeset 4:9ee8db6ffba3 (2019-07-07)
Commit message:
"planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
modified:
ecv_retrieve.py
essential_climate_variables.xml
b
diff -r 9ee8db6ffba3 -r ee42b7a33dc7 ecv_retrieve.py
--- a/ecv_retrieve.py Sun Jul 07 10:06:53 2019 -0400
+++ b/ecv_retrieve.py Tue Jun 08 08:58:04 2021 +0000
[
@@ -14,27 +14,28 @@
 class ECV ():
     def __init__(self, archive, variable, product_type, year,
                  month, time_aggregation, area, format, output,
-                 verbose=False
+                 climate_reference_period=None, verbose=False
                  ):
         self.archive = archive
         self.variable = variable.split(',')
+        self.climate_reference_period = climate_reference_period
         if product_type == '':
             self.product_type = 'climatology'
         else:
             self.product_type = product_type
-        if year == '':
-            self.year = '2019'
+        if year != '' and year is not None:
+            self.year = year.split(',')
         else:
-            self.year = year.split(',')
-        if month == '':
+            self.year = None
+        if month == '' or month is None:
             self.month = '01'
         else:
             self.month = month.split(',')
         if time_aggregation == '':
-            self.time_aggregation = '1_month'
+            self.time_aggregation = '1_month_mean'
         else:
             self.time_aggregation = time_aggregation
-        if area == '':
+        if area == '' or area is None:
             self.area = 'global'
         else:
             self.area = area
@@ -47,6 +48,7 @@
             self.outputfile = "donwload." + self.format
         else:
             self.outputfile = output
+        self.verbose = verbose
         if verbose:
             print("archive: ", self.archive)
             print("variable: ", self.variable)
@@ -56,17 +58,58 @@
 
     def retrieve(self):
 
-        self.cdsapi.retrieve(
-            self.archive, {
-                'variable': self.variable,
-                'year': self.year,
-                'month': self.month,
-                'origin': 'era5',
-                'area': self.area,
-                'format': self.format,
-                'product_type': self.product_type,
-                'time_aggregation': self.time_aggregation,
-                          },
+        if self.verbose:
+            print(self.archive)
+            print('variable', self.variable)
+            print('year', self.year)
+            print('month', self.month)
+            print('origin', 'era5')
+            print('area', self.area)
+            print('format', self.format)
+            print('product_type', self.product_type)
+            print('time_aggregation', self.time_aggregation)
+            print('climate_reference_period',
+                  self.climate_reference_period)
+            print(self.outputfile)
+        if self.climate_reference_period is None:
+            self.cdsapi.retrieve(
+                self.archive, {
+                    'variable': self.variable,
+                    'year': self.year,
+                    'month': self.month,
+                    'origin': 'era5',
+                    'area': self.area,
+                    'format': self.format,
+                    'product_type': self.product_type,
+                    'time_aggregation': self.time_aggregation,
+                },
+                self.outputfile)
+        elif self.year is None:
+            self.cdsapi.retrieve(
+                self.archive, {
+                    'variable': self.variable,
+                    'climate_reference_period':
+                    self.climate_reference_period,
+                    'month': self.month,
+                    'origin': 'era5',
+                    'format': self.format,
+                    'product_type': self.product_type,
+                    'time_aggregation': self.time_aggregation,
+                },
+                self.outputfile)
+        else:
+            self.cdsapi.retrieve(
+                self.archive, {
+                    'variable': self.variable,
+                    'climate_reference_period':
+                    self.climate_reference_period,
+                    'year': self.year,
+                    'month': self.month,
+                    'origin': 'era5',
+                    'format': self.format,
+                    'product_type': self.product_type,
+                    'time_aggregation': self.time_aggregation,
+                },
                 self.outputfile)
 
     def checktar(self):
@@ -92,10 +135,10 @@
     current_pwd = os.environ['HOME']
     if 'GALAXY_COPERNICUS_CDSAPIRC_KEY' in os.environ and \
        not os.path.isfile('.cdsapirc'):
+        print('GALAXY_COPERNICUS_CDSAPIRC_KEY ')
         with open(".cdsapirc", "w+") as apikey:
             apikey.write("url: https://cds.climate.copernicus.eu/api/v2\n")
-            apikey.write(
-                  "key: " + os.environ['GALAXY_COPERNICUS_CDSAPIRC_KEY'])
+            apikey.write("key: " + os.environ['GALAXY_COPERNICUS_CDSAPIRC_KEY'])
             remove_apikey = True
 
     parser.add_argument(
@@ -127,6 +170,10 @@
         help='Desired sub-area to extract (North/West/South/East)'
     )
     parser.add_argument(
+        '--climate_reference_period',
+        help='Climate reference period (default is 1981-2010)'
+    )
+    parser.add_argument(
         '--format',
         help='Output file format (GRIB or netCDF or tgz)'
     )
@@ -142,7 +189,7 @@
 
     p = ECV(args.archive, args.variable, args.product_type,
             args.year, args.month, args.time_aggregation, args.area,
-            args.format, args.output, args.verbose)
+            args.format, args.output, args.climate_reference_period, args.verbose)
     p.retrieve()
     p.checktar()
     # remove api key file if it was created
b
diff -r 9ee8db6ffba3 -r ee42b7a33dc7 essential_climate_variables.xml
--- a/essential_climate_variables.xml Sun Jul 07 10:06:53 2019 -0400
+++ b/essential_climate_variables.xml Tue Jun 08 08:58:04 2021 +0000
[
@@ -1,25 +1,33 @@
-<tool id="cds_essential_variability" name="Copernicus Essential Climate Variables" version="0.1.4">
+<tool id="cds_essential_variability" name="Copernicus Essential Climate Variables" version="0.2.0" profile="20.05">
     <description>for assessing climate variability</description>
     <requirements>
         <requirement type="package" version="3">python</requirement>
-        <requirement type="package" version="0.1.4">cdsapi</requirement>
-        <requirement type="package" version="1.9.6">cdo</requirement>
+        <requirement type="package" version="0.5.1">cdsapi</requirement>
+        <requirement type="package" version="1.9.10">cdo</requirement>
     </requirements>
     <command detect_errors="exit_code"><![CDATA[
-       HOME=`pwd`  &&
-       cp \$COPERNICUS_CDSAPIRC_KEY_FILE .cdsapirc | true &&
+       export HOME=`pwd` &&
+       #set $cdsapirc_file = os.environ.get('COPERNICUS_CDSAPIRC_KEY_FILE', '')
+       #if os.path.isfile(str($cdsapirc_file))
+           echo "xx $cdsapirc_file xx" &&
+           cp $cdsapirc_file .cdsapirc &&
+       #else
+           echo 'use tool cdsapirc file' &&
+           cp '$__tool_directory__/cdsapirc.cfg' .cdsapirc &&
+       #end if
        python3 '$__tool_directory__/ecv_retrieve.py'
             'ecv-for-climate-change' '$variable'
             --month '$month'
         #if str($product_type.product) == 'monthly_mean'
             --year '$product_type.year'
-            --time_aggregation '1_month'
+            --time_aggregation '1_month_mean'
         #else if str($product_type.product) == 'anomaly'
+            --climate_reference_period $product_type.climate_reference_period
             --time_aggregation '$product_type.selector'
             --year '$product_type.year'
         #else
-            --year '2018'
-           --time_aggregation '1_month'
+            --climate_reference_period $product_type.climate_reference_period
+           --time_aggregation '1_month_mean'
         #end if
            --product_type '$product_type.product'
            --format 'tgz' --output 'tmp.tgz'
@@ -43,6 +51,12 @@
                 <option value="climatology">Climatology</option>
                 <option value="anomaly">Anomaly</option>
             </param>
+            <when value="climatology">
+                <param name="climate_reference_period" type="select" multiple="false"  label="Select Climate reference period">
+                    <option value="1981_2010" selected="true">1981-2010</option>
+                    <option value="1991_2020">1991-2020</option>
+                </param>
+            </when>
             <when value="monthly_mean">
                 <param name="year" type="select" multiple="true"  label="Select year(s)">
                     <option value="1979">1979</option>
@@ -85,10 +99,15 @@
                     <option value="2016">2016</option>
                     <option value="2017">2017</option>
                     <option value="2018">2018</option>
-                    <option value="2019" selected="true">2019</option>
+                    <option value="2019">2019</option>
+                    <option value="2020" selected="true">2020</option>
                 </param>
             </when>
             <when value="anomaly">
+                <param name="climate_reference_period" type="select" multiple="false"  label="Select Climate reference period">
+                    <option value="1981_2010" selected="true">1981-2010</option>
+                    <option value="1991_2020">1991-2020</option>
+                </param>
                 <param name="year" type="select" multiple="true"  label="Select year(s)">
                     <option value="1979">1979</option>
                     <option value="1980">1980</option>
@@ -129,11 +148,13 @@
                     <option value="2015">2015</option>
                     <option value="2016">2016</option>
                     <option value="2017">2017</option>
-                    <option value="2018" selected="true">2018</option>
+                    <option value="2018">2018</option>
+                    <option value="2019">2019</option>
+                    <option value="2020" selected="true">2020</option>
                 </param>
                 <param name="selector" type="select" label="Time aggregation">
-                    <option value="12_month" selected="true">yearly</option>
-                    <option value="1_month">monthly</option>
+                    <option value="12_month_running_mean" selected="true">yearly</option>
+                    <option value="1_month_mean">monthly</option>
                 </param>
             </when>
         </conditional>
@@ -205,7 +226,7 @@
 the corresponding anomalies.
 
 
-- ECV Factsheets: https://gcos.wmo.int/en/essential-climate-variables/ecv-factsheets
+- ECV: https://gcos.wmo.int/en/essential-climate-variables
 - Copernicus Climate Data Store documentation on Essential Climate Variables:
   https://cds.climate.copernicus.eu/cdsapp#!/dataset/ecv-for-climate-change?tab=overview
 
@@ -229,4 +250,13 @@
         <citation type="doi">10.1002/qj.828</citation>
         <citation type="doi">10.1002/qj.2949</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>