Ignore:
Timestamp:
Oct 22, 2012, 8:05:55 PM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON
MCD interface and online version.

  • corrected a bug introduced recently for fixed / not fixed LT
  • clearer location for the fixed LT / not fixed LT option
  • submitting with a button on the beginner's column automatically reset the form with default values so that no risk to make mistake
  • now the button reset is a real reset. clicking on the Mars panorama also reset
  • display MCD version, coordinates etc... for values-only output
  • the plot is shown on a new window
  • added Ls or julian date in the title (automatic)
  • made the title to be on two lines
  • displayed values on colorbars are now adapted. e.g. if the unit is K then we use the format "%.0f"
  • clearer mention of vertical coordinates on the webpage. removed the possibility for above 3396 km from Mars Center
  • more points on vertical profiles and sections
  • added separator : and rewrote this part of the code so that it is easy to add othe separators
  • added a protection so that slightly negative values from the MCD are set to 0 (apply to mol/mol, kg/kg, kg/m2, W/m2 quantities)
  • better naming for RMS values

TODO (from easier to more difficult i.e. requiring more work)

  • more color palettes
  • fix ugly spacing when asking for 4 sections
  • zonal means
  • alert to user rather than modulo or bounds for time and coordinates
  • Hovmoller plots
  • test to prevent user to use a bad separator (for instance -)
File:
1 edited

