Changeset 1015 in lmdz_wrf
- Timestamp:
- Aug 12, 2016, 6:55:25 PM (8 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/model_graphics.py
r1011 r1015 342 342 for line in objf: 343 343 vals = line.split(' ') 344 if vals[0] == 'files ':345 Files = stringList_dictKeysVals(vals[1])346 elif vals[0] == 'testfiles ':347 TestFiles = stringList_dictKeysVals(vals[1])348 elif vals[0] == 'varcompute ':344 if vals[0] == 'files:': 345 Files = gen.stringList_dictKeysVals(vals[1]) 346 elif vals[0] == 'testfiles:': 347 TestFiles = gen.stringList_dictKeysVals(vals[1]) 348 elif vals[0] == 'varcompute:': 349 349 Vvals = vals[1].split('|') 350 350 if Vvals[3] == 'None': … … 358 358 359 359 allvarcomp[Vvals[0]+'_'+Vvals[1]] = [Vvals[2], mod, diag, Vvals[5]] 360 elif vals[0] == 'itotv ':360 elif vals[0] == 'itotv:': 361 361 ivop = int(vals[1]) 362 362 … … 420 420 fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '.nc' 421 421 422 if db:423 print ' ' + fname + ": creation of variable file '" + ifilen + "' ..."424 425 422 if scr: 426 423 sout = sub.call('rm ' + ifilen + ' >& /dev/null', shell=True) … … 432 429 # bars, if a variable has a diagnostic way to be computed, the later one will be 433 430 # preferred 431 if db: 432 print ' ' + fname + ": creation of variable file '" + CFvarn + \ 433 "' in file '" + ifilen + "' ..." 434 434 435 435 if modvar is not None and diagvar is None: … … 441 441 442 442 newfile, loc = gen.search_sec_list(output,'succesfull') 443 print fname, 'Lluis newfile', newfile444 443 ofile = newfile[0].split(' ')[7] 445 444 sub.call('mv ' + ofile + ' ' + ifilen, shell=True) … … 461 460 diagc = '@'.join(diagvar[1:]) 462 461 463 values = '-f ' + cf + ' -d ' + dims + " -v '" + diagn + '|' +diagc+"'" 462 values = '-f ' + cf + " -d '" + dims + "' -v '" + diagn + '|' + \ 463 diagc + "'" 464 464 sout = sub.call('python ' + pyH + '/diagnostics.py ' + values, \ 465 465 shell=True) … … 472 472 otrackf.write(pyins + '\n') 473 473 474 # adding CF lon,lat,time in WRF files 475 if minf.name == 'WRF': 476 values = vdnx + ':' + vdny + ':'+ Tref + ':' + Tunits 477 ncvar.WRF_toCF(values, ifilen) 478 479 # Attaching necessary variables for the pressure interpolation 480 if gP != 'none': 481 requiredinterpvars = ['P', 'PB', 'PSFC', 'PH', 'PHB', 'HGT', 'T','QVAPOR'] 482 print " " + ": adding variables:", requiredinterpvars, ' to allow ' + \ 483 'pressure interpolation' 484 for rqv in requiredinterpvars: 485 ncvar.fvaradd(cf+','+rqv,ifilen) 474 # Attaching necessary variables for the pressure interpolation 475 if gP != 'none': 476 requiredinterpvars = ['P', 'PB', 'PSFC', 'PH', 'PHB', 'HGT', 'T', \ 477 'QVAPOR', 'XLONG', 'XLAT', 'Times'] 478 print " " + fname + ": adding variables:", requiredinterpvars, \ 479 ' to allow pressure interpolation' 480 for rqv in requiredinterpvars: 481 ncvar.fvaradd(idir+'/'+cf+','+rqv,ifilen) 482 483 # adding CF lon,lat,time in WRF files 484 if minf.name == 'WRF': 485 values = vdnx + ':' + vdny + ':'+ Tref + ':' + Tunits 486 ncvar.WRF_toCF(values, ifilen) 486 487 487 488 ifile = ifile + 1 … … 502 503 return 503 504 504 def compute_statistics(minf, idir, usefiles, odir, cvar, plevels, gP, Opers, scr, \ 505 pyH, db): 505 def compute_statistics(minf, config, idir, usefiles, odir, cvar, gP, Opers, scr, db): 506 506 """ Function to compute different statistics it will take previous steps if they 507 507 are availale 508 508 minf= class with the information of the model 509 config= dictionary with the configuration of the experiment 509 510 idir= directory with the input files 510 511 usefiles= ',' list of files to use [file1],...,[fileN] 511 512 odir= directory to write the output files 512 513 cvar= class with the information of the variable: 'name', 'fheader', 'varmod', 'vardiag' 513 plevels= ':' separated list of pressures (in Pa) to use for the vertical interpolation514 514 gP= kind of vertical interpolation ('global', 'local', 'none') 515 515 Opers= kind of operation: (as possible multiple consecutive combination of operations separated by '+' … … 530 530 zsum: vertical aggregated values 531 531 scr= should it be done from the scratch? 532 pyH= location of the python HOME533 532 """ 534 533 fname='compute_statistics' … … 549 548 vdny = minf.vardyn 550 549 551 # For that variables which require vertical interpolation 'p' suffix to the 552 # file header is added 550 # Some experiment configuration values 551 # plevels= ':' separated list of pressures (in Pa) to use for the vertical interpolation 552 plevels = config['plevels'] 553 # pyH= location of the python HOME 554 pyH = config['pyHOME'] 555 # Tref= CF time reference 556 Tref = config['CFreftime'] 557 # Tunits= CF time units 558 Tunits = config['CFunitstime'] 559 # opsur = operation surnames 560 opsur = gen.get_specdictionary_HMT(config, H='opsur_',M='',T='') 561 Opsurs = {} 562 for opk in opsur: 563 opn = opk.split('_')[1] 564 vals = opsur[opk] 565 Opsurs[opn] = vals.split(':') 566 if db: 567 print ' ' + fname + ' operation surnames _______' 568 gen.printing_dictionary(Opsurs) 569 570 # Getting in working dir 571 os.chdir(odir) 572 573 # File to keep track of all operations 574 otrackf = open( odir + '/all_statsvars.inf', 'a') 575 576 # For that variables which require vertical interpolation 'p' suffix to the file 577 # header is added 553 578 if gP != 'none': 554 579 SgP = 'p' 555 if gP == 'local': 556 CFvarnp = CFvarn + ',P,PB,PSFC,PH,PHB,HGT,T,QVAPOR,XLONG,XLAT,Times' 557 else: 558 CFvarnp = CFvarn 580 varnCFs = ['lon', 'lat', 'pres', 'time'] 559 581 else: 560 582 SgP = '' 561 CFvarnp = CFvarn 562 563 # Getting in working dir 564 os.chdir(odir) 565 566 # File to keep track of all operations 567 otrackf = open( odir + '/all_statsvars.inf', 'a') 583 varnCFs = ['lon', 'lat', 'time'] 584 585 # Mandatory CF variables to be in all files 586 SvarnCFs = ',' + ','.join(varnCFs) 568 587 569 588 # Input file … … 578 597 # Variables to be kept in the final file 579 598 varkeep = [] 580 581 # Mandatory CF variables to be in all files582 varnCFs = ['lon', 'lat', 'pres', 'time']583 599 584 600 opers = Opers.split('+') … … 586 602 if db: print ' computing statistics of variable:', CFvarn, ' ...' 587 603 for op in opers: 604 605 # File name from previous operations 588 606 if op == opers[0]: 589 607 Fopers = op 590 608 prevfile = ifilen 609 vninF = CFvarn 591 610 else: 592 611 Fopers = Fopers + '_' + op 593 612 prevfile = fileon 594 613 fileon = odir + '/' + CFvarn + '_' + headerf + SgP + '_' + Fopers + '.nc' 614 615 # Adding required variables for the vertical interpolation in all operations 616 if gP != 'none': 617 if gP == 'local': 618 CFvarnp = vninF + ',P,PB,PSFC,PH,PHB,HGT,T,QVAPOR,XLONG,XLAT,Times' + SvarnCFs 619 else: 620 CFvarnp = vninF + SvarnCFs 621 else: 622 CFvarnp = vninF + SvarnCFs 595 623 596 624 if scr: … … 647 675 # pinterp: pressure interpolation (to the given $plevels) 648 676 vals=plevels + ',1,1' 649 ncvar.pinterp(vals,prevfile, CFvarnp)650 sout = sub. vall('mv pinterp.nc ' + fileon, shell=True)677 ncvar.pinterp(vals,prevfile,vninF) 678 sout = sub.call('mv pinterp.nc ' + fileon, shell=True) 651 679 652 680 # Keeping the operations 653 681 pyins=pyH + "/nc_var.py -o pinterp -S '" + vals + "' -f " + \ 654 prevfile + "-v " + CFvarnp682 prevfile + "-v " + vninF 655 683 otrackf.write("\n") 656 684 otrackf.write("# " + CFvarn + " " + Fopers + "\n") … … 663 691 664 692 # vertical interpolation variables are no more needed 665 CFvarnp = CFvarn 693 CFvarnp = vninF 694 gP = 'none' 666 695 667 696 elif op == 'tmean': … … 679 708 otrackf.write(pyins + "\n") 680 709 681 varkeep.append(CFvarn + 'mean') 710 # lon, lat CF-variables do not have time, thus they are not kept in 711 # output 712 for rqv in varnCFs: 713 if rqv != 'time': 714 ncvar.fvaradd(prevfile+','+rqv,fileon) 682 715 varkeep.append('timestats') 683 716 … … 711 744 otrackf.write(pyins + "\n") 712 745 713 varkeep.append(CFvarn + 'mean') 746 # time CF-variable do not have 'x', thus they are not kept in 747 # output 748 rqv = 'time' 749 ncvar.fvaradd(prevfile+','+rqv,fileon) 714 750 varkeep.append('lonstats') 715 751 … … 728 764 otrackf.write(pyins + "\n") 729 765 730 varkeep.append(CFvarn + 'mean') 766 # time CF-variable do not have 'y', thus they are not kept in 767 # output 768 rqv = 'time' 769 ncvar.fvaradd(prevfile+','+rqv,fileon) 731 770 varkeep.append('latstats') 732 771 elif op == 'zsum': 733 772 # vertical aggregated values 734 773 print " " + fname + ": kind '" + op + "' not ready !!" 735 wrongstats.appen (CFvarn + '_' + opers)774 wrongstats.append(CFvarn + '_' + opers) 736 775 break 737 776 else: … … 741 780 742 781 # End of kind of operation 782 783 # Variable name in file (vninF) changed due to operation 784 # but only if previous operation does not the same 'statistic' 785 chvn = gen.dictionary_key_list(Opsurs, op) 786 if chvn is not None: 787 oldvninF = vninF 788 if vninF.find(chvn) != -1: 789 Lchvn = len(chvn) 790 LvninF = len(vninF) 791 if vninF[LvninF-Lchvn:LvninF-Lchvn+1] != chvn: 792 vninF = vninF + chvn 793 else: 794 vninF = vninF + chvn 795 CFvarnp = CFvarnp.replace(oldvninF,vninF) 796 743 797 if len(varkeep) > 0: 744 798 varkeepS = ',' + ','.join(varkeep) … … 789 843 790 844 # Compute variable statistics 791 compute_statistics(modinf, iwdir, Files, owdir, vinf, config['plevels'],\792 globalP, op, fscr, config['pyHOME'], debug)845 compute_statistics(modinf, cnf, iwdir, Files, owdir, vinf, globalP, op, \ 846 fscr, debug) 793 847 794 848 else: … … 911 965 print ' ' + main + ": getting variables to compute already from file !!" 912 966 files, testfiles, allcompvar, Nvar = read_varcomp_file(owdir + \ 913 '/varcompute.inf') 967 '/varcompute.inf') 914 968 # End of avoiding to repeat all the experiment search 915 969 -
trunk/tools/model_graphics_template.dat
r1011 r1015 27 27 28 28 # Scratch figures: should be any figures previous work removed and start from the scratch? 29 figscratch = false29 figscratch = true 30 30 31 31 # Have new files been added and do they need to be processed? … … 91 91 # will compute first [calc1] and then [calc2] for 'tas' and 'wss' 92 92 VAR_last = tas:uas:vas:hfss:hfls:wss 93 VAR_ mean = tas:uas:vas:hfss:hfls:wss93 VAR_tmean = tas:uas:vas:hfss:hfls:wss 94 94 VAR_xmean = tas:uas:vas:hfss:hfls:wss 95 VAR_last+pinterp+xmean = ta:ua:va:hur:hus:turb95 #VAR_last+pinterp+xmean = ta:ua:va:hur:hus:turb 96 96 VAR_pinterp+tmean+xmean = ta:ua:va:hur:hus:turb 97 97 … … 104 104 vardiff = tas|last:tas|xmean:tas|tmean:wss|last:wss|xmean:wss|tmean:ua|pinterp@last@xmean:va|pinterp@last@xmean 105 105 106 # Operations which attach 'mean' at the end of the variable name 107 varmeanname=Lmean:lmean:tmean:xmean:ymean 106 # Operations which attach a 'surname' at the end of the variable name 107 # Values are given as opsur_[surname] = [operation1]:[operation2][:...[operationN]] 108 # opsur_mean = tmean:xmean 109 # once 'tmean', or 'xmean' are computed, variable [varn] will become [varn]mean 110 # NOTE: surnames are attaced only once 111 opsur_mean = Lmean:lmean:tmean:xmean:ymean 108 112 109 113 # Pressure levels
Note: See TracChangeset
for help on using the changeset viewer.