1 | ### Wrapper for all gcm utilities. |
---|
2 | ### |
---|
3 | ### A. Colaitis -- LMD -- 08/11/2011 <-- Added ZRECAST for altitude mode, and MCS and TES modes for Pressure |
---|
4 | ### A. Colaitis -- LMD -- 08/11/2011 <-- Added HRECAST for MCS and TES predefined grids |
---|
5 | ### Added wrapper to streamfunction.e |
---|
6 | ### Added wrapper to localtime.e |
---|
7 | |
---|
8 | def call_zrecast ( interp_mode = '4', \ |
---|
9 | input_name = None, \ |
---|
10 | fields = 'all', \ |
---|
11 | limites = None, \ |
---|
12 | predefined = None, \ |
---|
13 | verbose = True): |
---|
14 | |
---|
15 | import numpy as np |
---|
16 | from myplot import separatenames |
---|
17 | from os import system |
---|
18 | pressure_axis_tes=[1658.152,1291.37,1005.72,783.2555,610.,475.0685,369.9837,288.1436,224.4065,174.7679,136.1094,106.0021,82.55452,64.29353,50.07185,38.99599,30.37011,23.65227,18.4204,14.34583,11.17254] |
---|
19 | pressure_axis_mcs=[1878.9, 1658.2, 1463.3, 1291.4, 1139.6, 1005.7, 887.54, 783.26,691.22, 610., 538.32, 475.07, 419.25, 369.98, 326.51, 288.14, 254.29,224.41, 198.04, 174.77, 154.23, 136.11, 120.12, 106., 93.547, 82.555,72.854, 64.294, 56.739, 50.072, 44.188, 38.996, 34.414, 30.37, 26.802,23.652, 20.873, 18.42, 16.256, 14.346, 12.66, 11.173, 9.8597, 8.7012,7.6788, 6.7765, 5.9802, 5.2775, 4.6574, 4.1101, 3.6272, 3.201, 2.8249,2.4929, 2.2, 1.9415, 1.7134, 1.512, 1.3344, 1.1776, 1.0392, 0.9171,0.80934, 0.71424, 0.63031, 0.55625, 0.49089, 0.43321, 0.3823, 0.33738,0.29774, 0.26275, 0.23188, 0.20463, 0.18059, 0.15937, 0.14064, 0.12412,0.10953, 0.096661, 0.085303, 0.07528, 0.066434, 0.058628, 0.051739,0.04566, 0.040294, 0.03556, 0.031381, 0.027694, 0.02444, 0.021568,0.019034, 0.016797, 0.014824, 0.013082, 0.011545, 0.010188, 0.0089909,0.0079345, 0.0070021, 0.0061794, 0.0054533, 0.0048125, 0.004247] |
---|
20 | system("rm -f zrecast.auto.def") |
---|
21 | system("touch zrecast.auto.def") |
---|
22 | indicefile=0 |
---|
23 | outputfilename="" |
---|
24 | |
---|
25 | for zfile in input_name: |
---|
26 | f = open('zrecast.auto.def', 'w') |
---|
27 | f.write(zfile+"\n") |
---|
28 | for zvar in fields: |
---|
29 | f.write(zvar+"\n") |
---|
30 | f.write("\n") |
---|
31 | if interp_mode == 4: |
---|
32 | append="_S" |
---|
33 | f.write("3"+"\n") |
---|
34 | f.write("yes"+"\n") |
---|
35 | f.write("0 150000"+"\n") |
---|
36 | elif interp_mode == 2: |
---|
37 | append="_P" |
---|
38 | if predefined in ["TES","tes"]: |
---|
39 | print "Using TES pressure levels" |
---|
40 | f.write("1"+"\n") |
---|
41 | f.write("no"+"\n") |
---|
42 | f.write(str(len(pressure_axis_tes))+"\n") |
---|
43 | for zp in pressure_axis_tes: |
---|
44 | f.write(str(zp)+"\n") |
---|
45 | f.write("\n") |
---|
46 | elif predefined in ["MCS","mcs"]: |
---|
47 | print "Using MCS pressure levels" |
---|
48 | f.write("1"+"\n") |
---|
49 | f.write("no"+"\n") |
---|
50 | f.write(str(len(pressure_axis_mcs))+"\n") |
---|
51 | for zp in pressure_axis_mcs: |
---|
52 | f.write(str(zp)+"\n") |
---|
53 | f.write("\n") |
---|
54 | else: |
---|
55 | f.write("1"+"\n") |
---|
56 | f.write("yes"+"\n") |
---|
57 | if limites[0] != -9999.: f.write(str(limites[0])+" "+str(limites[-1])+"\n") |
---|
58 | else: f.write("370 0.1"+"\n") |
---|
59 | #f.write("1000000 100"+"\n") |
---|
60 | f.write("20"+"\n") |
---|
61 | else: |
---|
62 | print "zrecast interp option unsupported for now. Exiting." |
---|
63 | exit() |
---|
64 | f.close() |
---|
65 | if verbose: |
---|
66 | system("zrecast.e < zrecast.auto.def") |
---|
67 | else: |
---|
68 | system("zrecast.e < zrecast.auto.def > /dev/null") |
---|
69 | |
---|
70 | if indicefile is 0: |
---|
71 | outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc" |
---|
72 | else: |
---|
73 | outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc" |
---|
74 | indicefile = indicefile +1 |
---|
75 | |
---|
76 | for i in range(len(outputfilename)): |
---|
77 | output_name = separatenames(outputfilename) |
---|
78 | |
---|
79 | return output_name |
---|
80 | |
---|
81 | def call_hrecast ( input_name = None, \ |
---|
82 | fields = 'all', \ |
---|
83 | predefined = None,\ |
---|
84 | verbose = True): |
---|
85 | |
---|
86 | import numpy as np |
---|
87 | from myplot import separatenames |
---|
88 | from os import system |
---|
89 | # Beware that latitude axis in mcs and tes files is reversed |
---|
90 | # When comparing to MCS or TES data, one has to reverse the latitude axis and data along latitude axis. |
---|
91 | # This is for exemple automatically done in mcs.py. |
---|
92 | # This could also be done in a future tes.py. |
---|
93 | latitudes_reversed_tes_mcs=[88.5, 85.5, 82.5, 79.5, 76.5, 73.5, 70.5, 67.5, 64.5, 61.5, 58.5, 55.5, 52.5, 49.5, 46.5, 43.5, 40.5, 37.5, 34.5, 31.5, 28.5, 25.5, 22.5, 19.5, 16.5, 13.5, 10.5, 7.5, 4.5, 1.5, -1.5, -4.5, -7.5, -10.5, -13.5, -16.5, -19.5, -22.5, -25.5, -28.5, -31.5, -34.5, -37.5, -40.5, -43.5, -46.5, -49.5, -52.5, -55.5, -58.5, -61.5, -64.5, -67.5, -70.5, -73.5, -76.5, -79.5, -82.5, -85.5, -88.5] |
---|
94 | longitudes_tes_mcs=[-176.25, -168.75, -161.25, -153.75, -146.25, -138.75, -131.25,-123.75, -116.25, -108.75, -101.25, -93.75, -86.25, -78.75, -71.25, -63.75, -56.25, -48.75, -41.25, -33.75, -26.25, -18.75, -11.25, -3.75, 3.75, 11.25, 18.75, 26.25, 33.75, 41.25, 48.75, 56.25, 63.75, 71.25, 78.75, 86.25, 93.75, 101.25, 108.75, 116.25, 123.75, 131.25, 138.75, 146.25, 153.75, 161.25, 168.75, 176.25] |
---|
95 | system("rm -f hrecast.auto.def") |
---|
96 | system("touch hrecast.auto.def") |
---|
97 | indicefile=0 |
---|
98 | outputfilename="" |
---|
99 | append="_h" |
---|
100 | f = open('hrecast.auto.def', 'w') |
---|
101 | for zfile in input_name: |
---|
102 | f.write(zfile+"\n") |
---|
103 | for zvar in fields: |
---|
104 | f.write(zvar+"\n") |
---|
105 | f.write("\n") |
---|
106 | if predefined in ["MCS","mcs","TES","tes"]: |
---|
107 | f.write(str(len(longitudes_tes_mcs))+"\n") |
---|
108 | for lon in longitudes_tes_mcs: |
---|
109 | f.write(str(lon)+"\n") |
---|
110 | f.write(str(len(latitudes_reversed_tes_mcs))+"\n") |
---|
111 | for lat in latitudes_reversed_tes_mcs: |
---|
112 | f.write(str(lat)+"\n") |
---|
113 | f.close() |
---|
114 | if verbose: |
---|
115 | system("hrecast.e < hrecast.auto.def") |
---|
116 | else: |
---|
117 | system("hrecast.e < hrecast.auto.def > /dev/null") |
---|
118 | |
---|
119 | if indicefile is 0: |
---|
120 | outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc" |
---|
121 | else: |
---|
122 | outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc" |
---|
123 | indicefile = indicefile +1 |
---|
124 | |
---|
125 | for i in range(len(outputfilename)): |
---|
126 | output_name = separatenames(outputfilename) |
---|
127 | |
---|
128 | return output_name |
---|
129 | |
---|
130 | def call_localtime (input_name = None, \ |
---|
131 | fields = 'all', \ |
---|
132 | times = None, \ |
---|
133 | verbose = True): |
---|
134 | |
---|
135 | import numpy as np |
---|
136 | from myplot import separatenames |
---|
137 | from os import system |
---|
138 | system("rm -f localtime.auto.def") |
---|
139 | system("touch localtime.auto.def") |
---|
140 | outputfilename="" |
---|
141 | append="_LT" |
---|
142 | output_name = [] |
---|
143 | #print input_name |
---|
144 | for zfile in input_name: |
---|
145 | print 'LOCALTIME FOR FILE: '+zfile |
---|
146 | f = open('localtime.auto.def', 'w') |
---|
147 | #print zfile |
---|
148 | f.write(zfile+"\n") |
---|
149 | for zvar in fields: |
---|
150 | f.write(zvar+"\n") |
---|
151 | f.write("\n") |
---|
152 | f.write(str(len(times))+"\n") |
---|
153 | for t in times: |
---|
154 | f.write(str(t)+"\n") |
---|
155 | f.close() |
---|
156 | if verbose: |
---|
157 | system("localtime.e < localtime.auto.def") |
---|
158 | else: |
---|
159 | system("localtime.e < localtime.auto.def > /dev/null ") |
---|
160 | #print input_name |
---|
161 | zeoutput_name = zfile.replace('.nc','_LT'+str(times[0])+'.nc') |
---|
162 | |
---|
163 | system("mv -f "+zfile.replace('.nc','_LT.nc')+" "+zeoutput_name) |
---|
164 | |
---|
165 | output_name = np.append(output_name,zeoutput_name) |
---|
166 | |
---|
167 | return output_name |
---|
168 | |
---|
169 | |
---|
170 | def call_streamfunction ( input_name = None): |
---|
171 | import numpy as np |
---|
172 | from myplot import separatenames |
---|
173 | from os import system |
---|
174 | system("rm -f streamfunction.auto.def") |
---|
175 | system("touch streamfunction.auto.def") |
---|
176 | indicefile=0 |
---|
177 | outputfilename="" |
---|
178 | append="_stream" |
---|
179 | f = open('streamfunction.auto.def', 'w') |
---|
180 | for zfile in input_name: |
---|
181 | f.write(zfile+"\n") |
---|
182 | f.close() |
---|
183 | system("streamfunction.e < streamfunction.auto.def") |
---|
184 | |
---|
185 | if indicefile is 0: |
---|
186 | outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc" |
---|
187 | else: |
---|
188 | outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc" |
---|
189 | indicefile = indicefile +1 |
---|
190 | |
---|
191 | for i in range(len(outputfilename)): |
---|
192 | output_name = separatenames(outputfilename) |
---|
193 | |
---|
194 | return output_name |
---|
195 | |
---|
196 | |
---|
197 | def call_concat ( input_name = None, \ |
---|
198 | fields = 'all', \ |
---|
199 | begin = 0, \ |
---|
200 | verbose = True): |
---|
201 | |
---|
202 | import numpy as np |
---|
203 | from os import system |
---|
204 | system("rm -f concatnc.auto.def") |
---|
205 | system("touch concatnc.auto.def") |
---|
206 | |
---|
207 | f = open('concatnc.auto.def', 'w') |
---|
208 | for zfile in input_name: |
---|
209 | f.write(zfile+"\n") |
---|
210 | |
---|
211 | f.write("\n") |
---|
212 | f.write(str(begin)+"\n") |
---|
213 | f.write("sol"+"\n") |
---|
214 | |
---|
215 | for zvar in fields: |
---|
216 | f.write(zvar+"\n") |
---|
217 | f.write("\n") |
---|
218 | |
---|
219 | f.close() |
---|
220 | if verbose: |
---|
221 | system("concatnc.e < concatnc.auto.def") |
---|
222 | else: |
---|
223 | system("concatnc.e < concatnc.auto.def > /dev/null") |
---|
224 | |
---|
225 | |
---|
226 | #output_name = 'concat' + input_name[0].replace('diagfi','').replace('.nc','') \ |
---|
227 | # + '_' + input_name[len(input_name)-1].replace('diagfi','').replace('.nc','') + '.nc' |
---|
228 | |
---|
229 | #system('mv -f concat.nc '+output_name) |
---|
230 | |
---|
231 | output_name = 'concat.nc' |
---|
232 | |
---|
233 | return [output_name] |
---|
234 | |
---|
235 | |
---|
236 | |
---|
237 | def call_lslin ( input_name = None, \ |
---|
238 | begin = 0,\ |
---|
239 | timestep = None,\ |
---|
240 | isconcat = True, \ |
---|
241 | verbose = True): |
---|
242 | |
---|
243 | import numpy as np |
---|
244 | from os import system |
---|
245 | system("rm -f lslin.auto.def") |
---|
246 | system("touch lslin.auto.def") |
---|
247 | |
---|
248 | f = open('lslin.auto.def', 'w') |
---|
249 | |
---|
250 | f.write(input_name[0]+"\n") |
---|
251 | if isconcat: |
---|
252 | f.write("y"+"\n") |
---|
253 | else: |
---|
254 | f.write("n"+"\n") |
---|
255 | |
---|
256 | f.write(str(begin)+"\n") |
---|
257 | if timestep is None: |
---|
258 | f.write("y"+"\n") |
---|
259 | else: |
---|
260 | f.write("n"+"\n") |
---|
261 | f.write(str(timestep)+"\n") |
---|
262 | |
---|
263 | |
---|
264 | f.close() |
---|
265 | if verbose: |
---|
266 | system("lslin.e < lslin.auto.def") |
---|
267 | else: |
---|
268 | system("lslin.e < lslin.auto.def > /dev/null") |
---|
269 | |
---|
270 | output_name = input_name[0].replace('.nc','_Ls.nc') |
---|
271 | |
---|
272 | return [output_name] |
---|
273 | |
---|
274 | |
---|
275 | |
---|
276 | |
---|