Changeset 548 for trunk


Ignore:
Timestamp:
Mar 1, 2012, 12:50:08 AM (13 years ago)
Author:
aslmd
Message:

UTIL PYTHON: no more meso,mesoapi,mesoideal types -- only meso. fixed wind plotting for idealized file. also more flexible possibilities for naming wind fields in getwinddef

Location:
trunk/UTIL/PYTHON
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/myplot.py

    r525 r548  
    4141    elif 'phisinit' in nc.variables:           typefile = 'gcm'
    4242    elif 'time_counter' in nc.variables:       typefile = 'earthgcm'
    43     elif hasattr(nc,'START_DATE'):
    44       if '9999' in getattr(nc,'START_DATE') :  typefile = 'mesoideal'
    45       elif 'vert' in nc.variables:             typefile = 'mesoapi'
    46       elif 'U' in nc.variables:                typefile = 'meso'
    47       #elif 'HGT_M' in nc.variables:            typefile = 'geo'
    48       elif 'HGT' in nc.variables:              typefile = 'meso'
     43    elif hasattr(nc,'START_DATE'):             typefile = 'meso'
    4944    elif 'HGT_M' in nc.variables:              typefile = 'geo'
    5045    else:                                      typefile = 'gcm' # for lslin-ed files from gcm
     
    275270## Author: AS
    276271def getstralt(nc,nvert):
    277     typefile = whatkindfile(nc)
    278     if typefile is 'meso':                     
     272    varinfile = nc.variables.keys()
     273    if 'vert' not in varinfile:
    279274        stralt = "_lvl" + str(nvert)
    280     elif typefile is 'mesoapi':
     275    else:
    281276        zelevel = int(nc.variables['vert'][nvert])
    282277        if abs(zelevel) < 10000.:   strheight=str(zelevel)+"m"
     
    287282        elif 'pressure'     in nc.dimensions:   stralt = "_"+str(zelevel)+"Pa"
    288283        else:                                   stralt = ""
    289     else:
    290         stralt = ""
    291284    return stralt
    292285
     
    347340def getproj (nc):
    348341    typefile = whatkindfile(nc)
    349     if typefile in ['mesoapi','meso','geo']:
     342    if typefile in ['meso','geo']:
    350343        ### (il faudrait passer CEN_LON dans la projection ?)
    351344        map_proj = getattr(nc, 'MAP_PROJ')
     
    366359        else:
    367360            proj="merc"
    368     elif typefile in ['gcm']:  proj="cyl"    ## pb avec les autres (de trace derriere la sphere ?)
    369     else:                      proj="ortho"
     361    elif typefile in ['gcm']:        proj="cyl"    ## pb avec les autres (de trace derriere la sphere ?)
     362    else:                            proj="ortho"
    370363    return proj   
    371364
     
    439432    ## getcoord2d for predefined types
    440433    typefile = whatkindfile(nc)
    441     if typefile in ['mesoapi','meso']:
    442         [lon2d,lat2d] = getcoord2d(nc)
     434    if typefile in ['meso']:
     435        if '9999' not in getattr(nc,'START_DATE') :   
     436            ## regular mesoscale 
     437            [lon2d,lat2d] = getcoord2d(nc) 
     438        else:                     
     439            ## idealized mesoscale                     
     440            nx=getattr(nc,'WEST-EAST_GRID_DIMENSION')
     441            ny=getattr(nc,'SOUTH-NORTH_GRID_DIMENSION')
     442            dlat=getattr(nc,'DX')
     443            ## this is dirty because Martian-specific
     444            # ... but this just intended to get "lat-lon" like info
     445            falselon = np.arange(-dlat*(nx-1)/2.,dlat*(nx-1)/2.,dlat)/60000.
     446            falselat = np.arange(-dlat*(ny-1)/2.,dlat*(ny-1)/2.,dlat)/60000.
     447            [lon2d,lat2d] = np.meshgrid(falselon,falselat) ## dummy coordinates
     448            print "WARNING: domain plot artificially centered on lat,lon 0,0"
    443449    elif typefile in ['gcm']:
    444450        [lon2d,lat2d] = getcoord2d(nc,nlat="latitude",nlon="longitude",is1d=True)
     
    447453    elif typefile in ['geo']:
    448454        [lon2d,lat2d] = getcoord2d(nc,nlat='XLAT_M',nlon='XLONG_M')
    449     elif typefile in ['mesoideal']:
    450         nx=getattr(nc,'WEST-EAST_GRID_DIMENSION')
    451         ny=getattr(nc,'SOUTH-NORTH_GRID_DIMENSION')
    452         [lon2d,lat2d] = np.meshgrid(np.arange(nx),np.arange(ny))
    453455    return lon2d,lat2d   
    454456
     
    539541## Author: AS
    540542def getwinddef (nc):   
    541     ## getwinds for predefined types
    542     typefile = whatkindfile(nc)
    543543    ###
    544     if typefile is 'mesoapi':                  [uchar,vchar] = ['Um','Vm']
    545     elif typefile is 'gcm':                    [uchar,vchar] = ['u','v']
    546     elif typefile in ['meso','mesoideal']:     [uchar,vchar] = ['U','V']
    547     else:                                      [uchar,vchar] = ['not found','not found']
     544    varinfile = nc.variables.keys()
     545    if 'Um' in varinfile:   [uchar,vchar] = ['Um','Vm'] #; print "this is API meso file"
     546    elif 'U' in varinfile:  [uchar,vchar] = ['U','V']   #; print "this is RAW meso file"
     547    elif 'u' in varinfile:  [uchar,vchar] = ['u','v']   #; print "this is GCM file"
     548     ### you can add choices here !
     549    else:                   [uchar,vchar] = ['not found','not found']
    548550    ###
    549     if typefile in ['meso']:     metwind = False ## geometrical (wrt grid)
    550     else:                        metwind = True  ## meteorological (zon/mer)
    551     if metwind is False:         print "Not using meteorological winds. You trust numerical grid as being (x,y)"
     551    if uchar in ['U']:         metwind = False ## geometrical (wrt grid)
     552    else:                      metwind = True  ## meteorological (zon/mer)
     553    if metwind is False:       print "Not using meteorological winds. You trust numerical grid as being (x,y)"
    552554    ###
    553555    return uchar,vchar,metwind
  • trunk/UTIL/PYTHON/planetoplot.py

    r525 r548  
    126126      ### ... TYPEFILE
    127127      typefile = whatkindfile(nc)
    128       if typefile in ['mesoideal']:   mapmode=0
    129       elif typefile in ['gcm'] and len(nc.variables["longitude"][:]) is 1 and len(nc.variables["latitude"][:]) is 1:       mapmode=0
    130       elif typefile in ['earthgcm'] and len(nc.variables["lon"][:]) is 1 and len(nc.variables["lat"][:]) is 1:       mapmode=0
    131       if mapmode == 0:       winds=False
    132       elif mapmode == 1 and redope is None:
     128      if typefile in ['gcm'] and len(nc.variables["longitude"][:]) is 1 and len(nc.variables["latitude"][:]) is 1:       mapmode=0 ; winds=False
     129      elif typefile in ['earthgcm'] and len(nc.variables["lon"][:]) is 1 and len(nc.variables["lat"][:]) is 1:           mapmode=0 ; winds=False
     130      if redope is None and mapmode == 1:
    133131          if svert is None:  svert = readslices(str(level)) ; nvert=1
    134132          if stime is None and mrate is None:
     
    152150      [lon2d,lat2d] = getcoorddef(nc)
    153151      ### ... PROJECTION
    154       if ((proj == None) and (typefile not in ['mesoideal'])):   proj = getproj(nc)                 
     152      if proj == None:   proj = getproj(nc)                 
    155153
    156154      if firstfile:
     
    184182              time = (initime+time*24)%24
    185183              print "LOCAL TIMES.... ", time
    186       elif typefile in ['meso','mesoapi','geo','mesoideal']:
     184      elif typefile in ['meso','geo']:
    187185          area = None ## not active for the moment
    188186          ###### STUFF TO GET THE CORRECT LAT/LON FROM MESOSCALE FILES WITH 2D LAT/LON ARRAYS
     
    208206              lonp,latp = ( lon2d[indices[0,0,0],indices[0,0,1]] , lat2d[indices[0,0,0],indices[0,0,1]] )
    209207          ######
    210           if typefile in ['mesoapi','meso'] and mapmode == 1: lon2d = dumpbdy(lon2d,6) ; lat2d = dumpbdy(lat2d,6)  ### important to do that now and not before
     208          if typefile in ['meso'] and mapmode == 1: lon2d = dumpbdy(lon2d,6) ; lat2d = dumpbdy(lat2d,6)  ### important to do that now and not before
    211209          ######
    212210          if varname in ['PHTOT','W']:    vertdim='BOTTOM-TOP_PATCH_END_STAG'
     
    333331       else:                                 indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time)
    334332       ltst = None
    335        if typefile in ['mesoapi','meso'] and indextime is not None:  ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) 
     333       if typefile in ['meso'] and indextime is not None:  ltst = localtime ( interv[0]+indextime*interv[1], 0.5*(wlon[0]+wlon[1]) ) 
    336334       print "********** INDEX LON:",indexlon," LAT:",indexlat," VERT:",indexvert," TIME:",indextime
    337335       ##var = nc.variables["phisinit"][:,:]
     
    443441                            m = define_proj(proj,wlon,wlat,back=back,blat=blat,blon=blon)  ## this is dirty, defined above but out of imov loop
    444442                            x, y = m(lon2d, lat2d)                                         ## this is dirty, defined above but out of imov loop
    445                     if typefile in ['mesoapi','meso'] and mapmode == 1:   what_I_plot_frame = dumpbdy(what_I_plot_frame,6,condition=True)
     443                    if typefile in ['meso'] and mapmode == 1:   what_I_plot_frame = dumpbdy(what_I_plot_frame,6,condition=True)
    446444#                   if typefile in ['mesoideal']:    what_I_plot_frame = dumpbdy(what_I_plot_frame,0,stag='W',condition=dumped_vert_stag)
    447445
     
    471469                            #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20)
    472470                            zelevels = np.linspace(zevmin,zevmax,num=ticks)
     471                            #what_I_plot_frame = smooth(what_I_plot_frame,100)
    473472                            if mapmode == 1:       m.contourf( x, y, what_I_plot_frame, zelevels, cmap = palette, alpha=trans)
    474473                            elif mapmode == 0:     contourf( x, y, what_I_plot_frame, zelevels, cmap = palette, alpha=trans)
     
    487486                            if zeorientation == "horizontal" and zetitle != "fill": zecb.ax.set_xlabel(zetitle) ; zetitle=""
    488487                        if winds:
    489                             if typefile in ['mesoapi','meso']:
     488                            if typefile in ['meso']:
    490489                                [vecx_frame,vecy_frame] = [dumpbdy(vecx_frame,6,stag=uchar,condition=True), dumpbdy(vecy_frame,6,stag=vchar,condition=True)]
    491490                                key = True
    492491                            elif typefile in ['gcm']:
    493492                                key = False
    494                             if metwind:  [vecx_frame,vecy_frame] = m.rotate_vector(vecx_frame, vecy_frame, lon2d, lat2d)
     493                            if metwind and mapmode == 1:   [vecx_frame,vecy_frame] = m.rotate_vector(vecx_frame, vecy_frame, lon2d, lat2d)
    495494                            if var:       colorvec = definecolorvec(back)
    496495                            else:         colorvec = definecolorvec(colorb)
     
    559558           basename = basename + getstralt(nc,level)
    560559       if mrate is not None: basename = "movie_" + basename
    561        if typefile in ['mesoapi','meso']:
     560       if typefile in ['meso']:
    562561            if slon is not None: basename = basename + "_lon_" + str(int(round(lonp)))
    563562            if slat is not None: basename = basename + "_lat_" + str(int(round(latp)))
     
    598597    ### Save the figure in a file in the data folder or an user-defined folder
    599598    if outputname is None:
    600        if typefile in ['meso','mesoapi']:   prefix = getprefix(nc)
     599       if typefile in ['meso']:   prefix = getprefix(nc)
    601600       elif typefile in ['gcm']:            prefix = 'LMD_GCM_'
    602601       else:                                prefix = ''
Note: See TracChangeset for help on using the changeset viewer.