Changeset 936 for trunk/UTIL


Ignore:
Timestamp:
Apr 22, 2013, 8:31:47 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. fixed bug with minimum close to 0. number of ticks in 1D plots can be set with self.div. better labelling (actual values). better handling of time in case this is Ls.

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

Legend:

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

    r934 r936  
    710710                        plobj.label = ""
    711711                        if self.nfin > 1: plobj.label = plobj.label + " file #"+str(i+1)
    712                         if self.nvin > 1: plobj.label = plobj.label + " var #"+str(j+1)
    713                         if self.nplott > 1: plobj.label = plobj.label + " t #"+str(t+1)
    714                         if self.nplotz > 1: plobj.label = plobj.label + " z #"+str(z+1)
    715                         if self.nploty > 1: plobj.label = plobj.label + " y #"+str(y+1)
    716                         if self.nplotx > 1: plobj.label = plobj.label + " x #"+str(x+1)
     712                        if self.nvin > 1: plobj.label = plobj.label + " var "+plobj.var
     713                        if self.nplott > 1: plobj.label = plobj.label + " t="+str(self.t[t])
     714                        if self.nplotz > 1: plobj.label = plobj.label + " z="+str(self.z[z])
     715                        if self.nploty > 1: plobj.label = plobj.label + " y="+str(self.y[y])
     716                        if self.nplotx > 1: plobj.label = plobj.label + " x="+str(self.x[x])
    717717                    # specific 2d plot stuff
    718718                    if dp == 2:
     
    11741174          self.name_t = "nothing"
    11751175          for c in glob_listt:
    1176             if c in self.f.dimensions.keys():
     1176            if c in self.f.variables.keys():
    11771177             self.name_t = c
     1178             if self.verbose: print "**** OK. Found time variable: ",c
    11781179          try:
    11791180            # speed up: only get first value, last one.
    1180             dafirst = self.f.variables[self.name_t][0]
    1181             dalast = self.f.variables[self.name_t][self.dim_t-1]
    1182             self.field_t = np.linspace(dafirst,dalast,num=self.dim_t)
    1183             if dafirst == dalast: self.field_t = np.array([dafirst])
     1181            tabtime = self.f.variables[self.name_t]
     1182            # (consider the case where tabtime is not dim 1)
     1183            # (time is most often the first dimension)
     1184            if tabtime.ndim == 2: tabtime = tabtime[:,0]
     1185            elif tabtime.ndim == 3: tabtime = tabtime[:,0,0]
     1186            elif tabtime.ndim == 4: tabtime = tabtime[:,0,0,0]
     1187            # (now proceed)
     1188            dafirst = tabtime[0]
     1189            if self.dim_t == 1:
     1190                self.field_t = np.array([dafirst])
     1191            else:
     1192                daint = tabtime[1] - dafirst
     1193                dalast = dafirst + (self.dim_t-1)*daint
     1194                if dalast != tabtime[self.dim_t-1] and self.verbose:
     1195                    print "!! WARNING !! Time axis has been recast to be monotonic",dalast,tabtime[self.dim_t-1]
     1196                self.field_t = np.linspace(dafirst,dalast,num=self.dim_t)
    11841197          except:
    11851198            # ... or if a problem encountered, define a simple time axis
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r933 r936  
    1212from matplotlib.cm import get_cmap
    1313from mpl_toolkits.basemap import Basemap
    14 from matplotlib.ticker import FormatStrFormatter
     14from matplotlib.ticker import FormatStrFormatter,MaxNLocator
    1515# personal librairies
    1616import ppcompute
     
    219219    amin = ppcompute.min(field)
    220220    amax = ppcompute.max(field)
    221     cmin = 100.*np.abs((amin - zevmin)/amin)
     221    if np.abs(amin) < 1.e-15:
     222        zevmin = 0.
     223        cmin = 0.
     224    else:
     225        cmin = 100.*np.abs((amin - zevmin)/amin)
    222226    cmax = 100.*np.abs((amax - zevmax)/amax)
    223227    if cmin > 150. or cmax > 150.:
     
    430434        ax = mpl.gca()
    431435        # format labels
    432         if self.swap: ax.get_xaxis().set_major_formatter(FormatStrFormatter(self.fmt))
    433         else: ax.get_yaxis().set_major_formatter(FormatStrFormatter(self.fmt))
     436        if self.swap: ax.xaxis.set_major_formatter(FormatStrFormatter(self.fmt))
     437        else: ax.yaxis.set_major_formatter(FormatStrFormatter(self.fmt))
    434438        # plot limits: ensure that no curve would be outside the window
    435439        # x-axis
     
    447451        if ymax > y2: y2 = ymax
    448452        ax.set_ybound(lower=y1,upper=y2)
    449         ## set with .div the number of ticks. less good than automatic.
    450         #ticks = self.div + 1
    451         #ax.get_xaxis().set_ticks(np.linspace(x1,x2,ticks/2+1))
     453        ## set with .div the number of ticks. (is it better than automatic?)
     454        ax.xaxis.set_major_locator(MaxNLocator(self.div/2))
    452455
    453456################################
     
    586589                wlon, wlat = area[self.area]
    587590            # -- settings for meridians and parallels
    588             steplon = abs(wlon[1]-wlon[0])/6.
    589             steplat = abs(wlat[1]-wlat[0])/3.
    590             mertab = np.r_[wlon[0]:wlon[1]:steplon] ; merlab = [0,0,0,1]
    591             partab = np.r_[wlat[0]:wlat[1]:steplat] ; parlab = [1,0,0,0]
     591            steplon = int(abs(wlon[1]-wlon[0])/6.)
     592            steplat = int(abs(wlat[1]-wlat[0])/3.)
     593            #mertab = np.r_[wlon[0]:wlon[1]:steplon] ; merlab = [0,0,0,1]
     594            #partab = np.r_[wlat[0]:wlat[1]:steplat] ; parlab = [1,0,0,0]
     595            mertab = np.r_[-360.:360.:steplon] ; merlab = [0,0,0,1]
     596            partab = np.r_[-90.:90.:steplat] ; parlab = [1,0,0,0]
    592597            format = '%.1f'
    593598            # -- center of domain and bounding lats
  • trunk/UTIL/PYTHON/planetoplot_v2/set_ppclass.txt

    r921 r936  
    1313  # t-axis: possible names to search for. add in the line with a separating ;
    1414  #
    15 Times;time;Time;time_counter
     15Times;time;Time;time_counter;Ls
    1616  # area: possible names to search for. add in the line with a separating ;
    1717  #
Note: See TracChangeset for help on using the changeset viewer.