Ignore:
Timestamp:
Mar 29, 2013, 5:55:09 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. Added options to pp.py. Added help to pp.py. Set warnings in case files cannot be written. Set warnings for bounds too tight. Corrected one possible bug when several plots in a row.

Location:
trunk/UTIL/PYTHON/planetoplot_v2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot_v2/README.TXT

    r910 r920  
    77Contents
    88--------
     9--------
    910core
    1011----
     
    1415scripts
    1516-------
    16 - pp.py --> command line utility to use ppclass
     17- pp.py --> command line utility to use ppclass [HELP with 'pp.py -h']
    1718- pp_reload.py --> command line utility to load saved plot objects *.ppobj
    1819- example/* --> example scripts using ppclass
     
    3334Requirements
    3435------------
     36------------
    3537python + numpy + matplotlib + netCDF4
    3638- for mapping --> Basemap
     
    4042Installation
    4143------------
     44------------
    4245- install required softwares and librairies in requirements
    4346- add planetoplot_v2 in your PYTHONPATH environment variable (and in your PATH to use pp.py)
     
    4548Take a demo tour
    4649----------------
     50----------------
    4751pp_reload.py demo_data/*
    4852
    4953Improvements compared to v1
     54---------------------------
    5055---------------------------
    5156* code readability and structuration for future improvements
     
    7580Acknowledgements
    7681----------------
     82----------------
    7783Thanks to A. Colaitis, T. Navarro, J. Leconte
    7884for feedbacks and contributions on version 1
  • trunk/UTIL/PYTHON/planetoplot_v2/pp.py

    r916 r920  
    2020#####################################
    2121parser = OptionParser()
    22 parser.add_option('--verbose',action='store_true',dest='verbose',default=False,help='')
     22parser.add_option('--verbose',action='store_true',dest='verbose',default=False,help='make the program verbose')
    2323# 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='')
     24parser.add_option('-f','--file',action='append',dest='file',type="string",default=None,help="[NEEDED] 'file' or ['file1','file2',etc]")
     25parser.add_option('-v','--var',action='append',dest='var',type="string",default=None,help="'variable' or ['var1','var2',etc]")
     26parser.add_option('-x','--lon',action='append',dest='x',type="string",default=None,help="x axis value. either one value; or val1,val2 (computations)")
     27parser.add_option('-y','--lat',action='append',dest='y',type="string",default=None,help="y axis value. either one value; or val1,val2 (computations)")
     28parser.add_option('-z','--vert',action='append',dest='z',type="string",default=None,help="z axis value. either one value; or val1,val2 (computations)")
     29parser.add_option('-t','--time',action='append',dest='t',type="string",default=None,help="t axis value. either one value; or val1,val2 (computations)")
     30parser.add_option('-u','--compute',action='store',dest='compute',type="string",default="mean",help="computation: mean, min, max")
     31parser.add_option('-c','--contour',action='store',dest='contour',type="string",default=None,help="one 'variable' for contour")
     32parser.add_option('-i','--vecx',action='store',dest='vecx',type="string",default=None,help="one 'variable' for wind vector x component")
     33parser.add_option('-j','--vecy',action='store',dest='vecy',type="string",default=None,help="one 'variable' for wind vector x component")
     34parser.add_option('-m','--mult',action='store',dest='mult',type="float",default=None,help="multiplicative factor on field")
     35parser.add_option('-a','--add',action='store',dest='add',type="float",default=None,help="additive factor on field")
     36parser.add_option('-o','--output',action='store',dest='filename',type="string",default="myplot",help="name of output files")
     37parser.add_option('-d','--directory',action='store',dest='folder',type="string",default="./",help="directory of output files")
    3738# plot --> upper case
    3839# -- 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='')
     40parser.add_option('-T','--title',action='append',dest='title',type="string",default=None,help="change 'title'")
     41parser.add_option('-X','--xlabel',action='append',dest='xlabel',type="string",default=None,help="change 'xlabel'")
     42parser.add_option('-Y','--ylabel',action='append',dest='ylabel',type="string",default=None,help="change 'ylabel'")
     43parser.add_option('-D','--div',action='store',dest='div',type="int",default=20,help="integer for number of divisions")
     44parser.add_option('-H','--trans',action='store',dest='trans',type="float",default=1.0,help="float for transparency (0=transp,1=opaque)")
     45parser.add_option('-Z','--logy',action='store_true',dest='logy',default=False,help="set log for vertical axis")
     46parser.add_option('-O','--save',action='store',dest='out',type="string",default="gui",help="save mode: 'gui' 'png' 'pdf' 'eps' 'svg' 'ps'")
    4647# -- 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='')
     48parser.add_option('-L','--lstyle',action='append',dest='lstyle',type="string",default=None,help="[1D] linestyle: '-' '--' '.' '..'")
     49parser.add_option('-Q','--color',action='append',dest='color',type="string",default=None,help="[1D] color: 'b' 'g' 'r' etc")
     50parser.add_option('-K','--marker',action='append',dest='marker',type="string",default=None,help="[1D] marker: '' 'x' 'o' etc")
     51parser.add_option('-S','--superpose',action='store_true',dest='superpose',default=False,help="[1D] use same axis for all plots")
    4952# -- 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='')
     53parser.add_option('-C','--colorb',action='append',dest='colorb',type="string",default=None,help="[2D] colormap: http://micropore.files.wordpress.com/2010/06/colormaps.png")
     54parser.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'")
     55parser.add_option('-B','--back',action='append',dest='back',type="string",default=None,help='[2D] predefined map background (cf. set_back.txt)')
     56parser.add_option('-A','--area',action='append',dest='area',type="string",default=None,help='[2D] predefined region of mapping (cf. set_area.txt)')
     57parser.add_option('-I','--blon',action='append',dest='blon',type="float",default=None,help='[2D] float: bounding longitude for stere (or center longitude for ortho)')
     58parser.add_option('-J','--blat',action='append',dest='blat',type="float",default=None,help='[2D] float: bounding latitude for stere (or center latitude for ortho) ')
     59parser.add_option('-N','--vmin',action='append',dest='vmin',type="float",default=None,help='[2D] float: minimum value for displayed field')
     60parser.add_option('-M','--vmax',action='append',dest='vmax',type="float",default=None,help='[2D] float: maximum value for displayed field')
    5861(opt,args) = parser.parse_args()
    5962
     
    7881    if opt.vecy is not None: var.append(opt.vecy) ; vargoal.append("vector")
    7982# 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)
     83user = pp()
     84user.file = opt.file
     85user.var = var
     86user.vargoal = vargoal
     87user.x = opt.x
     88user.y = opt.y
     89user.z = opt.z
     90user.t = opt.t
     91user.verbose = opt.verbose
     92user.compute = opt.compute
    8393# define field
    8494user.define()
     
    105115command = ""
    106116for arg in sys.argv: command = command + arg + ' '
    107 f = open(opt.filename+'.sh', 'w')
    108 f.write(command)
     117try:
     118    f = open(opt.folder+'/'+opt.filename+'.sh', 'w')
     119    f.write(command)
     120except 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  
    172172    # print status
    173173    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
    175178
    176179    #####################################################
     
    216219               setattr(the_clone,k,v)
    217220        the_clone.verbose = False
     221        the_clone.filename = "THIS_IS_A_CLONE" # trick to avoid additional outputs
    218222        the_clone.define()
    219223        for i in range(self.nfin):
     
    511515        self.printstatus()
    512516        # 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()
    514518        ## first get fields
    515519        ## ... only what is needed is extracted from the files
     
    777781        if (self.n == self.howmanyplots):
    778782            ppplot.save(mode=self.out,filename=self.filename,folder=self.folder,custom=customplot)
     783            mpl.close()
    779784        # SAVE A PICKLE FILE WITH THE self.p ARRAY OF OBJECTS
    780785        if self.verbose: print "**** Saving session in "+self.filename + ".ppobj"
    781786        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."
    784792
    785793    ###########################################################
     
    884892            except:
    885893                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]
    886904                except: pass
    887905            ###
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r917 r920  
    202202       # special case: negative values with stddev while field is positive
    203203       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
    204212    return zevmin, zevmax   
    205213    #### treat vmin = vmax for continuity
  • trunk/UTIL/PYTHON/planetoplot_v2/set_var.txt

    r911 r920  
    5757ASR ; %.0f ; gist_heat ; Absorbed Solar Radiation (W m$^{-2}$)
    5858ISR ; %.0f ; gist_heat ; Incoming Solar Radiation (W m$^{-2}$)
     59SWDOWNZ ; %.0f ; gist_heat ; $\Phi^{SW}\downarrow$ (W m$^{-2}$)
Note: See TracChangeset for help on using the changeset viewer.