Changeset 1050 for trunk/UTIL
- Timestamp:
- Sep 26, 2013, 12:35:03 PM (11 years ago)
- 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 5 5 anewversion.defineplot(loadfile="../../demo_data/gw.ppobj") 6 6 for plot in anewversion.p: 7 plot.colorb = "Paired"7 plot.colorbar = "Paired" 8 8 plot.title = "Psychedelic plot!" 9 9 anewversion.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/additional/tes.py
r1029 r1050 12 12 tes.superpose = True 13 13 tes.getdefineplot() 14 tes.p[0].l abel= "MY24"15 tes.p[1].l abel= "MY25"16 tes.p[2].l abel= "MY26"14 tes.p[0].legend = "MY24" 15 tes.p[1].legend = "MY25" 16 tes.p[2].legend = "MY26" 17 17 tes.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/additional/vertpress1d.py
r1029 r1050 26 26 temp.filename = name 27 27 temp.includedate = False 28 temp.colorb = "hot"28 temp.colorbar = "hot" 29 29 30 30 # this is doing defineplot amongst other things … … 43 43 yeah.xmin = 70. 44 44 yeah.div = 32 45 yeah.l abel= labs[count]45 yeah.legend = labs[count] 46 46 yeah.title = "Equilibrium profile with a 1D globally-averaged model after 50 Saturn years" 47 47 count = count+1 -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/aire.py
r1029 r1050 11 11 tpond.compute = "meanarea" 12 12 tpond.superpose = True 13 tpond.l abel= "mean with ponderation by mesh area"13 tpond.legend = "mean with ponderation by mesh area" 14 14 tpond.getplot(extraplot=1) 15 15 … … 18 18 tnormal.compute = "mean" 19 19 tnormal.plotin = tpond 20 tnormal.l abel= "simple mean (kind of wrong)"20 tnormal.legend = "simple mean (kind of wrong)" 21 21 tnormal.filename = "aire" 22 22 tnormal.getplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/function.py
r1029 r1050 22 22 23 23 S.p[0].marker = 'o' 24 S.p[0].l style = ''24 S.p[0].linestyle = '' 25 25 S.p[0].ylabel = "Surface geopotential height (km)" 26 26 S.p[0].ycoeff = 1./1000. -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/gw.py
r1029 r1050 32 32 plot.div = 30 33 33 plot.nxticks = 5 34 gw.p[0].colorb = "RdBu_r"34 gw.p[0].colorbar = "RdBu_r" 35 35 gw.p[0].vmin = -1. 36 36 gw.p[0].vmax = 1. -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/gw_v2.py
r1029 r1050 15 15 # we define global settings for plot 16 16 # (must be done before defineplot) 17 gw.colorb = "RdBu_r"17 gw.colorbar = "RdBu_r" 18 18 gw.vmin = -1. ; gw.vmax = 1. 19 19 gw.div = 30 -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/meso_profile.py
r1029 r1050 17 17 m.verbose = True # making the programe verbose 18 18 #m.out = "pdf" # output format 19 m.colorb = "spectral" # color cycle according to a color map19 m.colorbar = "spectral" # color cycle according to a color map 20 20 21 21 # get data and make plot with default settings … … 43 43 # change a few plot settings 44 44 for curve in S.p: 45 curve.l style = "--"45 curve.linestyle = "--" 46 46 curve.marker = "" 47 47 S.p[0].swaplab = False -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/scatter.py
r1029 r1050 16 16 17 17 S = ps.func(tsurf) 18 S.p[0].l style=""18 S.p[0].linestyle="" 19 19 S.p[0].marker="h" 20 20 S.p[0].color="g" … … 27 27 28 28 S2 = icetot.func(tsurf) 29 S2.p[0].l style=""29 S2.p[0].linestyle="" 30 30 S2.p[0].marker="D" 31 31 S2.p[0].color="r" … … 46 46 wind = wind**0.5 47 47 S3 = wind.func(ps) 48 S3.p[0].l style=""48 S3.p[0].linestyle="" 49 49 S3.p[0].marker="o" 50 50 S3.p[0].color="k" … … 71 71 72 72 S = ps.func(tsurf) 73 S.p[0].l style=""73 S.p[0].linestyle="" 74 74 S.p[0].marker="h" 75 75 S.p[0].color="g" -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/simple.py
r1029 r1050 28 28 # we simply change the colorbar 29 29 # ... no need to reload data 30 u.p[0].colorb = "RdBu"30 u.p[0].colorbar = "RdBu" 31 31 u.filename = "myplot" 32 32 u.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/tide.py
r1029 r1050 22 22 addplot.title = "Tide signal at the equator" 23 23 addplot.ylabel = "$p_s$ diurnal anomaly (Pa)" 24 addplot.l style = ""24 addplot.linestyle = "" 25 25 addplot.marker = "." 26 26 addplot.plot() -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/vector.py
r1029 r1050 12 12 # stride both x and y 13 13 # this impacts field + vector 14 u.s tridex = 315 u.s tridey = 314 u.sx = 3 15 u.sy = 3 16 16 u.getplot() 17 u.s tridex = 1 # (reinitialise)18 u.s tridey = 1 # (reinitialise)17 u.sx = 1 # (reinitialise) 18 u.sy = 1 # (reinitialise) 19 19 20 20 # stride vectors only 21 21 # not field (here topography) 22 u.s tridevecx = 323 u.s tridevecy = 322 u.sx = 3 23 u.sy = 3 24 24 u.getplot() 25 25 … … 31 31 32 32 33 u.p[0].colorb = "jet"33 u.p[0].colorbar = "jet" 34 34 u.p[0].trans = 0.0 35 35 u.p[0].back = "vis" -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/windspeed.py
r1029 r1050 27 27 wind.filename = "windspeed" 28 28 wind.defineplot() 29 wind.p[2].proj = "ortho" 29 30 wind.p[2].title = "$\sqrt{u^2+v^2}$" 30 wind.p[2].proj = "ortho"31 31 wind.makeplot() # plot within the previous one (show because complete) 32 32 -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/zonalcontour.py
r1029 r1050 12 12 u.defineplot() 13 13 u.p[0].div = 30. 14 u.p[0].colorb = "spectral"14 u.p[0].colorbar = "spectral" 15 15 u.makeplot() 16 16 -
trunk/UTIL/PYTHON/planetoplot_v2/examples/reference/zonalmean.py
r1029 r1050 25 25 u.defineplot() 26 26 u.p[0].div = 30. 27 u.p[0].colorb = "RdBu_r"27 u.p[0].colorbar = "RdBu_r" 28 28 u.p[0].title = "This is a zonal mean" 29 29 u.makeplot() … … 35 35 u.defineplot() 36 36 u.p[0].div = 30. 37 u.p[0].colorb = "cool"37 u.p[0].colorbar = "cool" 38 38 u.p[0].title = "This is minimum over zonal axis" 39 39 u.makeplot() … … 45 45 u.defineplot() 46 46 u.p[0].div = 30. 47 u.p[0].colorb = "hot"47 u.p[0].colorbar = "hot" 48 48 u.p[0].title = "This is maximum over zonal axis" 49 49 u.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/pp.py
r1029 r1050 56 56 help="transformation on time axis : [None] | correctls | mars_sol2ls | mars_dayini | mars_meso_ls | mars_meso_sol | mars_meso_utc | mars_meso_lt ") 57 57 parser.add_option('-p','--print',action='store_true',dest='savtxt',default=False,help="[1D] output field+coord in an ASCII file") 58 parser.add_option('--s tridex',action='store',dest='stridex',type="int",default=1,help="Load data every stridex grid points over x dimension")59 parser.add_option('--s tridey',action='store',dest='stridey',type="int",default=1,help="Load data every stridexgrid points over y dimension")60 parser.add_option('--s tridez',action='store',dest='stridez',type="int",default=1,help="Load data every stridexgrid points over z dimension")61 parser.add_option('--st ridet',action='store',dest='stridet',type="int",default=1,help="Load data every stridexgrid points over t dimension")58 parser.add_option('--sx',action='store',dest='sx',type="int",default=1,help="Load data every sx grid points over x dimension") 59 parser.add_option('--sy',action='store',dest='sy',type="int",default=1,help="Load data every sy grid points over y dimension") 60 parser.add_option('--sz',action='store',dest='sz',type="int",default=1,help="Load data every sz grid points over z dimension") 61 parser.add_option('--st',action='store',dest='st',type="int",default=1,help="Load data every st grid points over t dimension") 62 62 # plot --> upper case 63 63 # -- generic … … 72 72 parser.add_option('-U','--units',action='append',dest='units',type="string",default=None,help="units for the field") 73 73 # -- 1D plot 74 parser.add_option('-L','--l style',action='append',dest='lstyle',type="string",default=None,help="[1D] linestyle: '-' '--' '.' '..'")74 parser.add_option('-L','--linestyle',action='append',dest='linestyle',type="string",default=None,help="[1D] linestyle: '-' '--' '.' '..'") 75 75 parser.add_option('-Q','--color',action='append',dest='color',type="string",default=None,help="[1D] color: 'b' 'g' 'r' etc") 76 76 parser.add_option('-K','--marker',action='append',dest='marker',type="string",default=None,help="[1D] marker: '' 'x' 'o' etc") 77 77 parser.add_option('-S','--superpose',action='store_true',dest='superpose',default=False,help="[1D] use same axis for all plots") 78 parser.add_option('-E','--l abel',action='append',dest='label',type="string",default=None,help="[1D] labelfor line")78 parser.add_option('-E','--legend',action='append',dest='legend',type="string",default=None,help="[1D] legend for line") 79 79 parser.add_option('--xcoeff',action='append',dest='xcoeff',type="float",default=None,help="[1D] multiply x axis") 80 80 parser.add_option('--ycoeff',action='append',dest='ycoeff',type="float",default=None,help="[1D] multiply y axis") … … 85 85 parser.add_option('--modx',action='append',dest='modx',type="float",default=None,help="[1D] change xticks with a modulo") 86 86 # -- 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")87 parser.add_option('-C','--colorbar',action='append',dest='colorbar',type="string",default=None,help="[2D] colormap: http://micropore.files.wordpress.com/2010/06/colormaps.png") 88 88 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' 'noproj'") 89 89 parser.add_option('-B','--back',action='append',dest='back',type="string",default=None,help='[2D] predefined map background (cf. set_back.txt)') … … 94 94 parser.add_option('-M','--vmax',action='append',dest='vmax',type="float",default=None,help='[2D] float: maximum value for displayed field') 95 95 parser.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('--s tridevecx',action='store',dest='stridevecx',type="int",default=1,help="Define an abscissa stride on vectors only -- not on field")97 parser.add_option('--s tridevecy',action='store',dest='stridevecy',type="int",default=1,help="Define an ordinate stride on vectors only -- not on field")96 parser.add_option('--svx',action='store',dest='svx',type="int",default=1,help="Define an abscissa stride on vectors only -- not on field") 97 parser.add_option('--svy',action='store',dest='svy',type="int",default=1,help="Define an ordinate stride on vectors only -- not on field") 98 98 ########################### 99 99 (opt,args) = parser.parse_args() … … 134 134 user.compute = opt.compute 135 135 user.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 136 user.sx = opt.sx ; user.sy = opt.sy 137 user.sz = opt.sz ; user.st = opt.st 138 user.svx = opt.svx ; user.svy = opt.svy 142 139 user.savtxt = opt.savtxt 143 140 # define field -
trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py
r977 r1050 14 14 parser.add_option('-K','--marker',action='store',dest='marker',type="string",default=None,help="[1D] Define a new marker") 15 15 parser.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")16 parser.add_option('-C','--colorbar',action='store',dest='colorbar',type="string",default=None,help="[2D] Define a new colormap") 17 17 parser.add_option('-E','--explore',action='store_true',dest='explore',default=False,help="[2D] Try many colormaps") 18 18 (opt,args) = parser.parse_args() … … 34 34 for plot in yeah.p: 35 35 plot.proj = opt.proj 36 if opt.colorb is not None:37 yeah.colorb = opt.colorb36 if opt.colorbar is not None: 37 yeah.colorbar = opt.colorbar 38 38 for plot in yeah.p: 39 plot.colorb = opt.colorb39 plot.colorbar = opt.colorbar 40 40 if opt.marker is not None: 41 41 for plot in yeah.p: … … 48 48 for cm in clb: 49 49 for plot in yeah.p: 50 plot.colorb = cm50 plot.colorbar = cm 51 51 plot.title = cm 52 52 yeah.makeplot() -
trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py
r1031 r1050 133 133 filegoal=None,vargoal=None,\ 134 134 x=None,y=None,z=None,t=None,\ 135 s tridex=1,stridey=1,\136 s tridez=1,stridet=1,\137 s tridevecx=1,\138 s tridevecy=1,\135 sx=1,sy=1,\ 136 sz=1,st=1,\ 137 svx=1,\ 138 svy=1,\ 139 139 compute="mean",\ 140 140 verbose=False,\ … … 155 155 vmin=None,vmax=None,\ 156 156 div=None,\ 157 colorb =None,\158 l style=None,\157 colorbar=None,\ 158 linestyle=None,\ 159 159 marker=None,\ 160 160 color=None,\ 161 l abel=None,\161 legend=None,\ 162 162 changetime=None,\ 163 163 units=None,\ … … 187 187 self.x = x ; self.y = y ## if None, free dimension 188 188 self.z = z ; self.t = t ## if None, free dimension 189 self.s tridex = stridex ; self.stridey = stridey190 self.s tridez = stridez ; self.stridet = stridet191 self.s tridevecx = stridevecx192 self.s tridevecy = stridevecy189 self.sx = sx ; self.sy = sy 190 self.sz = sz ; self.st = st 191 self.svx = svx 192 self.svy = svy 193 193 self.compute = compute 194 194 self.verbose = verbose … … 214 214 self.vmin = vmin ; self.vmax = vmax 215 215 self.div = div 216 self.colorb = colorb217 self.l style = lstyle216 self.colorbar = colorbar 217 self.linestyle = linestyle 218 218 self.marker = marker 219 219 self.color = color 220 self.l abel = label220 self.legend = legend 221 221 self.units = units 222 222 self.title = title … … 253 253 self.x = other.x ; self.y = other.y ## if None, free dimension 254 254 self.z = other.z ; self.t = other.t ## if None, free dimension 255 self.s tridex = other.stridex ; self.stridey = other.stridey256 self.s tridez = other.stridez ; self.stridet = other.stridet255 self.sx = other.sx ; self.sy = other.sy 256 self.sz = other.sz ; self.st = other.st 257 257 self.verbose = other.verbose 258 258 self.noproj = other.noproj … … 268 268 self.vmin = other.vmin ; self.vmax = other.vmax 269 269 self.div = other.div 270 self.colorb = other.colorb271 self.l style = other.lstyle270 self.colorbar = other.colorbar 271 self.linestyle = other.linestyle 272 272 self.marker = other.marker 273 273 self.color = other.color 274 self.l abel = other.label274 self.legend = other.legend 275 275 self.units = other.units 276 276 self.title = other.title … … 597 597 obj.performtimechange() 598 598 # get strides 599 obj.s tridex = self.stridex ; obj.stridey = self.stridey600 obj.s tridez = self.stridez ; obj.stridet = self.stridet599 obj.sx = self.sx ; obj.sy = self.sy 600 obj.sz = self.sz ; obj.st = self.st 601 601 ### get index 602 602 obj.getindextime(dalist=st,ind=t) … … 643 643 # save fields in self.f for the user 644 644 self.f[count] = obj.field 645 # save a l abelin self.l for the user645 # save a legend in self.l for the user 646 646 self.l[count] = "_" 647 647 if self.nfin > 1: self.l[count] = self.l[count] + "f=#"+str(int(i+1))+'_' … … 734 734 for count in range(self.nplot): 735 735 pl = self.p[count] 736 masked = np.ma.masked_where(np.abs(pl.f ield) > self.missing,pl.field)737 pl.f ield = masked ; pl.field[pl.field.mask] = np.NaN736 masked = np.ma.masked_where(np.abs(pl.f) > self.missing,pl.f) 737 pl.f = masked ; pl.f[pl.f.mask] = np.NaN 738 738 return #self? 739 739 # ----------------------------------------------------- … … 791 791 plobj.define_from_var() 792 792 # generic 1D/2D: load field and coord in plot object 793 plobj.f ield= obj.field # field to be plotted794 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) 796 796 # -- useless in 1D but not used anyway 797 797 # specific 1D plot stuff 798 798 if dp == 1: 799 # -- a default l abel800 plobj.l abel= ""801 if self.nfin > 1: plobj.l abel = plobj.label+ " file #"+str(i+1)802 if self.nvin > 1: plobj.l abel = plobj.label+ " var "+plobj.var803 if self.nplott > 1: plobj.l abel = plobj.label+ " t="+str(self.t[t])804 if self.nplotz > 1: plobj.l abel = plobj.label+ " z="+str(self.z[z])805 if self.nploty > 1: plobj.l abel = plobj.label+ " y="+str(self.y[y])806 if self.nplotx > 1: plobj.l abel = 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]) 807 807 # specific 2d plot stuff 808 808 if dp == 2: 809 809 # -- light grey background for missing values 810 if type(plobj.f ield).__name__ in 'MaskedArray': plobj.axisbg = '0.75'810 if type(plobj.f).__name__ in 'MaskedArray': plobj.axisbg = '0.75' 811 811 # -- define if it is a map or a plot 812 812 plobj.mapmode = ( obj.method_x+obj.method_y == "freefree" \ … … 821 821 if self.title is not None: plobj.title = self.title 822 822 if self.units is not None: plobj.units = self.units 823 if self.colorb is not None: plobj.colorb = self.colorb823 if self.colorbar is not None: plobj.colorbar = self.colorbar 824 824 if self.modx is not None: plobj.modx = self.modx 825 825 if self.nxticks is not None: plobj.nxticks = self.nxticks … … 827 827 # -- 1D specific 828 828 if dp == 1: 829 if self.l style is not None: plobj.lstyle = self.lstyle829 if self.linestyle is not None: plobj.linestyle = self.linestyle 830 830 if self.marker is not None: plobj.marker = self.marker 831 831 if self.color is not None: plobj.color = self.color 832 if self.l abel is not None: plobj.label = self.label832 if self.legend is not None: plobj.legend = self.legend 833 833 # -- 2D specific 834 834 elif dp == 2: … … 836 836 if self.vmin is not None: plobj.vmin = self.vmin 837 837 if self.vmax is not None: plobj.vmax = self.vmax 838 plobj.s tridevecx = self.stridevecx839 plobj.s tridevecy = self.stridevecy838 plobj.svx = self.svx 839 plobj.svy = self.svy 840 840 # finally append plot object 841 841 self.p.append(plobj) … … 871 871 ########################################## 872 872 if condvar == "contour": 873 plobj. addcontour= self.request[i][j+1][t][z][y][x].field ; found += 1873 plobj.c = self.request[i][j+1][t][z][y][x].field ; found += 1 874 874 if condfile == "contour": 875 plobj. addcontour= self.request[i+1][j][t][z][y][x].field ; found += 1875 plobj.c = self.request[i+1][j][t][z][y][x].field ; found += 1 876 876 # see if there is a vector requested... 877 877 # (we use try because we might be at the end of the list) … … 883 883 # (in some cases we would do this twice but this is cheap) 884 884 if "vector" in condvar: 885 plobj. addvecx = self.request[i][j+found+1][t][z][y][x].field886 plobj. addvecy = self.request[i][j+found+2][t][z][y][x].field885 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 887 887 if "vector" in condfile: 888 plobj. addvecx = self.request[i+found+1][j][t][z][y][x].field889 plobj. addvecy = self.request[i+found+2][j][t][z][y][x].field888 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 890 890 count = count + 1 891 891 # COUNT PLOTS. if 0 just exit. … … 924 924 ## adapted space for labels etc 925 925 ## ... except for ortho because there is no label anyway 926 self.customplot = self.p[0].f ield.ndim == 2 \926 self.customplot = self.p[0].f.ndim == 2 \ 927 927 and self.p[0].mapmode == True \ 928 928 and self.p[0].proj not in ["ortho"] … … 953 953 # possibility to color lines according to a color map 954 954 # ... 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) 958 958 else: 959 pl.invert = False ; pl.l style = None # don't invert again axis959 pl.invert = False ; pl.linestyle = None # don't invert again axis 960 960 # set saved titles and labels 961 961 if self.plotin is None: … … 978 978 if self.verbose: print "**** Printing results in a text file" 979 979 name = pl.var + "%04d" % self.n 980 ppplot.writeascii(field=pl.f ield,absc=pl.absc,name=name)980 ppplot.writeascii(field=pl.f,absc=pl.x,name=name) 981 981 # increment plot count (and propagate this in plotin) 982 982 self.n = self.n+1 … … 1044 1044 while count < self.howmanyplots: 1045 1045 sobj = self.p[count] ; oobj = other.p[count] 1046 if sobj.f ield.ndim !=1 or oobj.field.ndim !=1:1046 if sobj.f.ndim !=1 or oobj.f.ndim !=1: 1047 1047 if self.verbose: print "!! WARNING !! Flattening arrays because more than one-dimensional." 1048 sobj.f ield = np.ravel(sobj.field)1049 oobj.f ield = np.ravel(oobj.field)1050 sobj. absc = oobj.field1048 sobj.f = np.ravel(sobj.f) 1049 oobj.f = np.ravel(oobj.f) 1050 sobj.x = oobj.f 1051 1051 sobj.xlabel = oobj.ylabel 1052 if sobj. absc.size > sobj.field.size:1052 if sobj.x.size > sobj.f.size: 1053 1053 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.size1054 print "!! WARNING !! Trying to define y=f(x) with x and y not at the same size.",sobj.x.size,sobj.f.size 1055 1055 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] 1057 1057 count = count + 1 1058 1058 return self … … 1083 1083 except: pass 1084 1084 ### 1085 try: self.p[iii].colorb = opt.colorb[iii]1085 try: self.p[iii].colorbar = opt.colorbar[iii] 1086 1086 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] 1088 1088 except: pass 1089 1089 ### … … 1112 1112 except: pass 1113 1113 ### 1114 try: self.p[iii].l style = opt.lstyle[iii]1114 try: self.p[iii].linestyle = opt.linestyle[iii] 1115 1115 except: 1116 try: self.p[iii].l style = opt.lstyle[0]1116 try: self.p[iii].linestyle = opt.linestyle[0] 1117 1117 except: pass 1118 1118 ### … … 1127 1127 except: pass 1128 1128 ### 1129 try: self.p[iii].l abel = opt.label[iii]1129 try: self.p[iii].legend = opt.legend[iii] 1130 1130 except: 1131 try: self.p[iii].l abel = opt.label[0]1131 try: self.p[iii].legend = opt.legend[0] 1132 1132 except: pass 1133 1133 ### … … 1242 1242 self.compute = None 1243 1243 self.changetime = None 1244 self.s tridex = 1 ; self.stridey = 1 ; self.stridez = 1 ; self.stridet = 11244 self.sx = 1 ; self.sy = 1 ; self.sz = 1 ; self.st = 1 1245 1245 self.missing = '!! missing value: I am not set, damned !!' 1246 1246 … … 1462 1462 def getindextime(self,dalist=None,ind=None): 1463 1463 if self.method_t == "free": 1464 self.index_t = np.arange(0,self.dim_t,self.st ridet)1464 self.index_t = np.arange(0,self.dim_t,self.st) 1465 1465 if self.dim_t > 1: 1466 1466 self.dimplot = self.dimplot + 1 … … 1472 1472 start = np.argmin( np.abs( self.field_t - dalist[ind][0] ) ) 1473 1473 stop = np.argmin( np.abs( self.field_t - dalist[ind][1] ) ) 1474 self.index_t = np.arange(start,stop,self.st ridet)1474 self.index_t = np.arange(start,stop,self.st) 1475 1475 if self.verbose: print "**** OK. t values. comp over interval ",self.field_t[start],self.field_t[stop]," nvalues=",self.index_t.size 1476 1476 elif self.method_t == "fixed": … … 1486 1486 def getindexvert(self,dalist=None,ind=None): 1487 1487 if self.method_z == "free": 1488 self.index_z = np.arange(0,self.dim_z,self.s tridez)1488 self.index_z = np.arange(0,self.dim_z,self.sz) 1489 1489 if self.dim_z > 1: 1490 1490 self.dimplot = self.dimplot + 1 … … 1496 1496 start = np.argmin( np.abs( self.field_z - dalist[ind][0] ) ) 1497 1497 stop = np.argmin( np.abs( self.field_z - dalist[ind][1] ) ) 1498 self.index_z = np.arange(start,stop,self.s tridez)1498 self.index_z = np.arange(start,stop,self.sz) 1499 1499 if self.verbose: print "**** OK. z values. comp over interval",self.field_z[start],self.field_z[stop]," nvalues=",self.index_z.size 1500 1500 elif self.method_z == "fixed": … … 1521 1521 ## - LON IS COMP AND LAT IS FREE 1522 1522 if self.method_x == "free" or test in ["compfree","compcomp"]: 1523 self.index_x = range(0,self.dim_x,self.s tridex)1523 self.index_x = range(0,self.dim_x,self.sx) 1524 1524 if self.dim_x > 1: 1525 1525 if self.method_x == "free": self.dimplot = self.dimplot + 1 … … 1529 1529 if self.verbose: print "**** OK. no x dimension." 1530 1530 if self.method_y == "free" or test in ["freecomp","compcomp"]: 1531 self.index_y = range(0,self.dim_y,self.s tridey)1531 self.index_y = range(0,self.dim_y,self.sy) 1532 1532 if self.dim_y > 1: 1533 1533 if self.method_y == "free": self.dimplot = self.dimplot + 1 … … 1663 1663 # ... there are special cases with strides 1664 1664 # ... some other fixes will be needed probably TBD 1665 if self.method_x == "free" and self.s tridex != 1:1665 if self.method_x == "free" and self.sx != 1: 1666 1666 self.field_x = self.field_x[self.index_x] 1667 if self.method_y == "free" and self.s tridey != 1:1667 if self.method_y == "free" and self.sy != 1: 1668 1668 self.field_y = self.field_y[self.index_y] 1669 1669 self.field_z = self.field_z[self.index_z] … … 1675 1675 pass 1676 1676 elif test in ["fixedfree","fixedcomp"] or test in ["freefixed","compfixed"]: 1677 if self.s tridex == 1 and self.stridey == 1:1677 if self.sx == 1 and self.sy == 1: 1678 1678 time0 = timelib.time() 1679 1679 # now have to obtain the new indexes which correspond to the extracted self.field -
trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py
r1040 r1050 318 318 print "!! ERROR !! File format not supported. Supported: ",possiblesave 319 319 320 # a necessary addition for people used to matplotlib 321 def show(): 322 mpl.show() 323 320 324 ################################## 321 325 # a generic class to make a plot # … … 336 340 def __init__(self,\ 337 341 var=None,\ 338 f ield=None,\339 absc=None,\342 f=None,\ 343 x=None,\ 340 344 xlabel="",\ 341 345 ylabel="",\ … … 349 353 ycoeff=1.,\ 350 354 fmt=None,\ 351 colorb ="jet",\355 colorbar="jet",\ 352 356 units="",\ 353 357 modx=None,\ … … 361 365 ## what could be defined by the user 362 366 self.var = var 363 self.f ield = field364 self. absc = absc367 self.f = f 368 self.x = x 365 369 self.xlabel = xlabel 366 370 self.ylabel = ylabel … … 376 380 self.fmt = fmt 377 381 self.units = units 378 self.colorb = colorb382 self.colorbar = colorbar 379 383 self.modx = modx 380 384 self.xmin = xmin … … 392 396 # ------------------------------- 393 397 def check(self): 394 if self.f ieldis None: print "!! ERROR !! Please define a field to be plotted" ; exit()395 else: self.f ield = np.array(self.field) # ensure this is a numpy array398 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 396 400 397 401 # define_from_var … … 418 422 mpl.title(self.title) 419 423 # if masked array, set masked values to filled values (e.g. np.nan) for plotting purposes 420 if type(self.f ield).__name__ in 'MaskedArray':421 self.f ield[self.field.mask] = self.field.fill_value424 if type(self.f).__name__ in 'MaskedArray': 425 self.f[self.f.mask] = self.f.fill_value 422 426 423 427 ################################ … … 438 442 # ------------------------------- 439 443 def __init__(self,\ 440 l style=None,\444 linestyle=None,\ 441 445 color=None,\ 442 446 marker='x',\ 443 l abel=None):447 legend=None): 444 448 ## get initialization from parent class 445 449 plot.__init__(self) 446 450 ## what could be defined by the user 447 self.l style = lstyle451 self.linestyle = linestyle 448 452 self.color = color 449 453 self.marker = marker 450 self.l abel = label454 self.legend = legend 451 455 452 456 # define_from_var … … 471 475 # add specific stuff 472 476 mpl.grid(color='grey') 473 if self.l style == "": self.lstyle = " " # to allow for no line at all with ""477 if self.linestyle == "": self.linestyle = " " # to allow for no line at all with "" 474 478 # set dummy x axis if not defined 475 if self. abscis 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])) 477 481 print "!! WARNING !! dummy coordinates on x axis" 478 482 else: 479 self. absc = np.array(self.absc) # ensure this is a numpy array483 self.x = np.array(self.x) # ensure this is a numpy array 480 484 # swapping if requested 481 if self.swap: x = self.f ield ; y = self.absc482 else: x = self. absc ; y = self.field485 if self.swap: x = self.f ; y = self.x 486 else: x = self.x ; y = self.f 483 487 # coefficients on axis 484 488 x=x*self.xcoeff ; y=y*self.ycoeff … … 489 493 # make the 1D plot 490 494 # either request linestyle or let matplotlib decide 491 if self.l style is not None and self.color is not None:492 mpl.plot(x,y,self.color+self.l style,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) 493 497 elif self.color is not None: 494 mpl.plot(x,y,color=self.color,marker=self.marker,label=self.l abel)495 elif self.l style is not None:496 mpl.plot(x,y,linestyle=self.l style,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) 497 501 else: 498 mpl.plot(x,y,marker=self.marker,label=self.l abel)502 mpl.plot(x,y,marker=self.marker,label=self.legend) 499 503 # AXES 500 504 ax = mpl.gca() … … 510 514 self.xmin,self.xmax = self.xmax,self.xmin 511 515 # add a label for line(s) 512 if self.l abelis not None:513 if self.l abel!= "":516 if self.legend is not None: 517 if self.legend != "": 514 518 mpl.legend(loc="best",fancybox=True) 515 519 # format labels … … 544 548 ax = labelmodulo(ax,self.modx) 545 549 550 # makeshow = make + show 551 # ------------------------------- 552 def makeshow(self): 553 self.make() 554 mpl.show() 555 546 556 ################################ 547 557 # a subclass to make a 2D plot # … … 561 571 # ------------------------------- 562 572 def __init__(self,\ 563 ordi=None,\573 y=None,\ 564 574 mapmode=False,\ 565 575 proj="cyl",\ 566 576 back=None,\ 567 577 trans=1.0,\ 568 addvecx=None,\569 addvecy=None,\570 addcontour=None,\578 vx=None,\ 579 vy=None,\ 580 c=None,\ 571 581 blon=None,\ 572 582 blat=None,\ … … 576 586 showcb=True,\ 577 587 wscale=None,\ 578 s tridevecx=1,\579 s tridevecy=1,\588 svx=1,\ 589 svy=1,\ 580 590 leftcorrect=False,\ 581 591 colorvec="black"): … … 583 593 plot.__init__(self) 584 594 ## what could be defined by the user 585 self. ordi = ordi595 self.y = y 586 596 self.mapmode = mapmode 587 597 self.proj = proj 588 598 self.back = back 589 599 self.trans = trans 590 self. addvecx = addvecx591 self. addvecy = addvecy600 self.vx = vx 601 self.vy = vy 592 602 self.colorvec = colorvec 593 self. addcontour = addcontour603 self.c = c 594 604 self.blon = blon ; self.blat = blat 595 605 self.area = area … … 597 607 self.showcb = showcb 598 608 self.wscale = wscale 599 self.s tridevecx = stridevecx600 self.s tridevecy = stridevecy609 self.svx = svx 610 self.svy = svy 601 611 self.leftcorrect = leftcorrect 602 612 … … 610 620 if self.var is not None: 611 621 if self.var.upper() in vl.keys(): 612 self.colorb = vc[self.var.upper()]622 self.colorbar = vc[self.var.upper()] 613 623 self.fmt = vf[self.var.upper()] 614 624 … … 624 634 ############################################################################################ 625 635 # set dummy xy axis if not defined 626 if self. abscis 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])) 628 638 self.mapmode = False 629 639 print "!! WARNING !! dummy coordinates on x axis" 630 if self. ordiis 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])) 632 642 self.mapmode = False 633 643 print "!! WARNING !! dummy coordinates on y axis" 634 644 # transposing if necessary 635 shape = self.f ield.shape645 shape = self.f.shape 636 646 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]: 638 648 print "!! WARNING !! Transposing axes" 639 self.f ield = np.transpose(self.field)649 self.f = np.transpose(self.f) 640 650 # bound field 641 zevmin, zevmax = calculate_bounds(self.f ield,vmin=self.vmin,vmax=self.vmax)642 what_I_plot = bounds(self.f ield,zevmin,zevmax)651 zevmin, zevmax = calculate_bounds(self.f,vmin=self.vmin,vmax=self.vmax) 652 what_I_plot = bounds(self.f,zevmin,zevmax) 643 653 # define contour field levels. define color palette 644 654 ticks = self.div + 1 645 655 zelevels = np.linspace(zevmin,zevmax,ticks) 646 palette = get_cmap(name=self.colorb )656 palette = get_cmap(name=self.colorbar) 647 657 # do the same thing for possible contourline entries 648 if self. addcontouris not None:658 if self.c is not None: 649 659 # 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_value652 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) 654 664 ticks = self.div + 1 655 665 zelevelsc = np.linspace(zevminc,zevmaxc,ticks) … … 662 672 ################### 663 673 # swapping if requested 664 if self.swap: x = self. ordi ; y = self.absc665 else: x = self. absc ; y = self.ordi674 if self.swap: x = self.y ; y = self.x 675 else: x = self.x ; y = self.y 666 676 # coefficients on axis 667 677 x=x*self.xcoeff ; y=y*self.ycoeff 668 678 # make shaded and line contours 669 if self. addcontouris not None:679 if self.c is not None: 670 680 objC = mpl.contour(x, y, what_I_contour, \ 671 681 zelevelsc, colors = ccol, linewidths = cline) … … 673 683 # inline_spacing=1,fmt="%.0f") 674 684 mpl.contourf(x, y, \ 675 self.f ield, \685 self.f, \ 676 686 zelevels, cmap=palette) 677 687 #mpl.pcolor(x,y,\ 678 # self.f ield, \688 # self.f, \ 679 689 # cmap=palette) 680 690 # make log axes and/or invert ordinate … … 708 718 # get lon and lat in 2D version. 709 719 # (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" 712 722 # 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)] 715 725 # -- area presets are in set_area.txt 716 726 if self.area is not None: … … 800 810 print "!! ERROR !! requested background not defined. change name or fill in set_back.txt" ; exit() 801 811 # define x and y given the projection 802 x, y = m(self. absc, self.ordi)812 x, y = m(self.x, self.y) 803 813 # contour field. first line contour then shaded contour. 804 if self. addcontouris not None:814 if self.c is not None: 805 815 objC2 = m.contour(x, y, what_I_contour, \ 806 816 zelevelsc, colors = ccol, linewidths = cline) … … 829 839 ### VECTORS. must be after the colorbar. we could also leave possibility for streamlines. 830 840 ############################################################################################ 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: 833 843 # vectors on map projection or simple 2D mapping 834 844 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 ? 836 846 else: 837 vecx,vecy = self. addvecx,self.addvecy847 vecx,vecy = self.vx,self.vy 838 848 if x.ndim < 2 and y.ndim < 2: x,y = np.meshgrid(x,y) 839 849 # reference vector is scaled 840 850 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)) 842 852 # make vector field 843 853 if self.mapmode: 844 q = m.quiver( x[::self.s tridevecy,::self.stridevecx],y[::self.stridevecy,::self.stridevecx],\845 vecx[::self.s tridevecy,::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],\ 846 856 angles='xy',color=self.colorvec,pivot='tail',\ 847 857 scale=self.wscale*reducevec,width=widthvec ) 848 858 else: 849 q = mpl.quiver( x[::self.s tridevecy,::self.stridevecx],y[::self.stridevecy,::self.stridevecx],\850 vecx[::self.s tridevecy,::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],\ 851 861 angles='xy',color=self.colorvec,pivot='tail',\ 852 862 scale=self.wscale*reducevec,width=widthvec ) … … 880 890 except IOError: 881 891 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.