annotate ecv_retrieve.py @ 5:a781bdaaa30e draft default tip

"planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
author climate
date Tue, 08 Jun 2021 08:57:38 +0000
parents f47873f1a4b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
1 # Retrieve Copernicus ECV
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
2 # (Essential climate Variables)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
3
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
4 import argparse
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
5 import os
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
6 import shutil
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
7 import tarfile
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
8 import tempfile
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
9 import warnings
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
10
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
11 import cdsapi
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
12
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
13
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
14 class ECV ():
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
15 def __init__(self, archive, variable, product_type, year,
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
16 month, time_aggregation, area, format, output,
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
17 climate_reference_period=None, verbose=False
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
18 ):
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
19 self.archive = archive
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
20 self.variable = variable.split(',')
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
21 self.climate_reference_period = climate_reference_period
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
22 if product_type == '':
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
23 self.product_type = 'climatology'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
24 else:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
25 self.product_type = product_type
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
26 if year != '' and year is not None:
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
27 self.year = year.split(',')
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
28 else:
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
29 self.year = None
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
30 if month == '' or month is None:
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
31 self.month = '01'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
32 else:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
33 self.month = month.split(',')
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
34 if time_aggregation == '':
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
35 self.time_aggregation = '1_month_mean'
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
36 else:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
37 self.time_aggregation = time_aggregation
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
38 if area == '' or area is None:
2
f47873f1a4b3 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 6045302c39c9c11fb6a73966a364cc395f2f9b28
climate
parents: 0
diff changeset
39 self.area = 'global'
f47873f1a4b3 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 6045302c39c9c11fb6a73966a364cc395f2f9b28
climate
parents: 0
diff changeset
40 else:
f47873f1a4b3 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 6045302c39c9c11fb6a73966a364cc395f2f9b28
climate
parents: 0
diff changeset
41 self.area = area
f47873f1a4b3 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 6045302c39c9c11fb6a73966a364cc395f2f9b28
climate
parents: 0
diff changeset
42
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
43 if format == '':
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
44 self.format = 'tgz'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
45 else:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
46 self.format = format
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
47 if output == '':
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
48 self.outputfile = "donwload." + self.format
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
49 else:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
50 self.outputfile = output
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
51 self.verbose = verbose
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
52 if verbose:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
53 print("archive: ", self.archive)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
54 print("variable: ", self.variable)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
55 print("year: ", self.year)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
56 print("month: ", self.month)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
57 self.cdsapi = cdsapi.Client()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
58
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
59 def retrieve(self):
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
60
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
61 if self.verbose:
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
62 print(self.archive)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
63 print('variable', self.variable)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
64 print('year', self.year)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
65 print('month', self.month)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
66 print('origin', 'era5')
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
67 print('area', self.area)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
68 print('format', self.format)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
69 print('product_type', self.product_type)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
70 print('time_aggregation', self.time_aggregation)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
71 print('climate_reference_period',
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
72 self.climate_reference_period)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
73 print(self.outputfile)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
74 if self.climate_reference_period is None:
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
75 self.cdsapi.retrieve(
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
76 self.archive, {
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
77 'variable': self.variable,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
78 'year': self.year,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
79 'month': self.month,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
80 'origin': 'era5',
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
81 'area': self.area,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
82 'format': self.format,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
83 'product_type': self.product_type,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
84 'time_aggregation': self.time_aggregation,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
85 },
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
86 self.outputfile)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
87 elif self.year is None:
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
88 self.cdsapi.retrieve(
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
89 self.archive, {
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
90 'variable': self.variable,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
91 'climate_reference_period':
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
92 self.climate_reference_period,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
93 'month': self.month,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
94 'origin': 'era5',
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
95 'format': self.format,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
96 'product_type': self.product_type,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
97 'time_aggregation': self.time_aggregation,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
98 },
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
99 self.outputfile)
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
100 else:
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
101 self.cdsapi.retrieve(
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
102 self.archive, {
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
103 'variable': self.variable,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
104 'climate_reference_period':
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
105 self.climate_reference_period,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
106 'year': self.year,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
107 'month': self.month,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
108 'origin': 'era5',
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
109 'format': self.format,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
110 'product_type': self.product_type,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
111 'time_aggregation': self.time_aggregation,
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
112 },
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
113 self.outputfile)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
114
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
115 def checktar(self):
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
116 is_grib = False
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
117 with open(self.outputfile, 'rb') as ofile:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
118 is_grib = ofile.read(4)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
119 if (is_grib == b'GRIB' and self.format == 'tgz'):
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
120 # we create a tgz to be consistent
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
121 newfilename = tempfile.NamedTemporaryFile()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
122 gribfile = os.path.basename(newfilename.name) + '.grib'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
123 shutil.copyfile(self.outputfile, gribfile)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
124 newfilename.close()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
125 tar = tarfile.open(self.outputfile, 'w:gz')
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
126 tar.add(gribfile)
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
127 tar.close()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
128
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
129
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
130 if __name__ == '__main__':
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
131 warnings.filterwarnings("ignore")
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
132 parser = argparse.ArgumentParser()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
133
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
134 remove_apikey = False
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
135 current_pwd = os.environ['HOME']
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
136 if 'GALAXY_COPERNICUS_CDSAPIRC_KEY' in os.environ and \
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
137 not os.path.isfile('.cdsapirc'):
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
138 print('GALAXY_COPERNICUS_CDSAPIRC_KEY ')
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
139 with open(".cdsapirc", "w+") as apikey:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
140 apikey.write("url: https://cds.climate.copernicus.eu/api/v2\n")
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
141 apikey.write("key: " + os.environ['GALAXY_COPERNICUS_CDSAPIRC_KEY'])
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
142 remove_apikey = True
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
143
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
144 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
145 'archive',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
146 help='Archive name'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
147 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
148 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
149 'variable',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
150 help='Specify which variable to retrieve'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
151 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
152 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
153 '--product_type',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
154 help='Type of product (climatology or anomaly)'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
155 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
156 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
157 '--year',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
158 help='Year(s) to retrieve.'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
159 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
160 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
161 '--month',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
162 help='List of months to retrieve.'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
163 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
164 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
165 '--time_aggregation',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
166 help='Time range over which data is aggregated (monthly/yearly).'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
167 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
168 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
169 '--area',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
170 help='Desired sub-area to extract (North/West/South/East)'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
171 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
172 parser.add_argument(
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
173 '--climate_reference_period',
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
174 help='Climate reference period (default is 1981-2010)'
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
175 )
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
176 parser.add_argument(
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
177 '--format',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
178 help='Output file format (GRIB or netCDF or tgz)'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
179 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
180 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
181 '--output',
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
182 help='output filename'
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
183 )
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
184 parser.add_argument(
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
185 "-v", "--verbose",
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
186 help="switch on verbose mode",
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
187 action="store_true")
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
188 args = parser.parse_args()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
189
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
190 p = ECV(args.archive, args.variable, args.product_type,
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
191 args.year, args.month, args.time_aggregation, args.area,
5
a781bdaaa30e "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
192 args.format, args.output, args.climate_reference_period, args.verbose)
0
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
193 p.retrieve()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
194 p.checktar()
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
195 # remove api key file if it was created
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
196 if remove_apikey and os.getcwd() == current_pwd:
edc85cde5f71 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
197 os.remove(os.path.join(current_pwd, '.cdsapirc'))