Changeset 981 for trunk/UTIL/PYTHON


Ignore:
Timestamp:
Jun 7, 2013, 1:22:11 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. added support for wind vectors in 2D section (not only maps, thanks Benjamin for the request). fixed stride problems (not all though). now to stride vectors simply use the stride command, this is more flexible. added stride to pp.py. also corrected a bug for logx axis (thanks Alizee)

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

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/planetoplot_v2/pp.py

    r977 r981  
    4848parser.add_option('-c','--contour',action='store',dest='contour',type="string",default=None,help="one 'variable' for contour")
    4949parser.add_option('-i','--vecx',action='store',dest='vecx',type="string",default=None,help="one 'variable' for wind vector x component")
    50 parser.add_option('-j','--vecy',action='store',dest='vecy',type="string",default=None,help="one 'variable' for wind vector x component")
     50parser.add_option('-j','--vecy',action='store',dest='vecy',type="string",default=None,help="one 'variable' for wind vector y component")
    5151parser.add_option('-m','--mult',action='store',dest='mult',type="float",default=None,help="multiplicative factor on field")
    5252parser.add_option('-a','--add',action='store',dest='add',type="float",default=None,help="additive factor on field")
     
    5555parser.add_option('-s','--changetime',action='store',dest='changetime',type="string",default=None,\
    5656                  help="transformation on time axis : [None] | mars_sol2ls | mars_meso_ls | mars_meso_sol | mars_meso_utc | mars_meso_lt ")
     57parser.add_option('--stridex',action='store',dest='stridex',type="int",default=1,help="Load data every stridex grid points over x dimension")
     58parser.add_option('--stridey',action='store',dest='stridey',type="int",default=1,help="Load data every stridex grid points over y dimension")
     59parser.add_option('--stridez',action='store',dest='stridez',type="int",default=1,help="Load data every stridex grid points over z dimension")
     60parser.add_option('--stridet',action='store',dest='stridet',type="int",default=1,help="Load data every stridex grid points over t dimension")
    5761# plot --> upper case
    5862# -- generic
     
    125129user.compute = opt.compute
    126130user.changetime = opt.changetime
     131user.stridex = opt.stridex
     132user.stridey = opt.stridey
     133user.stridez = opt.stridez
     134user.stridet = opt.stridet
    127135# define field
    128136user.define()
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r978 r981  
    572572              obj.changetime = self.changetime
    573573              obj.performtimechange()
     574              # get strides
     575              obj.stridex = self.stridex ; obj.stridey = self.stridey
     576              obj.stridez = self.stridez ; obj.stridet = self.stridet
    574577              ### get index
    575               obj.getindextime(dalist=st,ind=t,stride=self.stridet)
    576               obj.getindexvert(dalist=sz,ind=z,stride=self.stridez)
    577               obj.getindexhori(dalistx=sx,dalisty=sy,indx=x,indy=y,stridex=self.stridex,stridey=self.stridey)
     578              obj.getindextime(dalist=st,ind=t)
     579              obj.getindexvert(dalist=sz,ind=z)
     580              obj.getindexhori(dalistx=sx,dalisty=sy,indx=x,indy=y)
    578581        # change status
    579582        self.status = "defined"
     
    11911194        self.compute = None
    11921195        self.changetime = None
     1196        self.stridex = 1 ; self.stridey = 1 ; self.stridez = 1 ; self.stridet = 1
    11931197
    11941198    # open a file. for now it is netcdf. TBD for other formats.
     
    13641368    ### TBD: il faudrait ne prendre que les indices qui correspondent a l interieur d un plot (dans all)
    13651369    # -------------------------------
    1366     def getindextime(self,dalist=None,ind=None,stride=1):
     1370    def getindextime(self,dalist=None,ind=None):
    13671371        if self.method_t == "free":
    1368             self.index_t = np.arange(0,self.dim_t,stride)
     1372            self.index_t = np.arange(0,self.dim_t,self.stridet)
    13691373            if self.dim_t > 1: 
    13701374                self.dimplot = self.dimplot + 1
     
    13761380            start = np.argmin( np.abs( self.field_t - dalist[ind][0] ) )
    13771381            stop = np.argmin( np.abs( self.field_t - dalist[ind][1] ) )
    1378             self.index_t = np.arange(start,stop,stride)
     1382            self.index_t = np.arange(start,stop,self.stridet)
    13791383            if self.verbose: print "**** OK. t values. comp over interval ",self.field_t[start],self.field_t[stop]," nvalues=",self.index_t.size
    13801384        elif self.method_t == "fixed":
     
    13881392    ### TBD: il faudrait ne prendre que les indices qui correspondent a l interieur d un plot (dans all)
    13891393    # -------------------------------
    1390     def getindexvert(self,dalist=None,ind=None,stride=1):
     1394    def getindexvert(self,dalist=None,ind=None):
    13911395        if self.method_z == "free":
    1392             self.index_z = np.arange(0,self.dim_z,stride)
     1396            self.index_z = np.arange(0,self.dim_z,self.stridez)
    13931397            if self.dim_z > 1: 
    13941398                self.dimplot = self.dimplot + 1
     
    14001404            start = np.argmin( np.abs( self.field_z - dalist[ind][0] ) )
    14011405            stop = np.argmin( np.abs( self.field_z - dalist[ind][1] ) )
    1402             self.index_z = np.arange(start,stop,stride)
     1406            self.index_z = np.arange(start,stop,self.stridez)
    14031407            if self.verbose: print "**** OK. z values. comp over interval",self.field_z[start],self.field_z[stop]," nvalues=",self.index_z.size
    14041408        elif self.method_z == "fixed":
     
    14161420    ### TBD: il faudrait ne prendre que les indices qui correspondent a l interieur d un plot (dans all)
    14171421    # -------------------------------
    1418     def getindexhori(self,dalistx=None,dalisty=None,indx=None,indy=None,stridex=1,stridey=1):
     1422    def getindexhori(self,dalistx=None,dalisty=None,indx=None,indy=None):
    14191423        ## get what is the method over x and y axis
    14201424        test = self.method_x+self.method_y
     
    14251429        ## - LON IS COMP AND LAT IS FREE
    14261430        if self.method_x == "free" or test in ["compfree","compcomp"]:
    1427             self.index_x = range(0,self.dim_x,stridex)
     1431            self.index_x = range(0,self.dim_x,self.stridex)
    14281432            if self.dim_x > 1: 
    14291433                if self.method_x == "free": self.dimplot = self.dimplot + 1
     
    14331437                if self.verbose: print "**** OK. no x dimension."
    14341438        if self.method_y == "free" or test in ["freecomp","compcomp"]:
    1435             self.index_y = range(0,self.dim_y,stridey)
     1439            self.index_y = range(0,self.dim_y,self.stridey)
    14361440            if self.dim_y > 1: 
    14371441                if self.method_y == "free": self.dimplot = self.dimplot + 1
     
    15651569          self.field_x = self.field_x[self.index_y2d, self.index_x2d]
    15661570          self.field_y = self.field_y[self.index_y2d, self.index_x2d]
     1571          # ... there are special cases with strides
     1572          # ... some other fixes will be needed probably TBD
     1573          if self.method_x == "free" and self.stridex != 1:
     1574              self.field_x = self.field_x[self.index_x]
     1575          if self.method_y == "free" and self.stridey != 1:
     1576              self.field_y = self.field_y[self.index_y]
    15671577        self.field_z = self.field_z[self.index_z]
    15681578        self.field_t = self.field_t[self.index_t]
     
    15731583          pass
    15741584        elif test in ["fixedfree","fixedcomp"] or test in ["freefixed","compfixed"]:
     1585         if self.stridex == 1 and self.stridey == 1:
    15751586          time0 = timelib.time()
    15761587          # now have to obtain the new indexes which correspond to the extracted self.field
     
    16061617          if what_I_am_supposed_to_do == "keepx":     self.field = self.field[:,:,0,:] ; ny = 1 ; self.field = np.reshape(self.field,(nt,nz,ny,nx))
    16071618          elif what_I_am_supposed_to_do == "keepy":   self.field = self.field[:,:,:,0] ; nx = 1 ; self.field = np.reshape(self.field,(nt,nz,ny,nx))
     1619         else:
     1620          # there is a problem above if stride != 1. a fix must be found. rewrite might be necessary. TBD
     1621          pass
    16081622        # make a mask in case there are non-NaN missing values. (what about NaN missing values?)
    16091623        # ... this is important for computations below (see ppcompute)
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r977 r981  
    476476        ax.set_ybound(lower=y1,upper=y2)
    477477        ## set with .div the number of ticks. (is it better than automatic?)
    478         ax.xaxis.set_major_locator(MaxNLocator(self.div/2))
     478        if not self.logx:
     479            ax.xaxis.set_major_locator(MaxNLocator(self.div/2))
     480        else:
     481            print "!! WARNING. in logx mode, ticks are set automatically."
    479482
    480483################################
     
    727730        ### not expecting NaN in self.addvecx and self.addvecy. masked arrays is just enough.
    728731        stride = 3
    729         #stride = 1
    730         if self.addvecx is not None and self.addvecy is not None and self.mapmode:
    731                 ### for metwinds only ???
    732                 [vecx,vecy] = m.rotate_vector(self.addvecx,self.addvecy,self.absc,self.ordi)
    733                 #vecx,vecy = self.addvecx,self.addvecy
     732        stride = 1 ## no need to stride. done with data. except if you want to stride wind and not field TBD.
     733        if self.addvecx is not None and self.addvecy is not None:
     734                if self.mapmode: [vecx,vecy] = m.rotate_vector(self.addvecx,self.addvecy,self.absc,self.ordi) # for metwinds only ?
     735                else: vecx,vecy = self.addvecx,self.addvecy ; x,y = np.meshgrid(x,y)
    734736                # reference vector is scaled
    735737                if self.wscale is None: self.wscale = ppcompute.mean(np.sqrt(self.addvecx*self.addvecx+self.addvecy*self.addvecy))
    736738                # make vector field
    737                 q = m.quiver( x[::stride,::stride],y[::stride,::stride],\
    738                               vecx[::stride,::stride],vecy[::stride,::stride],\
    739                               angles='xy',color=self.colorvec,pivot='middle',\
    740                               scale=self.wscale*reducevec,width=widthvec )
     739                if self.mapmode:
     740                    q = m.quiver( x[::stride,::stride],y[::stride,::stride],\
     741                                  vecx[::stride,::stride],vecy[::stride,::stride],\
     742                                  angles='xy',color=self.colorvec,pivot='tail',\
     743                                  scale=self.wscale*reducevec,width=widthvec )
     744                else:
     745                    q = mpl.quiver( x[::stride,::stride],y[::stride,::stride],\
     746                                    vecx[::stride,::stride],vecy[::stride,::stride],\
     747                                    angles='xy',color=self.colorvec,pivot='tail',\
     748                                    scale=self.wscale*reducevec,width=widthvec )
    741749                # make vector key.
    742750                #keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar
  • trunk/UTIL/PYTHON/planetoplot_v2/set_ppclass.txt

    r977 r981  
    1010  # z-axis: possible names to search for. add in the line with a separating ;
    1111  #
    12 altitude;Alt;vert;presnivs;bottom_top;altitude_abg
     12altitude;Alt;vert;presnivs;bottom_top;altitude_abg;lev
    1313  # t-axis: possible names to search for. add in the line with a separating ;
    1414  #
Note: See TracChangeset for help on using the changeset viewer.