Changeset 796 for trunk


Ignore:
Timestamp:
Oct 1, 2012, 1:29:35 AM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON. Added local plot/map capability to MCD interface. Added possibility to set projection and title. Added possibility to map horizontal wind velocity

Location:
trunk/UTIL/PYTHON
Files:
5 edited

Legend:

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

    r793 r796  
    4545import matplotlib.pyplot as mpl
    4646#mpl.show()
    47 mpl.savefig("img/temp.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
     47mpl.savefig("temp.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
  • trunk/UTIL/PYTHON/mcd/mcd.py

    r793 r796  
    3232        ## 1. spatio-temporal coordinates
    3333        self.lat       = 0.
     34        self.lats      = None
     35        self.late      = None
    3436        self.lon       = 0.
     37        self.lons      = None
     38        self.lone      = None
    3539        self.loct      = 0.
     40        self.locts     = None
     41        self.locte     = None
    3642        self.xdate     = 0.  # see datekey
    3743        self.xz        = 10. # see zkey
     44        self.xzs       = None
     45        self.xze       = None
    3846        ## 1bis. related settings
    3947        self.zkey      = 3  # specify that xz is the altitude above surface (m)
     
    177185    def getnameset(self):
    178186    # set a name referring to settings [convenient for databases]
    179         name = str(self.zkey)+str(self.xz)+str(self.lon)+str(self.lat)+str(self.hrkey)+str(self.datekey)+str(self.xdate)+str(self.loct)+str(self.dust)
     187        strlat = str(self.lat)+str(self.lats)+str(self.late)
     188        strlon = str(self.lon)+str(self.lons)+str(self.lone)
     189        strxz = str(self.xz)+str(self.xzs)+str(self.xze)
     190        strloct = str(self.loct)+str(self.locts)+str(self.locte)
     191        name = str(self.zkey)+strxz+strlon+strlat+str(self.hrkey)+str(self.datekey)+str(self.xdate)+strloct+str(self.dust)
    180192        return name
    181193
     
    257269      self.extvartab[i,1:100] = self.extvar[0:99] ## note: var numbering according to MCD manual is kept
    258270
    259     def diurnal(self,nd=13,start=0.,end=24.):
     271    def diurnal(self,nd=13):
    260272    ### retrieve a local time slice
    261273      self.xlabel = "Local time (Martian hour)"
    262       self.prepare(ndx=nd) ; self.xcoord = np.linspace(start,end,nd)
     274      self.prepare(ndx=nd)
     275      if self.locts is not None and self.locte is not None:
     276          if self.locts > self.locte: yeah = self.locts ; self.locts = self.locte ; self.locte = yeah
     277          self.xcoord = np.linspace(self.locts,self.locte,nd)
     278      else:
     279          self.xcoord = np.linspace(0.,24.,nd)
    263280      for i in range(nd): self.loct = self.xcoord[i] ; self.update() ; self.put1d(i)
    264281
    265     def zonal(self,nd=37,start=-180.,end=180.):
     282    def zonal(self,nd=37):
    266283    ### retrieve a longitude slice
    267284      self.xlabel = "East longitude (degrees)"
    268       self.prepare(ndx=nd) ; self.xcoord = np.linspace(start,end,nd)
     285      self.prepare(ndx=nd)
     286      if self.lons is not None and self.lone is not None:
     287          if self.lons > self.lone: yeah = self.lons ; self.lons = self.lone ; self.lone = yeah
     288          self.xcoord = np.linspace(self.lons,self.lone,nd)
     289      else:
     290          self.xcoord = np.linspace(-180.,180.,nd)
    269291      for i in range(nd): self.lon = self.xcoord[i] ; self.update() ; self.put1d(i)
    270292
    271     def meridional(self,nd=19,start=-90.,end=90.):
     293    def meridional(self,nd=19):
    272294    ### retrieve a latitude slice
    273295      self.xlabel = "North latitude (degrees)"
    274       self.prepare(ndx=nd) ; self.xcoord = np.linspace(start,end,nd)
     296      self.prepare(ndx=nd)
     297      if self.lats is not None and self.late is not None:
     298          if self.lats > self.late: yeah = self.lats ; self.lats = self.late ; self.late = yeah
     299          self.xcoord = np.linspace(self.lats,self.late,nd)
     300      else:                                               
     301          self.xcoord = np.linspace(-90.,90.,nd)
    275302      for i in range(nd): self.lat = self.xcoord[i] ; self.update() ; self.put1d(i)
    276303
    277     def profile(self,nd=20,start=0.,end=120000.,tabperso=None):
     304    def profile(self,nd=20,tabperso=None):
    278305    ### retrieve an altitude slice (profile)
    279306      self.xlabel = "Altitude (m)"
    280307      if tabperso is not None: nd = len(tabperso)
    281308      self.prepare(ndx=nd)
    282       if tabperso is None:  self.xcoord = np.linspace(start,end,nd)
    283       else:                 self.xcoord = tabperso
     309      if tabperso is not None:
     310          self.xcoord = tabperso
     311      elif self.xzs is not None and self.xze is not None:
     312          ## here we should code the log axis for pressure
     313          self.xcoord = np.linspace(self.xzs,self.xze,nd)
     314      else:
     315          self.xcoord = np.linspace(0.,120000.,nd)
    284316      for i in range(nd): self.xz = self.xcoord[i] ; self.update() ; self.put1d(i)
    285317
     
    332364###################
    333365
    334     def latlon(self,ndx=37,startx=-180.,endx=180.,ndy=19,starty=-90.,endy=90.,fixedlt=False):
     366    def latlon(self,ndx=37,ndy=19,fixedlt=False):
    335367    ### retrieve a latitude/longitude slice
    336368    ### default is: local time is not fixed. user-defined local time is at longitude 0.
    337369      self.xlabel = "East longitude (degrees)" ; self.ylabel = "North latitude (degrees)"
    338370      self.prepare(ndx=ndx,ndy=ndy)
    339       self.xcoord = np.linspace(startx,endx,ndx) ; self.ycoord = np.linspace(starty,endy,ndy)
     371      if self.lons is not None and self.lone is not None:
     372          if self.lons > self.lone: yeah = self.lons ; self.lons = self.lone ; self.lone = yeah
     373          self.xcoord = np.linspace(self.lons,self.lone,ndx)
     374      else:
     375          self.xcoord = np.linspace(-180.,180.,ndx)
     376      if self.lats is not None and self.late is not None:
     377          if self.lats > self.late: yeah = self.lats ; self.lats = self.late ; self.late = yeah
     378          self.ycoord = np.linspace(self.lats,self.late,ndy)
     379      else:
     380          self.ycoord = np.linspace(-90.,90.,ndy)
    340381      if not fixedlt: umst = self.loct
    341382      for i in range(ndx):
     
    355396      self.extvartab[i,j,1:100] = self.extvar[0:99] ## note: var numbering according to MCD manual is kept
    356397
    357     def makemap2d(self,choice,incwind=False,fixedlt=False):
     398    def makemap2d(self,choice,incwind=False,fixedlt=False,proj="cyl"):
    358399    ### one 2D map is created for the user-defined variable in choice.
    359400      self.latlon(fixedlt=fixedlt) ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
    360       (field, fieldlab) = self.definefield(choice)
    361       if incwind:
     401      if choice == "wind" or incwind:
    362402          (windx, fieldlabwx) = self.definefield("u")
    363403          (windy, fieldlabwy) = self.definefield("v")
    364           myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj="cyl",vecx=windx,vecy=windy)
    365       else:
    366           myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj="moll")
     404      if choice == "wind":
     405          field = np.sqrt(windx*windx + windy*windy)
     406          fieldlab = "Horizontal wind speed (m/s)"
     407      else:   
     408          (field, fieldlab) = self.definefield(choice)
     409      if incwind:   myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj=proj,vecx=windx,vecy=windy) #,stride=1)
     410      else:         myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj=proj)
    367411      mpl.figtext(0.5, 0.0, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center')
    368412
    369     def map2d(self,tabtodo,incwind=False,fixedlt=False):
     413    def map2d(self,tabtodo,incwind=False,fixedlt=False,proj="cyl"):
    370414    ### complete 2D figure with possible multiplots
    371415      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
     
    373417      fig = mpl.figure()
    374418      subv,subh = myplot.definesubplot( len(tabtodo) , fig )
    375       for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind,fixedlt=fixedlt)
    376 
    377     def htmlmap2d(self,tabtodo,incwind=False,fixedlt=False,figname="temp.png"):
     419      for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind,fixedlt=fixedlt,proj=proj)
     420
     421    def htmlmap2d(self,tabtodo,incwind=False,fixedlt=False,figname="temp.png",title=""):
    378422    ### complete 2D figure with possible multiplots
    379423    ### added in 09/2012 for online MCD
     
    392436        yeah = fig.add_subplot(subv,subh,i+1)
    393437        choice = tabtodo[i]
    394         self.latlon(fixedlt=fixedlt) ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
     438        self.latlon(fixedlt=fixedlt)
     439        ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
    395440        (field, fieldlab) = self.definefield(choice)
    396441        if incwind: (windx, fieldlabwx) = self.definefield("u") ; (windy, fieldlabwy) = self.definefield("v")
     
    428473        Figure.colorbar(fig,c,orientation='vertical',format="%.1e")
    429474        ax = fig.gca() ; ax.set_title(fieldlab) ; ax.set_ylabel("Latitude") ; ax.set_xlabel("Longitude")
    430         ax.set_xticks(np.arange(-180,181,45)) ; ax.set_xbound(lower=-180, upper=180)
    431         ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=-90, upper=90)
     475        ax.set_xticks(np.arange(-180,181,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
     476        ax.set_yticks(np.arange(-90,91,30)) ; ax.set_ybound(lower=self.lats, upper=self.late)
    432477        if incwind:
    433478          [x2d,y2d] = np.meshgrid(x,y)
    434479          yeah.quiver(x2d,y2d,np.transpose(windx),np.transpose(windy))
     480      fig.text(0.5, 0.95, title, ha='center')
    435481      fig.text(0.5, 0.01, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center')
    436482      canvas = FigureCanvasAgg(fig)
  • trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py

    r794 r796  
     1###!/usr/bin/env python
    12#!/usr/bin/python
    23###!/home/aymeric/Software/epd-7.0-2-rh5-x86/bin/python
     
    1213##################################################
    1314### ajouts et corrections par Franck Guyon 09/2012
     15### ajouts suite a brainstorm equipe AS 10/2012
    1416
    1517import cgi, cgitb
     
    3638# Get data from user-defined fields and define free dimensions
    3739# FG: add tests if var==None to have values in local without forms ones
     40query.lat = -9999.
    3841getlat = form.getvalue("latitude")
    39 if getlat == None: getlat = 1
    40 if getlat == "all":  islatfree = 1 ; query.lat = -9999.
     42if getlat == None: getlat = "1"
     43if getlat == "all":  islatfree = 1 ; query.lats = -90. ; query.late = 90.
     44elif ";" in getlat:  islatfree = 1 ; ind = getlat.find(";") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:])
    4145else:                islatfree = 0 ; query.lat = float(getlat)
    4246
     47query.lon = -9999.
    4348getlon = form.getvalue("longitude")
    44 if getlon == None: getlon = 1
    45 if getlon == "all":  islonfree = 1 ; query.lon = -9999.
     49if getlon == None: getlon = "1"
     50if getlon == "all":  islonfree = 1 ; query.lons = -180. ; query.lone = 180.
     51elif ";" in getlon:  islonfree = 1 ; ind = getlon.find(";") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:])
    4652else:                islonfree = 0 ; query.lon = float(getlon)
    4753
     54query.loct = -9999.
    4855getloct = form.getvalue("localtime")
    49 if getloct == None: getloct = 1
    50 if getloct == "all": isloctfree = 1 ; query.loct = -9999.
     56if getloct == None: getloct = "1"
     57if getloct == "all": isloctfree = 1 ; query.locts = 0. ; query.locte = 24.
     58elif ";" in getloct: isloctfree = 1 ; ind = getloct.find(";") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:])
    5159else:                isloctfree = 0 ; query.loct = float(getloct)
    5260
     61query.xz = -9999.
    5362getalt = form.getvalue("altitude")
    54 if getalt == None: getalt = 1
    55 if getalt == "all":  isaltfree = 1 ; query.xz = -9999.
     63if getalt == None: getalt = "1"
     64if getalt == "all":  isaltfree = 1 ; query.xzs = 0. ; query.xze = 120000.
     65elif ";" in getalt:  isaltfree = 1 ; ind = getalt.find(";") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:])
    5666else:                isaltfree = 0 ; query.xz = float(getalt)
    5767
     
    96106
    97107# reference name (to test which figures are already in the database)
    98 reference = str(islatfree)+str(islonfree)+str(isloctfree)+str(isaltfree)+query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)
     108reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)
    99109figname = '../img/'+reference+'.png'
    100110
     
    127137
    128138    ### figure   
    129     query.htmlmap2d(vartoplot,incwind=iswindlog,fixedlt=input_fixedlt,figname=figname)
     139    zetitle = "MCD v4.3 - Dust scenario "+str(query.dust)+" - Date is "+str(query.xdate)
     140    query.htmlmap2d(vartoplot,incwind=iswindlog,fixedlt=input_fixedlt,figname=figname,title=zetitle)
    130141    #mpl.savefig("img/temp.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
    131142    #Image.open("img/temp.png").save(figname,'JPEG') ##lighter images   
  • trunk/UTIL/PYTHON/mcd/proto/index.html

    r793 r796  
    9696<td align="center">
    9797<b>CUSTOMIZE COORDINATES ON MARS</b><br />
     98please give: a value (or) a range val1;val2 (or) 'all'<br />
    9899<ul>
    99 <li>Latitude <input type="text" size="3" name="latitude" value="0."> (write a value or 'all')
    100 <li>Longitude <input type="text" size="3" name="longitude" value="0."> (write a value or 'all')
    101 <li>Local Time <input type="text" size="2" name="localtime" value="0."> (write a value or 'all')
    102 <li>Altitude (m) <input type="text" size="3" name="altitude" value="10."> (write a value or 'all')
     100<li>North Latitude <input type="text" size="7" name="latitude" value="0.">
     101<li>East Longitude <input type="text" size="7" name="longitude" value="0.">
     102<li>Local Time <input type="text" size="7" name="localtime" value="0.">
     103<li>Altitude (m) <input type="text" size="7" name="altitude" value="10.">
    103104<!--
    104105<li>Latitude   
  • trunk/UTIL/PYTHON/myplot.py

    r792 r796  
    14191419    elif numdim == 1:   [lon2d,lat2d] = np.meshgrid(lon,lat)
    14201420    else:               errormess("lon and lat arrays must be 1D or 2D")
    1421     [wlon,wlat] = latinterv()
     1421    #[wlon,wlat] = latinterv()
     1422    [wlon,wlat] = simplinterv(lon2d,lat2d)
    14221423    ## define projection and background. define x and y given the projection
    14231424    m = define_proj(proj,wlon,wlat,back=zeback,blat=None,blon=None)
Note: See TracChangeset for help on using the changeset viewer.