Changeset 1095 in lmdz_wrf
- Timestamp:
- Sep 9, 2016, 7:05:24 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/model_graphics.py
r1085 r1095 30 30 'diffscratch', 'figdiffscratch', 'figallmodexpscratch', 'addfiles', \ 31 31 'addfigures', 'adddiffs', 'adddifffigures', 'addallmodexpfigures', 'debug', \ 32 'models', 'ifold', 'ofold', 'warnmsg', 'errmsg', 'titleoperations', 'kindfig', \ 33 'CFreftime', 'CFunitstime', 'mapval', 'timekind', 'timefmt', 'timelabel' ] 32 'models', 'modgraphchar', 'expgraphchar', 'ifold', 'ofold', 'warnmsg', \ 33 'errmsg', 'titleoperations', 'kindfig', 'CFreftime', 'CFunitstime', 'mapval', \ 34 'timekind', 'timefmt', 'timelabel' ] 34 35 35 36 # List with the optional keys … … 248 249 addmoddifffigs, addallmodexpfigs, debug 249 250 251 252 class gc(object): 253 """ Class which holds all the graphical characteristics 254 [label]: label as it should appear in the graphics 255 [color]: specific color of the model 256 [linetype]: specific type of line of the model 257 [marker]: specific marker of the model 258 [sizes]: line width and point size for the model 259 [tmod]: time modification to apply to the model files (None for nothing) 260 'setorigin',[YYYYMMDDHHMISS]: re-set origin of times at [YYYYMMDDHHMISS] 261 """ 262 def __init__( self, label, color, linetype, marker, sizes, Tmod): 263 self.label = None 264 self.color = None 265 self.linetype = None 266 self.marker = None 267 self.sizes = None 268 self.tmod = None 269 if label is not None: 270 self.label = label 271 self.color = color 272 self.linetype = linetype 273 self.marker = marker 274 self.sizes = sizes 275 if Tmod != 'None': 276 self.tmod = Tmod 277 278 def graphical_characteristics(config, debug): 279 """ Function to provide the graphical characteristics of models and experiments 280 config= configuration of the experiment 281 """ 282 fname = 'graphical_characteristics' 283 284 modgraphchar = {} 285 modvals = config['modgraphchar'].split(':') 286 for modval in modvals: 287 modv = modval.split('|') 288 modgraphchar[modv[0]] = gc(modv[1], modv[2], modv[3], modv[4], modv[5], modv[6]) 289 290 expgraphchar = {} 291 expvals = config['expgraphchar'].split(':') 292 for expval in expvals: 293 expvs = expval.split('|') 294 modexp = expvs[0] + '/' + expvs[1] 295 if not modgraphchar.has_key(expvs[0]): 296 print errmsg 297 print ' ' + fname + ": a model called '" +expvs[0]+ "' does not exist !!" 298 print ' existing models with graphic characteristics:', \ 299 modgraphchar.keys() 300 quit(-1) 301 302 modvs = modgraphchar[expvs[0]] 303 expv = expvs[2:7] 304 if expv[1] == 'asmodel': expv[1] = modvs.color 305 if expv[2] == 'asmodel': expv[2] = modvs.linetype 306 if expv[3] == 'asmodel': expv[3] = modvs.marker 307 if expv[4] == 'asmodel': expv[4] = modvs.sizes 308 309 expgraphchar[modexp] = gc(expv[0], expv[1], expv[2], expv[3], expv[4], 'None') 310 311 # Running some tests 312 mods = config['models'].split(':') 313 for mod in mods: 314 if not modgraphchar.has_key(mod): 315 print errmsg 316 print ' ' + fname + ": model called '" + mod + "' does not have " + \ 317 "graphical characteristics !!" 318 print ' existing models with graphic characteristics:', \ 319 modgraphchar.keys() 320 quit(-1) 321 322 exps = config[mod + 'exps'].split(':') 323 for exp in exps: 324 modexp = mod + '/' + exp 325 if not expgraphchar.has_key(modexp): 326 print errmsg 327 print ' ' + fname + ": model/experiment called '" + modexp + \ 328 "' does not have graphical characteristics !!" 329 print ' existing model/experiments with graphic ' + \ 330 'characteristics:', expgraphchar.keys() 331 quit(-1) 332 333 if debug: 334 print ' ' + fname + ': model graphical characteristics _______' 335 for modn in modgraphchar.keys(): 336 with gen.Capturing() as output: 337 gen.printing_class(modgraphchar[modn]) 338 print "'" + modn + "'; " + ', '.join(output) 339 print ' ' + fname + ': experiment graphical characteristics _______' 340 for modexpn in expgraphchar.keys(): 341 with gen.Capturing() as output: 342 gen.printing_class(expgraphchar[modexpn]) 343 print "'" + modexpn + "'; " + ', '.join(output) 344 345 return modgraphchar, expgraphchar 346 250 347 def exp_headers(mod,config): 251 348 """ Function to provide the headers and the experiments of a given model … … 299 396 dimensions= list of the dimensions 300 397 vardimensions= list of the variable-dimensions 398 timemodif= time modification to apply to the model files ('None' for nothing) 399 'setorigin',[YYYYMMDDHHMISS]: re-set origin of times at [YYYYMMDDHHMISS] 301 400 """ 302 def __init__( self, name, model, dx, dy, dz, dt, ds, vdx, vdy, vdz, vdt, vds): 303 self.name= None 304 self.model= None 305 self.dimxn= None 306 self.dimyn= None 307 self.dimzn= None 308 self.dimtn= None 309 self.dimsn= None 310 self.vardxn= None 311 self.vardyn= None 312 self.vardzn= None 313 self.vardtn= None 314 self.vardsn= None 315 if name is not None: 316 self.name = name 317 self.model= model 318 self.dimxn= dx 319 self.dimyn= dy 320 self.dimzn= dz 321 self.dimtn= dt 322 self.dimsn= ds 323 self.vardxn= vdx 324 self.vardyn= vdy 325 self.vardzn= vdz 326 self.vardtn= vdt 327 self.vardsn= vds 328 self.dimensions = [dx, dy, dz, dt, ds] 329 self.vardimensions = [vdx, vdy, vdz, vdt, vds] 401 def __init__( self, name, model, dx, dy, dz, dt, ds, vdx, vdy, vdz, vdt, vds, \ 402 tmod): 403 self.name= None 404 self.model= None 405 self.dimxn= None 406 self.dimyn= None 407 self.dimzn= None 408 self.dimtn= None 409 self.dimsn= None 410 self.vardxn= None 411 self.vardyn= None 412 self.vardzn= None 413 self.vardtn= None 414 self.vardsn= None 415 self.timemodif = None 416 if name is not None: 417 self.name = name 418 self.model= model 419 self.dimxn= dx 420 self.dimyn= dy 421 self.dimzn= dz 422 self.dimtn= dt 423 self.dimsn= ds 424 self.vardxn= vdx 425 self.vardyn= vdy 426 self.vardzn= vdz 427 self.vardtn= vdt 428 self.vardsn= vds 429 if tmod is not None: 430 self.timemodif = tmod 431 self.dimensions = [dx, dy, dz, dt, ds] 432 self.vardimensions = [vdx, vdy, vdz, vdt, vds] 330 433 331 434 def variable_compute(idir,var,ftests,db): … … 671 774 print ' ' + fname + ": creation of variable file '" + CFvarn + \ 672 775 "' in file '" + ifilen + "' ..." 673 print ' model variable:', modvar674 print ' diagostic variable:', diagvar776 print ' model variable:', modvar 777 print ' diagostic variable:', diagvar 675 778 676 779 if diagvar is None: … … 777 880 try: 778 881 with gen.Capturing() as output: 779 ncvar.LMDZ_toCF( ifilen)882 ncvar.LMDZ_toCF(Tunits + '!since!' + Tref, ifilen) 780 883 except: 781 884 print errmsg 782 print 'LMDZ_toCF('+ ifilen + ')'885 print 'LMDZ_toCF('+ Tunits +'!since!'+ Tref + ', ' + ifilen + ')' 783 886 for s1out in output: print s1out 784 887 quit(-1) … … 815 918 sout = sub.call('mv netcdf_fold_concatenated_HMT.nc ' + fileon, shell=True) 816 919 if os.path.isfile(fileon): 817 sout = sub.call('rm ' + CFvarn +'_'+ headerf+SgP + '_*-*.nc >& /dev/null',920 sout = sub.call('rm '+CFvarn +'_'+ headerf+SgP + '_*-*.nc >& /dev/null',\ 818 921 shell=True) 922 923 # Re-setting time of final concatenated file 924 if minf.timemodif is not None: 925 if db: 926 print ' ' + fname + ": Modifying times of the file by '" + \ 927 minf.timemodif + "' !!" 928 try: 929 with gen.Capturing() as output: 930 ncvar.time_reset(minf.timemodif, fileon,'time') 931 except: 932 print errmsg 933 print 'time_reset(' + minf.timemodif + ', ' + fileon + ', time)' 934 for s1out in output: print s1out 935 quit(-1) 936 if db: 937 for s1out in output: print s1out 819 938 820 939 return … … 1365 1484 vopnV = allvarcomp[vopn] 1366 1485 fheader = vopnV[0] 1367 model = vopnV[1] 1486 if type(vopnV[1]) == type([1, 2]) and len(vopnV[1]) == 1: 1487 vals = vopnV[1] 1488 model = vals[0] 1489 else: 1490 model = vopnV[1] 1368 1491 diag = vopnV[2] 1369 1492 globalP = vopnV[3] … … 1570 1693 1571 1694 def draw_plot(kplot, CFvplot, fplot, vplot, dplot, pplot, finame, tfig, kfig, mapval,\ 1572 tvals, od, pyH, fscr, db):1695 tvals, expgraphc, od, pyH, fscr, db): 1573 1696 """ Function to draw a plot 1574 1697 kplot= kind of plot … … 1587 1710 timefmt: format of time ticks in the plot 1588 1711 timelabel: label of time-axis in the plot 1712 expgraphc= dictionary with expriment graphical characteristics 1589 1713 od= output directory 1590 1714 pyH= python HOME … … 1609 1733 timefmt = tvals[2] 1610 1734 timelabel = tvals[3] 1735 1736 # Graphical labels and configuration 1737 1611 1738 1612 1739 if not os.path.isfile(finame): … … 1815 1942 kinds = kinds + ',' + kind 1816 1943 lines = lines + ',' + line 1817 marks = marks + ' ,' + mark1944 marks = marks + '@' + mark 1818 1945 sizes = sizes + ',' + str(size) 1819 1946 else: … … 1823 1950 sizes = '2.' 1824 1951 1825 1826 1952 secsf = fplot[il].split('/') 1827 1953 Nsecsf = len(secsf) 1828 lablines.append(secsf[Nsecsf-3] + '/' + secsf[Nsecsf-2]) 1954 expvs = expgraphc[secsf[Nsecsf-3] + '/' + secsf[Nsecsf-2]] 1955 lablines.append(expvs.label) 1829 1956 1830 1957 # It is assumed that if the space variable is 'lon': is desired a … … 1873 2000 for s1out in output: print s1out 1874 2001 quit(-1) 2002 2003 # keeping all figures 2004 trkobjf.write('\n') 2005 trkobjf.write("#" + tfig.replace('!',' ') + '\n') 2006 trkobjf.write(plotins + '\n') 2007 2008 elif kplot == 'Nlines_time': 2009 figtit = tfig.replace('!','|') 2010 2011 linestdn = CFvplot[0] 2012 figfs = ','.join(fplot) 2013 2014 Nlines = len(fplot) 2015 2016 lablines = [] 2017 for il in range(Nlines): 2018 linev = pplot[il] 2019 # Values are changed from specific values in `model_graphics.dat' 2020 if linev[3].find('%') == -1: 2021 line = linev[2] 2022 kind = linev[3] 2023 mark = linev[4] 2024 size = linev[5] 2025 if il == 0: 2026 vrange = str(linev[0]) + ',' + str(linev[1]) 2027 kinds = kind 2028 lines = line 2029 marks = mark 2030 sizes = str(size) 2031 else: 2032 kinds = kinds + ',' + kind 2033 lines = lines + ',' + line 2034 marks = marks + '@' + mark 2035 sizes = sizes + ',' + str(size) 2036 else: 2037 lines = 'None' 2038 kinds = '-' 2039 marks = ',' 2040 sizes = '2.' 2041 2042 secsf = fplot[il].split('/') 2043 Nsecsf = len(secsf) 2044 expvs = expgraphc[secsf[Nsecsf-3] + '/' + secsf[Nsecsf-2]] 2045 lablines.append(expvs.label) 2046 2047 valsaxis = 'y' 2048 figmid = 'evolution' 2049 2050 figtit = '|'.join(tfig.split('!')[0:2]) + '|' + figmid + '|' + \ 2051 '|'.join(tfig.split('!')[2:]) 2052 leglabels = ','.join(lablines) 2053 2054 graphvals = 'time;' + valsaxis + ';time;' + leglabels + ';' + \ 2055 CFvplot[0] + ';' + figtit + ';None;time|' + '|'.join(tvals) + \ 2056 ';0|auto;' + kfig + ';' + kinds + ';' + lines + ';' + marks + ';' + \ 2057 sizes + ';' + sizes + ';all;-1' 2058 2059 fvarS = vplot[0] 2060 2061 drwins = 'draw_lines_time' 2062 plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ 2063 " -S '" + graphvals + "' -v " + fvarS 2064 2065 try: 2066 with gen.Capturing() as output: 2067 sout = sub.call(plotins, shell=True) 2068 except: 2069 print errmsg 2070 print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' 2071 print sout 2072 for s1out in output: print s1out 2073 quit(-1) 2074 2075 sout = sub.call('mv lines_time.' + kfig + ' ' + finame, shell=True) 1875 2076 1876 2077 # keeping all figures … … 2226 2427 kindfigure = config['kindfig'] 2227 2428 2429 # Graphical labels and configuration 2430 modgc, expgc = graphical_characteristics(config, debug) 2431 modv = modgc[mod] 2432 modlab = modv.label 2433 expv = expgc[mod+'/'+exp] 2434 explab = expv.label 2435 2228 2436 # Map value 2229 2437 mapvalue = config['mapval'] … … 2329 2537 2330 2538 # Title of figure 2331 titfigure = create_figure_title(mod , exp, varops, opexplained)2539 titfigure = create_figure_title(modlab, explab, varops, opexplained) 2332 2540 2333 2541 draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ 2334 figname, titfigure, kindfigure, mapvalue, timevals, odir, pyHOME,\2335 figscr, debug)2542 figname, titfigure, kindfigure, mapvalue, timevals, expgc, odir, \ 2543 pyHOME, figscr, debug) 2336 2544 2337 2545 # End of variables-operations … … 3278 3486 kindfigure = config['kindfig'] 3279 3487 3488 # Graphical labels and configuration 3489 modgc, expgc = graphical_characteristics(config, debug) 3490 3280 3491 # Map value 3281 3492 mapvalue = config['mapval'] … … 3337 3548 headf = vopvals[4] 3338 3549 3339 modexpdiff = mod2 + '/' + exp2 + '-' + mod1 + '/' + exp1 3550 modv = modgc[mod1] 3551 expv = expgc[mod1+'/'+exp1] 3552 modlab1 = modv.label 3553 explab1 = expv.label 3554 modv = modgc[mod2] 3555 expv = expgc[mod2+'/'+exp2] 3556 modlab2 = modv.label 3557 explab2 = expv.label 3558 3559 modexpdiff = explab2 + '-' + explab1 3340 3560 modexpdiffS = mod2 + '-' + exp2 + '_' + mod1 + '-' + exp1 3341 3561 … … 3406 3626 3407 3627 draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ 3408 figname, titfigure, kindfigure, mapvalue, timevals, odir, pyHOME,\3409 figscr, debug)3628 figname, titfigure, kindfigure, mapvalue, timevals, expgc, odir, \ 3629 pyHOME, figscr, debug) 3410 3630 3411 3631 # End of variables-operations … … 3575 3795 print ' ' + fname + ': computing from the original reprojected file' 3576 3796 ModI = ModelInf(mod, mod, 'lon', 'lat', 'pres', 'time', 'depth', \ 3577 'lon', 'lat', 'pres', 'time', 'depth' )3797 'lon', 'lat', 'pres', 'time', 'depth', None) 3578 3798 VarI = VariableInf(vn, values[0], values[2], values[3]) 3579 3799 usefs = {values[0]: ofileorig} … … 3718 3938 objf.close() 3719 3939 3720 return all plts, Nallmodexp3940 return allmodexp, Nallmodexp 3721 3941 3722 3942 def allmodexps_read(filen): … … 3737 3957 values = line.replace('\n','').split(' ') 3738 3958 if values[0] == 'allmodexps:': 3739 allplts = gen.stringList_dictKeysVals(values[1] )3959 allplts = gen.stringList_dictKeysVals(values[1],cV=':') 3740 3960 elif values[0] == 'Nallmodexp:': 3741 3961 Nallmodexp = int(values[1]) … … 3812 4032 gen.printing_dictionary(plotspecifics) 3813 4033 4034 # Graphical labels and configuration 4035 modgc, expgc = graphical_characteristics(config, debug) 4036 3814 4037 # Kind of figures 3815 4038 kindfigure = config['kindfig'] … … 3933 4156 3934 4157 draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ 3935 figname, titfigure, kindfigure, mapvalue, timevals, odir, pyHOME,\3936 figscr, debug)4158 figname, titfigure, kindfigure, mapvalue, timevals, expgc, odir, \ 4159 pyHOME, figscr, debug) 3937 4160 3938 4161 # End of variables-operations … … 3972 4195 # Getting models 3973 4196 mods = cnf['models'].split(':') 4197 4198 # Getting graphical characeristics 4199 modGC, expGC = graphical_characteristics(cnf, dbg) 3974 4200 3975 4201 # Models loop … … 4000 4226 dnz = Modinf.dimzn 4001 4227 dnt = Modinf.dimtn 4228 dns = Modinf.dimsn 4002 4229 vdnx = Modinf.vardxn 4003 4230 vdny = Modinf.vardyn 4004 4231 vdnz = Modinf.vardzn 4005 4232 vdnt = Modinf.vardtn 4233 vdns = Modinf.vardsn 4234 4235 modgraphv = modGC[mod] 4236 Modinf = ModelInf(mod, mod, dnx, dny, dnz, dnt, dns, vdnx, vdny, vdnz, vdnt, \ 4237 vdns, modgraphv.tmod) 4006 4238 4007 4239 if dbg: 4008 4240 print ' model characteristics _______' 4009 print " dims:", dnx, dny, dnz, dnt 4010 print " var dims:", vdnx, vdny, vdnz, vdnt 4241 gen.printing_class(Modinf) 4011 4242 4012 4243 moddims = dnx + ',' + dny + ',' + dnz + ',' + dnt … … 4568 4799 sout = sub.call('rm ' + allf + ' >& /dev/null', shell=True) 4569 4800 sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) 4570 4571 objf = open(allfig,'w') 4801 sout = sub.call('rm ' + allfigf + ' >& /dev/null', shell=True) 4802 4803 objf = open(allfigf,'w') 4572 4804 objf.write("## Drawing of all variables figures for all model-experiments\n") 4573 4805 objf.close() 4574 4806 4575 4807 if addallmodexpfigures: 4576 sout = sub.call('rm ' + allf + ' >& /dev/null', shell=True)4808 sout = sub.call('rm ' + allfigf + ' >& /dev/null', shell=True) 4577 4809 sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) 4578 4810
Note: See TracChangeset
for help on using the changeset viewer.