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)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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)
Note: See TracChangeset for help on using the changeset viewer.