Legend:

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

    r811 r812  
    2626from PIL import Image
    2727
     28
     29
     30### a function to read HTML arguments for coordinates
     31def gethtmlcoord(userinput,defmin,defmax):
     32   # accepted separators
     33   separators = [":",";",",","/"]
     34   # initial values
     35   val = -9999. ; vals = None ; vale = None ; foundinterv = False
     36   if userinput == None:   userinput = "1"
     37   # the main work. either all -- or an interval -- or a single value.
     38   if userinput == "all":  isfree = 1 ; vals = defmin ; vale = defmax ; foundinterv = True
     39   else:
     40       for sep in separators:
     41           isfree = 1 ; ind = userinput.find(sep)
     42           if ind != -1: vals = float(userinput[:ind]) ; vale = float(userinput[ind+1:]) ; foundinterv = True
     43   if not foundinterv: isfree = 0 ; val = float(userinput)
     44   # return values
     45   return isfree, val, vals, vale
     46
     47
    2848# for debugging in web browser
    2949cgitb.enable()
     
    3656query=mcd.mcd() #FG: import from module mcd
    3757
    38 # Get data from user-defined fields and define free dimensions
    39 # FG: add tests if var==None to have values in local without forms ones
    40 query.lat = -9999.
    41 getlat = form.getvalue("latitude")
    42 if getlat == None: getlat = "1"
    43 if getlat == "all":  islatfree = 1 ; query.lats = -90. ; query.late = 90.
    44 elif ";" in getlat:  islatfree = 1 ; ind = getlat.find(";") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:])
    45 elif "," in getlat:  islatfree = 1 ; ind = getlat.find(",") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:])
    46 elif "/" in getlat:  islatfree = 1 ; ind = getlat.find("/") ; query.lats = float(getlat[:ind]) ; query.late = float(getlat[ind+1:])
    47 else:                islatfree = 0 ; query.lat = float(getlat)
    48 
    49 query.lon = -9999.
    50 getlon = form.getvalue("longitude")
    51 if getlon == None: getlon = "1"
    52 if getlon == "all":  islonfree = 1 ; query.lons = -180. ; query.lone = 180.
    53 elif ";" in getlon:  islonfree = 1 ; ind = getlon.find(";") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:])
    54 elif "," in getlon:  islonfree = 1 ; ind = getlon.find(",") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:])
    55 elif "/" in getlon:  islonfree = 1 ; ind = getlon.find("/") ; query.lons = float(getlon[:ind]) ; query.lone = float(getlon[ind+1:])
    56 else:                islonfree = 0 ; query.lon = float(getlon)
    57 
    58 query.loct = -9999.
    59 getloct = form.getvalue("localtime")
    60 if getloct == None: getloct = "1"
    61 if getloct == "all": isloctfree = 1 ; query.locts = 0. ; query.locte = 24.
    62 elif ";" in getloct: isloctfree = 1 ; ind = getloct.find(";") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:])
    63 elif "," in getloct: isloctfree = 1 ; ind = getloct.find(",") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:])
    64 elif "/" in getloct: isloctfree = 1 ; ind = getloct.find("/") ; query.locts = float(getloct[:ind]) ; query.locte = float(getloct[ind+1:])
    65 else:                isloctfree = 0 ; query.loct = float(getloct)
    66 
     58# Get the kind of vertical coordinates and choose default behavior for "all"
    6759try: query.zkey = int(form.getvalue("zkey"))
    6860except: query.zkey = int(3)
    69 
    70 query.xz = -9999.
    71 getalt = form.getvalue("altitude")
    72 if getalt == None: getalt = "1"
    73 if getalt == "all": 
    74     isaltfree = 1
    75     if query.zkey == 2:    query.xzs = -5000.   ; query.xze = 100000.
    76     elif query.zkey == 3:  query.xzs = 0.       ; query.xze = 120000.
    77     elif query.zkey == 5:  query.xzs = -5000.   ; query.xze = 100000.
    78     elif query.zkey == 4:  query.xzs = 1000.    ; query.xze = 0.001
    79     elif query.zkey == 1:  query.xzs = 3396000. ; query.xze = 3596000.
    80 elif ";" in getalt:  isaltfree = 1 ; ind = getalt.find(";") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:])
    81 elif "," in getalt:  isaltfree = 1 ; ind = getalt.find(",") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:])
    82 elif "/" in getalt:  isaltfree = 1 ; ind = getalt.find("/") ; query.xzs = float(getalt[:ind]) ; query.xze = float(getalt[ind+1:])
    83 else:                isaltfree = 0 ; query.xz = float(getalt)
     61if query.zkey == 2:    minxz = -5000.   ; maxxz = 100000.
     62elif query.zkey == 3:  minxz = 0.       ; maxxz = 120000.
     63elif query.zkey == 5:  minxz = -5000.   ; maxxz = 100000.
     64elif query.zkey == 4:  minxz = 1000.    ; maxxz = 0.001
     65elif query.zkey == 1:  minxz = 3396000. ; maxxz = 3596000.
     66
     67# Get data from user-defined fields and define free dimensions
     68islatfree,  query.lat,  query.lats,  query.late  = gethtmlcoord( form.getvalue("latitude"),   -90.,  90. )
     69islonfree,  query.lon,  query.lons,  query.lone  = gethtmlcoord( form.getvalue("longitude"), -180., 180. )
     70isloctfree, query.loct, query.locts, query.locte = gethtmlcoord( form.getvalue("localtime"),    0.,  24. )
     71isaltfree,  query.xz,   query.xzs,   query.xze   = gethtmlcoord( form.getvalue("altitude"),  minxz, maxxz)
    8472
    8573sumfree = islatfree + islonfree + isloctfree + isaltfree
     
    143131    ### getting data
    144132    if isloctfree == 1:         query.diurnal(nd=24)
    145     elif islonfree == 1:        query.zonal()
    146     elif islatfree == 1:        query.meridional()
    147     elif isaltfree == 1:        query.profile()   
     133    elif islonfree == 1:        query.zonal(nd=64)
     134    elif islatfree == 1:        query.meridional(nd=48)
     135    elif isaltfree == 1:        query.profile(nd=35)   
    148136    else:                       exit() 
    149137
     
    184172#print "<br />"
    185173
    186 print "<a href='../index.html'>Click here to start a new query</a><br />"
     174
     175#print "<a href='../index.html'>Click here to start a new query</a><br />"
     176#print "<hr>"
    187177
    188178## Now the part which differs
     
    191181elif sumfree == 1:     
    192182    print "<a href='"+txtname+"'>Click here to download an ASCII file containing data</a><br />"
     183    print "<hr>"
    193184    print "<img src='"+figname+"'><br />"
    194185else:                   print "<h1>ERROR : sumfree is not or badly defined ...</h1></body></html>"
     
    230221## Close opend file
    231222#fo.close()
     223
Note: See TracChangeset for help on using the changeset viewer.