[803] | 1 | # Wrapper for the generic functions written in python from 'generic_tools.py' |
---|
| 2 | # L. Fita, LMD. June 2016 |
---|
[1217] | 3 | # Python to manage netCDF files. |
---|
| 4 | # From L. Fita work in different places: LMD (France) |
---|
[1219] | 5 | # More information at: http://www.xn--llusfb-5va.cat/python/PyNCplot |
---|
[1217] | 6 | # |
---|
| 7 | # pyNCplot and its component generic.py comes with ABSOLUTELY NO WARRANTY. |
---|
| 8 | # This work is licendes under a Creative Commons |
---|
| 9 | # Attribution-ShareAlike 4.0 International License (http://creativecommons.org/licenses/by-sa/4.0) |
---|
| 10 | # |
---|
[803] | 11 | |
---|
| 12 | from optparse import OptionParser |
---|
| 13 | import numpy as np |
---|
| 14 | import datetime as dt |
---|
| 15 | import generic_tools as gen |
---|
| 16 | |
---|
[1326] | 17 | main = 'generic.py' |
---|
[803] | 18 | errormsg = 'ERROR -- error -- ERROR -- error' |
---|
| 19 | warnmsg = 'WARNING -- warning --WARNING -- warning' |
---|
| 20 | import os |
---|
| 21 | import re |
---|
| 22 | |
---|
[1918] | 23 | # ASCIIfile_stats: Function to provide the statistics of a series of values from an ASCII file |
---|
[1221] | 24 | # coincident_CFtimes: Function to make coincident times for two different sets of CFtimes |
---|
[2490] | 25 | # coldec_hex: Function to pas a decimal ([r,g,b]; [0.,1.]) color to hexadecimal (#[RR][GG][BB], 00-64, 0A-FF) |
---|
[1221] | 26 | # count_cond: Function to count values of a variable which attain a condition |
---|
[2035] | 27 | # create_LateX_figs: Function to create a LaTeX from a folder with multiple plots from different values |
---|
[1221] | 28 | # datetimeStr_conversion: Function to transform a string date to an another date object |
---|
[2706] | 29 | # DegMinSec_angle: Function to transform Degrees Minutes Seconds to an angle |
---|
[2203] | 30 | # get_right_CFtimeunits: Function to get the right CFtime units from any given format |
---|
[1221] | 31 | # grid_combinations: Function to provide all the possible grid points combination for a given pair of values |
---|
| 32 | # x,y= pair of grid points |
---|
[2027] | 33 | # inf_operSlist: Function to provide information from a string as a list separated by |
---|
| 34 | # a given character followig a given operation and a set of values |
---|
[1221] | 35 | # interpolate_locs: Function to provide interpolate locations on a given axis |
---|
| 36 | # PolyArea: Function to compute the area of the polygon following 'Shoelace formula' |
---|
| 37 | # radial_points: Function to provide a number of grid point positions for a given angle |
---|
| 38 | # radius_dist: Function to generate a matrix with the distance at a given point |
---|
| 39 | # rmNOnum: Removing from a string all that characters which are not numbers |
---|
| 40 | # running_mean: Function to compute a running mean of a series of values |
---|
| 41 | # significant_decomposition: Function to decompose a given number by its signifcant potencies |
---|
| 42 | # squared_radial: Function to provide the series of radii as composite of pairs (x,y) of gid cells |
---|
| 43 | # Npt= largest amount of grid points on x and y directions |
---|
[2750] | 44 | # stations_values: Function to provide information from a given station from one of its values |
---|
| 45 | # from ASCII file 'OBStations.csv' |
---|
[1221] | 46 | # table_tex_file: Function to write into a file a LaTeX tabular from a table of values |
---|
| 47 | # unitsDate: Function to know how many units of time are from a given pair of dates |
---|
| 48 | # variables_values: Function to provide values to plot the different variables values from ASCII file |
---|
| 49 | # wdismean: Function to compute the mean value weighted to its 4 distances |
---|
[1897] | 50 | # WRFsetup: Function to check the set-up of a series of model namelist |
---|
[1896] | 51 | |
---|
[803] | 52 | # Character to split passed values |
---|
| 53 | cS = ',' |
---|
[1896] | 54 | # Character to split a serie of values |
---|
[805] | 55 | cV = '@' |
---|
[809] | 56 | # Character for spaces |
---|
| 57 | cE = '!' |
---|
| 58 | |
---|
[803] | 59 | # List of available operations |
---|
[2490] | 60 | operations=['ASCIIfile_stats', 'coincident_CFtimes', 'coldec_hex', 'count_cond', \ |
---|
[2706] | 61 | 'create_LateX_figs', 'datetimeStr_conversion', 'DegMinSec_angle', \ |
---|
| 62 | 'get_right_CFtimeunits', 'grid_combinations', 'inf_operSlist', \ |
---|
[1326] | 63 | 'interpolate_locs', 'latex_fig_array', 'list_operations', 'PolyArea', \ |
---|
[809] | 64 | 'radial_points', 'radius_dist', \ |
---|
[807] | 65 | 'rmNOnum', 'running_mean', \ |
---|
[2750] | 66 | 'significant_decomposition', 'squared_radial', 'stations_values', \ |
---|
[1896] | 67 | 'table_tex_file', 'unitsDate', 'variables_values', 'wdismean', 'WRFsetup'] |
---|
[803] | 68 | |
---|
[807] | 69 | hundredvals = '0' |
---|
[809] | 70 | for i in range(1,100): hundredvals = hundredvals + cV + str(i) |
---|
[807] | 71 | |
---|
| 72 | vs100 = '0@1@2@3@4@5@6@7@8@9@10@11@12@13@14@15@16@17@18@19@20@21@22@23@24@25@26@27' |
---|
| 73 | vs100 = vs100 + '@28@29@30@31@32@33@34@35@36@37@38@39@40@41@42@43@44@45@46@47@48@49' |
---|
| 74 | vs100 = vs100 + '@50@51@52@53@54@55@56@57@58@59@60@61@62@63@64@65@66@67@68@69@70@71' |
---|
| 75 | va100 = vs100 + '@72@73@74@75@76@77@78@79@80@81@82@83@84@85@86@87@88@89@90@91@92@93' |
---|
| 76 | va100 = vs100 + '@94@95@96@97@98@99' |
---|
| 77 | |
---|
| 78 | ## e.g. # generic.py -o 'coincident_CFtimes' -S '0@1@2@3@4@5@6@7@8@9,seconds since 1949-12-01 00:00:00,hours since 1949-12-01 00:00:00' |
---|
| 79 | ## e.g. # generic.py -o count_cond -S 0@1@2@3@4@5@6@7@8@9,4,le |
---|
[809] | 80 | ## e.g. # generic.py -o datetimeStr_conversion -S '1976-02-17_08:32:05,Y-m-d_H:M:S,matYmdHMS' |
---|
[805] | 81 | ## e.g. # generic.py -o grid_combinations -S 1,2 |
---|
[809] | 82 | ## e.g. # generic.py -o interpolate_locs -S -1.2@2.4@5.6@7.8@12.0,0.5@2.5,lin |
---|
[805] | 83 | ## e.g. # generic.py -o PolyArea -S -0.5@0.5@0.5@-0.5,0.5@0.5@-0.5@-0.5 |
---|
[807] | 84 | ## e.g. # generic.py -o radial_points -S 0.785398163397,5 |
---|
[809] | 85 | ## e.g. # generic.py -o radius_dist -S 3,5,2,2 |
---|
[805] | 86 | ## e.g. # generic.py -o rmNOnum -S LMD123IPSL |
---|
[1222] | 87 | ## e.g. # generic.py -o significant_decomposition -S 3.576,-2 |
---|
[809] | 88 | ## e.g. # generic.py -o table_tex_file -S '5,3,0@5@10@1@6@11@2@7@12@3@8@13@4@9@14,!@a@b@c@d@e,i@ii@iii,table.tex' |
---|
[806] | 89 | ## e.g. # generic.py -o unitsDate -S '19490101000000,19760217082932,second' |
---|
[807] | 90 | ## e.g. # generic.py -o running_mean -S 0@1@2@3@4@5@6@7@8@9,10 |
---|
[805] | 91 | ## e.g. # generic.py -o squared_radial -S 3 |
---|
[892] | 92 | ## e.g. # generic.py -o variables_values -S 'hus' |
---|
[807] | 93 | ## e.g. # generic.py -o wdismean -S 0.005@0.005,0.@1.@2.@3. |
---|
[1897] | 94 | ## e.g. # generic.py -o WRFsetup -S '/home/lluis/estudios/RELAMPAGO/SimCoor/UBA/namelist.input@/home/lluis/estudios/RELAMPAGO/SimCoor/SMN/namelist.input@/home/lluis/estudios/RELAMPAGO/SimCoor/NOA-IERSD/namelist.input@/home/lluis/estudios/RELAMPAGO/SimCoor/UBAmili/namelist.input,basic,textabrow' |
---|
[1919] | 95 | ## e.g. # generic.py -o ASCIIfile_stats -S times_CDXWRF1.dat,#,R |
---|
[2027] | 96 | ## e.g. # generic.py -o inf_operSlist -S '-98.21:1.2:3.45:100.1:34321.1,threshold,:,3.' |
---|
[2035] | 97 | ## e.g. # generic.py -o create_LateX_figs -S '/home/lluis/estudios/FPS_ALPS/additional/IOP/analysis/figs,WindRose_obs_@SkewT-logP_obs_ta-tda@SkewT-logP_obs_evol@WindRose_obs-sim_step@SkewT-logP_obs-sim_step@SkewT-logP_obs-sim_evol,10868@16080@16144@16546,png' |
---|
[2203] | 98 | ## e.g. # generic.py -o get_right_CFtimeunits -S 'minutes!since!1-1-1' |
---|
[2490] | 99 | ## e.g. # generic.py -o coldec_hex -S 0.545,0.352,0. |
---|
[2706] | 100 | ## e.g. # generic.py -o DegMinSec_angle -S 35,10,21 |
---|
[803] | 101 | |
---|
| 102 | operationnames = "'" + gen.numVector_String(operations, "', '") + "'" |
---|
[805] | 103 | valuesinf = "'" + cS + "' list of values to use according to the operation ('" + cV +\ |
---|
| 104 | "' for list of values)" |
---|
[803] | 105 | |
---|
| 106 | parser = OptionParser() |
---|
| 107 | parser.add_option("-o", "--operation", type='choice', dest="operation", |
---|
| 108 | choices=operations, help="operation to make: " + operationnames, metavar="OPER") |
---|
| 109 | parser.add_option("-S", "--valueS (when applicable)", dest="values", |
---|
[805] | 110 | help=valuesinf, metavar="VALUES") |
---|
[803] | 111 | (opts, args) = parser.parse_args() |
---|
| 112 | |
---|
| 113 | ####### ####### |
---|
| 114 | ## MAIN |
---|
| 115 | ####### |
---|
| 116 | oper = opts.operation |
---|
| 117 | |
---|
| 118 | if oper == 'list_operations': |
---|
| 119 | # From: http://www.diveintopython.net/power_of_introspection/all_together.html |
---|
| 120 | object = gen |
---|
| 121 | for opern in operations: |
---|
| 122 | if opern != 'list_operations': |
---|
| 123 | print opern + '_______ ______ _____ ____ ___ __ _' |
---|
| 124 | print getattr(object, opern).__doc__ |
---|
[805] | 125 | |
---|
[2203] | 126 | elif oper == 'ASCIIfile_stats': |
---|
| 127 | Nvals = 3 |
---|
| 128 | vals = opts.values.split(cS) |
---|
| 129 | if vals[0] == 'h': |
---|
| 130 | print gen.ASCIIfile_stats.__doc__ |
---|
| 131 | quit(-1) |
---|
| 132 | else: |
---|
| 133 | if len(vals) != Nvals: |
---|
| 134 | print errormsg |
---|
| 135 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 136 | len(vals), ' has passed!!' |
---|
| 137 | print gen.ASCIIfile_stats.__doc__ |
---|
| 138 | quit(-1) |
---|
| 139 | vals0 = vals[0] |
---|
| 140 | vals1 = vals[1] |
---|
| 141 | vals2 = vals[2] |
---|
| 142 | |
---|
| 143 | print gen.ASCIIfile_stats(vals0, vals1, vals2) |
---|
| 144 | |
---|
[807] | 145 | elif oper == 'coincident_CFtimes': |
---|
| 146 | Nvals = 3 |
---|
| 147 | vals = opts.values.split(cS) |
---|
| 148 | if vals[0] == 'h': |
---|
| 149 | print gen.coincident_CFtimes.__doc__ |
---|
| 150 | quit(-1) |
---|
| 151 | else: |
---|
| 152 | if len(vals) != Nvals: |
---|
| 153 | print errormsg |
---|
| 154 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 155 | len(vals), ' has passed!!' |
---|
| 156 | print gen.coincident_CFtimes.__doc__ |
---|
| 157 | quit(-1) |
---|
[809] | 158 | vals0 = np.array(vals[0].split(cV), dtype=np.float) |
---|
[807] | 159 | print gen.coincident_CFtimes(vals0, vals[1], vals[2]) |
---|
| 160 | |
---|
[2490] | 161 | elif oper == 'coldec_hex': |
---|
| 162 | Nvals = 3 |
---|
| 163 | vals = opts.values.split(cS) |
---|
| 164 | if vals[0] == 'h': |
---|
| 165 | print gen.coldec_hex.__doc__ |
---|
| 166 | quit(-1) |
---|
| 167 | else: |
---|
| 168 | if len(vals) != Nvals: |
---|
| 169 | print errormsg |
---|
| 170 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 171 | len(vals), ' has passed!!' |
---|
| 172 | print gen.coldec_hex.__doc__ |
---|
| 173 | quit(-1) |
---|
| 174 | valsF = np.array(vals, dtype=np.float) |
---|
| 175 | print gen.coldec_hex(valsF) |
---|
| 176 | |
---|
[807] | 177 | elif oper == 'count_cond': |
---|
| 178 | Nvals = 3 |
---|
| 179 | vals = opts.values.split(cS) |
---|
| 180 | if vals[0] == 'h': |
---|
| 181 | print gen.count_cond.__doc__ |
---|
| 182 | quit(-1) |
---|
| 183 | else: |
---|
| 184 | if len(vals) != Nvals: |
---|
| 185 | print errormsg |
---|
| 186 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 187 | len(vals), ' has passed!!' |
---|
| 188 | print gen.count_cond.__doc__ |
---|
| 189 | quit(-1) |
---|
[809] | 190 | vals0 = np.array(vals[0].split(cV), dtype=np.float) |
---|
| 191 | print gen.count_cond(np.array(vals[0].split(cV), dtype=np.float), \ |
---|
[807] | 192 | np.float(vals[1]), vals[2]) |
---|
| 193 | |
---|
[2035] | 194 | elif oper == 'create_LateX_figs': |
---|
| 195 | Nvals = 4 |
---|
| 196 | vals = opts.values.split(cS) |
---|
| 197 | if vals[0] == 'h': |
---|
| 198 | print gen.create_LateX_figs.__doc__ |
---|
| 199 | quit(-1) |
---|
| 200 | else: |
---|
| 201 | if len(vals) != Nvals: |
---|
| 202 | print errormsg |
---|
| 203 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 204 | len(vals), ' has passed!!' |
---|
| 205 | print gen.create_LateX_figs.__doc__ |
---|
| 206 | quit(-1) |
---|
| 207 | vals0 = vals[0] |
---|
| 208 | vals1 = vals[1].split('@') |
---|
| 209 | vals2 = vals[2].split('@') |
---|
| 210 | vals3 = vals[3] |
---|
| 211 | |
---|
| 212 | print gen.create_LateX_figs(vals0, vals1, vals2, vals3) |
---|
| 213 | |
---|
[809] | 214 | elif oper == 'datetimeStr_conversion': |
---|
| 215 | Nvals = 3 |
---|
| 216 | vals = opts.values.split(cS) |
---|
[2092] | 217 | if vals[0] == 'h': |
---|
| 218 | print gen.datetimeStr_conversion.__doc__ |
---|
| 219 | quit(-1) |
---|
| 220 | |
---|
[1757] | 221 | newvals = [] |
---|
| 222 | if vals[1] == 'cfTime': |
---|
| 223 | newvals.append(vals[0]) |
---|
| 224 | newvals.append(vals[1]+','+vals[2]) |
---|
[2433] | 225 | if vals[2] == 'cfTime': |
---|
| 226 | newvals.append(vals[3]+','+vals[4].replace('!',' ')) |
---|
| 227 | else: |
---|
[2489] | 228 | newvals.append(vals[3]) |
---|
[2429] | 229 | elif vals[1] == 'cfTimeCal': |
---|
| 230 | newvals.append(vals[0]) |
---|
| 231 | newvals.append(vals[1]+','+vals[2]+','+vals[3]) |
---|
| 232 | if vals[2] == 'cfTimeCal': newvals.append(vals[3] + ',' + \ |
---|
[2430] | 233 | vals[4].replace('!',' ')+','+vals[5]) |
---|
[2433] | 234 | else: |
---|
| 235 | newvals.append(vals[4]) |
---|
[1757] | 236 | if vals[2] == 'cfTime': |
---|
| 237 | newvals.append(vals[0]) |
---|
| 238 | newvals.append(vals[1]) |
---|
[2092] | 239 | newvals.append(vals[2]+','+vals[3].replace('!',' ')) |
---|
[2429] | 240 | elif vals[2] == 'cfTimeCal': |
---|
| 241 | newvals.append(vals[0]) |
---|
[2430] | 242 | newvals.append(vals[1]) |
---|
[2433] | 243 | newvals.append(vals[2] + ',' + vals[3].replace('!',' ')+','+vals[4]) |
---|
| 244 | if len(newvals) > 0: |
---|
[2429] | 245 | vals = list(newvals) |
---|
[2433] | 246 | |
---|
[2092] | 247 | if len(vals) != Nvals: |
---|
| 248 | print errormsg |
---|
[2429] | 249 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
[2092] | 250 | len(vals), ' has passed!!' |
---|
[809] | 251 | print gen.datetimeStr_conversion.__doc__ |
---|
| 252 | quit(-1) |
---|
[2092] | 253 | print gen.datetimeStr_conversion(vals[0], vals[1], vals[2]) |
---|
[809] | 254 | |
---|
[828] | 255 | #'days_period' |
---|
[818] | 256 | |
---|
[2706] | 257 | elif oper == 'DegMinSec_angle': |
---|
| 258 | Nvals = 3 |
---|
| 259 | vals = opts.values.split(cS) |
---|
| 260 | if vals[0] == 'h': |
---|
| 261 | print gen.DegMinSec_angle.__doc__ |
---|
| 262 | quit(-1) |
---|
| 263 | else: |
---|
| 264 | if len(vals) != Nvals: |
---|
| 265 | print errormsg |
---|
| 266 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 267 | len(vals), ' has passed!!' |
---|
| 268 | print gen.DegMinSec_angle.__doc__ |
---|
| 269 | quit(-1) |
---|
| 270 | vals0 = np.float(vals[0]) |
---|
| 271 | vals1 = np.float(vals[1]) |
---|
| 272 | vals2 = np.float(vals[2]) |
---|
| 273 | |
---|
| 274 | print gen.DegMinSec_angle(vals0, vals1, vals2) |
---|
| 275 | |
---|
[2203] | 276 | elif oper == 'get_right_CFtimeunits': |
---|
| 277 | Nvals = 1 |
---|
| 278 | vals = opts.values.split(cS) |
---|
| 279 | if vals[0] == 'h': |
---|
| 280 | print gen.get_right_CFtimeunits.__doc__ |
---|
| 281 | quit(-1) |
---|
| 282 | else: |
---|
| 283 | if len(vals) != Nvals: |
---|
| 284 | print errormsg |
---|
| 285 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 286 | len(vals), ' has passed!!' |
---|
| 287 | print gen.get_right_CFtimeunits.__doc__ |
---|
| 288 | quit(-1) |
---|
| 289 | print gen.get_right_CFtimeunits(vals[0].replace('!', ' ')) |
---|
| 290 | |
---|
[805] | 291 | elif oper == 'grid_combinations': |
---|
| 292 | Nvals = 2 |
---|
| 293 | vals = opts.values.split(cS) |
---|
| 294 | if vals[0] == 'h': |
---|
| 295 | print gen.grid_combinations.__doc__ |
---|
| 296 | quit(-1) |
---|
| 297 | else: |
---|
| 298 | if len(vals) != Nvals: |
---|
| 299 | print errormsg |
---|
| 300 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 301 | len(vals), ' has passed!!' |
---|
| 302 | print gen.grid_combinations.__doc__ |
---|
| 303 | quit(-1) |
---|
| 304 | |
---|
| 305 | print gen.grid_combinations(np.int(vals[0]), np.int(vals[1])) |
---|
| 306 | |
---|
[1326] | 307 | elif oper == 'latex_fig_array': |
---|
| 308 | vals = opts.values.split(cS) |
---|
| 309 | if vals[0] == 'h': |
---|
| 310 | print gen.latex_fig_array.__doc__ |
---|
| 311 | print " NOTE: first argument as existing LaTeX file" |
---|
| 312 | print " figs: passing list of figures as '@' separated list" |
---|
| 313 | print " caption: using '!' for spaces" |
---|
| 314 | quit(-1) |
---|
| 315 | else: |
---|
| 316 | expectargs = '[latexfile],[figs],[figcaption],[figlabel],[dist],[refsize],'+ \ |
---|
| 317 | '[width],[height],[dorest]' |
---|
| 318 | gen.check_arguments(oper,opts.values,expectargs,cS) |
---|
| 319 | |
---|
| 320 | objf = open(vals[0], 'a') |
---|
| 321 | |
---|
| 322 | figs = vals[1].split('@') |
---|
| 323 | caption = vals[2].replace('!',' ') |
---|
| 324 | gen.latex_fig_array(figs, objf, caption, vals[3], dist=vals[4], \ |
---|
| 325 | refsize=vals[5], width=vals[6], height=vals[7], dorest=vals[8]) |
---|
| 326 | objf.write('\\end{document}\n') |
---|
| 327 | objf.close() |
---|
| 328 | |
---|
[2027] | 329 | elif oper == 'inf_operSlist': |
---|
| 330 | Nvals = 4 |
---|
| 331 | vals = opts.values.split(cS) |
---|
| 332 | if vals[0] == 'h': |
---|
| 333 | print gen.inf_operSlist.__doc__ |
---|
| 334 | quit(-1) |
---|
| 335 | else: |
---|
| 336 | if len(vals) != Nvals: |
---|
| 337 | print errormsg |
---|
| 338 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 339 | len(vals), ' has passed!!' |
---|
| 340 | print gen.inf_operSlist.__doc__ |
---|
| 341 | quit(-1) |
---|
| 342 | vals0 = vals[0] |
---|
| 343 | vals1 = vals[1] |
---|
| 344 | vals2 = vals[2] |
---|
| 345 | vals3 = vals[3] |
---|
| 346 | |
---|
| 347 | print gen.inf_operSlist(vals0, vals1, char=vals2, values=vals3) |
---|
| 348 | |
---|
[809] | 349 | elif oper == 'interpolate_locs': |
---|
| 350 | Nvals = 3 |
---|
| 351 | vals = opts.values.split(cS) |
---|
| 352 | if vals[0] == 'h': |
---|
| 353 | print gen.interpolate_locs.__doc__ |
---|
| 354 | quit(-1) |
---|
| 355 | else: |
---|
| 356 | if len(vals) != Nvals: |
---|
| 357 | print errormsg |
---|
| 358 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 359 | len(vals), ' has passed!!' |
---|
| 360 | print gen.interpolate_locs.__doc__ |
---|
| 361 | quit(-1) |
---|
| 362 | vals0 = np.array(vals[0].split(cV), dtype=np.float) |
---|
| 363 | vals1 = np.array(vals[1].split(cV), dtype=np.float) |
---|
| 364 | |
---|
| 365 | print gen.interpolate_locs(vals0, vals1, vals[2]) |
---|
| 366 | |
---|
[805] | 367 | elif oper == 'PolyArea': |
---|
| 368 | Nvals = 2 |
---|
| 369 | vals = opts.values.split(cS) |
---|
| 370 | if vals[0] == 'h': |
---|
| 371 | print gen.PolyArea.__doc__ |
---|
| 372 | quit(-1) |
---|
| 373 | else: |
---|
| 374 | if len(vals) != Nvals: |
---|
| 375 | print errormsg |
---|
| 376 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 377 | len(vals), ' has passed!!' |
---|
| 378 | print gen.PolyArea.__doc__ |
---|
| 379 | quit(-1) |
---|
| 380 | xvals = np.array(vals[0].split(cV), dtype=np.float) |
---|
| 381 | yvals = np.array(vals[1].split(cV), dtype=np.float) |
---|
| 382 | |
---|
| 383 | print gen.PolyArea(xvals, yvals) |
---|
| 384 | |
---|
[807] | 385 | elif oper == 'radial_points': |
---|
| 386 | Nvals = 2 |
---|
| 387 | vals = opts.values.split(cS) |
---|
| 388 | if vals[0] == 'h': |
---|
| 389 | print gen.radial_points.__doc__ |
---|
| 390 | quit(-1) |
---|
| 391 | else: |
---|
| 392 | if len(vals) != Nvals: |
---|
| 393 | print errormsg |
---|
| 394 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 395 | len(vals), ' has passed!!' |
---|
| 396 | print gen.radial_points.__doc__ |
---|
| 397 | quit(-1) |
---|
| 398 | print gen.radial_points(np.float(vals[0]), int(vals[1])) |
---|
| 399 | |
---|
[809] | 400 | elif oper == 'radius_dist': |
---|
| 401 | Nvals = 1 |
---|
| 402 | vals = opts.values.split(cS) |
---|
| 403 | if vals[0] == 'h': |
---|
| 404 | print gen.radius_dist.__doc__ |
---|
| 405 | quit(-1) |
---|
| 406 | else: |
---|
| 407 | if len(vals) != Nvals: |
---|
| 408 | print errormsg |
---|
| 409 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 410 | len(vals), ' has passed!!' |
---|
| 411 | print gen.radius_dist.__doc__ |
---|
| 412 | quit(-1) |
---|
| 413 | print gen.radius_dist(int(vals[0]), int(vals[1]), int(vals[2]), int(vals[2])) |
---|
| 414 | |
---|
[805] | 415 | elif oper == 'rmNOnum': |
---|
| 416 | Nvals = 1 |
---|
| 417 | vals = opts.values.split(cS) |
---|
| 418 | if vals[0] == 'h': |
---|
| 419 | print gen.rmNOnum.__doc__ |
---|
| 420 | quit(-1) |
---|
| 421 | else: |
---|
| 422 | if len(vals) != Nvals: |
---|
| 423 | print errormsg |
---|
| 424 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 425 | len(vals), ' has passed!!' |
---|
| 426 | print gen.rmNOnum.__doc__ |
---|
| 427 | quit(-1) |
---|
| 428 | print gen.rmNOnum(vals[0]) |
---|
| 429 | |
---|
[807] | 430 | elif oper == 'running_mean': |
---|
| 431 | Nvals = 2 |
---|
| 432 | vals = opts.values.split(cS) |
---|
| 433 | if vals[0] == 'h': |
---|
| 434 | print gen.running_mean.__doc__ |
---|
| 435 | quit(-1) |
---|
| 436 | else: |
---|
| 437 | if len(vals) != Nvals: |
---|
| 438 | print errormsg |
---|
| 439 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 440 | len(vals), ' has passed!!' |
---|
| 441 | print gen.running_mean.__doc__ |
---|
| 442 | quit(-1) |
---|
[809] | 443 | print gen.running_mean(np.array(vals[0].split(cV), dtype=np.float), int(vals[1])) |
---|
[807] | 444 | |
---|
[805] | 445 | elif oper == 'significant_decomposition': |
---|
| 446 | Nvals = 2 |
---|
| 447 | vals = opts.values.split(cS) |
---|
| 448 | if vals[0] == 'h': |
---|
| 449 | print gen.significant_decomposition.__doc__ |
---|
| 450 | quit(-1) |
---|
| 451 | else: |
---|
| 452 | if len(vals) != Nvals: |
---|
| 453 | print errormsg |
---|
| 454 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 455 | len(vals), ' has passed!!' |
---|
| 456 | print gen.significant_decomposition.__doc__ |
---|
| 457 | quit(-1) |
---|
| 458 | print gen.significant_decomposition(np.float(vals[0]), int(vals[1])) |
---|
| 459 | |
---|
| 460 | elif oper == 'squared_radial': |
---|
| 461 | Nvals = 1 |
---|
| 462 | vals = opts.values.split(cS) |
---|
| 463 | if vals[0] == 'h': |
---|
| 464 | print gen.squared_radial.__doc__ |
---|
| 465 | quit(-1) |
---|
| 466 | else: |
---|
| 467 | if len(vals) != Nvals: |
---|
| 468 | print errormsg |
---|
| 469 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 470 | len(vals), ' has passed!!' |
---|
| 471 | print gen.squared_radial.__doc__ |
---|
| 472 | quit(-1) |
---|
| 473 | print gen.squared_radial(int(vals[0])) |
---|
| 474 | |
---|
[2750] | 475 | elif oper == 'stations_values': |
---|
[2785] | 476 | Nvals = 5 |
---|
[2750] | 477 | vals = opts.values.split(cS) |
---|
| 478 | if vals[0] == 'h': |
---|
| 479 | print gen.stations_values.__doc__ |
---|
| 480 | quit(-1) |
---|
| 481 | else: |
---|
| 482 | if len(vals) != Nvals: |
---|
| 483 | print errormsg |
---|
| 484 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 485 | len(vals), ' has passed!!' |
---|
| 486 | print gen.stations_values.__doc__ |
---|
| 487 | quit(-1) |
---|
[2785] | 488 | result = gen.stations_values(vals[0], vals[1], vals[2], vals[3], vals[4]) |
---|
| 489 | if type(result) == type({0: 'zero'}): |
---|
| 490 | keys = list(result.keys()) |
---|
| 491 | for kv in keys: |
---|
| 492 | vals = result[kv] |
---|
| 493 | print '##'+str(kv)+'## ' + gen.numVector_String(vals,':') |
---|
| 494 | else: |
---|
| 495 | print gen.numVector_String(result,':') |
---|
[2750] | 496 | |
---|
[809] | 497 | elif oper == 'table_tex_file': |
---|
| 498 | Nvals = 6 |
---|
| 499 | vals = opts.values.split(cS) |
---|
| 500 | if vals[0] == 'h': |
---|
| 501 | print gen.table_tex_file.__doc__ |
---|
| 502 | quit(-1) |
---|
| 503 | else: |
---|
| 504 | if len(vals) != Nvals: |
---|
| 505 | print errormsg |
---|
| 506 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 507 | len(vals), ' has passed!!' |
---|
| 508 | print gen.table_tex_file.__doc__ |
---|
| 509 | quit(-1) |
---|
| 510 | vals2 = np.array(vals[2].split(cV),dtype=np.float).reshape(int(vals[0]), \ |
---|
| 511 | int(vals[1])) |
---|
| 512 | vals3 = vals[3].replace(cE,' ').split(cV) |
---|
| 513 | vals4 = vals[4].replace(cE,' ').split(cV) |
---|
| 514 | |
---|
| 515 | print gen.table_tex_file(int(vals[0]), int(vals[1]), vals2, vals3, vals4, \ |
---|
| 516 | vals[5]) |
---|
| 517 | |
---|
[803] | 518 | elif oper == 'unitsDate': |
---|
| 519 | Nvals = 3 |
---|
| 520 | vals = opts.values.split(cS) |
---|
| 521 | if vals[0] == 'h': |
---|
| 522 | print gen.unitsDate.__doc__ |
---|
| 523 | quit(-1) |
---|
| 524 | else: |
---|
[805] | 525 | if len(vals) != Nvals: |
---|
[803] | 526 | print errormsg |
---|
| 527 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 528 | len(vals), ' has passed!!' |
---|
| 529 | print gen.unitsDate.__doc__ |
---|
| 530 | quit(-1) |
---|
| 531 | print gen.unitsDate(vals[0], vals[1], vals[2]) |
---|
| 532 | |
---|
[892] | 533 | elif oper == 'variables_values': |
---|
| 534 | Nvals = 1 |
---|
| 535 | vals = opts.values.split(cS) |
---|
| 536 | if vals[0] == 'h': |
---|
| 537 | print gen.variables_values.__doc__ |
---|
| 538 | quit(-1) |
---|
| 539 | else: |
---|
| 540 | if len(vals) != Nvals: |
---|
| 541 | print errormsg |
---|
| 542 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 543 | len(vals), ' has passed!!' |
---|
| 544 | print gen.variables_values.__doc__ |
---|
| 545 | quit(-1) |
---|
| 546 | result = gen.variables_values(vals[0]) |
---|
| 547 | print gen.numVector_String(result,':') |
---|
| 548 | |
---|
[807] | 549 | elif oper == 'wdismean': |
---|
| 550 | Nvals = 2 |
---|
| 551 | vals = opts.values.split(cS) |
---|
| 552 | if vals[0] == 'h': |
---|
| 553 | print gen.wdismean.__doc__ |
---|
| 554 | quit(-1) |
---|
| 555 | else: |
---|
| 556 | if len(vals) != Nvals: |
---|
| 557 | print errormsg |
---|
| 558 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 559 | len(vals), ' has passed!!' |
---|
| 560 | print gen.wdismean.__doc__ |
---|
| 561 | quit(-1) |
---|
[809] | 562 | vals0 = np.array(vals[0].split(cV), dtype=np.float) |
---|
| 563 | vals1 = np.array(vals[1].split(cV), dtype=np.float).reshape(2,2) |
---|
[807] | 564 | |
---|
| 565 | print gen.wdismean(vals0, vals1) |
---|
| 566 | |
---|
[1896] | 567 | elif oper == 'WRFsetup': |
---|
| 568 | Nvals = 3 |
---|
| 569 | vals = opts.values.split(cS) |
---|
| 570 | if vals[0] == 'h': |
---|
| 571 | print gen.WRFsetup.__doc__ |
---|
| 572 | quit(-1) |
---|
| 573 | else: |
---|
| 574 | if len(vals) != Nvals: |
---|
| 575 | print errormsg |
---|
| 576 | print ' ' + main + ": operation '" + oper + "' requires", Nvals, 'and', \ |
---|
| 577 | len(vals), ' has passed!!' |
---|
| 578 | print gen.WRFsetup.__doc__ |
---|
| 579 | quit(-1) |
---|
[1897] | 580 | vals0 = vals[0].replace('@', ',') |
---|
[1896] | 581 | vals1 = vals[1] |
---|
| 582 | vals2 = vals[2] |
---|
| 583 | |
---|
| 584 | print gen.WRFsetup(vals0, vals1, vals2) |
---|
| 585 | |
---|