Ignore:
Timestamp:
Aug 19, 2012, 12:19:59 AM (13 years ago)
Author:
aslmd
Message:

UTIL PYTHON : a more definitive version of what could make a new and simple MCD web interface. added a lot of capabilities: variable setting, beginner mode, wind vector, fixed or not local time, etc etc etc. some modifications were made to the python MCD interface too (this makes the basis for the web interface).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py

    r639 r761  
    44##################################################
    55### A Python CGI for the Mars Climate Database ###
    6 ### -------------------------------------------###
    7 ### Aymeric SPIGA 18-19/04/2012                ###
    8 ### -------------------------------------------###
     6### ------------------------------------------ ###
     7### Aymeric SPIGA 18-19/04/2012 ~ 11/08/2012   ###
     8### ------------------------------------------ ###
    99### (see mcdtest.py for examples of use)       ###
    1010##################################################
     
    2727query = mcd()
    2828
    29 # Get data from user-defined fields
    30 query.lat = float(form.getvalue("latitude"))
    31 query.lon = float(form.getvalue("longitude"))
    32 query.loct = float(form.getvalue("localtime"))
     29# Get data from user-defined fields and define free dimensions
     30getlat = form.getvalue("latitude")
     31if getlat == "all":  islatfree = 1 ; query.lat = -9999.
     32else:                islatfree = 0 ; query.lat = float(getlat)
     33getlon = form.getvalue("longitude")
     34if getlon == "all":  islonfree = 1 ; query.lon = -9999.
     35else:                islonfree = 0 ; query.lon = float(getlon)
     36getloct = form.getvalue("localtime")
     37if getloct == "all": isloctfree = 1 ; query.loct = -9999.
     38else:                isloctfree = 0 ; query.loct = float(getloct)
     39getalt = form.getvalue("altitude")
     40if getalt == "all":  isaltfree = 1 ; query.xz = -9999.
     41else:                isaltfree = 0 ; query.xz = float(getalt)
     42sumfree = islatfree + islonfree + isloctfree + isaltfree
     43if sumfree > 2: exit() ## only 1D or 2D plots for the moment
    3344query.xdate = float(form.getvalue("ls"))
    34 query.xz = float(form.getvalue("altitude"))
    3545query.hrkey = int(form.getvalue("hrkey"))
    3646query.dust = int(form.getvalue("dust"))
     
    4050#        self.gwlength  = 0. #gravity Wave wavelength (unused if perturkey=0)
    4151
    42 # Get free dimensions
    43 islatfree  = float(form.getvalue("islatfree"))
    44 islonfree  = float(form.getvalue("islonfree"))
    45 isloctfree = float(form.getvalue("isloctfree"))
    46 isaltfree  = float(form.getvalue("isaltfree"))
    47 sumfree = islatfree + islonfree + isloctfree + isaltfree
    48 if sumfree > 2: exit() ## only 1D or 2D plots for the moment
     52# Get variables to plot
     53var1 = form.getvalue("var1")
     54var2 = form.getvalue("var2")
     55var3 = form.getvalue("var3")
     56var4 = form.getvalue("var4")
     57vartoplot = [var1]
     58if var2 != "none": vartoplot = np.append(vartoplot,var2)
     59if var3 != "none": vartoplot = np.append(vartoplot,var3)
     60if var4 != "none": vartoplot = np.append(vartoplot,var4)
     61iswind = form.getvalue("iswind")
     62if iswind == "on": iswindlog = True
     63else:              iswindlog = False
     64isfixedlt = form.getvalue("isfixedlt")
     65if isfixedlt == "on": input_fixedlt=True
     66else:                 input_fixedlt=False 
    4967
    5068# reference name (to test which figures are already in the database)
    51 reference = str(islatfree)+str(islonfree)+str(isloctfree)+str(isaltfree)+query.getnameset()
     69reference = str(islatfree)+str(islonfree)+str(isloctfree)+str(isaltfree)+query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)
    5270figname = 'img/'+reference+'.jpg'
    5371testexist = daos.path.isfile(figname)
     
    6785
    6886    ### generic building of figure
    69     query.plot1d(["t","p","u","v"],vertplot=isaltfree)   
     87    #query.plot1d(["t","p","u","v"],vertplot=isaltfree)
     88    query.plot1d(vartoplot,vertplot=isaltfree)
    7089    mpl.savefig("img/temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25)
    7190    Image.open("img/temp.png").save(figname,'JPEG')
     
    7796    if islatfree == 1 and islonfree == 1:       query.latlon()   
    7897    else:                                       exit() 
    79    
    80     query.map2d(["t","u"])
     98
     99    ### figure   
     100    query.map2d(vartoplot,incwind=iswindlog,fixedlt=input_fixedlt)
    81101    mpl.savefig("img/temp.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
    82102    Image.open("img/temp.png").save(figname,'JPEG') ##lighter images   
     
    92112
    93113## Now the part which differs
    94 if sumfree == 0:        query.update() ; query.printmeanvar() 
     114if sumfree == 0:        query.update() ; query.htmlprinttabextvar(vartoplot)  #query.printmeanvar()
    95115elif sumfree >= 1:      print "<img src='../"+figname+"'><br />"
    96116else:                   exit()
    97117
    98118## This is quite common
    99 print "Based on the <a href='http://www-mars.lmd.jussieu.fr'>Mars Climate Database</a> (c) LMD/OU/IAA/ESA/CNES.<br />"
     119#print "Based on the <a href='http://www-mars.lmd.jussieu.fr'>Mars Climate Database</a> (c) LMD/OU/IAA/ESA/CNES.<br />"
    100120print "<hr>"
    101 query.printset()
     121print "<a href='../index.html'>Click here to start a new query</a>."
     122#query.printset()
     123print "<hr>"
    102124print "</body>"
    103125print "</html>"
Note: See TracChangeset for help on using the changeset viewer.