[994] | 1 | # Python script to generate the files and the plots for a sensitivity study with multiple modle configurations and models |
---|
| 2 | # L. Fita |
---|
| 3 | # LMD, Jussieu/Palaisseau, France |
---|
| 4 | # Script configuration get from ASCII file 'model_graphics.dat' |
---|
| 5 | |
---|
[1378] | 6 | # `Wheeler-Kiladis' diagram: https://github.com/UV-CDAT/wk |
---|
[1377] | 7 | # $ cd /home/lluis/Downloads |
---|
| 8 | # $ git clone https://github.com/UV-CDAT/wk |
---|
| 9 | # $ cd wk |
---|
| 10 | # $ su |
---|
| 11 | # # python setup.py build >& run_pysetup.log |
---|
| 12 | # # python setup.py install >& run_pyinstall.log |
---|
| 13 | |
---|
[994] | 14 | import numpy as np |
---|
| 15 | import nc_var_tools as ncvar |
---|
| 16 | import generic_tools as gen |
---|
[1025] | 17 | import drawing_tools as drw |
---|
[994] | 18 | import time as tim |
---|
| 19 | # To avoid errors like: '/bin/sh: 1: Syntax error: Bad fd number' |
---|
| 20 | # Make sure that /bin/sh directs to bash and not to dash: |
---|
| 21 | # http://stackoverflow.com/questions/15809060/sh-syntax-error-bad-fd-number |
---|
| 22 | import subprocess as sub |
---|
| 23 | import os |
---|
| 24 | |
---|
| 25 | main = 'model_graphics.py' |
---|
| 26 | |
---|
| 27 | errmsg = ncvar.errormsg |
---|
| 28 | warnmsg = ncvar.warnmsg |
---|
| 29 | |
---|
[1039] | 30 | def verify_configuration(ExpConf, debug): |
---|
| 31 | """ Function to verify mandatory keys from experiment configuration |
---|
| 32 | ExpConf= dictionary with the configuration |
---|
| 33 | """ |
---|
| 34 | fname = 'verify_configuration' |
---|
| 35 | |
---|
| 36 | # List with the mandatory keys |
---|
| 37 | mandatorykeys = ['pyHOME', 'cdoHOME', 'scratch', 'filescratch', 'figscratch', \ |
---|
[1082] | 38 | 'diffscratch', 'figdiffscratch', 'figallmodexpscratch', 'addfiles', \ |
---|
| 39 | 'addfigures', 'adddiffs', 'adddifffigures', 'addallmodexpfigures', 'debug', \ |
---|
[1095] | 40 | 'models', 'modgraphchar', 'expgraphchar', 'ifold', 'ofold', 'warnmsg', \ |
---|
| 41 | 'errmsg', 'titleoperations', 'kindfig', 'CFreftime', 'CFunitstime', 'mapval', \ |
---|
| 42 | 'timekind', 'timefmt', 'timelabel' ] |
---|
[1039] | 43 | |
---|
| 44 | # List with the optional keys |
---|
[1064] | 45 | optionalkeys = ['specificvarplot', 'specificdiffopplot', 'specificdiffvarplot', \ |
---|
| 46 | 'RefProj'] |
---|
[1039] | 47 | |
---|
[1064] | 48 | # Dictionary with the mandatory keys which are required as function of a given |
---|
| 49 | # key from the dictionary |
---|
| 50 | # if [key] must exist [keyB] = [values] |
---|
[1039] | 51 | ifkeys = {'WRFexps': ['models','WRF'], 'LMDZexps': ['models','LMDZ'], \ |
---|
[1290] | 52 | 'WRF_LMDZexps': ['models','WRF_LMDZ'], 'DYNAMICOexps': ['models','DYNAMICO'], \ |
---|
[1431] | 53 | 'mthDYNAMICOexps': ['models','mthDYNAMICO'], \ |
---|
[1290] | 54 | 'WRFheaders': ['models','WRF'], 'WRF_LMDZheaders': ['models','WRF_LMDZ'], \ |
---|
[1431] | 55 | 'LMDZheaders': ['models','LMDZ'], 'DYNAMICOheaders': ['models','DYNAMICO'], \ |
---|
| 56 | 'mthDYNAMICOheaders': ['models','mthDYNAMICO']} |
---|
[1039] | 57 | |
---|
[1064] | 58 | # Dictionary with the optional keys (at least one) which are required as function |
---|
| 59 | # of a given key from the dictionary |
---|
| 60 | # if [key] must exist at least one of the [keyA, keyB, keyC, ...] with values |
---|
[1188] | 61 | ifopkeys = {'RefProj': ['reprojectvar_remapbil', 'reprojectvar_remapbic', \ |
---|
| 62 | 'reprojectvar_remapdis', 'reprojectvar_remapnn', 'reprojectvar_remapcon', \ |
---|
| 63 | 'reprojectvar_remapcon2', 'reprojectvar_remaplaf', 'reprojectvar_dis', \ |
---|
| 64 | 'reprojecvar_dis']} |
---|
[1064] | 65 | |
---|
[1039] | 66 | for kdict in mandatorykeys: |
---|
| 67 | if not ExpConf.has_key(kdict): |
---|
| 68 | print errmsg |
---|
| 69 | print ' ' + fname + "' configuration without required '" + kdict + "' !!" |
---|
| 70 | quit(-1) |
---|
| 71 | if debug: |
---|
| 72 | print ExpConf[kdict] |
---|
| 73 | |
---|
| 74 | for kdict in ifkeys.keys(): |
---|
| 75 | vals = ifkeys[kdict] |
---|
| 76 | keyn = vals[0] |
---|
| 77 | keyv = vals[1] |
---|
| 78 | if type(ExpConf[keyn]) == type('A'): |
---|
| 79 | if not ExpConf.has_key(kdict) and ExpConf[keyn] == keyv: |
---|
| 80 | print errmsg |
---|
| 81 | print ' ' + fname + "' configuration without '" + kdict + \ |
---|
| 82 | "' when it is required with configuration '" + keyn + '=' + keyv + \ |
---|
| 83 | "' !!" |
---|
| 84 | quit(-1) |
---|
| 85 | elif type(ExpConf[keyn]) == type(['A', 'B']): |
---|
| 86 | keyvals = ExpConf[keyn] |
---|
| 87 | if not ExpConf.has_key(kdict) and gen.searchInlist(keyvals, keyv): |
---|
| 88 | print errmsg |
---|
| 89 | print ' ' + fname + "' configuration without '" + kdict + \ |
---|
| 90 | "' when it is required with configuration '" + keyn + '= [..., ' + \ |
---|
| 91 | keyv + ", ...]' !!" |
---|
| 92 | quit(-1) |
---|
| 93 | else: |
---|
| 94 | print errmsg |
---|
| 95 | print ' ' +fname+ 'dictionary type ', type(ExpConf[keyn]), ' not ready!!' |
---|
| 96 | quit(-1) |
---|
| 97 | if debug: |
---|
[1291] | 98 | print ' Experiments configuration _______' |
---|
| 99 | gen.printing_dictionary(ExpConf) |
---|
[1039] | 100 | |
---|
[1064] | 101 | for kdict in ifopkeys.keys(): |
---|
| 102 | if ExpConf.has_key(kdict): |
---|
| 103 | opkeys = ifopkeys[kdict] |
---|
| 104 | hasopkey = False |
---|
| 105 | opdictvals = {} |
---|
| 106 | for opkv in opkeys: |
---|
| 107 | if ExpConf.has_key(opkv): |
---|
| 108 | hasopkey = True |
---|
| 109 | opdictvals[opkv] = ExpConf[opkv] |
---|
| 110 | |
---|
| 111 | if not hasopkey: |
---|
| 112 | print errmsg |
---|
| 113 | print ' ' + fname + "' configuration wit '" + kdict + "' but " + \ |
---|
| 114 | "without any key value:", opkeys, "' when it is required !!" |
---|
| 115 | quit(-1) |
---|
| 116 | |
---|
| 117 | if debug: |
---|
| 118 | print " Optional key '" + kdict + "' with values ________" |
---|
| 119 | gen.printing_dictionary(opdictvals) |
---|
| 120 | |
---|
[1039] | 121 | print fname + ': configuration seems to be fine' |
---|
| 122 | |
---|
| 123 | return |
---|
| 124 | |
---|
[994] | 125 | def scratches(config): |
---|
| 126 | """ Function to set-up if it is needed to start from the scratch |
---|
| 127 | config: dictionary with the configuration |
---|
| 128 | """ |
---|
| 129 | fname = 'scratches' |
---|
| 130 | |
---|
[1371] | 131 | if gen.Str_Bool(config['scratch']): |
---|
[994] | 132 | scr = True |
---|
| 133 | print warnmsg |
---|
[1072] | 134 | print " " + fname + ": starting from the SCRATCH !!" |
---|
[994] | 135 | print " 10 seconds left!!" |
---|
| 136 | filescr = True |
---|
| 137 | figscr = True |
---|
[1031] | 138 | difscr = True |
---|
[1039] | 139 | figdifscr = True |
---|
[1064] | 140 | moddifscr = True |
---|
| 141 | figmoddifscr = True |
---|
[1081] | 142 | figallmodexpscr = True |
---|
[1011] | 143 | tim.sleep(10) |
---|
[994] | 144 | else: |
---|
| 145 | scr = False |
---|
[1371] | 146 | if gen.Str_Bool(config['filescratch']): |
---|
[994] | 147 | filescr = True |
---|
| 148 | print warnmsg |
---|
| 149 | print " " + main + ": files starting from the SCRATCH !!" |
---|
| 150 | print " 5 seconds left!!" |
---|
| 151 | tim.sleep(5) |
---|
| 152 | else: |
---|
| 153 | filescr = False |
---|
| 154 | |
---|
[1371] | 155 | if gen.Str_Bool(config['figscratch']): |
---|
[994] | 156 | figscr = True |
---|
| 157 | print warnmsg |
---|
| 158 | print " " + main + ": figures starting from the SCRATCH !!" |
---|
| 159 | print " 5 seconds left!!" |
---|
| 160 | tim.sleep(5) |
---|
| 161 | else: |
---|
| 162 | figscr = False |
---|
| 163 | |
---|
[1371] | 164 | if gen.Str_Bool(config['diffscratch']): |
---|
[1031] | 165 | difscr = True |
---|
| 166 | print warnmsg |
---|
[1064] | 167 | print " " + main + ": experiment differences starting from the SCRATCH !!" |
---|
[1031] | 168 | print " 5 seconds left!!" |
---|
| 169 | tim.sleep(5) |
---|
| 170 | else: |
---|
| 171 | difscr = False |
---|
| 172 | |
---|
[1371] | 173 | if gen.Str_Bool(config['figdiffscratch']): |
---|
[1039] | 174 | figdifscr = True |
---|
| 175 | print warnmsg |
---|
[1064] | 176 | print " " + main + ": figures experiment differences starting from the SCRATCH !!" |
---|
[1039] | 177 | print " 5 seconds left!!" |
---|
| 178 | tim.sleep(5) |
---|
| 179 | else: |
---|
| 180 | figdifscr = False |
---|
| 181 | |
---|
[1371] | 182 | if gen.Str_Bool(config['moddiffscratch']): |
---|
[1064] | 183 | moddifscr = True |
---|
| 184 | print warnmsg |
---|
| 185 | print " " + main + ": model differences starting from the SCRATCH !!" |
---|
| 186 | print " 5 seconds left!!" |
---|
| 187 | tim.sleep(5) |
---|
| 188 | else: |
---|
| 189 | moddifscr = False |
---|
| 190 | |
---|
[1371] | 191 | if gen.Str_Bool(config['figmoddiffscratch']): |
---|
[1064] | 192 | figmoddifscr = True |
---|
| 193 | print warnmsg |
---|
| 194 | print " " + main + ": figures model differences starting from the SCRATCH !!" |
---|
| 195 | print " 5 seconds left!!" |
---|
| 196 | tim.sleep(5) |
---|
| 197 | else: |
---|
| 198 | figmoddifscr = False |
---|
| 199 | |
---|
[1371] | 200 | if gen.Str_Bool(config['figallmodexpscratch']): |
---|
[1081] | 201 | figallmodexpscr = True |
---|
| 202 | print warnmsg |
---|
| 203 | print " " + main + ": figures all model-experiment starting from the SCRATCH !!" |
---|
| 204 | print " 5 seconds left!!" |
---|
| 205 | tim.sleep(5) |
---|
| 206 | else: |
---|
| 207 | figallmodexpscr = False |
---|
| 208 | |
---|
[1371] | 209 | if gen.Str_Bool(config['addall']): |
---|
[1072] | 210 | print warnmsg |
---|
| 211 | print " " + fname + ": adding new values everywhere !!" |
---|
[994] | 212 | addfils = True |
---|
| 213 | addfigs = True |
---|
[1031] | 214 | adddiffs = True |
---|
[1041] | 215 | adddifffigs = True |
---|
[1064] | 216 | addmoddiffs = True |
---|
| 217 | addmoddifffigs = True |
---|
[1081] | 218 | addallmodexpfigs = True |
---|
[1064] | 219 | else: |
---|
[1371] | 220 | addfils = gen.Str_Bool(config['addfiles']) |
---|
| 221 | addfigs = gen.Str_Bool(config['addfigures']) |
---|
| 222 | adddiffs = gen.Str_Bool(config['adddiffs']) |
---|
| 223 | adddifffigs = gen.Str_Bool(config['adddifffigures']) |
---|
| 224 | addmoddiffs = gen.Str_Bool(config['addmoddiffs']) |
---|
| 225 | addmoddifffigs = gen.Str_Bool(config['addmoddifffigures']) |
---|
| 226 | addallmodexpfigs = gen.Str_Bool(config['addallmodexpfigures']) |
---|
[1064] | 227 | |
---|
[1371] | 228 | debug = gen.Str_Bool(config['debug']) |
---|
[1072] | 229 | |
---|
[1081] | 230 | return scr, filescr, figscr, difscr, figdifscr, moddifscr, figmoddifscr, \ |
---|
| 231 | figallmodexpscr, addfils, addfigs, adddiffs, adddifffigs, addmoddiffs, \ |
---|
[1082] | 232 | addmoddifffigs, addallmodexpfigs, debug |
---|
[994] | 233 | |
---|
[1095] | 234 | |
---|
| 235 | class gc(object): |
---|
| 236 | """ Class which holds all the graphical characteristics |
---|
| 237 | [label]: label as it should appear in the graphics |
---|
| 238 | [color]: specific color of the model |
---|
| 239 | [linetype]: specific type of line of the model |
---|
| 240 | [marker]: specific marker of the model |
---|
| 241 | [sizes]: line width and point size for the model |
---|
| 242 | [tmod]: time modification to apply to the model files (None for nothing) |
---|
| 243 | 'setorigin',[YYYYMMDDHHMISS]: re-set origin of times at [YYYYMMDDHHMISS] |
---|
| 244 | """ |
---|
| 245 | def __init__( self, label, color, linetype, marker, sizes, Tmod): |
---|
| 246 | self.label = None |
---|
| 247 | self.color = None |
---|
| 248 | self.linetype = None |
---|
| 249 | self.marker = None |
---|
| 250 | self.sizes = None |
---|
| 251 | self.tmod = None |
---|
| 252 | if label is not None: |
---|
| 253 | self.label = label |
---|
| 254 | self.color = color |
---|
| 255 | self.linetype = linetype |
---|
| 256 | self.marker = marker |
---|
| 257 | self.sizes = sizes |
---|
| 258 | if Tmod != 'None': |
---|
| 259 | self.tmod = Tmod |
---|
| 260 | |
---|
| 261 | def graphical_characteristics(config, debug): |
---|
| 262 | """ Function to provide the graphical characteristics of models and experiments |
---|
| 263 | config= configuration of the experiment |
---|
| 264 | """ |
---|
| 265 | fname = 'graphical_characteristics' |
---|
| 266 | |
---|
| 267 | modgraphchar = {} |
---|
| 268 | modvals = config['modgraphchar'].split(':') |
---|
| 269 | for modval in modvals: |
---|
| 270 | modv = modval.split('|') |
---|
| 271 | modgraphchar[modv[0]] = gc(modv[1], modv[2], modv[3], modv[4], modv[5], modv[6]) |
---|
| 272 | |
---|
| 273 | expgraphchar = {} |
---|
| 274 | expvals = config['expgraphchar'].split(':') |
---|
| 275 | for expval in expvals: |
---|
| 276 | expvs = expval.split('|') |
---|
| 277 | modexp = expvs[0] + '/' + expvs[1] |
---|
| 278 | if not modgraphchar.has_key(expvs[0]): |
---|
| 279 | print errmsg |
---|
| 280 | print ' ' + fname + ": a model called '" +expvs[0]+ "' does not exist !!" |
---|
| 281 | print ' existing models with graphic characteristics:', \ |
---|
| 282 | modgraphchar.keys() |
---|
| 283 | quit(-1) |
---|
| 284 | |
---|
| 285 | modvs = modgraphchar[expvs[0]] |
---|
| 286 | expv = expvs[2:7] |
---|
| 287 | if expv[1] == 'asmodel': expv[1] = modvs.color |
---|
| 288 | if expv[2] == 'asmodel': expv[2] = modvs.linetype |
---|
| 289 | if expv[3] == 'asmodel': expv[3] = modvs.marker |
---|
| 290 | if expv[4] == 'asmodel': expv[4] = modvs.sizes |
---|
| 291 | |
---|
| 292 | expgraphchar[modexp] = gc(expv[0], expv[1], expv[2], expv[3], expv[4], 'None') |
---|
| 293 | |
---|
| 294 | # Running some tests |
---|
| 295 | mods = config['models'].split(':') |
---|
| 296 | for mod in mods: |
---|
| 297 | if not modgraphchar.has_key(mod): |
---|
| 298 | print errmsg |
---|
| 299 | print ' ' + fname + ": model called '" + mod + "' does not have " + \ |
---|
| 300 | "graphical characteristics !!" |
---|
| 301 | print ' existing models with graphic characteristics:', \ |
---|
| 302 | modgraphchar.keys() |
---|
| 303 | quit(-1) |
---|
| 304 | |
---|
| 305 | exps = config[mod + 'exps'].split(':') |
---|
| 306 | for exp in exps: |
---|
| 307 | modexp = mod + '/' + exp |
---|
| 308 | if not expgraphchar.has_key(modexp): |
---|
| 309 | print errmsg |
---|
| 310 | print ' ' + fname + ": model/experiment called '" + modexp + \ |
---|
| 311 | "' does not have graphical characteristics !!" |
---|
| 312 | print ' existing model/experiments with graphic ' + \ |
---|
| 313 | 'characteristics:', expgraphchar.keys() |
---|
| 314 | quit(-1) |
---|
| 315 | |
---|
| 316 | if debug: |
---|
| 317 | print ' ' + fname + ': model graphical characteristics _______' |
---|
| 318 | for modn in modgraphchar.keys(): |
---|
| 319 | with gen.Capturing() as output: |
---|
| 320 | gen.printing_class(modgraphchar[modn]) |
---|
| 321 | print "'" + modn + "'; " + ', '.join(output) |
---|
| 322 | print ' ' + fname + ': experiment graphical characteristics _______' |
---|
| 323 | for modexpn in expgraphchar.keys(): |
---|
| 324 | with gen.Capturing() as output: |
---|
| 325 | gen.printing_class(expgraphchar[modexpn]) |
---|
| 326 | print "'" + modexpn + "'; " + ', '.join(output) |
---|
| 327 | |
---|
[1394] | 328 | if debug: print " End of '" + fname + "' " |
---|
| 329 | |
---|
[1095] | 330 | return modgraphchar, expgraphchar |
---|
| 331 | |
---|
[994] | 332 | def exp_headers(mod,config): |
---|
| 333 | """ Function to provide the headers and the experiments of a given model |
---|
| 334 | model= model |
---|
| 335 | config= configuration of the experiment |
---|
| 336 | """ |
---|
| 337 | fname = 'exp_headers' |
---|
| 338 | |
---|
| 339 | # No CASE in python! |
---|
| 340 | # case ${mod} in ... |
---|
| 341 | if mod == 'WRF': |
---|
| 342 | expers = config['WRFexps'].split(':') |
---|
| 343 | fhs = config['WRFheaders'].split(':') |
---|
| 344 | elif mod == 'LMDZ': |
---|
| 345 | expers = config['LMDZexps'].split(':') |
---|
| 346 | fhs = config['LMDZheaders'].split(':') |
---|
| 347 | elif mod == 'WRF_LMDZ': |
---|
| 348 | expers = config['WRF_LMDZexps'].split(':') |
---|
| 349 | fhs = config['WRF_LMDZheaders'].split(':') |
---|
[1292] | 350 | elif mod == 'DYNAMICO': |
---|
| 351 | expers = config['DYNAMICOexps'].split(':') |
---|
| 352 | fhs = config['DYNAMICOheaders'].split(':') |
---|
[1420] | 353 | elif mod == 'mthDYNAMICO': |
---|
| 354 | expers = config['mthDYNAMICOexps'].split(':') |
---|
| 355 | fhs = config['mthDYNAMICOheaders'].split(':') |
---|
[994] | 356 | else: |
---|
| 357 | print errmsg |
---|
| 358 | print " " + fname + ": model '" + mod + "' not ready!!" |
---|
| 359 | quit(-1) |
---|
| 360 | |
---|
| 361 | return expers, fhs |
---|
| 362 | |
---|
[1001] | 363 | class VariableInf(object): |
---|
| 364 | """ Class which holds all information of a given variable |
---|
[1227] | 365 | name= CF name of the variabgle |
---|
[1001] | 366 | header= header of the file from which it can be computed |
---|
| 367 | model= file-header variable from which it can be directly computed |
---|
| 368 | diag= file-header diagnostics from which it can be computed |
---|
| 369 | """ |
---|
| 370 | def __init__( self, name, fheader, model, diag): |
---|
| 371 | self.name= None |
---|
| 372 | self.fheader= None |
---|
| 373 | self.model= None |
---|
| 374 | self.diag= None |
---|
| 375 | if name is not None: |
---|
| 376 | self.name = name |
---|
| 377 | self.fheader= fheader |
---|
| 378 | self.model= model |
---|
| 379 | self.diag= diag |
---|
| 380 | |
---|
[1085] | 381 | class ModelInf(object): |
---|
| 382 | """ Class which holds all information from a given model |
---|
| 383 | name= Acronym of the model |
---|
| 384 | model= Long description of the model |
---|
| 385 | dim[x/y/z/t/s]n= name of the dimensions of the model |
---|
| 386 | vdim[x/y/z/t/s]n= name of the variable-dimensions of the model |
---|
| 387 | dimensions= list of the dimensions |
---|
| 388 | vardimensions= list of the variable-dimensions |
---|
[1095] | 389 | timemodif= time modification to apply to the model files ('None' for nothing) |
---|
| 390 | 'setorigin',[YYYYMMDDHHMISS]: re-set origin of times at [YYYYMMDDHHMISS] |
---|
[1085] | 391 | """ |
---|
[1095] | 392 | def __init__( self, name, model, dx, dy, dz, dt, ds, vdx, vdy, vdz, vdt, vds, \ |
---|
| 393 | tmod): |
---|
| 394 | self.name= None |
---|
| 395 | self.model= None |
---|
| 396 | self.dimxn= None |
---|
| 397 | self.dimyn= None |
---|
| 398 | self.dimzn= None |
---|
| 399 | self.dimtn= None |
---|
| 400 | self.dimsn= None |
---|
| 401 | self.vardxn= None |
---|
| 402 | self.vardyn= None |
---|
| 403 | self.vardzn= None |
---|
| 404 | self.vardtn= None |
---|
| 405 | self.vardsn= None |
---|
| 406 | self.timemodif = None |
---|
| 407 | if name is not None: |
---|
| 408 | self.name = name |
---|
| 409 | self.model= model |
---|
| 410 | self.dimxn= dx |
---|
| 411 | self.dimyn= dy |
---|
| 412 | self.dimzn= dz |
---|
| 413 | self.dimtn= dt |
---|
| 414 | self.dimsn= ds |
---|
| 415 | self.vardxn= vdx |
---|
| 416 | self.vardyn= vdy |
---|
| 417 | self.vardzn= vdz |
---|
| 418 | self.vardtn= vdt |
---|
| 419 | self.vardsn= vds |
---|
| 420 | if tmod is not None: |
---|
| 421 | self.timemodif = tmod |
---|
| 422 | self.dimensions = [dx, dy, dz, dt, ds] |
---|
| 423 | self.vardimensions = [vdx, vdy, vdz, vdt, vds] |
---|
[1085] | 424 | |
---|
[1001] | 425 | def variable_compute(idir,var,ftests,db): |
---|
| 426 | """ Function to retrieve the computation way of a given variable using a series of test files |
---|
| 427 | iwdir= directory with the test files |
---|
| 428 | var= name of the variable to test |
---|
| 429 | filtests= dictionary with the test files for each header |
---|
| 430 | """ |
---|
| 431 | fname='variable_compute' |
---|
| 432 | |
---|
| 433 | cancompute = True |
---|
| 434 | for headerf in ftests.keys(): |
---|
| 435 | filen=ftests[headerf] |
---|
[1029] | 436 | try: |
---|
| 437 | with gen.Capturing() as output: |
---|
| 438 | vmod, vdiag = ncvar.computevar_model(var, idir + '/' + filen) |
---|
| 439 | except: |
---|
[1039] | 440 | print errmsg |
---|
[1029] | 441 | print 'ncvar.computevar_model(' + var + ', ' + idir + '/' + filen + ')' |
---|
[1064] | 442 | for s1out in output: print s1out |
---|
[1029] | 443 | quit(-1) |
---|
[1001] | 444 | |
---|
| 445 | if vmod is None and vdiag is None: |
---|
| 446 | cancompute = False |
---|
| 447 | else: |
---|
| 448 | cancompute = True |
---|
| 449 | # Should be considered that variable can also be computed by both ways? |
---|
| 450 | break |
---|
| 451 | |
---|
| 452 | if not cancompute: |
---|
| 453 | print warnmsg |
---|
| 454 | print ' ' + fname + ": there is no way to compute '" + var + \ |
---|
| 455 | "' for model '" + mod |
---|
| 456 | # Too extrict! |
---|
| 457 | # quit(-1) |
---|
| 458 | |
---|
[1011] | 459 | # Getting only the first possibility of model and diagnostic |
---|
| 460 | if vmod is not None: |
---|
| 461 | modV = vmod[0] |
---|
| 462 | else: |
---|
| 463 | modV = None |
---|
[1001] | 464 | if vdiag is not None: |
---|
[1011] | 465 | diagV = vdiag[0] |
---|
[1001] | 466 | else: |
---|
[1011] | 467 | diagV = None |
---|
[1001] | 468 | |
---|
[1011] | 469 | varcomp = VariableInf(var, headerf, modV, diagV) |
---|
| 470 | |
---|
[1001] | 471 | # a ';' list 'varcompute' it is created for each variable giving: |
---|
| 472 | # [var]|[vark]|[headerf][varmod]|[vardiag] |
---|
| 473 | # This list will be used to compute a new file for each variable |
---|
| 474 | |
---|
| 475 | if db: |
---|
| 476 | print 'Variable information _______' |
---|
| 477 | gen.printing_class(varcomp) |
---|
| 478 | |
---|
[1394] | 479 | if db: print " End of '" + fname + "' " |
---|
| 480 | |
---|
[1001] | 481 | return varcomp |
---|
| 482 | |
---|
| 483 | def get_operations_var(vc,db): |
---|
| 484 | """ Function to provide the operations to make for each variable from 'VAR_' dictionary |
---|
| 485 | vc= 'VAR_' dictionary, dictionary with all the parameters started with 'VAR_' |
---|
| 486 | """ |
---|
| 487 | fname = 'get_operations_var' |
---|
| 488 | |
---|
| 489 | LH = len('VAR_') |
---|
| 490 | iop = 1 |
---|
| 491 | # list of operations |
---|
| 492 | doopers = {} |
---|
| 493 | # operations by variable |
---|
| 494 | operationsvar = {} |
---|
| 495 | # individual operations by variable (not repeated) |
---|
| 496 | indivoperationsvar = {} |
---|
| 497 | |
---|
| 498 | # Variables with a calculation whic requires vertical interpolation to all the |
---|
| 499 | # file (operations stating by 'VAR_pinterp') |
---|
| 500 | LVp = len('VAR_pinterp') |
---|
| 501 | varglobalp = [] |
---|
| 502 | |
---|
| 503 | for oper in vc.keys(): |
---|
| 504 | Loper = len(oper) |
---|
| 505 | opn = oper[LH:Loper+1] |
---|
| 506 | vns = vc[oper].split(':') |
---|
| 507 | ops1 = opn.split('+') |
---|
| 508 | doopers[opn] = ops1 |
---|
| 509 | for vn in vns: |
---|
| 510 | if not operationsvar.has_key(vn): |
---|
| 511 | operationsvar[vn] = [opn] |
---|
| 512 | indivoperationsvar[vn] = ops1 |
---|
| 513 | else: |
---|
| 514 | opers = operationsvar[vn] |
---|
| 515 | opers.append(opn) |
---|
| 516 | operationsvar[vn] = opers |
---|
| 517 | opers1 = indivoperationsvar[vn] |
---|
| 518 | for op1 in ops1: |
---|
| 519 | if not gen.searchInlist(opers1, op1): |
---|
| 520 | opers1.append(op1) |
---|
| 521 | indivoperationsvar[vn] = opers1 |
---|
| 522 | |
---|
| 523 | if oper[0:LVp] == 'VAR_pinterp': |
---|
| 524 | for vn in vns: |
---|
| 525 | if not gen.searchInlist(varglobalp,vn): varglobalp.append(vn) |
---|
| 526 | |
---|
| 527 | iop = iop + 1 |
---|
| 528 | |
---|
| 529 | if db: |
---|
| 530 | print ' operations to make _______' |
---|
| 531 | gen.printing_dictionary(doopers) |
---|
| 532 | print ' operations by variable _______' |
---|
| 533 | gen.printing_dictionary(operationsvar) |
---|
| 534 | print ' individual operations by variable _______' |
---|
| 535 | gen.printing_dictionary(indivoperationsvar) |
---|
| 536 | print ' variables with the vertical interpolation for all the file _______' |
---|
| 537 | print ' #', varglobalp |
---|
| 538 | |
---|
[1394] | 539 | if db: print " End of '" + fname + "' " |
---|
| 540 | |
---|
[1001] | 541 | return doopers, operationsvar, indivoperationsvar, varglobalp |
---|
| 542 | |
---|
| 543 | def pinterp_var(oper): |
---|
| 544 | """ Function to retrieve characteristics of the vertical interpolation for the operation |
---|
| 545 | oper= operation |
---|
| 546 | Wether vertical interpolation is: |
---|
| 547 | # 'global': for all file |
---|
| 548 | # 'local': at a given step of the process |
---|
| 549 | # 'none': no vertical interpolation |
---|
| 550 | >>> pinterp_var('last+pinterp+xmean') |
---|
| 551 | local |
---|
| 552 | >>> pinterp_var('pinterp+tmean+xmean') |
---|
| 553 | global |
---|
| 554 | >>> pinterp_var('xmean') |
---|
| 555 | none |
---|
| 556 | """ |
---|
| 557 | fname = 'pinterp_var' |
---|
| 558 | |
---|
| 559 | pinn = 'pinterp' |
---|
| 560 | |
---|
| 561 | Lpinterp = len(pinn) |
---|
| 562 | if oper[0:Lpinterp] == pinn: |
---|
| 563 | pkind = 'global' |
---|
| 564 | return pkind |
---|
| 565 | |
---|
| 566 | if oper.find(pinn) != -1: |
---|
| 567 | pkind = 'local' |
---|
| 568 | else: |
---|
| 569 | pkind = 'none' |
---|
| 570 | |
---|
| 571 | return pkind |
---|
| 572 | |
---|
| 573 | def compvars_listconstruct(config, minf, Files, TestFiles, idir, odir, debug): |
---|
| 574 | """ Function to construct the list of variables to compute |
---|
| 575 | config= dictionary with the configuration of the execution |
---|
| 576 | variables to compute are get with all values started by `VAR_' in 'module_graphics.dat', and then |
---|
| 577 | providing a consecutive number of calculations separated by '+' |
---|
| 578 | VAR_[calc1]+[calc2] = tas:wss |
---|
[1011] | 579 | will compute first [calc1] and then [calc2] for 'tas' and 'wss' |
---|
[1001] | 580 | minf= class with information about the model |
---|
| 581 | Files= dictionary of files for heach header |
---|
| 582 | TestFiles= dictionary of files to test how to compute the variable |
---|
| 583 | odir= output directory |
---|
| 584 | """ |
---|
| 585 | fname='compvars_listconstruct' |
---|
| 586 | |
---|
| 587 | varcomp = gen.get_specdictionary_HMT(config,H='VAR_') |
---|
| 588 | |
---|
| 589 | if debug: |
---|
| 590 | print ' variables to compute ________' |
---|
| 591 | gen.printing_dictionary(varcomp) |
---|
| 592 | |
---|
| 593 | # Getting operations by variable |
---|
| 594 | opers, varoper, indivaroper, varglobp = get_operations_var(varcomp,debug) |
---|
| 595 | |
---|
| 596 | strfiles = gen.dictKeysVals_stringList(Files) |
---|
| 597 | strtestfiles = gen.dictKeysVals_stringList(TestFiles) |
---|
| 598 | |
---|
| 599 | Svarcompute = '' |
---|
| 600 | |
---|
| 601 | # Main dictionary with all the variables and their calculation |
---|
| 602 | allvarcomp = {} |
---|
| 603 | |
---|
| 604 | ivop = 0 |
---|
| 605 | for vn in varoper: |
---|
| 606 | vcomp = variable_compute(idir,vn,TestFiles,False) |
---|
| 607 | for op in varoper[vn]: |
---|
| 608 | # Creation of a String as: [CFname]|[operation]|[fheader]|[vmodel]|[vdiag]|[globalP] |
---|
| 609 | # [CFname]: CF-name of the variable (must appear in 'variables_values.dat') |
---|
| 610 | # [operation]: operation to compute |
---|
| 611 | # [fheader]: header of file with the required variables |
---|
[1025] | 612 | # [vmodel]: Variable from model output |
---|
| 613 | # [vdiag]: Varible as diagnostic from different variables of the model output |
---|
[1001] | 614 | # [globalP]: Wether vertical interpolation is: |
---|
| 615 | # 'global': for all file |
---|
| 616 | # 'local': at a given step of the process |
---|
| 617 | # 'none': no vertical interpolation |
---|
| 618 | globalP = pinterp_var(op) |
---|
| 619 | if vcomp.model is not None: |
---|
[1029] | 620 | if type(vcomp.model) == type(list([1, 2])): |
---|
| 621 | Smodel = ':'.join(vcomp.model) |
---|
| 622 | elif type(vcomp.model) == type('A'): |
---|
| 623 | Smodel = vcomp.model |
---|
[1001] | 624 | else: |
---|
| 625 | Smodel = 'None' |
---|
| 626 | if vcomp.diag is not None: |
---|
[1029] | 627 | if type(vcomp.diag) == type(list([1, 2])): |
---|
| 628 | Sdiag = ':'.join(vcomp.diag) |
---|
| 629 | elif type(vcomp.diag) == type('A'): |
---|
| 630 | Sdiag = vcomp.diag |
---|
[1001] | 631 | else: |
---|
| 632 | Sdiag = 'None' |
---|
| 633 | |
---|
[1158] | 634 | # To get a combination of operations, all the precedent steps are kept |
---|
| 635 | # thus, they are also available ! |
---|
| 636 | seqops = op.split('+') |
---|
| 637 | for seqop in seqops: |
---|
| 638 | if seqop == seqops[0]: seqopS=seqop |
---|
| 639 | else: seqopS = seqopS + '+' + seqop |
---|
| 640 | allvarcomp[vn+'_'+seqopS] = [vcomp.fheader, vcomp.model, vcomp.diag, \ |
---|
| 641 | globalP] |
---|
[1160] | 642 | |
---|
| 643 | Svc = vcomp.name + '|' + seqopS + '|' + vcomp.fheader + '|' + \ |
---|
| 644 | Smodel + '|' + Sdiag + '|' + globalP |
---|
| 645 | if ivop == 0: |
---|
| 646 | Svarcompute = Svc |
---|
| 647 | else: |
---|
| 648 | Svarcompute = Svarcompute + ',' + Svc |
---|
| 649 | |
---|
[1158] | 650 | ivop = ivop + 1 |
---|
[1001] | 651 | |
---|
| 652 | if debug: |
---|
| 653 | print ' Variables to compute _______' |
---|
| 654 | gen.printing_dictionary(allvarcomp) |
---|
| 655 | |
---|
| 656 | # Outwritting the varcompute to avoid next time (if it is not filescratch!) |
---|
[1025] | 657 | objf = open(odir + '/varcompute.inf', 'w') |
---|
[1001] | 658 | objf.write('files: ' + strfiles + '\n') |
---|
| 659 | objf.write('testfiles: ' + strtestfiles + '\n') |
---|
| 660 | objf.write('varcompute: ' + Svarcompute + '\n') |
---|
| 661 | objf.write('itotv: ' + str(ivop) + '\n') |
---|
[1025] | 662 | objf.close() |
---|
[1001] | 663 | |
---|
[1394] | 664 | if debug: print " End of '" + fname + "' " |
---|
| 665 | |
---|
[1001] | 666 | return allvarcomp, ivop |
---|
| 667 | |
---|
| 668 | def read_varcomp_file(filen): |
---|
| 669 | """ Function to read 'varcompute.inf' and reconstruct the dictionaries |
---|
| 670 | """ |
---|
| 671 | fname = 'read_varcomp_file' |
---|
| 672 | |
---|
| 673 | allvarcomp = {} |
---|
| 674 | |
---|
| 675 | objf = open(filen, 'r') |
---|
| 676 | |
---|
| 677 | for line in objf: |
---|
[1064] | 678 | vals = line.replace('\n','').split(' ') |
---|
[1015] | 679 | if vals[0] == 'files:': |
---|
| 680 | Files = gen.stringList_dictKeysVals(vals[1]) |
---|
| 681 | elif vals[0] == 'testfiles:': |
---|
| 682 | TestFiles = gen.stringList_dictKeysVals(vals[1]) |
---|
| 683 | elif vals[0] == 'varcompute:': |
---|
[1022] | 684 | for VvalsS in vals[1].split(','): |
---|
| 685 | |
---|
| 686 | Vvals = VvalsS.split('|') |
---|
| 687 | if Vvals[3] == 'None': |
---|
| 688 | mod = None |
---|
| 689 | else: |
---|
| 690 | mod = Vvals[3].split(':') |
---|
| 691 | if Vvals[4] == 'None': |
---|
| 692 | diag = None |
---|
| 693 | else: |
---|
| 694 | diag = Vvals[4].split(':') |
---|
[1001] | 695 | |
---|
[1158] | 696 | allvarcomp[Vvals[0]+'_'+Vvals[1]] = [Vvals[2], mod, diag, Vvals[5]] |
---|
| 697 | |
---|
| 698 | # # To get a combination of operations, all the precedent steps are kept |
---|
| 699 | # # thus, they are also available ! |
---|
| 700 | # seqops = Vvals[1].split('+') |
---|
| 701 | # for seqop in seqops: |
---|
| 702 | # if seqop == seqops[0]: seqopS=seqop |
---|
| 703 | # else: seqopS = seqopS + '+' + seqop |
---|
| 704 | # allvarcomp[Vvals[0]+'_'+seqopS] = [Vvals[2], mod, diag, Vvals[5]] |
---|
[1015] | 705 | elif vals[0] == 'itotv:': |
---|
[1001] | 706 | ivop = int(vals[1]) |
---|
| 707 | |
---|
| 708 | objf.close() |
---|
| 709 | |
---|
| 710 | return Files, TestFiles, allvarcomp, ivop |
---|
| 711 | |
---|
[1025] | 712 | def pinterpS(gP): |
---|
| 713 | """ For that variables which require vertical interpolation 'p' suffix to the file header is added |
---|
| 714 | gP= kind of pinterp: 'global', 'local', 'none' |
---|
| 715 | """ |
---|
| 716 | fname = 'pinterpS' |
---|
| 717 | |
---|
| 718 | if gP != 'none': |
---|
| 719 | gPS = 'p' |
---|
| 720 | else: |
---|
| 721 | gPS = '' |
---|
| 722 | |
---|
| 723 | return gPS |
---|
| 724 | |
---|
[1011] | 725 | def compute_variable(minf, idir, usefiles, odir, cvar, gP, scr, pyH, Tref, Tunits, db): |
---|
[1001] | 726 | """ Function to compute a variable |
---|
| 727 | minf= class with the information of the model |
---|
| 728 | idir= directory with the input files |
---|
| 729 | usefiles= dictionary of files as dict([headerf]) = [file1], ..., [fileN] |
---|
| 730 | odir= directory to write the output files |
---|
[1011] | 731 | cvar= class with the information of the variable: 'name', 'fheader', 'varmod', 'vardiag' |
---|
[1001] | 732 | gP= kind of vertical interpolation ('global', 'local', 'none') |
---|
[1011] | 733 | scr= should it be done from the scratch? |
---|
| 734 | pyH= location of the python HOME |
---|
| 735 | Tref= CF time reference |
---|
| 736 | Tunits= CF time units |
---|
[1001] | 737 | """ |
---|
| 738 | fname='compute_variable' |
---|
| 739 | |
---|
| 740 | CFvarn=cvar.name |
---|
| 741 | headerf = cvar.fheader |
---|
| 742 | modvar = cvar.model |
---|
| 743 | diagvar = cvar.diag |
---|
| 744 | |
---|
| 745 | cfiles = usefiles[headerf] |
---|
| 746 | |
---|
| 747 | # dimensions |
---|
| 748 | dnx = minf.dimxn |
---|
| 749 | dny = minf.dimyn |
---|
| 750 | # var-dimensions |
---|
| 751 | vdnx = minf.vardxn |
---|
| 752 | vdny = minf.vardyn |
---|
| 753 | |
---|
| 754 | # Computing separately and then joinging for all files |
---|
| 755 | Ntotfiles = len(cfiles) |
---|
[1011] | 756 | Nzeros = len(str(Ntotfiles)) |
---|
| 757 | NStot = str(Ntotfiles).zfill(Nzeros) |
---|
| 758 | # For that variables which require vertical interpolation 'p' suffix to the |
---|
| 759 | # file header is added |
---|
[1025] | 760 | SgP = pinterpS(gP) |
---|
[1011] | 761 | |
---|
| 762 | # Getting in working dir |
---|
| 763 | os.chdir(odir) |
---|
| 764 | |
---|
| 765 | # File to keep track of all operations |
---|
| 766 | otrackf = open( odir + '/all_computevars.inf', 'a') |
---|
| 767 | |
---|
| 768 | # Computing variable |
---|
[1001] | 769 | ifile=1 |
---|
| 770 | for cf in cfiles: |
---|
[1011] | 771 | ifS = str(ifile).zfill(Nzeros) |
---|
| 772 | ifilen = odir + '/' + CFvarn + '_' + headerf + SgP + '_' + ifS + '-' + \ |
---|
| 773 | NStot + '.nc' |
---|
| 774 | fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '.nc' |
---|
[1001] | 775 | |
---|
[1011] | 776 | if scr: |
---|
| 777 | sout = sub.call('rm ' + ifilen + ' >& /dev/null', shell=True) |
---|
| 778 | sout = sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1001] | 779 | |
---|
[1011] | 780 | if not os.path.isfile(ifilen) and not os.path.isfile(fileon): |
---|
| 781 | # Since model direct values are retrieved from `variables_valules.dat' which was |
---|
| 782 | # initially coincived as a way to only give variable attributes, range and color |
---|
| 783 | # bars, if a variable has a diagnostic way to be computed, the later one will be |
---|
| 784 | # preferred |
---|
[1015] | 785 | if db: |
---|
| 786 | print ' ' + fname + ": creation of variable file '" + CFvarn + \ |
---|
| 787 | "' in file '" + ifilen + "' ..." |
---|
[1095] | 788 | print ' model variable:', modvar |
---|
| 789 | print ' diagostic variable:', diagvar |
---|
[1001] | 790 | |
---|
[1031] | 791 | if diagvar is None: |
---|
[1011] | 792 | # model variable |
---|
[1031] | 793 | if db: print ' '+fname+ ": variable direct from model '" +modvar+ "'" |
---|
| 794 | values = modvar + ',0,-1,-1' |
---|
| 795 | vs = modvar + ',' + vdnx + ',' + vdny + ',' + vdnz + ',' + vdnt |
---|
| 796 | |
---|
| 797 | try: |
---|
| 798 | with gen.Capturing() as output: |
---|
[1048] | 799 | ncvar.DataSetSection_multivars(values, idir + '/' + cf, vs) |
---|
[1031] | 800 | except: |
---|
| 801 | print errmsg |
---|
[1048] | 802 | print 'ncvar.DataSetSection_multivars('+values+', '+idir+'/'+cf+ \ |
---|
| 803 | ', '+vs+')' |
---|
[1064] | 804 | for s1out in output: print s1out |
---|
[1031] | 805 | quit(-1) |
---|
| 806 | |
---|
[1011] | 807 | newfile, loc = gen.search_sec_list(output,'succesfull') |
---|
| 808 | ofile = newfile[0].split(' ')[7] |
---|
| 809 | sub.call('mv ' + ofile + ' ' + ifilen, shell=True) |
---|
[1001] | 810 | |
---|
[1011] | 811 | # Keeping track of the operations |
---|
[1048] | 812 | pyins = pyH + "/nc_var.py -f " + idir + '/' + cf + \ |
---|
| 813 | " -o DataSetSection_multivars -v " + vs + " -S '" + values + "'" |
---|
[1011] | 814 | otrackf.write('\n') |
---|
[1031] | 815 | otrackf.write('# ' + CFvarn + " " + modvar + '\n') |
---|
[1048] | 816 | otrackf.write('python ' + pyins + '\n') |
---|
[1001] | 817 | |
---|
[1011] | 818 | # CF renaming of variable |
---|
[1031] | 819 | ncvar.chvarname(CFvarn,ifilen,modvar) |
---|
[1011] | 820 | else: |
---|
| 821 | # diagnostic variable |
---|
[1031] | 822 | if db: print ' '+fname+ ": variable as diagnostic '" +diagvar[0]+ "'" |
---|
[1623] | 823 | if minf.name == 'WRF': |
---|
| 824 | dims = dnt+'@WRFtime,'+dnz+'@'+vdnz+','+dny+'@'+vdny+','+dnx+ \ |
---|
| 825 | '@'+vdnx |
---|
| 826 | else: |
---|
| 827 | dims = dnt+'@'+vdnt+','+dnz+'@'+vdnz+','+dny+'@'+vdny+','+dnx+ \ |
---|
| 828 | '@'+vdnx |
---|
[1011] | 829 | diagn = diagvar[0] |
---|
| 830 | Ndiagvars = len(diagvar) |
---|
| 831 | diagc = '@'.join(diagvar[1:]) |
---|
| 832 | |
---|
[1048] | 833 | values = '-f ' + idir + '/' + cf + " -d '" + dims + "' -v '" + \ |
---|
| 834 | diagn + '|' + diagc + "'" |
---|
[1022] | 835 | try: |
---|
| 836 | with gen.Capturing() as output: |
---|
| 837 | sout = sub.call('python ' +pyH+ '/diagnostics.py ' + values, \ |
---|
| 838 | shell=True) |
---|
| 839 | except: |
---|
[1039] | 840 | print errmsg |
---|
[1022] | 841 | print 'python ' + pyH + '/diagnostics.py ' + values |
---|
[1064] | 842 | for s1out in output: print s1out |
---|
[1022] | 843 | quit(-1) |
---|
| 844 | if db: |
---|
[1064] | 845 | for s1out in output: print s1out |
---|
[1022] | 846 | |
---|
[1011] | 847 | sout = sub.call(' mv diagnostics.nc ' + ifilen, shell=True) |
---|
[1001] | 848 | |
---|
[1011] | 849 | # Keeping track of the operations |
---|
| 850 | pyins = 'python ' + pyH + '/diagnostics.py ' + values |
---|
| 851 | otrackf.write('\n') |
---|
| 852 | otrackf.write('# ' + CFvarn + " " + diagn + '\n') |
---|
| 853 | otrackf.write(pyins + '\n') |
---|
[1001] | 854 | |
---|
[1015] | 855 | # Attaching necessary variables for the pressure interpolation |
---|
| 856 | if gP != 'none': |
---|
[1056] | 857 | if minf.name == 'WRF' or minf.name == 'WRF_LMDZ': |
---|
| 858 | requiredinterpvars = ['P', 'PB', 'PSFC', 'PH', 'PHB', 'HGT', 'T',\ |
---|
| 859 | 'QVAPOR', 'XLONG', 'XLAT', 'Times'] |
---|
| 860 | elif minf.name == 'LMDZ': |
---|
| 861 | requiredinterpvars = ['pres', 'psol', 'geop', 'phis', 'temp', \ |
---|
| 862 | 'ovap', 'lon', 'lat', 'time_counter'] |
---|
[1298] | 863 | elif minf.name == 'DYNAMICO': |
---|
| 864 | requiredinterpvars = ['pres', 'psol', 'geop', 'phis', 'temp', \ |
---|
| 865 | 'ovap', 'lon', 'lat', 'time_counter'] |
---|
[1431] | 866 | elif minf.name == 'mthDYNAMICO': |
---|
| 867 | requiredinterpvars = ['pres', 'psol', 'geop', 'phis', 'temp', \ |
---|
| 868 | 'ovap', 'lon', 'lat', 'time_centered'] |
---|
[1056] | 869 | else: |
---|
| 870 | print errmsg |
---|
| 871 | print fname + ": for model '" + minf.name + "' required " + \ |
---|
| 872 | " variables for vertical interpolation are not known !!" |
---|
| 873 | quit(-1) |
---|
| 874 | |
---|
[1015] | 875 | print " " + fname + ": adding variables:", requiredinterpvars, \ |
---|
| 876 | ' to allow pressure interpolation' |
---|
| 877 | for rqv in requiredinterpvars: |
---|
[1022] | 878 | try: |
---|
| 879 | with gen.Capturing() as output: |
---|
| 880 | ncvar.fvaradd(idir+'/'+cf+','+rqv,ifilen) |
---|
| 881 | except: |
---|
[1039] | 882 | print errmsg |
---|
[1067] | 883 | print 'fvaradd('+idir+'/'+cf+','+rqv+', '+ifilen+')' |
---|
[1064] | 884 | for s1out in output: print s1out |
---|
[1022] | 885 | quit(-1) |
---|
| 886 | if db: |
---|
[1064] | 887 | for s1out in output: print s1out |
---|
[1001] | 888 | |
---|
[1048] | 889 | # CFification of files |
---|
| 890 | if minf.name == 'WRF' or minf.name == 'WRF_LMDZ': |
---|
[1638] | 891 | # Assuming that all diagnostics are outputed with CF-times |
---|
| 892 | values = vdnx + ':' + vdny + ':' + 'time:'+ Tref + ':' + Tunits |
---|
[1048] | 893 | try: |
---|
| 894 | with gen.Capturing() as output: |
---|
[1628] | 895 | ncvar.WRF_to_newCF(values, ifilen, 'all') |
---|
[1629] | 896 | sub.call('mv CF_WRF.nc '+ifilen + ' >& /dev/null', shell=True) |
---|
[1048] | 897 | except: |
---|
| 898 | print errmsg |
---|
[1630] | 899 | print 'WRF_to_newCF('+ values +', ' + ifilen + ',all)' |
---|
[1064] | 900 | for s1out in output: print s1out |
---|
[1270] | 901 | # Removing file in order to make sure that it will be redone |
---|
| 902 | print ' ' + fname + " removing file '" + ifilen + "' ..." |
---|
| 903 | sub.call('rm ' + ifilen + ' >& /dev/null', shell=True) |
---|
[1048] | 904 | quit(-1) |
---|
| 905 | if db: |
---|
[1064] | 906 | for s1out in output: print s1out |
---|
[1048] | 907 | elif minf.name == 'LMDZ': |
---|
| 908 | try: |
---|
| 909 | with gen.Capturing() as output: |
---|
[1095] | 910 | ncvar.LMDZ_toCF(Tunits + '!since!' + Tref, ifilen) |
---|
[1048] | 911 | except: |
---|
| 912 | print errmsg |
---|
[1095] | 913 | print 'LMDZ_toCF('+ Tunits +'!since!'+ Tref + ', ' + ifilen + ')' |
---|
[1064] | 914 | for s1out in output: print s1out |
---|
[1270] | 915 | # Removing file in order to make sure that it will be redone |
---|
| 916 | print ' ' + fname + " removing file '" + ifilen + "' ..." |
---|
| 917 | sub.call('rm ' + ifilen + ' >& /dev/null', shell=True) |
---|
[1048] | 918 | quit(-1) |
---|
| 919 | if db: |
---|
[1064] | 920 | for s1out in output: print s1out |
---|
[1294] | 921 | # At this stage, let's be simple. It might be necessary to complicate it! Since |
---|
| 922 | # DYNAMICO might have 'time_counter' or 'time_instant' |
---|
[1422] | 923 | elif minf.name == 'DYNAMICO': |
---|
[1294] | 924 | try: |
---|
| 925 | with gen.Capturing() as output: |
---|
[1296] | 926 | ncvar.DYNAMICO_toCF(Tunits + '!since!' + Tref, ifilen) |
---|
[1294] | 927 | except: |
---|
| 928 | print errmsg |
---|
[1296] | 929 | print 'DYNAMICO_toCF('+Tunits+'!since!'+Tref+ ', ' + ifilen + ')' |
---|
[1294] | 930 | for s1out in output: print s1out |
---|
| 931 | # Removing file in order to make sure that it will be redone |
---|
| 932 | print ' ' + fname + " removing file '" + ifilen + "' ..." |
---|
| 933 | sub.call('rm ' + ifilen + ' >& /dev/null', shell=True) |
---|
| 934 | quit(-1) |
---|
| 935 | if db: |
---|
| 936 | for s1out in output: print s1out |
---|
[1422] | 937 | elif minf.name == 'mthDYNAMICO': |
---|
| 938 | try: |
---|
| 939 | with gen.Capturing() as output: |
---|
| 940 | ncvar.mthDYNAMICO_toCF(Tunits + '!since!' + Tref, ifilen) |
---|
| 941 | except: |
---|
| 942 | print errmsg |
---|
| 943 | print 'mthDYNAMICO_toCF('+Tunits+'!since!'+Tref+ ', ' + ifilen + ')' |
---|
| 944 | for s1out in output: print s1out |
---|
| 945 | # Removing file in order to make sure that it will be redone |
---|
| 946 | print ' ' + fname + " removing file '" + ifilen + "' ..." |
---|
| 947 | sub.call('rm ' + ifilen + ' >& /dev/null', shell=True) |
---|
| 948 | quit(-1) |
---|
| 949 | if db: |
---|
| 950 | for s1out in output: print s1out |
---|
[1048] | 951 | else: |
---|
| 952 | print errmsg |
---|
| 953 | print ' ' + fname + ": no CFification for model '" +minf.name+ "' !!" |
---|
[1424] | 954 | print " available ones: 'WRF', 'WRF_LMDZ', 'LMDZ', 'DYNAMICO'" + \ |
---|
| 955 | ", 'mthDYNAMICO'" |
---|
[1048] | 956 | quit(-1) |
---|
| 957 | |
---|
[1011] | 958 | ifile = ifile + 1 |
---|
[1001] | 959 | |
---|
[1011] | 960 | otrackf.close() |
---|
[1001] | 961 | |
---|
[1011] | 962 | # Joining variable files |
---|
| 963 | if not os.path.isfile(fileon): |
---|
[1297] | 964 | if Ntotfiles > 1: |
---|
| 965 | if db: |
---|
| 966 | print ' ' + fname + ": concatenating all variable files to " + \ |
---|
| 967 | "create '" + fileon + "..." |
---|
| 968 | try: |
---|
| 969 | with gen.Capturing() as output: |
---|
[1643] | 970 | ncvar.netcdf_fold_concatenation_HMT(odir+',time,time', CFvarn + \ |
---|
[1640] | 971 | '_' + headerf + SgP +'_,-,.nc', 'all') |
---|
[1297] | 972 | except: |
---|
| 973 | print errmsg |
---|
[1643] | 974 | print 'netcdf_fold_concatenation_HMT('+odir+',time,time ' + CFvarn + \ |
---|
[1640] | 975 | '_' + headerf +SgP + '_,-,.nc, all)' |
---|
[1297] | 976 | for s1out in output: print s1out |
---|
| 977 | quit(-1) |
---|
| 978 | if db: |
---|
| 979 | for s1out in output: print s1out |
---|
[1022] | 980 | |
---|
[1297] | 981 | sout = sub.call('mv netcdf_fold_concatenated_HMT.nc '+fileon, shell=True) |
---|
| 982 | if os.path.isfile(fileon): |
---|
| 983 | sout = sub.call('rm '+CFvarn + '_' + headerf + SgP + '_*-*.nc >& ' + \ |
---|
| 984 | '/dev/null', shell=True) |
---|
| 985 | else: |
---|
| 986 | sout = sub.call('mv ' + CFvarn + '_' + headerf + SgP + '_1-1.nc ' + \ |
---|
| 987 | fileon, shell=True) |
---|
[1001] | 988 | |
---|
[1095] | 989 | # Re-setting time of final concatenated file |
---|
| 990 | if minf.timemodif is not None: |
---|
| 991 | if db: |
---|
| 992 | print ' ' + fname + ": Modifying times of the file by '" + \ |
---|
| 993 | minf.timemodif + "' !!" |
---|
| 994 | try: |
---|
| 995 | with gen.Capturing() as output: |
---|
| 996 | ncvar.time_reset(minf.timemodif, fileon,'time') |
---|
| 997 | except: |
---|
| 998 | print errmsg |
---|
| 999 | print 'time_reset(' + minf.timemodif + ', ' + fileon + ', time)' |
---|
| 1000 | for s1out in output: print s1out |
---|
[1270] | 1001 | # Removing file in order to make sure that it will be redone |
---|
| 1002 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 1003 | sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1095] | 1004 | quit(-1) |
---|
| 1005 | if db: |
---|
| 1006 | for s1out in output: print s1out |
---|
| 1007 | |
---|
[1394] | 1008 | if db: print " End of '" + fname + "' " |
---|
| 1009 | |
---|
[1011] | 1010 | return |
---|
| 1011 | |
---|
[1015] | 1012 | def compute_statistics(minf, config, idir, usefiles, odir, cvar, gP, Opers, scr, db): |
---|
[1011] | 1013 | """ Function to compute different statistics it will take previous steps if they |
---|
| 1014 | are availale |
---|
| 1015 | minf= class with the information of the model |
---|
[1015] | 1016 | config= dictionary with the configuration of the experiment |
---|
[1011] | 1017 | idir= directory with the input files |
---|
| 1018 | usefiles= ',' list of files to use [file1],...,[fileN] |
---|
| 1019 | odir= directory to write the output files |
---|
| 1020 | cvar= class with the information of the variable: 'name', 'fheader', 'varmod', 'vardiag' |
---|
| 1021 | gP= kind of vertical interpolation ('global', 'local', 'none') |
---|
| 1022 | Opers= kind of operation: (as possible multiple consecutive combination of operations separated by '+' |
---|
| 1023 | [calc1]+[calc2] will compute first [calc1] and then [calc2] |
---|
| 1024 | acc: temporal accumulated values |
---|
| 1025 | diff: differences between models |
---|
| 1026 | direct: no statistics |
---|
| 1027 | last: last temporal value |
---|
| 1028 | Lmean: latitudinal mean values |
---|
| 1029 | Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) |
---|
| 1030 | lmean: longitudinal mean values |
---|
| 1031 | lsec: longitudinal section (longitudinal value must be given, [var]@[lat]) |
---|
| 1032 | pinterp: pressure interpolation (to the given $plevels) |
---|
[1371] | 1033 | smean: spatial-weighted mean values |
---|
[1011] | 1034 | tmean: temporal mean values |
---|
[1041] | 1035 | tstd: temporal standard deviation values |
---|
[1104] | 1036 | tturb: Taylor's turbulence decomposition value (x - <x>) for time |
---|
| 1037 | tvar: temporal variance values |
---|
[1011] | 1038 | xmean: x-axis mean values |
---|
[1078] | 1039 | xvar: x-axis variance values |
---|
[1011] | 1040 | ymean: y-axis mean values |
---|
| 1041 | zsum: vertical aggregated values |
---|
| 1042 | scr= should it be done from the scratch? |
---|
| 1043 | """ |
---|
| 1044 | fname='compute_statistics' |
---|
| 1045 | |
---|
| 1046 | # Getting a previous file name to continue with(for combinations) |
---|
| 1047 | CFvarn=cvar.name |
---|
| 1048 | headerf = cvar.fheader |
---|
| 1049 | modvar = cvar.model |
---|
| 1050 | diagvar = cvar.diag |
---|
| 1051 | |
---|
| 1052 | cfiles = usefiles[headerf] |
---|
| 1053 | |
---|
| 1054 | # dimensions |
---|
| 1055 | dnx = minf.dimxn |
---|
| 1056 | dny = minf.dimyn |
---|
| 1057 | # var-dimensions |
---|
| 1058 | vdnx = minf.vardxn |
---|
| 1059 | vdny = minf.vardyn |
---|
[1022] | 1060 | # Model dimension-variable dictionary |
---|
| 1061 | Modeldimvardict = {dnx: vdnx, dny: vdny, dnz: vdnz, dnt: vdnt} |
---|
[1011] | 1062 | |
---|
[1015] | 1063 | # Some experiment configuration values |
---|
| 1064 | # plevels= ':' separated list of pressures (in Pa) to use for the vertical interpolation |
---|
| 1065 | plevels = config['plevels'] |
---|
| 1066 | # pyH= location of the python HOME |
---|
| 1067 | pyH = config['pyHOME'] |
---|
| 1068 | # Tref= CF time reference |
---|
| 1069 | Tref = config['CFreftime'] |
---|
| 1070 | # Tunits= CF time units |
---|
| 1071 | Tunits = config['CFunitstime'] |
---|
| 1072 | # opsur = operation surnames |
---|
| 1073 | opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') |
---|
| 1074 | Opsurs = {} |
---|
| 1075 | for opk in opsur: |
---|
| 1076 | opn = opk.split('_')[1] |
---|
| 1077 | vals = opsur[opk] |
---|
| 1078 | Opsurs[opn] = vals.split(':') |
---|
[1025] | 1079 | # if db: |
---|
| 1080 | # print ' ' + fname + ' operation surnames _______' |
---|
| 1081 | # gen.printing_dictionary(Opsurs) |
---|
[1011] | 1082 | |
---|
| 1083 | # Getting in working dir |
---|
| 1084 | os.chdir(odir) |
---|
| 1085 | |
---|
| 1086 | # File to keep track of all operations |
---|
| 1087 | otrackf = open( odir + '/all_statsvars.inf', 'a') |
---|
| 1088 | |
---|
[1015] | 1089 | # For that variables which require vertical interpolation 'p' suffix to the file |
---|
[1022] | 1090 | # header is added. |
---|
| 1091 | # After some operations some CF dimension-variables might not be kept |
---|
| 1092 | |
---|
[1015] | 1093 | if gP != 'none': |
---|
| 1094 | SgP = 'p' |
---|
| 1095 | varnCFs = ['lon', 'lat', 'pres', 'time'] |
---|
| 1096 | else: |
---|
| 1097 | SgP = '' |
---|
| 1098 | varnCFs = ['lon', 'lat', 'time'] |
---|
| 1099 | |
---|
[1022] | 1100 | # CF dimension-variable dictionary |
---|
| 1101 | CFdimvardict = {'lon': 'lon', 'lat': 'lat', 'pres': 'pres', 'time': 'time'} |
---|
[1015] | 1102 | |
---|
[1011] | 1103 | # Input file |
---|
| 1104 | ifilen = odir + '/' + CFvarn + '_' + headerf + SgP + '.nc' |
---|
| 1105 | |
---|
| 1106 | # Computing variable statisitcs |
---|
| 1107 | istats=0 |
---|
| 1108 | |
---|
| 1109 | # List of not computed statistics |
---|
| 1110 | wrongstats = [] |
---|
| 1111 | |
---|
| 1112 | opers = Opers.split('+') |
---|
| 1113 | Fopers = '' |
---|
[1022] | 1114 | if db: print " computing statistics of variable:'", CFvarn, "' operation '" + \ |
---|
[1193] | 1115 | Opers + "' using file '" + ifilen + "...'" |
---|
[1011] | 1116 | for op in opers: |
---|
[1015] | 1117 | |
---|
[1022] | 1118 | # File name from previous operations, and name of the variable within the |
---|
| 1119 | # file (some operations change the name of the variable) |
---|
[1011] | 1120 | if op == opers[0]: |
---|
| 1121 | Fopers = op |
---|
| 1122 | prevfile = ifilen |
---|
[1015] | 1123 | vninF = CFvarn |
---|
[1011] | 1124 | else: |
---|
| 1125 | Fopers = Fopers + '_' + op |
---|
| 1126 | prevfile = fileon |
---|
| 1127 | fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '_' + Fopers + '.nc' |
---|
| 1128 | |
---|
[1015] | 1129 | # Adding required variables for the vertical interpolation in all operations |
---|
[1022] | 1130 | SvarnCFs = ',' + ','.join(varnCFs) |
---|
| 1131 | |
---|
[1015] | 1132 | if gP != 'none': |
---|
| 1133 | if gP == 'local': |
---|
[1022] | 1134 | CFvarnp = vninF + ',P,PB,PSFC,PH,PHB,HGT,T,QVAPOR,XLONG,XLAT,Times'+ \ |
---|
| 1135 | SvarnCFs |
---|
[1015] | 1136 | else: |
---|
| 1137 | CFvarnp = vninF + SvarnCFs |
---|
| 1138 | else: |
---|
| 1139 | CFvarnp = vninF + SvarnCFs |
---|
| 1140 | |
---|
[1011] | 1141 | if scr: |
---|
| 1142 | sout = sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
| 1143 | |
---|
| 1144 | hprevfile = prevfile[0:len(prevfile)-3] |
---|
[1022] | 1145 | |
---|
| 1146 | if db: print ' ', op, "using '" + prevfile + "' " |
---|
| 1147 | # Just produce file in case output file does not exist |
---|
[1011] | 1148 | if not os.path.isfile(fileon): |
---|
[1022] | 1149 | if db: |
---|
| 1150 | print ' ' + fname + ": creation of file '" + fileon + "' ..." |
---|
| 1151 | dofile = True |
---|
| 1152 | else: |
---|
| 1153 | dofile = False |
---|
[1011] | 1154 | |
---|
[1022] | 1155 | # Variables to be kept in the final file |
---|
| 1156 | varkeep = [] |
---|
| 1157 | |
---|
| 1158 | if op == 'acc': |
---|
| 1159 | # temporal accumulated values |
---|
| 1160 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
[1036] | 1161 | wrongstats.append(CFvarn + '_' + opers) |
---|
[1022] | 1162 | break |
---|
[1363] | 1163 | |
---|
| 1164 | elif op[0:11] == 'dimvarvalue': |
---|
| 1165 | # Slicing along the index at the nearest given value of a dimension-variable |
---|
| 1166 | dimvarn = op.split('~')[1] |
---|
| 1167 | dimvalue = op.split('~')[2] |
---|
| 1168 | vals = dimvarn + ',' + dimvalue + ',' + dimvalue + ',0' |
---|
| 1169 | if dofile: |
---|
| 1170 | try: |
---|
| 1171 | with gen.Capturing() as output: |
---|
| 1172 | ncvar.DataSetSection_multivars(vals,prevfile,CFvarnp) |
---|
| 1173 | except: |
---|
| 1174 | print errmsg |
---|
| 1175 | print 'DataSetSection_multivars('+vals+',', prevfile, ',' + \ |
---|
| 1176 | CFvarnp + ')' |
---|
| 1177 | for s1out in output: print s1out |
---|
| 1178 | quit(-1) |
---|
| 1179 | |
---|
| 1180 | if db: |
---|
| 1181 | for s1out in output: print s1out |
---|
| 1182 | |
---|
| 1183 | sout = sub.call('mv DataSetSection_multivars.nc '+fileon, shell=True) |
---|
| 1184 | |
---|
| 1185 | # Keeping the operations |
---|
| 1186 | pyins=pyH + "/nc_var.py -o DataSetSection_multivars -S '" + vals + \ |
---|
| 1187 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1188 | otrackf.write("\n") |
---|
| 1189 | otrackf.write("# " + CFvarnp + " " + Fopers + "\n") |
---|
| 1190 | otrackf.write(pyins + "\n") |
---|
| 1191 | |
---|
| 1192 | # removing the given variable-dimension |
---|
| 1193 | varnCFs.remove(dimvarn) |
---|
| 1194 | |
---|
[1022] | 1195 | elif op == 'direct': |
---|
| 1196 | # no statistics |
---|
| 1197 | if dofile: |
---|
[1011] | 1198 | sout = sub.call('mv ' + prevfile + ' ' + fileon, shell=True) |
---|
[1022] | 1199 | elif op == 'last': |
---|
| 1200 | # last temporal value |
---|
| 1201 | vals='time,-9,0,0' |
---|
| 1202 | if dofile: |
---|
| 1203 | try: |
---|
| 1204 | with gen.Capturing() as output: |
---|
| 1205 | ncvar.DataSetSection(vals,prevfile) |
---|
| 1206 | except: |
---|
[1039] | 1207 | print errmsg |
---|
[1022] | 1208 | print 'DataSetSection('+vals+',', prevfile, ')' |
---|
[1064] | 1209 | for s1out in output: print s1out |
---|
[1022] | 1210 | quit(-1) |
---|
| 1211 | |
---|
| 1212 | if db: |
---|
[1064] | 1213 | for s1out in output: print s1out |
---|
[1011] | 1214 | |
---|
| 1215 | sout = sub.call('mv ' + hprevfile + '_time_B-9-E0-I0.nc ' + fileon, \ |
---|
| 1216 | shell=True) |
---|
| 1217 | |
---|
| 1218 | # Keeping the operations |
---|
| 1219 | pyins=pyH + "/nc_var.py -o DataSetSection -S '" + vals + "' -f " + \ |
---|
| 1220 | prevfile |
---|
| 1221 | otrackf.write("\n") |
---|
| 1222 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1223 | otrackf.write(pyins + "\n") |
---|
[1022] | 1224 | |
---|
| 1225 | elif op =='Lmean': |
---|
| 1226 | # latitudinal mean values |
---|
| 1227 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
[1036] | 1228 | wrongstats.append(CFvarn + '_' + opers) |
---|
[1022] | 1229 | break |
---|
| 1230 | elif op =='Lsec': |
---|
| 1231 | # latitudinal section (latitudinal value must be given, [var]@[lat]) |
---|
| 1232 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
[1036] | 1233 | wrongstats.append(CFvarn + '_' + opers) |
---|
[1022] | 1234 | break |
---|
| 1235 | elif op =='lmean': |
---|
| 1236 | # longitudinal mean values |
---|
| 1237 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
[1036] | 1238 | wrongstats.append(CFvarn + '_' + opers) |
---|
[1022] | 1239 | break |
---|
| 1240 | elif op =='lsec': |
---|
| 1241 | # longitudinal section (longitudinal value must be given, [var]@[lon]) |
---|
| 1242 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
[1036] | 1243 | wrongstats.append(CFvarn + '_' + opers) |
---|
[1022] | 1244 | break |
---|
| 1245 | elif op == 'pinterp': |
---|
| 1246 | # pinterp: pressure interpolation (to the given $plevels) |
---|
| 1247 | vals=plevels + ',1,1' |
---|
| 1248 | if dofile: |
---|
| 1249 | try: |
---|
| 1250 | with gen.Capturing() as output: |
---|
| 1251 | ncvar.pinterp(vals,prevfile,vninF) |
---|
| 1252 | except: |
---|
[1039] | 1253 | print errmsg |
---|
[1022] | 1254 | print 'pinterp('+vals+',', prevfile, ','+vninF+')' |
---|
[1064] | 1255 | for s1out in output: print s1out |
---|
[1300] | 1256 | ncvar.pinterp(vals,prevfile,vninF) |
---|
[1022] | 1257 | quit(-1) |
---|
| 1258 | |
---|
| 1259 | if db: |
---|
[1064] | 1260 | for s1out in output: print s1out |
---|
[1022] | 1261 | |
---|
[1015] | 1262 | sout = sub.call('mv pinterp.nc ' + fileon, shell=True) |
---|
[1011] | 1263 | |
---|
| 1264 | # Keeping the operations |
---|
| 1265 | pyins=pyH + "/nc_var.py -o pinterp -S '" + vals + "' -f " + \ |
---|
[1015] | 1266 | prevfile + "-v " + vninF |
---|
[1011] | 1267 | otrackf.write("\n") |
---|
| 1268 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1269 | otrackf.write(pyins + "\n") |
---|
| 1270 | |
---|
| 1271 | # adding CF lon,lat,time in WRF files |
---|
[1270] | 1272 | if minf.name == 'WRF' or minf.name == 'WRF_LMDZ': |
---|
[1011] | 1273 | values = vdnx + ':' + vdny + ':'+ Tref + ':' + Tunits |
---|
[1287] | 1274 | if db: |
---|
| 1275 | print " CFification of '" + fileon + "' with:", values, "..." |
---|
[1270] | 1276 | try: |
---|
| 1277 | with gen.Capturing() as output: |
---|
| 1278 | ncvar.WRF_toCF(values, fileon) |
---|
| 1279 | except: |
---|
| 1280 | print errmsg |
---|
| 1281 | print 'ncvar.WRF_toCF(' + values+ ', ' + fileon + ')' |
---|
| 1282 | for s1out in output: print s1out |
---|
| 1283 | # Removing file in order to make sure that it will be redone |
---|
| 1284 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 1285 | sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
| 1286 | quit(-1) |
---|
[1011] | 1287 | |
---|
[1022] | 1288 | # vertical interpolation variables are no more needed |
---|
| 1289 | CFvarnp = vninF |
---|
| 1290 | gP = 'none' |
---|
[1011] | 1291 | |
---|
[1371] | 1292 | elif op == 'smean': |
---|
| 1293 | # spatial-weighted mean values |
---|
| 1294 | noLlvdims = list(varnCFs) |
---|
| 1295 | noLlvdims.remove('lon') |
---|
| 1296 | noLlvdims.remove('lat') |
---|
| 1297 | Saddvars = ':'.join(noLlvdims) |
---|
| 1298 | if len(Saddvars) > 1: |
---|
| 1299 | vals = 'reglonlat,lon,lat,lon,lat,' + Saddvars |
---|
| 1300 | else: |
---|
| 1301 | vals = 'reglonlat,lon,lat,lon,lat,None' |
---|
| 1302 | |
---|
| 1303 | if dofile: |
---|
| 1304 | try: |
---|
| 1305 | with gen.Capturing() as output: |
---|
| 1306 | ncvar.SpatialWeightedMean(vals,prevfile,vninF) |
---|
| 1307 | except: |
---|
| 1308 | print errmsg |
---|
| 1309 | print 'SpatialWeightedMean('+vals+',', prevfile, ','+vninF+')' |
---|
| 1310 | for s1out in output: print s1out |
---|
| 1311 | quit(-1) |
---|
| 1312 | |
---|
| 1313 | if db: |
---|
| 1314 | for s1out in output: print s1out |
---|
| 1315 | |
---|
| 1316 | # renaming variable |
---|
| 1317 | ncvar.chvarname(vninF+'mean', 'SpatialWeightedMean_reglonlat.nc', \ |
---|
| 1318 | vninF+'spaceweightmean') |
---|
| 1319 | sout = sub.call('mv SpatialWeightedMean_reglonlat.nc '+fileon, \ |
---|
| 1320 | shell=True) |
---|
| 1321 | |
---|
| 1322 | # Keeping the operations |
---|
| 1323 | pyins=pyH + "/nc_var.py -o SpatialWeightedMean -S '" + vals + \ |
---|
| 1324 | "' -f " + prevfile + " -v " + vninF |
---|
| 1325 | otrackf.write("\n") |
---|
| 1326 | otrackf.write("# " + vninF + " " + Fopers + "\n") |
---|
| 1327 | otrackf.write(pyins + "\n") |
---|
| 1328 | |
---|
| 1329 | # removing dimension variable-dimension 'lon', 'lat' |
---|
| 1330 | varnCFs.remove('lon') |
---|
| 1331 | varnCFs.remove('lat') |
---|
| 1332 | |
---|
| 1333 | varkeep.append(vninF + 'mean') |
---|
| 1334 | |
---|
[1022] | 1335 | elif op == 'tmean': |
---|
| 1336 | # temporal mean values |
---|
| 1337 | vals='time|-1,time,mean,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 1338 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 1339 | if dofile: |
---|
| 1340 | try: |
---|
| 1341 | with gen.Capturing() as output: |
---|
| 1342 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 1343 | except: |
---|
[1039] | 1344 | print errmsg |
---|
[1022] | 1345 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 1346 | for s1out in output: print s1out |
---|
[1022] | 1347 | quit(-1) |
---|
| 1348 | |
---|
| 1349 | if db: |
---|
[1064] | 1350 | for s1out in output: print s1out |
---|
[1022] | 1351 | |
---|
[1011] | 1352 | sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True) |
---|
| 1353 | |
---|
| 1354 | # Keeping the operations |
---|
| 1355 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 1356 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1357 | otrackf.write("\n") |
---|
| 1358 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1359 | otrackf.write(pyins + "\n") |
---|
| 1360 | |
---|
[1022] | 1361 | # removing dimension variable-dimension 'time' |
---|
| 1362 | varnCFs.remove('time') |
---|
[1011] | 1363 | |
---|
[1022] | 1364 | varkeep.append('timestats') |
---|
[1011] | 1365 | |
---|
[1041] | 1366 | elif op == 'tstd': |
---|
| 1367 | # temporal standard deviation values |
---|
| 1368 | vals='time|-1,time,std,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 1369 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 1370 | if dofile: |
---|
| 1371 | try: |
---|
| 1372 | with gen.Capturing() as output: |
---|
| 1373 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 1374 | except: |
---|
| 1375 | print errmsg |
---|
| 1376 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 1377 | for s1out in output: print s1out |
---|
[1041] | 1378 | quit(-1) |
---|
| 1379 | |
---|
| 1380 | if db: |
---|
[1064] | 1381 | for s1out in output: print s1out |
---|
[1041] | 1382 | |
---|
| 1383 | sout = sub.call('mv file_oper_alongdims_std.nc '+fileon, shell=True) |
---|
| 1384 | |
---|
| 1385 | # Keeping the operations |
---|
| 1386 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 1387 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1388 | otrackf.write("\n") |
---|
| 1389 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1390 | otrackf.write(pyins + "\n") |
---|
| 1391 | |
---|
| 1392 | # removing dimension variable-dimension 'time' |
---|
| 1393 | varnCFs.remove('time') |
---|
| 1394 | |
---|
| 1395 | varkeep.append('timestats') |
---|
| 1396 | |
---|
[1104] | 1397 | elif op == 'tturb': |
---|
| 1398 | # temporal turbulent values |
---|
| 1399 | vals='time|-1,time,turb,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 1400 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 1401 | if dofile: |
---|
| 1402 | try: |
---|
| 1403 | with gen.Capturing() as output: |
---|
| 1404 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 1405 | except: |
---|
| 1406 | print errmsg |
---|
| 1407 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
| 1408 | for s1out in output: print s1out |
---|
| 1409 | quit(-1) |
---|
[1011] | 1410 | |
---|
[1104] | 1411 | if db: |
---|
| 1412 | for s1out in output: print s1out |
---|
[1043] | 1413 | |
---|
[1104] | 1414 | sout = sub.call('mv file_oper_alongdims_turb.nc '+fileon, shell=True) |
---|
[1043] | 1415 | |
---|
[1104] | 1416 | # Keeping the operations |
---|
| 1417 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 1418 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1419 | otrackf.write("\n") |
---|
| 1420 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1421 | otrackf.write(pyins + "\n") |
---|
[1011] | 1422 | |
---|
[1104] | 1423 | # removing dimension variable-dimension 'time' |
---|
| 1424 | varkeep.append('timestats') |
---|
[1022] | 1425 | |
---|
[1043] | 1426 | elif op == 'tvar': |
---|
| 1427 | # temporal variance values (Taylor's turbulence) |
---|
| 1428 | vals='time|-1,time,var,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 1429 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 1430 | if dofile: |
---|
| 1431 | try: |
---|
| 1432 | with gen.Capturing() as output: |
---|
| 1433 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 1434 | except: |
---|
| 1435 | print errmsg |
---|
| 1436 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 1437 | for s1out in output: print s1out |
---|
[1043] | 1438 | quit(-1) |
---|
| 1439 | |
---|
| 1440 | if db: |
---|
[1064] | 1441 | for s1out in output: print s1out |
---|
[1043] | 1442 | |
---|
| 1443 | sout = sub.call('mv file_oper_alongdims_var.nc '+fileon, shell=True) |
---|
| 1444 | |
---|
| 1445 | # Keeping the operations |
---|
| 1446 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 1447 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1448 | otrackf.write("\n") |
---|
| 1449 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1450 | otrackf.write(pyins + "\n") |
---|
| 1451 | |
---|
| 1452 | # removing dimension variable-dimension 'time' |
---|
| 1453 | varnCFs.remove('time') |
---|
| 1454 | |
---|
| 1455 | varkeep.append('timestats') |
---|
| 1456 | |
---|
[1022] | 1457 | elif op == 'xmean': |
---|
| 1458 | # x-axis mean values |
---|
| 1459 | vals='lon|-1,lon,mean,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 1460 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 1461 | if dofile: |
---|
| 1462 | try: |
---|
| 1463 | with gen.Capturing() as output: |
---|
| 1464 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 1465 | except: |
---|
[1039] | 1466 | print errmsg |
---|
[1022] | 1467 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 1468 | for s1out in output: print s1out |
---|
[1022] | 1469 | quit(-1) |
---|
| 1470 | |
---|
| 1471 | if db: |
---|
[1064] | 1472 | for s1out in output: print s1out |
---|
[1022] | 1473 | |
---|
[1011] | 1474 | sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True) |
---|
| 1475 | |
---|
| 1476 | # Keeping the operations |
---|
| 1477 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 1478 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1479 | otrackf.write("\n") |
---|
| 1480 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1481 | otrackf.write(pyins + "\n") |
---|
| 1482 | |
---|
[1056] | 1483 | # removing dimension variable-dimension 'lon' |
---|
| 1484 | varnCFs.remove('lon') |
---|
| 1485 | |
---|
[1022] | 1486 | varkeep.append('lonstats') |
---|
[1011] | 1487 | |
---|
[1078] | 1488 | elif op == 'xvar': |
---|
| 1489 | # x-axis variance values |
---|
| 1490 | vals='lon|-1,lon,var,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 1491 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 1492 | if dofile: |
---|
| 1493 | try: |
---|
| 1494 | with gen.Capturing() as output: |
---|
| 1495 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 1496 | except: |
---|
| 1497 | print errmsg |
---|
| 1498 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
| 1499 | for s1out in output: print s1out |
---|
| 1500 | quit(-1) |
---|
| 1501 | |
---|
| 1502 | if db: |
---|
| 1503 | for s1out in output: print s1out |
---|
| 1504 | |
---|
| 1505 | sout = sub.call('mv file_oper_alongdims_var.nc '+fileon, shell=True) |
---|
| 1506 | |
---|
| 1507 | # Keeping the operations |
---|
| 1508 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 1509 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1510 | otrackf.write("\n") |
---|
| 1511 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1512 | otrackf.write(pyins + "\n") |
---|
| 1513 | |
---|
| 1514 | # removing dimension variable-dimension 'lon' |
---|
| 1515 | varnCFs.remove('lon') |
---|
| 1516 | |
---|
| 1517 | varkeep.append('lonstats') |
---|
| 1518 | |
---|
[1022] | 1519 | elif op == 'ymean': |
---|
| 1520 | # y-axis mean values |
---|
| 1521 | vals='lat|-1,lat,mean,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 1522 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 1523 | if dofile: |
---|
| 1524 | try: |
---|
| 1525 | with gen.Capturing() as output: |
---|
| 1526 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 1527 | except: |
---|
[1039] | 1528 | print errmsg |
---|
[1022] | 1529 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 1530 | for s1out in output: print s1out |
---|
[1022] | 1531 | quit(-1) |
---|
| 1532 | |
---|
| 1533 | if db: |
---|
[1064] | 1534 | for s1out in output: print s1out |
---|
[1022] | 1535 | |
---|
[1011] | 1536 | sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True) |
---|
| 1537 | |
---|
| 1538 | # Keeping the operations |
---|
| 1539 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 1540 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 1541 | otrackf.write("\n") |
---|
| 1542 | otrackf.write("# " + CFvarn + " " + Fopers + "\n") |
---|
| 1543 | otrackf.write(pyins + "\n") |
---|
| 1544 | |
---|
[1056] | 1545 | # removing dimension variable-dimension 'lat' |
---|
| 1546 | varnCFs.remove('lat') |
---|
| 1547 | |
---|
[1022] | 1548 | varkeep.append('latstats') |
---|
[1011] | 1549 | |
---|
[1022] | 1550 | elif op == 'zsum': |
---|
| 1551 | # vertical aggregated values |
---|
| 1552 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
| 1553 | wrongstats.append(CFvarn + '_' + opers) |
---|
| 1554 | break |
---|
| 1555 | else: |
---|
| 1556 | print errmsg |
---|
| 1557 | print ' ' + fname + ": operation '" + op + "' not ready !!" |
---|
| 1558 | quit(-1) |
---|
[1015] | 1559 | |
---|
[1022] | 1560 | # End of kind of operation |
---|
| 1561 | |
---|
| 1562 | # Variable name in file (vninF) changed due to operation |
---|
| 1563 | # but only if previous operation does not the same 'statistic' |
---|
| 1564 | chvn = gen.dictionary_key_list(Opsurs, op) |
---|
| 1565 | if chvn is not None: |
---|
| 1566 | oldvninF = vninF |
---|
| 1567 | vninF = vninF + chvn |
---|
| 1568 | CFvarnp = CFvarnp.replace(oldvninF,vninF) |
---|
[1015] | 1569 | |
---|
[1022] | 1570 | if dofile: |
---|
[1011] | 1571 | if len(varkeep) > 0: |
---|
| 1572 | varkeepS = ',' + ','.join(varkeep) |
---|
| 1573 | else: |
---|
| 1574 | varkeepS = '' |
---|
| 1575 | |
---|
[1022] | 1576 | # Adding such CF dimension variables which might not be in the |
---|
| 1577 | # post-operation file |
---|
| 1578 | try: |
---|
| 1579 | with gen.Capturing() as output: |
---|
| 1580 | varinfile = ncvar.ivars(fileon) |
---|
| 1581 | except: |
---|
[1039] | 1582 | print errmsg |
---|
[1022] | 1583 | print 'ivars('+fileon+')' |
---|
[1064] | 1584 | for s1out in output: print s1out |
---|
[1270] | 1585 | # Removing file in order to make sure that it will be redone |
---|
| 1586 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 1587 | sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1022] | 1588 | quit(-1) |
---|
| 1589 | |
---|
| 1590 | for CFvn in varnCFs: |
---|
| 1591 | if not gen.searchInlist(varinfile, CFvn): |
---|
| 1592 | if db: |
---|
| 1593 | print ' ' + fname + ": recupering CF variable '" + CFvn + "'" |
---|
| 1594 | try: |
---|
| 1595 | with gen.Capturing() as output: |
---|
| 1596 | ncvar.fvaradd(prevfile+','+CFvn, fileon) |
---|
| 1597 | except: |
---|
[1039] | 1598 | print errmsg |
---|
[1056] | 1599 | print 'fvaradd(' + prevfile + ',' + CFvn +', '+fileon+')' |
---|
[1270] | 1600 | ncvar.fvaradd(prevfile+','+CFvn, fileon) |
---|
[1064] | 1601 | for s1out in output: print s1out |
---|
[1270] | 1602 | # Removing file in order to make sure that it will be redone |
---|
| 1603 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 1604 | #sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1022] | 1605 | quit(-1) |
---|
| 1606 | |
---|
| 1607 | if db: |
---|
[1064] | 1608 | for s1out in output: print s1out |
---|
[1022] | 1609 | |
---|
[1011] | 1610 | totalvarkeeps = CFvarnp + ',' + ','.join(varnCFs) + varkeepS |
---|
[1022] | 1611 | try: |
---|
| 1612 | with gen.Capturing() as output: |
---|
| 1613 | oclean = ncvar.cleaning_varsfile(totalvarkeeps,fileon) |
---|
| 1614 | except: |
---|
[1039] | 1615 | print errmsg |
---|
[1022] | 1616 | print 'cleaning_varsfile('+totalvarkeeps+','+fileon+')' |
---|
[1270] | 1617 | ncvar.cleaning_varsfile(totalvarkeeps,fileon) |
---|
[1064] | 1618 | for s1out in output: print s1out |
---|
[1270] | 1619 | # Removing file in order to make sure that it will be redone |
---|
| 1620 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 1621 | sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1022] | 1622 | quit(-1) |
---|
[1011] | 1623 | |
---|
[1022] | 1624 | if db: |
---|
[1064] | 1625 | for s1out in output: print s1out |
---|
[1022] | 1626 | |
---|
[1011] | 1627 | # End of operations |
---|
[1022] | 1628 | if db: |
---|
| 1629 | print fname + ": successful calculation of '" + vninF + "' from '" + \ |
---|
| 1630 | CFvarn + "' '" + Opers + "' !!" |
---|
| 1631 | |
---|
[1011] | 1632 | if len(wrongstats) > 1: |
---|
| 1633 | print warnmsg |
---|
| 1634 | print ' ' + fname + ": statisitcs not possible to compute:", wrongstats |
---|
| 1635 | |
---|
[1394] | 1636 | if db: print " End of '" + fname + "' " |
---|
| 1637 | |
---|
[1011] | 1638 | return |
---|
| 1639 | |
---|
| 1640 | def compute_vars(config, modinf, idir, odir, Files, allvarcomp, fscr, debug): |
---|
[1001] | 1641 | """ Function to compute the variables |
---|
| 1642 | config= Configuration of the experiment |
---|
[1011] | 1643 | modinf= class with information about the model |
---|
| 1644 | idir= input experiment folder |
---|
| 1645 | odir= output experiment folder |
---|
[1001] | 1646 | Files= dictionary with the header and the files' correspondence |
---|
| 1647 | allvarcomp= dictionary with all the variables to compute and their information |
---|
[1011] | 1648 | fscr= whether files should be done from the scratch or not |
---|
[1001] | 1649 | """ |
---|
| 1650 | fname = 'compute_vars' |
---|
| 1651 | |
---|
[1031] | 1652 | for vopn in allvarcomp.keys(): |
---|
[1001] | 1653 | # variable & operation |
---|
| 1654 | vn = vopn.split('_')[0] |
---|
| 1655 | op = vopn.split('_')[1] |
---|
| 1656 | vopnV = allvarcomp[vopn] |
---|
| 1657 | fheader = vopnV[0] |
---|
[1095] | 1658 | if type(vopnV[1]) == type([1, 2]) and len(vopnV[1]) == 1: |
---|
| 1659 | vals = vopnV[1] |
---|
| 1660 | model = vals[0] |
---|
| 1661 | else: |
---|
| 1662 | model = vopnV[1] |
---|
[1001] | 1663 | diag = vopnV[2] |
---|
| 1664 | globalP = vopnV[3] |
---|
| 1665 | |
---|
| 1666 | if debug: |
---|
| 1667 | print ' ' + vn + ': ' + op |
---|
| 1668 | |
---|
| 1669 | # Computing CF variable |
---|
[1011] | 1670 | if model is not None or diag is not None: |
---|
[1001] | 1671 | vinf = VariableInf(vn,fheader,model,diag) |
---|
[1056] | 1672 | if op.find('pinterp') != -1: |
---|
| 1673 | SP = 'p' |
---|
| 1674 | else: |
---|
| 1675 | SP = '' |
---|
| 1676 | |
---|
[1011] | 1677 | # Comppute variable |
---|
[1056] | 1678 | finalfilen = odir + '/' + vn + '_' + fheader + SP + '.nc' |
---|
| 1679 | if fscr: |
---|
| 1680 | sout = sub.call('rm ' + finalfilen + ' >& /dev/null', shell=True) |
---|
[1011] | 1681 | |
---|
[1056] | 1682 | if not os.path.isfile(finalfilen): |
---|
| 1683 | compute_variable(modinf, idir, Files, odir, vinf, globalP, fscr, \ |
---|
| 1684 | config['pyHOME'], config['CFreftime'], config['CFunitstime'], debug) |
---|
| 1685 | |
---|
[1011] | 1686 | # Compute variable statistics |
---|
[1056] | 1687 | finalfilen = odir + '/' + vn + '_' + fheader + SP + '_' + \ |
---|
| 1688 | op.replace('+','_') + '.nc' |
---|
| 1689 | if fscr: |
---|
| 1690 | sout = sub.call('rm ' + finalfilen + ' >& /dev/null', shell=True) |
---|
[1011] | 1691 | |
---|
[1056] | 1692 | if not os.path.isfile(finalfilen): |
---|
| 1693 | compute_statistics(modinf, cnf, iwdir, Files, owdir, vinf, globalP, \ |
---|
| 1694 | op, fscr, debug) |
---|
| 1695 | |
---|
[1001] | 1696 | else: |
---|
| 1697 | print errmsg |
---|
| 1698 | print ' ' + fname + ": neither 'model' or 'diag' variables for '" + vn \ |
---|
| 1699 | + "' !!" |
---|
| 1700 | quit(-1) |
---|
| 1701 | |
---|
| 1702 | return |
---|
| 1703 | |
---|
[1025] | 1704 | def get_plots_var(vc,pltk,db): |
---|
| 1705 | """ Function to provide the plots to make for each variable from pltk ('DIRPLT_', or 'DIFFPLT_') dictionary |
---|
| 1706 | vc= pltk dictionary, dictionary with all the parameters started with pltk |
---|
| 1707 | pltk= kind of plots. Values started by 'DIRPLT_', or 'DIFFPLT_' in model configuration |
---|
| 1708 | """ |
---|
| 1709 | fname = 'get_plots_var' |
---|
| 1710 | |
---|
| 1711 | LH = len(pltk) |
---|
| 1712 | # list of plots |
---|
| 1713 | doplots = {} |
---|
| 1714 | # plots by variable |
---|
| 1715 | plotsvar = {} |
---|
| 1716 | # individual plots by variable (not repeated) |
---|
| 1717 | indivplotsvar = {} |
---|
| 1718 | |
---|
| 1719 | # Variables with a plot which requires vertical interpolation |
---|
| 1720 | varplotp = [] |
---|
| 1721 | |
---|
| 1722 | ipl = 0 |
---|
| 1723 | for plot in vc.keys(): |
---|
| 1724 | Lplot = len(plot) |
---|
| 1725 | pln = plot[LH:Lplot+1] |
---|
| 1726 | varops = vc[plot].split(':') |
---|
| 1727 | for vn in varops: |
---|
| 1728 | VOn = vn.split('#') |
---|
| 1729 | # Variables and operations in plot |
---|
| 1730 | vplt = [] |
---|
| 1731 | oplt = [] |
---|
| 1732 | voplt = [] |
---|
| 1733 | for vop in VOn: |
---|
| 1734 | vv = vop.split('|')[0] |
---|
| 1735 | oo = vop.split('|')[1] |
---|
| 1736 | vplt.append(vv) |
---|
| 1737 | oplt.append(oo) |
---|
| 1738 | if not gen.searchInlist(voplt,vop): voplt.append(vop) |
---|
| 1739 | vpltS = '#'.join(vplt) |
---|
| 1740 | opltS = '#'.join(oplt) |
---|
| 1741 | |
---|
| 1742 | if not doplots.has_key(pln): |
---|
| 1743 | doplots[pln] = [vn] |
---|
| 1744 | else: |
---|
| 1745 | plots = doplots[pln] |
---|
| 1746 | plots.append(vn) |
---|
| 1747 | doplots[pln] = plots |
---|
| 1748 | |
---|
| 1749 | if not plotsvar.has_key(vn): |
---|
| 1750 | plotsvar[vn] = [pln] |
---|
| 1751 | else: |
---|
| 1752 | plots = plotsvar[vn] |
---|
| 1753 | plots.append(pln) |
---|
| 1754 | plotsvar[vn] = plots |
---|
| 1755 | |
---|
| 1756 | for VOv in voplt: |
---|
| 1757 | if not indivplotsvar.has_key(VOv): |
---|
| 1758 | indivplotsvar[VOv] = [pln] |
---|
| 1759 | else: |
---|
| 1760 | plots = indivplotsvar[VOv] |
---|
[1031] | 1761 | plots.append(pln) |
---|
[1025] | 1762 | indivplotsvar[VOv] = plots |
---|
| 1763 | |
---|
| 1764 | if vc[plot].find('pinterp') != -1: |
---|
| 1765 | if not gen.searchInlist(varplotp,vn): varplotp.append(pln) |
---|
| 1766 | |
---|
| 1767 | ipl = ipl + 1 |
---|
| 1768 | |
---|
| 1769 | if db: |
---|
| 1770 | print ' plots to make _______' |
---|
| 1771 | gen.printing_dictionary(doplots) |
---|
| 1772 | print ' plots by variable|operation _______' |
---|
| 1773 | gen.printing_dictionary(plotsvar) |
---|
| 1774 | print ' individual plots by variable|operation _______' |
---|
| 1775 | gen.printing_dictionary(indivplotsvar) |
---|
| 1776 | print ' plots with the vertical interpolation _______' |
---|
| 1777 | print ' #', varplotp |
---|
| 1778 | |
---|
[1394] | 1779 | if db: print " End of '" + fname + "' " |
---|
| 1780 | |
---|
[1025] | 1781 | return doplots, plotsvar, indivplotsvar, varplotp |
---|
| 1782 | |
---|
[1039] | 1783 | def plots_listconstruct(config, pkind, finf, odir, debug): |
---|
[1025] | 1784 | """ Function to create the list of plots to draw |
---|
| 1785 | config= Configuration of the experiment |
---|
[1039] | 1786 | pkind= kind of plots ('DIRPLT', 'DIFFPLT') |
---|
| 1787 | finf= file with the instructions of the plots |
---|
[1025] | 1788 | odir= output experiment folder |
---|
| 1789 | """ |
---|
| 1790 | fname='plots_listconstruct' |
---|
| 1791 | |
---|
[1039] | 1792 | dirplot = gen.get_specdictionary_HMT(config, H=pkind+'_') |
---|
[1025] | 1793 | |
---|
[1069] | 1794 | # No plots because there are not plots of this kind |
---|
| 1795 | if dirplot is None: |
---|
| 1796 | print warnmsg |
---|
| 1797 | print ' ' + fname + ": no plots for type '" + pkind + "' !!" |
---|
| 1798 | return {}, 0 |
---|
| 1799 | |
---|
[1025] | 1800 | if debug: |
---|
[1039] | 1801 | print " '" + pkind + "' plots to draw ________" |
---|
[1025] | 1802 | gen.printing_dictionary(dirplot) |
---|
| 1803 | |
---|
| 1804 | # Getting plots by variable |
---|
[1039] | 1805 | plots, varplot, indivarplot, plotp = get_plots_var(dirplot, pkind+'_', debug) |
---|
[1025] | 1806 | |
---|
| 1807 | Svarplot = gen.dictKeysVals_stringList(plots,cV=':') |
---|
| 1808 | |
---|
| 1809 | Nplots = 0 |
---|
| 1810 | for pl in Svarplot.split(','): |
---|
| 1811 | Nplots = Nplots + len(pl.split(':')) |
---|
| 1812 | |
---|
| 1813 | # Outwritting the varcompute to avoid next time (if it is not filescratch!) |
---|
[1039] | 1814 | objf = open(finf, 'w') |
---|
[1025] | 1815 | objf.write('plots: ' + Svarplot + '\n') |
---|
| 1816 | objf.write('itotp: ' + str(Nplots) + '\n') |
---|
| 1817 | objf.close() |
---|
| 1818 | |
---|
[1394] | 1819 | if debug: print " End of '" + fname + "' " |
---|
| 1820 | |
---|
[1025] | 1821 | return plots, Nplots |
---|
| 1822 | |
---|
| 1823 | def read_plot_file(figfile): |
---|
| 1824 | """ Function to read the file with the information about the plots to draw |
---|
| 1825 | figfile= file with the information |
---|
| 1826 | """ |
---|
| 1827 | fname = 'read_plot_file' |
---|
| 1828 | |
---|
| 1829 | if not os.path.isfile(figfile): |
---|
| 1830 | print errormsg |
---|
| 1831 | print ' ' + fname + ": figures file '" + figfile + "' does not exist !!" |
---|
| 1832 | quit(-1) |
---|
| 1833 | |
---|
| 1834 | objf = open(figfile, 'r') |
---|
| 1835 | for line in objf: |
---|
| 1836 | if line[0:1] != '#' and len(line) > 1: |
---|
[1064] | 1837 | values = line.replace('\\n','').split(' ') |
---|
[1025] | 1838 | if values[0] == 'plots:': |
---|
[1069] | 1839 | if values[1] != 'none': |
---|
| 1840 | plots = gen.stringList_dictKeysVals(values[1],cV=':') |
---|
| 1841 | else: |
---|
| 1842 | pots = {} |
---|
[1025] | 1843 | elif values[0] == 'itotp:': |
---|
| 1844 | Nplots = int(values[1]) |
---|
| 1845 | |
---|
| 1846 | objf.close() |
---|
| 1847 | |
---|
| 1848 | return plots, Nplots |
---|
| 1849 | |
---|
| 1850 | def varnoper(vn, oper, opsurdict): |
---|
| 1851 | """ Function to provide name of the variable after operation as result of addition of the 'surnames' |
---|
| 1852 | vn= variable name |
---|
| 1853 | oper= '+' separated list of operations |
---|
| 1854 | opsurdict= dictionary with the surname of operations |
---|
| 1855 | >>> OpSurDict = {'mean': ['tmean', 'xmean', 'ymean']} |
---|
| 1856 | >>> varnoper('tas', 'pinterp+tmean+xmean', OpSurDict) |
---|
| 1857 | tasmeanmean |
---|
| 1858 | """ |
---|
| 1859 | fname = 'varnoper' |
---|
| 1860 | |
---|
| 1861 | newvn = vn |
---|
| 1862 | |
---|
| 1863 | for op in oper.split('+'): |
---|
| 1864 | surname = gen.dictionary_key_list(opsurdict,op) |
---|
| 1865 | if surname is not None: |
---|
| 1866 | newvn = newvn + surname |
---|
| 1867 | |
---|
| 1868 | return newvn |
---|
| 1869 | |
---|
| 1870 | def draw_plot(kplot, CFvplot, fplot, vplot, dplot, pplot, finame, tfig, kfig, mapval,\ |
---|
[1095] | 1871 | tvals, expgraphc, od, pyH, fscr, db): |
---|
[1025] | 1872 | """ Function to draw a plot |
---|
| 1873 | kplot= kind of plot |
---|
| 1874 | CFvplot= list of the CFnames of the variables |
---|
| 1875 | fplot= list with the files in the plot |
---|
| 1876 | vplot= list with the name of the variables in each file |
---|
| 1877 | dplot= list of the dimensions in each file |
---|
| 1878 | pplot= list of pictoric characteristics for each variable |
---|
| 1879 | finame= name of the figure |
---|
| 1880 | tfig= title of the figure |
---|
| 1881 | kfig= kind of the figure |
---|
| 1882 | mapval= value of the map |
---|
[1026] | 1883 | tvals= list with time values |
---|
| 1884 | tunits: units of time ('!' for spaces) |
---|
| 1885 | timekind: kind of time ticks in the plot |
---|
| 1886 | timefmt: format of time ticks in the plot |
---|
| 1887 | timelabel: label of time-axis in the plot |
---|
[1095] | 1888 | expgraphc= dictionary with expriment graphical characteristics |
---|
[1025] | 1889 | od= output directory |
---|
| 1890 | pyH= python HOME |
---|
| 1891 | fscr= whether figure should be done from scratch |
---|
| 1892 | """ |
---|
| 1893 | fname = 'draw_plot' |
---|
| 1894 | |
---|
| 1895 | if fscr: |
---|
| 1896 | sout = sub.call('rm ' + finame + ' >& /dev/null', shell=True) |
---|
| 1897 | |
---|
| 1898 | os.chdir(od) |
---|
| 1899 | |
---|
| 1900 | # CF variable-dimensions |
---|
| 1901 | CFvardims = {'lon':'lon', 'lat': 'lat', 'pres': 'pres', 'time': 'time'} |
---|
| 1902 | |
---|
| 1903 | # Tracking file with all the figures |
---|
| 1904 | trkobjf = open('all_figures.inf', 'a') |
---|
| 1905 | |
---|
[1026] | 1906 | # Time-characteristics |
---|
| 1907 | tunits = tvals[0] |
---|
| 1908 | timekind = tvals[1] |
---|
| 1909 | timefmt = tvals[2] |
---|
| 1910 | timelabel = tvals[3] |
---|
| 1911 | |
---|
[1095] | 1912 | # Graphical labels and configuration |
---|
| 1913 | |
---|
| 1914 | |
---|
[1025] | 1915 | if not os.path.isfile(finame): |
---|
| 1916 | if db: |
---|
| 1917 | print " drawing '" + finame + "' ..." |
---|
[1085] | 1918 | print ' plot kind:', kplot |
---|
[1025] | 1919 | print ' CFvars:', CFvplot |
---|
| 1920 | print ' files:', fplot |
---|
| 1921 | print ' in file vars:', vplot |
---|
| 1922 | print ' dims:', dplot |
---|
| 1923 | print ' pictoric values:', pplot |
---|
| 1924 | print ' figure name:', finame |
---|
| 1925 | print ' title:', tfig.replace('!',' ') |
---|
| 1926 | print ' kind:', kfig |
---|
| 1927 | print ' map:', mapval |
---|
| 1928 | print ' time units:', tunits |
---|
| 1929 | |
---|
| 1930 | if kplot == 'diffmap2Dsfc': |
---|
| 1931 | print " " + fname + ": kind of plot '" + kplot + "' not ready !!" |
---|
| 1932 | quit(-1) |
---|
| 1933 | elif kplot == 'diffmap2Dz': |
---|
| 1934 | print " " + fname + ": kind of plot '" + kplot + "' not ready !!" |
---|
| 1935 | quit(-1) |
---|
| 1936 | elif kplot == 'map2Dsfc': |
---|
| 1937 | print " " + fname + ": kind of plot '" + kplot + "' not ready !!" |
---|
| 1938 | quit(-1) |
---|
| 1939 | elif kplot == 'map3D': |
---|
| 1940 | print " " + fname + ": kind of plot '" + kplot + "' not ready !!" |
---|
| 1941 | quit(-1) |
---|
[1072] | 1942 | elif kplot == '2lines': |
---|
| 1943 | figtit = tfig.replace('!','|') |
---|
| 1944 | |
---|
| 1945 | lineAstdn = CFvplot[0] |
---|
| 1946 | lineBstdn = CFvplot[1] |
---|
| 1947 | figfs = ','.join(fplot) |
---|
| 1948 | |
---|
| 1949 | lineA = pplot[0] |
---|
| 1950 | Arange = str(lineA[0]) + ',' + str(lineA[1]) |
---|
[1085] | 1951 | # Values are changed from specific values in `model_graphics.dat' |
---|
| 1952 | if lineA[3].find('%') == -1: |
---|
| 1953 | Aline = lineA[2] |
---|
| 1954 | Akind = lineA[3] |
---|
| 1955 | Amark = lineA[4] |
---|
| 1956 | Asize = lineA[5] |
---|
| 1957 | else: |
---|
| 1958 | Aline = 'red' |
---|
| 1959 | Akind = '-' |
---|
| 1960 | Amark = ',' |
---|
| 1961 | Asize = 2. |
---|
[1072] | 1962 | |
---|
[1345] | 1963 | lineB = pplot[1] |
---|
[1072] | 1964 | Brange = str(lineB[0]) + ',' + str(lineB[1]) |
---|
[1085] | 1965 | # Values are changed from specific values in `model_graphics.dat' |
---|
| 1966 | if lineB[3].find('%') == -1: |
---|
| 1967 | Bline = lineB[2] |
---|
| 1968 | Bkind = lineB[3] |
---|
| 1969 | Bmark = lineB[4] |
---|
| 1970 | Bsize = lineB[5] |
---|
| 1971 | else: |
---|
| 1972 | Bline = 'blue' |
---|
| 1973 | Bkind = '-' |
---|
| 1974 | Bmark = ',' |
---|
| 1975 | Bsize = '2.' |
---|
[1072] | 1976 | |
---|
| 1977 | # It is assumed that if the space variable is 'lon': is desired a |
---|
| 1978 | # (lon, vals) plot if it is 'lat': then (vals, lat) plot |
---|
[1085] | 1979 | if gen.searchInlist(dplot[0],'lon'): |
---|
[1072] | 1980 | spacedim ='lon' |
---|
[1078] | 1981 | axisvals = 'y' |
---|
| 1982 | figmid = 'longitudinal' |
---|
[1085] | 1983 | elif gen.searchInlist(dplot[0],'lat'): |
---|
[1078] | 1984 | spacedim = 'lat' |
---|
| 1985 | axisvals = 'x' |
---|
| 1986 | figmid = 'meridional' |
---|
[1085] | 1987 | elif gen.searchInlist(dplot[0],'pres'): |
---|
[1078] | 1988 | spacedim = 'pres' |
---|
| 1989 | axisvals = 'x' |
---|
| 1990 | figmid = 'vertical' |
---|
[1072] | 1991 | else: |
---|
[1078] | 1992 | print errmsg |
---|
| 1993 | print ' ' + fname + ": in '2lines' only ready for: 'lon', 'lat'," + \ |
---|
| 1994 | " 'pres' as common dimension !!" |
---|
[1085] | 1995 | print ' dimensions in plot:', dplot[0] |
---|
[1078] | 1996 | quit(-1) |
---|
[1072] | 1997 | |
---|
[1111] | 1998 | figtit = '!'.join(tfig.split('!')[0:2]) + '!' + figmid + '!' + \ |
---|
| 1999 | '!'.join(tfig.split('!')[2:]) |
---|
[1072] | 2000 | |
---|
[1078] | 2001 | graphvals = spacedim + ':' + Arange + ':' + Brange + ':Extrs:' + \ |
---|
| 2002 | axisvals + ':' + ','.join(CFvplot) + ':' + Aline + ',' + Bline + \ |
---|
[1085] | 2003 | ':2.,2.:' + Akind + ',' + Bkind + ':2.,2.:,:' + figtit + ':' + \ |
---|
[1160] | 2004 | spacedim + ':0|auto:' + finame.replace('.'+kfig, '') + ':' + kfig + \ |
---|
[1157] | 2005 | ':True' |
---|
[1078] | 2006 | |
---|
[1072] | 2007 | fvarS = ','.join(vplot) |
---|
| 2008 | |
---|
[1078] | 2009 | drwins = 'draw_2lines' |
---|
[1072] | 2010 | plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ |
---|
| 2011 | " -S '" + graphvals + "' -v " + fvarS |
---|
| 2012 | |
---|
[1078] | 2013 | try: |
---|
| 2014 | with gen.Capturing() as output: |
---|
| 2015 | sout = sub.call(plotins, shell=True) |
---|
| 2016 | except: |
---|
| 2017 | print errmsg |
---|
| 2018 | print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' |
---|
| 2019 | print sout |
---|
| 2020 | for s1out in output: print s1out |
---|
| 2021 | quit(-1) |
---|
[1072] | 2022 | |
---|
[1078] | 2023 | # keeping all figures |
---|
| 2024 | trkobjf.write('\n') |
---|
[1160] | 2025 | trkobjf.write("# '" + kplot + "'; " + tfig.replace('!',' ') + '\n') |
---|
[1078] | 2026 | trkobjf.write(plotins + '\n') |
---|
[1072] | 2027 | |
---|
[1078] | 2028 | elif kplot == '2linesTime': |
---|
| 2029 | figtit = tfig.replace('!','|') |
---|
| 2030 | |
---|
| 2031 | lineAstdn = CFvplot[0] |
---|
| 2032 | lineBstdn = CFvplot[1] |
---|
| 2033 | figfs = ','.join(fplot) |
---|
| 2034 | |
---|
| 2035 | lineA = pplot[0] |
---|
| 2036 | Arange = str(lineA[0]) + ',' + str(lineA[1]) |
---|
| 2037 | # Values are changed from specific values in `model_graphics.dat' |
---|
| 2038 | if lineA[3].find('%') == -1: |
---|
| 2039 | Aline = lineA[2] |
---|
| 2040 | Akind = lineA[3] |
---|
| 2041 | Amark = lineA[4] |
---|
| 2042 | Asize = lineA[5] |
---|
| 2043 | else: |
---|
| 2044 | Aline = 'red' |
---|
| 2045 | Akind = '-' |
---|
| 2046 | Amark = ',' |
---|
[1085] | 2047 | Asize = '2.' |
---|
[1078] | 2048 | |
---|
| 2049 | lineB = pplot[1] |
---|
| 2050 | Brange = str(lineB[0]) + ',' + str(lineB[1]) |
---|
| 2051 | # Values are changed from specific values in `model_graphics.dat' |
---|
| 2052 | if lineB[3].find('%') == -1: |
---|
| 2053 | Bline = lineB[2] |
---|
| 2054 | Bkind = lineB[3] |
---|
| 2055 | Bmark = lineB[4] |
---|
| 2056 | Bsize = lineB[5] |
---|
| 2057 | else: |
---|
[1085] | 2058 | Bline = 'blue' |
---|
[1078] | 2059 | Bkind = '-' |
---|
| 2060 | Bmark = ',' |
---|
[1085] | 2061 | Bsize = '2.' |
---|
[1078] | 2062 | |
---|
| 2063 | timeaxis = 'x' |
---|
| 2064 | figmid = 'evolution' |
---|
| 2065 | |
---|
| 2066 | figtit = '!'.join(tfig.split('!')[0:2]) + '!' + figmid + '!' + \ |
---|
| 2067 | '!'.join(tfig.split('!')[2:]) |
---|
| 2068 | |
---|
| 2069 | graphvals = 'time:' + Arange + ':' + Brange + ':' + timekind + ';' + \ |
---|
| 2070 | timefmt + ':' + timeaxis + ':' + ','.join(CFvplot) + ':' + Aline + ',' \ |
---|
| 2071 | + Bline + ':2.,2.:' + Akind + ',' + Bkind + ':2.,2.:,:' + figtit + ':' \ |
---|
[1160] | 2072 | + timelabel + ':0|auto:' + finame.replace('.'+kfig, '') + ':' + \ |
---|
[1158] | 2073 | kfig + ':True' |
---|
[1078] | 2074 | |
---|
| 2075 | fvarS = ','.join(vplot) |
---|
| 2076 | |
---|
| 2077 | drwins = 'draw_2lines_time' |
---|
| 2078 | plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ |
---|
| 2079 | " -S '" + graphvals + "' -v " + fvarS |
---|
| 2080 | |
---|
[1072] | 2081 | try: |
---|
| 2082 | with gen.Capturing() as output: |
---|
| 2083 | sout = sub.call(plotins, shell=True) |
---|
| 2084 | except: |
---|
| 2085 | print errmsg |
---|
| 2086 | print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' |
---|
| 2087 | print sout |
---|
| 2088 | for s1out in output: print s1out |
---|
| 2089 | quit(-1) |
---|
| 2090 | |
---|
| 2091 | # keeping all figures |
---|
| 2092 | trkobjf.write('\n') |
---|
[1160] | 2093 | trkobjf.write("# '" + kplot + "'; " + tfig.replace('!',' ') + '\n') |
---|
[1072] | 2094 | trkobjf.write(plotins + '\n') |
---|
[1078] | 2095 | |
---|
[1085] | 2096 | elif kplot == 'Nlines': |
---|
| 2097 | figtit = tfig.replace('!','|') |
---|
| 2098 | |
---|
| 2099 | linestdn = CFvplot[0] |
---|
| 2100 | figfs = ','.join(fplot) |
---|
| 2101 | |
---|
| 2102 | Nlines = len(fplot) |
---|
| 2103 | |
---|
| 2104 | lablines = [] |
---|
| 2105 | for il in range(Nlines): |
---|
| 2106 | linev = pplot[il] |
---|
| 2107 | # Values are changed from specific values in `model_graphics.dat' |
---|
| 2108 | if linev[3].find('%') == -1: |
---|
| 2109 | line = linev[2] |
---|
| 2110 | kind = linev[3] |
---|
| 2111 | mark = linev[4] |
---|
| 2112 | size = linev[5] |
---|
| 2113 | if il == 0: |
---|
| 2114 | vrange = str(linev[0]) + ',' + str(linev[1]) |
---|
| 2115 | kinds = kind |
---|
| 2116 | lines = line |
---|
| 2117 | marks = mark |
---|
| 2118 | sizes = str(size) |
---|
| 2119 | else: |
---|
| 2120 | kinds = kinds + ',' + kind |
---|
| 2121 | lines = lines + ',' + line |
---|
[1095] | 2122 | marks = marks + '@' + mark |
---|
[1085] | 2123 | sizes = sizes + ',' + str(size) |
---|
| 2124 | else: |
---|
| 2125 | lines = 'None' |
---|
| 2126 | kinds = '-' |
---|
| 2127 | marks = ',' |
---|
| 2128 | sizes = '2.' |
---|
| 2129 | |
---|
| 2130 | secsf = fplot[il].split('/') |
---|
| 2131 | Nsecsf = len(secsf) |
---|
[1095] | 2132 | expvs = expgraphc[secsf[Nsecsf-3] + '/' + secsf[Nsecsf-2]] |
---|
| 2133 | lablines.append(expvs.label) |
---|
[1085] | 2134 | |
---|
| 2135 | # It is assumed that if the space variable is 'lon': is desired a |
---|
| 2136 | # (lon, vals) plot if it is 'lat': then (vals, lat) plot |
---|
| 2137 | if gen.searchInlist(dplot[0],'lon'): |
---|
| 2138 | spacedim ='lon' |
---|
[1153] | 2139 | sdlab ='lon ($degrees\ East$)' |
---|
[1085] | 2140 | axisvals = 'y' |
---|
| 2141 | figmid = 'longitudinal' |
---|
| 2142 | elif gen.searchInlist(dplot[0],'lat'): |
---|
| 2143 | spacedim = 'lat' |
---|
[1153] | 2144 | sdlab = 'lat ($degrees\ North$)' |
---|
[1085] | 2145 | axisvals = 'x' |
---|
| 2146 | figmid = 'meridional' |
---|
| 2147 | elif gen.searchInlist(dplot[0],'pres'): |
---|
| 2148 | spacedim = 'pres' |
---|
[1153] | 2149 | sdlab = 'pres ($Pa$)' |
---|
[1085] | 2150 | axisvals = 'x' |
---|
| 2151 | figmid = 'vertical' |
---|
| 2152 | else: |
---|
| 2153 | print errmsg |
---|
| 2154 | print ' ' + fname + ": in 'Nlines' only ready for: 'lon', 'lat'," + \ |
---|
| 2155 | " 'pres' as common dimension !!" |
---|
| 2156 | print ' dimensions in plot:', dplot[0] |
---|
| 2157 | quit(-1) |
---|
| 2158 | |
---|
[1111] | 2159 | figtit = '!'.join(tfig.split('!')[0:2]) + '!' + figmid + '!' + \ |
---|
| 2160 | '!'.join(tfig.split('!')[2:]) |
---|
| 2161 | figtit = figtit.replace('!',' ') |
---|
[1085] | 2162 | leglabels = ','.join(lablines) |
---|
| 2163 | |
---|
[1264] | 2164 | graphvals = spacedim + ':' + axisvals + ':' + sdlab + ':auto:' + \ |
---|
| 2165 | leglabels + ':' + CFvplot[0] +':'+ figtit + ':0|auto:' + lines + ':' + \ |
---|
| 2166 | kinds + ':' + marks +':'+ sizes +':'+ sizes +':all:'+ \ |
---|
| 2167 | finame.replace('.'+kfig, '') + ':' + kfig + ':True' |
---|
[1085] | 2168 | |
---|
| 2169 | fvarS = vplot[0] |
---|
| 2170 | |
---|
| 2171 | drwins = 'draw_lines' |
---|
| 2172 | plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ |
---|
| 2173 | " -S '" + graphvals + "' -v " + fvarS |
---|
| 2174 | |
---|
| 2175 | try: |
---|
| 2176 | with gen.Capturing() as output: |
---|
| 2177 | sout = sub.call(plotins, shell=True) |
---|
| 2178 | except: |
---|
| 2179 | print errmsg |
---|
| 2180 | print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' |
---|
| 2181 | print sout |
---|
| 2182 | for s1out in output: print s1out |
---|
| 2183 | quit(-1) |
---|
| 2184 | |
---|
| 2185 | # keeping all figures |
---|
| 2186 | trkobjf.write('\n') |
---|
[1160] | 2187 | trkobjf.write("# '" + kplot + "'; " + tfig.replace('!',' ') + '\n') |
---|
[1085] | 2188 | trkobjf.write(plotins + '\n') |
---|
| 2189 | |
---|
[1095] | 2190 | elif kplot == 'Nlines_time': |
---|
| 2191 | figtit = tfig.replace('!','|') |
---|
| 2192 | |
---|
| 2193 | linestdn = CFvplot[0] |
---|
| 2194 | figfs = ','.join(fplot) |
---|
| 2195 | |
---|
| 2196 | Nlines = len(fplot) |
---|
| 2197 | |
---|
| 2198 | lablines = [] |
---|
| 2199 | for il in range(Nlines): |
---|
| 2200 | linev = pplot[il] |
---|
| 2201 | # Values are changed from specific values in `model_graphics.dat' |
---|
| 2202 | if linev[3].find('%') == -1: |
---|
| 2203 | line = linev[2] |
---|
| 2204 | kind = linev[3] |
---|
| 2205 | mark = linev[4] |
---|
| 2206 | size = linev[5] |
---|
| 2207 | if il == 0: |
---|
| 2208 | vrange = str(linev[0]) + ',' + str(linev[1]) |
---|
| 2209 | kinds = kind |
---|
| 2210 | lines = line |
---|
| 2211 | marks = mark |
---|
| 2212 | sizes = str(size) |
---|
| 2213 | else: |
---|
| 2214 | kinds = kinds + ',' + kind |
---|
| 2215 | lines = lines + ',' + line |
---|
| 2216 | marks = marks + '@' + mark |
---|
| 2217 | sizes = sizes + ',' + str(size) |
---|
| 2218 | else: |
---|
| 2219 | lines = 'None' |
---|
| 2220 | kinds = '-' |
---|
| 2221 | marks = ',' |
---|
| 2222 | sizes = '2.' |
---|
| 2223 | |
---|
| 2224 | secsf = fplot[il].split('/') |
---|
| 2225 | Nsecsf = len(secsf) |
---|
| 2226 | expvs = expgraphc[secsf[Nsecsf-3] + '/' + secsf[Nsecsf-2]] |
---|
| 2227 | lablines.append(expvs.label) |
---|
| 2228 | |
---|
| 2229 | valsaxis = 'y' |
---|
| 2230 | figmid = 'evolution' |
---|
| 2231 | |
---|
[1111] | 2232 | figtit = '!'.join(tfig.split('!')[0:2]) + '!' + figmid + '!' + \ |
---|
| 2233 | '!'.join(tfig.split('!')[2:]) |
---|
| 2234 | figtit = figtit.replace('!',' ') |
---|
[1095] | 2235 | leglabels = ','.join(lablines) |
---|
| 2236 | |
---|
| 2237 | graphvals = 'time;' + valsaxis + ';time;' + leglabels + ';' + \ |
---|
| 2238 | CFvplot[0] + ';' + figtit + ';None;time|' + '|'.join(tvals) + \ |
---|
| 2239 | ';0|auto;' + kfig + ';' + kinds + ';' + lines + ';' + marks + ';' + \ |
---|
[1157] | 2240 | sizes + ';' + sizes + ';all;-1;True' |
---|
[1095] | 2241 | |
---|
| 2242 | fvarS = vplot[0] |
---|
| 2243 | |
---|
| 2244 | drwins = 'draw_lines_time' |
---|
| 2245 | plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ |
---|
| 2246 | " -S '" + graphvals + "' -v " + fvarS |
---|
| 2247 | |
---|
| 2248 | try: |
---|
| 2249 | with gen.Capturing() as output: |
---|
| 2250 | sout = sub.call(plotins, shell=True) |
---|
| 2251 | except: |
---|
| 2252 | print errmsg |
---|
| 2253 | print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' |
---|
| 2254 | print sout |
---|
| 2255 | for s1out in output: print s1out |
---|
| 2256 | quit(-1) |
---|
| 2257 | |
---|
| 2258 | sout = sub.call('mv lines_time.' + kfig + ' ' + finame, shell=True) |
---|
| 2259 | |
---|
| 2260 | # keeping all figures |
---|
| 2261 | trkobjf.write('\n') |
---|
[1160] | 2262 | trkobjf.write("# '" + kplot + "'; " + tfig.replace('!',' ') + '\n') |
---|
[1095] | 2263 | trkobjf.write(plotins + '\n') |
---|
| 2264 | |
---|
[1025] | 2265 | elif kplot == 'shadcont2Dsfc': |
---|
| 2266 | figtit = tfig.replace('!','|') |
---|
| 2267 | shdstdn = CFvplot[0] |
---|
| 2268 | cntstdn = CFvplot[1] |
---|
| 2269 | figfs = ','.join(fplot) |
---|
[1026] | 2270 | |
---|
[1025] | 2271 | shad = pplot[0] |
---|
| 2272 | srange = str(shad[0]) + ',' + str(shad[1]) |
---|
| 2273 | cbar = shad[2] |
---|
| 2274 | cnt = pplot[1] |
---|
| 2275 | crange = str(cnt[0]) + ',' + str(cnt[1]) |
---|
[1026] | 2276 | cfmt = cnt[3] |
---|
[1056] | 2277 | ckind = cnt[4] |
---|
| 2278 | cline = cnt[5] |
---|
[1025] | 2279 | |
---|
| 2280 | graphvals = ','.join(CFvplot) |
---|
[1148] | 2281 | graphvals = graphvals + ':lon|-1,lat|-1:lon|-1,lat|-1:lon:lat:auto:' + \ |
---|
| 2282 | cbar + ',auto,auto:' + ckind + ',' + cline + ':' + cfmt + ':' + \ |
---|
| 2283 | srange + ':' + crange + ',9:' + figtit + ':' + kfig + ':None:' + \ |
---|
| 2284 | mapval + ':True' |
---|
[1025] | 2285 | |
---|
| 2286 | fvarS = ','.join(vplot) |
---|
| 2287 | |
---|
[1029] | 2288 | drwins = 'draw_2D_shad_cont' |
---|
| 2289 | plotins = "python " + pyH + "/drawing.py -f " + figfs + " -o " + drwins +\ |
---|
| 2290 | " -S '" + graphvals + "' -v " + fvarS |
---|
[1025] | 2291 | try: |
---|
| 2292 | with gen.Capturing() as output: |
---|
[1072] | 2293 | sout = sub.call(plotins, shell=True) |
---|
[1025] | 2294 | except: |
---|
[1039] | 2295 | print errmsg |
---|
[1029] | 2296 | print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' |
---|
[1072] | 2297 | print sout |
---|
[1064] | 2298 | for s1out in output: print s1out |
---|
[1025] | 2299 | quit(-1) |
---|
| 2300 | |
---|
| 2301 | sout = sub.call('mv 2Dfields_shadow-contour.'+kfig+' '+finame, shell=True) |
---|
| 2302 | |
---|
| 2303 | # keeping all figures |
---|
| 2304 | trkobjf.write('\n') |
---|
[1160] | 2305 | trkobjf.write("# '" + kplot + "'; " + tfig.replace('!',' ') + '\n') |
---|
[1025] | 2306 | trkobjf.write(plotins + '\n') |
---|
[1026] | 2307 | |
---|
| 2308 | elif kplot == 'shadconthovmsfc': |
---|
| 2309 | figtit = tfig.replace('!','|') |
---|
| 2310 | shdstdn = CFvplot[0] |
---|
| 2311 | cntstdn = CFvplot[1] |
---|
| 2312 | figfs = ','.join(fplot) |
---|
| 2313 | |
---|
| 2314 | shad = pplot[0] |
---|
| 2315 | srange = str(shad[0]) + ',' + str(shad[1]) |
---|
| 2316 | cbar = shad[2] |
---|
| 2317 | cnt = pplot[1] |
---|
| 2318 | crange = str(cnt[0]) + ',' + str(cnt[1]) |
---|
| 2319 | cfmt = cnt[3] |
---|
[1056] | 2320 | ckind = cnt[4] |
---|
| 2321 | cline = cnt[5] |
---|
[1026] | 2322 | # It is assumed that if the space variable is 'lon': is desired a |
---|
[1072] | 2323 | # (lon, time) plot if it is 'lat': then (time, lat) plot |
---|
[1026] | 2324 | if gen.searchInlist(dplot,'lon'): |
---|
| 2325 | spacedim ='lon' |
---|
| 2326 | figmid = 'longitudinal|evolution|of' |
---|
| 2327 | figtit = '|'.join(tfig.split('!')[0:2]) + '|' + figmid + '|' + \ |
---|
| 2328 | '|'.join(tfig.split('!')[2:]) |
---|
| 2329 | reverse= 'None' |
---|
| 2330 | dims= spacedim+'|-1,time|-1;'+spacedim+'|-1,time|-1;'+spacedim+';time' |
---|
| 2331 | else: |
---|
| 2332 | spacedim='lat' |
---|
| 2333 | figmid = 'meridional|evolution|of' |
---|
| 2334 | figtit = '|'.join(tfig.split('!')[0:2]) + '|' + figmid + '|' + \ |
---|
| 2335 | '|'.join(tfig.split('!')[2:]) |
---|
| 2336 | reverse='None' |
---|
| 2337 | dims= spacedim+'|-1,time|-1;'+spacedim+'|-1,time|-1;time;'+spacedim |
---|
| 2338 | |
---|
| 2339 | graphvals = ','.join(CFvplot) |
---|
[1158] | 2340 | graphvals = graphvals + ';' + dims +';auto;' + cbar + ',auto,auto' + ';' \ |
---|
| 2341 | + ckind + ',' + cline + ';' + cfmt + ';' + srange + ';' + crange + \ |
---|
[1056] | 2342 | ',9;' + figtit + ';' + kfig + ';' + reverse + ';' + 'time|' + tunits + \ |
---|
[1157] | 2343 | '|'+ timekind + '|' + timefmt + '|' + timelabel + ';True' |
---|
[1026] | 2344 | |
---|
| 2345 | fvarS = ','.join(vplot) |
---|
| 2346 | |
---|
| 2347 | drwins = 'draw_2D_shad_cont_time' |
---|
| 2348 | plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ |
---|
| 2349 | " -S '" + graphvals + "' -v " + fvarS |
---|
| 2350 | |
---|
| 2351 | try: |
---|
| 2352 | with gen.Capturing() as output: |
---|
[1072] | 2353 | sout = sub.call(plotins, shell=True) |
---|
[1026] | 2354 | except: |
---|
[1039] | 2355 | print errmsg |
---|
[1029] | 2356 | print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' |
---|
[1072] | 2357 | print sout |
---|
[1064] | 2358 | for s1out in output: print s1out |
---|
[1026] | 2359 | quit(-1) |
---|
| 2360 | |
---|
| 2361 | sout = sub.call('mv 2Dfields_shadow-contour.'+kfig+' '+finame, shell=True) |
---|
| 2362 | |
---|
| 2363 | # keeping all figures |
---|
| 2364 | trkobjf.write('\n') |
---|
[1160] | 2365 | trkobjf.write("# '" + kplot + "'; " + tfig.replace('!',' ') + '\n') |
---|
[1026] | 2366 | trkobjf.write(plotins + '\n') |
---|
| 2367 | |
---|
[1085] | 2368 | elif kplot == 'shadcont2Dzsec': |
---|
[1029] | 2369 | figtit = tfig.replace('!','|') |
---|
| 2370 | shdstdn = CFvplot[0] |
---|
| 2371 | cntstdn = CFvplot[1] |
---|
| 2372 | figfs = ','.join(fplot) |
---|
| 2373 | |
---|
| 2374 | shad = pplot[0] |
---|
| 2375 | srange = str(shad[0]) + ',' + str(shad[1]) |
---|
| 2376 | cbar = shad[2] |
---|
| 2377 | cnt = pplot[1] |
---|
| 2378 | crange = str(cnt[0]) + ',' + str(cnt[1]) |
---|
| 2379 | cfmt = cnt[3] |
---|
[1056] | 2380 | ckind = cnt[4] |
---|
| 2381 | cline = cnt[5] |
---|
[1029] | 2382 | |
---|
| 2383 | # It is assumed that if the space variable is 'lon': is desired a |
---|
| 2384 | # (lon, pres) plot it it is 'lat': then (pres, lat) plot |
---|
| 2385 | if gen.searchInlist(dplot, 'lon'): |
---|
| 2386 | spacedim='lon' |
---|
| 2387 | figmid = 'long.|vert.|cross|sec.|of' |
---|
| 2388 | figtit = '|'.join(tfig.split('!')[0:2]) + '|' + figmid + '|' + \ |
---|
| 2389 | '|'.join(tfig.split('!')[2:]) |
---|
| 2390 | dims= spacedim+'|-1,pres|-1:'+spacedim+'|-1,pres|-1:'+spacedim+':pres' |
---|
| 2391 | else: |
---|
| 2392 | spacedim='lat' |
---|
| 2393 | figmid = 'mer.|vert.|cross|sec.|of' |
---|
| 2394 | figtit = '|'.join(tfig.split('!')[0:2]) + '|' + figmid + '|' + \ |
---|
| 2395 | '|'.join(tfig.split('!')[2:]) |
---|
| 2396 | # NOT WORKING? dims= spacedim+'|-1,pres|-1:'+spacedim+'|-1,pres|-1:'+'pres:'+spacedim |
---|
| 2397 | dims= spacedim+'|-1,pres|-1:'+spacedim+'|-1,pres|-1:'+spacedim+':pres' |
---|
| 2398 | |
---|
[1335] | 2399 | reverse = 'None' |
---|
[1029] | 2400 | |
---|
| 2401 | graphvals = ','.join(CFvplot) |
---|
[1148] | 2402 | graphvals = graphvals + ':' + dims + ':auto:' + cbar + ',auto,auto:' + \ |
---|
| 2403 | ckind + ',' + cline + ':' + cfmt + ':' + srange + ':' + crange + ',9:' \ |
---|
| 2404 | + figtit + ':' + kfig + ':' + reverse + ':None:True' |
---|
[1029] | 2405 | |
---|
| 2406 | fvarS = ','.join(vplot) |
---|
| 2407 | |
---|
| 2408 | drwins = 'draw_2D_shad_cont' |
---|
| 2409 | plotins = 'python ' + pyH + '/drawing.py -f ' + figfs + ' -o ' + drwins + \ |
---|
| 2410 | " -S '" + graphvals + "' -v " + fvarS |
---|
| 2411 | try: |
---|
| 2412 | with gen.Capturing() as output: |
---|
| 2413 | sout0 = sub.call(plotins, shell=True) |
---|
| 2414 | except: |
---|
[1039] | 2415 | print errmsg |
---|
[1029] | 2416 | print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' |
---|
[1064] | 2417 | for s1out in output: print s1out |
---|
[1029] | 2418 | quit(-1) |
---|
| 2419 | |
---|
| 2420 | sout = sub.call('mv 2Dfields_shadow-contour.'+kfig+' '+finame, shell=True) |
---|
| 2421 | |
---|
| 2422 | # keeping all figures |
---|
| 2423 | trkobjf.write('\n') |
---|
[1160] | 2424 | trkobjf.write("# '" + kplot + "'; " + tfig.replace('!',' ') + '\n') |
---|
[1029] | 2425 | trkobjf.write(plotins + '\n') |
---|
| 2426 | |
---|
[1025] | 2427 | else: |
---|
| 2428 | print errmsg |
---|
| 2429 | print " " + fname + ": plot kind '" + kplot + "' not ready !!" |
---|
| 2430 | quit(-1) |
---|
| 2431 | |
---|
| 2432 | trkobjf.close() |
---|
| 2433 | |
---|
[1394] | 2434 | if db: print " End of '" + fname + "' " |
---|
| 2435 | |
---|
[1025] | 2436 | return |
---|
| 2437 | |
---|
[1363] | 2438 | def opexplained(Opn,Exp): |
---|
| 2439 | """ Function to provide the final explanation for the title in the graph. Some operations have |
---|
| 2440 | values separated by `~' which need to be processed |
---|
| 2441 | Opn= full operation string |
---|
| 2442 | Exp= explanation from dictionary |
---|
| 2443 | >>> opexplained('dimvarvalue~pres~85000','@') |
---|
| 2444 | pres@85000 |
---|
| 2445 | >>> opexplained('xmean','xmean') |
---|
| 2446 | xmean |
---|
| 2447 | """ |
---|
| 2448 | fname = 'opexplained' |
---|
| 2449 | |
---|
| 2450 | if Opn.find('~') == -1: |
---|
| 2451 | explanation = Exp |
---|
| 2452 | else: |
---|
| 2453 | Opnv = Opn.split('~') |
---|
| 2454 | if Opnv[0] == 'dimvarvalue': |
---|
| 2455 | explanation = Opnv[1] + Exp + Opnv[2] |
---|
| 2456 | else: |
---|
| 2457 | print errormsg |
---|
| 2458 | print ' ' + fname + ": unknow '~' separated operation '" + Opnv[0] + \ |
---|
| 2459 | "' !!" |
---|
| 2460 | quit(-1) |
---|
| 2461 | return explanation |
---|
| 2462 | |
---|
[1080] | 2463 | def optitle(op,opexp): |
---|
| 2464 | """ Function to creat the operation section in the title of a figure ('!' for spaces) |
---|
| 2465 | op= '+' separated list of operations |
---|
| 2466 | opexp= dictionary with the `explanation'(text in title) to appear for each operation |
---|
| 2467 | >>> optitle('pinterp+xmean+tmean',{'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean'}) |
---|
| 2468 | $_{[pinterp\!xmean\!tmean]}$ |
---|
[1363] | 2469 | >>> optitle('pinterp+dimvarvalue~pres~85000+tmean',{'dimvarvalue':'@', 'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean'}) |
---|
| 2470 | $_{[pinterp\!pres@85000\!tmean]}$ |
---|
[1080] | 2471 | """ |
---|
| 2472 | fname = 'optitle' |
---|
| 2473 | |
---|
| 2474 | opvals = op.split('+') |
---|
| 2475 | for op1 in opvals: |
---|
[1363] | 2476 | op1n = op1.split('~')[0] |
---|
| 2477 | if not opexp.has_key(op1n): |
---|
[1080] | 2478 | print errmsg |
---|
[1363] | 2479 | print ' ' + fname + ": no explanation for operation '" + op1n + "' !!" |
---|
[1080] | 2480 | print ' provided:', opexp.keys() |
---|
| 2481 | quit(-1) |
---|
[1363] | 2482 | # Final explanation |
---|
| 2483 | op1en = opexplained(op1,opexp[op1n]).replace(' ','!') |
---|
| 2484 | |
---|
| 2485 | if op1n == opvals[0].split('~')[0]: |
---|
| 2486 | titop = '$_{[' + op1en |
---|
[1080] | 2487 | if len(opvals) == 1: titop = titop + ']}$' |
---|
[1363] | 2488 | elif op1n == opvals[len(opvals)-1].split('~')[0]: |
---|
| 2489 | titop = titop + '\!' + op1en + ']}$' |
---|
[1080] | 2490 | else: |
---|
[1363] | 2491 | titop = titop + '\!' + op1en |
---|
[1080] | 2492 | |
---|
| 2493 | return titop |
---|
| 2494 | |
---|
| 2495 | def create_figure_title(mod,exp,varops,explop): |
---|
| 2496 | """ Function to create the title of a figure ('!' for spaces) |
---|
| 2497 | mod: model name |
---|
| 2498 | exp: experiment name |
---|
| 2499 | varops: list with [var]|[op] values from wich create the title |
---|
| 2500 | explop: dictionary with the `explanation'(text in title) to appear for each operation |
---|
| 2501 | >>> expops = {'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean', 'last':'last'} |
---|
| 2502 | >>> create_figure_title('WRF','current',['ua|pinterp+xmean+tmean', 'va|pinterp+xmean+tmean'], expops) |
---|
| 2503 | WRF!current!ua!&!va$_{[pinterp\!xmean\!tmean]}$ |
---|
| 2504 | >>> create_figure_title('WRF','current',['ua|pinterp+xmean+tmean', 'ua|pinterp+xmean+last'], expops) |
---|
| 2505 | WRF!current!ua$_{[pinterp\!xmean\!tmean]}$!&!!$_{[pinterp\!xmean\!last]}$ |
---|
| 2506 | >>> create_figure_title('WRF','current',['ua|pinterp+xmean+tmean', 'va|pinterp+xmean+last'], expops) |
---|
| 2507 | WRF!current!ua$_{[pinterp\!xmean\!tmean]}$!&!va$_{[pinterp\!xmean\!last]}$ |
---|
[1363] | 2508 | >>> create_figure_title('WRF','current',['uas|dimvarvalue~lon~23.23', 'vas|dimvarvalue~lon~23.23'], expops) |
---|
| 2509 | WRF!current!uas!&!vas$_{[lon@23.23]}$ |
---|
| 2510 | >>> create_figure_title('WRF','current',['hus|pinterp+tmean+dimvarvalue~pres~85000.', 'ta|pinterp+tmean+dimvarvalue~pres~85000.'], expops) |
---|
| 2511 | WRF!current!hus!&!ta$_{[pinterp\!tmean\!pres@85000.]}$ |
---|
[1080] | 2512 | """ |
---|
| 2513 | fname = 'create_figure_title' |
---|
| 2514 | |
---|
| 2515 | titfig = mod + '!' + exp + '!' |
---|
| 2516 | |
---|
| 2517 | varns = [] |
---|
| 2518 | opns = [] |
---|
| 2519 | for varop in varops: |
---|
| 2520 | vn = varop.split('|')[0] |
---|
| 2521 | op = varop.split('|')[1] |
---|
| 2522 | varns.append(vn) |
---|
| 2523 | opns.append(op) |
---|
| 2524 | if varop == varops[0]: |
---|
| 2525 | allvarequal = True |
---|
| 2526 | allopequal = True |
---|
| 2527 | varinfig = vn |
---|
| 2528 | opinfig = op |
---|
| 2529 | else: |
---|
| 2530 | if vn != varinfig: allvarequal = False |
---|
| 2531 | if op != opinfig: allopequal = False |
---|
| 2532 | |
---|
| 2533 | Nvars = len(varns) |
---|
| 2534 | Nops = len(opns) |
---|
| 2535 | |
---|
| 2536 | if allvarequal: |
---|
| 2537 | titfig = titfig + '!' + varns[0] |
---|
| 2538 | if allopequal: |
---|
| 2539 | opS = optitle(op,explop) |
---|
| 2540 | titfig = titfig + opS |
---|
| 2541 | else: |
---|
| 2542 | for opn in opns: |
---|
| 2543 | opS = optitle(opn,explop) |
---|
| 2544 | if opn == opns[0]: |
---|
| 2545 | titfig = titfig + opS |
---|
| 2546 | elif opn == opns[Nops-1]: |
---|
| 2547 | titfig = titfig + '!&!' + opS |
---|
| 2548 | else: |
---|
| 2549 | titfig = titfig + ',!' + opS |
---|
| 2550 | else: |
---|
| 2551 | if allopequal: |
---|
| 2552 | opS = optitle(op,explop) |
---|
| 2553 | for vn in varns: |
---|
| 2554 | if vn == varns[0]: |
---|
| 2555 | titfig = titfig + '!' + vn |
---|
| 2556 | elif vn == varns[Nvars-1]: |
---|
| 2557 | titfig = titfig + '!&!' + vn |
---|
| 2558 | else: |
---|
| 2559 | titfig = titfig + ',!' + vn |
---|
| 2560 | titfig = titfig + opS |
---|
| 2561 | else: |
---|
| 2562 | for ivop in range(Nvars): |
---|
| 2563 | vn = varns[ivop] |
---|
| 2564 | op = opns[ivop] |
---|
| 2565 | vnop = vn + optitle(op,explop) |
---|
| 2566 | |
---|
| 2567 | if vn == varns[0]: |
---|
| 2568 | titfig = titfig + '!' + vnop |
---|
| 2569 | elif vn == varns[Nvars-1]: |
---|
| 2570 | titfig = titfig + '!&!' + vnop |
---|
| 2571 | else: |
---|
| 2572 | titfig = titfig + ',!' + vnop |
---|
| 2573 | |
---|
[1363] | 2574 | return titfig.replace('!!','!') |
---|
| 2575 | #expops = {'dimvarvalue':'@', 'last':'last', 'pinterp':'pinterp', 'xmean':'xmean', 'tmean':'tmean'} |
---|
[1080] | 2576 | |
---|
[1025] | 2577 | def draw_plots(config, plots, mod, exp, odir, allvarcomp, figscr, debug): |
---|
| 2578 | """ Function to draw all plots |
---|
| 2579 | config= Configuration of the experiment |
---|
| 2580 | plots= dictionary with the plots |
---|
| 2581 | mod= model of the plots |
---|
| 2582 | exp= experiment of the plots |
---|
| 2583 | odir= output experiment folder |
---|
| 2584 | allvarcomp= dictionary with all the variables to compute and their information |
---|
| 2585 | figscr= whether figures should be done from the scratch or not |
---|
| 2586 | |
---|
| 2587 | * Plot as |
---|
| 2588 | {[kplot]} = [varn1]|[op1]#[varn2]|[op2]#[...[varnN]|[opN]], ... |
---|
| 2589 | [kplot] ___ |
---|
| 2590 | diffmap2Dsfc: 2D map of surface differences values of 1 variable |
---|
| 2591 | diffmap2Dz: 2D map of 3D differences values of 1 variable |
---|
| 2592 | map2Dsfc: 2D map of surface values of 1 variable |
---|
| 2593 | map3D: 2D map of 3D values of 1 variable |
---|
| 2594 | shadconthovmsfc: Hovmoeller diagrams of 2 variable at the surface in shadow and the other in contourn |
---|
| 2595 | shadcont2Dsfc: 2D map of shadow (1st variable) and countour (2nd variable) [stvar1]#[stvar2] |
---|
| 2596 | shadcont2Dzsec: 2D map of vertical section of 2 variables one in shadow and the other in contourn |
---|
| 2597 | [varn] |
---|
| 2598 | variable |
---|
| 2599 | [op] |
---|
| 2600 | '+' separated list of operations |
---|
| 2601 | in figures with more than 1 variable, use '#' to separate the [varn]|[op] |
---|
| 2602 | """ |
---|
| 2603 | fname = 'draw_plots' |
---|
| 2604 | |
---|
| 2605 | os.chdir(odir) |
---|
| 2606 | |
---|
| 2607 | # Dictionary with the operations with surnames for the operated variable |
---|
| 2608 | opersurnames = {} |
---|
| 2609 | opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') |
---|
| 2610 | for opsr in opsur.keys(): |
---|
| 2611 | opn = opsr.split('_')[1] |
---|
| 2612 | vls = opsur[opsr].split(':') |
---|
| 2613 | opersurnames[opn] = vls |
---|
| 2614 | |
---|
[1026] | 2615 | # time values |
---|
[1025] | 2616 | # Units time for the plots |
---|
| 2617 | rd = config['CFreftime'] |
---|
[1026] | 2618 | tunits = config['CFunitstime'] + '!since!' + rd[0:4] + '-' + rd[4:6] + '-' + \ |
---|
[1025] | 2619 | rd[6:8] + '!' + rd[8:10] + ':' + rd[10:12] + ':' + rd[12:14] |
---|
[1026] | 2620 | # time ticks kind |
---|
| 2621 | tkind = config['timekind'] |
---|
| 2622 | # time ticks format |
---|
| 2623 | tfmt = config['timefmt'] |
---|
| 2624 | # time axis label |
---|
| 2625 | tlab = config['timelabel'] |
---|
| 2626 | timevals = [tunits, tkind, tfmt, tlab] |
---|
[1025] | 2627 | |
---|
[1026] | 2628 | # Dictionary of plot specificities |
---|
[1039] | 2629 | specplotkeyn = 'specificvarplot' |
---|
[1025] | 2630 | plotspecifics = {} |
---|
[1039] | 2631 | if config.has_key(specplotkeyn): |
---|
| 2632 | # [minval]: minimum value |
---|
| 2633 | # [maxval]: minimum value |
---|
| 2634 | # [colorbar]: name of the colorbar (from matplotlib) to use |
---|
| 2635 | # [cntformat]: format of the contour labels |
---|
| 2636 | # [colorcnt]: color for the countor lines |
---|
| 2637 | plotspecs = config[specplotkeyn].split(':') |
---|
| 2638 | for pltspc in plotspecs: |
---|
| 2639 | pltvls = pltspc.split('|') |
---|
| 2640 | vn = pltvls[0] |
---|
| 2641 | op = pltvls[1] |
---|
| 2642 | fn = pltvls[2] |
---|
| 2643 | plotspecifics[fn + '_' + vn + '_' + op] = pltvls[3:] |
---|
| 2644 | if debug: |
---|
| 2645 | print 'Specific values for plots _______' |
---|
| 2646 | gen.printing_dictionary(plotspecifics) |
---|
[1025] | 2647 | |
---|
| 2648 | # Kind of figures |
---|
| 2649 | kindfigure = config['kindfig'] |
---|
| 2650 | |
---|
[1095] | 2651 | # Graphical labels and configuration |
---|
| 2652 | modgc, expgc = graphical_characteristics(config, debug) |
---|
| 2653 | modv = modgc[mod] |
---|
| 2654 | modlab = modv.label |
---|
| 2655 | expv = expgc[mod+'/'+exp] |
---|
| 2656 | explab = expv.label |
---|
| 2657 | |
---|
[1025] | 2658 | # Map value |
---|
| 2659 | mapvalue = config['mapval'] |
---|
| 2660 | |
---|
| 2661 | # pythone scripts HOME |
---|
| 2662 | pyHOME = config['pyHOME'] |
---|
| 2663 | |
---|
| 2664 | # Title-text of operations |
---|
| 2665 | opexplained = {} |
---|
| 2666 | optits = config['titleoperations'].split(':') |
---|
| 2667 | for optit in optits: |
---|
| 2668 | opn = optit.split('|')[0] |
---|
| 2669 | opt = optit.split('|')[1] |
---|
| 2670 | opexplained[opn] = opt |
---|
| 2671 | if debug: |
---|
| 2672 | print 'Titles for operations _______' |
---|
| 2673 | gen.printing_dictionary(opexplained) |
---|
| 2674 | |
---|
| 2675 | for kplot in plots.keys(): |
---|
| 2676 | varsplt = plots[kplot] |
---|
| 2677 | for varplt in varsplt: |
---|
| 2678 | if debug: |
---|
| 2679 | print " printing '" + kplot + "' var ':" + varplt + "'..." |
---|
| 2680 | varops = varplt.split('#') |
---|
| 2681 | |
---|
| 2682 | # CF variables in plot |
---|
| 2683 | CFvarsplot = [] |
---|
| 2684 | # Files in plot |
---|
| 2685 | filesplot = [] |
---|
| 2686 | # Variables in plot within the files |
---|
| 2687 | varsplot = [] |
---|
| 2688 | # Dims in figure |
---|
| 2689 | dimsplot = [] |
---|
| 2690 | # pictoric values in figure |
---|
| 2691 | pictplot = [] |
---|
| 2692 | # Name of the figure |
---|
| 2693 | figname = '' |
---|
| 2694 | # Title of the figure |
---|
| 2695 | titfigure = '' |
---|
| 2696 | |
---|
| 2697 | ivp = 0 |
---|
| 2698 | for varop in varops: |
---|
| 2699 | vn = varop.split('|')[0] |
---|
| 2700 | op = varop.split('|')[1] |
---|
| 2701 | |
---|
| 2702 | # CF variables in plot |
---|
| 2703 | CFvarsplot.append(vn) |
---|
| 2704 | |
---|
| 2705 | vnopS = vn + '_' + op |
---|
| 2706 | if not allvarcomp.has_key(vnopS): |
---|
[1031] | 2707 | print errmsg |
---|
| 2708 | print ' ' + fname + ": no file for variable-operation '" + \ |
---|
[1025] | 2709 | vnopS + "' !!" |
---|
| 2710 | vopvals = allvarcomp[vnopS] |
---|
| 2711 | headf = vopvals[0] |
---|
| 2712 | globalP = vopvals[3] |
---|
| 2713 | gP = pinterpS(globalP) |
---|
| 2714 | |
---|
[1029] | 2715 | filen = vn + '_' + headf + gP + '_' + op.replace('+','_') + '.nc' |
---|
[1025] | 2716 | filesplot.append(filen) |
---|
| 2717 | # Do we have processed the given variable? |
---|
| 2718 | if not os.path.isfile(filen): |
---|
| 2719 | print warnmsg |
---|
| 2720 | print " " + fname + ": there is no file for variable '" + varop \ |
---|
| 2721 | + "' skiping it !!" |
---|
| 2722 | break |
---|
| 2723 | |
---|
| 2724 | # Name of the variable inside the file |
---|
| 2725 | vnsur = varnoper(vn, op, opersurnames) |
---|
| 2726 | varsplot.append(vnsur) |
---|
| 2727 | |
---|
| 2728 | # Dimensions in file |
---|
| 2729 | try: |
---|
| 2730 | with gen.Capturing() as output: |
---|
| 2731 | dims = ncvar.idims(filen) |
---|
| 2732 | except: |
---|
[1039] | 2733 | print errmsg |
---|
[1025] | 2734 | print 'ncvar.idims('+filen+')' |
---|
[1064] | 2735 | for s1out in output: print s1out |
---|
[1025] | 2736 | quit(-1) |
---|
| 2737 | |
---|
| 2738 | dimsplot.append(dims) |
---|
| 2739 | |
---|
| 2740 | # pictoric values for the figure |
---|
| 2741 | Sfivaop = kplot + '_' + vn + '_' + op |
---|
| 2742 | if plotspecifics.has_key(Sfivaop): |
---|
| 2743 | pictvals = plotspecifics[Sfivaop] |
---|
| 2744 | else: |
---|
| 2745 | Vvals = gen.variables_values(vn) |
---|
[1059] | 2746 | pictvals = [Vvals[2], Vvals[3], Vvals[6], '%g', 'fixc', 'black'] |
---|
[1025] | 2747 | |
---|
| 2748 | pictplot.append(pictvals) |
---|
| 2749 | |
---|
| 2750 | # Header of the name of the figure |
---|
| 2751 | if ivp == 0: |
---|
| 2752 | figname = kplot +'_'+ vn + '_' + headf + '_' + op.replace('+','-') |
---|
| 2753 | else: |
---|
| 2754 | figname = figname + '-'+vn+'_'+headf+'_'+op.replace('+','-') |
---|
| 2755 | |
---|
| 2756 | ivp = ivp + 1 |
---|
| 2757 | # End of variable-operation |
---|
[1026] | 2758 | figname = figname + '.' + kindfigure |
---|
[1025] | 2759 | |
---|
[1363] | 2760 | # Removig double '..' (from `dimvarvalue') |
---|
| 2761 | figname = figname.replace('..', '.') |
---|
| 2762 | |
---|
[1080] | 2763 | # Title of figure |
---|
[1095] | 2764 | titfigure = create_figure_title(modlab, explab, varops, opexplained) |
---|
[1080] | 2765 | |
---|
[1025] | 2766 | draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ |
---|
[1095] | 2767 | figname, titfigure, kindfigure, mapvalue, timevals, expgc, odir, \ |
---|
| 2768 | pyHOME, figscr, debug) |
---|
[1025] | 2769 | |
---|
| 2770 | # End of variables-operations |
---|
| 2771 | |
---|
| 2772 | # End of kind of plots |
---|
| 2773 | |
---|
[1394] | 2774 | if debug: print " End of '" + fname + "' " |
---|
| 2775 | |
---|
[1025] | 2776 | return |
---|
| 2777 | |
---|
[1032] | 2778 | def get_differences_var(vc,kdiff,db): |
---|
| 2779 | """ Function to provide the operations to make for each variable from kdiff ('DIFFOP_' or 'DIFFVAR_') dictionary |
---|
| 2780 | vc= kdiff dictionary, dictionary with all the parameters started with kdiff |
---|
[1081] | 2781 | kdiff= kind of differences 'op', 'var' |
---|
[1032] | 2782 | """ |
---|
| 2783 | fname = 'get_differences_var' |
---|
| 2784 | |
---|
| 2785 | if kdiff == 'op': |
---|
| 2786 | diffn = 'DIFFOP' |
---|
| 2787 | elif kdiff == 'var': |
---|
| 2788 | diffn = 'DIFFVAR' |
---|
| 2789 | else: |
---|
| 2790 | print errmsg |
---|
| 2791 | print ' ' + fname + ": differences '" + kdiff + "' not ready !!" |
---|
| 2792 | quit(-1) |
---|
| 2793 | LD = len(diffn + '_') |
---|
| 2794 | |
---|
| 2795 | iop = 1 |
---|
| 2796 | # list of operations by difference |
---|
| 2797 | doopers = {} |
---|
| 2798 | # operations by variable |
---|
| 2799 | operationsvar = {} |
---|
| 2800 | # individual operations by variable (not repeated) |
---|
| 2801 | indivoperationsvar = {} |
---|
| 2802 | |
---|
| 2803 | # Variables with a calculation whic requires vertical interpolation to all the |
---|
| 2804 | # file (operations stating by [kdiff]'_pinterp') |
---|
| 2805 | LVp = len(diffn + '_pinterp') |
---|
| 2806 | varglobalp = [] |
---|
| 2807 | |
---|
| 2808 | for oper in vc.keys(): |
---|
| 2809 | Loper = len(oper) |
---|
| 2810 | opn = oper[LD:Loper+1] |
---|
| 2811 | vns = vc[oper].split(':') |
---|
| 2812 | ops1 = opn.split('+') |
---|
| 2813 | doopers[opn] = ops1 |
---|
| 2814 | for vn in vns: |
---|
| 2815 | if not operationsvar.has_key(vn): |
---|
| 2816 | operationsvar[vn] = [opn] |
---|
| 2817 | indivoperationsvar[vn] = ops1 |
---|
| 2818 | else: |
---|
| 2819 | opers = operationsvar[vn] |
---|
| 2820 | opers.append(opn) |
---|
| 2821 | operationsvar[vn] = opers |
---|
| 2822 | opers1 = indivoperationsvar[vn] |
---|
| 2823 | for op1 in ops1: |
---|
| 2824 | if not gen.searchInlist(opers1, op1): |
---|
| 2825 | opers1.append(op1) |
---|
| 2826 | indivoperationsvar[vn] = opers1 |
---|
| 2827 | |
---|
| 2828 | if oper[0:LVp] == diffn + '_pinterp': |
---|
| 2829 | for vn in vns: |
---|
| 2830 | if not gen.searchInlist(varglobalp,vn): varglobalp.append(vn) |
---|
| 2831 | |
---|
| 2832 | iop = iop + 1 |
---|
| 2833 | |
---|
| 2834 | if db: |
---|
| 2835 | print ' operations to make _______' |
---|
| 2836 | gen.printing_dictionary(doopers) |
---|
| 2837 | print ' operations by variable _______' |
---|
| 2838 | gen.printing_dictionary(operationsvar) |
---|
| 2839 | print ' individual operations by variable _______' |
---|
| 2840 | gen.printing_dictionary(indivoperationsvar) |
---|
| 2841 | print ' variables with the vertical interpolation for all the file _______' |
---|
| 2842 | print ' #', varglobalp |
---|
| 2843 | |
---|
[1394] | 2844 | if db: print " End of '" + fname + "' " |
---|
| 2845 | |
---|
[1032] | 2846 | return doopers, operationsvar, indivoperationsvar, varglobalp |
---|
| 2847 | |
---|
[1064] | 2848 | def diffvarop_listconstruct(config, mods, exps, reprj, odir, debug): |
---|
[1032] | 2849 | """ Function to create the list of differences to compute and draw |
---|
| 2850 | config= Configuration of the experiment |
---|
| 2851 | mods= list with the models to use |
---|
| 2852 | exps= list with the experiments to use |
---|
[1064] | 2853 | reprj= list with whether re-rpojection needs to be done |
---|
[1032] | 2854 | odir= output differences folder |
---|
| 2855 | """ |
---|
| 2856 | fname='diffvarop_listconstruct' |
---|
| 2857 | |
---|
| 2858 | diffop = gen.get_specdictionary_HMT(config, H='DIFFOP_') |
---|
| 2859 | diffvar = gen.get_specdictionary_HMT(config, H='DIFFVAR_') |
---|
| 2860 | |
---|
| 2861 | if debug: |
---|
[1069] | 2862 | if diffop is not None: |
---|
| 2863 | print " 'op' differences ________" |
---|
| 2864 | gen.printing_dictionary(diffop) |
---|
| 2865 | if diffvar is not None: |
---|
| 2866 | print " 'var' differences ________" |
---|
| 2867 | gen.printing_dictionary(diffvar) |
---|
[1032] | 2868 | |
---|
| 2869 | # Getting variable characteristics from each model/experiment |
---|
| 2870 | idir1 = config['ofold'] + '/' + mods[0] + '/' + exps[0] |
---|
| 2871 | idir2 = config['ofold'] + '/' + mods[1] + '/' + exps[1] |
---|
| 2872 | |
---|
[1064] | 2873 | fvarcomp = 'varcompute.inf' |
---|
| 2874 | if reprj[0]: fvc1 = 'reproj_' + fvarcomp |
---|
| 2875 | else: fvc1 = fvarcomp |
---|
[1032] | 2876 | |
---|
[1064] | 2877 | if reprj[1]: fvc2 = 'reproj_' + fvarcomp |
---|
| 2878 | else: fvc2 = fvarcomp |
---|
| 2879 | |
---|
| 2880 | files1, testfiles1, allcompvar1, Nvar1= read_varcomp_file(idir1 + '/' + fvc1) |
---|
| 2881 | files2, testfiles2, allcompvar2, Nvar2= read_varcomp_file(idir2 + '/' + fvc2) |
---|
| 2882 | |
---|
[1032] | 2883 | diffops = {} |
---|
[1069] | 2884 | if diffop is not None: |
---|
| 2885 | # Getting 'op' differences characteristics |
---|
| 2886 | doops, opvar, indivopvar, varglobalp = get_differences_var(diffop,'op',debug) |
---|
[1032] | 2887 | |
---|
[1069] | 2888 | Ndiffop = 0 |
---|
| 2889 | for vn in opvar.keys(): |
---|
| 2890 | vnops = opvar[vn] |
---|
| 2891 | for op in vnops: |
---|
| 2892 | vnop = vn + '_' + op |
---|
| 2893 | if not allcompvar1.has_key(vnop): |
---|
| 2894 | print warnmsg |
---|
| 2895 | print ' ' + fname + ": DIFFOP variable+operation '" + vnop + \ |
---|
| 2896 | "' in '" + mods[0] + '/' + exps[0] + "' was not computed !!" |
---|
| 2897 | print ' skipping it!' |
---|
[1111] | 2898 | print ' variables computed:', allcompvar1 |
---|
[1069] | 2899 | break |
---|
| 2900 | if not allcompvar2.has_key(vnop): |
---|
| 2901 | print warnmsg |
---|
| 2902 | print ' ' + fname + ": DIFFOP variable+operation '" + vnop + \ |
---|
| 2903 | "' in '" + mods[1] + '/' + exps[1] + "' was not computed !!" |
---|
| 2904 | print ' skipping it!' |
---|
[1111] | 2905 | print ' variables computed:', allcompvar2 |
---|
[1069] | 2906 | break |
---|
| 2907 | vals1 = allcompvar1[vnop] |
---|
| 2908 | vals2 = allcompvar2[vnop] |
---|
[1032] | 2909 | |
---|
[1069] | 2910 | headerf1 = vals1[0] |
---|
| 2911 | headerf2 = vals2[0] |
---|
[1032] | 2912 | |
---|
[1069] | 2913 | diffops[vnop] = [mods[0],mods[1],exps[0],exps[1],headerf1,headerf2] |
---|
[1032] | 2914 | |
---|
[1069] | 2915 | Ndiffop = Ndiffop + 1 |
---|
| 2916 | else: |
---|
| 2917 | Ndiffop = 0 |
---|
[1032] | 2918 | |
---|
| 2919 | diffvars = {} |
---|
[1069] | 2920 | if diffvar is not None: |
---|
| 2921 | # Getting 'var' differences characteristics |
---|
| 2922 | doops,opvar,indivopvar,varglobalp = get_differences_var(diffvar,'var',debug) |
---|
[1032] | 2923 | |
---|
[1069] | 2924 | Ndiffvar = 0 |
---|
| 2925 | for vn in opvar.keys(): |
---|
| 2926 | vnops = opvar[vn] |
---|
| 2927 | for op in vnops: |
---|
| 2928 | vnop = vn + '_' + op |
---|
| 2929 | if not allcompvar1.has_key(vnop): |
---|
| 2930 | print warnmsg |
---|
| 2931 | print ' ' + fname + ": DIFFVAR variable+operation '" + vnop + \ |
---|
| 2932 | "' in '" + mods[0] + '/' + exps[0] + "' was not computed !!" |
---|
| 2933 | print ' skipping it!' |
---|
[1111] | 2934 | print ' variables computed:', allcompvar1 |
---|
[1069] | 2935 | break |
---|
| 2936 | if not allcompvar2.has_key(vnop): |
---|
| 2937 | print warnmsg |
---|
| 2938 | print ' ' + fname + ": DIFFVAR variable+operation '" + vnop + \ |
---|
| 2939 | "' in '" + mods[1] + '/' + exps[1] + "' was not computed !!" |
---|
| 2940 | print ' skipping it!' |
---|
[1111] | 2941 | print ' variables computed:', allcompvar2 |
---|
[1069] | 2942 | break |
---|
| 2943 | vals1 = allcompvar1[vnop] |
---|
| 2944 | vals2 = allcompvar2[vnop] |
---|
| 2945 | |
---|
| 2946 | headerf1 = vals1[0] |
---|
| 2947 | headerf2 = vals2[0] |
---|
[1032] | 2948 | |
---|
[1069] | 2949 | diffvars[vnop] = [mods[0],mods[1],exps[0],exps[1],headerf1,headerf2] |
---|
[1032] | 2950 | |
---|
[1069] | 2951 | Ndiffvar = Ndiffvar + 1 |
---|
| 2952 | else: |
---|
| 2953 | Ndiffvar = 0 |
---|
[1032] | 2954 | |
---|
[1069] | 2955 | if diffop is not None: |
---|
| 2956 | Sopdiffs = gen.dictKeysVals_stringList(diffops) |
---|
| 2957 | else: |
---|
| 2958 | Sopdiffs = 'none' |
---|
| 2959 | # Outwritting the op diffferences file to avoid next time |
---|
[1032] | 2960 | objf = open(odir + '/diffop.inf', 'w') |
---|
| 2961 | objf.write('differences: ' + Sopdiffs + '\n') |
---|
| 2962 | objf.write('Ndiff: ' + str(Ndiffop) + '\n') |
---|
| 2963 | objf.close() |
---|
| 2964 | |
---|
[1069] | 2965 | if diffvar is not None: |
---|
| 2966 | Svardiffs = gen.dictKeysVals_stringList(diffvars) |
---|
| 2967 | else: |
---|
| 2968 | Svardiffs = 'none' |
---|
| 2969 | # Outwritting the var diffferences file to avoid next time |
---|
[1032] | 2970 | objf = open(odir + '/diffvar.inf', 'w') |
---|
| 2971 | objf.write('differences: ' + Svardiffs + '\n') |
---|
| 2972 | objf.write('Ndiff: ' + str(Ndiffvar) + '\n') |
---|
| 2973 | objf.close() |
---|
| 2974 | |
---|
[1394] | 2975 | if debug: print " End of '" + fname + "' " |
---|
| 2976 | |
---|
[1069] | 2977 | return diffops, diffvars, Ndiffop, Ndiffvar |
---|
[1032] | 2978 | |
---|
| 2979 | def read_diff_file(difffile): |
---|
| 2980 | """ Function to read the file with the information about the differences |
---|
| 2981 | difffile= file with the information |
---|
| 2982 | """ |
---|
| 2983 | fname = 'read_diff_file' |
---|
| 2984 | |
---|
| 2985 | if not os.path.isfile(difffile): |
---|
| 2986 | print errormsg |
---|
| 2987 | print ' ' + fname + ": differences file '" + difffile + "' does not exist !!" |
---|
| 2988 | quit(-1) |
---|
| 2989 | |
---|
| 2990 | objf = open(difffile, 'r') |
---|
| 2991 | for line in objf: |
---|
| 2992 | if line[0:1] != '#' and len(line) > 1: |
---|
[1064] | 2993 | values = line.replace('\n','').split(' ') |
---|
[1032] | 2994 | if values[0] == 'differences:': |
---|
[1085] | 2995 | if values[1] != 'none': |
---|
| 2996 | diffs = gen.stringList_dictKeysVals(values[1]) |
---|
| 2997 | else: |
---|
| 2998 | diffs = {} |
---|
[1032] | 2999 | elif values[0] == 'Ndiff:': |
---|
| 3000 | Ndiffs = int(values[1]) |
---|
| 3001 | |
---|
| 3002 | objf.close() |
---|
| 3003 | |
---|
| 3004 | return diffs, Ndiffs |
---|
| 3005 | |
---|
[1036] | 3006 | def compute_op_diffs(config, diffallop, odir, diffscr, debug): |
---|
| 3007 | """ Function to compute operation differences |
---|
| 3008 | config= experiment configuration |
---|
| 3009 | diffallop= dictonary with the differences to compute |
---|
| 3010 | odir= output folder |
---|
| 3011 | diffscr= wether it should be done from the scratch |
---|
| 3012 | """ |
---|
| 3013 | fname = 'compute_op_diffs' |
---|
| 3014 | |
---|
| 3015 | # output folder |
---|
| 3016 | ofold = config['ofold'] |
---|
| 3017 | |
---|
| 3018 | # Home of the python scripts |
---|
| 3019 | pyH = config['pyHOME'] |
---|
| 3020 | |
---|
| 3021 | # opsur = operation surnames |
---|
| 3022 | opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') |
---|
| 3023 | Opsurs = {} |
---|
| 3024 | for opk in opsur: |
---|
| 3025 | opn = opk.split('_')[1] |
---|
| 3026 | vals = opsur[opk] |
---|
| 3027 | Opsurs[opn] = vals.split(':') |
---|
| 3028 | |
---|
| 3029 | # Getting in working dir |
---|
| 3030 | os.chdir(odir) |
---|
| 3031 | |
---|
| 3032 | # CF dimensions |
---|
| 3033 | CFdims = ['lon', 'lat', 'pres', 'time'] |
---|
| 3034 | |
---|
| 3035 | # Trakcing file |
---|
| 3036 | trkobjf = open(odir + '/all_diffop.inf', 'a') |
---|
| 3037 | |
---|
| 3038 | for vnop in diffallop.keys(): |
---|
| 3039 | vn = vnop.split('_')[0] |
---|
| 3040 | op = vnop.split('_')[1] |
---|
| 3041 | opS = op.replace('+','_') |
---|
| 3042 | |
---|
| 3043 | # `p' header add related to 'pinterp' |
---|
| 3044 | if opS.find('pinterp') != -1: SgP = 'p' |
---|
| 3045 | else: SgP = '' |
---|
| 3046 | |
---|
| 3047 | # Variable name within the file |
---|
| 3048 | vninF = varnoper(vn, op, Opsurs) |
---|
| 3049 | |
---|
| 3050 | vals = diffallop[vnop] |
---|
| 3051 | mod1 = vals[0] |
---|
| 3052 | mod2 = vals[1] |
---|
| 3053 | exp1 = vals[2] |
---|
| 3054 | exp2 = vals[3] |
---|
| 3055 | headerf1 = vals[4] |
---|
| 3056 | headerf2 = vals[5] |
---|
| 3057 | modexpdiff = mod2 + '/' + exp2 + ' - ' + mod1 + '/' + exp1 |
---|
| 3058 | modexpdiffS = mod2 + '-' + exp2 + '_' + mod1 + '-' + exp1 |
---|
| 3059 | |
---|
| 3060 | ifile1 = ofold + '/' + mod1 + '/' + exp1 + '/' + vn + '_' + headerf1 + SgP + \ |
---|
| 3061 | '_' + opS + '.nc' |
---|
| 3062 | ifile2 = ofold + '/' + mod2 + '/' + exp2 + '/' + vn + '_' + headerf2 + SgP + \ |
---|
| 3063 | '_' + opS + '.nc' |
---|
| 3064 | difffilen = odir + '/' + vn + '_diffop_' + modexpdiffS + '_' + opS + '.nc' |
---|
| 3065 | |
---|
| 3066 | if diffscr: |
---|
| 3067 | sout = sub.call('rm ' + difffilen + ' >& /dev/null', shell=True) |
---|
| 3068 | |
---|
| 3069 | if not os.path.isfile(difffilen): |
---|
| 3070 | if debug: |
---|
[1085] | 3071 | print " Computing operation difference '" + op + "' of '" + vn + \ |
---|
[1036] | 3072 | "' for: '" + modexpdiff |
---|
| 3073 | print " var in file: '" + vninF + "'" |
---|
| 3074 | |
---|
[1266] | 3075 | # Range of the dimensions |
---|
| 3076 | for CFd in CFdims: |
---|
| 3077 | if CFd == CFdims[0]: |
---|
| 3078 | CFdimS = CFd + '|' + CFd + '|-1' |
---|
| 3079 | else: |
---|
[1268] | 3080 | CFdimS = CFdimS + ';' + CFd + '|' + CFd + '|-1' |
---|
[1266] | 3081 | |
---|
[1394] | 3082 | ncvar.ivattrs(ifile2,vninF) |
---|
| 3083 | |
---|
[1266] | 3084 | # Attributes of the variable |
---|
[1394] | 3085 | try: |
---|
| 3086 | with gen.Capturing() as output: |
---|
| 3087 | varattrs = ncvar.ivattrs(ifile2,vninF) |
---|
| 3088 | except: |
---|
| 3089 | print errmsg |
---|
| 3090 | print 'ncvar.ivarattrs(' + ifile2 + ',' + vninF + ')' |
---|
| 3091 | for s1out in output: print s1out |
---|
| 3092 | quit(-1) |
---|
| 3093 | |
---|
[1325] | 3094 | if debug: |
---|
| 3095 | for s1out in output: print s1out |
---|
[1268] | 3096 | varvals = vninF + ',' + varattrs['long_name'][0] + ',' + \ |
---|
| 3097 | varattrs['units'][0] |
---|
[1266] | 3098 | |
---|
[1268] | 3099 | values = CFdimS + '@' + 'add|' + ifile2 + '|' + vninF + '%' + CFdimS + \ |
---|
| 3100 | '@' + 'sub|' + ifile1 + '|' + vninF |
---|
[1036] | 3101 | pyins = 'python ' + pyH + "/nc_var.py -o compute_opersvarsfiles -S '" + \ |
---|
[1316] | 3102 | values + "' -v '" + varvals + "'" |
---|
[1036] | 3103 | |
---|
| 3104 | try: |
---|
| 3105 | with gen.Capturing() as output: |
---|
[1266] | 3106 | ncvar.compute_opersvarsfiles(values,varvals) |
---|
[1036] | 3107 | except: |
---|
| 3108 | print errmsg |
---|
[1266] | 3109 | print 'ncvar.compute_opersvarsfiles(' + values + ',' + varvals + ')' |
---|
[1064] | 3110 | for s1out in output: print s1out |
---|
[1036] | 3111 | quit(-1) |
---|
| 3112 | |
---|
| 3113 | sout = sub.call('mv opersvarsfiles_'+vninF+'.nc ' + difffilen, shell=True) |
---|
| 3114 | |
---|
| 3115 | # keeping all differences |
---|
| 3116 | trkobjf.write('\n') |
---|
| 3117 | trkobjf.write("#" + vn + ' ' + op + '\n') |
---|
| 3118 | trkobjf.write( pyins + '\n') |
---|
| 3119 | |
---|
| 3120 | trkobjf.close() |
---|
[1394] | 3121 | if debug: print " End of '" + fname + "' " |
---|
[1036] | 3122 | |
---|
| 3123 | return |
---|
| 3124 | |
---|
| 3125 | def compute_diff_statistics(Ecnf, filen, ofold, varn, Opers, scr, db): |
---|
| 3126 | """ Function to compute statistics from var diff files |
---|
| 3127 | Ecnf= dictionary with the configuration of the experiment |
---|
| 3128 | filen= variable difference file to use |
---|
| 3129 | ofold= directory to write the output files |
---|
| 3130 | varn= name of the variable |
---|
| 3131 | Opers= kind of operation: (as possible multiple consecutive combination of operations separated by '+' |
---|
| 3132 | [calc1]+[calc2] will compute first [calc1] and then [calc2] |
---|
| 3133 | acc: temporal accumulated values |
---|
| 3134 | diff: differences between models |
---|
[1363] | 3135 | dimvarvalue~[dimvarn]~[value]: Slicing along the index at the nearest given value of a dimension-variable |
---|
[1036] | 3136 | direct: no statistics |
---|
| 3137 | last: last temporal value |
---|
| 3138 | Lmean: latitudinal mean values |
---|
| 3139 | Lsec: latitudinal section (latitudinal value must be given, [var]@[lat]) |
---|
| 3140 | lmean: longitudinal mean values |
---|
| 3141 | lsec: longitudinal section (longitudinal value must be given, [var]@[lat]) |
---|
| 3142 | pinterp: pressure interpolation (to the given $plevels) |
---|
| 3143 | tmean: temporal mean values |
---|
[1041] | 3144 | tstd: temporal standard deviation values |
---|
[1104] | 3145 | tturb: Taylor's turbulence decomposition value (x - <x>) for time |
---|
| 3146 | tvar: temporal variance values |
---|
[1036] | 3147 | xmean: x-axis mean values |
---|
[1078] | 3148 | xvar: x-axis variance values |
---|
[1036] | 3149 | ymean: y-axis mean values |
---|
| 3150 | zsum: vertical aggregated values |
---|
| 3151 | scr= should it be done from the scratch? |
---|
| 3152 | """ |
---|
| 3153 | fname='compute_diff_statistics' |
---|
| 3154 | |
---|
| 3155 | # Full header of file |
---|
| 3156 | Lfilen = len(filen) |
---|
| 3157 | Hfile = filen[0:Lfilen-3] |
---|
| 3158 | |
---|
| 3159 | # CF dimension-variables name |
---|
| 3160 | OpersS = '+'.join(Opers) |
---|
[1039] | 3161 | if OpersS.find('pinterp') != -1 or filen.find('pinterp') != -1: |
---|
[1036] | 3162 | varnCFs = ['lon', 'lat', 'pres', 'time'] |
---|
| 3163 | else: |
---|
| 3164 | varnCFs = ['lon', 'lat', 'time'] |
---|
| 3165 | |
---|
| 3166 | # Variable-dimension CF dictionary |
---|
| 3167 | CFdimvardict = {'lon': 'lon', 'lat': 'lat', 'pres': 'pres', 'time': 'time'} |
---|
| 3168 | |
---|
| 3169 | # Python scripts HOME |
---|
| 3170 | pyH = Ecnf['pyHOME'] |
---|
| 3171 | |
---|
| 3172 | # opsur = operation surnames |
---|
| 3173 | opsur = gen.get_specdictionary_HMT(Ecnf, H='opsur_',M='',T='') |
---|
| 3174 | Opsurs = {} |
---|
| 3175 | for opk in opsur: |
---|
| 3176 | opn = opk.split('_')[1] |
---|
| 3177 | vals = opsur[opk] |
---|
| 3178 | Opsurs[opn] = vals.split(':') |
---|
| 3179 | |
---|
| 3180 | # Getting in working dir |
---|
| 3181 | os.chdir(ofold) |
---|
| 3182 | |
---|
| 3183 | # File to keep track of all the statistics of var differences |
---|
| 3184 | otrackf = open(ofold + '/all_vardiffstatistics.inf', 'a') |
---|
| 3185 | |
---|
| 3186 | if db: |
---|
| 3187 | print " computing statistics of diff variable: '", varn ,"' operation '"+ \ |
---|
| 3188 | OpersS + "' using file '" + filen + " ...'" |
---|
| 3189 | |
---|
| 3190 | for op in Opers: |
---|
| 3191 | # File name from previous operations, and name of the variable within the |
---|
| 3192 | # file (some operations change the name of the variable) |
---|
| 3193 | if op == Opers[0]: |
---|
| 3194 | Fopers = op |
---|
| 3195 | prevfile = filen |
---|
| 3196 | vninF = varn |
---|
| 3197 | else: |
---|
| 3198 | Fopers = Fopers + '_' + op |
---|
| 3199 | prevfile = fileon |
---|
| 3200 | fileon = Hfile + '_' + Fopers + '.nc' |
---|
| 3201 | |
---|
| 3202 | SvarnCFs = ',' + ','.join(varnCFs) |
---|
| 3203 | CFvarnp = vninF + SvarnCFs |
---|
| 3204 | |
---|
| 3205 | if scr: |
---|
| 3206 | sout = sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
| 3207 | |
---|
| 3208 | # Just produce file in case output file does not exist |
---|
| 3209 | if not os.path.isfile(fileon): |
---|
| 3210 | if db: |
---|
| 3211 | print ' ' + fname + ": creation of file '" + fileon + "' ..." |
---|
| 3212 | dofile = True |
---|
| 3213 | else: |
---|
| 3214 | dofile = False |
---|
| 3215 | |
---|
| 3216 | # Variables to be kept in the final file |
---|
| 3217 | varkeep = [] |
---|
| 3218 | |
---|
| 3219 | if op == 'acc': |
---|
| 3220 | # temporal accumulated values |
---|
| 3221 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
| 3222 | wrongstats.append(varn + '_' + opers) |
---|
| 3223 | break |
---|
[1363] | 3224 | |
---|
| 3225 | elif op[0:11] == 'dimvarvalue': |
---|
| 3226 | # Slicing along the index at the nearest given value of a dimension-variable |
---|
| 3227 | dimvarn = op.split('~')[1] |
---|
| 3228 | dimvalue = op.split('~')[2] |
---|
| 3229 | vals = dimvarn + ',' + dimvalue + ',' + dimvalue + ',0' |
---|
| 3230 | if dofile: |
---|
| 3231 | try: |
---|
| 3232 | with gen.Capturing() as output: |
---|
| 3233 | ncvar.DataSetSection_multivars(vals,prevfile,CFvarnp) |
---|
| 3234 | except: |
---|
| 3235 | print errmsg |
---|
| 3236 | print 'DataSetSection_multivars('+vals+',', prevfile, ',' + \ |
---|
| 3237 | CFvarnp + ')' |
---|
| 3238 | for s1out in output: print s1out |
---|
| 3239 | quit(-1) |
---|
| 3240 | |
---|
| 3241 | if db: |
---|
| 3242 | for s1out in output: print s1out |
---|
| 3243 | |
---|
| 3244 | sout = sub.call('mv DataSetSection_multivars.nc '+fileon, shell=True) |
---|
| 3245 | |
---|
| 3246 | # Keeping the operations |
---|
| 3247 | pyins=pyH + "/nc_var.py -o DataSetSection_multivars -S '" + vals + \ |
---|
| 3248 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3249 | otrackf.write("\n") |
---|
| 3250 | otrackf.write("# " + CFvarnp + " " + Fopers + "\n") |
---|
| 3251 | otrackf.write(pyins + "\n") |
---|
| 3252 | |
---|
| 3253 | # removing the given variable-dimension |
---|
| 3254 | varnCFs.remove(dimvarn) |
---|
| 3255 | |
---|
[1036] | 3256 | elif op == 'direct': |
---|
| 3257 | # no statistics |
---|
| 3258 | if dofile: |
---|
| 3259 | sout = sub.call('mv ' + prevfile + ' ' + fileon, shell=True) |
---|
| 3260 | elif op == 'last': |
---|
| 3261 | # last temporal value |
---|
| 3262 | vals='time,-9,0,0' |
---|
| 3263 | if dofile: |
---|
| 3264 | try: |
---|
| 3265 | with gen.Capturing() as output: |
---|
| 3266 | ncvar.DataSetSection(vals,prevfile) |
---|
| 3267 | except: |
---|
[1039] | 3268 | print errmsg |
---|
[1036] | 3269 | print 'DataSetSection('+vals+',', prevfile, ')' |
---|
[1064] | 3270 | for s1out in output: print s1out |
---|
[1036] | 3271 | quit(-1) |
---|
| 3272 | |
---|
| 3273 | if db: |
---|
[1064] | 3274 | for s1out in output: print s1out |
---|
[1036] | 3275 | |
---|
| 3276 | hprevfile = prevfile[0:len(prevfile)-3] |
---|
| 3277 | |
---|
| 3278 | sout = sub.call('mv ' + hprevfile + '_time_B-9-E0-I0.nc ' + fileon, \ |
---|
| 3279 | shell=True) |
---|
| 3280 | |
---|
| 3281 | # Keeping the operations |
---|
| 3282 | pyins=pyH + "/nc_var.py -o DataSetSection -S '" + vals + "' -f " + \ |
---|
| 3283 | prevfile |
---|
| 3284 | otrackf.write("\n") |
---|
| 3285 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
| 3286 | otrackf.write(pyins + "\n") |
---|
| 3287 | |
---|
| 3288 | elif op =='Lmean': |
---|
| 3289 | # latitudinal mean values |
---|
| 3290 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
| 3291 | wrongstats.append(varn + '_' + opers) |
---|
| 3292 | break |
---|
| 3293 | elif op =='Lsec': |
---|
| 3294 | # latitudinal section (latitudinal value must be given, [var]@[lat]) |
---|
| 3295 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
| 3296 | wrongstats.append(varn + '_' + opers) |
---|
| 3297 | break |
---|
| 3298 | elif op =='lmean': |
---|
| 3299 | # longitudinal mean values |
---|
| 3300 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
| 3301 | wrongstats.append(varn + '_' + opers) |
---|
| 3302 | break |
---|
| 3303 | elif op =='lsec': |
---|
| 3304 | # longitudinal section (longitudinal value must be given, [var]@[lon]) |
---|
| 3305 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
| 3306 | wrongstats.append(varn + '_' + opers) |
---|
| 3307 | break |
---|
| 3308 | elif op == 'tmean': |
---|
| 3309 | # temporal mean values |
---|
| 3310 | vals='time|-1,time,mean,' + ':'.join(varnCFs) |
---|
| 3311 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') |
---|
| 3312 | if dofile: |
---|
| 3313 | try: |
---|
| 3314 | with gen.Capturing() as output: |
---|
| 3315 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 3316 | except: |
---|
[1039] | 3317 | print errmsg |
---|
[1036] | 3318 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 3319 | for s1out in output: print s1out |
---|
[1036] | 3320 | quit(-1) |
---|
| 3321 | |
---|
| 3322 | if db: |
---|
[1064] | 3323 | for s1out in output: print s1out |
---|
[1036] | 3324 | |
---|
| 3325 | sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True) |
---|
| 3326 | |
---|
| 3327 | # Keeping the operations |
---|
| 3328 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 3329 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3330 | otrackf.write("\n") |
---|
| 3331 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
| 3332 | otrackf.write(pyins + "\n") |
---|
| 3333 | |
---|
| 3334 | # removing dimension variable-dimension 'time' |
---|
| 3335 | varnCFs.remove('time') |
---|
| 3336 | |
---|
| 3337 | varkeep.append('timestats') |
---|
| 3338 | |
---|
[1041] | 3339 | elif op == 'tstd': |
---|
| 3340 | # temporal standard deviation values |
---|
| 3341 | vals='time|-1,time,std,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 3342 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 3343 | if dofile: |
---|
| 3344 | try: |
---|
| 3345 | with gen.Capturing() as output: |
---|
| 3346 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 3347 | except: |
---|
| 3348 | print errmsg |
---|
| 3349 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 3350 | for s1out in output: print s1out |
---|
[1041] | 3351 | quit(-1) |
---|
| 3352 | |
---|
| 3353 | if db: |
---|
[1064] | 3354 | for s1out in output: print s1out |
---|
[1041] | 3355 | |
---|
| 3356 | sout = sub.call('mv file_oper_alongdims_std.nc '+fileon, shell=True) |
---|
| 3357 | |
---|
| 3358 | # Keeping the operations |
---|
| 3359 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 3360 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3361 | otrackf.write("\n") |
---|
| 3362 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
| 3363 | otrackf.write(pyins + "\n") |
---|
| 3364 | |
---|
| 3365 | # removing dimension variable-dimension 'time' |
---|
| 3366 | varnCFs.remove('time') |
---|
| 3367 | |
---|
| 3368 | varkeep.append('timestats') |
---|
| 3369 | |
---|
[1104] | 3370 | elif op == 'tturb': |
---|
| 3371 | # temporal turbulent values |
---|
| 3372 | vals='time|-1,time,turb,' + ':'.join(varnCFs) |
---|
| 3373 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') |
---|
| 3374 | if dofile: |
---|
| 3375 | try: |
---|
| 3376 | with gen.Capturing() as output: |
---|
| 3377 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 3378 | except: |
---|
| 3379 | print errmsg |
---|
| 3380 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
| 3381 | for s1out in output: print s1out |
---|
| 3382 | quit(-1) |
---|
[1036] | 3383 | |
---|
[1104] | 3384 | if db: |
---|
| 3385 | for s1out in output: print s1out |
---|
[1036] | 3386 | |
---|
[1104] | 3387 | sout = sub.call('mv file_oper_alongdims_turb.nc '+fileon, shell=True) |
---|
[1036] | 3388 | |
---|
[1104] | 3389 | # Keeping the operations |
---|
| 3390 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 3391 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3392 | otrackf.write("\n") |
---|
| 3393 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
| 3394 | otrackf.write(pyins + "\n") |
---|
| 3395 | |
---|
| 3396 | varkeep.append('timestats') |
---|
| 3397 | |
---|
[1043] | 3398 | elif op == 'tvar': |
---|
| 3399 | # temporal variance values (Taylor's turbulence) |
---|
| 3400 | vals='time|-1,time,var,' + ':'.join(varnCFs) + ':' + vdnz |
---|
| 3401 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') + dnz+'@'+vdnz |
---|
| 3402 | if dofile: |
---|
| 3403 | try: |
---|
| 3404 | with gen.Capturing() as output: |
---|
| 3405 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 3406 | except: |
---|
| 3407 | print errmsg |
---|
| 3408 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 3409 | for s1out in output: print s1out |
---|
[1043] | 3410 | quit(-1) |
---|
| 3411 | |
---|
| 3412 | if db: |
---|
[1064] | 3413 | for s1out in output: print s1out |
---|
[1043] | 3414 | |
---|
| 3415 | sout = sub.call('mv file_oper_alongdims_var.nc '+fileon, shell=True) |
---|
| 3416 | |
---|
| 3417 | # Keeping the operations |
---|
| 3418 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 3419 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3420 | otrackf.write("\n") |
---|
| 3421 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
| 3422 | otrackf.write(pyins + "\n") |
---|
| 3423 | |
---|
| 3424 | # removing dimension variable-dimension 'time' |
---|
| 3425 | varnCFs.remove('time') |
---|
| 3426 | |
---|
| 3427 | varkeep.append('timestats') |
---|
| 3428 | |
---|
[1036] | 3429 | elif op == 'xmean': |
---|
| 3430 | # x-axis mean values |
---|
| 3431 | vals='lon|-1,lon,mean,' + ':'.join(varnCFs) |
---|
| 3432 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') |
---|
| 3433 | if dofile: |
---|
| 3434 | try: |
---|
| 3435 | with gen.Capturing() as output: |
---|
| 3436 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 3437 | except: |
---|
[1039] | 3438 | print errmsg |
---|
[1036] | 3439 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 3440 | for s1out in output: print s1out |
---|
[1036] | 3441 | quit(-1) |
---|
| 3442 | |
---|
| 3443 | if db: |
---|
[1064] | 3444 | for s1out in output: print s1out |
---|
[1036] | 3445 | |
---|
| 3446 | sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True) |
---|
| 3447 | |
---|
| 3448 | # Keeping the operations |
---|
| 3449 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 3450 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3451 | otrackf.write("\n") |
---|
| 3452 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
| 3453 | otrackf.write(pyins + "\n") |
---|
| 3454 | |
---|
[1067] | 3455 | # removing dimension variable-dimension 'lon' |
---|
| 3456 | varnCFs.remove('lon') |
---|
| 3457 | |
---|
[1036] | 3458 | varkeep.append('lonstats') |
---|
| 3459 | |
---|
[1078] | 3460 | elif op == 'xvar': |
---|
| 3461 | # x-axis variance values |
---|
[1080] | 3462 | vals='lon|-1,lon,var,' + ':'.join(varnCFs) |
---|
| 3463 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') |
---|
[1078] | 3464 | if dofile: |
---|
| 3465 | try: |
---|
| 3466 | with gen.Capturing() as output: |
---|
| 3467 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 3468 | except: |
---|
| 3469 | print errmsg |
---|
| 3470 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
| 3471 | for s1out in output: print s1out |
---|
| 3472 | quit(-1) |
---|
| 3473 | |
---|
| 3474 | if db: |
---|
| 3475 | for s1out in output: print s1out |
---|
| 3476 | |
---|
| 3477 | sout = sub.call('mv file_oper_alongdims_var.nc '+fileon, shell=True) |
---|
| 3478 | |
---|
| 3479 | # Keeping the operations |
---|
| 3480 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 3481 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3482 | otrackf.write("\n") |
---|
[1080] | 3483 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
[1078] | 3484 | otrackf.write(pyins + "\n") |
---|
| 3485 | |
---|
| 3486 | # removing dimension variable-dimension 'lon' |
---|
| 3487 | varnCFs.remove('lon') |
---|
| 3488 | |
---|
| 3489 | varkeep.append('lonstats') |
---|
| 3490 | |
---|
[1036] | 3491 | elif op == 'ymean': |
---|
| 3492 | # y-axis mean values |
---|
| 3493 | vals='lat|-1,lat,mean,' + ':'.join(varnCFs) |
---|
| 3494 | dims = gen.dictvar_listS(varnCFs,CFdimvardict,',','@') |
---|
| 3495 | if dofile: |
---|
| 3496 | try: |
---|
| 3497 | with gen.Capturing() as output: |
---|
| 3498 | ncvar.file_oper_alongdims(vals,prevfile,CFvarnp) |
---|
| 3499 | except: |
---|
[1039] | 3500 | print errmsg |
---|
[1036] | 3501 | print 'file_oper_alongdims('+vals+',', prevfile, ','+CFvarnp+')' |
---|
[1064] | 3502 | for s1out in output: print s1out |
---|
[1036] | 3503 | quit(-1) |
---|
| 3504 | |
---|
| 3505 | if db: |
---|
[1064] | 3506 | for s1out in output: print s1out |
---|
[1036] | 3507 | |
---|
| 3508 | sout = sub.call('mv file_oper_alongdims_mean.nc '+fileon, shell=True) |
---|
| 3509 | |
---|
| 3510 | # Keeping the operations |
---|
| 3511 | pyins=pyH + "/nc_var.py -o file_oper_alongdims -S '" + vals + \ |
---|
| 3512 | "' -f " + prevfile + " -v " + CFvarnp |
---|
| 3513 | otrackf.write("\n") |
---|
| 3514 | otrackf.write("# " + varn + " " + Fopers + "\n") |
---|
| 3515 | otrackf.write(pyins + "\n") |
---|
| 3516 | |
---|
[1067] | 3517 | # removing dimension variable-dimension 'lat' |
---|
| 3518 | varnCFs.remove('lat') |
---|
| 3519 | |
---|
[1036] | 3520 | varkeep.append('latstats') |
---|
| 3521 | |
---|
| 3522 | elif op == 'zsum': |
---|
| 3523 | # vertical aggregated values |
---|
| 3524 | print " " + fname + ": kind '" + op + "' not ready !!" |
---|
| 3525 | wrongstats.append(varn + '_' + opers) |
---|
| 3526 | break |
---|
| 3527 | else: |
---|
| 3528 | print errmsg |
---|
| 3529 | print ' ' + fname + ": operation '" + op + "' not ready !!" |
---|
| 3530 | quit(-1) |
---|
| 3531 | |
---|
| 3532 | # End of kind of operation |
---|
| 3533 | |
---|
| 3534 | # Variable name in file (vninF) changed due to operation |
---|
| 3535 | # but only if previous operation does not the same 'statistic' |
---|
| 3536 | chvn = gen.dictionary_key_list(Opsurs, op) |
---|
| 3537 | if chvn is not None: |
---|
| 3538 | oldvninF = vninF |
---|
| 3539 | vninF = vninF + chvn |
---|
| 3540 | CFvarnp = CFvarnp.replace(oldvninF,vninF) |
---|
| 3541 | |
---|
| 3542 | if dofile: |
---|
| 3543 | if len(varkeep) > 0: |
---|
| 3544 | varkeepS = ',' + ','.join(varkeep) |
---|
| 3545 | else: |
---|
| 3546 | varkeepS = '' |
---|
| 3547 | |
---|
| 3548 | # Adding such CF dimension variables which might not be in the |
---|
| 3549 | # post-operation file |
---|
| 3550 | try: |
---|
| 3551 | with gen.Capturing() as output: |
---|
| 3552 | varinfile = ncvar.ivars(fileon) |
---|
| 3553 | except: |
---|
[1039] | 3554 | print errmsg |
---|
[1036] | 3555 | print 'ivars('+fileon+')' |
---|
[1064] | 3556 | for s1out in output: print s1out |
---|
[1270] | 3557 | # Removing file in order to make sure that it will be redone |
---|
| 3558 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 3559 | sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1036] | 3560 | quit(-1) |
---|
| 3561 | |
---|
| 3562 | for CFvn in varnCFs: |
---|
| 3563 | if not gen.searchInlist(varinfile, CFvn): |
---|
| 3564 | if db: |
---|
| 3565 | print ' ' + fname + ": recupering CF variable '" + CFvn + "'" |
---|
| 3566 | try: |
---|
| 3567 | with gen.Capturing() as output: |
---|
| 3568 | ncvar.fvaradd(prevfile+','+CFvn, fileon) |
---|
| 3569 | except: |
---|
[1039] | 3570 | print errmsg |
---|
[1067] | 3571 | print 'fvaradd(' + prevfile + ',' + CFvn +', ' + fileon + ')' |
---|
[1064] | 3572 | for s1out in output: print s1out |
---|
[1270] | 3573 | # Removing file in order to make sure that it will be redone |
---|
| 3574 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 3575 | sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1036] | 3576 | quit(-1) |
---|
| 3577 | |
---|
| 3578 | if db: |
---|
[1064] | 3579 | for s1out in output: print s1out |
---|
[1036] | 3580 | |
---|
| 3581 | totalvarkeeps = CFvarnp + ',' + ','.join(varnCFs) + varkeepS |
---|
| 3582 | try: |
---|
| 3583 | with gen.Capturing() as output: |
---|
| 3584 | oclean = ncvar.cleaning_varsfile(totalvarkeeps,fileon) |
---|
| 3585 | except: |
---|
[1039] | 3586 | print errmsg |
---|
[1036] | 3587 | print 'cleaning_varsfile('+totalvarkeeps+','+fileon+')' |
---|
[1064] | 3588 | for s1out in output: print s1out |
---|
[1270] | 3589 | # Removing file in order to make sure that it will be redone |
---|
| 3590 | print ' ' + fname + " removing file '" + fileon + "' ..." |
---|
| 3591 | sub.call('rm ' + fileon + ' >& /dev/null', shell=True) |
---|
[1036] | 3592 | quit(-1) |
---|
| 3593 | |
---|
| 3594 | if db: |
---|
[1064] | 3595 | for s1out in output: print s1out |
---|
[1036] | 3596 | |
---|
| 3597 | # End of operations |
---|
| 3598 | otrackf.close() |
---|
| 3599 | |
---|
[1394] | 3600 | if db: print " End of '" + fname + "' " |
---|
| 3601 | |
---|
[1036] | 3602 | return |
---|
| 3603 | |
---|
| 3604 | def compute_var_diffs(config, diffallvar, odir, diffscr, debug): |
---|
| 3605 | """ Function to compute variable differences |
---|
| 3606 | config= experiment configuration |
---|
| 3607 | diffallvar= dictonary with the differences to compute |
---|
| 3608 | odir= output folder |
---|
| 3609 | diffscr= wether it should be done from the scratch |
---|
| 3610 | """ |
---|
| 3611 | fname = 'compute_var_diffs' |
---|
| 3612 | |
---|
| 3613 | # output folder |
---|
| 3614 | ofold = config['ofold'] |
---|
| 3615 | |
---|
| 3616 | # Home of the python scripts |
---|
| 3617 | pyH = config['pyHOME'] |
---|
| 3618 | |
---|
| 3619 | # opsur = operation surnames |
---|
| 3620 | opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') |
---|
| 3621 | Opsurs = {} |
---|
| 3622 | for opk in opsur: |
---|
| 3623 | opn = opk.split('_')[1] |
---|
| 3624 | vals = opsur[opk] |
---|
| 3625 | Opsurs[opn] = vals.split(':') |
---|
| 3626 | |
---|
| 3627 | # Getting in working dir |
---|
| 3628 | os.chdir(odir) |
---|
| 3629 | |
---|
| 3630 | # CF dimensions |
---|
| 3631 | CFdims = ['lon', 'lat', 'pres', 'time'] |
---|
| 3632 | |
---|
| 3633 | # Trakcing file |
---|
| 3634 | trkobjf = open(odir + '/all_diffvar.inf', 'a') |
---|
| 3635 | |
---|
| 3636 | for vnop in diffallvar.keys(): |
---|
| 3637 | vn = vnop.split('_')[0] |
---|
| 3638 | op = vnop.split('_')[1] |
---|
| 3639 | opSfinal = op.replace('+','_') |
---|
| 3640 | |
---|
| 3641 | lop = op.split('+') |
---|
| 3642 | # `p' header add related to 'pinterp' |
---|
| 3643 | if op.find('pinterp') != -1: |
---|
| 3644 | print warnmsg |
---|
| 3645 | print ' ' + fname + ': there is the vertical interpolation as operation' |
---|
| 3646 | print ' variable differences will be computed from that files where ' |
---|
| 3647 | print ' vertical interpolation was just done' |
---|
| 3648 | ipop = lop.index('pinterp') |
---|
| 3649 | opS = '_' + '_'.join(lop[0:ipop+1]) |
---|
| 3650 | doops = lop[ipop+1:] |
---|
| 3651 | SgP = 'p' |
---|
| 3652 | vninF = varnoper(vn, '+'.join(lop[0:ipop+1]), Opsurs) |
---|
| 3653 | print ' operations to perform:', doops |
---|
| 3654 | else: |
---|
| 3655 | SgP = '' |
---|
| 3656 | opS = '' |
---|
| 3657 | doops = lop |
---|
| 3658 | vninF = vn |
---|
| 3659 | |
---|
| 3660 | Sdoops = '+'.join(doops) |
---|
| 3661 | |
---|
| 3662 | # Variable name within the file |
---|
| 3663 | |
---|
| 3664 | vals = diffallvar[vnop] |
---|
| 3665 | mod1 = vals[0] |
---|
| 3666 | mod2 = vals[1] |
---|
| 3667 | exp1 = vals[2] |
---|
| 3668 | exp2 = vals[3] |
---|
| 3669 | headerf1 = vals[4] |
---|
| 3670 | headerf2 = vals[5] |
---|
| 3671 | modexpdiff = mod2 + '/' + exp2 + ' - ' + mod1 + '/' + exp1 |
---|
| 3672 | modexpdiffS = mod2 + '-' + exp2 + '_' + mod1 + '-' + exp1 |
---|
| 3673 | |
---|
| 3674 | ifile1 = ofold + '/' + mod1 + '/' + exp1 + '/' + vn + '_' + headerf1 + SgP + \ |
---|
| 3675 | opS + '.nc' |
---|
| 3676 | ifile2 = ofold + '/' + mod2 + '/' + exp2 + '/' + vn + '_' + headerf2 + SgP + \ |
---|
| 3677 | opS + '.nc' |
---|
| 3678 | difffilen = odir + '/' + vn + '_diffvar_' + modexpdiffS + opS + '.nc' |
---|
| 3679 | difffinalfilen = odir + '/' + vn + '_diffvar_' + modexpdiffS + opS + '_' + \ |
---|
| 3680 | Sdoops + '.nc' |
---|
| 3681 | |
---|
| 3682 | if diffscr: |
---|
| 3683 | sout = sub.call('rm ' + difffilen + ' >& /dev/null', shell=True) |
---|
| 3684 | sout = sub.call('rm ' + difffinalfilen + ' >& /dev/null', shell=True) |
---|
| 3685 | |
---|
| 3686 | if not os.path.isfile(difffinalfilen): |
---|
| 3687 | if debug: |
---|
[1085] | 3688 | print " Computing variable difference of '" + vn + "' for: '" + \ |
---|
[1036] | 3689 | modexpdiff + "' and performing operation '" + Sdoops + "'" |
---|
| 3690 | print " var in file: '" + vninF + "'" |
---|
| 3691 | |
---|
[1266] | 3692 | # Range of the dimensions |
---|
| 3693 | for CFd in CFdims: |
---|
| 3694 | if CFd == CFdims[0]: |
---|
| 3695 | CFdimS = CFd + '|' + CFd + '|-1' |
---|
| 3696 | else: |
---|
[1268] | 3697 | CFdimS = CFdimS + ';' + CFd + '|' + CFd + '|-1' |
---|
[1266] | 3698 | |
---|
| 3699 | # Attributes of the variable |
---|
[1325] | 3700 | with gen.Capturing() as output: |
---|
| 3701 | varattrs = ncvar.ivattrs(ifile2,vninF) |
---|
| 3702 | if debug: |
---|
| 3703 | for s1out in output: print s1out |
---|
[1268] | 3704 | varvals = vninF + ',' + varattrs['long_name'][0] + ',' + \ |
---|
| 3705 | varattrs['units'][0] |
---|
[1266] | 3706 | |
---|
[1268] | 3707 | values = CFdimS + '@' + 'add|' + ifile2 + '|' + vninF + '%' + CFdimS + \ |
---|
| 3708 | '@' + 'sub|' + ifile1 + '|' + vninF |
---|
[1036] | 3709 | pyins = 'python ' + pyH + "/nc_var.py -o compute_opersvarsfiles -S '" + \ |
---|
[1316] | 3710 | values + "' -v '" + varvals + "'" |
---|
[1036] | 3711 | |
---|
| 3712 | try: |
---|
| 3713 | with gen.Capturing() as output: |
---|
[1266] | 3714 | ncvar.compute_opersvarsfiles(values,varvals) |
---|
[1036] | 3715 | except: |
---|
| 3716 | print errmsg |
---|
[1266] | 3717 | print 'ncvar.compute_opersvarsfiles(' + values + ', ' + varvals + ')' |
---|
[1064] | 3718 | for s1out in output: print s1out |
---|
[1036] | 3719 | quit(-1) |
---|
| 3720 | |
---|
| 3721 | sout = sub.call('mv opersvarsfiles_'+vninF+'.nc ' + difffilen, shell=True) |
---|
| 3722 | |
---|
| 3723 | # keeping all differences |
---|
| 3724 | trkobjf.write('\n') |
---|
| 3725 | trkobjf.write("#" + vn + ' ' + op + '\n') |
---|
| 3726 | trkobjf.write( pyins + '\n') |
---|
| 3727 | |
---|
| 3728 | # Computing statisitcs |
---|
| 3729 | compute_diff_statistics(config, difffilen, odir, vninF, doops, diffscr, \ |
---|
| 3730 | debug) |
---|
| 3731 | |
---|
| 3732 | trkobjf.close() |
---|
| 3733 | |
---|
[1394] | 3734 | if debug: print " End of '" + fname + "' " |
---|
| 3735 | |
---|
[1036] | 3736 | return |
---|
| 3737 | |
---|
[1039] | 3738 | |
---|
| 3739 | def draw_diff_plots(config, plots, odir, allvarcomp, kdiff, figscr, debug): |
---|
| 3740 | """ Function to draw all plots |
---|
| 3741 | config= Configuration of the experiment |
---|
| 3742 | plots= dictionary with the plots |
---|
| 3743 | odir= output experiment folder |
---|
| 3744 | allvarcomp= dictionary with all the variables to compute and their information |
---|
| 3745 | kdiff= kind of differences: |
---|
| 3746 | 'diffop': plots from operation differences |
---|
| 3747 | 'diffvar': plots from variable differences |
---|
| 3748 | figscr= whether figures should be done from the scratch or not |
---|
| 3749 | |
---|
| 3750 | * Plot as |
---|
| 3751 | {[kplot]} = [varn1]|[op1]#[varn2]|[op2]#[...[varnN]|[opN]], ... |
---|
| 3752 | [kplot] ___ |
---|
| 3753 | diffmap2Dsfc: 2D map of surface differences values of 1 variable |
---|
| 3754 | diffmap2Dz: 2D map of 3D differences values of 1 variable |
---|
| 3755 | map2Dsfc: 2D map of surface values of 1 variable |
---|
| 3756 | map3D: 2D map of 3D values of 1 variable |
---|
| 3757 | shadconthovmsfc: Hovmoeller diagrams of 2 variable at the surface in shadow and the other in contourn |
---|
| 3758 | shadcont2Dsfc: 2D map of shadow (1st variable) and countour (2nd variable) [stvar1]#[stvar2] |
---|
| 3759 | shadcont2Dzsec: 2D map of vertical section of 2 variables one in shadow and the other in contourn |
---|
| 3760 | [varn] |
---|
| 3761 | variable |
---|
| 3762 | [op] |
---|
| 3763 | '+' separated list of operations |
---|
| 3764 | in figures with more than 1 variable, use '#' to separate the [varn]|[op] |
---|
| 3765 | """ |
---|
| 3766 | fname = 'draw_diff_plots' |
---|
| 3767 | |
---|
| 3768 | os.chdir(odir) |
---|
| 3769 | |
---|
| 3770 | # Dictionary with the operations with surnames for the operated variable |
---|
| 3771 | opersurnames = {} |
---|
| 3772 | opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') |
---|
| 3773 | for opsr in opsur.keys(): |
---|
| 3774 | opn = opsr.split('_')[1] |
---|
| 3775 | vls = opsur[opsr].split(':') |
---|
| 3776 | opersurnames[opn] = vls |
---|
| 3777 | |
---|
| 3778 | # time values |
---|
| 3779 | # Units time for the plots |
---|
| 3780 | rd = config['CFreftime'] |
---|
| 3781 | tunits = config['CFunitstime'] + '!since!' + rd[0:4] + '-' + rd[4:6] + '-' + \ |
---|
| 3782 | rd[6:8] + '!' + rd[8:10] + ':' + rd[10:12] + ':' + rd[12:14] |
---|
| 3783 | # time ticks kind |
---|
| 3784 | tkind = config['timekind'] |
---|
| 3785 | # time ticks format |
---|
| 3786 | tfmt = config['timefmt'] |
---|
| 3787 | # time axis label |
---|
| 3788 | tlab = config['timelabel'] |
---|
| 3789 | timevals = [tunits, tkind, tfmt, tlab] |
---|
| 3790 | |
---|
| 3791 | if kdiff == 'diffop': |
---|
| 3792 | specplotkeyn = 'specificdiffopplot' |
---|
| 3793 | elif kdiff == 'diffvar': |
---|
| 3794 | specplotkeyn = 'specificdiffvarplot' |
---|
| 3795 | else: |
---|
| 3796 | print errmsg |
---|
| 3797 | print ' ' + fname + ": differences kind '" + kdiff + "' not ready !!" |
---|
| 3798 | quit(-1) |
---|
| 3799 | |
---|
| 3800 | # Dictionary of plot specificities |
---|
| 3801 | plotspecifics = {} |
---|
| 3802 | if config.has_key(specplotkeyn): |
---|
| 3803 | # [minval]: minimum value |
---|
| 3804 | # [maxval]: minimum value |
---|
| 3805 | # [colorbar]: name of the colorbar (from matplotlib) to use |
---|
| 3806 | # [cntformat]: format of the contour labels |
---|
| 3807 | # [colorcnt]: color for the countor lines |
---|
| 3808 | plotspecs = config[specplotkeyn].split(':') |
---|
| 3809 | for pltspc in plotspecs: |
---|
| 3810 | pltvls = pltspc.split('|') |
---|
| 3811 | vn = pltvls[0] |
---|
| 3812 | op = pltvls[1] |
---|
| 3813 | fn = pltvls[2] |
---|
| 3814 | plotspecifics[fn + '_' + vn + '_' + op] = pltvls[3:] |
---|
| 3815 | if debug: |
---|
| 3816 | print 'Specific values for plots _______' |
---|
| 3817 | gen.printing_dictionary(plotspecifics) |
---|
| 3818 | |
---|
| 3819 | # Kind of figures |
---|
| 3820 | kindfigure = config['kindfig'] |
---|
| 3821 | |
---|
[1095] | 3822 | # Graphical labels and configuration |
---|
| 3823 | modgc, expgc = graphical_characteristics(config, debug) |
---|
| 3824 | |
---|
[1039] | 3825 | # Map value |
---|
| 3826 | mapvalue = config['mapval'] |
---|
| 3827 | |
---|
| 3828 | # pythone scripts HOME |
---|
| 3829 | pyHOME = config['pyHOME'] |
---|
| 3830 | |
---|
| 3831 | # Title-text of operations |
---|
| 3832 | opexplained = {} |
---|
| 3833 | optits = config['titleoperations'].split(':') |
---|
| 3834 | for optit in optits: |
---|
| 3835 | opn = optit.split('|')[0] |
---|
| 3836 | opt = optit.split('|')[1] |
---|
| 3837 | opexplained[opn] = opt |
---|
| 3838 | if debug: |
---|
| 3839 | print 'Titles for operations _______' |
---|
| 3840 | gen.printing_dictionary(opexplained) |
---|
| 3841 | |
---|
| 3842 | for kplot in plots.keys(): |
---|
| 3843 | varsplt = plots[kplot] |
---|
| 3844 | for varplt in varsplt: |
---|
| 3845 | if debug: |
---|
| 3846 | print " printing '" + kplot + "' var ':" + varplt + "'..." |
---|
| 3847 | varops = varplt.split('#') |
---|
| 3848 | |
---|
| 3849 | # CF variables in plot |
---|
| 3850 | CFvarsplot = [] |
---|
| 3851 | # Files in plot |
---|
| 3852 | filesplot = [] |
---|
| 3853 | # Variables in plot within the files |
---|
| 3854 | varsplot = [] |
---|
| 3855 | # Dims in figure |
---|
| 3856 | dimsplot = [] |
---|
| 3857 | # pictoric values in figure |
---|
| 3858 | pictplot = [] |
---|
| 3859 | # Name of the figure |
---|
| 3860 | figname = '' |
---|
| 3861 | # Title of the figure |
---|
| 3862 | titfigure = '' |
---|
| 3863 | |
---|
| 3864 | ivp = 0 |
---|
| 3865 | for varop in varops: |
---|
| 3866 | vn = varop.split('|')[0] |
---|
| 3867 | op = varop.split('|')[1] |
---|
| 3868 | |
---|
| 3869 | # CF variables in plot |
---|
| 3870 | CFvarsplot.append(vn) |
---|
| 3871 | |
---|
| 3872 | vnopS = vn + '_' + op |
---|
| 3873 | if not allvarcomp.has_key(vnopS): |
---|
| 3874 | print errmsg |
---|
| 3875 | print ' ' + fname + ": no file for variable-operation '" + \ |
---|
| 3876 | vnopS + "' !!" |
---|
[1341] | 3877 | print ' available ones:', allvarcomp.keys() |
---|
| 3878 | quit(-1) |
---|
[1039] | 3879 | vopvals = allvarcomp[vnopS] |
---|
| 3880 | mod1 = vopvals[0] |
---|
| 3881 | mod2 = vopvals[1] |
---|
| 3882 | mod3 = vopvals[2] |
---|
| 3883 | mod4 = vopvals[3] |
---|
| 3884 | headf = vopvals[4] |
---|
| 3885 | |
---|
[1095] | 3886 | modv = modgc[mod1] |
---|
| 3887 | expv = expgc[mod1+'/'+exp1] |
---|
| 3888 | modlab1 = modv.label |
---|
| 3889 | explab1 = expv.label |
---|
| 3890 | modv = modgc[mod2] |
---|
| 3891 | expv = expgc[mod2+'/'+exp2] |
---|
| 3892 | modlab2 = modv.label |
---|
| 3893 | explab2 = expv.label |
---|
| 3894 | |
---|
| 3895 | modexpdiff = explab2 + '-' + explab1 |
---|
[1039] | 3896 | modexpdiffS = mod2 + '-' + exp2 + '_' + mod1 + '-' + exp1 |
---|
| 3897 | |
---|
| 3898 | difffilen = odir + '/' + vn + '_' + kdiff + '_' + modexpdiffS + \ |
---|
| 3899 | '_' + op.replace('+','_') + '.nc' |
---|
| 3900 | |
---|
| 3901 | filesplot.append(difffilen) |
---|
| 3902 | # Do we have processed the given difference? |
---|
| 3903 | if not os.path.isfile(difffilen): |
---|
| 3904 | print warnmsg |
---|
| 3905 | print " " + fname + ": there is no file for '" + kdiff + \ |
---|
| 3906 | "' difference '" + varop + "' skiping it !!" |
---|
| 3907 | break |
---|
| 3908 | |
---|
| 3909 | # Name of the variable inside the file |
---|
| 3910 | vnsur = varnoper(vn, op, opersurnames) |
---|
| 3911 | varsplot.append(vnsur) |
---|
| 3912 | |
---|
| 3913 | # Dimensions in file |
---|
| 3914 | try: |
---|
| 3915 | with gen.Capturing() as output: |
---|
| 3916 | dims = ncvar.idims(difffilen) |
---|
| 3917 | except: |
---|
| 3918 | print errmsg |
---|
| 3919 | print 'ncvar.idims('+difffilen+')' |
---|
[1064] | 3920 | for s1out in output: print s1out |
---|
[1039] | 3921 | quit(-1) |
---|
| 3922 | |
---|
| 3923 | dimsplot.append(dims) |
---|
| 3924 | |
---|
| 3925 | # pictoric values for the figure |
---|
| 3926 | Sfivaop = kplot + '_' + vn + '_' + op |
---|
| 3927 | if plotspecifics.has_key(Sfivaop): |
---|
| 3928 | pictvals = plotspecifics[Sfivaop] |
---|
| 3929 | else: |
---|
| 3930 | Vvals = gen.variables_values(vn) |
---|
[1067] | 3931 | pictvals = [Vvals[2], Vvals[3], Vvals[6], '%g', 'fixsigc','black'] |
---|
[1039] | 3932 | |
---|
| 3933 | pictplot.append(pictvals) |
---|
| 3934 | |
---|
| 3935 | # Header of the name of the figure |
---|
| 3936 | if ivp == 0: |
---|
| 3937 | figname = kplot + '_' + vn + '_' + kdiff + '_' + modexpdiffS + \ |
---|
| 3938 | '_' + op.replace('+','-') |
---|
| 3939 | else: |
---|
| 3940 | figname = figname + '-' + vn + '_' + op.replace('+','-') |
---|
| 3941 | |
---|
| 3942 | # Title of the figure: |
---|
| 3943 | if mod1 == mod2: |
---|
| 3944 | modexptit = mod1 + '!' + exp2 + '-' + exp1 |
---|
| 3945 | else: |
---|
| 3946 | modexptit = modexpdiff |
---|
| 3947 | |
---|
| 3948 | ivp = ivp + 1 |
---|
| 3949 | # End of variable-operation |
---|
| 3950 | figname = figname + '.' + kindfigure |
---|
| 3951 | |
---|
[1080] | 3952 | # Title of figure |
---|
| 3953 | titfigure = create_figure_title(modexptit, kdiff, varops, opexplained) |
---|
| 3954 | |
---|
[1039] | 3955 | if len(titfigure) > 80: |
---|
| 3956 | print warnmsg |
---|
| 3957 | print ' ' + fname + ": figure title '" + titfigure.replace('!', ' ')+\ |
---|
| 3958 | "' larger than 80 characters (actually", len(titfigure), ') !!' |
---|
| 3959 | print " simplifying it to '" + modexptit.replace('!',' ') + '!' + \ |
---|
| 3960 | kdiff + '!' + vnS + "'" |
---|
| 3961 | titfigure = modexptit.replace(' ','!') + '!' + kdiff + '!' + vnS |
---|
| 3962 | |
---|
| 3963 | draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ |
---|
[1095] | 3964 | figname, titfigure, kindfigure, mapvalue, timevals, expgc, odir, \ |
---|
| 3965 | pyHOME, figscr, debug) |
---|
[1039] | 3966 | |
---|
| 3967 | # End of variables-operations |
---|
| 3968 | |
---|
| 3969 | # End of kind of plots |
---|
| 3970 | |
---|
[1394] | 3971 | if debug: print " End of '" + fname + "' " |
---|
| 3972 | |
---|
[1039] | 3973 | return |
---|
| 3974 | |
---|
[1186] | 3975 | def reproject_modexp(mod,exp,config,REPRJops,fscr,fadd,debug): |
---|
[1064] | 3976 | """ Function to re-project and re-compute files from a given model/experiment |
---|
| 3977 | mod= model |
---|
| 3978 | exp= experiment |
---|
| 3979 | config= configuration |
---|
[1186] | 3980 | REPRJops= dictionary with the reprojection operators to use for reproject and for which variable |
---|
| 3981 | # remapbil CDO: Bilinear interpolation |
---|
| 3982 | # remapbic CDO: Bicubic interpolation |
---|
| 3983 | # remapdis CDO: Distance-weighted average remapping |
---|
| 3984 | # remapnn CDO: Nearest neighbor remapping |
---|
| 3985 | # Operators only available if projections have the corners of the grid points. |
---|
| 3986 | # remapcon CDO: First order conservative remapping |
---|
| 3987 | # remapcon2 CDO: Second order conservative remapping |
---|
| 3988 | # remaplaf CDO: Largest area fraction remapping |
---|
| 3989 | ####### ####### ####### or additionally ####### ####### ####### |
---|
| 3990 | # python remapping |
---|
| 3991 | # dis python: Distance-weighted average remapping |
---|
| 3992 | # pnn python: Nearest neighbor remapping |
---|
| 3993 | |
---|
[1064] | 3994 | fscr= re-projected files to compute from the scratch |
---|
| 3995 | fadd= re-projected files to be added |
---|
| 3996 | """ |
---|
| 3997 | fname = 'reproject_modexp' |
---|
| 3998 | |
---|
| 3999 | odir = config['ofold'] + '/' + mod + '/' + exp |
---|
| 4000 | |
---|
[1067] | 4001 | # NON re-projectable operations |
---|
| 4002 | opNOreproj = config['NOreprojops'].split(':') |
---|
| 4003 | |
---|
[1064] | 4004 | # Need to pass to analyze all the data? |
---|
| 4005 | inffiles = ['reproj_varcompute.inf', 'all_reproj_computevars.inf'] |
---|
| 4006 | if fscr: |
---|
| 4007 | for inff in inffiles: |
---|
| 4008 | if debug: print " removing information file '" + inff + "' ..." |
---|
| 4009 | ins = 'rm ' + odir + '/' + inff + ' >& /dev/null' |
---|
| 4010 | sout = sub.call(ins, shell=True) |
---|
| 4011 | |
---|
| 4012 | objf = open(odir+'/all_reproj_computevars.inf','w') |
---|
| 4013 | objf.write("## Computation of reprojected variables \n") |
---|
| 4014 | objf.close() |
---|
| 4015 | |
---|
| 4016 | varcompf = odir + '/reproj_varcompute.inf' |
---|
| 4017 | if fadd: |
---|
| 4018 | sub.call('rm ' + varcompf +' >& /dev/null', shell=True) |
---|
| 4019 | |
---|
[1186] | 4020 | # CF dims-vardims pairs: |
---|
| 4021 | CFvardims = ['long@lon', 'lat@lat', 'pres@pres', 'time@time'] |
---|
| 4022 | |
---|
| 4023 | # Dictionary with the operations with surnames for the operated variable |
---|
| 4024 | opersurnames = {} |
---|
| 4025 | opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') |
---|
| 4026 | for opsr in opsur.keys(): |
---|
| 4027 | opn = opsr.split('_')[1] |
---|
| 4028 | vls = opsur[opsr].split(':') |
---|
| 4029 | opersurnames[opn] = vls |
---|
| 4030 | |
---|
[1064] | 4031 | if not os.path.isfile(varcompf): |
---|
| 4032 | # Getting original computing information |
---|
| 4033 | origvarcompf = odir + '/varcompute.inf' |
---|
| 4034 | origfiles,origtestfiles,origallcompvar, Nvar = read_varcomp_file(origvarcompf) |
---|
| 4035 | |
---|
| 4036 | Svarcompute = '' |
---|
| 4037 | allcompvar = dict(origallcompvar) |
---|
| 4038 | ivop = 0 |
---|
| 4039 | for vnop in origallcompvar.keys(): |
---|
| 4040 | vn = vnop.split('_')[0] |
---|
| 4041 | op = vnop.split('_')[1] |
---|
| 4042 | values = allcompvar[vnop] |
---|
| 4043 | values[0] = 'reproj-' + values[0] |
---|
| 4044 | allcompvar[vnop] = values |
---|
| 4045 | |
---|
| 4046 | # Building strings from list values |
---|
| 4047 | model = values[1] |
---|
| 4048 | diag = values[2] |
---|
| 4049 | if model is not None: |
---|
| 4050 | if type(model) == type(list([1, 2])): |
---|
| 4051 | Smodel = ':'.join(model) |
---|
| 4052 | elif type(model) == type('A'): |
---|
| 4053 | Smodel = model |
---|
| 4054 | else: |
---|
| 4055 | Smodel = 'None' |
---|
| 4056 | if diag is not None: |
---|
| 4057 | if type(diag) == type(list([1, 2])): |
---|
| 4058 | Sdiag = ':'.join(diag) |
---|
| 4059 | elif type(diag) == type('A'): |
---|
| 4060 | Sdiag = diag |
---|
| 4061 | else: |
---|
| 4062 | Sdiag = 'None' |
---|
| 4063 | |
---|
| 4064 | Svc = vn + '|' + op + '|' + values[0] + '|' + Smodel + '|' + Sdiag + \ |
---|
| 4065 | '|' + values[3] |
---|
| 4066 | if ivop == 0: |
---|
| 4067 | Svarcompute = Svc |
---|
| 4068 | else: |
---|
| 4069 | Svarcompute = Svarcompute + ',' + Svc |
---|
| 4070 | ivop = ivop + 1 |
---|
| 4071 | |
---|
| 4072 | origstrfiles = gen.dictKeysVals_stringList(origfiles) |
---|
| 4073 | origstrtestfiles = gen.dictKeysVals_stringList(origtestfiles) |
---|
| 4074 | |
---|
| 4075 | # Outwritting the varcompute to avoid next time (if it is not filescratch!) |
---|
| 4076 | objf = open(odir + '/reproj_varcompute.inf', 'w') |
---|
| 4077 | objf.write('files: ' + origstrfiles + '\n') |
---|
| 4078 | objf.write('testfiles: ' + origstrtestfiles + '\n') |
---|
| 4079 | objf.write('varcompute: ' + Svarcompute + '\n') |
---|
| 4080 | objf.write('itotv: ' + str(ivop) + '\n') |
---|
| 4081 | objf.close() |
---|
| 4082 | else: |
---|
[1325] | 4083 | if dbg: |
---|
| 4084 | print warnmsg |
---|
| 4085 | print ' ' + main + ": getting variables to compute already from file !!" |
---|
[1064] | 4086 | origfiles, origtestfiles, allcompvar, Nvar = read_varcomp_file(varcompf) |
---|
| 4087 | |
---|
| 4088 | # End of avoiding to repeat all the experiment search |
---|
| 4089 | |
---|
| 4090 | print " For experiment '" + exp + "' is required to re-project:", Nvar, \ |
---|
| 4091 | "variables" |
---|
| 4092 | |
---|
| 4093 | if dbg: |
---|
| 4094 | print 'Variables to re-project _______' |
---|
| 4095 | gen.printing_dictionary(allcompvar) |
---|
| 4096 | |
---|
| 4097 | # Re-projection variables |
---|
| 4098 | print " Reprojecting variables ..." |
---|
| 4099 | os.chdir(odir) |
---|
| 4100 | |
---|
| 4101 | # Keeping track of reprojection |
---|
| 4102 | trckobjf = open(odir + '/all_reproj_computevars.inf','a') |
---|
| 4103 | |
---|
| 4104 | for vnop in allcompvar.keys(): |
---|
| 4105 | vn = vnop.split('_')[0] |
---|
| 4106 | op = vnop.split('_')[1] |
---|
| 4107 | values = allcompvar[vnop] |
---|
[1193] | 4108 | VnOpS = varnoper(vn, op, opersurnames) |
---|
[1064] | 4109 | |
---|
[1067] | 4110 | # Only are reprojected that files which do contain 'lon' and 'lat', |
---|
| 4111 | # otherways, it is only re-projected the original file |
---|
| 4112 | inNO, iopNO, iop = gen.list_coincidences(opNOreproj,op.split('+')) |
---|
| 4113 | |
---|
[1186] | 4114 | reprjop = gen.dictionary_key_list(REPRJops,vn).split('_')[1] |
---|
| 4115 | if reprjop is None: |
---|
[1064] | 4116 | print errmsg |
---|
[1186] | 4117 | print ' ' + fname + ": no reprojecting operator found for " + \ |
---|
[1064] | 4118 | " variable '" + vn + "' !!" |
---|
| 4119 | print ' available values _______' |
---|
[1186] | 4120 | gen.printing_dictionary(REPRJops) |
---|
[1064] | 4121 | quit(-1) |
---|
| 4122 | |
---|
| 4123 | # Re-projecting also the 'original' (at least with 'pinterp') file for varsdif |
---|
| 4124 | if op.find('pinterp') != -1: |
---|
[1069] | 4125 | ifileorig = vn +'_'+ values[0].replace('reproj-','') + 'p_pinterp.nc' |
---|
| 4126 | ofileorig = vn +'_'+ values[0] + 'p_pinterp.nc' |
---|
| 4127 | ofilen = vn +'_'+ values[0] + 'p_pinterp.nc' |
---|
[1312] | 4128 | ifileop = vn +'_'+ values[0].replace('reproj-','') + 'p_' + \ |
---|
| 4129 | op.replace('+','_') + '.nc' |
---|
[1064] | 4130 | else: |
---|
| 4131 | ifileorig = vn +'_'+ values[0].replace('reproj-','') + '.nc' |
---|
| 4132 | ofileorig = vn +'_'+ values[0] + '.nc' |
---|
[1312] | 4133 | ifileop = vn +'_'+ values[0].replace('reproj-','') + '_' + \ |
---|
| 4134 | op.replace('+','_') + '.nc' |
---|
[1064] | 4135 | |
---|
| 4136 | ofileop = vn + '_' + values[0] + '_' + op.replace('+','_') + '.nc' |
---|
| 4137 | |
---|
| 4138 | if fscr: |
---|
| 4139 | sout = sub.call('rm ' + odir+'/'+ofileorig + ' >& /dev/null', shell=True) |
---|
| 4140 | sout = sub.call('rm ' + odir+'/'+ofileop + ' >& /dev/null', shell=True) |
---|
| 4141 | |
---|
[1193] | 4142 | # List of files to re-project (first without operation) |
---|
[1064] | 4143 | ifiles = [odir+'/'+ifileorig, odir+'/'+ifileop] |
---|
[1193] | 4144 | # List of output files after re-projection (first without operation) |
---|
[1064] | 4145 | ofiles = [odir+'/'+ofileorig, odir+'/'+ofileop] |
---|
| 4146 | |
---|
| 4147 | for iif in range(2): |
---|
| 4148 | ifile = ifiles[iif] |
---|
| 4149 | ofile = ofiles[iif] |
---|
[1067] | 4150 | |
---|
| 4151 | # Only projecting original file-variable if there are not 'lon' and 'lat' |
---|
| 4152 | doreproj = True |
---|
| 4153 | if iif == 1 and len(inNO) > 0: |
---|
| 4154 | doreproj = False |
---|
[1325] | 4155 | if dbg: |
---|
| 4156 | print warnmsg |
---|
| 4157 | print ' ' + fname + ": operation '" + op + "' can not be " + \ |
---|
| 4158 | "reprojected due to the lack of 'lon' or 'lat' skipping it !!" |
---|
| 4159 | print " NOTE: difference can only be computed as:" |
---|
| 4160 | print " - 1st: compute variable's differences between models" |
---|
| 4161 | print " - 2nd: Perform the operations" |
---|
[1067] | 4162 | |
---|
[1085] | 4163 | # Building up resources to compute re-projected statistics |
---|
[1325] | 4164 | if dbg: |
---|
| 4165 | print ' '+fname+': computing from the original reprojected file' |
---|
[1085] | 4166 | ModI = ModelInf(mod, mod, 'lon', 'lat', 'pres', 'time', 'depth', \ |
---|
[1095] | 4167 | 'lon', 'lat', 'pres', 'time', 'depth', None) |
---|
[1226] | 4168 | if type(values) == type([1]): |
---|
| 4169 | fileh = values[0] |
---|
| 4170 | else: |
---|
| 4171 | fileh = values |
---|
| 4172 | |
---|
| 4173 | if type(values) == type([1]): |
---|
| 4174 | fileh = values[0] |
---|
| 4175 | else: |
---|
| 4176 | fileh = values |
---|
| 4177 | |
---|
[1085] | 4178 | VarI = VariableInf(vn, values[0], values[2], values[3]) |
---|
| 4179 | usefs = {values[0]: ofileorig} |
---|
| 4180 | |
---|
| 4181 | compute_statistics(ModI, config, config['ifold'], usefs, \ |
---|
| 4182 | config['ofold']+'/'+mod+'/'+exp,VarI,pinterp_var(op), op, fscr, dbg) |
---|
| 4183 | |
---|
[1067] | 4184 | if not os.path.isfile(ofile) and doreproj: |
---|
[1064] | 4185 | if debug and ofile == ofiles[0]: |
---|
| 4186 | print " reprojecting '" + vn + "' '" + op + "' into '" + \ |
---|
| 4187 | ofile + "'" |
---|
| 4188 | |
---|
[1186] | 4189 | # Reprojecting... |
---|
| 4190 | if reprjop[0:6] == 'remap': |
---|
| 4191 | ins = config['cdoHOME'] + '/cdo ' + reprjop + ',' + \ |
---|
| 4192 | config['RefProjfile'] + ' ' + ifile + ' ' + ofile |
---|
| 4193 | try: |
---|
| 4194 | with gen.Capturing() as output: |
---|
| 4195 | sout = sub.call(ins, shell=True) |
---|
| 4196 | except: |
---|
| 4197 | print errmsg |
---|
| 4198 | print ' ' + fname + ': $ ' + ins |
---|
| 4199 | for s1out in output: print s1out |
---|
| 4200 | print sout |
---|
| 4201 | quit(-1) |
---|
| 4202 | if sout != 0: |
---|
| 4203 | print errmsg |
---|
| 4204 | print ' ' + fname + ': $ ' + ins |
---|
| 4205 | sub.call(ins, shell=True) |
---|
| 4206 | quit(-1) |
---|
| 4207 | else: |
---|
[1193] | 4208 | # Name of the variable to reproject |
---|
| 4209 | if iif == 0: |
---|
| 4210 | reprjvn = vn |
---|
| 4211 | else: |
---|
| 4212 | reprjvn = VnOpS |
---|
| 4213 | |
---|
[1227] | 4214 | reprojvalues = 'lon,lat,' + config['RefProjfile'] + ',lon,lat,'+ \ |
---|
[1193] | 4215 | reprjop + ',' + ':'.join(CFvardims) |
---|
[1227] | 4216 | ins= 'ncvar.reproject('+reprojvalues + ', ' + ifile + ', '+ \ |
---|
| 4217 | reprjvn + ')' |
---|
[1186] | 4218 | try: |
---|
| 4219 | with gen.Capturing() as output: |
---|
[1227] | 4220 | sout=ncvar.reproject(reprojvalues, ifile, reprjvn) |
---|
[1186] | 4221 | except: |
---|
| 4222 | print errmsg |
---|
| 4223 | print ' ' + fname + ': ' + ins |
---|
| 4224 | for s1out in output: print s1out |
---|
| 4225 | quit(-1) |
---|
[1064] | 4226 | |
---|
[1193] | 4227 | sub.call('mv reproject.nc ' + ofile, shell=True) |
---|
| 4228 | |
---|
[1064] | 4229 | if debug: |
---|
| 4230 | for s1out in output: print s1out |
---|
| 4231 | print sout |
---|
| 4232 | |
---|
[1187] | 4233 | # Keeping track of re-projection |
---|
[1064] | 4234 | trckobjf.write('\n') |
---|
[1067] | 4235 | if iif == 0: |
---|
| 4236 | trckobjf.write('# ' + vn + '\n') |
---|
| 4237 | else: |
---|
| 4238 | trckobjf.write('# ' + vn + ' ' + op + '\n') |
---|
| 4239 | |
---|
[1064] | 4240 | trckobjf.write(ins + '\n') |
---|
| 4241 | |
---|
[1186] | 4242 | if reprjop[0:6] == 'remap': |
---|
| 4243 | # CFing the reprojected file |
---|
| 4244 | try: |
---|
| 4245 | with gen.Capturing() as output: |
---|
| 4246 | ncvar.CDO_toCF(ofile) |
---|
| 4247 | except: |
---|
| 4248 | print errmsg |
---|
| 4249 | print 'ncvar.CDO_toCF(' + ofile + ')' |
---|
| 4250 | for s1out in output: print s1out |
---|
[1270] | 4251 | # Removing file in order to make sure that it will be redone |
---|
| 4252 | print ' ' + fname + " removing file '" + ofile + "' ..." |
---|
| 4253 | sub.call('rm ' + ofile + ' >& /dev/null', shell=True) |
---|
[1186] | 4254 | quit(-1) |
---|
[1064] | 4255 | |
---|
[1186] | 4256 | if debug: |
---|
| 4257 | for s1out in output: print s1out |
---|
[1064] | 4258 | |
---|
| 4259 | trckobjf.close() |
---|
| 4260 | |
---|
[1394] | 4261 | if debug: print " End of '" + fname + "' " |
---|
| 4262 | |
---|
[1064] | 4263 | return |
---|
| 4264 | |
---|
[1082] | 4265 | def allmodexps_listconstruct(config, modexps, odir, debug): |
---|
[1081] | 4266 | """ Function to create the list of all model-experiments to draw |
---|
| 4267 | config= Configuration of the experiment |
---|
| 4268 | modexps= list with the models-experiments pairs to use |
---|
| 4269 | odir= output differences folder |
---|
| 4270 | """ |
---|
| 4271 | fname='allmodexps_listconstruct' |
---|
| 4272 | |
---|
| 4273 | allplts = gen.get_specdictionary_HMT(config, H='PLOTALLMODEXP_') |
---|
| 4274 | |
---|
| 4275 | if debug: |
---|
| 4276 | if allplts is not None: |
---|
| 4277 | print " 'all mod-exps' plots ________" |
---|
| 4278 | gen.printing_dictionary(allplts) |
---|
| 4279 | |
---|
| 4280 | # Getting Model-Reference Projection |
---|
| 4281 | ModComProj = cnf['RefProj'].split(':') |
---|
| 4282 | |
---|
[1082] | 4283 | allmodexp = {} |
---|
| 4284 | Nallmodexp = 0 |
---|
[1081] | 4285 | for modexp in modexps: |
---|
[1082] | 4286 | if debug: |
---|
| 4287 | print " " + fname + ": '" + modexp + "' ..." |
---|
[1081] | 4288 | mod = modexp.split('/')[0] |
---|
| 4289 | exp = modexp.split('/')[1] |
---|
| 4290 | |
---|
| 4291 | # Getting variable characteristics from each model/experiment |
---|
| 4292 | idir = config['ofold'] + '/' + modexp |
---|
| 4293 | |
---|
| 4294 | reproj = not gen.searchInlist(ModComProj,mod) |
---|
| 4295 | |
---|
[1082] | 4296 | fvarcomp = 'varcompute.inf' |
---|
[1081] | 4297 | if reproj: fvc = 'reproj_' + fvarcomp |
---|
| 4298 | else: fvc = fvarcomp |
---|
| 4299 | |
---|
| 4300 | files, testfiles, allcompvar, Nvar= read_varcomp_file(idir + '/' + fvc) |
---|
| 4301 | |
---|
| 4302 | if allplts is not None: |
---|
| 4303 | # Getting all model-experiments plots characteristics |
---|
| 4304 | |
---|
| 4305 | for allplt in allplts.keys(): |
---|
[1082] | 4306 | pltn = allplt.split('_')[1] |
---|
| 4307 | if debug and modexp == modexps[0]: |
---|
| 4308 | print ' ' + fname + ": plot '" + pltn + "' " |
---|
[1081] | 4309 | varops = allplts[allplt].split(':') |
---|
[1082] | 4310 | for varop in varops: |
---|
[1081] | 4311 | vn = varop.split('|')[0] |
---|
| 4312 | op = varop.split('|')[1] |
---|
[1082] | 4313 | vnop = vn + '_' + op |
---|
| 4314 | if debug and modexp == modexps[0]: |
---|
| 4315 | print ' ' + fname + ": varop '" + vnop + "' " |
---|
[1081] | 4316 | if not allcompvar.has_key(vnop): |
---|
| 4317 | print warnmsg |
---|
| 4318 | print ' ' + fname + ": variable+operation '" + vnop + \ |
---|
| 4319 | "' in '" + modexp + "' was not computed !!" |
---|
| 4320 | print ' skipping it!' |
---|
[1082] | 4321 | print ' computed values:', allcompvar.keys() |
---|
[1081] | 4322 | break |
---|
| 4323 | |
---|
| 4324 | vals = allcompvar[vnop] |
---|
| 4325 | |
---|
| 4326 | headerf = vals[0] |
---|
| 4327 | if modexp == modexps[0]: |
---|
| 4328 | allmodexp[vnop] = [modexp,headerf] |
---|
[1082] | 4329 | Nallmodexp = Nallmodexp + 1 |
---|
[1081] | 4330 | else: |
---|
| 4331 | prevals = allmodexp[vnop] |
---|
| 4332 | prevals = prevals + [modexp,headerf] |
---|
| 4333 | allmodexp[vnop] = prevals |
---|
| 4334 | |
---|
| 4335 | else: |
---|
| 4336 | Nallmodexp = 0 |
---|
| 4337 | |
---|
| 4338 | if allplts is not None: |
---|
| 4339 | Sallmodexps = gen.dictKeysVals_stringList(allmodexp) |
---|
| 4340 | else: |
---|
| 4341 | Sallmodexps = 'none' |
---|
| 4342 | |
---|
| 4343 | # Outwritting the all model-experiment plots file to avoid next time |
---|
| 4344 | objf = open(odir + '/allmodexp.inf', 'w') |
---|
| 4345 | objf.write('allmodexps: ' + Sallmodexps + '\n') |
---|
| 4346 | objf.write('Nallmodexp: ' + str(Nallmodexp) + '\n') |
---|
| 4347 | objf.close() |
---|
| 4348 | |
---|
[1394] | 4349 | if debug: print " End of '" + fname + "' " |
---|
| 4350 | |
---|
[1095] | 4351 | return allmodexp, Nallmodexp |
---|
[1081] | 4352 | |
---|
[1085] | 4353 | def allmodexps_read(filen): |
---|
[1081] | 4354 | """ Function to read the file with the information about the all model-experiment plots |
---|
| 4355 | filen= file with the information |
---|
| 4356 | """ |
---|
[1085] | 4357 | fname = 'allmodexps_read' |
---|
[1081] | 4358 | |
---|
| 4359 | if not os.path.isfile(filen): |
---|
| 4360 | print errormsg |
---|
| 4361 | print ' ' + fname + ": all model-experiment file '" + filen + \ |
---|
| 4362 | "' does not exist !!" |
---|
| 4363 | quit(-1) |
---|
| 4364 | |
---|
| 4365 | objf = open(filen, 'r') |
---|
| 4366 | for line in objf: |
---|
| 4367 | if line[0:1] != '#' and len(line) > 1: |
---|
| 4368 | values = line.replace('\n','').split(' ') |
---|
| 4369 | if values[0] == 'allmodexps:': |
---|
[1338] | 4370 | allplts = gen.stringList_dictKeysVals(values[1]) |
---|
[1081] | 4371 | elif values[0] == 'Nallmodexp:': |
---|
| 4372 | Nallmodexp = int(values[1]) |
---|
| 4373 | |
---|
| 4374 | objf.close() |
---|
| 4375 | |
---|
| 4376 | return allplts, Nallmodexp |
---|
| 4377 | |
---|
| 4378 | def draw_allmodexp_plots(config, allvarcomp, plots, modexp, odir, figscr, debug): |
---|
| 4379 | """ Function to draw all model-experiment plots |
---|
| 4380 | config= Configuration of the experiment |
---|
| 4381 | allvarcomp = dictionary with the file headers for each variable |
---|
| 4382 | plots= dictionary with the plots |
---|
| 4383 | modexps= list with the names of the model-experiment pairs |
---|
| 4384 | odir= output experiment folder |
---|
| 4385 | figscr= whether figures should be done from the scratch or not |
---|
| 4386 | |
---|
| 4387 | * Plot as |
---|
| 4388 | {[kplot]} = [varn1]|[op1]#[varn2]|[op2]#[...[varnN]|[opN]], ... |
---|
| 4389 | [kplot] ___ |
---|
| 4390 | Nlines: Multiple lines with one line by model-experiment pairs |
---|
| 4391 | [varn] |
---|
| 4392 | variable |
---|
| 4393 | [op] |
---|
| 4394 | '+' separated list of operations |
---|
| 4395 | in figures with more than 1 variable, use '#' to separate the [varn]|[op] |
---|
| 4396 | """ |
---|
| 4397 | fname = 'draw_allmodexp_plots' |
---|
| 4398 | |
---|
| 4399 | os.chdir(odir) |
---|
| 4400 | |
---|
[1085] | 4401 | # Folder with the processed files |
---|
| 4402 | infold = config['ofold'] |
---|
| 4403 | |
---|
[1081] | 4404 | # Dictionary with the operations with surnames for the operated variable |
---|
| 4405 | opersurnames = {} |
---|
| 4406 | opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') |
---|
| 4407 | for opsr in opsur.keys(): |
---|
| 4408 | opn = opsr.split('_')[1] |
---|
| 4409 | vls = opsur[opsr].split(':') |
---|
| 4410 | opersurnames[opn] = vls |
---|
| 4411 | |
---|
| 4412 | # time values |
---|
| 4413 | # Units time for the plots |
---|
| 4414 | rd = config['CFreftime'] |
---|
| 4415 | tunits = config['CFunitstime'] + '!since!' + rd[0:4] + '-' + rd[4:6] + '-' + \ |
---|
| 4416 | rd[6:8] + '!' + rd[8:10] + ':' + rd[10:12] + ':' + rd[12:14] |
---|
| 4417 | # time ticks kind |
---|
| 4418 | tkind = config['timekind'] |
---|
| 4419 | # time ticks format |
---|
| 4420 | tfmt = config['timefmt'] |
---|
| 4421 | # time axis label |
---|
| 4422 | tlab = config['timelabel'] |
---|
| 4423 | timevals = [tunits, tkind, tfmt, tlab] |
---|
| 4424 | |
---|
| 4425 | # Dictionary of plot specificities |
---|
| 4426 | specplotkeyn = 'specificvarplot' |
---|
| 4427 | plotspecifics = {} |
---|
| 4428 | if config.has_key(specplotkeyn): |
---|
| 4429 | # [minval]: minimum value |
---|
| 4430 | # [maxval]: minimum value |
---|
| 4431 | # [colorbar]: name of the colorbar (from matplotlib) to use |
---|
| 4432 | # [cntformat]: format of the contour labels |
---|
| 4433 | # [colorcnt]: color for the countor lines |
---|
| 4434 | plotspecs = config[specplotkeyn].split(':') |
---|
| 4435 | for pltspc in plotspecs: |
---|
| 4436 | pltvls = pltspc.split('|') |
---|
| 4437 | vn = pltvls[0] |
---|
| 4438 | op = pltvls[1] |
---|
| 4439 | fn = pltvls[2] |
---|
| 4440 | plotspecifics[fn + '_' + vn + '_' + op] = pltvls[3:] |
---|
| 4441 | if debug: |
---|
| 4442 | print 'Specific values for plots _______' |
---|
| 4443 | gen.printing_dictionary(plotspecifics) |
---|
| 4444 | |
---|
[1095] | 4445 | # Graphical labels and configuration |
---|
| 4446 | modgc, expgc = graphical_characteristics(config, debug) |
---|
| 4447 | |
---|
[1081] | 4448 | # Kind of figures |
---|
| 4449 | kindfigure = config['kindfig'] |
---|
| 4450 | |
---|
| 4451 | # Map value |
---|
| 4452 | mapvalue = config['mapval'] |
---|
| 4453 | |
---|
| 4454 | # pythone scripts HOME |
---|
| 4455 | pyHOME = config['pyHOME'] |
---|
| 4456 | |
---|
| 4457 | # Title-text of operations |
---|
| 4458 | opexplained = {} |
---|
| 4459 | optits = config['titleoperations'].split(':') |
---|
| 4460 | for optit in optits: |
---|
| 4461 | opn = optit.split('|')[0] |
---|
| 4462 | opt = optit.split('|')[1] |
---|
| 4463 | opexplained[opn] = opt |
---|
| 4464 | if debug: |
---|
| 4465 | print 'Titles for operations _______' |
---|
| 4466 | gen.printing_dictionary(opexplained) |
---|
| 4467 | |
---|
| 4468 | for kplot in plots.keys(): |
---|
| 4469 | varsplt = plots[kplot] |
---|
| 4470 | for varplt in varsplt: |
---|
| 4471 | if debug: |
---|
[1317] | 4472 | print " printing '" + kplot + "' var: '" + varplt + "'..." |
---|
[1081] | 4473 | varops = varplt.split('#') |
---|
| 4474 | |
---|
| 4475 | # CF variables in plot |
---|
| 4476 | CFvarsplot = [] |
---|
| 4477 | # Files in plot |
---|
| 4478 | filesplot = [] |
---|
| 4479 | # Variables in plot within the files |
---|
| 4480 | varsplot = [] |
---|
| 4481 | # Dims in figure |
---|
| 4482 | dimsplot = [] |
---|
| 4483 | # pictoric values in figure |
---|
| 4484 | pictplot = [] |
---|
| 4485 | # Name of the figure |
---|
| 4486 | figname = '' |
---|
| 4487 | # Title of the figure |
---|
| 4488 | titfigure = '' |
---|
| 4489 | |
---|
| 4490 | ivp = 0 |
---|
| 4491 | for varop in varops: |
---|
| 4492 | vn = varop.split('|')[0] |
---|
| 4493 | op = varop.split('|')[1] |
---|
| 4494 | |
---|
| 4495 | # CF variables in plot |
---|
| 4496 | CFvarsplot.append(vn) |
---|
| 4497 | |
---|
[1085] | 4498 | if op.find('pinterp') != -1: gP = 'p' |
---|
| 4499 | else: gP = '' |
---|
| 4500 | |
---|
| 4501 | vnopS = vn + '_' + op |
---|
[1081] | 4502 | if not allvarcomp.has_key(vnopS): |
---|
| 4503 | print errmsg |
---|
[1085] | 4504 | print ' ' + fname + ": no file for variable-operation '" + \ |
---|
[1081] | 4505 | vnopS + "' !!" |
---|
[1341] | 4506 | modexpvals = allvarcomp[vnopS] |
---|
[1085] | 4507 | Nmodexps = len(modexpvals) |
---|
[1081] | 4508 | |
---|
[1085] | 4509 | for imodexp in range(0,Nmodexps,2): |
---|
| 4510 | modexp = modexpvals[imodexp] |
---|
| 4511 | headf = modexpvals[imodexp+1] |
---|
| 4512 | if debug: |
---|
| 4513 | print ' ' + fname + " model/experiment: '" + modexp + "'" |
---|
[1081] | 4514 | |
---|
[1085] | 4515 | filen = infold + '/' + modexp + '/' + vn +'_'+ headf+gP + '_' + \ |
---|
| 4516 | op.replace('+','_') + '.nc' |
---|
[1081] | 4517 | |
---|
[1085] | 4518 | filesplot.append(filen) |
---|
| 4519 | # Do we have processed the given variable? |
---|
| 4520 | if not os.path.isfile(filen): |
---|
| 4521 | print warnmsg |
---|
| 4522 | print " " + fname + ": there is no file for variable '" + \ |
---|
| 4523 | varop + "' skiping it !!" |
---|
| 4524 | break |
---|
[1081] | 4525 | |
---|
[1085] | 4526 | if imodexp == 0: |
---|
| 4527 | # Name of the variable inside the file |
---|
| 4528 | vnsur = varnoper(vn, op, opersurnames) |
---|
| 4529 | varsplot.append(vnsur) |
---|
[1081] | 4530 | |
---|
[1085] | 4531 | # Dimensions in file |
---|
| 4532 | try: |
---|
| 4533 | with gen.Capturing() as output: |
---|
| 4534 | dims = ncvar.idims(filen) |
---|
| 4535 | except: |
---|
| 4536 | print errmsg |
---|
| 4537 | print 'ncvar.idims('+filen+')' |
---|
| 4538 | for s1out in output: print s1out |
---|
| 4539 | quit(-1) |
---|
[1081] | 4540 | |
---|
[1085] | 4541 | if imodexp == 0: |
---|
| 4542 | # Dimensions in plot |
---|
| 4543 | dimsplot.append(dims) |
---|
[1081] | 4544 | |
---|
[1085] | 4545 | # Header of the name of the figure |
---|
| 4546 | if ivp == 0: |
---|
| 4547 | figname = kplot+'_'+vn+'_'+headf+'_'+ op.replace('+','-') |
---|
| 4548 | else: |
---|
| 4549 | figname = figname+'-'+vn+'_'+headf+'_'+op.replace('+','-') |
---|
[1081] | 4550 | |
---|
[1085] | 4551 | # pictoric values for the figure |
---|
| 4552 | Sfivaop = kplot + '_' + vn + '_' + op |
---|
| 4553 | if plotspecifics.has_key(Sfivaop): |
---|
| 4554 | pictvals = plotspecifics[Sfivaop] |
---|
| 4555 | else: |
---|
| 4556 | Vvals = gen.variables_values(vn) |
---|
| 4557 | pictvals = [Vvals[2],Vvals[3],Vvals[6], '%g', 'fixc', 'black'] |
---|
| 4558 | |
---|
| 4559 | pictplot.append(pictvals) |
---|
| 4560 | |
---|
[1081] | 4561 | ivp = ivp + 1 |
---|
| 4562 | # End of variable-operation |
---|
| 4563 | figname = figname + '.' + kindfigure |
---|
| 4564 | |
---|
| 4565 | # Title of figure |
---|
[1111] | 4566 | titfigure = 'all!model-experiments!' + vn + optitle(op,opexplained) |
---|
[1081] | 4567 | |
---|
| 4568 | draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ |
---|
[1095] | 4569 | figname, titfigure, kindfigure, mapvalue, timevals, expgc, odir, \ |
---|
| 4570 | pyHOME, figscr, debug) |
---|
[1081] | 4571 | |
---|
| 4572 | # End of variables-operations |
---|
| 4573 | |
---|
| 4574 | # End of kind of plots |
---|
| 4575 | |
---|
[1394] | 4576 | if debug: print " End of '" + fname + "' " |
---|
| 4577 | |
---|
[1081] | 4578 | return |
---|
| 4579 | |
---|
[1329] | 4580 | def figinf_figname(figname,config): |
---|
| 4581 | """ Function to retrieve figure information from its name |
---|
| 4582 | figname= name of the figure |
---|
| 4583 | config= configuration of `model_graphics.py' |
---|
| 4584 | >>> figinf_figname('2linesTime_wss_wrfout_xvar-ymean-tas_wrfout_xvar-ymean.pdf', cnf) |
---|
| 4585 | (2, '2linesTime', 'wss-tas', 'xvar-ymean@xvar-ymean') |
---|
| 4586 | >>> figinf_figname('Nlines_tas_wrfout_tturb-xmean-tmean.pdf', cnf) |
---|
| 4587 | (1, 'Nlines', 'tas', 'tturb-xmean-tmean') |
---|
| 4588 | >>> figinf_figname('2lines_wss_diffvar_WRF-micro1_WRF-current_tturb-xmean-last-tas_tturb-xmean-last.pdf',cnf) |
---|
| 4589 | (2, '2lines', 'wss-tas', 'tturb-xmean-last@tturb-xmean-last') |
---|
| 4590 | """ |
---|
| 4591 | fname = 'figinf_figname' |
---|
| 4592 | plotsecs = figname.split('_') |
---|
| 4593 | plotk = plotsecs[0] |
---|
| 4594 | |
---|
| 4595 | if gen.searchInlist(config['pairfigures'].split(':'), plotk): |
---|
| 4596 | Nvars = 2 |
---|
| 4597 | varn1 = plotsecs[1] |
---|
| 4598 | if plotsecs[2] == 'diffvar' or plotsecs[2] == 'diffop': |
---|
| 4599 | statn1varn2 = plotsecs[5].split('-') |
---|
| 4600 | statn2 = plotsecs[6].split('.')[0] |
---|
| 4601 | Lstatn1varn2 = len(statn1varn2) |
---|
| 4602 | statn1 = '-'.join(statn1varn2[0:Lstatn1varn2-1]) |
---|
| 4603 | varn2 = statn1varn2[Lstatn1varn2-1] |
---|
| 4604 | else: |
---|
| 4605 | statn1varn2 = plotsecs[3].split('-') |
---|
| 4606 | statn2 = plotsecs[5].split('.')[0] |
---|
| 4607 | Lstatn1varn2 = len(statn1varn2) |
---|
| 4608 | statn1 = '-'.join(statn1varn2[0:Lstatn1varn2-1]) |
---|
| 4609 | varn2 = statn1varn2[Lstatn1varn2-1] |
---|
| 4610 | return Nvars, plotk, varn1+'-'+varn2, statn1+'@'+statn2 |
---|
| 4611 | elif gen.searchInlist(config['Nsourcesfigures'].split(':'), plotk): |
---|
| 4612 | Nvars = 1 |
---|
| 4613 | varn = plotsecs[1] |
---|
| 4614 | statn = plotsecs[3].split('.')[0] |
---|
| 4615 | return Nvars, plotk, varn, statn |
---|
| 4616 | else: |
---|
| 4617 | print errmsg |
---|
| 4618 | print ' ' + fname + ": kind of figure '" + plotk + "' not ready !!" |
---|
| 4619 | print ' ready ones _______' |
---|
| 4620 | print " 'pair_figures': figures of pair of variables: ", \ |
---|
| 4621 | config['pairfigures'].split(':') |
---|
| 4622 | print " 'N-sources_figures': figures of pair of variables: ", \ |
---|
| 4623 | config['Nsourcesfigures'].split(':') |
---|
| 4624 | quit(-1) |
---|
| 4625 | |
---|
[994] | 4626 | # Files with information about the configuration of the script |
---|
| 4627 | inffiles = ['varcompute.inf', 'all_computevars.inf', 'all_statsvars.inf'] |
---|
| 4628 | |
---|
| 4629 | ####### ####### |
---|
| 4630 | ## MAIN |
---|
| 4631 | ####### |
---|
[1160] | 4632 | if not os.path.isfile('model_graphics.dat'): |
---|
| 4633 | print errmsg |
---|
| 4634 | print main + ": configuration file 'model_graphics.dat' does not exist!!" |
---|
| 4635 | quit(-1) |
---|
[994] | 4636 | |
---|
| 4637 | # Getting configuration from external ASCII file 'model_graphics.dat' |
---|
| 4638 | cnf = gen.get_configuration('model_graphics.dat', False) |
---|
| 4639 | |
---|
[1039] | 4640 | verify_configuration(cnf, gen.Str_Bool(cnf['debug'])) |
---|
| 4641 | |
---|
[994] | 4642 | # scratches |
---|
[1064] | 4643 | scratch, filescratch, figscratch, diffscratch, figdiffscratch, moddiffscratch, \ |
---|
[1081] | 4644 | figmoddiffscratch, figallmodexpscratch, addfiles, addfigures, adddiffs, \ |
---|
[1082] | 4645 | adddifffigures, addmoddiffs, addmoddifffigures, addallmodexpfigures, dbg = \ |
---|
[1081] | 4646 | scratches(cnf) |
---|
[994] | 4647 | |
---|
[1067] | 4648 | if dbg: |
---|
| 4649 | print 'Experiment configuration scratches _______' |
---|
| 4650 | print ' scratch:', scratch, 'filescratch:', filescratch,'figscratch:', figscratch |
---|
| 4651 | print ' diffscratch:', diffscratch, 'figdiffscratch:', figdiffscratch |
---|
| 4652 | print ' moddiffscratch:', moddiffscratch, 'figmoddiffscratch:', figmoddiffscratch |
---|
| 4653 | print 'Experiment configuration adding _______' |
---|
| 4654 | print ' addfiles:', addfiles, 'addfigures:', addfigures |
---|
| 4655 | print ' adddiffs:', adddiffs, 'adddifffigures:', adddifffigures |
---|
| 4656 | print ' addmoddiffs:', addmoddiffs, 'addmoddifffigures:', addmoddifffigures |
---|
| 4657 | |
---|
[994] | 4658 | # Getting models |
---|
| 4659 | mods = cnf['models'].split(':') |
---|
| 4660 | |
---|
[1095] | 4661 | # Getting graphical characeristics |
---|
| 4662 | modGC, expGC = graphical_characteristics(cnf, dbg) |
---|
| 4663 | |
---|
[994] | 4664 | # Models loop |
---|
| 4665 | ## |
---|
[1060] | 4666 | |
---|
| 4667 | # dictionary with the experiments of each model |
---|
| 4668 | modexps = {} |
---|
| 4669 | |
---|
[994] | 4670 | for mod in mods: |
---|
| 4671 | print mod |
---|
[1025] | 4672 | if scratch: |
---|
[1031] | 4673 | if cnf['ofold'] != cnf['ifold']: |
---|
| 4674 | sout = sub.call('rm -rf '+cnf['ofold']+'/'+mod+' > /dev/null', shell=True) |
---|
| 4675 | else: |
---|
| 4676 | print warnmsg |
---|
| 4677 | print ' ' + main + ": input '" + cnf['ifold'] + "' and output '" + \ |
---|
| 4678 | cnf['ofold'] + "' are the same folder !!" |
---|
| 4679 | print " Keeping output folder although it has 'scratch' start" |
---|
[1025] | 4680 | |
---|
[994] | 4681 | # Get experiments and headers of model |
---|
| 4682 | exps, fheaders = exp_headers(mod,cnf) |
---|
| 4683 | |
---|
[1060] | 4684 | modexps[mod] = exps |
---|
[994] | 4685 | # Characteristics of the model |
---|
[1011] | 4686 | Modinf = ncvar.model_characteristics(mod,'None','False') |
---|
| 4687 | dnx = Modinf.dimxn |
---|
| 4688 | dny = Modinf.dimyn |
---|
| 4689 | dnz = Modinf.dimzn |
---|
| 4690 | dnt = Modinf.dimtn |
---|
[1095] | 4691 | dns = Modinf.dimsn |
---|
[1011] | 4692 | vdnx = Modinf.vardxn |
---|
| 4693 | vdny = Modinf.vardyn |
---|
| 4694 | vdnz = Modinf.vardzn |
---|
| 4695 | vdnt = Modinf.vardtn |
---|
[1095] | 4696 | vdns = Modinf.vardsn |
---|
[994] | 4697 | |
---|
[1095] | 4698 | modgraphv = modGC[mod] |
---|
| 4699 | Modinf = ModelInf(mod, mod, dnx, dny, dnz, dnt, dns, vdnx, vdny, vdnz, vdnt, \ |
---|
| 4700 | vdns, modgraphv.tmod) |
---|
| 4701 | |
---|
[994] | 4702 | if dbg: |
---|
| 4703 | print ' model characteristics _______' |
---|
[1095] | 4704 | gen.printing_class(Modinf) |
---|
[994] | 4705 | |
---|
| 4706 | moddims = dnx + ',' + dny + ',' + dnz + ',' + dnt |
---|
| 4707 | modvdims = vdnx + ',' + vdny + ',' + vdnz + ',' + vdnt |
---|
| 4708 | |
---|
[1001] | 4709 | # Experiments loop |
---|
| 4710 | ## |
---|
[994] | 4711 | for exp in exps: |
---|
| 4712 | print ' ' + exp + '...' |
---|
| 4713 | |
---|
| 4714 | # input folder |
---|
| 4715 | iwdir = cnf['ifold'] + '/' + mod + '/' + exp |
---|
| 4716 | |
---|
| 4717 | # Does input folder exist? |
---|
| 4718 | if not os.path.isdir(iwdir): |
---|
[1085] | 4719 | if filescratch*addfiles: |
---|
| 4720 | print errmsg |
---|
| 4721 | print " " + main + ": folder '" + iwdir + "' does not exist !!" |
---|
| 4722 | quit(-1) |
---|
| 4723 | else: |
---|
| 4724 | print warnmsg |
---|
| 4725 | print " " + main + ": folder '" + iwdir + "' does not exist !!" |
---|
| 4726 | print " but start of files from scratch 'filescratch':", \ |
---|
| 4727 | filescratch, "and there is not the add of any file 'addfiles':", \ |
---|
| 4728 | addfiles |
---|
| 4729 | print ' so, keep moving' |
---|
[994] | 4730 | |
---|
| 4731 | owdir = cnf['ofold'] + '/' + mod + '/' + exp |
---|
| 4732 | sout = sub.call('mkdir -p ' + owdir, shell=True) |
---|
| 4733 | |
---|
| 4734 | # Need to pass to analyze all the data? |
---|
| 4735 | if filescratch: |
---|
| 4736 | for inff in inffiles: |
---|
| 4737 | if dbg: print " removing information file '" + inff + "' ..." |
---|
| 4738 | ins = 'rm ' + owdir + '/' + inff + ' >& /dev/null' |
---|
| 4739 | sout = sub.call(ins, shell=True) |
---|
| 4740 | |
---|
| 4741 | objf = open(owdir+'/all_computevars.inf','w') |
---|
| 4742 | objf.write("## Computation of variables \n") |
---|
| 4743 | objf.close() |
---|
| 4744 | objf = open(owdir+'/all_statsvars.inf','w') |
---|
| 4745 | objf.write("## Computation of statistics \n") |
---|
| 4746 | objf.close() |
---|
| 4747 | |
---|
[1025] | 4748 | varcompf = owdir + '/varcompute.inf' |
---|
[994] | 4749 | if addfiles: |
---|
[1111] | 4750 | if dbg: |
---|
[1238] | 4751 | print ' ' + main + ": adding variables to compute removing " + \ |
---|
[1111] | 4752 | "file '" + varcompf + "' ..." |
---|
[1025] | 4753 | sub.call('rm ' + varcompf +' >& /dev/null', shell=True) |
---|
[994] | 4754 | |
---|
| 4755 | if not os.path.isfile(varcompf): |
---|
| 4756 | # Does input folder has header files? |
---|
| 4757 | ih=1 |
---|
| 4758 | # Dictionary with the list of files for each headers |
---|
| 4759 | files = {} |
---|
| 4760 | # Dictionary with a file fromor each headers |
---|
| 4761 | testfiles = {} |
---|
| 4762 | |
---|
| 4763 | for fh in fheaders: |
---|
| 4764 | if filescratch: |
---|
| 4765 | ins = 'rm '+ owdir+'/*_' + fh + '*.nc >& /dev/null' |
---|
| 4766 | sout = sub.call(ins, shell=True) |
---|
[1025] | 4767 | files1h = gen.files_folder(iwdir,fh) |
---|
| 4768 | if len(files1h) < 1: |
---|
| 4769 | print errmsg |
---|
| 4770 | print ' ' + main + ": folder '" + iwdir + "' does not " + \ |
---|
| 4771 | "contain files '" + fh + "*' !!" |
---|
| 4772 | quit(-1) |
---|
| 4773 | files[fh] = files1h |
---|
| 4774 | testfiles[fh] = files1h[0] |
---|
[994] | 4775 | |
---|
| 4776 | if dbg: |
---|
| 4777 | print ' Dictionary of files _______' |
---|
| 4778 | gen.printing_dictionary(files) |
---|
| 4779 | |
---|
| 4780 | print ' Dictionary of test-files _______' |
---|
| 4781 | gen.printing_dictionary(testfiles) |
---|
| 4782 | |
---|
[1011] | 4783 | allcompvar, Nvar = compvars_listconstruct(cnf, Modinf, files, testfiles, \ |
---|
[1001] | 4784 | iwdir, owdir, dbg) |
---|
[1325] | 4785 | else: |
---|
| 4786 | if dbg: |
---|
| 4787 | print warnmsg |
---|
| 4788 | print ' '+main+": getting variables to compute already from file !!" |
---|
[1025] | 4789 | files, testfiles, allcompvar, Nvar = read_varcomp_file(varcompf) |
---|
[1022] | 4790 | |
---|
[1011] | 4791 | # End of avoiding to repeat all the experiment search |
---|
[994] | 4792 | |
---|
[1048] | 4793 | print " For experiment '" + exp + "' is required to compute:", Nvar, \ |
---|
| 4794 | "variables" |
---|
[1001] | 4795 | |
---|
[1022] | 4796 | if dbg: |
---|
[1025] | 4797 | print 'Variables to compute _______' |
---|
[1022] | 4798 | gen.printing_dictionary(allcompvar) |
---|
| 4799 | |
---|
[1064] | 4800 | # Computing variables |
---|
[1001] | 4801 | print " Computing variables ..." |
---|
[1011] | 4802 | compute_vars(cnf, Modinf, iwdir, owdir, files, allcompvar, filescratch, dbg) |
---|
[1001] | 4803 | |
---|
[1064] | 4804 | # Figures of variables direct from files |
---|
[1048] | 4805 | print " Plotting direct figures ..." |
---|
[1025] | 4806 | dirfigf = owdir + '/directplotsdraw.inf' |
---|
| 4807 | if figscratch: |
---|
| 4808 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
| 4809 | |
---|
| 4810 | objf = open(owdir+'/all_figures.inf','w') |
---|
| 4811 | objf.write("## Drawing of all figures \n") |
---|
| 4812 | objf.close() |
---|
| 4813 | |
---|
| 4814 | if addfigures: |
---|
[1111] | 4815 | if dbg: |
---|
| 4816 | print ' ' + main + ": adding direct figures removing file '" + \ |
---|
| 4817 | dirfigf + "' ..." |
---|
[1025] | 4818 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
| 4819 | |
---|
| 4820 | if not os.path.isfile(dirfigf): |
---|
[1039] | 4821 | listplots, Nplt = plots_listconstruct(cnf, 'DIRPLT', dirfigf, owdir, dbg) |
---|
[1025] | 4822 | else: |
---|
[1325] | 4823 | if dbg: |
---|
| 4824 | print warnmsg |
---|
| 4825 | print ' ' + main + ": getting plots to draw already from file !!" |
---|
[1025] | 4826 | listplots, Nplt = read_plot_file(dirfigf) |
---|
| 4827 | |
---|
| 4828 | # End of avoiding to repeat all the plots search |
---|
| 4829 | |
---|
[1048] | 4830 | print " For experiment '" + exp + "' is required to plot:", Nplt, "plots" |
---|
[1025] | 4831 | |
---|
| 4832 | if dbg: |
---|
| 4833 | print 'Plots to draw _______' |
---|
| 4834 | gen.printing_dictionary(listplots) |
---|
| 4835 | |
---|
| 4836 | draw_plots(cnf, listplots, mod, exp, owdir, allcompvar, figscratch, dbg) |
---|
| 4837 | |
---|
| 4838 | # end of experiments loop |
---|
[1001] | 4839 | |
---|
[1031] | 4840 | ### ## # |
---|
| 4841 | # Experiment differences |
---|
| 4842 | ## # ## # |
---|
| 4843 | |
---|
| 4844 | # Experiments loop |
---|
| 4845 | ## |
---|
[1048] | 4846 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 4847 | print " ** '" + mod + "': Inter experiments differences " |
---|
| 4848 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 4849 | print ' experiments:', exps |
---|
[1032] | 4850 | # There are two kind of differences: |
---|
| 4851 | # DIFFop: differences between operations of each given variable. |
---|
| 4852 | # Differences are computed directly from the last stage of the operation |
---|
| 4853 | # DIFFvar: operations of differences between variables |
---|
| 4854 | # First are computed the differences from the initial variable file |
---|
| 4855 | # and then operations are made |
---|
| 4856 | # NOTE: remember that: meanvar2 - meanvar1 = mean(var2 - var1) |
---|
| 4857 | difffiles = ['diffop.inf', 'diffvar.inf'] |
---|
| 4858 | |
---|
[1031] | 4859 | Nexps = len(exps) |
---|
[1048] | 4860 | for iexp1 in range(0,Nexps-1): |
---|
| 4861 | exp1 = exps[iexp1] |
---|
| 4862 | for iexp2 in range(iexp1+1,Nexps): |
---|
| 4863 | exp2 = exps[iexp2] |
---|
[1039] | 4864 | Sexps = exp2 + '-' + exp1 |
---|
| 4865 | print ' ' + Sexps + '...' |
---|
[1031] | 4866 | owdir = cnf['ofold'] + '/' + mod + '/' + exp2 + '-' + exp1 |
---|
| 4867 | sout = sub.call('mkdir -p ' + owdir, shell=True) |
---|
| 4868 | |
---|
[1032] | 4869 | # Removing files with list of differences if should be started from scratch or add differences |
---|
| 4870 | for fdiff in difffiles: |
---|
| 4871 | difff = owdir + '/' + fdiff |
---|
| 4872 | if diffscratch: |
---|
| 4873 | sub.call('rm -rf' + owdir +' >& /dev/null', shell=True) |
---|
[1036] | 4874 | sub.call('rm ' + difff +' >& /dev/null', shell=True) |
---|
[1032] | 4875 | objf = open(owdir+'/all_' + fdiff,'w') |
---|
| 4876 | objf.write("## Computation and drawing of differences " + \ |
---|
| 4877 | "between '" + exp2 + "'-'" + exp1 + "'\n") |
---|
| 4878 | objf.close() |
---|
[1036] | 4879 | difff = owdir + '/all_vardiffstatistics.inf' |
---|
[1039] | 4880 | sub.call('rm ' + difff +' >& /dev/null', shell=True) |
---|
[1036] | 4881 | objf = open(owdir+'/all_' + fdiff,'w') |
---|
| 4882 | objf.write("## Computation of all differences statistics " + \ |
---|
| 4883 | "between '" + exp2 + "'-'" + exp1 + "'\n") |
---|
| 4884 | objf.close() |
---|
[1031] | 4885 | |
---|
[1032] | 4886 | if adddiffs: |
---|
[1111] | 4887 | if dbg: |
---|
| 4888 | print ' ' + main + ": adding differences removing file '" + \ |
---|
| 4889 | difff + "' ..." |
---|
[1032] | 4890 | sub.call('rm ' + difff +' >& /dev/null', shell=True) |
---|
[1031] | 4891 | |
---|
[1032] | 4892 | # op and var differences |
---|
| 4893 | diffvarcompf = owdir + '/' + difffiles[0] |
---|
[1031] | 4894 | if not os.path.isfile(diffvarcompf): |
---|
[1032] | 4895 | alldiffop, alldiffvar,Nopdiffs,Nvardiffs=diffvarop_listconstruct(cnf,\ |
---|
[1064] | 4896 | [mod, mod], [exp1, exp2], [False, False], owdir, dbg) |
---|
[1325] | 4897 | else: |
---|
| 4898 | if dbg: |
---|
| 4899 | print warnmsg |
---|
[1327] | 4900 | print ' ' + main + ": getting 'op' and 'var' differences to " + \ |
---|
[1325] | 4901 | "compute already from file !!" |
---|
[1032] | 4902 | alldiffop, Nopdiffops = read_diff_file(diffvarcompf) |
---|
| 4903 | alldiffvar, Nopdiffvars = read_diff_file(owdir+'/'+difffiles[1]) |
---|
[1327] | 4904 | print 'Nopdiffops:', Nopdiffops,'Nopdiffvars:', Nopdiffvars |
---|
[1031] | 4905 | |
---|
[1327] | 4906 | # End of avoiding to repeat all the experiment search |
---|
| 4907 | print " For experiments '"+exp2+"'-'"+exp1+"' is required to " + \ |
---|
| 4908 | "compute:", Nvar, "differences" |
---|
[1031] | 4909 | |
---|
[1327] | 4910 | if dbg: |
---|
| 4911 | print 'Differences to compute _______' |
---|
| 4912 | gen.printing_dictionary(alldiffop) |
---|
| 4913 | gen.printing_dictionary(alldiffvar) |
---|
[1031] | 4914 | |
---|
[1327] | 4915 | # Computing differences |
---|
| 4916 | ## |
---|
| 4917 | print " Computing operation differences ..." |
---|
| 4918 | compute_op_diffs(cnf, alldiffop, owdir, diffscratch, dbg) |
---|
| 4919 | print " Computing variable differences ..." |
---|
| 4920 | compute_var_diffs(cnf, alldiffvar, owdir, diffscratch, dbg) |
---|
[1031] | 4921 | |
---|
[1327] | 4922 | # Plotting operation differences |
---|
| 4923 | ## |
---|
| 4924 | print " " + main + ": Plotting operation differences' figures ..." |
---|
| 4925 | dirfigf = owdir + '/diffopplotsdraw.inf' |
---|
| 4926 | if figscratch: |
---|
| 4927 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
[1036] | 4928 | |
---|
[1327] | 4929 | objf = open(owdir+'/all_diffopfigures.inf','w') |
---|
| 4930 | objf.write("## Drawing of all operation difference figures \n") |
---|
| 4931 | objf.close() |
---|
[1039] | 4932 | |
---|
[1327] | 4933 | if adddifffigures: |
---|
| 4934 | if dbg: |
---|
| 4935 | print ' ' + main + ": adding differences' figures removing " + \ |
---|
| 4936 | "file '" + dirfigf + "' ..." |
---|
[1039] | 4937 | |
---|
[1327] | 4938 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
[1111] | 4939 | |
---|
[1327] | 4940 | if not os.path.isfile(dirfigf): |
---|
| 4941 | listplots, Nplt = plots_listconstruct(cnf, 'PLOTDIFFOP', dirfigf, \ |
---|
| 4942 | owdir, dbg) |
---|
| 4943 | else: |
---|
| 4944 | if dbg: |
---|
| 4945 | print warnmsg |
---|
| 4946 | print ' ' + main + ": getting plots to draw already from file !!" |
---|
| 4947 | listplots, Nplt = read_plot_file(dirfigf) |
---|
[1039] | 4948 | |
---|
[1327] | 4949 | # End of avoiding to repeat all the plots search |
---|
| 4950 | |
---|
| 4951 | print " For experiment 'operation' differences '" + Sexps + "' is " + \ |
---|
| 4952 | "required to plot:" , Nplt, "plots" |
---|
| 4953 | |
---|
[1325] | 4954 | if dbg: |
---|
[1327] | 4955 | print ' Plots to draw _______' |
---|
| 4956 | gen.printing_dictionary(listplots) |
---|
[1039] | 4957 | |
---|
[1327] | 4958 | draw_diff_plots(cnf, listplots, owdir, alldiffop, 'diffop', \ |
---|
| 4959 | figdiffscratch, dbg) |
---|
[1039] | 4960 | |
---|
[1327] | 4961 | # Plotting variable differences |
---|
| 4962 | ## |
---|
| 4963 | print " " + main + ": Plotting variable differences' figures ..." |
---|
| 4964 | dirfigf = owdir + '/diffvarplotsdraw.inf' |
---|
| 4965 | if figscratch: |
---|
| 4966 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
[1039] | 4967 | |
---|
[1327] | 4968 | objf = open(owdir+'/all_diffvarfigures.inf','w') |
---|
| 4969 | objf.write("## Drawing of all variables difference figures \n") |
---|
| 4970 | objf.close() |
---|
[1039] | 4971 | |
---|
[1327] | 4972 | if adddifffigures: |
---|
| 4973 | if dbg: |
---|
| 4974 | print ' '+main+": adding differences' figures removing file '" +\ |
---|
| 4975 | dirfigf + "' ..." |
---|
| 4976 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
[1067] | 4977 | |
---|
[1327] | 4978 | if not os.path.isfile(dirfigf): |
---|
| 4979 | listplots, Nplt = plots_listconstruct(cnf, 'PLOTDIFFVAR', dirfigf, \ |
---|
| 4980 | owdir, dbg) |
---|
| 4981 | else: |
---|
| 4982 | if dbg: |
---|
| 4983 | print warnmsg |
---|
| 4984 | print ' ' + main + ": getting plots to draw already from file !!" |
---|
| 4985 | listplots, Nplt = read_plot_file(dirfigf) |
---|
[1067] | 4986 | |
---|
[1327] | 4987 | # End of avoiding to repeat all the plots search |
---|
[1067] | 4988 | |
---|
[1327] | 4989 | print " For experiment 'variables' differences '" + Sexps + "' is " + \ |
---|
| 4990 | "required to plot:" , Nplt, "plots" |
---|
| 4991 | |
---|
[1111] | 4992 | if dbg: |
---|
[1327] | 4993 | print ' Plots to draw _______' |
---|
| 4994 | gen.printing_dictionary(listplots) |
---|
[1067] | 4995 | |
---|
[1327] | 4996 | draw_diff_plots(cnf, listplots, owdir, alldiffvar, 'diffvar', \ |
---|
| 4997 | figdiffscratch, dbg) |
---|
[1067] | 4998 | |
---|
[994] | 4999 | # end of mods loop |
---|
| 5000 | |
---|
[1060] | 5001 | ### ## # |
---|
| 5002 | # Model differences |
---|
[1081] | 5003 | ### ## # |
---|
[1060] | 5004 | |
---|
[1064] | 5005 | # Models already at the reference projection |
---|
| 5006 | ModComProj = cnf['RefProj'].split(':') |
---|
| 5007 | if dbg: |
---|
| 5008 | print 'Models to use as reference for the projection:', ModComProj |
---|
| 5009 | |
---|
[1186] | 5010 | # Operators to use for the reprojection of each variable |
---|
| 5011 | REPRJvar0 = gen.get_specdictionary_HMT(cnf, H='reprojectvar_') |
---|
| 5012 | REPRJvar = {} |
---|
| 5013 | for Skey in REPRJvar0.keys(): |
---|
| 5014 | REPRJvar[Skey] = gen.str_list(REPRJvar0[Skey],':') |
---|
[1064] | 5015 | |
---|
| 5016 | if dbg: |
---|
| 5017 | print 'Remaping operators to use _______' |
---|
[1186] | 5018 | gen.printing_dictionary(REPRJvar) |
---|
[1064] | 5019 | |
---|
[1186] | 5020 | # Getting common base weights for grid point remapping with CDO |
---|
[1064] | 5021 | frefgridn = 'RefProj.nc' |
---|
| 5022 | for mod in mods: |
---|
| 5023 | frefgriddes = cnf['ofold'] + '/' + mod + '/' + frefgridn |
---|
| 5024 | if moddiffscratch: |
---|
| 5025 | sout = sub.call('rm ' + frefgriddes + ' >& /dev/null', shell=True) |
---|
| 5026 | if gen.searchInlist(ModComProj,mod) and not os.path.isfile(frefgriddes): |
---|
| 5027 | # Looking for a file to use (all files are CF compilant, but we need to |
---|
| 5028 | # be sure that at least they have 'lon', 'lat' variables) |
---|
| 5029 | exps = modexps[mod] |
---|
| 5030 | exp = exps[0] |
---|
[1186] | 5031 | reprjfdir = cnf['ofold'] + '/' + mod + '/' + exp |
---|
| 5032 | reprjfile = None |
---|
| 5033 | for reprjop in REPRJvar.keys(): |
---|
[1314] | 5034 | reprjvars = REPRJvar[reprjop] |
---|
[1186] | 5035 | for reprjvar in reprjvars: |
---|
| 5036 | reprjfs= gen.files_folder_HMT(folder=reprjfdir,head=reprjvar+'_',tail='.nc') |
---|
| 5037 | for reprjf in reprjfs: |
---|
[1064] | 5038 | # Getting direct files as [var]_[fhead].nc |
---|
[1186] | 5039 | if len(reprjf.split('_')) == 2: |
---|
| 5040 | reprjfile = reprjfdir + '/' + reprjf |
---|
| 5041 | reprjvn = reprjvar |
---|
[1064] | 5042 | break |
---|
[1186] | 5043 | if reprjfile is None: |
---|
[1064] | 5044 | print errmsg |
---|
| 5045 | print ' ' + main + ": no proper file to get projection information " + \ |
---|
[1186] | 5046 | "from '" + reprjfdir + "' has been found !!" |
---|
[1064] | 5047 | quit(-1) |
---|
| 5048 | |
---|
| 5049 | print " Creation of reference projection information file from '" + mod+ "'" |
---|
| 5050 | if dbg: |
---|
[1186] | 5051 | print " using file: '" + reprjfile |
---|
[1064] | 5052 | |
---|
| 5053 | # Getting only 1 time-step for disk space issues |
---|
| 5054 | try: |
---|
| 5055 | with gen.Capturing() as output: |
---|
[1186] | 5056 | ncvar.DataSetSection('time,0,1,1', reprjfile) |
---|
[1064] | 5057 | except: |
---|
| 5058 | print errmsg |
---|
[1186] | 5059 | print 'ncvar.DataSetSection(time,0,1,1, ' + reprjfile + ')' |
---|
[1064] | 5060 | for s1out in output: print s1out |
---|
| 5061 | quit(-1) |
---|
| 5062 | |
---|
[1186] | 5063 | of = reprjfile.split('.')[0] + '_time_B0-E1-I1.nc' |
---|
[1064] | 5064 | |
---|
| 5065 | # Cleaning variables |
---|
| 5066 | try: |
---|
| 5067 | with gen.Capturing() as output: |
---|
[1186] | 5068 | ncvar.selvar('lon@lon,lat@lat,time@time', of, reprjvn) |
---|
[1064] | 5069 | except: |
---|
| 5070 | print errmsg |
---|
[1186] | 5071 | print 'ncvar.selvar(lon@lon,lat@lat, ' + of + ', ' + reprjvn + ')' |
---|
[1064] | 5072 | for s1out in output: print s1out |
---|
| 5073 | quit(-1) |
---|
| 5074 | sout = sub.call('mv selvar_new.nc ' + frefgriddes, shell=True) |
---|
| 5075 | sout = sub.call('rm ' + of + ' >& /dev/null', shell=True) |
---|
| 5076 | |
---|
| 5077 | cnf['RefProjfile'] = frefgriddes |
---|
| 5078 | |
---|
| 5079 | if dbg: |
---|
| 5080 | for s1out in output: print s1out |
---|
| 5081 | break |
---|
| 5082 | |
---|
| 5083 | elif gen.searchInlist(ModComProj,mod) and os.path.isfile(frefgriddes): |
---|
| 5084 | # Including reprojecting reference file in configuration dictionary |
---|
| 5085 | cnf['RefProjfile'] = frefgriddes |
---|
| 5086 | |
---|
[1060] | 5087 | Nmods = len(mods) |
---|
| 5088 | for imod1 in range(0,Nmods-1): |
---|
| 5089 | mod1 = mods[imod1] |
---|
| 5090 | exps1 = modexps[mod1] |
---|
[1064] | 5091 | |
---|
[1060] | 5092 | for imod2 in range(imod1+1,Nmods): |
---|
| 5093 | mod2 = mods[imod2] |
---|
| 5094 | exps2 = modexps[mod2] |
---|
| 5095 | |
---|
| 5096 | Smods = mod2 + '-' + mod1 |
---|
| 5097 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 5098 | print " ** '" + Smods + "': Inter models differences " |
---|
| 5099 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 5100 | print ' experiments mod1:', exps1 |
---|
| 5101 | print ' experiments mod2:', exps2 |
---|
| 5102 | |
---|
| 5103 | # Experiments loop |
---|
| 5104 | ## |
---|
| 5105 | difffiles = ['diffop.inf', 'diffvar.inf'] |
---|
| 5106 | |
---|
| 5107 | Nexps1 = len(exps1) |
---|
| 5108 | Nexps2 = len(exps2) |
---|
| 5109 | for iexp1 in range(0,Nexps1): |
---|
| 5110 | exp1 = exps1[iexp1] |
---|
| 5111 | for iexp2 in range(0,Nexps2): |
---|
| 5112 | exp2 = exps2[iexp2] |
---|
| 5113 | Sexps = exp2 + '-' + exp1 |
---|
| 5114 | print ' ' + Sexps + '...' |
---|
[1067] | 5115 | owdir = cnf['ofold'] + '/' + Smods + '/' + Sexps |
---|
[1060] | 5116 | sout = sub.call('mkdir -p ' + owdir, shell=True) |
---|
| 5117 | |
---|
[1064] | 5118 | # Getting the right projection in order to perform differences |
---|
| 5119 | difmods = [mod1, mod2] |
---|
| 5120 | difexps = [exp1, exp2] |
---|
| 5121 | difreproj = [False, False] |
---|
| 5122 | |
---|
| 5123 | for imod in range(2): |
---|
| 5124 | mod = difmods[imod] |
---|
| 5125 | exp = difexps[imod] |
---|
| 5126 | if not gen.searchInlist(ModComProj,mod): |
---|
| 5127 | print " Projecting files of model '" + mod + "' exp: '" + \ |
---|
| 5128 | exp + "' with file '" + cnf['RefProjfile'] + "'" |
---|
[1186] | 5129 | reproject_modexp(mod, exp, cnf, REPRJvar, moddiffscratch, \ |
---|
[1064] | 5130 | addmoddiffs, dbg) |
---|
| 5131 | difreproj[imod] = True |
---|
| 5132 | |
---|
[1060] | 5133 | # Removing files with list of differences if should be started from |
---|
| 5134 | # scratch or add differences |
---|
| 5135 | for fdiff in difffiles: |
---|
| 5136 | difff = owdir + '/' + fdiff |
---|
[1064] | 5137 | if moddiffscratch: |
---|
[1060] | 5138 | sub.call('rm -rf' + owdir +' >& /dev/null', shell=True) |
---|
| 5139 | sub.call('rm ' + difff +' >& /dev/null', shell=True) |
---|
| 5140 | objf = open(owdir+'/all_' + fdiff,'w') |
---|
| 5141 | objf.write("## Computation and drawing of differences " + \ |
---|
| 5142 | "between '" + mod2+'@'+exp2 + "'-'" + mod1+'@'+exp1 + "'\n") |
---|
| 5143 | objf.close() |
---|
| 5144 | difff = owdir + '/all_vardiffstatistics.inf' |
---|
| 5145 | sub.call('rm ' + difff +' >& /dev/null', shell=True) |
---|
| 5146 | objf = open(owdir+'/all_' + fdiff,'w') |
---|
| 5147 | objf.write("## Computation of all differences statistics " + \ |
---|
| 5148 | "between '" + mod2+'@'+exp2 + "'-'" + mod1+'@'+exp1 + "'\n") |
---|
| 5149 | objf.close() |
---|
| 5150 | |
---|
[1064] | 5151 | if addmoddiffs: |
---|
[1111] | 5152 | if dbg: |
---|
| 5153 | print ' ' + main + ": adding model differences " + \ |
---|
| 5154 | "removing file '" + difff + "' ..." |
---|
[1060] | 5155 | sub.call('rm ' + difff +' >& /dev/null', shell=True) |
---|
| 5156 | |
---|
| 5157 | # op and var differences |
---|
| 5158 | diffvarcompf = owdir + '/' + difffiles[0] |
---|
[1067] | 5159 | if not os.path.isfile(owdir+'/'+difffiles[0]) or \ |
---|
| 5160 | not os.path.isfile(owdir+'/'+difffiles[1]): |
---|
[1060] | 5161 | alldiffop, alldiffvar, Nopdiffs, Nvardiffs = \ |
---|
[1064] | 5162 | diffvarop_listconstruct(cnf, difmods, difexps, difreproj,owdir,\ |
---|
[1060] | 5163 | dbg) |
---|
| 5164 | else: |
---|
[1325] | 5165 | if dbg: |
---|
| 5166 | print warnmsg |
---|
| 5167 | print ' '+main+": getting 'op' and 'var' differences to " + \ |
---|
| 5168 | "compute already from file !!" |
---|
[1060] | 5169 | alldiffop, Nopdiffops = read_diff_file(diffvarcompf) |
---|
| 5170 | alldiffvar, Nopdiffvars = read_diff_file(owdir+'/'+difffiles[1]) |
---|
| 5171 | |
---|
| 5172 | # End of avoiding to repeat all the experiment search |
---|
| 5173 | |
---|
[1064] | 5174 | print " For experiments '" + mod2+'@'+exp2 + "'-'" + mod+'@'+exp1+\ |
---|
[1060] | 5175 | "' is required to compute:", Nvar, "differences" |
---|
| 5176 | |
---|
| 5177 | if dbg: |
---|
[1085] | 5178 | print ' op differences to compute _______' |
---|
[1060] | 5179 | gen.printing_dictionary(alldiffop) |
---|
[1085] | 5180 | print ' var differences to compute _______' |
---|
[1060] | 5181 | gen.printing_dictionary(alldiffvar) |
---|
| 5182 | |
---|
| 5183 | # Computing differences |
---|
| 5184 | ## |
---|
| 5185 | print " Computing operation differences ..." |
---|
[1067] | 5186 | compute_op_diffs(cnf, alldiffop, owdir, moddiffscratch, dbg) |
---|
[1060] | 5187 | print " Computing variable differences ..." |
---|
[1067] | 5188 | compute_var_diffs(cnf, alldiffvar, owdir, moddiffscratch, dbg) |
---|
[1060] | 5189 | |
---|
| 5190 | # Plotting operation differences |
---|
| 5191 | ## |
---|
| 5192 | print " " + main + ": Plotting operation differences' figures ..." |
---|
| 5193 | dirfigf = owdir + '/diffopplotsdraw.inf' |
---|
[1067] | 5194 | if figmoddiffscratch: |
---|
[1060] | 5195 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
| 5196 | |
---|
| 5197 | objf = open(owdir+'/all_diffopfigures.inf','w') |
---|
| 5198 | objf.write("## Drawing of all operation difference figures \n") |
---|
| 5199 | objf.close() |
---|
| 5200 | |
---|
[1067] | 5201 | if addmoddifffigures: |
---|
[1111] | 5202 | if dbg: |
---|
| 5203 | print ' ' + main + ": adding model differences' figures " + \ |
---|
| 5204 | "removing file '" + dirfigf + "' ..." |
---|
[1060] | 5205 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
| 5206 | |
---|
| 5207 | if not os.path.isfile(dirfigf): |
---|
| 5208 | listplots, Nplt = plots_listconstruct(cnf, 'PLOTDIFFOP', dirfigf,\ |
---|
| 5209 | owdir, dbg) |
---|
| 5210 | else: |
---|
[1325] | 5211 | if dbg: |
---|
| 5212 | print warnmsg |
---|
| 5213 | print ' '+main+": getting plots to draw already from file !!" |
---|
[1064] | 5214 | listplots, Nplt = read_plot_file(dirfigf) |
---|
[1060] | 5215 | |
---|
| 5216 | # End of avoiding to repeat all the plots search |
---|
| 5217 | |
---|
| 5218 | print " For experiment 'operation' differences '" + Sexps + "' is "+\ |
---|
| 5219 | "required to plot:" , Nplt, "plots" |
---|
| 5220 | |
---|
| 5221 | if dbg: |
---|
| 5222 | print 'Plots to draw _______' |
---|
| 5223 | gen.printing_dictionary(listplots) |
---|
| 5224 | |
---|
| 5225 | draw_diff_plots(cnf, listplots, owdir, alldiffop, 'diffop', \ |
---|
[1067] | 5226 | figmoddiffscratch, dbg) |
---|
| 5227 | |
---|
| 5228 | # Plotting variable differences |
---|
| 5229 | ## |
---|
| 5230 | print " " + main + ": Plotting variable differences' figures ..." |
---|
| 5231 | dirfigf = owdir + '/diffvarplotsdraw.inf' |
---|
| 5232 | if figscratch: |
---|
| 5233 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
| 5234 | |
---|
| 5235 | objf = open(owdir+'/all_diffvarfigures.inf','w') |
---|
| 5236 | objf.write("## Drawing of all variables difference figures \n") |
---|
| 5237 | objf.close() |
---|
| 5238 | |
---|
| 5239 | if adddifffigures: |
---|
[1111] | 5240 | if dbg: |
---|
| 5241 | print ' ' + main + ": adding differences's figures " + \ |
---|
| 5242 | "removing file '" + dirfigf + "' ..." |
---|
[1067] | 5243 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
| 5244 | |
---|
| 5245 | if not os.path.isfile(dirfigf): |
---|
| 5246 | listplots, Nplt = plots_listconstruct(cnf,'PLOTDIFFVAR',dirfigf, \ |
---|
| 5247 | owdir, dbg) |
---|
| 5248 | else: |
---|
[1325] | 5249 | if dbg: |
---|
| 5250 | print warnmsg |
---|
| 5251 | print ' '+main+": getting plots to draw already from file !!" |
---|
[1067] | 5252 | listplots, Nplt = read_plot_file(dirfigf) |
---|
| 5253 | |
---|
| 5254 | # End of avoiding to repeat all the plots search |
---|
| 5255 | |
---|
| 5256 | print " For experiment 'variables' differences '" + Sexps+ "' is "+ \ |
---|
| 5257 | "required to plot:" , Nplt, "plots" |
---|
| 5258 | |
---|
| 5259 | if dbg: |
---|
| 5260 | print ' Plots to draw _______' |
---|
| 5261 | gen.printing_dictionary(listplots) |
---|
| 5262 | |
---|
[1060] | 5263 | draw_diff_plots(cnf, listplots, owdir, alldiffvar, 'diffvar', \ |
---|
| 5264 | figdiffscratch, dbg) |
---|
| 5265 | |
---|
| 5266 | # end of exp2 loop |
---|
| 5267 | # end of exp1 loop |
---|
| 5268 | # end of mod2 loop |
---|
| 5269 | # end of mod1 loop |
---|
| 5270 | |
---|
[1081] | 5271 | ### ## # |
---|
| 5272 | # All model/exps linear plots |
---|
| 5273 | ### ## # |
---|
| 5274 | |
---|
| 5275 | allmodexps = [] |
---|
| 5276 | for mod in mods: |
---|
| 5277 | for exp in modexps[mod]: |
---|
| 5278 | allmodexps.append(mod + '/' + exp) |
---|
| 5279 | |
---|
| 5280 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 5281 | print ' ** Multi models, multi experiments plots ' |
---|
| 5282 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 5283 | print ' Model/experiments:', allmodexps |
---|
| 5284 | |
---|
| 5285 | owdir = cnf['ofold'] + '/allmodexps' |
---|
| 5286 | sout = sub.call('mkdir -p ' + owdir, shell=True) |
---|
| 5287 | |
---|
| 5288 | # Plotting all model-experiments lines |
---|
| 5289 | ## |
---|
| 5290 | print " " + main + ": Plotting all model-experiments variable figures ..." |
---|
| 5291 | allf = owdir + '/allmodexp.inf' |
---|
| 5292 | dirfigf = owdir + '/allmodexpfigures.inf' |
---|
| 5293 | allfigf = owdir+'/all_figures.inf' |
---|
[1082] | 5294 | if figallmodexpscratch: |
---|
[1081] | 5295 | sout = sub.call('rm ' + allf + ' >& /dev/null', shell=True) |
---|
| 5296 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
[1095] | 5297 | sout = sub.call('rm ' + allfigf + ' >& /dev/null', shell=True) |
---|
[1081] | 5298 | |
---|
[1095] | 5299 | objf = open(allfigf,'w') |
---|
[1081] | 5300 | objf.write("## Drawing of all variables figures for all model-experiments\n") |
---|
| 5301 | objf.close() |
---|
| 5302 | |
---|
| 5303 | if addallmodexpfigures: |
---|
[1111] | 5304 | if dbg: |
---|
| 5305 | print ' ' + main + ": adding model-experiment differences removing " + \ |
---|
| 5306 | " file '" + allfigf + "' ..." |
---|
| 5307 | print ' ' + main + ": adding model-experiment differences' figures " + \ |
---|
| 5308 | "removing file '" + dirfigf + "' ..." |
---|
[1095] | 5309 | sout = sub.call('rm ' + allfigf + ' >& /dev/null', shell=True) |
---|
[1081] | 5310 | sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) |
---|
| 5311 | |
---|
| 5312 | if not os.path.isfile(dirfigf): |
---|
| 5313 | listplots, Nplt = plots_listconstruct(cnf, 'PLOTALLMODEXP', dirfigf, owdir, dbg) |
---|
| 5314 | else: |
---|
[1325] | 5315 | if dbg: |
---|
| 5316 | print warnmsg |
---|
| 5317 | print ' ' + main + ": getting plots to draw already from file !!" |
---|
[1081] | 5318 | listplots, Nplt = read_plot_file(dirfigf) |
---|
| 5319 | |
---|
| 5320 | # End of avoiding to repeat all the plots search |
---|
| 5321 | |
---|
| 5322 | print " Is required to plot:", Nplt, " all model-experiment plots" |
---|
| 5323 | |
---|
| 5324 | if dbg: |
---|
| 5325 | print ' Plots to draw _______' |
---|
| 5326 | gen.printing_dictionary(listplots) |
---|
| 5327 | |
---|
| 5328 | if not os.path.isfile(allf): |
---|
| 5329 | # Constructing the information of modexp / variable |
---|
[1082] | 5330 | allmodexpvar, Nallmodexpvar = allmodexps_listconstruct(cnf, allmodexps, owdir, dbg) |
---|
[1081] | 5331 | else: |
---|
| 5332 | allmodexpvar, Nallmodexpvar = allmodexps_read(allf) |
---|
| 5333 | |
---|
[1085] | 5334 | draw_allmodexp_plots(cnf, allmodexpvar, listplots, modexps, owdir, figallmodexpscratch, dbg) |
---|
[1081] | 5335 | |
---|
[1085] | 5336 | print main + ': all files and figures have been properly done !!' |
---|
[1325] | 5337 | |
---|
| 5338 | # Creation of a pdf with all figures |
---|
| 5339 | ## |
---|
| 5340 | ### |
---|
| 5341 | owdir = cnf['ofold'] |
---|
| 5342 | os.chdir(owdir) |
---|
| 5343 | |
---|
| 5344 | texout ='model_graphics-images' |
---|
| 5345 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 5346 | print ' ** Creation of a pdf with all figures ' |
---|
| 5347 | print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' |
---|
| 5348 | print ' ' + owdir + '/' + texout + '.pdf' |
---|
| 5349 | |
---|
| 5350 | if dbg: |
---|
| 5351 | print main + ": generation of a pdf file '" + owdir + '/' + texout + \ |
---|
| 5352 | "' with all the figures..." |
---|
| 5353 | |
---|
| 5354 | otexf = open(owdir + '/' + texout + '.tex', 'w') |
---|
| 5355 | otexf.write('\\documentclass{article}\n') |
---|
| 5356 | otexf.write('\\usepackage{graphicx}\n') |
---|
| 5357 | otexf.write('\\usepackage[colorlinks=true,urlcolor=blue]{hyperref}\n') |
---|
| 5358 | otexf.write('\\textheight=23cm\n') |
---|
| 5359 | otexf.write('\\textwidth=18cm\n') |
---|
| 5360 | otexf.write('\\oddsidemargin=-1cm\n') |
---|
| 5361 | otexf.write('\\evensidemargin=-1cm\n') |
---|
| 5362 | otexf.write('\\topmargin=-1cm\n') |
---|
| 5363 | |
---|
| 5364 | otexf.write('\n') |
---|
| 5365 | otexf.write('\\begin{document}\n') |
---|
| 5366 | otexf.write('\n') |
---|
| 5367 | otexf.write('\\def\\fontBloc{\\fontfamily{\\sfdefault}\\large\\bfseries}\n') |
---|
| 5368 | otexf.write('\\def\\linia{\\setlength{\\unitlength}{1mm}\n') |
---|
| 5369 | otexf.write('\\line(1,0){80}}\n') |
---|
| 5370 | otexf.write('\\newcommand{\\modexp}[1]{\\clearpage\n') |
---|
| 5371 | otexf.write('\\noindent\\linia\n') |
---|
| 5372 | otexf.write('\\section{#1}\n') |
---|
| 5373 | otexf.write('\\linia}\n') |
---|
| 5374 | otexf.write('\n') |
---|
| 5375 | |
---|
| 5376 | otexf.write('\\title{model\_graphics: ' + gen.latex_text(owdir) + '}\n') |
---|
| 5377 | otexf.write('\\maketitle\n') |
---|
| 5378 | otexf.write('\n') |
---|
| 5379 | otexf.write('\\tableofcontents\n') |
---|
| 5380 | otexf.write('\\listoffigures\n') |
---|
| 5381 | otexf.write('\\clearpage\n') |
---|
| 5382 | |
---|
| 5383 | Nmods = len(mods) |
---|
[1327] | 5384 | lmodexps = [] |
---|
| 5385 | ldiffmodexps = [] |
---|
[1325] | 5386 | # Figures from mod/exp pairs |
---|
| 5387 | for mod in mods: |
---|
| 5388 | exps = modexps[mod] |
---|
| 5389 | for exp in exps: |
---|
| 5390 | print ' direct plots:', mod, exp |
---|
[1327] | 5391 | lmodexps.append(mod+'/'+exp) |
---|
[1325] | 5392 | owdirme = owdir + '/' + mod + '/' + exp |
---|
| 5393 | otexf.write('% ' + mod + ' ' + exp + '\n') |
---|
| 5394 | otexf.write('\\modexp{' + gen.latex_text(mod+' '+exp) + '}\n') |
---|
| 5395 | listplots, Nplt = read_plot_file(owdirme + '/directplotsdraw.inf') |
---|
| 5396 | for plot in listplots.keys(): |
---|
| 5397 | plots = listplots[plot] |
---|
| 5398 | ops = [] |
---|
| 5399 | for plt in plots: |
---|
| 5400 | opn = plt.split('#')[0].split('|')[1] |
---|
| 5401 | if not gen.searchInlist(ops,opn): ops.append(opn) |
---|
| 5402 | for op in ops: |
---|
| 5403 | opS = op.replace('+','_') |
---|
| 5404 | modexpimg = gen.files_folder_HMT(owdirme, head=plot, middle=opS, \ |
---|
| 5405 | tail=cnf['kindfig']) |
---|
| 5406 | Nimages = len(modexpimg) |
---|
| 5407 | if Nimages > 0: |
---|
| 5408 | for img in range(Nimages): modexpimg[img] = owdirme + '/' + \ |
---|
| 5409 | modexpimg[img] |
---|
| 5410 | caption = mod + ' ' + exp + ' ' + plot + ' ' + op |
---|
| 5411 | flab = 'fig:' + caption.replace(' ', '_') |
---|
| 5412 | try: |
---|
| 5413 | with gen.Capturing() as output: |
---|
| 5414 | gen.latex_fig_array(modexpimg, otexf, \ |
---|
| 5415 | gen.latex_text(caption), flab, refsize=0.5, dist='sqr',\ |
---|
| 5416 | dorest='center') |
---|
| 5417 | except: |
---|
| 5418 | print errmsg |
---|
[1327] | 5419 | print 'gen.latex_fig_array(',modexpimg,', '+otexf+', '+ \ |
---|
[1325] | 5420 | 'gen.latex_text(' + caption + '), ' + flab + \ |
---|
| 5421 | ", refsize=0.5, dist='sqr', dorest='center')" |
---|
| 5422 | for s1out in output: print s1out |
---|
| 5423 | quit(-1) |
---|
| 5424 | otexf.write('%\\clearpage\n') |
---|
| 5425 | |
---|
| 5426 | # differences between experiments |
---|
| 5427 | Nexps = len(exps) |
---|
| 5428 | for iexp1 in range(0,Nexps-1): |
---|
| 5429 | exp1 = exps[iexp1] |
---|
| 5430 | for iexp2 in range(iexp1+1,Nexps): |
---|
| 5431 | exp2 = exps[iexp2] |
---|
| 5432 | Sexps = exp2 + '-' + exp1 |
---|
| 5433 | owdirme = owdir + '/' + mod + '/' + Sexps |
---|
| 5434 | print ' diffs:', mod + '/' + Sexps + ' ...' |
---|
[1327] | 5435 | ldiffmodexps.append(mod + '/' + Sexps) |
---|
[1325] | 5436 | for diffn in ['op', 'var']: |
---|
| 5437 | fileplotinf = owdirme + '/diff' + diffn + 'plotsdraw.inf' |
---|
| 5438 | if os.path.isfile(fileplotinf): |
---|
| 5439 | otexf.write('% ' + mod + ' ' + Sexps + ' diff' + diffn + '\n') |
---|
| 5440 | otexf.write('\\modexp{' + gen.latex_text(mod+' '+Sexps+' diff'+ \ |
---|
| 5441 | diffn)+ '}\n') |
---|
| 5442 | listplots, Nplt = read_plot_file(fileplotinf) |
---|
| 5443 | for plot in listplots.keys(): |
---|
| 5444 | plots = listplots[plot] |
---|
| 5445 | ops = [] |
---|
| 5446 | for plt in plots: |
---|
| 5447 | opn = plt.split('#')[0].split('|')[1] |
---|
| 5448 | if not gen.searchInlist(ops,opn): ops.append(opn) |
---|
| 5449 | for op in ops: |
---|
| 5450 | opS = op.replace('+','-') |
---|
| 5451 | modexpimg = gen.files_folder_HMT(owdirme, head=plot, \ |
---|
| 5452 | middle=opS, tail=cnf['kindfig']) |
---|
| 5453 | Nimages = len(modexpimg) |
---|
| 5454 | if Nimages > 0: |
---|
| 5455 | for img in range(Nimages): modexpimg[img] = owdirme +\ |
---|
| 5456 | '/' + modexpimg[img] |
---|
| 5457 | caption = mod + ' ' + Sexps + ' ' + plot + ' ' + op +\ |
---|
| 5458 | ' diff' + diffn |
---|
| 5459 | flab = 'fig:' + caption.replace(' ', '_') |
---|
| 5460 | try: |
---|
| 5461 | with gen.Capturing() as output: |
---|
| 5462 | gen.latex_fig_array(modexpimg, otexf, \ |
---|
| 5463 | gen.latex_text(caption), flab, refsize=0.5,\ |
---|
| 5464 | dist='sqr', dorest='center') |
---|
| 5465 | except: |
---|
| 5466 | print errmsg |
---|
[1327] | 5467 | print 'gen.latex_fig_array(',modexpimg,', '+ \ |
---|
[1325] | 5468 | otexf+', gen.latex_text(' + caption + '), ' + \ |
---|
| 5469 | flab + ", refsize=0.5, dist='sqr', " + \ |
---|
| 5470 | "dorest='center')" |
---|
| 5471 | for s1out in output: print s1out |
---|
| 5472 | quit(-1) |
---|
| 5473 | |
---|
| 5474 | otexf.write('%\\clearpage\n') |
---|
| 5475 | print ' mods-exps diffs ...' |
---|
| 5476 | for imod1 in range(0,Nmods-1): |
---|
| 5477 | mod1 = mods[imod1] |
---|
| 5478 | exps1 = modexps[mod1] |
---|
| 5479 | for imod2 in range(imod1+1,Nmods): |
---|
| 5480 | mod2 = mods[imod2] |
---|
| 5481 | exps2 = modexps[mod2] |
---|
| 5482 | |
---|
| 5483 | Smods = mod2 + '-' + mod1 |
---|
| 5484 | Nexps1 = len(exps1) |
---|
| 5485 | Nexps2 = len(exps2) |
---|
| 5486 | for iexp1 in range(0,Nexps1): |
---|
| 5487 | exp1 = exps1[iexp1] |
---|
| 5488 | for iexp2 in range(0,Nexps2): |
---|
| 5489 | exp2 = exps2[iexp2] |
---|
| 5490 | Sexps = exp2 + '-' + exp1 |
---|
| 5491 | print ' ' + Smods + ' ' + Sexps + ' ...' |
---|
[1327] | 5492 | ldiffmodexps.append(Smods + '/' + Sexps) |
---|
[1325] | 5493 | owdirme = owdir + '/' + Smods + '/' + Sexps |
---|
| 5494 | for diffn in ['op', 'var']: |
---|
| 5495 | fileplotinf = owdirme + '/diff' + diffn + 'plotsdraw.inf' |
---|
| 5496 | if os.path.isfile(fileplotinf): |
---|
| 5497 | otexf.write('% '+Smods + ' ' + Sexps + ' diff'+diffn+'\n') |
---|
| 5498 | otexf.write('\\modexp{' + gen.latex_text(Smods+' '+Sexps+\ |
---|
| 5499 | ' diff'+diffn) + '}\n') |
---|
| 5500 | listplots, Nplt = read_plot_file(fileplotinf) |
---|
| 5501 | for plot in listplots.keys(): |
---|
| 5502 | plots = listplots[plot] |
---|
| 5503 | ops = [] |
---|
| 5504 | for plt in plots: |
---|
| 5505 | opn = plt.split('#')[0].split('|')[1] |
---|
| 5506 | if not gen.searchInlist(ops,opn): ops.append(opn) |
---|
| 5507 | for op in ops: |
---|
| 5508 | opS = op.replace('+','-') |
---|
| 5509 | modexpimg = gen.files_folder_HMT(owdirme, \ |
---|
| 5510 | head=plot, middle=opS, tail=cnf['kindfig']) |
---|
| 5511 | Nimages = len(modexpimg) |
---|
| 5512 | if Nimages > 0: |
---|
| 5513 | for img in range(Nimages): modexpimg[img] = \ |
---|
| 5514 | owdirme + '/' + modexpimg[img] |
---|
| 5515 | caption = Smods + ' ' + Sexps + ' ' + plot + \ |
---|
| 5516 | ' ' + op + ' diff' + diffn |
---|
| 5517 | flab = 'fig:' + caption.replace(' ', '_') |
---|
| 5518 | try: |
---|
| 5519 | with gen.Capturing() as output: |
---|
| 5520 | gen.latex_fig_array(modexpimg, otexf,\ |
---|
| 5521 | gen.latex_text(caption), flab, \ |
---|
| 5522 | refsize=0.5, dist='sqr', \ |
---|
| 5523 | dorest='center') |
---|
| 5524 | except: |
---|
| 5525 | print errmsg |
---|
[1327] | 5526 | print 'gen.latex_fig_array(',modexpimg, \ |
---|
[1325] | 5527 | ', '+otexf+', gen.latex_text(' + \ |
---|
| 5528 | caption + '), '+flab+ ", refsize=0.5,"+\ |
---|
| 5529 | " dist='sqr', dorest='center')" |
---|
| 5530 | for s1out in output: print s1out |
---|
| 5531 | quit(-1) |
---|
| 5532 | otexf.write('%\\clearpage\n') |
---|
| 5533 | |
---|
| 5534 | # allmodexp |
---|
| 5535 | owdirme = owdir + '/allmodexps' |
---|
| 5536 | print ' allmodexps...' |
---|
| 5537 | fileplotinf = owdirme + '/allmodexpfigures.inf' |
---|
| 5538 | if os.path.isfile(fileplotinf): |
---|
| 5539 | otexf.write('% allmodexps\n') |
---|
| 5540 | otexf.write('\\modexp{allmodexps}\n') |
---|
| 5541 | listplots, Nplt = read_plot_file(fileplotinf) |
---|
| 5542 | for plot in listplots.keys(): |
---|
| 5543 | plots = listplots[plot] |
---|
| 5544 | ops = [] |
---|
| 5545 | for plt in plots: |
---|
| 5546 | opn = plt.split('|')[1] |
---|
| 5547 | if not gen.searchInlist(ops,opn): ops.append(opn) |
---|
| 5548 | for op in ops: |
---|
| 5549 | opS = op.replace('+','-') |
---|
| 5550 | modexpimg = gen.files_folder_HMT(owdirme, head=plot, middle=opS, \ |
---|
| 5551 | tail=cnf['kindfig']) |
---|
| 5552 | Nimages = len(modexpimg) |
---|
| 5553 | if Nimages > 0: |
---|
| 5554 | for img in range(Nimages): modexpimg[img] = owdirme + '/' + \ |
---|
| 5555 | modexpimg[img] |
---|
| 5556 | caption = 'allmodexps ' + plot + ' ' + op + ' diff' + diffn |
---|
| 5557 | flab = 'fig:' + caption.replace(' ', '_') |
---|
| 5558 | try: |
---|
| 5559 | with gen.Capturing() as output: |
---|
| 5560 | gen.latex_fig_array(modexpimg,otexf, gen.latex_text(caption),\ |
---|
[1331] | 5561 | flab, refsize=0.9, dist='sqr', dorest='center') |
---|
[1325] | 5562 | except: |
---|
| 5563 | print errmsg |
---|
[1327] | 5564 | print 'gen.latex_fig_array(',modexpimg,', '+otexf+ \ |
---|
[1331] | 5565 | ', gen.latex_text(' + caption + '), ' +flab+ ", refsize=0.9," +\ |
---|
[1325] | 5566 | " dist='sqr', dorest='center')" |
---|
| 5567 | for s1out in output: print s1out |
---|
| 5568 | quit(-1) |
---|
| 5569 | |
---|
| 5570 | otexf.write('%\\clearpage\n') |
---|
[1327] | 5571 | # |
---|
| 5572 | # Grouping by type of figure |
---|
| 5573 | # |
---|
| 5574 | Nmods = len(mods) |
---|
| 5575 | # Figures from mod/exp pairs |
---|
| 5576 | owsearch = owdir + '/' + mods[0] + '/' + modexps[mods[0]][0] |
---|
| 5577 | print " Looking in '" + owsearch + "' for figures by kind and variable..." |
---|
| 5578 | otexf.write('% figures by kind and variable from:' + owsearch + '\n') |
---|
| 5579 | modexpimg = gen.files_folder_HMT(owsearch, tail=cnf['kindfig']) |
---|
| 5580 | # dictionary with kind of plots |
---|
| 5581 | dplots = {} |
---|
| 5582 | # list with kind of plots |
---|
| 5583 | lplots = [] |
---|
| 5584 | # dictionary with variable-statistics of each kind of plot |
---|
| 5585 | dvarstats = {} |
---|
| 5586 | # list with variables of each kind of plot |
---|
| 5587 | lvars = [] |
---|
| 5588 | for plot in modexpimg: |
---|
[1329] | 5589 | Nvars, plotk, varn, statn = figinf_figname(plot,cnf) |
---|
[1327] | 5590 | if not gen.searchInlist(lplots,plotk): |
---|
| 5591 | lplots.append(plotk) |
---|
| 5592 | if not dplots.has_key(plotk+'_'+varn): |
---|
| 5593 | if not gen.searchInlist(lvars,varn): lvars.append(varn) |
---|
| 5594 | dplots[plotk+'_'+varn] = [statn] |
---|
| 5595 | else: |
---|
| 5596 | vals = dplots[plotk+'_'+varn] |
---|
| 5597 | dplots[plotk+'_'+varn] = vals + [statn] |
---|
| 5598 | else: |
---|
| 5599 | if not dplots.has_key(plotk+'_'+varn): |
---|
| 5600 | if not gen.searchInlist(lvars,varn): lvars.append(varn) |
---|
| 5601 | dplots[plotk+'_'+varn] = [statn] |
---|
| 5602 | else: |
---|
| 5603 | vals = dplots[plotk+'_'+varn] |
---|
| 5604 | dplots[plotk+'_'+varn] = vals + [statn] |
---|
| 5605 | |
---|
| 5606 | # Figures found |
---|
| 5607 | print ' direct figures to group:', modexpimg |
---|
| 5608 | print ' plots:', lplots |
---|
| 5609 | print ' variables:', lvars |
---|
[1325] | 5610 | |
---|
[1329] | 5611 | for dplot in dplots.keys(): |
---|
| 5612 | plot = dplot.split('_')[0] |
---|
| 5613 | var = dplot.split('_')[1] |
---|
[1327] | 5614 | otexf.write('% ' + var + '\n') |
---|
| 5615 | otexf.write('\\modexp{' + gen.latex_text(var) + '}\n') |
---|
[1329] | 5616 | varn1 = var.split('-')[0] |
---|
| 5617 | varn2 = var.split('-')[1] |
---|
| 5618 | varn = varn1+'-'+varn2 |
---|
| 5619 | for stn12 in dplots[dplot]: |
---|
| 5620 | stn1 = stn12.split('@')[0] |
---|
| 5621 | stn2 = stn12.split('@')[1] |
---|
| 5622 | stn = gen.lstring_values(stn12, '@',' & ') |
---|
| 5623 | plotvarfigs = [] |
---|
| 5624 | caption = varn.replace('-',' & ') + ' ' + plot + ' ' + stn |
---|
| 5625 | flab = 'fig:' + varn + '_' + plot + '_' + stn12 + '_allmodexp' |
---|
| 5626 | for me in lmodexps: |
---|
| 5627 | modexpn = expGC[me].label |
---|
| 5628 | modn = me.split('/')[0] |
---|
| 5629 | imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn1, \ |
---|
| 5630 | middle=stn1+'-'+varn2, tail=stn2+'.'+cnf['kindfig']) |
---|
| 5631 | caption = caption + ', ' + modexpn |
---|
| 5632 | imgn = owdir+'/'+me+'/'+imgns[0] |
---|
| 5633 | if os.path.isfile(imgn): |
---|
| 5634 | plotvarfigs.append(imgn) |
---|
| 5635 | if dbg: |
---|
| 5636 | print ' Grouping figures:', plotvarfigs |
---|
| 5637 | try: |
---|
| 5638 | with gen.Capturing() as output: |
---|
| 5639 | gen.latex_fig_array(plotvarfigs, otexf, gen.latex_text(caption), \ |
---|
[1331] | 5640 | flab, refsize=0.9, dist='sqr', dorest='center') |
---|
[1329] | 5641 | except: |
---|
| 5642 | print errmsg |
---|
| 5643 | print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', gen.latex_text(' +\ |
---|
[1331] | 5644 | caption + '), ' + flab + ", refsize=0.9, dist='sqr', dorest='center')" |
---|
[1329] | 5645 | for s1out in output: print s1out |
---|
| 5646 | quit(-1) |
---|
[1327] | 5647 | |
---|
| 5648 | Nmods = len(mods) |
---|
| 5649 | # Figures from mod/exp differences |
---|
| 5650 | owsearch = owdir + '/' + ldiffmodexps[0] |
---|
| 5651 | print " Looking in '" + owsearch + "' for difference figures by kind and variable..." |
---|
| 5652 | otexf.write('% difference figures by kind and variable from:' + owsearch + '\n') |
---|
| 5653 | modexpimg = gen.files_folder_HMT(owsearch, tail=cnf['kindfig']) |
---|
| 5654 | # dictionary with kind of plots |
---|
| 5655 | dplots = {} |
---|
| 5656 | # list with kind of plots |
---|
| 5657 | lplots = [] |
---|
| 5658 | # dictionary with variable-statistics of each kind of plot |
---|
| 5659 | dvarstats = {} |
---|
| 5660 | # list with variables of each kind of plot |
---|
| 5661 | lvars = [] |
---|
| 5662 | for plot in modexpimg: |
---|
[1329] | 5663 | Nvars, plotk, varn, statn = figinf_figname(plot,cnf) |
---|
[1327] | 5664 | if not gen.searchInlist(lplots,plotk): |
---|
| 5665 | lplots.append(plotk) |
---|
| 5666 | if not dplots.has_key(plotk+'_'+varn): |
---|
| 5667 | if not gen.searchInlist(lvars,varn): lvars.append(varn) |
---|
| 5668 | dplots[plotk+'_'+varn] = [statn] |
---|
| 5669 | else: |
---|
| 5670 | vals = dplots[plotk+'_'+varn] |
---|
| 5671 | dplots[plotk+'_'+varn] = vals + [statn] |
---|
| 5672 | else: |
---|
| 5673 | if not dplots.has_key(plotk+'_'+varn): |
---|
| 5674 | if not gen.searchInlist(lvars,varn): lvars.append(varn) |
---|
| 5675 | dplots[plotk+'_'+varn] = [statn] |
---|
| 5676 | else: |
---|
| 5677 | vals = dplots[plotk+'_'+varn] |
---|
| 5678 | dplots[plotk+'_'+varn] = vals + [statn] |
---|
| 5679 | |
---|
| 5680 | # Figures found |
---|
| 5681 | print ' difference figures to group:', modexpimg |
---|
| 5682 | print ' plots:', lplots |
---|
| 5683 | print ' variables:', lvars |
---|
| 5684 | |
---|
[1329] | 5685 | for dplot in dplots.keys(): |
---|
| 5686 | plot = dplot.split('_')[0] |
---|
| 5687 | var = dplot.split('_')[1] |
---|
[1327] | 5688 | otexf.write('% ' + var + '\n') |
---|
| 5689 | otexf.write('\\modexp{diff ' + gen.latex_text(var) + '}\n') |
---|
[1329] | 5690 | varn1 = var.split('-')[0] |
---|
| 5691 | varn2 = var.split('-')[1] |
---|
| 5692 | varn = varn1+'-'+varn2 |
---|
| 5693 | for stn12 in dplots[dplot]: |
---|
| 5694 | stn1 = stn12.split('@')[0] |
---|
| 5695 | stn2 = stn12.split('@')[1] |
---|
| 5696 | stn = gen.lstring_values(stn12, '@',' & ') |
---|
| 5697 | plotvarfigs = [] |
---|
| 5698 | caption = varn.replace('-',' & ') + ' ' + plot + ' ' + stn |
---|
| 5699 | flab = 'fig:' + varn + '_' + plot + '_' + stn12 + '_alldiffmodexp' |
---|
| 5700 | for me in ldiffmodexps: |
---|
| 5701 | mods = me.split('/')[0] |
---|
| 5702 | exps = me.split('/')[1] |
---|
| 5703 | if exps.find('-') != -1: |
---|
| 5704 | expn1 = exps.split('-')[0] |
---|
| 5705 | expn2 = exps.split('-')[1] |
---|
| 5706 | else: |
---|
| 5707 | expn1 = exps |
---|
| 5708 | expn2 = exps |
---|
[1327] | 5709 | |
---|
[1329] | 5710 | if mods.find('-') != -1: |
---|
| 5711 | modn1 = mods.split('-')[0] |
---|
| 5712 | modn2 = mods.split('-')[1] |
---|
| 5713 | else: |
---|
| 5714 | modn1 = mods |
---|
| 5715 | modn2 = mods |
---|
| 5716 | modexpn1 = expGC[modn1 + '/' + expn1].label |
---|
| 5717 | modexpn2 = expGC[modn2 + '/' + expn2].label |
---|
| 5718 | modexpn = modexpn1 + '-' + modexpn2 |
---|
[1327] | 5719 | |
---|
[1329] | 5720 | modn = me.split('/')[0] |
---|
| 5721 | imgns = gen.files_folder_HMT(owdir+'/'+me, head=plot+'_'+varn1, \ |
---|
| 5722 | middle=stn1+'-'+varn2, tail=stn2+'.'+cnf['kindfig']) |
---|
| 5723 | caption = caption + ', ' + modexpn |
---|
| 5724 | imgn = owdir+'/'+me+'/'+imgns[0] |
---|
| 5725 | if os.path.isfile(imgn): |
---|
| 5726 | plotvarfigs.append(imgn) |
---|
| 5727 | if dbg: |
---|
| 5728 | print ' Grouping figures:', plotvarfigs |
---|
| 5729 | try: |
---|
| 5730 | with gen.Capturing() as output: |
---|
| 5731 | gen.latex_fig_array(plotvarfigs, otexf, gen.latex_text(caption), \ |
---|
[1331] | 5732 | flab, refsize=0.9, dist='sqr', dorest='center') |
---|
[1329] | 5733 | except: |
---|
| 5734 | print errmsg |
---|
| 5735 | print 'gen.latex_fig_array(',plotvarfigs,', '+otexf+', gen.latex_text('+ \ |
---|
[1331] | 5736 | caption + '), ' + flab + ", refsize=0.9, dist='sqr', dorest='center')" |
---|
[1329] | 5737 | for s1out in output: print s1out |
---|
| 5738 | quit(-1) |
---|
[1327] | 5739 | |
---|
[1325] | 5740 | otexf.write('\\end{document}\n') |
---|
| 5741 | otexf.close() |
---|
| 5742 | |
---|
| 5743 | try: |
---|
| 5744 | with gen.Capturing() as output: |
---|
| 5745 | ins = 'pdflatex ' + owdir + '/' + texout |
---|
| 5746 | sout = sub.call(ins, shell=True) |
---|
| 5747 | except: |
---|
| 5748 | print errormsg |
---|
| 5749 | print ' ' + ins |
---|
| 5750 | print sout |
---|
| 5751 | for s1out in output: print s1out |
---|
| 5752 | quit(-1) |
---|
| 5753 | |
---|
| 5754 | with gen.Capturing() as output: |
---|
| 5755 | sout = sub.call(ins + '>& /dev/null', shell=True) |
---|
| 5756 | with gen.Capturing() as output: |
---|
| 5757 | sout = sub.call(ins + '>& /dev/null', shell=True) |
---|
| 5758 | with gen.Capturing() as output: |
---|
| 5759 | sout = sub.call(ins + '>& /dev/null', shell=True) |
---|
| 5760 | with gen.Capturing() as output: |
---|
| 5761 | sout = sub.call(ins, shell=True) |
---|
| 5762 | if dbg: |
---|
| 5763 | print sout |
---|
| 5764 | for s1out in output: print s1out |
---|
| 5765 | |
---|
| 5766 | sub.call('evince ' + owdir + '/' + texout + '.pdf &', shell=True) |
---|
| 5767 | |
---|