Changeset 990


Ignore:
Timestamp:
Jun 14, 2013, 9:52:31 AM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON planetoplot_v2. ASCII output. 4D altitude coordinate is possible.

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

Legend:

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

    r982 r990  
    5555parser.add_option('-s','--changetime',action='store',dest='changetime',type="string",default=None,\
    5656                  help="transformation on time axis : [None] | mars_sol2ls | mars_meso_ls | mars_meso_sol | mars_meso_utc | mars_meso_lt ")
     57parser.add_option('-p','--print',action='store_true',dest='savtxt',default=False,help="[1D] output field+coord in an ASCII file")
    5758parser.add_option('--stridex',action='store',dest='stridex',type="int",default=1,help="Load data every stridex grid points over x dimension")
    5859parser.add_option('--stridey',action='store',dest='stridey',type="int",default=1,help="Load data every stridex grid points over y dimension")
     
    138139user.stridevecx = opt.stridevecx
    139140user.stridevecy = opt.stridevecy
     141user.savtxt = opt.savtxt
    140142# define field
    141143user.define()
  • trunk/UTIL/PYTHON/planetoplot_v2/ppclass.py

    r984 r990  
    161161                      changetime=None,\
    162162                      units=None,\
     163                      savtxt=False,\
    163164                      title=None):
    164165        self.request = None
     
    199200        self.includedate = includedate
    200201        self.changetime = changetime
     202        self.savtxt = savtxt
    201203        ## here are user-defined plot settings
    202204        ## -- if not None, valid on all plots in the pp() objects
     
    262264            self.includedate = other.includedate
    263265            self.changetime = other.changetime
     266            self.savtxt = other.savtxt
    264267        else:
    265268            print "!! ERROR !! argument must be a pp object." ; exit()
     
    943946            # finally make the plot
    944947            pl.make()
     948            # possibly print results in a text file
     949            if self.savtxt:
     950                if self.verbose: print "**** Printing results in a text file"
     951                name = pl.var + "%04d" % self.n
     952                ppplot.writeascii(field=pl.field,absc=pl.absc,name=name)
    945953            # increment plot count (and propagate this in plotin)
    946954            self.n = self.n+1
     
    12991307            self.name_z = "z grid points"
    13001308          else:
    1301             self.field_z = self.f.variables[self.name_z][:] # specify dimension
    1302                                                             # TBD: have to check that this is not a 3D field
     1309            tabalt = self.f.variables[self.name_z]
     1310            # (consider the case where tabtime is not dim 1) TBD: 2D and 3D cases
     1311            if tabalt.ndim == 4:
     1312                try:
     1313                    self.field_z = tabalt[1,:,0,0] # 4D case. alt is usually third dimension.
     1314                                                   # 1 for time to avoid initial 0s
     1315                except:
     1316                    self.field_z = tabalt[0,:,0,0]
     1317                if self.verbose: print "!! WARNING !! "+self.name_z+" is 4D var. We made it 1D."
     1318            else:
     1319                self.field_z = self.f.variables[self.name_z][:] # specify dimension
    13031320          if self.dim_z > 1:
    13041321               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())
  • trunk/UTIL/PYTHON/planetoplot_v2/ppplot.py

    r982 r990  
    247247    what_I_plot[ what_I_plot > zevmax ] = zevmax*(1.-small_enough)
    248248    return what_I_plot
     249
     250# a function to output an ascii file
     251# ----------------------------------
     252def writeascii (field=None,absc=None,name=None):
     253    if name is None:
     254        name = "prof"
     255        for ttt in timelib.gmtime():
     256            name = name + "_" + str(ttt)
     257    if field is None or absc is None:
     258        print "!! WARNING !! Not printing the file, incorrect field or absc."
     259    else:
     260        if field.ndim == 1:
     261            myfile = open(name, 'w')
     262            for ix in range(len(absc)):
     263                myfile.write("%15.5e%15.5e\n" % ( absc[ix], field[ix] ))
     264            myfile.close()
     265        else:
     266            print "!! WARNING !! Not printing the file, 2D fields not supported yet."
     267#    mydata = np.transpose([absc,np.transpose(field)]) #tab
     268#    for line in mydata:
     269#        zeline = str(line)
     270#        zeline = zeline.replace('[','')
     271#        zeline = zeline.replace(']','')
     272#        myfile.write(zeline + '\n')
     273    return
    249274
    250275# a generic function to show (GUI) or save a plot (PNG,EPS,PDF,...)
  • trunk/UTIL/PYTHON/planetoplot_v2/set_ppclass.txt

    r981 r990  
    1010  # z-axis: possible names to search for. add in the line with a separating ;
    1111  #
    12 altitude;Alt;vert;presnivs;bottom_top;altitude_abg;lev
     12altitude;Alt;vert;presnivs;bottom_top;altitude_abg;lev;PTOT
    1313  # t-axis: possible names to search for. add in the line with a separating ;
    1414  #
  • trunk/UTIL/PYTHON/planetoplot_v2/set_var.txt

    r943 r990  
    1313VM ; %.1f ; jet ; Meridional wind ; m s$^{-1}$
    1414W ; %.2f ; jet ; Vertical wind ; m s$^{-1}$
     15U025 ; %.1f ; jet ; Wind speed 25cm above the surface ; m s$^{-1}$
    1516WIND ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$
    1617UV ; %.0f ; YlOrRd ; Wind speed ; m s$^{-1}$
Note: See TracChangeset for help on using the changeset viewer.