source: trunk/UTIL/PYTHON/gcm_transformations.py @ 579

Last change on this file since 579 was 489, checked in by aslmd, 13 years ago

UTIL PYTHON : 1) no more negative values for --time but use --axtime lt ; this actually fix a stupid bug with negative lat lon. 2) use of -l is now possible with GCM files, try it with -i 2. 3) now correct handling of sol/ls in mesoscale files 4) for mesoscale files with chosen lat+lon now shows a topo map with a cross on it.

File size: 7.9 KB
Line 
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
8def call_zrecast (  interp_mode   = '4', \
9                    input_name      = None, \
10                    fields  = 'all', \
11                    limites = None, \
12                    predefined = None):
13
14    import numpy as np
15    from myplot import separatenames
16    from os import system
17    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]
18    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]
19    system("rm -f zrecast.auto.def")
20    system("touch zrecast.auto.def")
21    indicefile=0
22    outputfilename=""
23    f = open('zrecast.auto.def', 'w')
24
25    for zfile in input_name:
26        f.write(zfile+"\n")
27        for zvar in fields:
28             f.write(zvar+"\n")
29        f.write("\n")
30        if interp_mode == 4:
31             append="_S"
32             f.write("3"+"\n")
33             f.write("yes"+"\n")
34             f.write("0 150000"+"\n")
35        elif interp_mode == 2:
36             append="_P"
37             if predefined in ["TES","tes"]:
38                print "Using TES pressure levels"
39                f.write("1"+"\n")
40                f.write("no"+"\n")
41                f.write(str(len(pressure_axis_tes))+"\n")
42                for zp in pressure_axis_tes:
43                    f.write(str(zp)+"\n")
44                f.write("\n")
45             elif predefined in ["MCS","mcs"]:
46                print "Using MCS pressure levels"
47                f.write("1"+"\n")
48                f.write("no"+"\n")
49                f.write(str(len(pressure_axis_mcs))+"\n")
50                for zp in pressure_axis_mcs:
51                    f.write(str(zp)+"\n")
52                f.write("\n")
53             else:
54                f.write("1"+"\n")
55                f.write("yes"+"\n")
56                if limites[0] != -9999.:  f.write(str(limites[0])+" "+str(limites[-1])+"\n")
57                else:                     f.write("370 0.1"+"\n")
58                #f.write("1000000 100"+"\n")
59                f.write("20"+"\n")
60        else:
61             print "zrecast interp option unsupported for now. Exiting."
62             exit()
63        f.close()
64        system("zrecast.e < zrecast.auto.def")
65
66        if indicefile is 0:
67              outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
68        else:
69              outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
70        indicefile = indicefile +1
71
72        for i in range(len(outputfilename)):
73            output_name = separatenames(outputfilename)
74
75    return output_name
76
77def call_hrecast (  input_name = None, \
78                    fields  = 'all', \
79                    predefined = None):
80
81    import numpy as np
82    from myplot import separatenames
83    from os import system
84    # Beware that latitude axis in mcs and tes files is reversed
85    # When comparing to MCS or TES data, one has to reverse the latitude axis and data along latitude axis.
86    # This is for exemple automatically done in mcs.py.
87    # This could also be done in a future tes.py.
88    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]
89    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]
90    system("rm -f hrecast.auto.def")
91    system("touch hrecast.auto.def")
92    indicefile=0
93    outputfilename=""
94    append="_h"
95    f = open('hrecast.auto.def', 'w')
96    for zfile in input_name:
97        f.write(zfile+"\n")
98        for zvar in fields:
99             f.write(zvar+"\n")
100        f.write("\n")
101    if predefined in ["MCS","mcs","TES","tes"]:
102        f.write(str(len(longitudes_tes_mcs))+"\n")
103        for lon in longitudes_tes_mcs:
104            f.write(str(lon)+"\n")
105        f.write(str(len(latitudes_reversed_tes_mcs))+"\n")
106        for lat in latitudes_reversed_tes_mcs:
107            f.write(str(lat)+"\n")
108        f.close()
109        system("hrecast.e < hrecast.auto.def")
110
111        if indicefile is 0:
112              outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
113        else:
114              outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
115        indicefile = indicefile +1
116
117        for i in range(len(outputfilename)):
118            output_name = separatenames(outputfilename)
119
120    return output_name
121
122def call_localtime (  input_name = None, \
123                    fields  = 'all', \
124                    times = None):
125
126    import numpy as np
127    from myplot import separatenames
128    from os import system
129    system("rm -f localtime.auto.def")
130    system("touch localtime.auto.def")
131    indicefile=0
132    outputfilename=""
133    append="_LT"
134    f = open('localtime.auto.def', 'w')
135    for zfile in input_name:
136        f.write(zfile+"\n")
137        for zvar in fields:
138             f.write(zvar+"\n")
139        f.write("\n")
140    f.write(str(len(times))+"\n")
141    for t in times:
142        f.write(str(t)+"\n")
143    f.close()
144    system("localtime.e < localtime.auto.def")
145
146    if indicefile is 0:
147          outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
148    else:
149          outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
150    indicefile = indicefile +1
151
152    for i in range(len(outputfilename)):
153        output_name = separatenames(outputfilename)
154
155    return output_name
156
157def call_streamfunction (  input_name = None):
158    import numpy as np
159    from myplot import separatenames
160    from os import system
161    system("rm -f streamfunction.auto.def")
162    system("touch streamfunction.auto.def")
163    indicefile=0
164    outputfilename=""
165    append="_stream"
166    f = open('streamfunction.auto.def', 'w')
167    for zfile in input_name:
168        f.write(zfile+"\n")
169    f.close()
170    system("streamfunction.e < streamfunction.auto.def")
171
172    if indicefile is 0:
173          outputfilename=input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
174    else:
175          outputfilename=outputfilename+","+input_name[indicefile][0:len(input_name[0])-3]+append+".nc"
176    indicefile = indicefile +1
177
178    for i in range(len(outputfilename)):
179        output_name = separatenames(outputfilename)
180
181    return output_name
182
Note: See TracBrowser for help on using the repository browser.