Changeset 1029 for trunk/UTIL/PYTHON


Ignore:
Timestamp:
Sep 5, 2013, 2:28:49 PM (11 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2

  • added keywords nxticks nyticks xp yp missing for improved plot settings
  • added function to print contents of pp object
  • added to ppplot a function figureref to easily set a figure of given size
  • bug fix affecting .ppobj objects containing fields with missing values
  • bug fix when size of z coordinate do not match field
  • bug fix for Ls time coordinates (added changetime=correctls)
  • bug fix if not connected to internet
  • tidying up examples
Location:
trunk/UTIL/PYTHON/planetoplot_v2
Files:
26 added
16 deleted
5 edited
11 moved

Legend:

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

    r1027 r1029  
    33
    44anewversion = pp()
    5 anewversion.defineplot(loadfile="../demo_data/gw.ppobj")
     5anewversion.defineplot(loadfile="../../demo_data/gw.ppobj")
    66for plot in anewversion.p:
    77    plot.colorb = "Paired"
    8     plot.title = "This is a psychedelic plot"
     8    plot.title = "Psychedelic plot!"
    99anewversion.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/additional/vertpress.py

    r1027 r1029  
    44prof = pp()
    55prof.verbose = True
    6 prof.file = "/home/aymeric/Big_Data/case_night.nc"
     6#prof.file = "/home/aymeric/Big_Data/case_night.nc"
     7prof.file = "/home/aymeric/Big_Data/GALE/wrfout_d03_2024-06-09_00:00:00_z"
    78prof.var = "tk"
    89prof.t = [10.,20.]
    9 prof.x = 30
    10 prof.y = 30
     10prof.x = -5. #30
     11prof.y = 138. #30
    1112prof.filename = "vertpress"
    1213
  • trunk/UTIL/PYTHON/planetoplot_v2/pp.py

    r1015 r1029  
    5454parser.add_option('-d','--directory',action='store',dest='folder',type="string",default="./",help="directory of output files")
    5555parser.add_option('-s','--changetime',action='store',dest='changetime',type="string",default=None,\
    56                   help="transformation on time axis : [None] | mars_sol2ls | mars_dayini | mars_meso_ls | mars_meso_sol | mars_meso_utc | mars_meso_lt ")
     56                  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")
    5858parser.add_option('--stridex',action='store',dest='stridex',type="int",default=1,help="Load data every stridex grid points over x dimension")
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r1015 r1029  
    151151                      xlabel=None,ylabel=None,\
    152152                      xcoeff=None,ycoeff=None,\
     153                      nxticks=10,nyticks=10,\
    153154                      proj=None,\
    154155                      vmin=None,vmax=None,\
     
    163164                      savtxt=False,\
    164165                      modx=None,\
     166                      xp=16,yp=8,\
     167                      missing=1.e25,\
    165168                      title=None):
    166169        self.request = None
     
    203206        self.savtxt = savtxt
    204207        self.modx = modx
     208        self.missing = missing
    205209        ## here are user-defined plot settings
    206210        ## -- if not None, valid on all plots in the pp() objects
     
    217221        self.units = units
    218222        self.title = title
     223        self.xp = xp ; self.yp = yp
     224        self.nxticks = nxticks ; self.nyticks = nyticks
    219225
    220226    # print status
     
    225231        else:
    226232            print "**** PPCLASS. Done step: " + self.status
     233
     234    # print attributes
     235    def printme(self):
     236        for k, v in vars(self).items():
     237            print k,v
    227238
    228239    #####################################################
     
    268279            self.savtxt = other.savtxt
    269280            self.modx = other.modx
     281            self.xp = other.xp ; self.yp = other.yp
     282            self.missing = other.missing
     283            self.nxticks = other.nxticks ; self.nyticks = other.nyticks
    270284        else:
    271285            print "!! ERROR !! argument must be a pp object." ; exit()
     
    589603              obj.getindexvert(dalist=sz,ind=z)
    590604              obj.getindexhori(dalistx=sx,dalisty=sy,indx=x,indy=y)
     605              # missing value
     606              obj.missing = self.missing
    591607        # change status
    592608        self.status = "defined"
     
    715731            self.status = "definedplot" ; self.plotin = None
    716732            self.nplot = len(self.p) ; self.howmanyplots = self.nplot
    717             return
     733            ## [BUG FIX: apparently info about missing values is not saved correctly]
     734            for count in range(self.nplot):
     735              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
     738            return #self?
    718739        # -----------------------------------------------------
    719740        # REGULAR MODE
     
    802823                    if self.colorb is not None: plobj.colorb = self.colorb
    803824                    if self.modx is not None: plobj.modx = self.modx
     825                    if self.nxticks is not None: plobj.nxticks = self.nxticks
     826                    if self.nyticks is not None: plobj.nyticks = self.nyticks
    804827                    # -- 1D specific
    805828                    if dp == 1:
     
    896919        if self.plotin is None: 
    897920            # start from scratch
    898             self.fig = mpl.figure(figsize=(16,8))
     921            self.fig = ppplot.figuref(x=self.xp,y=self.yp)
    899922            self.subv,self.subh = ppplot.definesubplot(self.howmanyplots,self.fig)
    900923            self.n = 0
     
    12201243        self.changetime = None
    12211244        self.stridex = 1 ; self.stridey = 1 ; self.stridez = 1 ; self.stridet = 1
     1245        self.missing = '!! missing value: I am not set, damned !!'
    12221246
    12231247    # open a file. for now it is netcdf. TBD for other formats.
     
    13091333               if self.verbose: print "**** OK. y axis %4.0f values [%5.1f,%5.1f]" % (self.dim_y,self.field_y.min(),self.field_y.max())
    13101334          # ALTITUDE. Try preset fields. If not present set grid points axis.
    1311           # WARNING: how do we do if several are available?
     1335          # WARNING: how do we do if several are available? the last one is chosen.
    13121336          self.name_z = "nothing"
    13131337          for c in glob_listz:
     
    13291353            else:
    13301354                self.field_z = self.f.variables[self.name_z][:] # specify dimension
     1355            # TBD: problems when self.dim_z != self.field_z.size
     1356            if self.field_z.size != self.dim_z:
     1357                if self.verbose: print "!! WARNING !! Cannot use this z coordinate. Not enough points. Use simple z axis."
     1358                self.field_z = np.array(range(self.dim_z))
     1359                self.name_z = "z grid points"
    13311360          if self.dim_z > 1:
    13321361               if self.verbose: print "**** OK. z axis %4.0f values [%5.1f,%5.1f]" % (self.dim_z,self.field_z.min(),self.field_z.max())
     1362
    13331363          # TIME. Try preset fields.
    13341364          self.name_t = "nothing"
     
    13511381            else:
    13521382                daint = tabtime[1] - dafirst
    1353                 dalast = dafirst + (self.dim_t-1)*daint
    1354                 if dalast != tabtime[self.dim_t-1] and self.verbose:
    1355                     print "!! WARNING !! Time axis has been recast to be monotonic",dalast,tabtime[self.dim_t-1]
     1383                dalast = dafirst + (self.dim_t-1)*daint
    13561384                self.field_t = np.linspace(dafirst,dalast,num=self.dim_t)
     1385                if self.verbose:
     1386                    print "!! WARNING !! WARNING !! Time axis is supposed to be equally spaced !!             
     1387                    if dalast != tabtime[self.dim_t-1]:
     1388                        print "!! WARNING !! Time axis has been recast to be monotonic",dalast,tabtime[self.dim_t-1]
    13571389          except:
    13581390            # ... or if a problem encountered, define a simple time axis
     
    13691401        if self.changetime is not None:
    13701402            if self.verbose: print "**** OK. Converting time axis:",self.changetime
    1371             ### option added by T. Navarro
     1403            ### options added by T. Navarro
    13721404            if self.changetime == "mars_sol2ls":
    13731405                if "controle" in self.f.variables:
     
    13811413                              + self.f.variables['controle'][26]
    13821414            ### options added by A. Spiga
     1415            elif self.changetime == "correctls":
     1416                # not regularly spaced + handle modulo 360. in files
     1417                dafirst = tabtime[0] + 0.
     1418                daint = tabtime[1] - dafirst
     1419                dalast = dafirst + (self.dim_t-1)*daint
     1420                year = 0.
     1421                add = np.linspace(dafirst,dalast,num=self.dim_t) ; add[0] = 0.
     1422                for iii in range(1,self.dim_t):
     1423                  if tabtime[iii] - tabtime[iii-1] < 0: year = year+1.
     1424                  add[iii] = year*360.
     1425                self.field_t = add + tabtime
    13831426            elif "mars_meso" in self.changetime:
    13841427                if 'Times' not in self.f.variables.keys():
     
    16711714        # make a mask in case there are non-NaN missing values. (what about NaN missing values?)
    16721715        # ... this is important for computations below (see ppcompute)
    1673         masked = np.ma.masked_where(np.abs(self.field) > 1e25,self.field)
     1716        masked = np.ma.masked_where(np.abs(self.field) > self.missing,self.field)
    16741717        if masked.mask.any() == True:
    1675              if self.verbose: print "!! WARNING !! Values over +-1e25 are considered missing values."
     1718             if self.verbose: print "!! WARNING !! Values over %5.3e are considered missing values." % self.missing
    16761719             self.field = masked
    16771720             self.field.set_fill_value([np.NaN])
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r1027 r1029  
    187187# a function for predefined figure sizes
    188188def figuref(x=16,y=9):
    189     mpl.figure(figsize=(x,y))
     189    fig = mpl.figure(figsize=(x,y))
     190    return fig
    190191
    191192# a function to change color lines according to a color map (idea by A. Pottier)
     
    208209        subv, subh = subv_t[numplot],subh_t[numplot]
    209210    except:
    210         print "!! WARNING !! no preset found from set_multiplot.txt, or this setting file was not found."
     211        print "!! WARNING !! (ignore if superpose mode) no preset found from set_multiplot.txt, or this setting file was not found."
    211212        subv = 1 ; subh = numplot
    212213    return subv,subh
     
    355356                 xmax=None,\
    356357                 ymax=None,\
     358                 nxticks=10,\
     359                 nyticks=10,\
    357360                 title=""):
    358361        ## what could be defined by the user
     
    379382        self.xmax = xmax
    380383        self.ymax = ymax
     384        self.nxticks = nxticks
     385        self.nyticks = nyticks
    381386        ## other useful arguments
    382387        ## ... not used here in ppplot but need to be attached to plot object
     
    532537        ## set with .div the number of ticks. (is it better than automatic?)
    533538        if not self.logx:
    534             ax.xaxis.set_major_locator(MaxNLocator(self.div/2))
     539            ax.xaxis.set_major_locator(MaxNLocator(self.div/2)) #TBD: with nxticks?
    535540        else:
    536541            print "!! WARNING. in logx mode, ticks are set automatically."
     
    684689            if self.ymin is not None: ax.set_ybound(lower=self.ymin)
    685690            if self.ymax is not None: ax.set_ybound(upper=self.ymax)
    686             # set the number of ticks (hardcoded)
    687             ax.xaxis.set_major_locator(MaxNLocator(10))
     691            # set the number of ticks
     692            if not self.logx:
     693                ax.xaxis.set_major_locator(MaxNLocator(self.nxticks))
     694            else:
     695                print "!! WARNING. in logx mode, ticks are set automatically."
    688696            ## specific modulo labels
    689697            if self.modx is not None:
     
    773781              if self.back in back.keys():
    774782                 print "**** info: loading a background, please wait.",self.back
    775                  if self.back not in ["coast","sea"]:   m.warpimage(back[self.back],scale=0.75)
    776                  elif self.back == "coast":             m.drawcoastlines()
    777                  elif self.back == "sea":               m.drawlsmask(land_color='white',ocean_color='aqua')
     783                 if self.back not in ["coast","sea"]:
     784                    try: m.warpimage(back[self.back],scale=0.75)
     785                    except: print "!! ERROR !! no background image could be loaded. probably not connected to the internet?"
     786                 elif self.back == "coast":
     787                    m.drawcoastlines()
     788                 elif self.back == "sea":
     789                    m.drawlsmask(land_color='white',ocean_color='aqua')
    778790              else:
    779791                 print "!! ERROR !! requested background not defined. change name or fill in set_back.txt" ; exit()
  • trunk/UTIL/PYTHON/planetoplot_v2/set_back.txt

    r933 r1029  
    77tesalbedo ; http://www.lmd.jussieu.fr/~aslmd/maps/tesalbedo.jpg
    88vis ; http://www.lmd.jussieu.fr/~aslmd/maps/mar0kuu2.jpg
    9 vishires ; http://www.lmd.jussieu.fr/~aslmd/maps/MarsMap_2500x1250.jpg
     9vishires ; /home/aymeric/Dropbox/Public/MarsMap_2500x1250.jpg
    1010geolocal ; http://www.lmd.jussieu.fr/~aslmd/maps/geolocal.jpg
    1111mola ; http://www.lmd.jussieu.fr/~aslmd/maps/mars-mola-2k.jpg
    12 molabw ; http://www.lmd.jussieu.fr/~aslmd/maps/MarsElevation_2500x1250.jpg
     12molabw ; /home/aymeric/Dropbox/Public/MarsElevation_2500x1250.jpg
    1313bw ; http://www.lmd.jussieu.fr/~aslmd/maps/EarthElevation_2500x1250.jpg
    1414contrast ; http://www.lmd.jussieu.fr/~aslmd/maps/EarthMapAtmos_2500x1250.jpg
     
    2424titan ; http://laps.noaa.gov/albers/sos/saturn/titan/titan_rgb_cyl_www.jpg
    2525titanuni ; http://maps.jpl.nasa.gov/pix/sat6fss1.jpg
     26titanreg ; http://laps.noaa.gov/albers/sos/features/combined_titan_lon_zero_center.png
    2627venus ; http://laps.noaa.gov/albers/sos/venus/venus4/venus4_rgb_cyl_www.jpg
    2728cosmic ; http://laps.noaa.gov/albers/sos/universe/wmap/wmap_rgb_cyl_www.jpg
  • trunk/UTIL/PYTHON/planetoplot_v2/set_var.txt

    r990 r1029  
    44##################################
    55T ; %.0f ; gist_heat ; Temperature ; K
    6 TEMP ; %0.f ; gist_heat ; Temperature ; K
     6TEMP ; %.1f ; gist_heat ; Temperature ; K
    77TPOT ; %.0f ; Paired ; Potential temperature ; K 
    88TSURF ; %.0f ; RdBu_r ; Surface temperature ; K
Note: See TracChangeset for help on using the changeset viewer.