Changeset 1081 in lmdz_wrf
- Timestamp:
- Sep 4, 2016, 9:16:01 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/model_graphics.py
r1080 r1081 126 126 moddifscr = True 127 127 figmoddifscr = True 128 figallmodexpscr = True 128 129 tim.sleep(10) 129 130 else: … … 183 184 figmoddifscr = False 184 185 186 if config['figallmodexpscratch'] == 'true': 187 figallmodexpscr = True 188 print warnmsg 189 print " " + main + ": figures all model-experiment starting from the SCRATCH !!" 190 print " 5 seconds left!!" 191 tim.sleep(5) 192 else: 193 figallmodexpscr = False 194 185 195 if config['addall'] == 'true': 186 196 print warnmsg … … 192 202 addmoddiffs = True 193 203 addmoddifffigs = True 204 addallmodexpfigs = True 194 205 else: 195 206 if config['addfiles'] == 'true': … … 223 234 addmoddifffigs = False 224 235 236 if config['addmodexpfigures'] == 'true': 237 addmodexpfigs = True 238 else: 239 addmodexpfigs = False 240 225 241 if config['debug'] == 'true': 226 242 debug = True … … 228 244 debug = False 229 245 230 return scr, filescr, figscr, difscr, figdifscr, moddifscr, figmoddifscr, addfils,\ 231 addfigs, adddiffs, adddifffigs, addmoddiffs, addmoddifffigs, debug 246 return scr, filescr, figscr, difscr, figdifscr, moddifscr, figmoddifscr, \ 247 figallmodexpscr, addfils, addfigs, adddiffs, adddifffigs, addmoddiffs, \ 248 addmoddifffigs, addmodexpfigs, debug 232 249 233 250 def exp_headers(mod,config): … … 2180 2197 """ Function to provide the operations to make for each variable from kdiff ('DIFFOP_' or 'DIFFVAR_') dictionary 2181 2198 vc= kdiff dictionary, dictionary with all the parameters started with kdiff 2182 kdiff= kind of differences 'op' or'var'2199 kdiff= kind of differences 'op', 'var' 2183 2200 """ 2184 2201 fname = 'get_differences_var' … … 3457 3474 return 3458 3475 3476 def allmodexps_listconstruct(config, modexps, reprj, odir, debug): 3477 """ Function to create the list of all model-experiments to draw 3478 config= Configuration of the experiment 3479 modexps= list with the models-experiments pairs to use 3480 reprj= list with whether re-rpojection needs to be done 3481 odir= output differences folder 3482 """ 3483 fname='allmodexps_listconstruct' 3484 3485 allplts = gen.get_specdictionary_HMT(config, H='PLOTALLMODEXP_') 3486 3487 if debug: 3488 if allplts is not None: 3489 print " 'all mod-exps' plots ________" 3490 gen.printing_dictionary(allplts) 3491 3492 # Getting Model-Reference Projection 3493 ModComProj = cnf['RefProj'].split(':') 3494 3495 for modexp in modexps: 3496 mod = modexp.split('/')[0] 3497 exp = modexp.split('/')[1] 3498 3499 # Getting variable characteristics from each model/experiment 3500 idir = config['ofold'] + '/' + modexp 3501 3502 reproj = not gen.searchInlist(ModComProj,mod) 3503 3504 fvarcomp = 'varcompuet.inf' 3505 if reproj: fvc = 'reproj_' + fvarcomp 3506 else: fvc = fvarcomp 3507 3508 files, testfiles, allcompvar, Nvar= read_varcomp_file(idir + '/' + fvc) 3509 3510 allmodexp = {} 3511 if allplts is not None: 3512 # Getting all model-experiments plots characteristics 3513 3514 Nallmodexp = 0 3515 for allplt in allplts.keys(): 3516 varops = allplts[allplt].split(':') 3517 for vnop in varops: 3518 vn = varop.split('|')[0] 3519 op = varop.split('|')[1] 3520 if not allcompvar.has_key(vnop): 3521 print warnmsg 3522 print ' ' + fname + ": variable+operation '" + vnop + \ 3523 "' in '" + modexp + "' was not computed !!" 3524 print ' skipping it!' 3525 break 3526 3527 vals = allcompvar[vnop] 3528 3529 headerf = vals[0] 3530 if modexp == modexps[0]: 3531 allmodexp[vnop] = [modexp,headerf] 3532 else: 3533 prevals = allmodexp[vnop] 3534 prevals = prevals + [modexp,headerf] 3535 allmodexp[vnop] = prevals 3536 3537 Nallmodexp = Nallmodexp + 1 3538 else: 3539 Nallmodexp = 0 3540 3541 if allplts is not None: 3542 Sallmodexps = gen.dictKeysVals_stringList(allmodexp) 3543 else: 3544 Sallmodexps = 'none' 3545 3546 # Outwritting the all model-experiment plots file to avoid next time 3547 objf = open(odir + '/allmodexp.inf', 'w') 3548 objf.write('allmodexps: ' + Sallmodexps + '\n') 3549 objf.write('Nallmodexp: ' + str(Nallmodexp) + '\n') 3550 objf.close() 3551 3552 return allplts, Nallmodexp 3553 3554 def read_allmodexp_file(filen): 3555 """ Function to read the file with the information about the all model-experiment plots 3556 filen= file with the information 3557 """ 3558 fname = 'read_allmodexp_file' 3559 3560 if not os.path.isfile(filen): 3561 print errormsg 3562 print ' ' + fname + ": all model-experiment file '" + filen + \ 3563 "' does not exist !!" 3564 quit(-1) 3565 3566 objf = open(filen, 'r') 3567 for line in objf: 3568 if line[0:1] != '#' and len(line) > 1: 3569 values = line.replace('\n','').split(' ') 3570 if values[0] == 'allmodexps:': 3571 allplts = gen.stringList_dictKeysVals(values[1]) 3572 elif values[0] == 'Nallmodexp:': 3573 Nallmodexp = int(values[1]) 3574 3575 objf.close() 3576 3577 return allplts, Nallmodexp 3578 3579 def draw_allmodexp_plots(config, allvarcomp, plots, modexp, odir, figscr, debug): 3580 """ Function to draw all model-experiment plots 3581 config= Configuration of the experiment 3582 allvarcomp = dictionary with the file headers for each variable 3583 plots= dictionary with the plots 3584 modexps= list with the names of the model-experiment pairs 3585 odir= output experiment folder 3586 figscr= whether figures should be done from the scratch or not 3587 3588 * Plot as 3589 {[kplot]} = [varn1]|[op1]#[varn2]|[op2]#[...[varnN]|[opN]], ... 3590 [kplot] ___ 3591 Nlines: Multiple lines with one line by model-experiment pairs 3592 [varn] 3593 variable 3594 [op] 3595 '+' separated list of operations 3596 in figures with more than 1 variable, use '#' to separate the [varn]|[op] 3597 """ 3598 fname = 'draw_allmodexp_plots' 3599 3600 os.chdir(odir) 3601 3602 # Dictionary with the operations with surnames for the operated variable 3603 opersurnames = {} 3604 opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') 3605 for opsr in opsur.keys(): 3606 opn = opsr.split('_')[1] 3607 vls = opsur[opsr].split(':') 3608 opersurnames[opn] = vls 3609 3610 # time values 3611 # Units time for the plots 3612 rd = config['CFreftime'] 3613 tunits = config['CFunitstime'] + '!since!' + rd[0:4] + '-' + rd[4:6] + '-' + \ 3614 rd[6:8] + '!' + rd[8:10] + ':' + rd[10:12] + ':' + rd[12:14] 3615 # time ticks kind 3616 tkind = config['timekind'] 3617 # time ticks format 3618 tfmt = config['timefmt'] 3619 # time axis label 3620 tlab = config['timelabel'] 3621 timevals = [tunits, tkind, tfmt, tlab] 3622 3623 # Dictionary of plot specificities 3624 specplotkeyn = 'specificvarplot' 3625 plotspecifics = {} 3626 if config.has_key(specplotkeyn): 3627 # [minval]: minimum value 3628 # [maxval]: minimum value 3629 # [colorbar]: name of the colorbar (from matplotlib) to use 3630 # [cntformat]: format of the contour labels 3631 # [colorcnt]: color for the countor lines 3632 plotspecs = config[specplotkeyn].split(':') 3633 for pltspc in plotspecs: 3634 pltvls = pltspc.split('|') 3635 vn = pltvls[0] 3636 op = pltvls[1] 3637 fn = pltvls[2] 3638 plotspecifics[fn + '_' + vn + '_' + op] = pltvls[3:] 3639 if debug: 3640 print 'Specific values for plots _______' 3641 gen.printing_dictionary(plotspecifics) 3642 3643 # Kind of figures 3644 kindfigure = config['kindfig'] 3645 3646 # Map value 3647 mapvalue = config['mapval'] 3648 3649 # pythone scripts HOME 3650 pyHOME = config['pyHOME'] 3651 3652 # Title-text of operations 3653 opexplained = {} 3654 optits = config['titleoperations'].split(':') 3655 for optit in optits: 3656 opn = optit.split('|')[0] 3657 opt = optit.split('|')[1] 3658 opexplained[opn] = opt 3659 if debug: 3660 print 'Titles for operations _______' 3661 gen.printing_dictionary(opexplained) 3662 3663 for kplot in plots.keys(): 3664 varsplt = plots[kplot] 3665 for varplt in varsplt: 3666 if debug: 3667 print " printing '" + kplot + "' var ':" + varplt + "'..." 3668 varops = varplt.split('#') 3669 3670 # CF variables in plot 3671 CFvarsplot = [] 3672 # Files in plot 3673 filesplot = [] 3674 # Variables in plot within the files 3675 varsplot = [] 3676 # Dims in figure 3677 dimsplot = [] 3678 # pictoric values in figure 3679 pictplot = [] 3680 # Name of the figure 3681 figname = '' 3682 # Title of the figure 3683 titfigure = '' 3684 3685 ivp = 0 3686 for varop in varops: 3687 vn = varop.split('|')[0] 3688 op = varop.split('|')[1] 3689 3690 # CF variables in plot 3691 CFvarsplot.append(vn) 3692 3693 vnopS = vn + '_' + op 3694 if not allvarcomp.has_key(vnopS): 3695 print errmsg 3696 print ' ' + fname + ": no file for variable-operation '" + \ 3697 vnopS + "' !!" 3698 vopvals = allvarcomp[vnopS] 3699 headf = vopvals[0] 3700 globalP = vopvals[3] 3701 gP = pinterpS(globalP) 3702 3703 filen = vn + '_' + headf + gP + '_' + op.replace('+','_') + '.nc' 3704 filesplot.append(filen) 3705 # Do we have processed the given variable? 3706 if not os.path.isfile(filen): 3707 print warnmsg 3708 print " " + fname + ": there is no file for variable '" + varop \ 3709 + "' skiping it !!" 3710 break 3711 3712 # Name of the variable inside the file 3713 vnsur = varnoper(vn, op, opersurnames) 3714 varsplot.append(vnsur) 3715 3716 # Dimensions in file 3717 try: 3718 with gen.Capturing() as output: 3719 dims = ncvar.idims(filen) 3720 except: 3721 print errmsg 3722 print 'ncvar.idims('+filen+')' 3723 for s1out in output: print s1out 3724 quit(-1) 3725 3726 dimsplot.append(dims) 3727 3728 # pictoric values for the figure 3729 Sfivaop = kplot + '_' + vn + '_' + op 3730 if plotspecifics.has_key(Sfivaop): 3731 pictvals = plotspecifics[Sfivaop] 3732 else: 3733 Vvals = gen.variables_values(vn) 3734 pictvals = [Vvals[2], Vvals[3], Vvals[6], '%g', 'fixc', 'black'] 3735 3736 pictplot.append(pictvals) 3737 3738 # Header of the name of the figure 3739 if ivp == 0: 3740 figname = kplot +'_'+ vn + '_' + headf + '_' + op.replace('+','-') 3741 else: 3742 figname = figname + '-'+vn+'_'+headf+'_'+op.replace('+','-') 3743 3744 ivp = ivp + 1 3745 # End of variable-operation 3746 figname = figname + '.' + kindfigure 3747 3748 # Title of figure 3749 titfigure = create_figure_title(mod, exp, varops, opexplained) 3750 3751 draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ 3752 figname, titfigure, kindfigure, mapvalue, timevals, odir, pyHOME, \ 3753 figscr, debug) 3754 3755 # End of variables-operations 3756 3757 # End of kind of plots 3758 3759 return 3760 3459 3761 # Files with information about the configuration of the script 3460 3762 inffiles = ['varcompute.inf', 'all_computevars.inf', 'all_statsvars.inf'] … … 3471 3773 # scratches 3472 3774 scratch, filescratch, figscratch, diffscratch, figdiffscratch, moddiffscratch, \ 3473 figmoddiffscratch, addfiles, addfigures, adddiffs, adddifffigures, addmoddiffs, \ 3474 addmoddifffigures, dbg = scratches(cnf) 3775 figmoddiffscratch, figallmodexpscratch, addfiles, addfigures, adddiffs, \ 3776 adddifffigures, addmoddiffs, addmoddifffigures, addallmodexfigures, pdbg = \ 3777 scratches(cnf) 3475 3778 3476 3779 if dbg: … … 3792 4095 ### ## # 3793 4096 # Model differences 3794 ## 4097 ### ## # 3795 4098 3796 4099 # Models already at the reference projection … … 4042 4345 figdiffscratch, dbg) 4043 4346 4044 quit()4045 4046 4347 # end of exp2 loop 4047 4348 # end of exp1 loop … … 4049 4350 # end of mod1 loop 4050 4351 4352 ### ## # 4353 # All model/exps linear plots 4354 ### ## # 4355 4356 allmodexps = [] 4357 for mod in mods: 4358 for exp in modexps[mod]: 4359 allmodexps.append(mod + '/' + exp) 4360 4361 print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' 4362 print ' ** Multi models, multi experiments plots ' 4363 print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' 4364 print ' Model/experiments:', allmodexps 4365 4366 owdir = cnf['ofold'] + '/allmodexps' 4367 sout = sub.call('mkdir -p ' + owdir, shell=True) 4368 4369 # Plotting all model-experiments lines 4370 ## 4371 print " " + main + ": Plotting all model-experiments variable figures ..." 4372 allf = owdir + '/allmodexp.inf' 4373 dirfigf = owdir + '/allmodexpfigures.inf' 4374 allfigf = owdir+'/all_figures.inf' 4375 if allmodexpfigscratch: 4376 sout = sub.call('rm ' + allf + ' >& /dev/null', shell=True) 4377 sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) 4378 4379 objf = open(allfig,'w') 4380 objf.write("## Drawing of all variables figures for all model-experiments\n") 4381 objf.close() 4382 4383 if addallmodexpfigures: 4384 sout = sub.call('rm ' + allf + ' >& /dev/null', shell=True) 4385 sout = sub.call('rm ' + dirfigf + ' >& /dev/null', shell=True) 4386 4387 if not os.path.isfile(dirfigf): 4388 listplots, Nplt = plots_listconstruct(cnf, 'PLOTALLMODEXP', dirfigf, owdir, dbg) 4389 else: 4390 print warnmsg 4391 print ' ' + main + ": getting plots to draw already from file !!" 4392 listplots, Nplt = read_plot_file(dirfigf) 4393 4394 # End of avoiding to repeat all the plots search 4395 4396 print " Is required to plot:", Nplt, " all model-experiment plots" 4397 4398 if dbg: 4399 print ' Plots to draw _______' 4400 gen.printing_dictionary(listplots) 4401 4402 if not os.path.isfile(allf): 4403 # Constructing the information of modexp / variable 4404 allmodexpvar, Nallmodexpvar = allmodexps_listconstruct(config, modexps, , odir, debug) 4405 else: 4406 allmodexpvar, Nallmodexpvar = allmodexps_read(allf) 4407 4408 draw_allmodexp_plots(cnf, listplots, owdir, allmodexpvar, 'diffvar', allmodexpfigscratch, dbg) 4409
Note: See TracChangeset
for help on using the changeset viewer.