annotate ecv_retrieve.py @ 5:ee42b7a33dc7 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:58:04 +0000
parents b9d9fe0c2ce7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5c0ab9932311 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
5c0ab9932311 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)
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
3
5c0ab9932311 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
5c0ab9932311 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
5c0ab9932311 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
5c0ab9932311 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
5c0ab9932311 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
5c0ab9932311 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
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
10
5c0ab9932311 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
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
12
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
13
5c0ab9932311 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 ():
5c0ab9932311 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,
5c0ab9932311 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
ee42b7a33dc7 "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
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
18 ):
5c0ab9932311 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
5c0ab9932311 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
ee42b7a33dc7 "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
5c0ab9932311 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 == '':
5c0ab9932311 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'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
24 else:
5c0ab9932311 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
ee42b7a33dc7 "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:
ee42b7a33dc7 "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
5c0ab9932311 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
ee42b7a33dc7 "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
ee42b7a33dc7 "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
5c0ab9932311 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'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
32 else:
5c0ab9932311 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(',')
5c0ab9932311 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
ee42b7a33dc7 "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
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
36 else:
5c0ab9932311 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
ee42b7a33dc7 "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
b9d9fe0c2ce7 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'
b9d9fe0c2ce7 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:
b9d9fe0c2ce7 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
b9d9fe0c2ce7 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
5c0ab9932311 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 == '':
5c0ab9932311 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'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
45 else:
5c0ab9932311 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
5c0ab9932311 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 == '':
5c0ab9932311 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
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
49 else:
5c0ab9932311 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
ee42b7a33dc7 "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
5c0ab9932311 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:
5c0ab9932311 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)
5c0ab9932311 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)
5c0ab9932311 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)
5c0ab9932311 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)
5c0ab9932311 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()
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
58
5c0ab9932311 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):
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
60
5
ee42b7a33dc7 "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:
ee42b7a33dc7 "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)
ee42b7a33dc7 "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)
ee42b7a33dc7 "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)
ee42b7a33dc7 "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)
ee42b7a33dc7 "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')
ee42b7a33dc7 "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)
ee42b7a33dc7 "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)
ee42b7a33dc7 "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)
ee42b7a33dc7 "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)
ee42b7a33dc7 "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',
ee42b7a33dc7 "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)
ee42b7a33dc7 "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)
ee42b7a33dc7 "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:
ee42b7a33dc7 "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(
ee42b7a33dc7 "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, {
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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',
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
85 },
ee42b7a33dc7 "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)
ee42b7a33dc7 "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:
ee42b7a33dc7 "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(
ee42b7a33dc7 "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, {
ee42b7a33dc7 "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,
ee42b7a33dc7 "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':
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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',
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
98 },
ee42b7a33dc7 "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)
ee42b7a33dc7 "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:
ee42b7a33dc7 "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(
ee42b7a33dc7 "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, {
ee42b7a33dc7 "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,
ee42b7a33dc7 "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':
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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',
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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,
ee42b7a33dc7 "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
5c0ab9932311 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)
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
114
5c0ab9932311 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):
5c0ab9932311 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
5c0ab9932311 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:
5c0ab9932311 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)
5c0ab9932311 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'):
5c0ab9932311 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
5c0ab9932311 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()
5c0ab9932311 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'
5c0ab9932311 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)
5c0ab9932311 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()
5c0ab9932311 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')
5c0ab9932311 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)
5c0ab9932311 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()
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
128
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
129
5c0ab9932311 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__':
5c0ab9932311 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")
5c0ab9932311 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()
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
133
5c0ab9932311 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
5c0ab9932311 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']
5c0ab9932311 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 \
5c0ab9932311 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
ee42b7a33dc7 "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
5c0ab9932311 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:
5c0ab9932311 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
ee42b7a33dc7 "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
5c0ab9932311 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
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
143
5c0ab9932311 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(
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
145 'archive',
5c0ab9932311 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'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
147 )
5c0ab9932311 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(
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
149 'variable',
5c0ab9932311 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'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
151 )
5c0ab9932311 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(
5c0ab9932311 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',
5c0ab9932311 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)'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
155 )
5c0ab9932311 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(
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
157 '--year',
5c0ab9932311 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.'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
159 )
5c0ab9932311 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(
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
161 '--month',
5c0ab9932311 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.'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
163 )
5c0ab9932311 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(
5c0ab9932311 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',
5c0ab9932311 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).'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
167 )
5c0ab9932311 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(
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
169 '--area',
5c0ab9932311 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)'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
171 )
5c0ab9932311 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
ee42b7a33dc7 "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',
ee42b7a33dc7 "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)'
ee42b7a33dc7 "planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 9a008dba390aef21d4ab61240641bf455f5bb036"
climate
parents: 2
diff changeset
175 )
ee42b7a33dc7 "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
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
177 '--format',
5c0ab9932311 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)'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
179 )
5c0ab9932311 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(
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
181 '--output',
5c0ab9932311 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'
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
183 )
5c0ab9932311 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(
5c0ab9932311 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",
5c0ab9932311 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",
5c0ab9932311 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")
5c0ab9932311 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()
5c0ab9932311 planemo upload for repository https://github.com/NordicESMhub/galaxy-tools/tree/master/tools/essential_climate_variables commit 49926d09bb7d28f07b24050d25c40f2ae875d6f7
climate
parents:
diff changeset
189
5c0ab9932311 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,
5c0ab9932311 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
ee42b7a33dc7 "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
5c0ab9932311 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()
5c0ab9932311 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()
5c0ab9932311 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
5c0ab9932311 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:
5c0ab9932311 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'))