Changeset 637


Ignore:
Timestamp:
Apr 30, 2012, 11:09:59 AM (13 years ago)
Author:
aslmd
Message:

Working whether dimension is latitude/longitude or lat/lon (so, OK for UK assimilation files now). Better centering of lcc projection. Labels for contour plots.

Location:
trunk/UTIL/PYTHON
Files:
3 edited

Legend:

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

    r613 r637  
    290290    from mymath import max,mean
    291291    from scipy import integrate
     292    import numpy as np
    292293    if yint and vert is not None and indice is not None:
    293294       if type(input).__name__=='MaskedArray':
     
    320321        fig.subplots_adjust(hspace = 0.5)
    321322        rcParams['font.size'] = int( rcParams['font.size'] * 1. / 2. )
    322     elif   numplot == 4:
     323    elif numplot == 4:
    323324        subv = 2
    324325        subh = 2
     
    534535            [lon2d,lat2d] = np.meshgrid(falselon,falselat) ## dummy coordinates
    535536            print "WARNING: domain plot artificially centered on lat,lon 0,0"
    536     elif typefile in ['gcm']:
    537         [lon2d,lat2d] = getcoord2d(nc,nlat="latitude",nlon="longitude",is1d=True)
    538     elif typefile in ['earthgcm','ecmwf']:
    539         [lon2d,lat2d] = getcoord2d(nc,nlat="lat",nlon="lon",is1d=True)
     537    elif typefile in ['gcm','earthgcm','ecmwf']:
     538        if "longitude" in nc.dimensions:  dalon = "longitude"
     539        elif "lon" in nc.dimensions:      dalon = "lon"
     540        if "latitude" in nc.dimensions:   dalat = "latitude"
     541        elif "lat" in nc.dimensions:      dalat = "lat"
     542        [lon2d,lat2d] = getcoord2d(nc,nlat=dalat,nlon=dalon,is1d=True)
    540543    elif typefile in ['geo']:
    541544        [lon2d,lat2d] = getcoord2d(nc,nlat='XLAT_M',nlon='XLONG_M')
     
    692695    meanlon = 0.5*(wlon[0]+wlon[1])
    693696    meanlat = 0.5*(wlat[0]+wlat[1])
     697    zewidth = np.abs(wlon[0]-wlon[1])*60000.*np.cos(3.14*meanlat/180.)
     698    zeheight = np.abs(wlat[0]-wlat[1])*60000.
    694699    if blat is None:
    695700        ortholat=meanlat
     
    703708    h = 50.  ## en km
    704709    radius = 3397200.
     710    #print meanlat, meanlon
    705711    if   char == "cyl":     m = Basemap(rsphere=radius,projection='cyl',\
    706712                              llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1])
     
    708714    elif char == "ortho":   m = Basemap(rsphere=radius,projection='ortho',lon_0=ortholon,lat_0=ortholat)
    709715    elif char == "lcc":     m = Basemap(rsphere=radius,projection='lcc',lat_1=meanlat,lat_0=meanlat,lon_0=meanlon,\
    710                               llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1])
     716                              width=zewidth,height=zeheight)
     717                              #llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1])
    711718    elif char == "npstere": m = Basemap(rsphere=radius,projection='npstere', boundinglat=blat, lon_0=0.)
    712719    elif char == "spstere": m = Basemap(rsphere=radius,projection='spstere', boundinglat=blat, lon_0=180.)
    713720    elif char == "nplaea":  m = Basemap(rsphere=radius,projection='nplaea', boundinglat=wlat[0], lon_0=meanlon)
    714721    elif char == "laea":    m = Basemap(rsphere=radius,projection='laea',lon_0=meanlon,lat_0=meanlat,lat_ts=meanlat,\
    715                               llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1])
     722                              width=zewidth,height=zeheight)
     723                              #llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1])
    716724    elif char == "nsper":   m = Basemap(rsphere=radius,projection='nsper',lon_0=meanlon,lat_0=meanlat,satellite_height=h*1000.)
    717725    elif char == "merc":    m = Basemap(rsphere=radius,projection='merc',lat_ts=0.,\
     
    724732    zelinewidth = 1
    725733    zelatmax = 80
     734    if meanlat > 75.: zelatmax = 90. ; step = step/2.
    726735    # to show gcm grid:
    727736    #zecolor = 'r'
     
    833842             "DOWNDRAFT":    "%.0f",\
    834843             "TK":           "%.0f",\
     844             "T":            "%.0f",\
    835845             #"ZMAX_TH":      "%.0f",\
    836846             #"WSTAR":        "%.0f",\
     
    10141024        "South_Pole":            [[-90.,-50.],[-180., 180.]],\
    10151025        "Close_South_Pole":      [[-90.,-75.],[-180., 180.]],\
    1016         "Sirenum_Crater_large":  [[-46.,-34.],[-166., -151.]],\
    1017         "Sirenum_Crater_small":  [[-36.,-26.],[-168., -156.]],\
    1018 
     1026        "Sirenum_Crater_large":  [[-46.,-34.],[-166.,-151.]],\
     1027        "Sirenum_Crater_small":  [[-36.,-26.],[-168.,-156.]],\
     1028        "Rupes":                 [[ 72., 90.],[-120.,- 20.]],\
    10191029              }
    10201030    if area not in list:   area = "Whole"
  • trunk/UTIL/PYTHON/myscript.py

    r612 r637  
    3939    parser.add_option('--ylabel',       action='store',dest='ylab',       type="string",  default=None, help='customize the y-axis label')
    4040    parser.add_option('--labels',       action='store',dest='labels',     type="string",  default=None, help='customize 1D curve labels. Str comma-separated. [None]')
    41     parser.add_option('--lstyle',       action='store',dest='linestyle',  type="string",  default=None, help='customize 1D curve linestyles. String separated by commas. [None]')
     41    parser.add_option('--lstyle',       action='store',dest='linestyle',  type="string",  default=None, help='customize 1D curve linestyles. Str comma-separ. [None]')
    4242
    4343    ### SPECIFIC FOR MAPPING [MAPMODE 1]
     
    4949    parser.add_option('--blat',         action='store',dest='blat',      type="int",     default=None,  help='reference lat (or bounding lat for stere) [computed]')
    5050    parser.add_option('--blon',         action='store',dest='blon',      type="int",     default=None,  help='reference lon [computed]')
    51     parser.add_option('--mark',         action='append',dest='mark',  type="string",  default=None, help='superimpose a crossmark at given coords. lon,lat float separated by commas. [None]')
     51    parser.add_option('--mark',         action='append',dest='mark',  type="string",  default=None, help='superimpose a crossmark at given lon,lat [None]')
    5252
    5353    ### SPECIFIC FOR SLICING [MAPMODE 0]
  • trunk/UTIL/PYTHON/planetoplot.py

    r614 r637  
    8181    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
    8282    import matplotlib as mpl
    83     from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel, axis, ylabel, subplots_adjust, axes
     83    from matplotlib.pyplot import contour,contourf, subplot, figure, rcParams, savefig, colorbar, pcolor, show, plot, clabel, title, close, legend, xlabel, axis, ylabel, subplots_adjust, axes, clabel
    8484    from matplotlib.cm import get_cmap
    8585    #from mpl_toolkits.basemap import cm
     
    141141      elif typefile != typefile0:   errormess("Not the same kind of files !", [typefile0, typefile])
    142142    ### we care for input file being 1D simulations
    143       if typefile in ['gcm'] and len(nc.variables["longitude"][:]) is 1 and len(nc.variables["latitude"][:]) is 1:       mapmode=0 ; winds=False
    144       elif typefile in ['earthgcm'] and len(nc.variables["lon"][:]) is 1 and len(nc.variables["lat"][:]) is 1:           mapmode=0 ; winds=False
     143      if "longitude" in nc.dimensions and "latitude" in nc.dimensions: is1d = len(nc.variables["longitude"][:])*len(nc.variables["latitude"][:])
     144      elif "lon" in nc.dimensions and "lat" in nc.dimensions: is1d = len(nc.variables["lon"][:])*len(nc.variables["lat"][:])
     145      if typefile in ['gcm','earthgcm'] and is1d == 1:       mapmode=0 ; winds=False
    145146    ### we create default vert and time prescriptions if not here in case mapping mode is on (lat/lon maps)
    146147      if redope is None and mapmode == 1:
     
    282283      all_time[k] = time
    283284      if var2:
     285         all_var2[k] = getfield(nc,var2)
    284286         if ((var2 in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (var2 not in nc.variables)): all_var2[k] = slopeamplitude(nc)
    285          else: all_var2[k] = getfield(nc,var2)
    286287      if winds: all_windu[k] = getfield(nc,uchar) ; all_windv[k] = getfield(nc,vchar)
    287288      #####################
     
    561562                                [vecx_frame,vecy_frame] = [dumpbdy(vecx_frame,6,stag=uchar,condition=True), dumpbdy(vecy_frame,6,stag=vchar,condition=True)]
    562563                                key = True
     564                                if fvar in ['UV','uv','uvmet']: key = False
    563565                            elif typefile in ['gcm']:
    564566                                key = False
     
    573575                        zevminc, zevmaxc = calculate_bounds(what_I_plot_frame, vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame))
    574576                        zelevels = np.linspace(zevminc,zevmaxc,ticks/2) #20)
    575                         if var2 == 'HGT': zelevels = np.arange(-10000.,30000.,1000.)
     577                        if var2 == 'HGT':     zelevels = np.arange(-10000.,30000.,1000.)
     578                        elif var2 == 'tpot':  zelevels = np.arange(270,370,5)
     579                        elif var2 == 'tk':    zelevels = np.arange(150,250,5)
    576580                        if mapmode == 0:   
    577                             what_I_plot_frame, x, y = define_axis( lon,lat,vert,time,indexlon,indexlat,indexvert,\
     581                            what_I_plot_frame, x, y = define_axis( lonyeah,latyeah,vert,time,indexlon,indexlat,indexvert,\
    578582                                                              itime,what_I_plot_frame, len(all_var2[index_f].shape),vertmode )
    579                             cs = contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33, alpha=0.5, linestyles='solid')
    580                         elif mapmode == 1:  cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33, alpha=0.5, linestyles='solid')
     583                            ## is this needed? only if len(all_var2[index_f].shape) != len(all_var[index_f].shape)
     584                            cs = contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33)#, alpha=0.5, linestyles='solid')
     585                            clabel(cs, inline=1, fontsize = 4.*rcParams['font.size']/5., fmt=fmtvar(var2.upper()))
     586                        elif mapmode == 1:  cs = m.contour( x,y,what_I_plot_frame, zelevels, colors='k', linewidths = 0.33)#, alpha=0.5, linestyles='solid')
    581587                    if which in ["regular","unidim"]:
    582588
Note: See TracChangeset for help on using the changeset viewer.