Changeset 920 for trunk/UTIL/PYTHON/planetoplot_v2
- Timestamp:
- Mar 29, 2013, 5:55:09 PM (12 years ago)
- Location:
- trunk/UTIL/PYTHON/planetoplot_v2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/planetoplot_v2/README.TXT
r910 r920 7 7 Contents 8 8 -------- 9 -------- 9 10 core 10 11 ---- … … 14 15 scripts 15 16 ------- 16 - pp.py --> command line utility to use ppclass 17 - pp.py --> command line utility to use ppclass [HELP with 'pp.py -h'] 17 18 - pp_reload.py --> command line utility to load saved plot objects *.ppobj 18 19 - example/* --> example scripts using ppclass … … 33 34 Requirements 34 35 ------------ 36 ------------ 35 37 python + numpy + matplotlib + netCDF4 36 38 - for mapping --> Basemap … … 40 42 Installation 41 43 ------------ 44 ------------ 42 45 - install required softwares and librairies in requirements 43 46 - add planetoplot_v2 in your PYTHONPATH environment variable (and in your PATH to use pp.py) … … 45 48 Take a demo tour 46 49 ---------------- 50 ---------------- 47 51 pp_reload.py demo_data/* 48 52 49 53 Improvements compared to v1 54 --------------------------- 50 55 --------------------------- 51 56 * code readability and structuration for future improvements … … 75 80 Acknowledgements 76 81 ---------------- 82 ---------------- 77 83 Thanks to A. Colaitis, T. Navarro, J. Leconte 78 84 for feedbacks and contributions on version 1 -
trunk/UTIL/PYTHON/planetoplot_v2/pp.py
r916 r920 20 20 ##################################### 21 21 parser = OptionParser() 22 parser.add_option('--verbose',action='store_true',dest='verbose',default=False,help=' ')22 parser.add_option('--verbose',action='store_true',dest='verbose',default=False,help='make the program verbose') 23 23 # field --> lower case 24 parser.add_option('-f','--file',action='append',dest='file',type="string",default=None,help='') 25 parser.add_option('-v','--var',action='append',dest='var',type="string",default=None,help='') 26 parser.add_option('-x','--lon',action='append',dest='x',type="string",default=None,help='') 27 parser.add_option('-y','--lat',action='append',dest='y',type="string",default=None,help='') 28 parser.add_option('-z','--vert',action='append',dest='z',type="string",default=None,help='') 29 parser.add_option('-t','--time',action='append',dest='t',type="string",default=None,help='') 30 parser.add_option('-c','--contour',action='store',dest='contour',type="string",default=None,help='') 31 parser.add_option('-i','--vecx',action='store',dest='vecx',type="string",default=None,help='') 32 parser.add_option('-j','--vecy',action='store',dest='vecy',type="string",default=None,help='') 33 parser.add_option('-m','--mult',action='store',dest='mult',type="float",default=None,help='') 34 parser.add_option('-a','--add',action='store',dest='add',type="float",default=None,help='') 35 parser.add_option('-o','--output',action='store',dest='filename',type="string",default="myplot",help='') 36 parser.add_option('-d','--directory',action='store',dest='folder',type="string",default="./",help='') 24 parser.add_option('-f','--file',action='append',dest='file',type="string",default=None,help="[NEEDED] 'file' or ['file1','file2',etc]") 25 parser.add_option('-v','--var',action='append',dest='var',type="string",default=None,help="'variable' or ['var1','var2',etc]") 26 parser.add_option('-x','--lon',action='append',dest='x',type="string",default=None,help="x axis value. either one value; or val1,val2 (computations)") 27 parser.add_option('-y','--lat',action='append',dest='y',type="string",default=None,help="y axis value. either one value; or val1,val2 (computations)") 28 parser.add_option('-z','--vert',action='append',dest='z',type="string",default=None,help="z axis value. either one value; or val1,val2 (computations)") 29 parser.add_option('-t','--time',action='append',dest='t',type="string",default=None,help="t axis value. either one value; or val1,val2 (computations)") 30 parser.add_option('-u','--compute',action='store',dest='compute',type="string",default="mean",help="computation: mean, min, max") 31 parser.add_option('-c','--contour',action='store',dest='contour',type="string",default=None,help="one 'variable' for contour") 32 parser.add_option('-i','--vecx',action='store',dest='vecx',type="string",default=None,help="one 'variable' for wind vector x component") 33 parser.add_option('-j','--vecy',action='store',dest='vecy',type="string",default=None,help="one 'variable' for wind vector x component") 34 parser.add_option('-m','--mult',action='store',dest='mult',type="float",default=None,help="multiplicative factor on field") 35 parser.add_option('-a','--add',action='store',dest='add',type="float",default=None,help="additive factor on field") 36 parser.add_option('-o','--output',action='store',dest='filename',type="string",default="myplot",help="name of output files") 37 parser.add_option('-d','--directory',action='store',dest='folder',type="string",default="./",help="directory of output files") 37 38 # plot --> upper case 38 39 # -- generic 39 parser.add_option('-T','--title',action='append',dest='title',type="string",default=None,help= '')40 parser.add_option('-X','--xlabel',action='append',dest='xlabel',type="string",default=None,help= '')41 parser.add_option('-Y','--ylabel',action='append',dest='ylabel',type="string",default=None,help= '')42 parser.add_option('-D','--div',action='store',dest='div',type="int",default=20,help= '')43 parser.add_option('-H','--trans',action='store',dest='trans',type="float",default=1.0,help= '')44 parser.add_option('-Z','--logy',action='store_true',dest='logy',default=False,help= '')45 parser.add_option('-O','--save',action='store',dest='out',type="string",default="gui",help= '')40 parser.add_option('-T','--title',action='append',dest='title',type="string",default=None,help="change 'title'") 41 parser.add_option('-X','--xlabel',action='append',dest='xlabel',type="string",default=None,help="change 'xlabel'") 42 parser.add_option('-Y','--ylabel',action='append',dest='ylabel',type="string",default=None,help="change 'ylabel'") 43 parser.add_option('-D','--div',action='store',dest='div',type="int",default=20,help="integer for number of divisions") 44 parser.add_option('-H','--trans',action='store',dest='trans',type="float",default=1.0,help="float for transparency (0=transp,1=opaque)") 45 parser.add_option('-Z','--logy',action='store_true',dest='logy',default=False,help="set log for vertical axis") 46 parser.add_option('-O','--save',action='store',dest='out',type="string",default="gui",help="save mode: 'gui' 'png' 'pdf' 'eps' 'svg' 'ps'") 46 47 # -- 1D plot 47 parser.add_option('-L','--lstyle',action='append',dest='lstyle',type="string",default=None,help='') 48 parser.add_option('-S','--superpose',action='store_true',dest='superpose',default=False,help='') 48 parser.add_option('-L','--lstyle',action='append',dest='lstyle',type="string",default=None,help="[1D] linestyle: '-' '--' '.' '..'") 49 parser.add_option('-Q','--color',action='append',dest='color',type="string",default=None,help="[1D] color: 'b' 'g' 'r' etc") 50 parser.add_option('-K','--marker',action='append',dest='marker',type="string",default=None,help="[1D] marker: '' 'x' 'o' etc") 51 parser.add_option('-S','--superpose',action='store_true',dest='superpose',default=False,help="[1D] use same axis for all plots") 49 52 # -- 2D plot 50 parser.add_option('-C','--colorb',action='append',dest='colorb',type="string",default=None,help= '')51 parser.add_option('-P','--proj',action='append',dest='proj',type="string",default=None,help= '')52 parser.add_option('-B','--back',action='append',dest='back',type="string",default=None,help=' ')53 parser.add_option('-A','--area',action='append',dest='area',type="string",default=None,help=' ')54 parser.add_option('-I','--blon',action='append',dest='blon',type="float",default=None,help=' ')55 parser.add_option('-J','--blat',action='append',dest='blat',type="float",default=None,help=' ')56 parser.add_option('-N','--vmin',action='append',dest='vmin',type="float",default=None,help=' ')57 parser.add_option('-M','--vmax',action='append',dest='vmax',type="float",default=None,help=' ')53 parser.add_option('-C','--colorb',action='append',dest='colorb',type="string",default=None,help="[2D] colormap: http://micropore.files.wordpress.com/2010/06/colormaps.png") 54 parser.add_option('-P','--proj',action='append',dest='proj',type="string",default=None,help="[2D] map projection: 'cyl' 'npstere' 'spstere' 'ortho' 'moll' 'robin' 'lcc' 'laea' 'merc'") 55 parser.add_option('-B','--back',action='append',dest='back',type="string",default=None,help='[2D] predefined map background (cf. set_back.txt)') 56 parser.add_option('-A','--area',action='append',dest='area',type="string",default=None,help='[2D] predefined region of mapping (cf. set_area.txt)') 57 parser.add_option('-I','--blon',action='append',dest='blon',type="float",default=None,help='[2D] float: bounding longitude for stere (or center longitude for ortho)') 58 parser.add_option('-J','--blat',action='append',dest='blat',type="float",default=None,help='[2D] float: bounding latitude for stere (or center latitude for ortho) ') 59 parser.add_option('-N','--vmin',action='append',dest='vmin',type="float",default=None,help='[2D] float: minimum value for displayed field') 60 parser.add_option('-M','--vmax',action='append',dest='vmax',type="float",default=None,help='[2D] float: maximum value for displayed field') 58 61 (opt,args) = parser.parse_args() 59 62 … … 78 81 if opt.vecy is not None: var.append(opt.vecy) ; vargoal.append("vector") 79 82 # set pp object 80 user = pp(file=opt.file, var=var, vargoal=vargoal, \ 81 x=opt.x, y=opt.y, z=opt.z, t=opt.t,\ 82 verbose=opt.verbose) 83 user = pp() 84 user.file = opt.file 85 user.var = var 86 user.vargoal = vargoal 87 user.x = opt.x 88 user.y = opt.y 89 user.z = opt.z 90 user.t = opt.t 91 user.verbose = opt.verbose 92 user.compute = opt.compute 83 93 # define field 84 94 user.define() … … 105 115 command = "" 106 116 for arg in sys.argv: command = command + arg + ' ' 107 f = open(opt.filename+'.sh', 'w') 108 f.write(command) 117 try: 118 f = open(opt.folder+'/'+opt.filename+'.sh', 'w') 119 f.write(command) 120 except IOError: 121 print "!! WARNING !! pp.py command not saved. Probably do not have permission to write here." -
trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py
r917 r920 172 172 # print status 173 173 def printstatus(self): 174 print "**** Done step: " + self.status 174 if self.filename == "THIS_IS_A_CLONE": 175 pass 176 else: 177 print "**** Done step: " + self.status 175 178 176 179 ##################################################### … … 216 219 setattr(the_clone,k,v) 217 220 the_clone.verbose = False 221 the_clone.filename = "THIS_IS_A_CLONE" # trick to avoid additional outputs 218 222 the_clone.define() 219 223 for i in range(self.nfin): … … 511 515 self.printstatus() 512 516 # check if things were done OK before 513 if self.status != "defined": print "!! ERROR !! Please use .define() to define your pp object." 517 if self.status != "defined": print "!! ERROR !! Please use .define() to define your pp object." ; exit() 514 518 ## first get fields 515 519 ## ... only what is needed is extracted from the files … … 777 781 if (self.n == self.howmanyplots): 778 782 ppplot.save(mode=self.out,filename=self.filename,folder=self.folder,custom=customplot) 783 mpl.close() 779 784 # SAVE A PICKLE FILE WITH THE self.p ARRAY OF OBJECTS 780 785 if self.verbose: print "**** Saving session in "+self.filename + ".ppobj" 781 786 savfile = self.folder + "/" + self.filename + ".ppobj" 782 filehandler = open(savfile, 'w') 783 pickle.dump(self.p, filehandler) 787 try: 788 filehandler = open(savfile, 'w') 789 pickle.dump(self.p, filehandler) 790 except IOError: 791 print "!! WARNING !! Saved object file not written. Probably do not have permission to write here." 784 792 785 793 ########################################################### … … 884 892 except: 885 893 try: self.p[iii].lstyle = opt.lstyle[0] 894 except: pass 895 ### 896 try: self.p[iii].color = opt.color[iii] 897 except: 898 try: self.p[iii].color = opt.color[0] 899 except: pass 900 ### 901 try: self.p[iii].marker = opt.marker[iii] 902 except: 903 try: self.p[iii].marker = opt.marker[0] 886 904 except: pass 887 905 ### -
trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py
r917 r920 202 202 # special case: negative values with stddev while field is positive 203 203 if zevmin < 0. and ppcompute.min(fieldcalc) > 0.: zevmin = 0. 204 # check that bounds are not too tight given the field 205 amin = ppcompute.min(field) 206 amax = ppcompute.max(field) 207 cmin = 100.*np.abs((amin - zevmin)/amin) 208 cmax = 100.*np.abs((amax - zevmax)/amax) 209 if cmin > 150. or cmax > 150.: 210 print "!! WARNING !! Bounds are a bit too tight. Might need to reconsider those." 211 print "!! WARNING !! --> actual",amin,amax,"adopted",zevmin,zevmax 204 212 return zevmin, zevmax 205 213 #### treat vmin = vmax for continuity -
trunk/UTIL/PYTHON/planetoplot_v2/set_var.txt
r911 r920 57 57 ASR ; %.0f ; gist_heat ; Absorbed Solar Radiation (W m$^{-2}$) 58 58 ISR ; %.0f ; gist_heat ; Incoming Solar Radiation (W m$^{-2}$) 59 SWDOWNZ ; %.0f ; gist_heat ; $\Phi^{SW}\downarrow$ (W m$^{-2}$)
Note: See TracChangeset
for help on using the changeset viewer.