Changeset 1085 in lmdz_wrf
- Timestamp:
- Sep 5, 2016, 7:52:06 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified trunk/tools/model_graphics.py ¶
r1082 r1085 290 290 self.model= model 291 291 self.diag= diag 292 293 class ModelInf(object): 294 """ Class which holds all information from a given model 295 name= Acronym of the model 296 model= Long description of the model 297 dim[x/y/z/t/s]n= name of the dimensions of the model 298 vdim[x/y/z/t/s]n= name of the variable-dimensions of the model 299 dimensions= list of the dimensions 300 vardimensions= list of the variable-dimensions 301 """ 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] 292 330 293 331 def variable_compute(idir,var,ftests,db): … … 1575 1613 if db: 1576 1614 print " drawing '" + finame + "' ..." 1615 print ' plot kind:', kplot 1577 1616 print ' CFvars:', CFvplot 1578 1617 print ' files:', fplot … … 1607 1646 lineA = pplot[0] 1608 1647 Arange = str(lineA[0]) + ',' + str(lineA[1]) 1609 Akind = lineA[4] 1610 Aline = lineA[5] 1648 # Values are changed from specific values in `model_graphics.dat' 1649 if lineA[3].find('%') == -1: 1650 Aline = lineA[2] 1651 Akind = lineA[3] 1652 Amark = lineA[4] 1653 Asize = lineA[5] 1654 else: 1655 Aline = 'red' 1656 Akind = '-' 1657 Amark = ',' 1658 Asize = 2. 1611 1659 1612 1660 lineB = pplot[0] 1613 1661 Brange = str(lineB[0]) + ',' + str(lineB[1]) 1614 Bkind = lineB[4] 1615 Bline = lineB[5] 1662 # Values are changed from specific values in `model_graphics.dat' 1663 if lineB[3].find('%') == -1: 1664 Bline = lineB[2] 1665 Bkind = lineB[3] 1666 Bmark = lineB[4] 1667 Bsize = lineB[5] 1668 else: 1669 Bline = 'blue' 1670 Bkind = '-' 1671 Bmark = ',' 1672 Bsize = '2.' 1616 1673 1617 1674 # It is assumed that if the space variable is 'lon': is desired a 1618 1675 # (lon, vals) plot if it is 'lat': then (vals, lat) plot 1619 if gen.searchInlist(dplot ,'lon'):1676 if gen.searchInlist(dplot[0],'lon'): 1620 1677 spacedim ='lon' 1621 1678 axisvals = 'y' 1622 1679 figmid = 'longitudinal' 1623 elif gen.searchInlist(dplot ,'lat'):1680 elif gen.searchInlist(dplot[0],'lat'): 1624 1681 spacedim = 'lat' 1625 1682 axisvals = 'x' 1626 1683 figmid = 'meridional' 1627 elif gen.searchInlist(dplot ,'pres'):1684 elif gen.searchInlist(dplot[0],'pres'): 1628 1685 spacedim = 'pres' 1629 1686 axisvals = 'x' … … 1633 1690 print ' ' + fname + ": in '2lines' only ready for: 'lon', 'lat'," + \ 1634 1691 " 'pres' as common dimension !!" 1635 print ' dimensions in plot:', dplot 1692 print ' dimensions in plot:', dplot[0] 1636 1693 quit(-1) 1637 1694 … … 1641 1698 graphvals = spacedim + ':' + Arange + ':' + Brange + ':Extrs:' + \ 1642 1699 axisvals + ':' + ','.join(CFvplot) + ':' + Aline + ',' + Bline + \ 1643 ':2.,2.:' + Akind + ',' + Bkind + ': ,:' + figtit + ':' + spacedim +\1644 ':0:' + finame.replace('.'+kfig, '') + ':' + kfig1700 ':2.,2.:' + Akind + ',' + Bkind + ':2.,2.:,:' + figtit + ':' + \ 1701 spacedim + ':0:' + finame.replace('.'+kfig, '') + ':' + kfig 1645 1702 1646 1703 fvarS = ','.join(vplot) … … 1684 1741 Akind = '-' 1685 1742 Amark = ',' 1686 Asize = 2.1743 Asize = '2.' 1687 1744 1688 1745 lineB = pplot[1] … … 1695 1752 Bsize = lineB[5] 1696 1753 else: 1697 Bline = ' red'1754 Bline = 'blue' 1698 1755 Bkind = '-' 1699 1756 Bmark = ',' 1700 Bsize = 2.1757 Bsize = '2.' 1701 1758 1702 1759 timeaxis = 'x' … … 1714 1771 1715 1772 drwins = 'draw_2lines_time' 1773 plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ 1774 " -S '" + graphvals + "' -v " + fvarS 1775 1776 try: 1777 with gen.Capturing() as output: 1778 sout = sub.call(plotins, shell=True) 1779 except: 1780 print errmsg 1781 print drwins + '(' + graphvals + ',' + figfs + ',' + fvarS + ')' 1782 print sout 1783 for s1out in output: print s1out 1784 quit(-1) 1785 1786 # keeping all figures 1787 trkobjf.write('\n') 1788 trkobjf.write("#" + tfig.replace('!',' ') + '\n') 1789 trkobjf.write(plotins + '\n') 1790 1791 elif kplot == 'Nlines': 1792 figtit = tfig.replace('!','|') 1793 1794 linestdn = CFvplot[0] 1795 figfs = ','.join(fplot) 1796 1797 Nlines = len(fplot) 1798 1799 lablines = [] 1800 for il in range(Nlines): 1801 linev = pplot[il] 1802 # Values are changed from specific values in `model_graphics.dat' 1803 if linev[3].find('%') == -1: 1804 line = linev[2] 1805 kind = linev[3] 1806 mark = linev[4] 1807 size = linev[5] 1808 if il == 0: 1809 vrange = str(linev[0]) + ',' + str(linev[1]) 1810 kinds = kind 1811 lines = line 1812 marks = mark 1813 sizes = str(size) 1814 else: 1815 kinds = kinds + ',' + kind 1816 lines = lines + ',' + line 1817 marks = marks + ',' + mark 1818 sizes = sizes + ',' + str(size) 1819 else: 1820 lines = 'None' 1821 kinds = '-' 1822 marks = ',' 1823 sizes = '2.' 1824 1825 1826 secsf = fplot[il].split('/') 1827 Nsecsf = len(secsf) 1828 lablines.append(secsf[Nsecsf-3] + '/' + secsf[Nsecsf-2]) 1829 1830 # It is assumed that if the space variable is 'lon': is desired a 1831 # (lon, vals) plot if it is 'lat': then (vals, lat) plot 1832 if gen.searchInlist(dplot[0],'lon'): 1833 spacedim ='lon' 1834 axisvals = 'y' 1835 figmid = 'longitudinal' 1836 elif gen.searchInlist(dplot[0],'lat'): 1837 spacedim = 'lat' 1838 axisvals = 'x' 1839 figmid = 'meridional' 1840 elif gen.searchInlist(dplot[0],'pres'): 1841 spacedim = 'pres' 1842 axisvals = 'x' 1843 figmid = 'vertical' 1844 else: 1845 print errmsg 1846 print ' ' + fname + ": in 'Nlines' only ready for: 'lon', 'lat'," + \ 1847 " 'pres' as common dimension !!" 1848 print ' dimensions in plot:', dplot[0] 1849 quit(-1) 1850 1851 figtit = '|'.join(tfig.split('!')[0:2]) + '|' + figmid + '|' + \ 1852 '|'.join(tfig.split('!')[2:]) 1853 leglabels = ','.join(lablines) 1854 1855 graphvals = spacedim + ':' + axisvals + ':' + spacedim + ':' + \ 1856 leglabels + ':' + CFvplot[0] + ':' + figtit + ':0:' + lines + ':' + \ 1857 kinds + ':' + marks +':'+ sizes +':'+ sizes + ':all:' + \ 1858 finame.replace('.'+kfig, '') + ':' + kfig 1859 1860 fvarS = vplot[0] 1861 1862 drwins = 'draw_lines' 1716 1863 plotins = 'python ' + pyH + '/drawing.py -f ' + figfs +' -o ' + drwins + \ 1717 1864 " -S '" + graphvals + "' -v " + fvarS … … 1834 1981 trkobjf.write(plotins + '\n') 1835 1982 1836 elif 'shadcont2Dzsec':1983 elif kplot == 'shadcont2Dzsec': 1837 1984 figtit = tfig.replace('!','|') 1838 1985 shdstdn = CFvplot[0] … … 2403 2550 values = line.replace('\n','').split(' ') 2404 2551 if values[0] == 'differences:': 2405 diffs = gen.stringList_dictKeysVals(values[1]) 2552 if values[1] != 'none': 2553 diffs = gen.stringList_dictKeysVals(values[1]) 2554 else: 2555 diffs = {} 2406 2556 elif values[0] == 'Ndiff:': 2407 2557 Ndiffs = int(values[1]) … … 2476 2626 if not os.path.isfile(difffilen): 2477 2627 if debug: 2478 print " Computing operation difference '" + op + "' of '" + vn +\2628 print " Computing operation difference '" + op + "' of '" + vn + \ 2479 2629 "' for: '" + modexpdiff 2480 2630 print " var in file: '" + vninF + "'" … … 3011 3161 if not os.path.isfile(difffinalfilen): 3012 3162 if debug: 3013 print " Computing variable difference of '" + vn + "' for: '" +\3163 print " Computing variable difference of '" + vn + "' for: '" + \ 3014 3164 modexpdiff + "' and performing operation '" + Sdoops + "'" 3015 3165 print " var in file: '" + vninF + "'" … … 3422 3572 " values from each model" 3423 3573 3574 # Building up resources to compute re-projected statistics 3575 print ' ' + fname + ': computing from the original reprojected file' 3576 ModI = ModelInf(mod, mod, 'lon', 'lat', 'pres', 'time', 'depth', \ 3577 'lon', 'lat', 'pres', 'time', 'depth') 3578 VarI = VariableInf(vn, values[0], values[2], values[3]) 3579 usefs = {values[0]: ofileorig} 3580 3581 compute_statistics(ModI, config, config['ifold'], usefs, \ 3582 config['ofold']+'/'+mod+'/'+exp,VarI,pinterp_var(op), op, fscr, dbg) 3583 3424 3584 if not os.path.isfile(ofile) and doreproj: 3425 3585 if debug and ofile == ofiles[0]: … … 3560 3720 return allplts, Nallmodexp 3561 3721 3562 def read_allmodexp_file(filen):3722 def allmodexps_read(filen): 3563 3723 """ Function to read the file with the information about the all model-experiment plots 3564 3724 filen= file with the information 3565 3725 """ 3566 fname = ' read_allmodexp_file'3726 fname = 'allmodexps_read' 3567 3727 3568 3728 if not os.path.isfile(filen): … … 3607 3767 3608 3768 os.chdir(odir) 3769 3770 # Folder with the processed files 3771 infold = config['ofold'] 3609 3772 3610 3773 # Dictionary with the operations with surnames for the operated variable … … 3699 3862 CFvarsplot.append(vn) 3700 3863 3701 vnopS = vn + '_' + op 3864 if op.find('pinterp') != -1: gP = 'p' 3865 else: gP = '' 3866 3867 vnopS = vn + '_' + op 3702 3868 if not allvarcomp.has_key(vnopS): 3703 3869 print errmsg 3704 print ' ' + fname + ": no file for variable-operation '" + \3870 print ' ' + fname + ": no file for variable-operation '" + \ 3705 3871 vnopS + "' !!" 3706 vopvals = allvarcomp[vnopS] 3707 headf = vopvals[0] 3708 globalP = vopvals[3] 3709 gP = pinterpS(globalP) 3710 3711 filen = vn + '_' + headf + gP + '_' + op.replace('+','_') + '.nc' 3712 filesplot.append(filen) 3713 # Do we have processed the given variable? 3714 if not os.path.isfile(filen): 3715 print warnmsg 3716 print " " + fname + ": there is no file for variable '" + varop \ 3717 + "' skiping it !!" 3718 break 3719 3720 # Name of the variable inside the file 3721 vnsur = varnoper(vn, op, opersurnames) 3722 varsplot.append(vnsur) 3723 3724 # Dimensions in file 3725 try: 3726 with gen.Capturing() as output: 3727 dims = ncvar.idims(filen) 3728 except: 3729 print errmsg 3730 print 'ncvar.idims('+filen+')' 3731 for s1out in output: print s1out 3732 quit(-1) 3733 3734 dimsplot.append(dims) 3735 3736 # pictoric values for the figure 3737 Sfivaop = kplot + '_' + vn + '_' + op 3738 if plotspecifics.has_key(Sfivaop): 3739 pictvals = plotspecifics[Sfivaop] 3740 else: 3741 Vvals = gen.variables_values(vn) 3742 pictvals = [Vvals[2], Vvals[3], Vvals[6], '%g', 'fixc', 'black'] 3743 3744 pictplot.append(pictvals) 3745 3746 # Header of the name of the figure 3747 if ivp == 0: 3748 figname = kplot +'_'+ vn + '_' + headf + '_' + op.replace('+','-') 3749 else: 3750 figname = figname + '-'+vn+'_'+headf+'_'+op.replace('+','-') 3872 modexpvals = allvarcomp[vnopS] 3873 Nmodexps = len(modexpvals) 3874 3875 for imodexp in range(0,Nmodexps,2): 3876 modexp = modexpvals[imodexp] 3877 headf = modexpvals[imodexp+1] 3878 if debug: 3879 print ' ' + fname + " model/experiment: '" + modexp + "'" 3880 3881 filen = infold + '/' + modexp + '/' + vn +'_'+ headf+gP + '_' + \ 3882 op.replace('+','_') + '.nc' 3883 3884 filesplot.append(filen) 3885 # Do we have processed the given variable? 3886 if not os.path.isfile(filen): 3887 print warnmsg 3888 print " " + fname + ": there is no file for variable '" + \ 3889 varop + "' skiping it !!" 3890 break 3891 3892 if imodexp == 0: 3893 # Name of the variable inside the file 3894 vnsur = varnoper(vn, op, opersurnames) 3895 varsplot.append(vnsur) 3896 3897 # Dimensions in file 3898 try: 3899 with gen.Capturing() as output: 3900 dims = ncvar.idims(filen) 3901 except: 3902 print errmsg 3903 print 'ncvar.idims('+filen+')' 3904 for s1out in output: print s1out 3905 quit(-1) 3906 3907 if imodexp == 0: 3908 # Dimensions in plot 3909 dimsplot.append(dims) 3910 3911 # Header of the name of the figure 3912 if ivp == 0: 3913 figname = kplot+'_'+vn+'_'+headf+'_'+ op.replace('+','-') 3914 else: 3915 figname = figname+'-'+vn+'_'+headf+'_'+op.replace('+','-') 3916 3917 # pictoric values for the figure 3918 Sfivaop = kplot + '_' + vn + '_' + op 3919 if plotspecifics.has_key(Sfivaop): 3920 pictvals = plotspecifics[Sfivaop] 3921 else: 3922 Vvals = gen.variables_values(vn) 3923 pictvals = [Vvals[2],Vvals[3],Vvals[6], '%g', 'fixc', 'black'] 3924 3925 pictplot.append(pictvals) 3751 3926 3752 3927 ivp = ivp + 1 … … 3755 3930 3756 3931 # Title of figure 3757 titfigure = create_figure_title(mod, exp, varops,opexplained)3932 titfigure = 'all model-experiments ' + vn + optitle(op,opexplained) 3758 3933 3759 3934 draw_plot(kplot, CFvarsplot, filesplot, varsplot, dimsplot, pictplot, \ … … 3848 4023 # Does input folder exist? 3849 4024 if not os.path.isdir(iwdir): 3850 print errmsg 3851 print " " + main + ": folder '" + iwdir + "' does not exist !!" 3852 quit(-1) 4025 if filescratch*addfiles: 4026 print errmsg 4027 print " " + main + ": folder '" + iwdir + "' does not exist !!" 4028 quit(-1) 4029 else: 4030 print warnmsg 4031 print " " + main + ": folder '" + iwdir + "' does not exist !!" 4032 print " but start of files from scratch 'filescratch':", \ 4033 filescratch, "and there is not the add of any file 'addfiles':", \ 4034 addfiles 4035 print ' so, keep moving' 3853 4036 3854 4037 owdir = cnf['ofold'] + '/' + mod + '/' + exp … … 4274 4457 4275 4458 if dbg: 4276 print ' Differences to compute _______'4459 print ' op differences to compute _______' 4277 4460 gen.printing_dictionary(alldiffop) 4461 print ' var differences to compute _______' 4278 4462 gen.printing_dictionary(alldiffvar) 4279 4463 … … 4414 4598 allmodexpvar, Nallmodexpvar = allmodexps_read(allf) 4415 4599 4416 #draw_allmodexp_plots(cnf, listplots, owdir, allmodexpvar, 'diffvar', figallmodexpscratch, dbg) 4417 4600 draw_allmodexp_plots(cnf, allmodexpvar, listplots, modexps, owdir, figallmodexpscratch, dbg) 4601 4602 print main + ': all files and figures have been properly done !!'
Note: See TracChangeset
for help on using the changeset viewer.