Ignore:
Timestamp:
Oct 15, 2012, 2:12:07 AM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON. mcd. background topo from surfacenc. title on colorbar on 2D maps. correct aspect ratio for 2D maps.

File:
1 edited

Legend:

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

    r806 r807  
    110110        2: "Altitude above areoid (Mars geoid) (m)",\
    111111        3: "Altitude above local surface (m)",\
    112         4: "orographic height (m) (surface altitude above areoid)",\
     112        4: "orographic height (m) (surf alt above areoid)",\
    113113        5: "Ls, solar longitude of Mars (deg)",\
    114114        6: "LST local true solar time (hrs)",\
     
    122122        14: "GCM orography (m)",\
    123123        15: "surface temperature (K)",\
    124         16: "daily maximum mean surface temperature (K)",\
    125         17: "daily minimum mean surface temperature (K)",\
     124        16: "daily max mean surface temperature (K)",\
     125        17: "daily min mean surface temperature (K)",\
    126126        18: "surf. temperature RMS day to day variations (K)",\
    127127        19: "surface pressure (high resolution if hireskey=1)",\
     
    522522      for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind,fixedlt=fixedlt,proj=proj)
    523523
    524     def htmlmap2d(self,tabtodo,incwind=False,fixedlt=False,figname="temp.png",title=""):
     524    def htmlmap2d(self,tabtodo,incwind=False,fixedlt=False,figname="temp.png",title="",back="zMOL"):
    525525    ### complete 2D figure with possible multiplots
    526526    ### added in 09/2012 for online MCD
     
    529529      from matplotlib.backends.backend_agg import FigureCanvasAgg
    530530      from matplotlib.cm import get_cmap
     531
     532      #from mpl_toolkits.basemap import Basemap
     533
     534      from Scientific.IO import NetCDF
     535      filename = "/home/marshttp/surface.nc"
     536      zefile = NetCDF.NetCDFFile(filename, 'r')
     537      fieldc = zefile.variables[back]
     538      yc = zefile.variables['latitude']
     539      xc = zefile.variables['longitude']
     540      ## plutot que fieldc = self.getextvar(self.convertlab("topo"))
     541
    531542      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
    532543      if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
    533       fig = Figure(figsize=(8,8)) ; subv,subh = myplot.definesubplot( len(tabtodo) , fig )
    534 
    535       ### topocontours
    536       fieldc = self.getextvar(self.convertlab("topo"))
     544
     545      howmanyplots = len(tabtodo)
     546      if howmanyplots == 1: fig = Figure(figsize=(16,8))
     547      elif howmanyplots == 2: fig = Figure(figsize=(8,8))
     548      elif howmanyplots == 3: fig = Figure(figsize=(8,16))
     549      elif howmanyplots == 4: fig = Figure(figsize=(16,8))
     550
     551      subv,subh = myplot.definesubplot( len(tabtodo) , fig )
    537552
    538553      for i in range(len(tabtodo)):
     
    544559        if incwind: (windx, fieldlabwx) = self.definefield("u") ; (windy, fieldlabwy) = self.definefield("v")
    545560
    546         proj="cyl" ; colorb="jet" ; ndiv=20 ; zeback="molabw" ; trans=1.0 #0.6
     561        proj="moll" ; colorb="jet" ; ndiv=20 ; zeback="molabw" ; trans=1.0 #0.6
    547562        title="" ; vecx=None ; vecy=None ; stride=2
    548563        lon = self.xcoord
    549564        lat = self.ycoord
    550 
    551         ### get lon and lat in 2D version. get lat/lon intervals
    552         #numdim = len(np.array(lon).shape)
    553         #if numdim == 2:     [lon2d,lat2d] = [lon,lat]
    554         #elif numdim == 1:   [lon2d,lat2d] = np.meshgrid(lon,lat)
    555         #else:               errormess("lon and lat arrays must be 1D or 2D")
    556         #[wlon,wlat] = myplot.latinterv()
    557         ### define projection and background. define x and y given the projection
    558         #m = basemap.Basemap(projection='moll') marche pas
    559         #m = myplot.define_proj(proj,wlon,wlat,back=zeback,blat=None,blon=None)
    560         #x, y = m(lon2d, lat2d)
    561         ### TEMP
     565       
     566        #[lon2d,lat2d] = np.meshgrid(lon,lat)
     567        ##### define projection and background. define x and y given the projection
     568        ##[wlon,wlat] = myplot.latinterv()
     569        ##yeahm = myplot.define_proj(proj,wlon,wlat,back=zeback,blat=None,blon=None)
     570        ##x, y = yeahm(lon2d, lat2d)
     571        #map = Basemap(projection='ortho',lat_0=45,lon_0=-100)
     572        #x, y = map(lon2d, lat2d)
     573
     574        #### TEMP
    562575        x = lon ; y = lat
     576
    563577        ## define field. bound field.
    564578        what_I_plot = np.transpose(field)
     
    569583        zelevels = np.linspace(zevmin,zevmax,ticks)
    570584        palette = get_cmap(name=colorb)
     585
    571586        ## contours topo
    572         zelevc = np.linspace(-8000.,20000.,20)
    573         yeah.contour( x, y, np.transpose(fieldc), zelevc, colors='black',linewidths = 0.4)
     587        zelevc = np.linspace(-9.,20.,11)
     588        yeah.contour( xc, yc, fieldc, zelevc, colors='black',linewidths = 0.4)
    574589        # contour field
    575590        c = yeah.contourf( x, y, what_I_plot, zelevels, cmap = palette, alpha = trans )
    576         clb = Figure.colorbar(fig,c,orientation='vertical',format="%.1e")
     591        clb = Figure.colorbar(fig,c,orientation='vertical',format="%.2e",ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,21])))
    577592        clb.set_label(fieldlab)
    578         ax = fig.gca() ; ax.set_title(fieldlab) ; ax.set_ylabel("Latitude") ; ax.set_xlabel("Longitude")
     593        ax = fig.gca() ; ax.set_ylabel("Latitude") ; ax.set_xlabel("Longitude")
    579594        ax.set_xticks(np.arange(-180,181,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
    580595        ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=self.lats, upper=self.late)
     
    622637        # contour field
    623638        c = yeah.contourf( self.xcoord, self.ycoord, what_I_plot, zelevels, cmap = palette )
    624         clb = Figure.colorbar(fig,c,orientation='vertical',format="%.1e")
     639        clb = Figure.colorbar(fig,c,orientation='vertical',format="%.2e",ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,21])))
    625640        clb.set_label(fieldlab)
    626641        ax = fig.gca() ; ax.set_ylabel(self.ylabel) ; ax.set_xlabel(self.xlabel)
Note: See TracChangeset for help on using the changeset viewer.