Changeset 1325 in lmdz_wrf
- Timestamp:
- Nov 11, 2016, 9:38:47 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/model_graphics.py
r1317 r1325 2934 2934 2935 2935 # Attributes of the variable 2936 varattrs = ncvar.ivattrs(ifile2,vninF) 2936 with gen.Capturing() as output: 2937 varattrs = ncvar.ivattrs(ifile2,vninF) 2938 if debug: 2939 for s1out in output: print s1out 2937 2940 varvals = vninF + ',' + varattrs['long_name'][0] + ',' + \ 2938 2941 varattrs['units'][0] … … 3503 3506 3504 3507 # Attributes of the variable 3505 varattrs = ncvar.ivattrs(ifile2,vninF) 3508 with gen.Capturing() as output: 3509 varattrs = ncvar.ivattrs(ifile2,vninF) 3510 if debug: 3511 for s1out in output: print s1out 3506 3512 varvals = vninF + ',' + varattrs['long_name'][0] + ',' + \ 3507 3513 varattrs['units'][0] … … 3877 3883 objf.close() 3878 3884 else: 3879 print warnmsg 3880 print ' ' + main + ": getting variables to compute already from file !!" 3885 if dbg: 3886 print warnmsg 3887 print ' ' + main + ": getting variables to compute already from file !!" 3881 3888 origfiles, origtestfiles, allcompvar, Nvar = read_varcomp_file(varcompf) 3882 3889 … … 3948 3955 if iif == 1 and len(inNO) > 0: 3949 3956 doreproj = False 3950 print warnmsg 3951 print ' ' + fname + ": operation '" + op + "' can not be " + \ 3952 "reprojected due to the lack of 'lon' or 'lat' skipping it !!" 3953 print " NOTE: difference can only be computed as:" 3954 print " - 1st: compute variable's differences between models" 3955 print " - 2nd: Perform the operations" 3957 if dbg: 3958 print warnmsg 3959 print ' ' + fname + ": operation '" + op + "' can not be " + \ 3960 "reprojected due to the lack of 'lon' or 'lat' skipping it !!" 3961 print " NOTE: difference can only be computed as:" 3962 print " - 1st: compute variable's differences between models" 3963 print " - 2nd: Perform the operations" 3956 3964 3957 3965 # Building up resources to compute re-projected statistics 3958 print ' ' + fname + ': computing from the original reprojected file' 3966 if dbg: 3967 print ' '+fname+': computing from the original reprojected file' 3959 3968 ModI = ModelInf(mod, mod, 'lon', 'lat', 'pres', 'time', 'depth', \ 3960 3969 'lon', 'lat', 'pres', 'time', 'depth', None) … … 4293 4302 print ' ' + fname + ": no file for variable-operation '" + \ 4294 4303 vnopS + "' !!" 4295 modexpvals = allvarcomp[vnopS]4296 #modexpvalsS = allvarcomp[vnopS]4297 #modexpvals = modexpvalsS[0].split('|')4304 # modexpvals = allvarcomp[vnopS] 4305 modexpvalsS = allvarcomp[vnopS] 4306 modexpvals = modexpvalsS[0].split('|') 4298 4307 Nmodexps = len(modexpvals) 4299 4308 … … 4526 4535 allcompvar, Nvar = compvars_listconstruct(cnf, Modinf, files, testfiles, \ 4527 4536 iwdir, owdir, dbg) 4528 else: 4529 print warnmsg 4530 print ' ' + main + ": getting variables to compute already from file !!" 4537 else: 4538 if dbg: 4539 print warnmsg 4540 print ' '+main+": getting variables to compute already from file !!" 4531 4541 files, testfiles, allcompvar, Nvar = read_varcomp_file(varcompf) 4532 4542 … … 4563 4573 listplots, Nplt = plots_listconstruct(cnf, 'DIRPLT', dirfigf, owdir, dbg) 4564 4574 else: 4565 print warnmsg 4566 print ' ' + main + ": getting plots to draw already from file !!" 4575 if dbg: 4576 print warnmsg 4577 print ' ' + main + ": getting plots to draw already from file !!" 4567 4578 listplots, Nplt = read_plot_file(dirfigf) 4568 4579 … … 4636 4647 alldiffop, alldiffvar,Nopdiffs,Nvardiffs=diffvarop_listconstruct(cnf,\ 4637 4648 [mod, mod], [exp1, exp2], [False, False], owdir, dbg) 4638 else: 4639 print warnmsg 4640 print ' ' + main + ": getting 'op' and 'var'differences to " + \ 4641 "compute already from file !!" 4649 else: 4650 if dbg: 4651 print warnmsg 4652 print ' ' + main + ": getting 'op' and 'var'differences to " + \ 4653 "compute already from file !!" 4642 4654 alldiffop, Nopdiffops = read_diff_file(diffvarcompf) 4643 4655 alldiffvar, Nopdiffvars = read_diff_file(owdir+'/'+difffiles[1]) … … 4682 4694 dbg) 4683 4695 else: 4684 print warnmsg 4685 print ' ' + main + ": getting plots to draw already from file !!" 4696 if dbg: 4697 print warnmsg 4698 print ' ' + main + ": getting plots to draw already from file !!" 4686 4699 listplots, Nplt = read_plot_file(dirfigf) 4687 4700 … … 4719 4732 dbg) 4720 4733 else: 4721 print warnmsg 4722 print ' ' + main + ": getting plots to draw already from file !!" 4734 if dbg: 4735 print warnmsg 4736 print ' ' + main + ": getting plots to draw already from file !!" 4723 4737 listplots, Nplt = read_plot_file(dirfigf) 4724 4738 … … 4901 4915 dbg) 4902 4916 else: 4903 print warnmsg 4904 print ' ' + main + ": getting 'op' and 'var' differences to " + \ 4905 "compute already from file !!" 4917 if dbg: 4918 print warnmsg 4919 print ' '+main+": getting 'op' and 'var' differences to " + \ 4920 "compute already from file !!" 4906 4921 alldiffop, Nopdiffops = read_diff_file(diffvarcompf) 4907 4922 alldiffvar, Nopdiffvars = read_diff_file(owdir+'/'+difffiles[1]) … … 4946 4961 owdir, dbg) 4947 4962 else: 4948 print warnmsg 4949 print ' ' + main + ": getting plots to draw already from file !!" 4963 if dbg: 4964 print warnmsg 4965 print ' '+main+": getting plots to draw already from file !!" 4950 4966 listplots, Nplt = read_plot_file(dirfigf) 4951 4967 … … 4983 4999 owdir, dbg) 4984 5000 else: 4985 print warnmsg 4986 print ' ' + main + ": getting plots to draw already from file !!" 5001 if dbg: 5002 print warnmsg 5003 print ' '+main+": getting plots to draw already from file !!" 4987 5004 listplots, Nplt = read_plot_file(dirfigf) 4988 5005 … … 5048 5065 listplots, Nplt = plots_listconstruct(cnf, 'PLOTALLMODEXP', dirfigf, owdir, dbg) 5049 5066 else: 5050 print warnmsg 5051 print ' ' + main + ": getting plots to draw already from file !!" 5067 if dbg: 5068 print warnmsg 5069 print ' ' + main + ": getting plots to draw already from file !!" 5052 5070 listplots, Nplt = read_plot_file(dirfigf) 5053 5071 … … 5069 5087 5070 5088 print main + ': all files and figures have been properly done !!' 5089 5090 # Creation of a pdf with all figures 5091 ## 5092 ### 5093 owdir = cnf['ofold'] 5094 os.chdir(owdir) 5095 5096 texout ='model_graphics-images' 5097 print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' 5098 print ' ** Creation of a pdf with all figures ' 5099 print ' ******* ****** ***** **** *** ** * ** *** **** ***** ****** *******' 5100 print ' ' + owdir + '/' + texout + '.pdf' 5101 5102 if dbg: 5103 print main + ": generation of a pdf file '" + owdir + '/' + texout + \ 5104 "' with all the figures..." 5105 5106 otexf = open(owdir + '/' + texout + '.tex', 'w') 5107 otexf.write('\\documentclass{article}\n') 5108 otexf.write('\\usepackage{graphicx}\n') 5109 otexf.write('\\usepackage[colorlinks=true,urlcolor=blue]{hyperref}\n') 5110 otexf.write('\\textheight=23cm\n') 5111 otexf.write('\\textwidth=18cm\n') 5112 otexf.write('\\oddsidemargin=-1cm\n') 5113 otexf.write('\\evensidemargin=-1cm\n') 5114 otexf.write('\\topmargin=-1cm\n') 5115 5116 otexf.write('\n') 5117 otexf.write('\\begin{document}\n') 5118 otexf.write('\n') 5119 otexf.write('\\def\\fontBloc{\\fontfamily{\\sfdefault}\\large\\bfseries}\n') 5120 otexf.write('\\def\\linia{\\setlength{\\unitlength}{1mm}\n') 5121 otexf.write('\\line(1,0){80}}\n') 5122 otexf.write('\\newcommand{\\modexp}[1]{\\clearpage\n') 5123 otexf.write('\\noindent\\linia\n') 5124 otexf.write('\\section{#1}\n') 5125 otexf.write('\\linia}\n') 5126 otexf.write('\n') 5127 5128 otexf.write('\\title{model\_graphics: ' + gen.latex_text(owdir) + '}\n') 5129 otexf.write('\\maketitle\n') 5130 otexf.write('\n') 5131 otexf.write('\\tableofcontents\n') 5132 otexf.write('\\listoffigures\n') 5133 otexf.write('\\clearpage\n') 5134 5135 Nmods = len(mods) 5136 # Figures from mod/exp pairs 5137 for mod in mods: 5138 exps = modexps[mod] 5139 for exp in exps: 5140 print ' direct plots:', mod, exp 5141 owdirme = owdir + '/' + mod + '/' + exp 5142 otexf.write('% ' + mod + ' ' + exp + '\n') 5143 otexf.write('\\modexp{' + gen.latex_text(mod+' '+exp) + '}\n') 5144 listplots, Nplt = read_plot_file(owdirme + '/directplotsdraw.inf') 5145 for plot in listplots.keys(): 5146 plots = listplots[plot] 5147 ops = [] 5148 for plt in plots: 5149 opn = plt.split('#')[0].split('|')[1] 5150 if not gen.searchInlist(ops,opn): ops.append(opn) 5151 for op in ops: 5152 opS = op.replace('+','_') 5153 modexpimg = gen.files_folder_HMT(owdirme, head=plot, middle=opS, \ 5154 tail=cnf['kindfig']) 5155 Nimages = len(modexpimg) 5156 if Nimages > 0: 5157 for img in range(Nimages): modexpimg[img] = owdirme + '/' + \ 5158 modexpimg[img] 5159 caption = mod + ' ' + exp + ' ' + plot + ' ' + op 5160 flab = 'fig:' + caption.replace(' ', '_') 5161 try: 5162 with gen.Capturing() as output: 5163 gen.latex_fig_array(modexpimg, otexf, \ 5164 gen.latex_text(caption), flab, refsize=0.5, dist='sqr',\ 5165 dorest='center') 5166 except: 5167 print errmsg 5168 print 'gen.latex_fig_array('+modexpimg+', '+otexf+', '+ \ 5169 'gen.latex_text(' + caption + '), ' + flab + \ 5170 ", refsize=0.5, dist='sqr', dorest='center')" 5171 for s1out in output: print s1out 5172 quit(-1) 5173 otexf.write('%\\clearpage\n') 5174 5175 # differences between experiments 5176 Nexps = len(exps) 5177 for iexp1 in range(0,Nexps-1): 5178 exp1 = exps[iexp1] 5179 for iexp2 in range(iexp1+1,Nexps): 5180 exp2 = exps[iexp2] 5181 Sexps = exp2 + '-' + exp1 5182 owdirme = owdir + '/' + mod + '/' + Sexps 5183 print ' diffs:', mod + '/' + Sexps + ' ...' 5184 for diffn in ['op', 'var']: 5185 fileplotinf = owdirme + '/diff' + diffn + 'plotsdraw.inf' 5186 if os.path.isfile(fileplotinf): 5187 otexf.write('% ' + mod + ' ' + Sexps + ' diff' + diffn + '\n') 5188 otexf.write('\\modexp{' + gen.latex_text(mod+' '+Sexps+' diff'+ \ 5189 diffn)+ '}\n') 5190 listplots, Nplt = read_plot_file(fileplotinf) 5191 for plot in listplots.keys(): 5192 plots = listplots[plot] 5193 ops = [] 5194 for plt in plots: 5195 opn = plt.split('#')[0].split('|')[1] 5196 if not gen.searchInlist(ops,opn): ops.append(opn) 5197 for op in ops: 5198 opS = op.replace('+','-') 5199 modexpimg = gen.files_folder_HMT(owdirme, head=plot, \ 5200 middle=opS, tail=cnf['kindfig']) 5201 Nimages = len(modexpimg) 5202 if Nimages > 0: 5203 for img in range(Nimages): modexpimg[img] = owdirme +\ 5204 '/' + modexpimg[img] 5205 caption = mod + ' ' + Sexps + ' ' + plot + ' ' + op +\ 5206 ' diff' + diffn 5207 flab = 'fig:' + caption.replace(' ', '_') 5208 try: 5209 with gen.Capturing() as output: 5210 gen.latex_fig_array(modexpimg, otexf, \ 5211 gen.latex_text(caption), flab, refsize=0.5,\ 5212 dist='sqr', dorest='center') 5213 except: 5214 print errmsg 5215 print 'gen.latex_fig_array('+modexpimg+', '+ \ 5216 otexf+', gen.latex_text(' + caption + '), ' + \ 5217 flab + ", refsize=0.5, dist='sqr', " + \ 5218 "dorest='center')" 5219 for s1out in output: print s1out 5220 quit(-1) 5221 5222 otexf.write('%\\clearpage\n') 5223 print ' mods-exps diffs ...' 5224 for imod1 in range(0,Nmods-1): 5225 mod1 = mods[imod1] 5226 exps1 = modexps[mod1] 5227 for imod2 in range(imod1+1,Nmods): 5228 mod2 = mods[imod2] 5229 exps2 = modexps[mod2] 5230 5231 Smods = mod2 + '-' + mod1 5232 Nexps1 = len(exps1) 5233 Nexps2 = len(exps2) 5234 for iexp1 in range(0,Nexps1): 5235 exp1 = exps1[iexp1] 5236 for iexp2 in range(0,Nexps2): 5237 exp2 = exps2[iexp2] 5238 Sexps = exp2 + '-' + exp1 5239 print ' ' + Smods + ' ' + Sexps + ' ...' 5240 owdirme = owdir + '/' + Smods + '/' + Sexps 5241 for diffn in ['op', 'var']: 5242 fileplotinf = owdirme + '/diff' + diffn + 'plotsdraw.inf' 5243 if os.path.isfile(fileplotinf): 5244 otexf.write('% '+Smods + ' ' + Sexps + ' diff'+diffn+'\n') 5245 otexf.write('\\modexp{' + gen.latex_text(Smods+' '+Sexps+\ 5246 ' diff'+diffn) + '}\n') 5247 listplots, Nplt = read_plot_file(fileplotinf) 5248 for plot in listplots.keys(): 5249 plots = listplots[plot] 5250 ops = [] 5251 for plt in plots: 5252 opn = plt.split('#')[0].split('|')[1] 5253 if not gen.searchInlist(ops,opn): ops.append(opn) 5254 for op in ops: 5255 opS = op.replace('+','-') 5256 modexpimg = gen.files_folder_HMT(owdirme, \ 5257 head=plot, middle=opS, tail=cnf['kindfig']) 5258 Nimages = len(modexpimg) 5259 if Nimages > 0: 5260 for img in range(Nimages): modexpimg[img] = \ 5261 owdirme + '/' + modexpimg[img] 5262 caption = Smods + ' ' + Sexps + ' ' + plot + \ 5263 ' ' + op + ' diff' + diffn 5264 flab = 'fig:' + caption.replace(' ', '_') 5265 try: 5266 with gen.Capturing() as output: 5267 gen.latex_fig_array(modexpimg, otexf,\ 5268 gen.latex_text(caption), flab, \ 5269 refsize=0.5, dist='sqr', \ 5270 dorest='center') 5271 except: 5272 print errmsg 5273 print 'gen.latex_fig_array('+modexpimg+ \ 5274 ', '+otexf+', gen.latex_text(' + \ 5275 caption + '), '+flab+ ", refsize=0.5,"+\ 5276 " dist='sqr', dorest='center')" 5277 for s1out in output: print s1out 5278 quit(-1) 5279 otexf.write('%\\clearpage\n') 5280 5281 # allmodexp 5282 owdirme = owdir + '/allmodexps' 5283 print ' allmodexps...' 5284 fileplotinf = owdirme + '/allmodexpfigures.inf' 5285 if os.path.isfile(fileplotinf): 5286 otexf.write('% allmodexps\n') 5287 otexf.write('\\modexp{allmodexps}\n') 5288 listplots, Nplt = read_plot_file(fileplotinf) 5289 for plot in listplots.keys(): 5290 plots = listplots[plot] 5291 ops = [] 5292 for plt in plots: 5293 opn = plt.split('|')[1] 5294 if not gen.searchInlist(ops,opn): ops.append(opn) 5295 for op in ops: 5296 opS = op.replace('+','-') 5297 modexpimg = gen.files_folder_HMT(owdirme, head=plot, middle=opS, \ 5298 tail=cnf['kindfig']) 5299 Nimages = len(modexpimg) 5300 if Nimages > 0: 5301 for img in range(Nimages): modexpimg[img] = owdirme + '/' + \ 5302 modexpimg[img] 5303 caption = 'allmodexps ' + plot + ' ' + op + ' diff' + diffn 5304 flab = 'fig:' + caption.replace(' ', '_') 5305 try: 5306 with gen.Capturing() as output: 5307 gen.latex_fig_array(modexpimg,otexf, gen.latex_text(caption),\ 5308 flab, refsize=0.5, dist='sqr', dorest='center') 5309 except: 5310 print errmsg 5311 print 'gen.latex_fig_array('+modexpimg+', '+otexf+ \ 5312 ', gen.latex_text(' + caption + '), ' +flab+ ", refsize=0.5," +\ 5313 " dist='sqr', dorest='center')" 5314 for s1out in output: print s1out 5315 quit(-1) 5316 5317 otexf.write('%\\clearpage\n') 5318 5319 otexf.write('\\end{document}\n') 5320 otexf.close() 5321 5322 try: 5323 with gen.Capturing() as output: 5324 ins = 'pdflatex ' + owdir + '/' + texout 5325 sout = sub.call(ins, shell=True) 5326 except: 5327 print errormsg 5328 print ' ' + ins 5329 print sout 5330 for s1out in output: print s1out 5331 quit(-1) 5332 5333 with gen.Capturing() as output: 5334 sout = sub.call(ins + '>& /dev/null', shell=True) 5335 with gen.Capturing() as output: 5336 sout = sub.call(ins + '>& /dev/null', shell=True) 5337 with gen.Capturing() as output: 5338 sout = sub.call(ins + '>& /dev/null', shell=True) 5339 with gen.Capturing() as output: 5340 sout = sub.call(ins, shell=True) 5341 if dbg: 5342 print sout 5343 for s1out in output: print s1out 5344 5345 sub.call('evince ' + owdir + '/' + texout + '.pdf &', shell=True) 5346
Note: See TracChangeset
for help on using the changeset viewer.