Changeset 1990 in lmdz_wrf for trunk/tools/generic_tools.py
- Timestamp:
- Jul 31, 2018, 2:14:19 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1985 r1990 75 75 # color_deg: Function to generate a degradation of colors in rgb base 76 76 # contflow: Function to bring back the increment in j,i grid points according to a trip: (inflow directions) 77 # create_LateX_figs: Function to create a LaTeX from a folder with multiple plots from different values 77 78 # crossingpoint_2Dlines: Function to determinant the crossing point between two lines in a plane 78 79 # curvelocalize_2D: Function to provide the localization a curve in a 2D field of positions via the equivalent … … 13424 13425 #ASCIIfile_stats('times_NOCDXWRF2.dat') 13425 13426 13427 def create_LateX_figs(folder, plots, values, kfig): 13428 """ Function to create a LaTeX from a folder with multiple plots from different 13429 values 13430 plots: list of names of plots 13431 values: list of values for each plot to guess sort of plots 13432 kfig: kind of figure 13433 """ 13434 fname = 'create_LaTeX_figs' 13435 13436 texfn = 'LaTeX_figs.tex' 13437 13438 otex = open(texfn, 'w') 13439 otex.write('\\documentclass{article}\n') 13440 otex.write('\\usepackage{graphicx}\n') 13441 otex.write('\n') 13442 otex.write('\\textheight=23cm\n') 13443 otex.write('\\textwidth=18cm\n') 13444 otex.write('\\oddsidemargin=-1cm\n') 13445 otex.write('\\evensidemargin=-1cm\n') 13446 otex.write('\\topmargin=-1cm\n') 13447 13448 otex.write('\n') 13449 otex.write('\\begin{document}\n') 13450 13451 for plotn in plots: 13452 print plotn + ' ...' 13453 figs = files_folder_HMT(folder, head='', middle=plotn, tail=kfig) 13454 unsortfigs = figs + [] 13455 Nfigs = len(figs) 13456 # grouping figures 13457 for valn in values: 13458 print ' ' + valn + ' ...' 13459 valfigs = [] 13460 for fign in figs: 13461 if fign.find(valn) != -1: 13462 valfigs.append(fign) 13463 unsortfigs.remove(fign) 13464 13465 Nvalfig = len(valfigs) 13466 if Nvalfig > 0: 13467 Ncol = int(np.sqrt(Nvalfig)) 13468 cs = Ntchar('c', Ncol) 13469 frcwth = 0.9/Ncol 13470 13471 otex.write('\\begin{figure}\n') 13472 otex.write('\\begin{center}\n') 13473 13474 otex.write('\\begin{tabular}{' + cs + '}\n') 13475 13476 ifig = 1 13477 for valfn in valfigs: 13478 if ifig != 0 and np.mod(ifig,Ncol) == 0: endchar = ' \\\\\n' 13479 else: endchar = ' &\n' 13480 13481 otex.write('\\includegraphics[width=' + str(frcwth) + \ 13482 '\\textwidth]{' + valfigs[ifig-1] + '}' + endchar + '\n') 13483 ifig = ifig + 1 13484 13485 print 'Lluis ifig:', ifig-1, 'Ncol:', Ncol, 'mod:', np.mod(ifig-1,Ncol) 13486 if Nvalfig - ifig + 1 != 0: 13487 endrow = Ntchar(' & ', Nvalfig - ifig + 1) 13488 otex.write(endrow + '\n') 13489 otex.write('\\end{tabular}\n') 13490 otex.write('\\end{center}\n') 13491 otex.write('\\end{figure}\n') 13492 13493 if len(unsortfigs) != 0: 13494 Nunsortfig = len(unsortfigs) 13495 Ncol = int(np.sqrt(Nunsortfig)) 13496 cs = Ntchar('c', Ncol) 13497 frcwth = 0.9/Ncol 13498 13499 otex.write('\\begin{figure}\n') 13500 otex.write('\\begin{center}\n') 13501 13502 otex.write('\\begin{tabular}{' + cs + '}\n') 13503 13504 ifig = 1 13505 for valfn in unsortfigs: 13506 if ifig != 0 and np.mod(ifig,Ncol) == 0: endchar = ' \\\\\n' 13507 else: endchar = ' &\n' 13508 13509 otex.write('\\includegraphics[width=' + str(frcwth) + \ 13510 '\\textwidth]{' + valfigs[ifig-1] + '}' + endchar + '\n') 13511 ifig = ifig + 1 13512 13513 if np.mod(ifig-1,Ncol) != 0: 13514 endrow = Ntchar(' & ', np.mod(ifig-1,Ncol)) 13515 otex.write(endrow + '\n') 13516 otex.write('\\end{tabular}\n') 13517 otex.write('\\end{center}\n') 13518 otex.write('\\end{figure}\n') 13519 otex.write('\n') 13520 otex.write('\\clearpage\n') 13521 13522 otex.write('\\end{document}\n') 13523 13524 otex.close() 13525 print fname + ": LaTeX file '" + texfn + "' succesfully written !!" 13526 13527 sub.process('pdflatex ' + texfn.split('.')[0], shell=True) 13528 sub.process('pdflatex ' + texfn.split('.')[0], shell=True) 13529 sub.process('pdflatex ' + texfn.split('.')[0], shell=True) 13530 13531 return 13532 13533 #pltns = ['WindRose_', 'SkewT-logP_obs-sim_', 'SkewT-logP_'] 13534 #sts = ['10868', '16080', '16144', '16546'] 13535 #create_LateX_figs('/home/lluis/estudios/FPS_ALPS/additional/IOP/analysis/figs', pltns, sts, 'png') 13536 13426 13537 #quit() 13427 13538
Note: See TracChangeset
for help on using the changeset viewer.