Ignore:
Timestamp:
Sep 21, 2012, 5:11:37 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON : a working version of MCD python on an Apache server thanks to F. Guyon and L. Fairhead. plus added specific functions in mcd.py to make plots without using GUI, it was necessary to rewrite some stuff to avoid calling to matplotlib.pyplot.

File:
1 edited

Legend:

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

    r761 r793  
    1 #!/home/aymeric/Software/epd-7.0-2-rh5-x86/bin/python
     1#!/usr/bin/python
     2###!/home/aymeric/Software/epd-7.0-2-rh5-x86/bin/python
     3####!/home/marshttp/EPD/epd-7.0-2-rh5-x86_64/bin/python
    24### here the version used to f2py the MCD Fortran routines
    35
     
    911### (see mcdtest.py for examples of use)       ###
    1012##################################################
     13### ajouts et corrections par Franck Guyon 09/2012
    1114
    1215import cgi, cgitb
    1316import numpy as np
    14 from mcd import mcd
     17#from mcd import mcd
     18from modules import *
     19from modules import mcd
     20
    1521import cStringIO
    1622import os as daos
    1723import matplotlib.pyplot as mpl
    18 import Image
     24from PIL import Image
    1925
    2026# for debugging in web browser
     
    2531
    2632# create a MCD object
    27 query = mcd()
     33#query = mcd()
     34query=mcd.mcd() #FG: import from module mcd
    2835
    2936# Get data from user-defined fields and define free dimensions
     37# FG: add tests if var==None to have values in local without forms ones
    3038getlat = form.getvalue("latitude")
     39if getlat == None: getlat = 1
     40
    3141if getlat == "all":  islatfree = 1 ; query.lat = -9999.
    3242else:                islatfree = 0 ; query.lat = float(getlat)
    3343getlon = form.getvalue("longitude")
     44if getlon == None: getlon = 1
    3445if getlon == "all":  islonfree = 1 ; query.lon = -9999.
    3546else:                islonfree = 0 ; query.lon = float(getlon)
     47
    3648getloct = form.getvalue("localtime")
     49
     50if getloct == None: getloct = 1
    3751if getloct == "all": isloctfree = 1 ; query.loct = -9999.
    3852else:                isloctfree = 0 ; query.loct = float(getloct)
     53
    3954getalt = form.getvalue("altitude")
     55if getalt == None: getalt = 1
    4056if getalt == "all":  isaltfree = 1 ; query.xz = -9999.
    4157else:                isaltfree = 0 ; query.xz = float(getalt)
     58
    4259sumfree = islatfree + islonfree + isloctfree + isaltfree
    4360if sumfree > 2: exit() ## only 1D or 2D plots for the moment
    44 query.xdate = float(form.getvalue("ls"))
    45 query.hrkey = int(form.getvalue("hrkey"))
    46 query.dust = int(form.getvalue("dust"))
     61
     62try: query.xdate = float(form.getvalue("ls"))
     63except: query.xdate = float(1)
     64try: query.hrkey = int(form.getvalue("hrkey"))
     65except: query.hrkey = int(1)
     66try: query.dust = int(form.getvalue("dust"))
     67except: query.dust  = int(1)
    4768#        self.zkey      = 3  # specify that xz is the altitude above surface (m)
    4869#        self.perturkey = 0  #integer perturkey ! perturbation type (0: none)
     
    5576var3 = form.getvalue("var3")
    5677var4 = form.getvalue("var4")
    57 vartoplot = [var1]
     78
     79# fg: vartoplot is not None without form values
     80# vartoplot = [var1]
     81# fg: init var as with form values
     82if var1 == None: var1="t"
     83if var2 == None: var2="p"
     84
     85vartoplot = []
     86if var1 != "none": vartoplot = np.append(vartoplot,var1)
    5887if var2 != "none": vartoplot = np.append(vartoplot,var2)
    59 if var3 != "none": vartoplot = np.append(vartoplot,var3)
    60 if var4 != "none": vartoplot = np.append(vartoplot,var4)
     88if var3 != "none" and var3 != None: vartoplot = np.append(vartoplot,var3)
     89if var4 != "none" and var4 != None: vartoplot = np.append(vartoplot,var4)
     90
    6191iswind = form.getvalue("iswind")
    6292if iswind == "on": iswindlog = True
     
    6898# reference name (to test which figures are already in the database)
    6999reference = str(islatfree)+str(islonfree)+str(isloctfree)+str(isaltfree)+query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)
    70 figname = 'img/'+reference+'.jpg'
     100figname = '../img/'+reference+'.png'
     101
    71102testexist = daos.path.isfile(figname)
    72103
     
    85116
    86117    ### generic building of figure
    87     #query.plot1d(["t","p","u","v"],vertplot=isaltfree)
    88     query.plot1d(vartoplot,vertplot=isaltfree)
    89     mpl.savefig("img/temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25)
    90     Image.open("img/temp.png").save(figname,'JPEG')
     118    query.htmlplot1d(vartoplot,vertplot=isaltfree,figname=figname)
     119    #mpl.savefig("img/temp.png",dpi=85,bbox_inches='tight',pad_inches=0.25)
     120    #Image.open("../img/temp.png").save(figname,'JPEG')
    91121
    92122  ### 2D plots
     
    104134
    105135## This is quite common
    106 print "Content-type:text/html\r\n\r\n"
    107 print "<html>"
    108 print "<head>"
    109 print "<title>MCD. Simple Python interface</title>"
    110 print "</head>"
    111 print "<body>"
     136print "Content-type:text/html\n"
     137print "  "  #Apache needs a space after content-type
     138
     139#entete="""<?xml version="1.0" encoding="UTF-8"?>
     140#<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">
     141#<html xmlns="http://www.w3.org/1999/xhtml"> """
     142
     143header="""<html><head><title>Mars Climate Database: The Web Interface</title></head><body>"""
     144
     145print header
    112146
    113147## Now the part which differs
    114148if sumfree == 0:        query.update() ; query.htmlprinttabextvar(vartoplot)  #query.printmeanvar()
    115 elif sumfree >= 1:      print "<img src='../"+figname+"'><br />"
    116 else:                   exit()
     149elif sumfree >= 1:      print "<img src='"+figname+"'><br />"
     150else:                   print "<h1>ERROR : sumfree is not or badly defined ...</h1></body></html>"
     151
    117152
    118153## This is quite common
    119 #print "Based on the <a href='http://www-mars.lmd.jussieu.fr'>Mars Climate Database</a> (c) LMD/OU/IAA/ESA/CNES.<br />"
    120 print "<hr>"
    121 print "<a href='../index.html'>Click here to start a new query</a>."
    122 #query.printset()
    123 print "<hr>"
    124 print "</body>"
    125 print "</html>"
     154bottom = "<hr><a href='../index.html'>Click here to start a new query</a>.<hr></body></html>"
     155print bottom
    126156
    127157##write to file object
Note: See TracChangeset for help on using the changeset viewer.