Changeset 821 for trunk


Ignore:
Timestamp:
Oct 29, 2012, 11:06:27 AM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON. MCD online interface. addressed the TODO list of rev 812, plus other small improvements. this version was sent to beta-testers in the euromars list.

Location:
trunk/UTIL/PYTHON/mcd
Files:
4 edited

Legend:

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

    r813 r821  
    7474        self.zonwindtab = None ; self.merwindtab = None ; self.meanvartab = None ; self.extvartab = None
    7575        ## plot stuff
    76         self.xlabel = None ; self.ylabel = None
     76        self.xlabel = None ; self.ylabel = None ; self.title = ""
    7777        self.vertplot = False
    78         self.fmt = "%.2e"
     78        self.fmt = "%.2e"
     79        self.colorm = "jet"
     80        self.fixedlt = False
     81        self.zonmean = False
    7982
    8083    def viking1(self): self.name = "Viking 1 site. MCD v4.3 output" ; self.lat = 22.48 ; self.lon = -49.97 ; self.xdate = 97.
     
    97100        elif self.datekey == 0:  self.title = self.title + " JD " + str(self.xdate) + "."
    98101        if not oneline: self.title = self.title + "\n"
    99         if self.lats is None:  self.title = self.title + " Latitude " + str(self.lat) + "E"
    100         if self.lons is None:  self.title = self.title + " Longitude " + str(self.lon) + "N"
     102        if self.lats is None:  self.title = self.title + " Latitude " + str(self.lat) + "N"
     103        if self.zonmean: self.title = self.title + "Zonal mean over all longitudes."
     104        elif self.lons is None: self.title = self.title + " Longitude " + str(self.lon) + "E"
    101105        if self.xzs is None:   
    102106            self.vertunits()
    103107            self.title = self.title + " Altitude " + str(self.xz) + " " + self.vunits
    104         if self.locts is None: self.title = self.title + " Local time " + str(self.loct) + "h"
     108        if self.locts is None:
     109            self.title = self.title + " Local time " + str(self.loct) + "h"
     110            if not self.fixedlt:  self.title = self.title + " (at longitude 0) "
    105111
    106112    def getextvarlab(self,num):
     
    269275    # print extra MCD variables
    270276        num = self.convertlab(num)
    271         print self.getextvarlab(num) + " ..... " + str(self.extvar[num-1])
     277        dastr = str(self.extvar[num-1])
     278        if dastr == "nan":   print "!!!! There is a problem, probably a value is requested below the surface !!!!"
     279        else:                print self.getextvarlab(num) + " ..... " + dastr
    272280
    273281    def printallextvar(self):
     
    276284
    277285    def htmlprinttabextvar(self,tabtodo):
     286        self.fixedlt = True ## local time is real local time
    278287        self.gettitle()
    279288        print "<hr>"
     
    383392    def diurnal(self,nd=13):
    384393    ### retrieve a local time slice
     394      self.fixedlt = True  ## local time is real local time
    385395      save = self.loct
    386396      self.xlabel = "Local time (Martian hour)"
     
    394404      self.xlabel = "East longitude (degrees)"
    395405      self.prepare(ndx=nd) ; self.ininterv(-180.,180.,nd,start=self.lons,end=self.lone)
    396       for i in range(nd): self.lon = self.xcoord[i] ; self.update() ; self.put1d(i)
     406      if not self.fixedlt: umst = self.loct
     407      for i in range(nd):
     408          self.lon = self.xcoord[i]
     409          if not self.fixedlt: self.loct = (umst + self.lon/15.) % 24
     410          self.update() ; self.put1d(i)
    397411      self.lon = save
    398412
    399413    def meridional(self,nd=19):
    400414    ### retrieve a latitude slice
     415      self.fixedlt = True  ## local time is real local time
    401416      save = self.lat
    402417      self.xlabel = "North latitude (degrees)"
     
    407422    def profile(self,nd=20,tabperso=None):
    408423    ### retrieve an altitude slice (profile)
     424      self.fixedlt = True  ## local time is real local time
    409425      save = self.xz
    410426      self.vertlabel()
     
    482498        yeah.plot(absc,ordo,'-bo') #; mpl.xticks(query.xcoord)
    483499        ax = fig.gca() ; ax.set_ylabel(ordolab) ; ax.set_xlabel(absclab)
    484         if self.zkey == 4: ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1])
     500
     501        if self.xzs is not None and self.zkey == 4: ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1])
    485502
    486503        if self.lats is not None:      ax.set_xticks(np.arange(-90,91,15)) ; ax.set_xbound(lower=self.lats, upper=self.late)
    487504        elif self.lons is not None:    ax.set_xticks(np.arange(-360,361,30)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
    488505        elif self.locts is not None:   ax.set_xticks(np.arange(0,26,2)) ; ax.set_xbound(lower=self.locts, upper=self.locte)
     506
     507        ax.grid(True, linestyle=':', color='grey')
    489508
    490509      self.gettitle()
     
    500519###################
    501520
    502     def latlon(self,ndx=37,ndy=19,fixedlt=False):
     521    def latlon(self,ndx=37,ndy=19):
    503522    ### retrieve a latitude/longitude slice
    504523    ### default is: local time is not fixed. user-defined local time is at longitude 0.
     
    508527      self.ininterv(-180.,180.,ndx,start=self.lons,end=self.lone)
    509528      self.ininterv(-90.,  90.,ndy,start=self.lats,end=self.late,yaxis=True)
    510       if not fixedlt: umst = self.loct
     529      if not self.fixedlt: umst = self.loct
    511530      for i in range(ndx):
    512531       for j in range(ndy):
    513532         self.lon = self.xcoord[i] ; self.lat = self.ycoord[j]
    514          if not fixedlt: self.loct = (umst + self.lon/15.) % 24
     533         if not self.fixedlt: self.loct = (umst + self.lon/15.) % 24
    515534         self.update() ; self.put2d(i,j)
    516       if not fixedlt: self.loct = umst
     535      if not self.fixedlt: self.loct = umst
    517536      self.lon = save1 ; self.lat = save2 ; self.loct = save3
    518537
    519     def lonalt(self,ndx=37,ndy=20,fixedlt=False):
    520     ### retrieve a longitude/altitude slice
    521       save1 = self.lon ; save2 = self.xz ; save3 = self.loct
     538    def secalt(self,ndx=37,ndy=20,typex="lat"):
     539    ### retrieve a coordinate/altitude slice
     540      save1 = self.lon ; save2 = self.xz ; save3 = self.loct ; save4 = self.lat
     541      self.prepare(ndx=ndx,ndy=ndy)
    522542      self.vertlabel() ; self.ylabel = self.xlabel
    523       self.xlabel = "East longitude (degrees)"
    524       self.prepare(ndx=ndx,ndy=ndy)
    525       self.ininterv(-180.,180.,ndx,start=self.lons,end=self.lone)
    526543      self.vertaxis(ndy,yaxis=True)
    527       if not fixedlt: umst = self.loct
     544      if "lat" in typex:
     545          self.xlabel = "North latitude (degrees)"
     546          self.ininterv(-90.,90.,ndx,start=self.lats,end=self.late)
     547      elif typex == "lon":
     548          self.xlabel = "East longitude (degrees)"
     549          self.ininterv(-180.,180.,ndx,start=self.lons,end=self.lone)
     550      if not self.fixedlt: umst = self.loct
    528551      for i in range(ndx):
    529552       for j in range(ndy):
    530          self.lon = self.xcoord[i] ; self.xz = self.ycoord[j]
    531          if not fixedlt: self.loct = (umst + self.lon/15.) % 24
     553         if typex == "lat":   self.lat = self.xcoord[i]
     554         elif typex == "lon": self.lon = self.xcoord[i]
     555         self.xz = self.ycoord[j]
     556         if not self.fixedlt: self.loct = (umst + self.lon/15.) % 24
    532557         self.update() ; self.put2d(i,j)
    533       if not fixedlt: self.loct = umst
    534       self.lon = save1 ; self.xz = save2 ; self.loct = save3
    535 
    536     def latalt(self,ndx=19,ndy=20,fixedlt=False):
    537     ### retrieve a latitude/altitude slice
    538       save1 = self.lat ; save2 = self.xz ; save3 = self.loct
     558      if not self.fixedlt: self.loct = umst
     559      self.lon = save1 ; self.xz = save2 ; self.loct = save3 ; self.lat = save4
     560
     561    def zonalmean(self,ndx=37,ndy=20,ndmean=32):
     562    ### retrieve a zonalmean lat/altitude slice
     563      self.fixedlt = False
     564      save1 = self.lon ; save2 = self.xz ; save3 = self.loct ; save4 = self.lat
     565      self.prepare(ndx=ndx,ndy=ndy)
    539566      self.vertlabel() ; self.ylabel = self.xlabel
     567      self.vertaxis(ndy,yaxis=True)
    540568      self.xlabel = "North latitude (degrees)"
    541       self.prepare(ndx=ndx,ndy=ndy)
     569      self.ininterv(-180.,180.,ndmean)
     570      coordmean = self.xcoord
    542571      self.ininterv(-90.,90.,ndx,start=self.lats,end=self.late)
    543       self.vertaxis(ndy,yaxis=True)
    544       if not fixedlt: umst = self.loct
     572      umst = self.loct #fixedlt false for this case
     573      for i in range(ndx):
     574       self.lat = self.xcoord[i]
     575       for j in range(ndy):
     576        self.xz = self.ycoord[j]
     577        meanpres = 0. ; meandens = 0. ; meantemp = 0. ; meanzonwind = 0. ; meanmerwind = 0. ; meanmeanvar = np.zeros(5) ; meanextvar = np.zeros(100)       
     578        for m in range(ndmean):
     579           self.lon = coordmean[m]
     580           self.loct = (umst + self.lon/15.) % 24 #fixedlt false for this case
     581           self.update()
     582           meanpres = meanpres + self.pres/float(ndmean) ; meandens = meandens + self.dens/float(ndmean) ; meantemp = meantemp + self.temp/float(ndmean)
     583           meanzonwind = meanzonwind + self.zonwind/float(ndmean) ; meanmerwind = meanmerwind + self.merwind/float(ndmean)
     584           meanmeanvar = meanmeanvar + self.meanvar/float(ndmean) ; meanextvar = meanextvar + self.extvar/float(ndmean)
     585        self.pres=meanpres ; self.dens=meandens ; self.temp=meantemp ; self.zonwind=meanzonwind ; self.merwind=meanmerwind
     586        self.meanvar=meanmeanvar ; self.extvar=meanextvar
     587        self.put2d(i,j)
     588      self.loct = umst #fixedlt false for this case
     589      self.lon = save1 ; self.xz = save2 ; self.loct = save3 ; self.lat = save4
     590
     591    def hovmoller(self,ndtime=25,ndcoord=20,typex="lat"):
     592    ### retrieve a time/other coordinate slice
     593      save1 = self.lat ; save2 = self.xz ; save3 = self.loct ; save4 = self.lon
     594      if typex == "lat":
     595          ndx = ndcoord ; self.xlabel = "North latitude (degrees)"
     596          ndy = ndtime ; self.ylabel = "Local time (Martian hour)"
     597          self.prepare(ndx=ndx,ndy=ndy)
     598          self.ininterv(-90.,90.,ndx,start=self.lats,end=self.late)
     599          self.ininterv(0.,24.,ndy,start=self.locts,end=self.locte,yaxis=True)
     600      elif typex == "lon":
     601          ndx = ndcoord ; self.xlabel = "East longitude (degrees)"
     602          ndy = ndtime ; self.ylabel = "Local time (Martian hour)"
     603          self.prepare(ndx=ndx,ndy=ndy)
     604          self.ininterv(-180.,180.,ndx,start=self.lons,end=self.lone)
     605          self.ininterv(0.,24.,ndy,start=self.locts,end=self.locte,yaxis=True)
     606      elif typex == "alt":
     607          ndy = ndcoord ; self.vertlabel() ; self.ylabel = self.xlabel
     608          ndx = ndtime ; self.xlabel = "Local time (Martian hour)"
     609          self.prepare(ndx=ndx,ndy=ndy)
     610          self.vertaxis(ndy,yaxis=True)
     611          self.ininterv(0.,24.,ndx,start=self.locts,end=self.locte)
    545612      for i in range(ndx):
    546613       for j in range(ndy):
    547          self.lat = self.xcoord[i] ; self.xz = self.ycoord[j]
    548          if not fixedlt: self.loct = (umst + self.lon/15.) % 24
     614         if typex == "lat":   self.lat = self.xcoord[i] ; self.loct = self.ycoord[j]
     615         elif typex == "lon": self.lon = self.xcoord[i] ; self.loct = self.ycoord[j]
     616         elif typex == "alt": self.xz = self.ycoord[j] ; self.loct = self.xcoord[i]
    549617         self.update() ; self.put2d(i,j)
    550       if not fixedlt: self.loct = umst
    551       self.lat = save1 ; self.xz = save2 ; self.loct = save3
     618      self.lat = save1 ; self.xz = save2 ; self.loct = save3 ; self.lon = save4
    552619
    553620    def put2d(self,i,j):
     
    560627      self.extvartab[i,j,1:100] = self.extvar[0:99] ## note: var numbering according to MCD manual is kept
    561628
    562     def makemap2d(self,choice,incwind=False,fixedlt=False,proj="cyl"):
     629    def makemap2d(self,choice,incwind=False,proj="cyl"):
    563630    ### one 2D map is created for the user-defined variable in choice.
    564       self.latlon(fixedlt=fixedlt) ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
     631      self.latlon() ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
    565632      if choice == "wind" or incwind:
    566633          (windx, fieldlabwx) = self.definefield("u")
     
    575642      mpl.figtext(0.5, 0.0, self.ack, ha='center')
    576643
    577     def map2d(self,tabtodo,incwind=False,fixedlt=False,proj="cyl"):
     644    def map2d(self,tabtodo,incwind=False,proj="cyl"):
    578645    ### complete 2D figure with possible multiplots
    579646      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
     
    581648      fig = mpl.figure()
    582649      subv,subh = myplot.definesubplot( len(tabtodo) , fig )
    583       for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind,fixedlt=fixedlt,proj=proj)
    584 
    585     def htmlmap2d(self,tabtodo,incwind=False,fixedlt=False,figname="temp.png",title="",back="zMOL"):
     650      for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind,proj=proj)
     651
     652    def htmlmap2d(self,tabtodo,incwind=False,figname="temp.png",back="zMOL"):
    586653    ### complete 2D figure with possible multiplots
    587654    ### added in 09/2012 for online MCD
     
    591658      from matplotlib.cm import get_cmap
    592659      from matplotlib import rcParams
    593 
    594       #from mpl_toolkits.basemap import Basemap
    595 
     660      #from mpl_toolkits.basemap import Basemap # does not work
    596661      from Scientific.IO import NetCDF
     662
    597663      filename = "/home/marshttp/surface.nc"
    598664      zefile = NetCDF.NetCDFFile(filename, 'r')
     
    600666      yc = zefile.variables['latitude']
    601667      xc = zefile.variables['longitude']
    602       ## plutot que fieldc = self.getextvar(self.convertlab("topo"))
    603668
    604669      if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible.
     
    616681        yeah = fig.add_subplot(subv,subh,i+1)
    617682        choice = tabtodo[i]
    618         self.latlon(fixedlt=fixedlt,ndx=64,ndy=48)
     683        self.latlon(ndx=64,ndy=48)
    619684        ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)
    620685        (field, fieldlab) = self.definefield(choice)
    621686        if incwind: (windx, fieldlabwx) = self.definefield("u") ; (windy, fieldlabwy) = self.definefield("v")
    622687
    623         proj="moll" ; colorb="jet" ; ndiv=20 ; zeback="molabw" ; trans=1.0 #0.6
    624         title="" ; vecx=None ; vecy=None ; stride=2
     688        proj="moll" ; colorb= self.colorm ; ndiv=20 ; zeback="molabw" ; trans=1.0 #0.6
     689        vecx=None ; vecy=None ; stride=2
    625690        lon = self.xcoord
    626691        lat = self.ycoord
     
    671736      canvas.print_figure(figname, dpi=80)
    672737
    673     def htmlplot2d(self,tabtodo,fixedlt=False,figname="temp.png",title=""):
     738    def htmlplot2d(self,tabtodo,figname="temp.png"):
    674739    ### complete 2D figure with possible multiplots
    675740    ### added in 10/2012 for online MCD
     
    693758        choice = tabtodo[i]
    694759
    695         if self.lons is not None:    self.lonalt(fixedlt=fixedlt,ndx=64,ndy=35)
    696         elif self.lats is not None:  self.latalt(fixedlt=fixedlt,ndx=48,ndy=35)
     760        if self.lons is not None:   
     761           if self.locts is None:  self.secalt(ndx=64,ndy=35,typex="lon")
     762           else:                   self.hovmoller(ndcoord=64,typex="lon")
     763        elif self.lats is not None: 
     764           if self.locts is None: 
     765               if self.zonmean:   self.zonalmean()
     766               else:         self.secalt(ndx=48,ndy=35,typex="lat")
     767           else:                   self.hovmoller(ndcoord=48,typex="lat")
     768        else:
     769           self.hovmoller(ndcoord=35,typex="alt")
    697770
    698771        (field, fieldlab) = self.definefield(choice)
    699772
    700         colorb="jet" ; ndiv=20 ; title=""
     773        colorb=self.colorm ; ndiv=20
    701774
    702775        ## define field. bound field.
     
    714787        ax = fig.gca() ; ax.set_ylabel(self.ylabel) ; ax.set_xlabel(self.xlabel)
    715788
    716         if self.zkey == 4:
     789        if self.lons is not None:   ax.set_xticks(np.arange(-360,361,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
     790        elif self.lats is not None: ax.set_xticks(np.arange(-90,91,30)) ; ax.set_xbound(lower=self.lats, upper=self.late)
     791
     792        if self.locts is not None:
     793            if self.xzs is not None: ax.set_xticks(np.arange(0,26,2)) ; ax.set_xbound(lower=self.locts, upper=self.locte)
     794            else:                    ax.set_yticks(np.arange(0,26,2)) ; ax.set_ybound(lower=self.locts, upper=self.locte)
     795
     796        if self.zkey == 4 and self.xzs is not None:
    717797            ax.set_yscale('log') ; ax.set_ylim(ax.get_ylim()[::-1])
    718798        else:
    719799            #ax.set_yticks(np.arange(self.xzs,self.xze,10000.)) ;
    720800            ax.set_ybound(lower=self.xzs, upper=self.xze)
    721 
    722         if self.lons is not None: ax.set_xticks(np.arange(-360,361,45)) ; ax.set_xbound(lower=self.lons, upper=self.lone)
    723         elif self.lats is not None: ax.set_xticks(np.arange(-90,91,30)) ; ax.set_xbound(lower=self.lats, upper=self.late)
    724801
    725802      self.gettitle()
  • trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py

    r812 r821  
    1717import cgi, cgitb
    1818import numpy as np
    19 #from mcd import mcd
    2019from modules import *
    2120from modules import mcd
     
    2423import os as daos
    2524import matplotlib.pyplot as mpl
    26 from PIL import Image
    27 
    28 
    2925
    3026### a function to read HTML arguments for coordinates
    3127def gethtmlcoord(userinput,defmin,defmax):
    32    # accepted separators
    33    separators = [":",";",",","/"]
     28   import string
     29   # accepted separators. the symbol - should always be last.
     30   separators = [":",";",",","/","_"]
    3431   # initial values
    3532   val = -9999. ; vals = None ; vale = None ; foundinterv = False
    3633   if userinput == None:   userinput = "1"
    37    # the main work. either all -- or an interval -- or a single value.
     34   # the main work. either all, or an interval, or a single value.
     35   # ... all
    3836   if userinput == "all":  isfree = 1 ; vals = defmin ; vale = defmax ; foundinterv = True
     37   # ... an interval
    3938   else:
    4039       for sep in separators:
     40         if not foundinterv:
    4141           isfree = 1 ; ind = userinput.find(sep)
    4242           if ind != -1: vals = float(userinput[:ind]) ; vale = float(userinput[ind+1:]) ; foundinterv = True
    43    if not foundinterv: isfree = 0 ; val = float(userinput)
     43   # ... a single value (or an error)
     44   if not foundinterv:
     45       # treat the difficult case of possible - separator
     46       test = userinput[1:].find("-") # at this stage:
     47                                      # * if - is found in the first position, it could not be a separator
     48                                      # * if - found at positions > 0, it must be considered as a separator
     49       if test != -1:
     50         isfree = 1 ; ind=test+1
     51         vals = float(userinput[:ind]) ; vale = float(userinput[ind+1:]) ; foundinterv = True
     52       else:
     53         # check if input is valid (each character is numeric or -)
     54         for char in userinput:
     55            if char not in string.digits:
     56               if char not in ["-","."]: userinput="yorgl"
     57         # either we are OK. if we are not we set isfree to -1.
     58         if userinput != "yorgl":  isfree = 0 ; val = float(userinput)
     59         else:                     isfree = -1
    4460   # return values
    4561   return isfree, val, vals, vale
    4662
     63# set an errormess variable which must stay to None for interface to proceed
     64errormess = ""
    4765
    4866# for debugging in web browser
     
    5371
    5472# create a MCD object
    55 #query = mcd()
    56 query=mcd.mcd() #FG: import from module mcd
     73query=mcd.mcd()
    5774
    5875# Get the kind of vertical coordinates and choose default behavior for "all"
    5976try: query.zkey = int(form.getvalue("zkey"))
    6077except: query.zkey = int(3)
    61 if query.zkey == 2:    minxz = -5000.   ; maxxz = 100000.
    62 elif query.zkey == 3:  minxz = 0.       ; maxxz = 120000.
    63 elif query.zkey == 5:  minxz = -5000.   ; maxxz = 100000.
    64 elif query.zkey == 4:  minxz = 1000.    ; maxxz = 0.001
     78if query.zkey == 2:    minxz = -5000.   ; maxxz = 150000.
     79elif query.zkey == 3:  minxz = 0.       ; maxxz = 250000.
     80elif query.zkey == 5:  minxz = -5000.   ; maxxz = 150000.
     81elif query.zkey == 4:  minxz = 1.e3     ; maxxz = 1.e-6
    6582elif query.zkey == 1:  minxz = 3396000. ; maxxz = 3596000.
    6683
     
    7087isloctfree, query.loct, query.locts, query.locte = gethtmlcoord( form.getvalue("localtime"),    0.,  24. )
    7188isaltfree,  query.xz,   query.xzs,   query.xze   = gethtmlcoord( form.getvalue("altitude"),  minxz, maxxz)
    72 
    73 sumfree = islatfree + islonfree + isloctfree + isaltfree
    74 if sumfree > 2: exit() ## only 1D or 2D plots for the moment
    7589
    7690try: query.datekey = int(form.getvalue("datekeyhtml"))
     
    8498    query.loct = 0.
    8599
     100# Prevent the user from doing bad
     101badinterv = (islatfree == -1) or (islonfree == -1) or (isloctfree == -1) or (isaltfree == -1)
     102if badinterv:
     103    errormess = errormess+"<li>Bad syntax. Write a value (or) a range val1;val2 (or) 'all'. Separator shall be either ; : , / _ "
     104badls = (query.datekey == 1 and (query.xdate < 0. or query.xdate > 360.))
     105if badls:
     106    errormess = errormess+"<li>Solar longitude must be between 0 and 360."
     107badloct = (isloctfree == 0 and query.loct > 24.) \
     108       or (isloctfree == 1 and (query.locts > 24. or query.locte > 24.)) \
     109       or (isloctfree == 0 and query.loct < 0.) \
     110       or (isloctfree == 1 and (query.locts < 0. or query.locte < 0.))
     111if badloct:
     112    errormess = errormess+"<li>Local time must be less than 24 martian hours (and not a negative number)."
     113badlat = (islatfree == 0 and abs(query.lat) > 90.) \
     114      or (islatfree == 1 and (abs(query.lats) > 90. or abs(query.late) > 90.))
     115if badlat:
     116    errormess = errormess+"<li>Latitude coordinates must be between -90 and 90."
     117badlon = (islonfree == 0 and abs(query.lon) > 360.) \
     118      or (islonfree == 1 and (abs(query.lons) > 360. or abs(query.lone) > 360.))
     119if badlon:
     120    errormess = errormess+"<li>Longitude coordinates must be between -360 and 360."
     121badalt = (isaltfree == 0 and (query.zkey in [3]) and query.xz < 0.) \
     122      or (isaltfree == 1 and (query.zkey in [3]) and (query.xzs < 0. or query.xze < 0.))
     123if badalt:
     124    errormess = errormess+"<li>Vertical coordinates must be positive when requesting altitude above surface."
     125badalt2 = (isaltfree == 0 and (query.zkey in [1,4]) and query.xz <= 0.) \
     126      or (isaltfree == 1 and (query.zkey in [1,4]) and (query.xzs <= 0. or query.xze <= 0.))
     127if badalt2:
     128    errormess = errormess+"<li>Vertical coordinates must be <b>strictly</b> positive when requesting pressure levels or altitude above Mars center."
     129badalt3 = (isaltfree == 0 and query.zkey == 4 and query.xz > 1500.) \
     130       or (isaltfree == 1 and query.zkey == 4 and min(query.xzs,query.xze) > 1500.)
     131if badalt3:
     132    errormess = errormess+"<li>Pressure values larger than 1500 Pa are unlikely to be encountered in the Martian atmosphere."
     133badrange = (isloctfree == 1 and query.locts == query.locte) \
     134        or (islatfree == 1 and query.lats == query.late) \
     135        or (islonfree == 1 and query.lons == query.lone) \
     136        or (isaltfree == 1 and query.xzs == query.xze)
     137if badrange:
     138    errormess = errormess+"<li>One or several coordinate intervals are not... intervals. Set either a real range or an unique value."
     139
     140# Get how many free dimensions we have
     141sumfree = islatfree + islonfree + isloctfree + isaltfree
     142if sumfree >= 3: errormess = errormess + "<li>3 or more free dimensions are set... but only 1D and 2D plots are supported!"
     143
     144# Get additional parameters
    86145try: query.hrkey = int(form.getvalue("hrkey"))
    87146except: query.hrkey = int(1)
     
    91150#        self.seedin    = 1  #random number generator seed (unused if perturkey=0)
    92151#        self.gwlength  = 0. #gravity Wave wavelength (unused if perturkey=0)
     152try: query.colorm = form.getvalue("colorm")
     153except: query.colorm = "jet"
    93154
    94155# Get variables to plot
     
    98159var4 = form.getvalue("var4")
    99160
    100 # fg: vartoplot is not None without form values
    101 # vartoplot = [var1]
    102161# fg: init var as with form values
    103162if var1 == None: var1="t"
    104 #if var2 == None: var2="p"
    105163
    106164vartoplot = []
     
    114172else:              iswindlog = False
    115173isfixedlt = form.getvalue("isfixedlt")
    116 if isfixedlt == "on": input_fixedlt=True
    117 else:                 input_fixedlt=False 
    118 
    119 # reference name (to test which figures are already in the database)
    120 reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)
    121 figname = '../img/'+reference+'.png'
    122 txtname = '../txt/'+reference
    123 testexist = daos.path.isfile(figname)
    124 
    125 # extract data from MCD if needed
    126 if not testexist:
     174if isfixedlt == "on": query.fixedlt=True
     175else:                 query.fixedlt=False 
     176iszonmean = form.getvalue("zonmean")
     177if iszonmean  == "on": query.zonmean=True
     178else:                  query.zonmean=False
     179
     180### now, proceed...
     181if errormess == "":
     182
     183 # reference name (to test which figures are already in the database)
     184 reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)+str(iszonmean)+query.colorm
     185 figname = '../img/'+reference+'.png'
     186 txtname = '../txt/'+reference+'.txt'
     187 testexist = daos.path.isfile(figname)
     188
     189 # extract data from MCD if needed
     190 if not testexist:
    127191
    128192  ### 1D plots
     
    130194
    131195    ### getting data
    132     if isloctfree == 1:         query.diurnal(nd=24)
     196    if isloctfree == 1:         query.diurnal(nd=25)
    133197    elif islonfree == 1:        query.zonal(nd=64)
    134198    elif islatfree == 1:        query.meridional(nd=48)
     
    139203    query.getascii(vartoplot,filename=txtname)
    140204    query.htmlplot1d(vartoplot,figname=figname)
    141     #mpl.savefig("img/temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25)
    142     #Image.open("../img/temp.png").save(figname,'JPEG')
    143205
    144206  ### 2D plots
     
    146208
    147209    ### getting data
    148     if islatfree == 1 and islonfree == 1:       
    149         query.htmlmap2d(vartoplot,incwind=iswindlog,fixedlt=input_fixedlt,figname=figname)
    150         #mpl.savefig("img/temp.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
    151         #Image.open("img/temp.png").save(figname,'JPEG') ##lighter images   
    152         ### http://www.pythonware.com/library/pil/handbook/introduction.htm
    153     elif isaltfree == 1 and islonfree == 1:     
    154         query.htmlplot2d(vartoplot,fixedlt=input_fixedlt,figname=figname)
    155     elif isaltfree == 1 and islatfree == 1:     
    156         query.htmlplot2d(vartoplot,fixedlt=input_fixedlt,figname=figname)
    157     else:
    158         exit() 
     210    if islatfree == 1 and islonfree == 1:     query.htmlmap2d(vartoplot,incwind=iswindlog,figname=figname)
     211    else:                                     query.htmlplot2d(vartoplot,figname=figname)
     212
     213#### NOW WRITE THE HTML PAGE TO USER
    159214
    160215## This is quite common
     
    172227#print "<br />"
    173228
    174 
    175 #print "<a href='../index.html'>Click here to start a new query</a><br />"
    176 #print "<hr>"
    177 
    178229## Now the part which differs
    179 if sumfree == 0:        query.update() ; query.htmlprinttabextvar(vartoplot)  #query.printmeanvar()
    180 elif sumfree == 2:      print "<img src='"+figname+"'><br />"
    181 elif sumfree == 1:     
    182     print "<a href='"+txtname+"'>Click here to download an ASCII file containing data</a><br />"
    183     print "<hr>"
    184     print "<img src='"+figname+"'><br />"
    185 else:                   print "<h1>ERROR : sumfree is not or badly defined ...</h1></body></html>"
    186 
     230if errormess != "":
     231                       print "<h1>Ooops!</h1>"
     232                       print "Please correct the following problems before submitting again."
     233                       print "<ul>"
     234                       print errormess
     235                       print "</ul>"
     236else:
     237  if sumfree == 0:      query.update() ; query.htmlprinttabextvar(vartoplot)
     238  elif sumfree == 2:    print "<img src='"+figname+"'><br />"
     239  elif sumfree == 1:     
     240                        print "<a href='"+txtname+"'>Click here to download an ASCII file containing data</a><br />"
     241                        print "<hr>"
     242                        print "<img src='"+figname+"'><br />"
    187243
    188244## This is quite common
    189 bottom = "<hr><a href='../index.html'>Click here to start a new query</a>.<hr></body></html>"
    190 #print bottom
    191 
    192 ##write to file object
    193 #f = cStringIO.StringIO()
    194 #mpl.savefig(f)
    195 #f.seek(0)
    196 
    197 ##output to browser
    198 #print "Content-type: image/png\n"
    199 #print f.read()
    200 #exit()
    201 
    202 #print "Content-type:text/html\r\n\r\n"
    203 #print "<html>"
    204 #print "<head>"
    205 #print "<title>MCD. Simple Python interface</title>"
    206 #print "</head>"
    207 #print "<body>"
    208 
    209 
    210 
    211 
    212 
    213 
    214 ## HTTP Header
    215 #print "Content-Type:application/octet-stream; name=\"FileName\"\r\n";
    216 #print "Content-Disposition: attachment; filename=\"FileName\"\r\n\n";
    217 ## Actual File Content will go hear.
    218 #fo = open("foo.txt", "rb")
    219 #str = fo.read();
    220 #print str
    221 ## Close opend file
    222 #fo.close()
    223 
     245bottom = "</body></html>"
     246print bottom
  • trunk/UTIL/PYTHON/mcd/proto/index.html

    r812 r821  
    1 
    21<!-- Author Aymeric Spiga LMD -->
    3 
    42<!DOCTYPE html>
    53<html>
     
    1311<body onload="DefaultDateValues();DefaultTimeValues();Convert2Ls();PlaceValues(0.,0.);DefaultSpaceTime()">
    1412
     13<form name="calendar" action="./cgi-bin/mcdcgi.py" method="post" target="_blank">
    1514<!-- aussi possible: get a la place de post. pour avoir un beau lien -->
    16 
    17 <!--<form name="calendar" action="/marscgi-bin/mcdcgi.py" method="post"-->
    18 <form name="calendar" action="./cgi-bin/mcdcgi.py" method="post" target="_blank"> <!--target="_new">-->
    1915
    2016<center>
    2117<b style="font-size: 125%;">Mars Climate Database: The Web Interface</b><br>
    22 <!--Welcome! To reset your query, click on the Mars panorama.-->
    2318<a href="index.html"><img src="PIA03610_red.jpg" height=80 width=1200></a><br>
    2419</center>
     
    5449<b><font color="red">MARS date</font></b>
    5550Solar longitude <input type="text" size="3" name="ls"> degrees<br />
    56 Local Time <input type="text" size="4" name="localtime" value="0."> Martian hour<br />
     51Local Time <input type="text" size="3" name="localtime" value="0."> Martian hour<br />
     52<span style="font-size: 80%;">write a value (or) a range val1;val2 (or) 'all'</span><br />
    5753<br />
    5854<input type="radio" name="datekeyhtml" value="0">
     
    6460</td>
    6561<td align="center">
    66 Option for 2D maps: local time value is<br />
     62If longitude is a free dimension, local time value is<br />
    6763<input type="radio" name="isfixedlt" value="off" checked /> at longitude 0
    6864<input type="radio" name="isfixedlt" value="on"          /> fixed for the whole planet<br />
     
    8379<input type="radio" name="tata" value="Evening" onClick="PlaceValues2(21.)">Evening
    8480<input type="radio" name="tata" value="Night" onClick="PlaceValues2(3.)">Night<br />
    85 <!--<input type="radio" name="tata" value="Whole day!" onClick="PlaceValues2('all')"><i>Whole day!</i><br />-->
    8681<hr>
    8782<b>3) ALTITUDE</b>
     
    8984<input type="radio" name="toto" value="Boundary layer" onClick="PlaceValues3(1000.)">Boundary layer
    9085<input type="radio" name="toto" value="Troposphere" onClick="PlaceValues3(10000.)">Troposphere<br/>
    91 <input type="radio" name="toto" value="Mesophere" onClick="PlaceValues3(80000.)">Mesosphere<br />
    92 <!--<input type="radio" name="toto" value="Whole profile!" onClick="PlaceValues3('all')"><i>Whole profile!</i><br />-->
     86<input type="radio" name="toto" value="Mesophere" onClick="PlaceValues3(80000.)">Mesosphere
     87<input type="radio" name="toto" value="Thermosphere" onClick="PlaceValues3(180000.)">Thermosphere<br />
    9388<hr>
    94 <!--
    95 <b>4) COORDINATES</b> Automatic! <br />
    96 <input type="button" value="... or click here for global map!" onClick="PlaceValues('all','all')"><br />
    97 -->
    98 <!--
    99 <b>4)</b>
    100 <input type="button" value="Click here for a global map!" onClick="PlaceValues('all','all')"><br />
    101 -->
    102 <!--
    103 <input type="radio" name="titi" value="Global map" onClick="PlaceValues('all','all')">Global map<br />
    104 <input type="radio" name="toto" value="Vertical profile" onClick="PlaceValues3('all')">Vertical profile
    105 <input type="radio" name="tata" value="Diurnal cycle" onClick="PlaceValues2('all')">Diurnal cycle<br />
    106 -->
    10789</td>
    10890<td align="center">
    10991<b>CUSTOMIZE COORDINATES ON MARS</b><br />
    110 write a value (or) a range val1;val2 (or) 'all'<br />
     92<span style="font-size: 80%;">write a value (or) a range val1;val2 (or) 'all'</span><br />
    11193<ul>
    11294<li>Latitude <input type="text" size="7" name="latitude" value="0."> degree North
     
    121103-->
    122104</select>
    123 <!--
    124 <li>Latitude   
    125 <input type="radio" name="islatfree" value="0" checked> Value: <input type="text" size="2" name="latitude" value="0.">
    126 <input type="radio" name="islatfree" value="1"> All [-90 ; 90]
    127 </li>
    128 <li>Longitude
    129 <input type="radio" name="islonfree" value="0" checked> Value: <input type="text" size="2" name="longitude" value="0.">
    130 <input type="radio" name="islonfree" value="1"> All [-180 ; 180]
    131 </li>
    132 <li>Local Time 
    133 <input type="radio" name="isloctfree" value="0" checked> Value: <input type="text" size="2" name="localtime" value="0.">
    134 <input type="radio" name="isloctfree" value="1"> All [0 ; 24]
    135 </li>
    136 <li>Altitude   
    137 <input type="radio" name="isaltfree" value="0" checked> Value: <input type="text" size="2" name="altitude" value="10.">
    138 <input type="radio" name="isaltfree" value="1"> All [0 ; 100000] m
    139 </li>
    140 -->
    141105</ul>
    142106</td>
    143107<td align="center">
    144 <!--[Advanced settings for well-informed Martians]<br />-->
    145108<ul>
    146 <li>High resolution topography? <input type="radio" name="hrkey" value="1" checked /> Yes <input type="radio" name="hrkey" value="0" /> No </li>
     109<li>High resolution mode? <input type="radio" name="hrkey" value="1" checked /> Yes <input type="radio" name="hrkey" value="0" /> No </li>
    147110<li>Dust scenario? <select name="dust">
    148111<option value="1"         >MY24 min solar</option>
     
    155118<option value="8"         >cold scenario (low dust, min solar)</option>
    156119</select></li>
    157 <!--<li>Presets
    158 <input type="button" value="Now!" onClick="DefaultDateValues();DefaultTimeValues();Convert2Ls();">
    159 <input type="button" value="Curiosity" onClick="DateAndTimeValues(2012,8,6,05,30,00);Convert2Ls();PlaceValues(137.4,-4.6)">
    160 <input type="button" value="Phoenix" onClick="DateAndTimeValues(2008,5,25,23,38,23);Convert2Ls();PlaceValues(234.25,68.22)">
    161 <input type="button" value="Opportunity" onClick="DateAndTimeValues(2004,1,25,4,55,0);Convert2Ls();PlaceValues(354.47,-1.95)">
    162 <input type="button" value="Spirit" onClick="DateAndTimeValues(2004,1,4,4,26,0);Convert2Ls();PlaceValues(175.48,-14.57)">
    163 <input type="button" value="Pathfinder" onClick="DateAndTimeValues(1997,7,4,16,56,55);Convert2Ls();PlaceValues(-33.22,19.13)">
    164 <input type="button" value="Viking Lander 2" onClick="DateAndTimeValues(1976,9,3,22,58,20);Convert2Ls();PlaceValues(-225.74,47.97)">
    165 <input type="button" value="Viking Lander 1" onClick="DateAndTimeValues(1976,7,20,11,53,6);Convert2Ls();PlaceValues(-49.97,22.48)">
    166 </li>-->
    167120</ul>
    168121</td>
     
    171124<td align="center">
    172125<b>4) INTEREST</b>
    173 <input type="radio" name="yeah" value="Atmosphere" onClick="PlaceVar('t','p','none','none')" checked>Atmosphere<br />
    174 <input type="radio" name="yeah" value="Winds" onClick="PlaceVar('u','v','none','none')">Winds
    175 <input type="radio" name="yeah" value="Weather" onClick="PlaceVar('ps_ddv','t','none','none')">Weather<br />
    176 <input type="radio" name="yeah" value="Water clouds" onClick="PlaceVar('h2ovap','mtot','h2oice','icetot')">Water clouds
    177 <input type="radio" name="yeah" value="Chemistry" onClick="PlaceVar('o3','h2ovap','o','co')">Chemistry<br />
    178 <input type="radio" name="yeah" value="Landing engineering" onClick="PlaceVar('rho','rho_ddv','cp','visc')">Landing engineering<br />
    179 <input type="radio" name="yeah" value="Glaciology" onClick="PlaceVar('tsurfmn','tsurfmx','co2ice','icetot')">Glaciology
    180 <input type="radio" name="yeah" value="Surface meteorology" onClick="PlaceVar('ps','tsurf','none','none')">Surface meteorology<br />
    181 <input type="radio" name="yeah" value="Radiative balance" onClick="PlaceVar('lwdown','swdown','lwup','swup')">Radiative balance<br />
    182 <!--<input type="button" value="Surface data" onClick="PlaceVar('ps','tsurf','none','none')">-->
     126<input type="radio" name="yeah" value="Atmosphere" onClick="PlaceVar('t','p','none','none');ChooseColor('jet')" checked>Atmosphere<br />
     127<input type="radio" name="yeah" value="Winds" onClick="PlaceVar('u','v','none','none');ChooseColor('RdBu_r')">Winds
     128<input type="radio" name="yeah" value="Weather" onClick="PlaceVar('ps_ddv','rho_ddv','none','none');ChooseColor('RdBu_r')">Weather<br />
     129<input type="radio" name="yeah" value="Water cycle" onClick="PlaceVar('h2ovap','mtot','h2oice','icetot');ChooseColor('Blues')">Water cycle
     130<input type="radio" name="yeah" value="Chemistry" onClick="PlaceVar('o3','h2ovap','none','none');ChooseColor('jet')">Chemistry<br />
     131<input type="radio" name="yeah" value="Landing engineering" onClick="PlaceVar('rho','visc','none','none');ChooseColor('YlOrRd')">Landing engineering<br />
     132<input type="radio" name="yeah" value="Glaciology" onClick="PlaceVar('tsurfmn','tsurfmx','co2ice','icetot');ChooseColor('spectral')">Glaciology
     133<input type="radio" name="yeah" value="Surface meteorology" onClick="PlaceVar('ps','tsurf','none','none');ChooseColor('jet')">Surface meteorology<br />
     134<input type="radio" name="yeah" value="Radiative balance" onClick="PlaceVar('lwdown','swdown','lwup','swup');ChooseColor('hot')">Radiative balance<br />
    183135</td>
    184136<td align="center">
     
    301253</td>
    302254<td align="center">
    303 <!--[Additional settings]<br />-->
    304255<ul>
    305256<li> Add wind vectors
    306257<input type="radio" name="iswind" value="off" checked /> No
    307258<input type="radio" name="iswind" value="on"          /> Yes</li> 
    308 <!--
    309 <li> Set same LT on whole planet
    310 <input type="radio" name="isfixedlt" value="off" checked /> No
    311 <input type="radio" name="isfixedlt" value="on"          /> Yes</li>
    312 -->
    313 <!--
    314 <li> Add another variable
    315 <input type="radio" name="superimposed" value="0" checked /> side-by-side
    316 <input type="radio" name="superimposed" value="1"         /> superimposed</li>
    317 -->
    318 <!--
    319 <li>
    320 Presets
    321 <input type="button" value="Usual meteorology" onClick="PlaceVar('p','t','u','v')">
    322 <input type="button" value="Surface data" onClick="PlaceVar('ps','tsurf','none','none')">
    323 <input type="button" value="Water cycle" onClick="PlaceVar('mtot','icetot','none','none')">
    324 </select>
    325 -->
     259</li>
     260<li> Set colormap
     261<select name="colorm">
     262<option value="jet"       selected>blue green yellow red</option>
     263<option value="Greys"             >grey</option>
     264<option value="Blues"             >blue</option>
     265<option value="YlOrRd"            >yellow orange red</option>
     266<option value="spectral"          >rainbow</option>
     267<option value="hot"               >black red yellow</option>
     268<option value="RdBu_r"            >blue white red</option>
     269</select>
     270</li>
     271<li> Ask for zonal mean in lat/alt plot<br />
     272<input type="radio" name="zonmean" value="off" checked /> No
     273<input type="radio" name="zonmean" value="on"          /> Yes (please be patient)
    326274</li>
    327275</ul>
     
    336284</td>
    337285<td align="center">
    338 <input type="submit" value="SUBMIT" style="font-weight:bold"/>
    339 <!--<input type="button" value="RESET" style="font-weight:bold" onClick="DefaultDateValues();DefaultTimeValues();Convert2Ls();PlaceValues(0.,0.);DefaultSpaceTime()"/><br />-->
     286<input type="button" value="SUBMIT" style="font-weight:bold" onClick="submit_form()"/>
    340287<input type="button" value="RESET" style="font-weight:bold" onClick="window.open('index.html','_self')"/><br />
    341288</td>
    342289<td align="center">
    343290<a href="http://www-mars.lmd.jussieu.fr">Mars Climate Database</a> (c) LMD/OU/IAA/ESA/CNES.<br />
    344 Python-based interface by <a href="http://www.lmd.jussieu.fr/~aslmd/">Aymeric Spiga</a> (LMD).<br />
    345 </td>
    346 </tr>
    347 
    348 
     291Interface written by <a href="http://www.lmd.jussieu.fr/~aslmd/">A. Spiga</a> (LMD) using <a href="http://www.python.org">Python</a>.<br />
     292</td>
     293</tr>
    349294</table>
    350 
    351 
    352 
    353295</body>
    354296</html>
    355297
    356298<!--
    357 <form action="/cgi-bin/checkbox.cgi" method="POST" target="_blank">
    358299<input type="checkbox" name="maths" value="on" /> Maths
    359 <input type="checkbox" name="physics" value="on" /> Physics
    360 <input type="submit" value="Select Subject" />
    361 </form>
    362300-->
  • trunk/UTIL/PYTHON/mcd/proto/martian_time.js

    r812 r821  
    450450}
    451451
     452function ChooseColor(colorm){
     453var colorm;
     454document.calendar.colorm.value=colorm;
     455}
    452456
    453457function submit_form_beginner() {
    454 document.calendar.submit();
     458submit_form()
    455459document.calendar.reset();
    456460DefaultDateValues();
     
    461465}
    462466
     467function submit_form() {
     468Convert2Julian();
     469document.calendar.submit();
     470}
Note: See TracChangeset for help on using the changeset viewer.