Changeset 1050 for trunk/UTIL


Ignore:
Timestamp:
Sep 26, 2013, 12:35:03 PM (11 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2

RENAMED VARIABLES TO BE SIMPLER or COMPLIANT WITH MATPLOTLIB

colorb >> colorbar
lstyle >> linestyle
label >> legend

stridevecx >> svx
stridevecy >> svy
stridex >> sx
stridey >> sy
stridez >> sz
stridet >> st

(in ppplot only)
field >> f
absc >> x
ordi >> y
addvecx >> vx
addvecy >> vy
addontour >> c

ALSO added (same reason of compatibility)

  • the possibility to call ppplot.show() as in matplotlib
  • a shortcut method for a ppplot object: the so-called .makeshow()
Location:
trunk/UTIL/PYTHON/planetoplot_v2
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/additional/just_color_and_title.py

    r1029 r1050  
    55anewversion.defineplot(loadfile="../../demo_data/gw.ppobj")
    66for plot in anewversion.p:
    7     plot.colorb = "Paired"
     7    plot.colorbar = "Paired"
    88    plot.title = "Psychedelic plot!"
    99anewversion.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/additional/tes.py

    r1029 r1050  
    1212tes.superpose = True
    1313tes.getdefineplot()
    14 tes.p[0].label = "MY24"
    15 tes.p[1].label = "MY25"
    16 tes.p[2].label = "MY26"
     14tes.p[0].legend = "MY24"
     15tes.p[1].legend = "MY25"
     16tes.p[2].legend = "MY26"
    1717tes.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/additional/vertpress1d.py

    r1029 r1050  
    2626temp.filename = name
    2727temp.includedate = False
    28 temp.colorb = "hot"
     28temp.colorbar = "hot"
    2929
    3030# this is doing defineplot amongst other things
     
    4343    yeah.xmin = 70.
    4444    yeah.div = 32
    45     yeah.label = labs[count]
     45    yeah.legend = labs[count]
    4646    yeah.title = "Equilibrium profile with a 1D globally-averaged model after 50 Saturn years"
    4747    count = count+1
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/aire.py

    r1029 r1050  
    1111tpond.compute = "meanarea"
    1212tpond.superpose = True
    13 tpond.label = "mean with ponderation by mesh area"
     13tpond.legend = "mean with ponderation by mesh area"
    1414tpond.getplot(extraplot=1)
    1515
     
    1818tnormal.compute = "mean"
    1919tnormal.plotin = tpond
    20 tnormal.label = "simple mean (kind of wrong)"
     20tnormal.legend = "simple mean (kind of wrong)"
    2121tnormal.filename = "aire"
    2222tnormal.getplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/function.py

    r1029 r1050  
    2222
    2323S.p[0].marker = 'o'
    24 S.p[0].lstyle = ''
     24S.p[0].linestyle = ''
    2525S.p[0].ylabel = "Surface geopotential height (km)"
    2626S.p[0].ycoeff = 1./1000.
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/gw.py

    r1029 r1050  
    3232    plot.div = 30
    3333    plot.nxticks = 5
    34 gw.p[0].colorb = "RdBu_r"
     34gw.p[0].colorbar = "RdBu_r"
    3535gw.p[0].vmin = -1.
    3636gw.p[0].vmax = 1.
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/gw_v2.py

    r1029 r1050  
    1515# we define global settings for plot
    1616# (must be done before defineplot)
    17 gw.colorb = "RdBu_r"
     17gw.colorbar = "RdBu_r"
    1818gw.vmin = -1. ; gw.vmax = 1.
    1919gw.div = 30
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/meso_profile.py

    r1029 r1050  
    1717m.verbose = True # making the programe verbose
    1818#m.out = "pdf" # output format
    19 m.colorb = "spectral" # color cycle according to a color map
     19m.colorbar = "spectral" # color cycle according to a color map
    2020
    2121# get data and make plot with default settings
     
    4343# change a few plot settings
    4444for curve in S.p:
    45     curve.lstyle = "--"
     45    curve.linestyle = "--"
    4646    curve.marker = ""
    4747S.p[0].swaplab = False
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/scatter.py

    r1029 r1050  
    1616
    1717S = ps.func(tsurf)
    18 S.p[0].lstyle=""
     18S.p[0].linestyle=""
    1919S.p[0].marker="h"
    2020S.p[0].color="g"
     
    2727
    2828S2 = icetot.func(tsurf)
    29 S2.p[0].lstyle=""
     29S2.p[0].linestyle=""
    3030S2.p[0].marker="D"
    3131S2.p[0].color="r"
     
    4646wind = wind**0.5
    4747S3 = wind.func(ps)
    48 S3.p[0].lstyle=""
     48S3.p[0].linestyle=""
    4949S3.p[0].marker="o"
    5050S3.p[0].color="k"
     
    7171
    7272S = ps.func(tsurf)
    73 S.p[0].lstyle=""
     73S.p[0].linestyle=""
    7474S.p[0].marker="h"
    7575S.p[0].color="g"
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/simple.py

    r1029 r1050  
    2828# we simply change the colorbar
    2929# ... no need to reload data
    30 u.p[0].colorb = "RdBu"
     30u.p[0].colorbar = "RdBu"
    3131u.filename = "myplot"
    3232u.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/tide.py

    r1029 r1050  
    2222addplot.title = "Tide signal at the equator"
    2323addplot.ylabel = "$p_s$ diurnal anomaly (Pa)"
    24 addplot.lstyle = ""
     24addplot.linestyle = ""
    2525addplot.marker = "."
    2626addplot.plot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/vector.py

    r1029 r1050  
    1212# stride both x and y
    1313# this impacts field + vector
    14 u.stridex = 3
    15 u.stridey = 3
     14u.sx = 3
     15u.sy = 3
    1616u.getplot()
    17 u.stridex = 1 # (reinitialise)
    18 u.stridey = 1 # (reinitialise)
     17u.sx = 1 # (reinitialise)
     18u.sy = 1 # (reinitialise)
    1919
    2020# stride vectors only
    2121# not field (here topography)
    22 u.stridevecx = 3
    23 u.stridevecy = 3
     22u.sx = 3
     23u.sy = 3
    2424u.getplot()
    2525
     
    3131
    3232
    33 u.p[0].colorb = "jet"
     33u.p[0].colorbar = "jet"
    3434u.p[0].trans = 0.0
    3535u.p[0].back = "vis"
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/windspeed.py

    r1029 r1050  
    2727wind.filename = "windspeed"
    2828wind.defineplot()
     29wind.p[2].proj = "ortho"
    2930wind.p[2].title = "$\sqrt{u^2+v^2}$"
    30 wind.p[2].proj = "ortho"
    3131wind.makeplot() # plot within the previous one (show because complete)
    3232
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/zonalcontour.py

    r1029 r1050  
    1212u.defineplot()
    1313u.p[0].div = 30.
    14 u.p[0].colorb = "spectral"
     14u.p[0].colorbar = "spectral"
    1515u.makeplot()
    1616
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/zonalmean.py

    r1029 r1050  
    2525u.defineplot()
    2626u.p[0].div = 30.
    27 u.p[0].colorb = "RdBu_r"
     27u.p[0].colorbar = "RdBu_r"
    2828u.p[0].title = "This is a zonal mean"
    2929u.makeplot()
     
    3535u.defineplot()
    3636u.p[0].div = 30.
    37 u.p[0].colorb = "cool"
     37u.p[0].colorbar = "cool"
    3838u.p[0].title = "This is minimum over zonal axis"
    3939u.makeplot()
     
    4545u.defineplot()
    4646u.p[0].div = 30.
    47 u.p[0].colorb = "hot"
     47u.p[0].colorbar = "hot"
    4848u.p[0].title = "This is maximum over zonal axis"
    4949u.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/pp.py

    r1029 r1050  
    5656                  help="transformation on time axis : [None] | correctls | mars_sol2ls | mars_dayini | mars_meso_ls | mars_meso_sol | mars_meso_utc | mars_meso_lt ")
    5757parser.add_option('-p','--print',action='store_true',dest='savtxt',default=False,help="[1D] output field+coord in an ASCII file")
    58 parser.add_option('--stridex',action='store',dest='stridex',type="int",default=1,help="Load data every stridex grid points over x dimension")
    59 parser.add_option('--stridey',action='store',dest='stridey',type="int",default=1,help="Load data every stridex grid points over y dimension")
    60 parser.add_option('--stridez',action='store',dest='stridez',type="int",default=1,help="Load data every stridex grid points over z dimension")
    61 parser.add_option('--stridet',action='store',dest='stridet',type="int",default=1,help="Load data every stridex grid points over t dimension")
     58parser.add_option('--sx',action='store',dest='sx',type="int",default=1,help="Load data every sx grid points over x dimension")
     59parser.add_option('--sy',action='store',dest='sy',type="int",default=1,help="Load data every sy grid points over y dimension")
     60parser.add_option('--sz',action='store',dest='sz',type="int",default=1,help="Load data every sz grid points over z dimension")
     61parser.add_option('--st',action='store',dest='st',type="int",default=1,help="Load data every st grid points over t dimension")
    6262# plot --> upper case
    6363# -- generic
     
    7272parser.add_option('-U','--units',action='append',dest='units',type="string",default=None,help="units for the field")
    7373# -- 1D plot
    74 parser.add_option('-L','--lstyle',action='append',dest='lstyle',type="string",default=None,help="[1D] linestyle: '-' '--' '.' '..'")
     74parser.add_option('-L','--linestyle',action='append',dest='linestyle',type="string",default=None,help="[1D] linestyle: '-' '--' '.' '..'")
    7575parser.add_option('-Q','--color',action='append',dest='color',type="string",default=None,help="[1D] color: 'b' 'g' 'r' etc")
    7676parser.add_option('-K','--marker',action='append',dest='marker',type="string",default=None,help="[1D] marker: '' 'x' 'o' etc")
    7777parser.add_option('-S','--superpose',action='store_true',dest='superpose',default=False,help="[1D] use same axis for all plots")
    78 parser.add_option('-E','--label',action='append',dest='label',type="string",default=None,help="[1D] label for line")
     78parser.add_option('-E','--legend',action='append',dest='legend',type="string",default=None,help="[1D] legend for line")
    7979parser.add_option('--xcoeff',action='append',dest='xcoeff',type="float",default=None,help="[1D] multiply x axis")
    8080parser.add_option('--ycoeff',action='append',dest='ycoeff',type="float",default=None,help="[1D] multiply y axis")
     
    8585parser.add_option('--modx',action='append',dest='modx',type="float",default=None,help="[1D] change xticks with a modulo")
    8686# -- 2D plot
    87 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")
     87parser.add_option('-C','--colorbar',action='append',dest='colorbar',type="string",default=None,help="[2D] colormap: http://micropore.files.wordpress.com/2010/06/colormaps.png")
    8888parser.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' 'noproj'")
    8989parser.add_option('-B','--back',action='append',dest='back',type="string",default=None,help='[2D] predefined map background (cf. set_back.txt)')
     
    9494parser.add_option('-M','--vmax',action='append',dest='vmax',type="float",default=None,help='[2D] float: maximum value for displayed field')
    9595parser.add_option('-W','--wscale',action='append',dest='wscale',type="float",default=None,help='[2D] float: set size of reference wind vector')
    96 parser.add_option('--stridevecx',action='store',dest='stridevecx',type="int",default=1,help="Define an abscissa stride on vectors only -- not on field")
    97 parser.add_option('--stridevecy',action='store',dest='stridevecy',type="int",default=1,help="Define an ordinate stride on vectors only -- not on field")
     96parser.add_option('--svx',action='store',dest='svx',type="int",default=1,help="Define an abscissa stride on vectors only -- not on field")
     97parser.add_option('--svy',action='store',dest='svy',type="int",default=1,help="Define an ordinate stride on vectors only -- not on field")
    9898###########################
    9999(opt,args) = parser.parse_args()
     
    134134user.compute = opt.compute
    135135user.changetime = opt.changetime
    136 user.stridex = opt.stridex
    137 user.stridey = opt.stridey
    138 user.stridez = opt.stridez
    139 user.stridet = opt.stridet
    140 user.stridevecx = opt.stridevecx
    141 user.stridevecy = opt.stridevecy
     136user.sx = opt.sx ; user.sy = opt.sy
     137user.sz = opt.sz ; user.st = opt.st
     138user.svx = opt.svx ; user.svy = opt.svy
    142139user.savtxt = opt.savtxt
    143140# define field
  • trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py

    r977 r1050  
    1414parser.add_option('-K','--marker',action='store',dest='marker',type="string",default=None,help="[1D] Define a new marker")
    1515parser.add_option('-P','--proj',action='store',dest='proj',type="string",default=None,help='[2D] Define a new map projection')
    16 parser.add_option('-C','--colorb',action='store',dest='colorb',type="string",default=None,help="[2D] Define a new colormap")
     16parser.add_option('-C','--colorbar',action='store',dest='colorbar',type="string",default=None,help="[2D] Define a new colormap")
    1717parser.add_option('-E','--explore',action='store_true',dest='explore',default=False,help="[2D] Try many colormaps")
    1818(opt,args) = parser.parse_args()
     
    3434      for plot in yeah.p:
    3535        plot.proj = opt.proj
    36     if opt.colorb is not None:
    37       yeah.colorb = opt.colorb
     36    if opt.colorbar is not None:
     37      yeah.colorbar = opt.colorbar
    3838      for plot in yeah.p:
    39         plot.colorb = opt.colorb
     39        plot.colorbar = opt.colorbar
    4040    if opt.marker is not None:
    4141      for plot in yeah.p:
     
    4848      for cm in clb:
    4949       for plot in yeah.p:
    50          plot.colorb = cm
     50         plot.colorbar = cm
    5151         plot.title = cm
    5252       yeah.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r1031 r1050  
    133133                      filegoal=None,vargoal=None,\
    134134                      x=None,y=None,z=None,t=None,\
    135                       stridex=1,stridey=1,\
    136                       stridez=1,stridet=1,\
    137                       stridevecx=1,\
    138                       stridevecy=1,\
     135                      sx=1,sy=1,\
     136                      sz=1,st=1,\
     137                      svx=1,\
     138                      svy=1,\
    139139                      compute="mean",\
    140140                      verbose=False,\
     
    155155                      vmin=None,vmax=None,\
    156156                      div=None,\
    157                       colorb=None,\
    158                       lstyle=None,\
     157                      colorbar=None,\
     158                      linestyle=None,\
    159159                      marker=None,\
    160160                      color=None,\
    161                       label=None,\
     161                      legend=None,\
    162162                      changetime=None,\
    163163                      units=None,\
     
    187187        self.x = x ; self.y = y   ## if None, free dimension
    188188        self.z = z ; self.t = t   ## if None, free dimension
    189         self.stridex = stridex ; self.stridey = stridey
    190         self.stridez = stridez ; self.stridet = stridet
    191         self.stridevecx = stridevecx
    192         self.stridevecy = stridevecy
     189        self.sx = sx ; self.sy = sy
     190        self.sz = sz ; self.st = st
     191        self.svx = svx
     192        self.svy = svy
    193193        self.compute = compute
    194194        self.verbose = verbose
     
    214214        self.vmin = vmin ; self.vmax = vmax
    215215        self.div = div
    216         self.colorb = colorb
    217         self.lstyle = lstyle
     216        self.colorbar = colorbar
     217        self.linestyle = linestyle
    218218        self.marker = marker
    219219        self.color = color
    220         self.label = label
     220        self.legend = legend
    221221        self.units = units
    222222        self.title = title
     
    253253            self.x = other.x ; self.y = other.y   ## if None, free dimension
    254254            self.z = other.z ; self.t = other.t   ## if None, free dimension
    255             self.stridex = other.stridex ; self.stridey = other.stridey
    256             self.stridez = other.stridez ; self.stridet = other.stridet
     255            self.sx = other.sx ; self.sy = other.sy
     256            self.sz = other.sz ; self.st = other.st
    257257            self.verbose = other.verbose
    258258            self.noproj = other.noproj
     
    268268            self.vmin = other.vmin ; self.vmax = other.vmax
    269269            self.div = other.div
    270             self.colorb = other.colorb
    271             self.lstyle = other.lstyle
     270            self.colorbar = other.colorbar
     271            self.linestyle = other.linestyle
    272272            self.marker = other.marker
    273273            self.color = other.color
    274             self.label = other.label
     274            self.legend = other.legend
    275275            self.units = other.units
    276276            self.title = other.title
     
    597597              obj.performtimechange()
    598598              # get strides
    599               obj.stridex = self.stridex ; obj.stridey = self.stridey
    600               obj.stridez = self.stridez ; obj.stridet = self.stridet
     599              obj.sx = self.sx ; obj.sy = self.sy
     600              obj.sz = self.sz ; obj.st = self.st
    601601              ### get index
    602602              obj.getindextime(dalist=st,ind=t)
     
    643643              # save fields in self.f for the user
    644644              self.f[count] = obj.field
    645               # save a label in self.l for the user
     645              # save a legend in self.l for the user
    646646              self.l[count] = "_"
    647647              if self.nfin > 1:   self.l[count] = self.l[count] + "f=#"+str(int(i+1))+'_'
     
    734734            for count in range(self.nplot):
    735735              pl = self.p[count]
    736               masked = np.ma.masked_where(np.abs(pl.field) > self.missing,pl.field)
    737               pl.field = masked ; pl.field[pl.field.mask] = np.NaN
     736              masked = np.ma.masked_where(np.abs(pl.f) > self.missing,pl.f)
     737              pl.f = masked ; pl.f[pl.f.mask] = np.NaN
    738738            return #self?
    739739        # -----------------------------------------------------
     
    791791                    plobj.define_from_var()
    792792                    # generic 1D/2D: load field and coord in plot object
    793                     plobj.field = obj.field    # field to be plotted
    794                     plobj.absc = obj.absc      # abscissa (or longitude)
    795                     plobj.ordi = obj.ordi      # ordinate (or latitude)
     793                    plobj.f = obj.field    # field to be plotted
     794                    plobj.x = obj.absc      # abscissa (or longitude)
     795                    plobj.y = obj.ordi      # ordinate (or latitude)
    796796                                               # -- useless in 1D but not used anyway
    797797                    # specific 1D plot stuff
    798798                    if dp == 1:
    799                         # -- a default label
    800                         plobj.label = ""
    801                         if self.nfin > 1: plobj.label = plobj.label + " file #"+str(i+1)
    802                         if self.nvin > 1: plobj.label = plobj.label + " var "+plobj.var
    803                         if self.nplott > 1: plobj.label = plobj.label + " t="+str(self.t[t])
    804                         if self.nplotz > 1: plobj.label = plobj.label + " z="+str(self.z[z])
    805                         if self.nploty > 1: plobj.label = plobj.label + " y="+str(self.y[y])
    806                         if self.nplotx > 1: plobj.label = plobj.label + " x="+str(self.x[x])
     799                        # -- a default legend
     800                        plobj.legend = ""
     801                        if self.nfin > 1: plobj.legend = plobj.legend + " file #"+str(i+1)
     802                        if self.nvin > 1: plobj.legend = plobj.legend + " var "+plobj.var
     803                        if self.nplott > 1: plobj.legend = plobj.legend + " t="+str(self.t[t])
     804                        if self.nplotz > 1: plobj.legend = plobj.legend + " z="+str(self.z[z])
     805                        if self.nploty > 1: plobj.legend = plobj.legend + " y="+str(self.y[y])
     806                        if self.nplotx > 1: plobj.legend = plobj.legend + " x="+str(self.x[x])
    807807                    # specific 2d plot stuff
    808808                    if dp == 2:
    809809                        # -- light grey background for missing values
    810                         if type(plobj.field).__name__ in 'MaskedArray': plobj.axisbg = '0.75'
     810                        if type(plobj.f).__name__ in 'MaskedArray': plobj.axisbg = '0.75'
    811811                        # -- define if it is a map or a plot
    812812                        plobj.mapmode = ( obj.method_x+obj.method_y == "freefree" \
     
    821821                    if self.title is not None: plobj.title = self.title
    822822                    if self.units is not None: plobj.units = self.units
    823                     if self.colorb is not None: plobj.colorb = self.colorb
     823                    if self.colorbar is not None: plobj.colorbar = self.colorbar
    824824                    if self.modx is not None: plobj.modx = self.modx
    825825                    if self.nxticks is not None: plobj.nxticks = self.nxticks
     
    827827                    # -- 1D specific
    828828                    if dp == 1:
    829                         if self.lstyle is not None: plobj.lstyle = self.lstyle
     829                        if self.linestyle is not None: plobj.linestyle = self.linestyle
    830830                        if self.marker is not None: plobj.marker = self.marker
    831831                        if self.color is not None: plobj.color = self.color
    832                         if self.label is not None: plobj.label = self.label
     832                        if self.legend is not None: plobj.legend = self.legend
    833833                    # -- 2D specific
    834834                    elif dp == 2:
     
    836836                        if self.vmin is not None: plobj.vmin = self.vmin
    837837                        if self.vmax is not None: plobj.vmax = self.vmax
    838                         plobj.stridevecx = self.stridevecx
    839                         plobj.stridevecy = self.stridevecy
     838                        plobj.svx = self.svx
     839                        plobj.svy = self.svy
    840840                    # finally append plot object
    841841                    self.p.append(plobj)
     
    871871                  ##########################################
    872872                  if condvar == "contour":
    873                       plobj.addcontour = self.request[i][j+1][t][z][y][x].field ; found += 1
     873                      plobj.c = self.request[i][j+1][t][z][y][x].field ; found += 1
    874874                  if condfile == "contour":
    875                       plobj.addcontour = self.request[i+1][j][t][z][y][x].field ; found += 1
     875                      plobj.c = self.request[i+1][j][t][z][y][x].field ; found += 1
    876876                  # see if there is a vector requested...
    877877                  # (we use try because we might be at the end of the list)
     
    883883                  # (in some cases we would do this twice but this is cheap)
    884884                  if "vector" in condvar:
    885                       plobj.addvecx = self.request[i][j+found+1][t][z][y][x].field
    886                       plobj.addvecy = self.request[i][j+found+2][t][z][y][x].field
     885                      plobj.vx = self.request[i][j+found+1][t][z][y][x].field
     886                      plobj.vy = self.request[i][j+found+2][t][z][y][x].field
    887887                  if "vector" in condfile:
    888                       plobj.addvecx = self.request[i+found+1][j][t][z][y][x].field
    889                       plobj.addvecy = self.request[i+found+2][j][t][z][y][x].field
     888                      plobj.vx = self.request[i+found+1][j][t][z][y][x].field
     889                      plobj.vy = self.request[i+found+2][j][t][z][y][x].field
    890890                  count = count + 1
    891891        # COUNT PLOTS. if 0 just exit.
     
    924924            ## adapted space for labels etc
    925925            ## ... except for ortho because there is no label anyway
    926             self.customplot = self.p[0].field.ndim == 2 \
     926            self.customplot = self.p[0].f.ndim == 2 \
    927927                        and self.p[0].mapmode == True \
    928928                        and self.p[0].proj not in ["ortho"]
     
    953953                    # possibility to color lines according to a color map
    954954                    # ... made so that all plots span the whole color map automatically.
    955                     if self.colorb is not None:
    956                         if self.verbose: print "**** OK. We make a rainbow spaghetti plot with color map ",self.colorb
    957                         ppplot.rainbow(cb=self.colorb,num=self.howmanyplots)
     955                    if self.colorbar is not None:
     956                        if self.verbose: print "**** OK. We make a rainbow spaghetti plot with color map ",self.colorbar
     957                        ppplot.rainbow(cb=self.colorbar,num=self.howmanyplots)
    958958                else:
    959                     pl.invert = False ; pl.lstyle = None # don't invert again axis
     959                    pl.invert = False ; pl.linestyle = None # don't invert again axis
    960960                    # set saved titles and labels
    961961                    if self.plotin is None:
     
    978978                if self.verbose: print "**** Printing results in a text file"
    979979                name = pl.var + "%04d" % self.n
    980                 ppplot.writeascii(field=pl.field,absc=pl.absc,name=name)
     980                ppplot.writeascii(field=pl.f,absc=pl.x,name=name)
    981981            # increment plot count (and propagate this in plotin)
    982982            self.n = self.n+1
     
    10441044        while count < self.howmanyplots:
    10451045           sobj = self.p[count] ; oobj = other.p[count]
    1046            if sobj.field.ndim !=1 or oobj.field.ndim !=1:
     1046           if sobj.f.ndim !=1 or oobj.f.ndim !=1:
    10471047               if self.verbose: print "!! WARNING !! Flattening arrays because more than one-dimensional."
    1048                sobj.field = np.ravel(sobj.field)
    1049                oobj.field = np.ravel(oobj.field)
    1050            sobj.absc = oobj.field
     1048               sobj.f = np.ravel(sobj.f)
     1049               oobj.f = np.ravel(oobj.f)
     1050           sobj.x = oobj.f
    10511051           sobj.xlabel = oobj.ylabel
    1052            if sobj.absc.size > sobj.field.size:
     1052           if sobj.x.size > sobj.f.size:
    10531053               if self.verbose:
    1054                    print "!! WARNING !! Trying to define y=f(x) with x and y not at the same size.",sobj.absc.size,sobj.field.size
     1054                   print "!! WARNING !! Trying to define y=f(x) with x and y not at the same size.",sobj.x.size,sobj.f.size
    10551055                   print "!! WARNING !! Modifying x to fit y size but please check."
    1056                sobj.absc = sobj.absc[0:sobj.field.size]
     1056               sobj.x = sobj.x[0:sobj.f.size]
    10571057           count = count + 1
    10581058        return self
     
    10831083            except: pass
    10841084            ###
    1085             try: self.p[iii].colorb = opt.colorb[iii]
     1085            try: self.p[iii].colorbar = opt.colorbar[iii]
    10861086            except:
    1087                 try: self.p[iii].colorb = opt.colorb[0] ; self.colorb = opt.colorb[0]
     1087                try: self.p[iii].colorbar = opt.colorbar[0] ; self.colorbar = opt.colorbar[0]
    10881088                except: pass
    10891089            ###
     
    11121112                except: pass
    11131113            ###
    1114             try: self.p[iii].lstyle = opt.lstyle[iii]
     1114            try: self.p[iii].linestyle = opt.linestyle[iii]
    11151115            except:
    1116                 try: self.p[iii].lstyle = opt.lstyle[0]
     1116                try: self.p[iii].linestyle = opt.linestyle[0]
    11171117                except: pass
    11181118            ###
     
    11271127                except: pass
    11281128            ###
    1129             try: self.p[iii].label = opt.label[iii]
     1129            try: self.p[iii].legend = opt.legend[iii]
    11301130            except:
    1131                 try: self.p[iii].label = opt.label[0]
     1131                try: self.p[iii].legend = opt.legend[0]
    11321132                except: pass
    11331133            ###
     
    12421242        self.compute = None
    12431243        self.changetime = None
    1244         self.stridex = 1 ; self.stridey = 1 ; self.stridez = 1 ; self.stridet = 1
     1244        self.sx = 1 ; self.sy = 1 ; self.sz = 1 ; self.st = 1
    12451245        self.missing = '!! missing value: I am not set, damned !!'
    12461246
     
    14621462    def getindextime(self,dalist=None,ind=None):
    14631463        if self.method_t == "free":
    1464             self.index_t = np.arange(0,self.dim_t,self.stridet)
     1464            self.index_t = np.arange(0,self.dim_t,self.st)
    14651465            if self.dim_t > 1: 
    14661466                self.dimplot = self.dimplot + 1
     
    14721472            start = np.argmin( np.abs( self.field_t - dalist[ind][0] ) )
    14731473            stop = np.argmin( np.abs( self.field_t - dalist[ind][1] ) )
    1474             self.index_t = np.arange(start,stop,self.stridet)
     1474            self.index_t = np.arange(start,stop,self.st)
    14751475            if self.verbose: print "**** OK. t values. comp over interval ",self.field_t[start],self.field_t[stop]," nvalues=",self.index_t.size
    14761476        elif self.method_t == "fixed":
     
    14861486    def getindexvert(self,dalist=None,ind=None):
    14871487        if self.method_z == "free":
    1488             self.index_z = np.arange(0,self.dim_z,self.stridez)
     1488            self.index_z = np.arange(0,self.dim_z,self.sz)
    14891489            if self.dim_z > 1: 
    14901490                self.dimplot = self.dimplot + 1
     
    14961496            start = np.argmin( np.abs( self.field_z - dalist[ind][0] ) )
    14971497            stop = np.argmin( np.abs( self.field_z - dalist[ind][1] ) )
    1498             self.index_z = np.arange(start,stop,self.stridez)
     1498            self.index_z = np.arange(start,stop,self.sz)
    14991499            if self.verbose: print "**** OK. z values. comp over interval",self.field_z[start],self.field_z[stop]," nvalues=",self.index_z.size
    15001500        elif self.method_z == "fixed":
     
    15211521        ## - LON IS COMP AND LAT IS FREE
    15221522        if self.method_x == "free" or test in ["compfree","compcomp"]:
    1523             self.index_x = range(0,self.dim_x,self.stridex)
     1523            self.index_x = range(0,self.dim_x,self.sx)
    15241524            if self.dim_x > 1: 
    15251525                if self.method_x == "free": self.dimplot = self.dimplot + 1
     
    15291529                if self.verbose: print "**** OK. no x dimension."
    15301530        if self.method_y == "free" or test in ["freecomp","compcomp"]:
    1531             self.index_y = range(0,self.dim_y,self.stridey)
     1531            self.index_y = range(0,self.dim_y,self.sy)
    15321532            if self.dim_y > 1: 
    15331533                if self.method_y == "free": self.dimplot = self.dimplot + 1
     
    16631663          # ... there are special cases with strides
    16641664          # ... some other fixes will be needed probably TBD
    1665           if self.method_x == "free" and self.stridex != 1:
     1665          if self.method_x == "free" and self.sx != 1:
    16661666              self.field_x = self.field_x[self.index_x]
    1667           if self.method_y == "free" and self.stridey != 1:
     1667          if self.method_y == "free" and self.sy != 1:
    16681668              self.field_y = self.field_y[self.index_y]
    16691669        self.field_z = self.field_z[self.index_z]
     
    16751675          pass
    16761676        elif test in ["fixedfree","fixedcomp"] or test in ["freefixed","compfixed"]:
    1677          if self.stridex == 1 and self.stridey == 1:
     1677         if self.sx == 1 and self.sy == 1:
    16781678          time0 = timelib.time()
    16791679          # now have to obtain the new indexes which correspond to the extracted self.field
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r1040 r1050  
    318318          print "!! ERROR !! File format not supported. Supported: ",possiblesave
    319319
     320# a necessary addition for people used to matplotlib
     321def show():
     322    mpl.show()
     323
    320324##################################
    321325# a generic class to make a plot #
     
    336340    def __init__(self,\
    337341                 var=None,\
    338                  field=None,\
    339                  absc=None,\
     342                 f=None,\
     343                 x=None,\
    340344                 xlabel="",\
    341345                 ylabel="",\
     
    349353                 ycoeff=1.,\
    350354                 fmt=None,\
    351                  colorb="jet",\
     355                 colorbar="jet",\
    352356                 units="",\
    353357                 modx=None,\
     
    361365        ## what could be defined by the user
    362366        self.var = var
    363         self.field = field
    364         self.absc = absc
     367        self.f = f
     368        self.x = x
    365369        self.xlabel = xlabel
    366370        self.ylabel = ylabel
     
    376380        self.fmt = fmt
    377381        self.units = units
    378         self.colorb = colorb
     382        self.colorbar = colorbar
    379383        self.modx = modx
    380384        self.xmin = xmin
     
    392396    # -------------------------------
    393397    def check(self):
    394         if self.field is None: print "!! ERROR !! Please define a field to be plotted" ; exit()
    395         else: self.field = np.array(self.field) # ensure this is a numpy array
     398        if self.f is None: print "!! ERROR !! Please define a field to be plotted" ; exit()
     399        else: self.f = np.array(self.f) # ensure this is a numpy array
    396400
    397401    # define_from_var
     
    418422        mpl.title(self.title)
    419423        # if masked array, set masked values to filled values (e.g. np.nan) for plotting purposes
    420         if type(self.field).__name__ in 'MaskedArray':
    421             self.field[self.field.mask] = self.field.fill_value
     424        if type(self.f).__name__ in 'MaskedArray':
     425            self.f[self.f.mask] = self.f.fill_value
    422426
    423427################################
     
    438442    # -------------------------------
    439443    def __init__(self,\
    440                  lstyle=None,\
     444                 linestyle=None,\
    441445                 color=None,\
    442446                 marker='x',\
    443                  label=None):
     447                 legend=None):
    444448        ## get initialization from parent class
    445449        plot.__init__(self)
    446450        ## what could be defined by the user
    447         self.lstyle = lstyle
     451        self.linestyle = linestyle
    448452        self.color = color
    449453        self.marker = marker
    450         self.label = label
     454        self.legend = legend
    451455
    452456    # define_from_var
     
    471475        # add specific stuff
    472476        mpl.grid(color='grey')
    473         if self.lstyle == "": self.lstyle = " " # to allow for no line at all with ""
     477        if self.linestyle == "": self.linestyle = " " # to allow for no line at all with ""
    474478        # set dummy x axis if not defined
    475         if self.absc is None:
    476             self.absc = np.array(range(self.field.shape[0]))
     479        if self.x is None:
     480            self.x = np.array(range(self.f.shape[0]))
    477481            print "!! WARNING !! dummy coordinates on x axis"
    478482        else:
    479             self.absc = np.array(self.absc) # ensure this is a numpy array
     483            self.x = np.array(self.x) # ensure this is a numpy array
    480484        # swapping if requested
    481         if self.swap:  x = self.field ; y = self.absc
    482         else:          x = self.absc ; y = self.field
     485        if self.swap:  x = self.f ; y = self.x
     486        else:          x = self.x ; y = self.f
    483487        # coefficients on axis
    484488        x=x*self.xcoeff ; y=y*self.ycoeff
     
    489493        # make the 1D plot
    490494        # either request linestyle or let matplotlib decide
    491         if self.lstyle is not None and self.color is not None:
    492             mpl.plot(x,y,self.color+self.lstyle,marker=self.marker,label=self.label)
     495        if self.linestyle is not None and self.color is not None:
     496            mpl.plot(x,y,self.color+self.linestyle,marker=self.marker,label=self.legend)
    493497        elif self.color is not None:
    494             mpl.plot(x,y,color=self.color,marker=self.marker,label=self.label)
    495         elif self.lstyle is not None:
    496             mpl.plot(x,y,linestyle=self.lstyle,marker=self.marker,label=self.label)
     498            mpl.plot(x,y,color=self.color,marker=self.marker,label=self.legend)
     499        elif self.linestyle is not None:
     500            mpl.plot(x,y,linestyle=self.linestyle,marker=self.marker,label=self.legend)
    497501        else:
    498             mpl.plot(x,y,marker=self.marker,label=self.label)
     502            mpl.plot(x,y,marker=self.marker,label=self.legend)
    499503        # AXES
    500504        ax = mpl.gca()
     
    510514            self.xmin,self.xmax = self.xmax,self.xmin
    511515        # add a label for line(s)
    512         if self.label is not None:
    513             if self.label != "":
     516        if self.legend is not None:
     517            if self.legend != "":
    514518                mpl.legend(loc="best",fancybox=True)
    515519        # format labels
     
    544548            ax = labelmodulo(ax,self.modx)
    545549
     550    # makeshow = make + show
     551    # -------------------------------
     552    def makeshow(self):
     553        self.make()
     554        mpl.show()
     555
    546556################################
    547557# a subclass to make a 2D plot #
     
    561571    # -------------------------------
    562572    def __init__(self,\
    563                  ordi=None,\
     573                 y=None,\
    564574                 mapmode=False,\
    565575                 proj="cyl",\
    566576                 back=None,\
    567577                 trans=1.0,\
    568                  addvecx=None,\
    569                  addvecy=None,\
    570                  addcontour=None,\
     578                 vx=None,\
     579                 vy=None,\
     580                 c=None,\
    571581                 blon=None,\
    572582                 blat=None,\
     
    576586                 showcb=True,\
    577587                 wscale=None,\
    578                  stridevecx=1,\
    579                  stridevecy=1,\
     588                 svx=1,\
     589                 svy=1,\
    580590                 leftcorrect=False,\
    581591                 colorvec="black"):
     
    583593        plot.__init__(self)
    584594        ## what could be defined by the user
    585         self.ordi = ordi
     595        self.y = y
    586596        self.mapmode = mapmode
    587597        self.proj = proj
    588598        self.back = back
    589599        self.trans = trans
    590         self.addvecx = addvecx
    591         self.addvecy = addvecy
     600        self.vx = vx
     601        self.vy = vy
    592602        self.colorvec = colorvec
    593         self.addcontour = addcontour
     603        self.c = c
    594604        self.blon = blon ; self.blat = blat
    595605        self.area = area
     
    597607        self.showcb = showcb
    598608        self.wscale = wscale
    599         self.stridevecx = stridevecx
    600         self.stridevecy = stridevecy
     609        self.svx = svx
     610        self.svy = svy
    601611        self.leftcorrect = leftcorrect
    602612
     
    610620        if self.var is not None:
    611621         if self.var.upper() in vl.keys():
    612           self.colorb = vc[self.var.upper()]
     622          self.colorbar = vc[self.var.upper()]
    613623          self.fmt = vf[self.var.upper()]
    614624
     
    624634        ############################################################################################
    625635        # set dummy xy axis if not defined
    626         if self.absc is None:
    627             self.absc = np.array(range(self.field.shape[0]))
     636        if self.x is None:
     637            self.x = np.array(range(self.f.shape[0]))
    628638            self.mapmode = False
    629639            print "!! WARNING !! dummy coordinates on x axis"
    630         if self.ordi is None:
    631             self.ordi = np.array(range(self.field.shape[1]))
     640        if self.y is None:
     641            self.y = np.array(range(self.f.shape[1]))
    632642            self.mapmode = False
    633643            print "!! WARNING !! dummy coordinates on y axis"
    634644        # transposing if necessary
    635         shape = self.field.shape
     645        shape = self.f.shape
    636646        if shape[0] != shape[1]:
    637          if len(self.absc) == shape[0] and len(self.ordi) == shape[1]:
     647         if len(self.x) == shape[0] and len(self.y) == shape[1]:
    638648            print "!! WARNING !! Transposing axes"
    639             self.field = np.transpose(self.field)
     649            self.f = np.transpose(self.f)
    640650        # bound field
    641         zevmin, zevmax = calculate_bounds(self.field,vmin=self.vmin,vmax=self.vmax)
    642         what_I_plot = bounds(self.field,zevmin,zevmax)
     651        zevmin, zevmax = calculate_bounds(self.f,vmin=self.vmin,vmax=self.vmax)
     652        what_I_plot = bounds(self.f,zevmin,zevmax)
    643653        # define contour field levels. define color palette
    644654        ticks = self.div + 1
    645655        zelevels = np.linspace(zevmin,zevmax,ticks)
    646         palette = get_cmap(name=self.colorb)
     656        palette = get_cmap(name=self.colorbar)
    647657        # do the same thing for possible contourline entries
    648         if self.addcontour is not None:
     658        if self.c is not None:
    649659            # if masked array, set masked values to filled values (e.g. np.nan) for plotting purposes
    650             if type(self.addcontour).__name__ in 'MaskedArray':
    651                self.addcontour[self.addcontour.mask] = self.addcontour.fill_value
    652             zevminc, zevmaxc = calculate_bounds(self.addcontour)
    653             what_I_contour = bounds(self.addcontour,zevminc,zevmaxc)
     660            if type(self.c).__name__ in 'MaskedArray':
     661               self.c[self.c.mask] = self.c.fill_value
     662            zevminc, zevmaxc = calculate_bounds(self.c)
     663            what_I_contour = bounds(self.c,zevminc,zevmaxc)
    654664            ticks = self.div + 1
    655665            zelevelsc = np.linspace(zevminc,zevmaxc,ticks)
     
    662672            ###################
    663673            # swapping if requested
    664             if self.swap:  x = self.ordi ; y = self.absc
    665             else:          x = self.absc ; y = self.ordi
     674            if self.swap:  x = self.y ; y = self.x
     675            else:          x = self.x ; y = self.y
    666676            # coefficients on axis
    667677            x=x*self.xcoeff ; y=y*self.ycoeff
    668678            # make shaded and line contours
    669             if self.addcontour is not None:
     679            if self.c is not None:
    670680                objC = mpl.contour(x, y, what_I_contour, \
    671681                            zelevelsc, colors = ccol, linewidths = cline)
     
    673683                #             inline_spacing=1,fmt="%.0f")
    674684            mpl.contourf(x, y, \
    675                          self.field, \
     685                         self.f, \
    676686                         zelevels, cmap=palette)
    677687            #mpl.pcolor(x,y,\
    678             #             self.field, \
     688            #             self.f, \
    679689            #             cmap=palette)
    680690            # make log axes and/or invert ordinate
     
    708718            # get lon and lat in 2D version.
    709719            # (but first ensure we do have 2D coordinates)
    710             if self.absc.ndim == 1:     [self.absc,self.ordi] = np.meshgrid(self.absc,self.ordi)
    711             elif self.absc.ndim > 2:    print "!! ERROR !! lon and lat arrays must be 1D or 2D"
     720            if self.x.ndim == 1:        [self.x,self.y] = np.meshgrid(self.x,self.y)
     721            elif self.x.ndim > 2:    print "!! ERROR !! lon and lat arrays must be 1D or 2D"
    712722            # get lat lon intervals and associated settings
    713             wlon = [np.min(self.absc),np.max(self.absc)]
    714             wlat = [np.min(self.ordi),np.max(self.ordi)]
     723            wlon = [np.min(self.x),np.max(self.x)]
     724            wlat = [np.min(self.y),np.max(self.y)]
    715725            # -- area presets are in set_area.txt
    716726            if self.area is not None:
     
    800810                 print "!! ERROR !! requested background not defined. change name or fill in set_back.txt" ; exit()
    801811            # define x and y given the projection
    802             x, y = m(self.absc, self.ordi)
     812            x, y = m(self.x, self.y)
    803813            # contour field. first line contour then shaded contour.
    804             if self.addcontour is not None:
     814            if self.c is not None:
    805815                objC2 = m.contour(x, y, what_I_contour, \
    806816                            zelevelsc, colors = ccol, linewidths = cline)
     
    829839        ### VECTORS. must be after the colorbar. we could also leave possibility for streamlines.
    830840        ############################################################################################
    831         ### not expecting NaN in self.addvecx and self.addvecy. masked arrays is just enough.
    832         if self.addvecx is not None and self.addvecy is not None:
     841        ### not expecting NaN in self.vx and self.vy. masked arrays is just enough.
     842        if self.vx is not None and self.vy is not None:
    833843                # vectors on map projection or simple 2D mapping
    834844                if self.mapmode:
    835                    [vecx,vecy] = m.rotate_vector(self.addvecx,self.addvecy,self.absc,self.ordi) # for metwinds only ?
     845                   [vecx,vecy] = m.rotate_vector(self.vx,self.vy,self.x,self.y) # for metwinds only ?
    836846                else:
    837                    vecx,vecy = self.addvecx,self.addvecy
     847                   vecx,vecy = self.vx,self.vy
    838848                   if x.ndim < 2 and y.ndim < 2: x,y = np.meshgrid(x,y)
    839849                # reference vector is scaled
    840850                if self.wscale is None:
    841                     self.wscale = ppcompute.mean(np.sqrt(self.addvecx*self.addvecx+self.addvecy*self.addvecy))
     851                    self.wscale = ppcompute.mean(np.sqrt(self.vx*self.vx+self.vy*self.vy))
    842852                # make vector field
    843853                if self.mapmode:
    844                     q = m.quiver( x[::self.stridevecy,::self.stridevecx],y[::self.stridevecy,::self.stridevecx],\
    845                                   vecx[::self.stridevecy,::self.stridevecx],vecy[::self.stridevecy,::self.stridevecx],\
     854                    q = m.quiver( x[::self.svy,::self.svx],y[::self.svy,::self.svx],\
     855                                  vecx[::self.svy,::self.svx],vecy[::self.svy,::self.svx],\
    846856                                  angles='xy',color=self.colorvec,pivot='tail',\
    847857                                  scale=self.wscale*reducevec,width=widthvec )
    848858                else:
    849                     q = mpl.quiver( x[::self.stridevecy,::self.stridevecx],y[::self.stridevecy,::self.stridevecx],\
    850                                     vecx[::self.stridevecy,::self.stridevecx],vecy[::self.stridevecy,::self.stridevecx],\
     859                    q = mpl.quiver( x[::self.svy,::self.svx],y[::self.svy,::self.svx],\
     860                                    vecx[::self.svy,::self.svx],vecy[::self.svy,::self.svx],\
    851861                                    angles='xy',color=self.colorvec,pivot='tail',\
    852862                                    scale=self.wscale*reducevec,width=widthvec )
     
    880890        except IOError:
    881891            pass
     892
     893    # makeshow = make + show
     894    # -------------------------------
     895    def makeshow(self):
     896        self.make()
     897        mpl.show()
Note: See TracChangeset for help on using the changeset viewer.