Changeset 942


Ignore:
Timestamp:
Apr 25, 2013, 10:51:36 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. handling time for mesoscale files. added -E
to pp_reload to loop on several colormaps to try. corrected a bug for 1D

plots with linestyle and colors. added a functionality to easily add te

xt (or crosses, dots, etc...) on a map through a text file add_text.txt

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

Legend:

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

    r939 r942  
    5353parser.add_option('-o','--output',action='store',dest='filename',type="string",default="myplot",help="name of output files")
    5454parser.add_option('-d','--directory',action='store',dest='folder',type="string",default="./",help="directory of output files")
    55 parser.add_option('-s','--changetime',action='store',dest='changetime',type="string",default=None,help="transformation on time axis : [None] | mars_sol2ls")
     55parser.add_option('-s','--changetime',action='store',dest='changetime',type="string",default=None,\
     56                  help="transformation on time axis : [None] | mars_sol2ls | mars_meso_ls | mars_meso_sol | mars_meso_utc | mars_meso_lt ")
    5657# plot --> upper case
    5758# -- generic
  • trunk/UTIL/PYTHON/planetoplot_v2/pp_reload.py

    r933 r942  
    1414parser.add_option('-P','--proj',action='store',dest='proj',type="string",default=None,help='[2D] Define a new map projection')
    1515parser.add_option('-C','--colorb',action='store',dest='colorb',type="string",default=None,help="[2D] Define a new colormap")
     16parser.add_option('-E','--explore',action='store_true',dest='explore',default=False,help="[2D] Try many colormaps")
    1617(opt,args) = parser.parse_args()
    1718# -----------------------------------------------------------------------
     19clb = ["Greys","Blues","YlOrRd",\
     20       "jet","spectral","hot",\
     21       "RdBu","RdYlBu","Paired",\
     22       "gist_ncar","gist_rainbow","gist_stern"]
     23# -----------------------------------------------------------------------
     24
    1825for files in args:
     26
    1927    yeah = pp()
    2028    yeah.defineplot(loadfile=files)
    2129    yeah.out = opt.out
     30
    2231    if opt.proj is not None:
    2332      for plot in yeah.p:
     
    3241      for plot in yeah.p:
    3342        plot.title = opt.title
    34     yeah.makeplot()
    3543
     44    if opt.explore:
     45      for cm in clb:
     46       for plot in yeah.p:
     47         plot.colorb = cm
     48         plot.title = cm
     49       yeah.makeplot()
     50    else:         
     51      yeah.makeplot()
     52
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r936 r942  
    538538              obj.file = self.file[i]
    539539              obj.var = self.var[j]
     540              # get methods
     541              obj.method_x = mx ; obj.method_y = my
     542              obj.method_z = mz ; obj.method_t = mt
    540543              # indicate the computation method
    541544              obj.compute = self.compute
     
    547550              obj.changetime = self.changetime
    548551              obj.performtimechange()
    549               ### get methods
    550               obj.method_x = mx ; obj.method_y = my
    551               obj.method_z = mz ; obj.method_t = mt           
    552552              ### get index
    553553              obj.getindextime(dalist=st,ind=t,stride=self.stridet)
     
    12061206    # --------------------------
    12071207    def performtimechange(self):
    1208         if self.changetime is not None \
    1209           and self.name_t != "t grid points":
     1208        if self.changetime is not None:
    12101209            if self.verbose: print "**** OK. Converting time axis:",self.changetime
     1210            ### option added by T. Navarro
    12111211            if self.changetime == "mars_sol2ls":
    12121212                self.field_t = ppcompute.mars_sol2ls(self.field_t)
     1213            ### options added by A. Spiga
     1214            elif "mars_meso" in self.changetime:
     1215                if 'Times' not in self.f.variables.keys():
     1216                    if self.verbose: print "!! WARNING !! Variable Times not in file. Cannot proceed to change of time axis."
     1217                else:
     1218                    # get the array of strings describing dates
     1219                    dates = self.f.variables['Times']
     1220                    dates.set_auto_maskandscale(False) # necessary to solve the api Times bug!
     1221                    # get ls sol utc from those strings
     1222                    ls, sol, utc = ppcompute.mars_date(dates[:])
     1223                    # populate self.field_t with the right output from mars_date
     1224                    if self.changetime == "mars_meso_ls":
     1225                        self.field_t = ls
     1226                        self.name_t = "Ls"
     1227                    elif self.changetime == "mars_meso_sol":
     1228                        self.field_t = sol
     1229                        self.name_t = "sol"
     1230                    elif self.changetime == "mars_meso_utc" \
     1231                        and ( self.changetime == "mars_meso_lt" \
     1232                              and not hasattr(self.f,'CEN_LON') ):
     1233                        self.field_t = ppcompute.timecorrect(utc)
     1234                        self.name_t = "utc"
     1235                        if self.method_t == "fixed":
     1236                            self.field_t = self.field_t % 24 # so that the user is not mistaken!
     1237                    elif self.changetime == "mars_meso_lt":
     1238                        self.field_t = ppcompute.timecorrect(utc) + getattr(self.f,'CEN_LON') / 15.
     1239                        self.field_t = ppcompute.timecorrect(self.field_t)
     1240                        self.name_t = "local time (center of domain)"
     1241                        if self.method_t == "fixed":
     1242                            self.field_t = self.field_t % 24 # so that the user is not mistaken!
    12131243            else:
    12141244                print "!! WARNING !! This time change is not implemented. Nothing is done."
     1245            if self.verbose: print "**** OK. new t axis values [%5.1f,%5.1f]" % (self.field_t.min(),self.field_t.max())
    12151246
    12161247    # get list of index to be retrieved for time axis
  • trunk/UTIL/PYTHON/planetoplot_v2/ppcompute.py

    r938 r942  
    231231      return solout
    232232
     233# mars_date
     234# author A. Spiga
     235# ------------------------------
     236# get Ls, sol, utc from a string with format yyyy-mm-dd_hh:00:00
     237# -- argument timechar is a vector of such strings indicating dates
     238# -- example: timechar = nc.variables['Times'][:] in mesoscale files
     239# NB: uses mars_sol2ls function above
     240# ------------------------------
     241def mars_date(timechar):
     242    # some preliminary information
     243    days_in_month = [61, 66, 66, 65, 60, 54, 50, 46, 47, 47, 51, 56]
     244    plus_in_month = [ 0, 61,127,193,258,318,372,422,468,515,562,613]
     245    # get utc and sol from strings
     246    utc = [] ; sol = []
     247    for zetime in timechar:
     248        dautc = float(zetime[11]+zetime[12]) + float(zetime[14]+zetime[15])/37.
     249        dasol = dautc / 24.
     250        dasol = dasol + plus_in_month[ int(zetime[5]+zetime[6])-1 ] + int(zetime[8]+zetime[9])
     251        dasol = dasol - 1 ##les sols GCM commencent a 0
     252        utc.append(dautc)
     253        sol.append(dasol)
     254    sol = np.array(sol)
     255    utc = np.array(utc)
     256    # get ls from sol
     257    ls = mars_sol2ls(sol)
     258    return ls, sol, utc
     259
     260# timecorrect
     261# author A. Spiga
     262# -----------------------------
     263# ensure time axis is monotonic
     264# correct negative values
     265# -----------------------------
     266def timecorrect(time):
     267    for ind in range(len(time)-1):
     268        if time[ind] < 0.: time[ind] = time[ind] + 24.
     269        if time[ind+1] < time[ind]: time[ind+1] = time[ind+1] + 24.
     270    return time
     271
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r936 r942  
    220220    amax = ppcompute.max(field)
    221221    if np.abs(amin) < 1.e-15:
    222         zevmin = 0.
    223222        cmin = 0.
    224223    else:
     
    419418        if self.lstyle is not None and self.color is not None:
    420419            mpl.plot(x,y,self.color+self.lstyle,marker=self.marker,label=self.label)
     420        elif self.color is not None:
     421            mpl.plot(x,y,color=self.color,marker=self.marker,label=self.label)
     422        elif self.lstyle is not None:
     423            mpl.plot(x,y,self.lstyle,marker=self.marker,label=self.label)
    421424        else:
    422425            mpl.plot(x,y,marker=self.marker,label=self.label)
     
    672675            ## draw colorbar. settings are different with projections. or if not mapmode.
    673676            if not self.mapmode: orientation=zeorientation ; frac = 0.075 ; pad = 0.03 ; lu = 0.5
    674             elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.075 ; pad = 0.03 ; lu = 1.0
     677            elif self.proj in ['moll']: orientation="horizontal" ; frac = 0.08 ; pad = 0.03 ; lu = 1.0
    675678            elif self.proj in ['cyl']: orientation="vertical" ; frac = 0.023 ; pad = 0.03 ; lu = 0.5
    676679            else: orientation = zeorientation ; frac = zefrac ; pad = 0.03 ; lu = 0.5
     
    690693        ### not expecting NaN in self.addvecx and self.addvecy. masked arrays is just enough.
    691694        stride = 3
     695        #stride = 1
    692696        if self.addvecx is not None and self.addvecy is not None and self.mapmode:
    693697                ### for metwinds only ???
     
    696700                # reference vector is scaled
    697701                zescale = ppcompute.mean(np.sqrt(self.addvecx*self.addvecx+self.addvecy*self.addvecy))
     702                #zescale = 25.
    698703                # make vector field
    699704                q = m.quiver( x[::stride,::stride],y[::stride,::stride],\
     
    704709                #keyh = 1.025 ; keyv = 1.05 # upper right corner over colorbar
    705710                keyh = 0.98 ; keyv = 1.06
     711                keyh = 0.98 ; keyv = 1.07
    706712                #keyh = -0.03 ; keyv = 1.08 # upper left corner
    707713                p = mpl.quiverkey(q,keyh,keyv,\
    708714                                  zescale,str(int(zescale)),\
    709715                                  color='black',labelpos='S',labelsep = 0.07)
     716        ############################################################################################
     717        ### TEXT. ANYWHERE. add_text.txt should be present with lines x ; y ; text ; color
     718        ############################################################################################
     719        try:
     720            f = open("add_text.txt", 'r')
     721            for line in f:
     722              if "#" in line: pass
     723              else:
     724                  userx, usery, usert, userc = line.strip().split(';')
     725                  userc = userc.strip()
     726                  usert = usert.strip()
     727                  userx = float(userx.strip())
     728                  usery = float(usery.strip())
     729                  if self.mapmode: userx,usery = m(userx,usery)
     730                  mpl.text(userx,usery,usert,\
     731                           color = userc,\
     732                           horizontalalignment='center',\
     733                           verticalalignment='center')
     734            f.close()
     735        except IOError:
     736            pass
  • trunk/UTIL/PYTHON/planetoplot_v2/set_area.txt

    r930 r942  
    2424Xanadu ; -40 ; 20 ; 40 ; 120
    2525Hyperboreae ; 80 ; 87 ; -70 ; -10
    26 VM ; -15 ; 0 ; -90 ; -60
     26VM ; -18 ; 0 ; -95 ; -40
    2727VM_alt ; -15 ; 0 ; 270 ; 300
  • trunk/UTIL/PYTHON/planetoplot_v2/set_var.txt

    r933 r942  
    5858ISR ; %.0f ; gist_heat ; Incoming Solar Radiation ; W m$^{-2}$
    5959SWDOWNZ ; %.0f ; gist_heat ; $\Phi^{SW}\downarrow$ ; W m$^{-2}$
     60ZMAX_TH ; %.1f ; spectral ; PBL depth ; km
Note: See TracChangeset for help on using the changeset viewer.