Changeset 933 for trunk/UTIL


Ignore:
Timestamp:
Apr 19, 2013, 4:19:20 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. units: set an additional column set_var.txt and put units over colorbar. 1D bounding and formatting. possible mode nothing. corrected bug coast/sea.

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

Legend:

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

    r923 r933  
    1919anomaly.filename = "anomaly"
    2020anomaly.defineplot()
    21 anomaly.p[0].title = "surface temperature anomaly in %"
     21anomaly.p[0].title = "surface temperature anomaly"
     22anomaly.p[0].units = '%'
    2223anomaly.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/function.py

    r923 r933  
    2525S.p[0].ylabel = "Surface geopotential height (km)"
    2626S.p[0].ycoeff = 1./1000.
     27S.p[0].fmt = '%.0f'
    2728S.filename = "function"
    2829S.makeplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/les_psfc.py

    r923 r933  
    1414les.y = None
    1515les.t = ["10"]
    16 les.stridex = 3
    17 les.stridey = 3
     16#les.stridex = 3
     17#les.stridey = 3
    1818les.filename = "les_psfc"
    1919les.getplot()
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/simple.py

    r923 r933  
    1919# we define the plot, then set a few personal stuff
    2020u.defineplot()
    21 u.p[0].title = "This is what we name $u$ (m s$^{-1}$)"
     21u.p[0].title = "This is what we name $u$"
    2222u.p[0].proj = "robin"
    2323u.filename = "simple"
  • trunk/UTIL/PYTHON/planetoplot_v2/examples/windspeed.py

    r923 r933  
    99u.getdefineplot(extraplot=2) # prepare 2 extraplots (do not show)
    1010u.p[0].proj = "ortho"
    11 u.p[0].title = "$u$ (m s$^{-1}$)"
     11u.p[0].title = "$u$"
    1212u.makeplot()
    1313
     
    1919v.defineplot()
    2020v.p[1].proj = "ortho"
    21 v.p[1].title = "$v$ (m s$^{-1}$)"
     21v.p[1].title = "$v$"
    2222v.makeplot() # plot within the previous one (do not show)
    2323
     
    2727wind.filename = "windspeed"
    2828wind.defineplot()
    29 wind.p[2].title = "$\sqrt{u^2+v^2}$ (m s$^{-1}$)"
     29wind.p[2].title = "$\sqrt{u^2+v^2}$"
    3030wind.p[2].proj = "ortho"
    3131wind.makeplot() # plot within the previous one (show because complete)
  • trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py

    r923 r933  
    1010parser = OptionParser()
    1111parser.add_option('-O','--out',action='store',dest='out',type="string",default="gui",help='Specify a new output format')
     12parser.add_option('-T','--title',action='store',dest='title',type="string",default=None,help='Give a new title')
    1213parser.add_option('-K','--marker',action='store',dest='marker',type="string",default=None,help="[1D] Define a new marker")
    1314parser.add_option('-P','--proj',action='store',dest='proj',type="string",default=None,help='[2D] Define a new map projection')
     
    2829      for plot in yeah.p:
    2930        plot.marker = opt.marker
     31    if opt.title is not None:
     32      for plot in yeah.p:
     33        plot.title = opt.title
    3034    yeah.makeplot()
    3135
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r932 r933  
    13651365        # waiting for more fundamental modifications. case when self.index_y is a bool array.
    13661366        # ... be careful if no point...
    1367         if type(self.index_x[0]) == np.bool_: nx = np.sum(self.index_x) ## gives the size of the True part!
    1368         if type(self.index_y[0]) == np.bool_: ny = np.sum(self.index_y) ## gives the size of the True part!
     1367        try:
     1368            if type(self.index_x[0]) == np.bool_: nx = np.sum(self.index_x) ## gives the size of the True part!
     1369            if type(self.index_y[0]) == np.bool_: ny = np.sum(self.index_y) ## gives the size of the True part!
     1370        except:
     1371            pass
    13691372        # NB: ... always 4D array but possibly with "size 1" dimensions
    13701373        #     ... if one dimension is missing because 1D 2D or 3D requests, make it appear again
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r932 r933  
    1212from matplotlib.cm import get_cmap
    1313from mpl_toolkits.basemap import Basemap
     14from matplotlib.ticker import FormatStrFormatter
    1415# personal librairies
    1516import ppcompute
     
    7980# -------------------------------
    8081zefile = "set_var.txt"
    81 vf = {} ; vc = {} ; vl = {}
     82vf = {} ; vc = {} ; vl = {} ; vu = {}
    8283try:
    8384    f = open(whereset+zefile, 'r')
     
    8586        if "#" in line: pass
    8687        else:
    87             var, format, colorb, label = line.strip().split(';')
     88            var, format, colorb, label, units = line.strip().split(';')
    8889            ind = var.strip()
    8990            vf[ind] = format.strip()
    9091            vc[ind] = colorb.strip()
    9192            vl[ind] = label.strip()
     93            vu[ind] = units.strip()
    9294    f.close()
    9395except IOError:
     
    213215       if vmax is None: zevmax = damean + dev
    214216       # special case: negative values with stddev while field is positive
    215        if zevmin < 0. and ppcompute.min(fieldcalc) > 0.: zevmin = 0.
     217       if zevmin < 0. and ppcompute.min(fieldcalc) >= 0.: zevmin = 0.
    216218    # check that bounds are not too tight given the field
    217219    amin = ppcompute.min(field)
     
    239241# -------------------------------
    240242def save(mode="gui",filename="plot",folder="./",includedate=True,res=150,custom=False):
    241     # a few settings
    242     possiblesave = ['eps','ps','svg','png','jpg','pdf']
    243     # now the main instructions
    244     if mode == "gui":
    245         mpl.show()
    246     elif mode in possiblesave:
    247         ## name of plot
    248         name = folder+'/'+filename
    249         if includedate:
    250             for ttt in timelib.gmtime():
    251                 name = name + "_" + str(ttt)
    252         name = name +"."+mode
    253         ## save file
    254         print "**** Saving file in "+mode+" format... Please wait."
    255         if not custom:
    256             # ... regular plots
    257             mpl.savefig(name,dpi=res,pad_inches=pad_inches_value,bbox_inches='tight')
    258         else:
    259             # ... mapping mode, adapted space for labels etc...
    260             mpl.savefig(name,dpi=res)
    261     else:
    262         print "!! ERROR !! File format not supported. Supported: ",possiblesave
     243    if mode != "nothing":
     244      # a few settings
     245      possiblesave = ['eps','ps','svg','png','jpg','pdf']
     246      # now the main instructions
     247      if mode == "gui":
     248          mpl.show()
     249      elif mode in possiblesave:
     250          ## name of plot
     251          name = folder+'/'+filename
     252          if includedate:
     253              for ttt in timelib.gmtime():
     254                  name = name + "_" + str(ttt)
     255          name = name +"."+mode
     256          ## save file
     257          print "**** Saving file in "+mode+" format... Please wait."
     258          if not custom:
     259              # ... regular plots
     260              mpl.savefig(name,dpi=res,pad_inches=pad_inches_value,bbox_inches='tight')
     261          else:
     262              # ... mapping mode, adapted space for labels etc...
     263              mpl.savefig(name,dpi=res)
     264      else:
     265          print "!! ERROR !! File format not supported. Supported: ",possiblesave
    263266
    264267##################################
     
    292295                 xcoeff=1.,\
    293296                 ycoeff=1.,\
     297                 fmt=None,\
     298                 units="",\
    294299                 title=""):
    295300        ## what could be defined by the user
     
    308313        self.xcoeff = xcoeff
    309314        self.ycoeff = ycoeff
     315        self.fmt = fmt
     316        self.units = units
    310317        ## other useful arguments
    311318        ## ... not used here in ppplot but need to be attached to plot object
     
    325332         if self.var.upper() in vl.keys():
    326333          self.title = vl[self.var.upper()]
     334          self.units = vu[self.var.upper()]
    327335
    328336    # make
     
    383391          self.ylabel = vl[self.var.upper()]
    384392          self.title = ""
     393          self.fmt = vf[self.var.upper()]
    385394
    386395    # make
     
    389398        # get what is done in the parent class
    390399        plot.make(self)
     400        if self.fmt is None: self.fmt = '%.0f'
    391401        # add specific stuff
    392402        mpl.grid(color='grey')
     
    417427            if self.label != "":
    418428                mpl.legend(loc="best",fancybox=True)
    419         ## TBD: set with .div the number of ticks
     429        # AXES
     430        ax = mpl.gca()
     431        # 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))
     434        # plot limits: ensure that no curve would be outside the window
     435        # x-axis
     436        x1, x2 = ax.get_xbound()
     437        xmin = ppcompute.min(x)
     438        xmax = ppcompute.max(x)
     439        if xmin < x1: x1 = xmin
     440        if xmax > x2: x2 = xmax
     441        ax.set_xbound(lower=x1,upper=x2)
     442        # y-axis
     443        y1, y2 = ax.get_ybound()
     444        ymin = ppcompute.min(y)
     445        ymax = ppcompute.max(y)
     446        if ymin < y1: y1 = ymin
     447        if ymax > y2: y2 = ymax
     448        ax.set_ybound(lower=y1,upper=y2)
     449        ## set with .div the number of ticks. less good than automatic.
    420450        #ticks = self.div + 1
    421         #ax = mpl.gca()
    422         #ax.get_xaxis().set_ticks(np.linspace(ppcompute.min(x),ppcompute.max(x),ticks/2+1))
    423         # control plot limits (TBD: be able to control those)
    424         ax = mpl.gca() ; ax.set_xbound(lower=ppcompute.min(x), upper=ppcompute.max(x))
    425 
     451        #ax.get_xaxis().set_ticks(np.linspace(x1,x2,ticks/2+1))
    426452
    427453################################
     
    451477                 addvecy=None,\
    452478                 addcontour=None,\
    453                  fmt="%.2e",\
    454479                 blon=None,\
    455480                 blat=None,\
     
    471496        self.colorvec = colorvec
    472497        self.addcontour = addcontour
    473         self.fmt = fmt
    474498        self.blon = blon ; self.blat = blat
    475499        self.area = area
     
    493517        # get what is done in the parent class...
    494518        plot.make(self)
     519        if self.fmt is None: self.fmt = "%.2e"
    495520        # ... then add specific stuff
    496521        ############################################################################################
     
    624649              if self.back in back.keys():
    625650                 print "**** info: loading a background, please wait.",self.back
    626                  if back not in ["coast","sea"]:   m.warpimage(back[self.back],scale=0.75)
    627                  elif back == "coast":             m.drawcoastlines()
    628                  elif back == "sea":               m.drawlsmask(land_color='white',ocean_color='aqua')
     651                 if self.back not in ["coast","sea"]:   m.warpimage(back[self.back],scale=0.75)
     652                 elif self.back == "coast":             m.drawcoastlines()
     653                 elif self.back == "sea":               m.drawlsmask(land_color='white',ocean_color='aqua')
    629654              else:
    630655                 print "!! ERROR !! requested background not defined. change name or fill in set_back.txt" ; exit()
     
    641666        if self.trans > 0.:
    642667            ## draw colorbar. settings are different with projections. or if not mapmode.
    643             if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03
    644             elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.075 ; pad = 0.03
    645             elif self.proj in ['cyl']: orientation="vertical" ; frac = 0.023 ; pad = 0.03
    646             else: orientation = zeorientation ; frac = zefrac ; pad = 0.03
     668            if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03 ; lu = 0.5
     669            elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.075 ; pad = 0.03 ; lu = 1.0
     670            elif self.proj in ['cyl']: orientation="vertical" ; frac = 0.023 ; pad = 0.03 ; lu = 0.5
     671            else: orientation = zeorientation ; frac = zefrac ; pad = 0.03 ; lu = 0.5
    647672            zelevpal = np.linspace(zevmin,zevmax,num=min([ticks/2+1,21]))
    648673            zecb = mpl.colorbar(fraction=frac,pad=pad,\
    649674                                format=self.fmt,orientation=orientation,\
    650675                                ticks=zelevpal,\
    651                                 extend='neither',spacing='proportional') 
     676                                extend='neither',spacing='proportional')
    652677            if zeorientation == "horizontal": zecb.ax.set_xlabel(self.title) ; self.title = ""
     678            # colorbar title --> units
     679            if self.units not in ["dimless",""]:
     680                zecb.ax.set_title("["+self.units+"]",fontsize=3.*mpl.rcParams['font.size']/4.,x=lu,y=1.025)
     681
    653682        ############################################################################################
    654683        ### VECTORS. must be after the colorbar. we could also leave possibility for streamlines.
     
    668697                              scale=zescale*reducevec,width=widthvec )
    669698                # make vector key.
    670                 keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar
     699                #keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar
     700                keyh = 0.98 ; keyv = 1.06
    671701                #keyh = -0.03 ; keyv = 1.08 # upper left corner
    672702                p = mpl.quiverkey(q,keyh,keyv,\
  • trunk/UTIL/PYTHON/planetoplot_v2/set_back.txt

    r910 r933  
    2626venus ; http://laps.noaa.gov/albers/sos/venus/venus4/venus4_rgb_cyl_www.jpg
    2727cosmic ; http://laps.noaa.gov/albers/sos/universe/wmap/wmap_rgb_cyl_www.jpg
     28coast ; dummy
     29sea ; dummy
  • trunk/UTIL/PYTHON/planetoplot_v2/set_var.txt

    r920 r933  
    33## var ; format ; colormap ; label
    44##################################
    5 T ; %.0f ; gist_heat ; Temperature (K)
    6 TEMP ; %0.f ; gist_heat ; Temperature (K)
    7 TPOT ; %.0f ; Paired ; Potential temperature (K)
    8 TSURF ; %.0f ; RdBu_r ; Surface temperature (K)
    9 TK ; %.0f ; gist_heat ; Temperature (K)
    10 U ; %.1f ; jet ; Zonal wind (m s$^{-1}$)
    11 UM ; %.1f ; jet ; Zonal wind (m s$^{-1}$)
    12 V ; %.1f ; jet ; Meridional wind (m s$^{-1}$)
    13 VM ; %.1f ; jet ; Meridional wind (m s$^{-1}$)
    14 W ; %.2f ; jet ; Vertical wind (m s$^{-1}$)
    15 WIND ; %.0f ; YlOrRd ; Wind speed (m s$^{-1}$)
    16 UV ; %.0f ; YlOrRd ; Wind speed (m s$^{-1}$)
    17 UVMET ; %.0f ; YlOrRd ; Wind speed (m s$^{-1}$)
    18 PTOT ; %.0f ; jet ; Pressure (Pa)
    19 PSFC ; %.1f ; RdYlBu_r ; Surface pressure (Pa)
    20 PS ; %.1f ; RdYlBu_r ; Surface pressure (Pa)
    21 ANOMALY ; %.1f ; gist_ncar ; Anomaly (%)
    22 HGT ; %.1e ; spectral ; Topography (m)
    23 HGT_M ; %.1e ; spectral ; Topography (m)
    24 MARS_TI ; %.0f ; jet ; Thermal inertia (tiu)
    25 THERMAL_INERTIA ; %.0f ; jet ; Thermal inertia (tiu)
    26 TAU ; %.1f ; YlOrBr_r ; Opacity
    27 TAU_DUST ; %.1f ; Oranges_r ; Dust opacity
    28 QDUST ; %.6f ; Oranges_r ; Dust mass mixing ratio (kg/kg)
    29 CCNQ ; %.2e ; YlOrBr ; Cloud condensation nuclei (kg/kg)
    30 CCNN ; %.2e ; YlOrBr ; Cloud condensation nuclei density
    31 QH2O ; %.2e ; PuBu ; Water vapor mixing ratio (kg/kg)
    32 MTOT ; %.1e ; spectral ; Column vapor (pr. $\mu$m)
    33 ICETOT ; %.1e ; YlGnBu_r ; Column ice (pr. $\mu$m)
    34 TAU_ICE ; %.2f ; Blues ; Ice cloud opacity
    35 TAUICE ; %.2f ; Blues ; Ice cloud opacity
    36 VMR_ICE ; %.1e ; Blues ; Ice volume mix. rat.
    37 VMR_H2OICE ; %.0f ; PuBu ; Ice volume mix. rat.
    38 VMR_H2OVAP ; %.0f ; PuBu ; Vapor volume mix. rat.
    39 QSURFICE ; %.0f ; hot_r ; Surface ice
    40 WATERCAPTAG ; %.0f ; Blues ; Cap grid point
    41 TAUTES ; %.2f ; jet ; Opacity
    42 TAUTESAP ; %.2f ; jet ; Opacity
    43 USTM ; %.2f ; jet ; Friction velocity (m s$^{-1}$)
    44 HFX ; %.0f ; RdYlBu ; Sensible heat flux (W m$^{-2}$)
    45 WSTAR ; %.1f ; YlOrRd ; Turbulent convective velocity scale (m s$^{-1}$)
    46 CO2 ; %.2f ; YlOrBr_r ; CO$_2$ mixing ratio
    47 ENFACT ; %.1.f ; jet ; Enrichment factor
    48 T_NADIR_DAY ; %.0f ; RdBu_r ; Temperature (K)
    49 T_NADIR_NIT ; %.0f ; RdBu_r ; Temperature (K)
    50 TEMP_DAY ; %.0f ; gist_heat ; Temperature (K)
    51 TEMP_NIGHT ; %.0f ; gist_heat ; Temperature (K)
    52 DTEMP ; %.0f ; gist_heat ; Temperature (K)
    53 NTEMP ; %.0f ; gist_heat ; Temperature (K)
    54 DNUMBINTEMP ; %.0f ; gist_heat ; Temperature (K)
    55 NNUMBINTEMP ; %.0f ; gist_heat ; Temperature (K)
    56 OLR ; %.0f ; gist_heat ; Outgoing Longwave Radiation (W m$^{-2}$)
    57 ASR ; %.0f ; gist_heat ; Absorbed Solar Radiation (W m$^{-2}$)
    58 ISR ; %.0f ; gist_heat ; Incoming Solar Radiation (W m$^{-2}$)
    59 SWDOWNZ ; %.0f ; gist_heat ; $\Phi^{SW}\downarrow$ (W m$^{-2}$)
     5T ; %.0f ; gist_heat ; Temperature ; K
     6TEMP ; %0.f ; gist_heat ; Temperature ; K
     7TPOT ; %.0f ; Paired ; Potential temperature ; K
     8TSURF ; %.0f ; RdBu_r ; Surface temperature ; K
     9TK ; %.0f ; gist_heat ; Temperature ; K
     10U ; %.1f ; jet ; Zonal wind ; m s$^{-1}$
     11UM ; %.1f ; jet ; Zonal wind ; m s$^{-1}$
     12V ; %.1f ; jet ; Meridional wind ; m s$^{-1}$
     13VM ; %.1f ; jet ; Meridional wind ; m s$^{-1}$
     14W ; %.2f ; jet ; Vertical wind ; m s$^{-1}$
     15WIND ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$
     16UV ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$
     17UVMET ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$
     18PTOT ; %.0f ; jet ; Pressure ; Pa
     19PSFC ; %.1f ; RdYlBu_r ; Surface pressure ; Pa
     20PS ; %.1f ; RdYlBu_r ; Surface pressure ; Pa
     21ANOMALY ; %.1f ; gist_ncar ; Anomaly ; %
     22HGT ; %.1e ; spectral ; Topography ; m
     23HGT_M ; %.1e ; spectral ; Topography ; m
     24MARS_TI ; %.0f ; jet ; Thermal inertia ; tiu
     25THERMAL_INERTIA ; %.0f ; jet ; Thermal inertia ; tiu
     26TAU ; %.1f ; YlOrBr_r ; Opacity ; dimless
     27TAU_DUST ; %.1f ; Oranges_r ; Dust opacity ; dimless
     28QDUST ; %.6f ; Oranges_r ; Dust mass mixing ratio ; kg/kg
     29CCNQ ; %.2e ; YlOrBr ; Cloud condensation nuclei ; kg/kg
     30CCNN ; %.2e ; YlOrBr ; Cloud condensation nuclei density ; dimless
     31QH2O ; %.2e ; PuBu ; Water vapor mixing ratio ; kg/kg
     32MTOT ; %.1e ; spectral ; Column vapor ; pr. $\mu$m
     33ICETOT ; %.1e ; YlGnBu_r ; Column ice ; pr. $\mu$m
     34TAU_ICE ; %.2f ; Blues ; Ice cloud opacity ; dimless
     35TAUICE ; %.2f ; Blues ; Ice cloud opacity ; dimless
     36VMR_ICE ; %.1e ; Blues ; Ice volume mix. rat. ; dimless
     37VMR_H2OICE ; %.0f ; PuBu ; Ice volume mix. rat. ; dimless
     38VMR_H2OVAP ; %.0f ; PuBu ; Vapor volume mix. rat. ; dimless
     39QSURFICE ; %.0f ; hot_r ; Surface ice ; dimless
     40WATERCAPTAG ; %.0f ; Blues ; Cap grid point ; dimless
     41TAUTES ; %.2f ; jet ; Opacity ; dimless
     42TAUTESAP ; %.2f ; jet ; Opacity ; dimless
     43USTM ; %.2f ; jet ; Friction velocity ; m s$^{-1}$
     44HFX ; %.0f ; RdYlBu ; Sensible heat flux ; W m$^{-2}$
     45WSTAR ; %.1f ; YlOrRd ; Turbulent convective velocity scale ; m s$^{-1}$
     46CO2 ; %.2f ; YlOrBr_r ; CO$_2$ mixing ratio ; dimless
     47ENFACT ; %.1.f ; jet ; Enrichment factor ; dimless
     48T_NADIR_DAY ; %.0f ; RdBu_r ; Temperature ; K
     49T_NADIR_NIT ; %.0f ; RdBu_r ; Temperature ; K
     50TEMP_DAY ; %.0f ; gist_heat ; Temperature ; K
     51TEMP_NIGHT ; %.0f ; gist_heat ; Temperature ; K
     52DTEMP ; %.0f ; gist_heat ; Temperature ; K
     53NTEMP ; %.0f ; gist_heat ; Temperature ; K
     54DNUMBINTEMP ; %.0f ; gist_heat ; Temperature ; K
     55NNUMBINTEMP ; %.0f ; gist_heat ; Temperature ; K
     56OLR ; %.0f ; gist_heat ; Outgoing Longwave Radiation ; W m$^{-2}$
     57ASR ; %.0f ; gist_heat ; Absorbed Solar Radiation ; W m$^{-2}$
     58ISR ; %.0f ; gist_heat ; Incoming Solar Radiation ; W m$^{-2}$
     59SWDOWNZ ; %.0f ; gist_heat ; $\Phi^{SW}\downarrow$ ; W m$^{-2}$
Note: See TracChangeset for help on using the changeset viewer.