Changeset 859 for trunk/UTIL/PYTHON/mcd


Ignore:
Timestamp:
Jan 8, 2013, 9:33:07 AM (12 years ago)
Author:
aslmd
Message:

UTIL PYTHON MCDonline. Support for MCD5. Added eps figures. Various other informations added (diapo mode, text file with web arborescence).

Location:
trunk/UTIL/PYTHON/mcd
Files:
3 added
5 edited

Legend:

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

    r827 r859  
    88
    99import numpy as np
    10 import fmcd
    1110import matplotlib.pyplot as mpl
    1211import myplot
     
    8483        self.dpi = 80.
    8584
     85    def toversion5(self):
     86        self.name      = "MCD v5.0"
     87        self.dset      = '/home/marshttp/MCD_v5.0/data/'
     88        self.extvarkey = np.ones(100)
     89
    8690    def viking1(self): self.name = "Viking 1 site. MCD v4.3 output" ; self.lat = 22.48 ; self.lon = -49.97 ; self.xdate = 97.
    8791    def viking2(self): self.name = "Viking 2 site. MCD v4.3 output" ; self.lat = 47.97 ; self.lon = -225.74 ; self.xdate = 117.6
    8892
    8993    def getdustlabel(self):
    90         if self.dust == 1: self.dustlabel = "MY24 minimum solar scenario"
    91         elif self.dust == 2: self.dustlabel = "MY24 average solar scenario"
    92         elif self.dust == 3: self.dustlabel = "MY24 maximum solar scenario"
     94        if self.dust == 1: self.dustlabel = "climatology minimum solar scenario"
     95        elif self.dust == 2: self.dustlabel = "climatology average solar scenario"
     96        elif self.dust == 3: self.dustlabel = "climatology maximum solar scenario"
    9397        elif self.dust == 4: self.dustlabel = "dust storm minimum solar scenario"
    9498        elif self.dust == 5: self.dustlabel = "dust storm average solar scenario"
     
    140144        17: "daily min mean surface temperature (K)",\
    141145        18: "surf. temperature RMS day to day variations (K)",\
    142         19: "surface pressure (high resolution if hireskey=1)",\
     146        19: "surface pressure (Pa)",\
    143147        20: "GCM surface pressure (Pa)",\
    144148        21: "atmospheric pressure RMS day to day variations (Pa)",\
     
    173177        50: "Air viscosity estimation (N s m-2)"
    174178        }
     179        ### MCD version 5 new variables. AS 12/2012.
     180        if "v5" in self.name:
     181          whichfield[29] = "not used (set to zero)"
     182          whichfield[30] = "Surface roughness length z0 (m)"
     183          whichfield[37] = "DOD RMS day to day variations"
     184          whichfield[38] = "Dust mass mixing ratio (kg/kg)"
     185          whichfield[39] = "Dust effective radius (m)"
     186          whichfield[44] =  whichfield[43]
     187          whichfield[43] =  whichfield[42]
     188          whichfield[42] =  whichfield[41]
     189          whichfield[41] =  whichfield[40]
     190          whichfield[40] = "Dust deposition on flat surface (kg m-2 s-1)"
     191          whichfield[45] = "Water ice effective radius (m)"
     192          whichfield[46] = "Convective PBL height (m)"
     193          whichfield[47] = "Max. upward convective wind within the PBL (m/s)"
     194          whichfield[48] = "Max. downward convective wind within the PBL (m/s)"
     195          whichfield[49] = "Convective vertical wind variance at level z (m2/s2)"
     196          whichfield[50] = "Convective eddy vertical heat flux at level z (m/s/K)"
     197          whichfield[51] = "Surface wind stress (Kg/m/s2)"
     198          whichfield[52] = "Surface sensible heat flux (W/m2) (<0 when flux from surf to atm.)"
     199          whichfield[53] = "R: Molecular gas constant (J K-1 kg-1)"
     200          whichfield[54] = "Air viscosity estimation (N s m-2)"
     201          whichfield[55] = "not used (set to zero)"
     202          whichfield[56] = "not used (set to zero)"
     203          whichfield[57] = "[CO2] vol. mixing ratio (mol/mol)"
     204          whichfield[58] = "[N2] vol. mixing ratio (mol/mol)"
     205          whichfield[59] = "[Ar] vol. mixing ratio (mol/mol)"
     206          whichfield[60] = "[CO] vol. mixing ratio (mol/mol)"
     207          whichfield[61] = "[O] vol. mixing ratio (mol/mol)"
     208          whichfield[62] = "[O2] vol. mixing ratio (mol/mol)"
     209          whichfield[63] = "[O3] vol. mixing ratio (mol/mol)"
     210          whichfield[64] = "[H] vol. mixing ratio (mol/mol)"
     211          whichfield[65] = "[H2] vol. mixing ratio (mol/mol)"
     212          whichfield[66] = "[electron] vol. mixing ratio (mol/mol)"
     213          whichfield[67] = "CO2 column (kg/m2)"
     214          whichfield[68] = "N2 column (kg/m2)"
     215          whichfield[69] = "Ar column (kg/m2)"
     216          whichfield[70] = "CO column (kg/m2)"
     217          whichfield[71] = "O column (kg/m2)"
     218          whichfield[72] = "O2 column (kg/m2)"
     219          whichfield[73] = "O3 column (kg/m2)"
     220          whichfield[74] = "H column (kg/m2)"
     221          whichfield[75] = "H2 column (kg/m2)"
     222          whichfield[76] = "electron column (kg/m2)"
    175223        if num not in whichfield: myplot.errormess("Incorrect subscript in extvar.")
    176 
    177224        dastuff = whichfield[num]
    178  
    179225        if "(K)" in dastuff:      self.fmt="%.0f"
    180226        elif "(Pa)" in dastuff:   self.fmt="%.1f"
    181227        elif "(W/m2)" in dastuff: self.fmt="%.0f"
    182228        elif "(m/s)" in dastuff:  self.fmt="%.1f"
     229        elif "(m)" in dastuff:    self.fmt="%.0f"
    183230        else:                     self.fmt="%.2e"
    184 
    185231        return dastuff
    186232
     
    197243        elif num == "ps": num = 19
    198244        elif num == "tau": num = 36
    199         elif num == "mtot": num = 40
    200         elif num == "icetot": num = 42
     245        elif num == "mtot":
     246            if "v5" in self.name:  num = 41
     247            else:                  num = 40
     248        elif num == "icetot":
     249            if "v5" in self.name:  num = 43
     250            else:                  num = 42
    201251        elif num == "ps_ddv": num = 22
    202         elif num == "h2ovap": num = 41
    203         elif num == "h2oice": num = 43
     252        elif num == "h2ovap":
     253            if "v5" in self.name:  num = 42
     254            else:                  num = 41
     255        elif num == "h2oice":
     256            if "v5" in self.name:  num = 44
     257            else:                  num = 43
    204258        elif num == "cp": num = 8
    205259        elif num == "rho_ddv": num = 10
     
    210264        elif num == "lwup": num = 33
    211265        elif num == "swup": num = 34
    212         elif num == "o3": num = 44
    213         elif num == "o": num = 46
    214         elif num == "co": num = 48
    215         elif num == "visc": num = 50
     266        elif num == "o3":
     267            if "v5" in self.name:  num = 63
     268            else:                  num = 44
     269        elif num == "o":
     270            if "v5" in self.name:  num = 61
     271            else:                  num = 46
     272        elif num == "co":
     273            if "v5" in self.name:  num = 60
     274            else:                  num = 48
     275        elif num == "visc":
     276            if "v5" in self.name:  num = 54
     277            else:                  num = 50
    216278        elif num == "co2ice": num = 35
     279        elif num == "pbl":
     280            if "v5" in self.name:  num = 46
     281            else:                  num = 30 # an undefined variable to avoid misleading output
     282        elif num == "updraft":
     283            if "v5" in self.name:  num = 47
     284            else:                  num = 30 # an undefined variable to avoid misleading output
     285        elif num == "downdraft":
     286            if "v5" in self.name:  num = 48
     287            else:                  num = 30 # an undefined variable to avoid misleading output
     288        elif num == "pblwvar":
     289            if "v5" in self.name:  num = 49
     290            else:                  num = 30 # an undefined variable to avoid misleading output
     291        elif num == "pblhvar":
     292            if "v5" in self.name:  num = 50
     293            else:                  num = 30 # an undefined variable to avoid misleading output
     294        elif num == "stress":
     295            if "v5" in self.name:  num = 51
     296            else:                  num = 30 # an undefined variable to avoid misleading output
     297        elif num == "ar":
     298            if "v5" in self.name:  num = 59
     299            else:                  num = 30 # an undefined variable to avoid misleading output
    217300        elif not isinstance(num, np.int): myplot.errormess("field reference not found.")
    218301        return num
     
    230313            self.locte = abs(self.locte)%24
    231314            if self.locts == self.locte: self.locte = self.locts + 24
    232         if self.lat > 90.: self.lat = 90.
    233         if self.lat < -90.: self.lat = -90.
    234         if self.lats is not None and self.late is not None:
    235             if abs(self.lats) > 90.: self.lats = 90.
    236             if abs(self.late) > 90.: self.late = 90.
    237             if abs(self.lats) < -90.: self.lats = -90.
    238             if abs(self.late) < -90.: self.late = -90.
    239315        ## now MCD request
     316        if "v5" in self.name: from fmcd5 import call_mcd
     317        else:                 from fmcd import call_mcd
    240318        (self.pres, self.dens, self.temp, self.zonwind, self.merwind, \
    241319         self.meanvar, self.extvar, self.seedout, self.ierr) \
    242320         = \
    243          fmcd.call_mcd(self.zkey,self.xz,self.lon,self.lat,self.hrkey, \
     321         call_mcd(self.zkey,self.xz,self.lon,self.lat,self.hrkey, \
    244322             self.datekey,self.xdate,self.loct,self.dset,self.dust, \
    245323             self.perturkey,self.seedin,self.gwlength,self.extvarkey )
     
    262340        strloct = str(self.loct)+str(self.locts)+str(self.locte)
    263341        name = str(self.zkey)+strxz+strlon+strlat+str(self.hrkey)+str(self.datekey)+str(self.xdate)+strloct+str(self.dust)
     342        if "v5" in self.name: name = "v5beta_" + name
    264343        return name
    265344
     
    286365    def printallextvar(self):
    287366    # print all extra MCD variables   
    288         for i in range(50): self.printextvar(i+1)
     367        if "v5" in self.name:  limit=76
     368        else:                  limit=50
     369        for i in range(limit): self.printextvar(i+1)
    289370
    290371    def htmlprinttabextvar(self,tabtodo):
     
    813894      canvas.print_figure(figname, dpi=self.dpi)
    814895
    815 
    816896    ### TODO: makeplot2d, plot2d, passer plot settings
    817897
  • trunk/UTIL/PYTHON/mcd/mcdtest.py

    r639 r859  
    33from mcd import mcd
    44
     5
    56query = mcd()
     7
     8query.toversion5()
     9query.loct = 12.
     10
    611query.update()
    712query.printcoord()
     
    1217query.xz = 30000.
    1318query.printmcd()
     19query.printextvar(94)
     20query.printextvar(95)
     21
     22end
    1423
    1524query.viking1()
  • trunk/UTIL/PYTHON/mcd/proto/cgi-bin/mcdcgi.py

    r827 r859  
    7373query=mcd.mcd()
    7474
     75# set MCD version changes if needed
     76betatest = form.getvalue("betatest")
     77if betatest == "on": query.toversion5()
     78
    7579# Get the kind of vertical coordinates and choose default behavior for "all"
    7680try: query.zkey = int(form.getvalue("zkey"))
     
    9397if query.datekey == 1:
    9498    try: query.xdate = float(form.getvalue("ls"))
    95     except: query.xdate = float(1) ; badlschar = True
     99    except: query.xdate = float(1) ; badlschar = True # comment the second part if in debug command line mode
    96100else:
    97101    try: query.xdate = float(form.getvalue("julian"))
     
    161165except: query.max2d = None
    162166
    163 try: query.dpi = float(form.getvalue("dpi"))
     167try: query.dpi = form.getvalue("dpi")
    164168except: query.dpi = 80.
    165 
     169if query.dpi == "eps":  yeaheps = True  ; query.dpi = 300.
     170else:                   yeaheps = False ; query.dpi = float(query.dpi)
    166171
    167172# Get variables to plot
     
    194199
    195200 # reference name (to test which figures are already in the database)
    196  reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)+str(iszonmean)+query.colorm+str(query.min2d)+str(query.max2d)+str(query.dpi)
    197  figname = '../img/'+reference+'.png'
     201 try: reference = query.getnameset()+str(var1)+str(var2)+str(var3)+str(var4)+str(iswind)+str(isfixedlt)+str(iszonmean)+query.colorm+str(query.min2d)+str(query.max2d)+str(query.dpi)
     202 except: reference = "test"
     203 if yeaheps:  figname = '../img/'+reference+'.eps'
     204 else:        figname = '../img/'+reference+'.png'
    198205 txtname = '../txt/'+reference+'.txt'
    199206 testexist = daos.path.isfile(figname)
     
    234241
    235242header="""<html><head><title>Mars Climate Database: The Web Interface</title></head><body>"""
     243if betatest == "on":
     244    print "<b>!!! THIS IS A BETA VERSION. RESULTS ARE NOT VALIDATED !!!</b>"
     245    if sumfree == 2:     print "<br>"
    236246
    237247print header
     
    248258else:
    249259  if sumfree == 0:      query.update() ; query.htmlprinttabextvar(vartoplot)
    250   elif sumfree == 2:    print "<img src='"+figname+"'><br />"
     260  elif sumfree == 2:   
     261                        if yeaheps:  print "<hr><a href='"+figname+"'>!!!! Click here to download the EPS figure file !!!!</a><br /><hr>"
     262                        else:        print "<img src='"+figname+"'><br />"
    251263  elif sumfree == 1:     
    252264                        print "<a href='"+txtname+"'>Click here to download an ASCII file containing data</a><br />"
    253265                        print "<hr>"
    254                         print "<img src='"+figname+"'><br />"
     266                        if yeaheps:  print "<hr><a href='"+figname+"'>!!!! Click here to download the EPS figure file !!!!</a><br /><hr>"
     267                        else:        print "<img src='"+figname+"'><br />"
    255268
    256269## This is quite common
  • trunk/UTIL/PYTHON/mcd/proto/index.html

    r827 r859  
    108108<ul>
    109109<li>Dust scenario <select name="dust">
    110 <option value="1"         >MY24 min solar</option>
    111 <option value="2" selected>MY24 ave solar</option>
    112 <option value="3"         >MY24 max solar</option>
    113 <option value="4"         >dust storm tau=4 min solar</option>
    114 <option value="5"         >dust storm tau=4 ave solar</option>
    115 <option value="6"         >dust storm tau=4 max solar</option>
    116 <option value="7"         >warm scenario (dusty, max solar)</option>
    117 <option value="8"         >cold scenario (low dust, min solar)</option>
     110<option value="1"         >climatology min solar</option>
     111<option value="2" selected>climatology ave solar</option>
     112<option value="3"         >climatology max solar</option>
     113<option value="4"         >dust storm min solar</option>
     114<option value="5"         >dust storm ave solar</option>
     115<option value="6"         >dust storm max solar</option>
     116<option value="7"         >warm (dusty, max solar)</option>
     117<option value="8"         >cold (low dust, min solar)</option>
    118118</select></li>
    119119<li>Interpolate using MOLA topography <input type="radio" name="hrkey" value="1" checked /> on <input type="radio" name="hrkey" value="0" /> off </li>
     120<li> <span style="font-size: 80%;"> Beta-testing (only for developers)
     121<input type="radio" name="betatest" value="off" checked /> off
     122<input type="radio" name="betatest" value="on"          /> on
     123</span>
     124</li>
    120125</ul>
    121126</td>
     
    163168<option value="co"            >[CO] vol. mixing ratio (mol/mol)</option>
    164169<option value="visc"          >Air viscosity estimation (N s m-2)</option>
     170<option value="pbl"           >(beta) Convective PBL height (m)</option>
     171<option value="stress"        >(beta) Surf. wind stress (Kg/m/s2)</option>
     172<option value="ar"            >(beta) Ar vol.mix.rat. (mol/mol)</option>
     173<option value="updraft"       >(beta) Max PBL updraft wind (m/s)</option>
     174<option value="downdraft"     >(beta) Max PBL downdraft wind (m/s)</option>
     175<option value="pblwvar"       >(beta) PBL vert wind variance (m2/s2)</option>
     176<option value="pblhvar"       >(beta) PBL eddy vert heat flux (m/s/K)</option>
    165177</select>
    166178<br />
     
    192204<option value="co"            >[CO] vol. mixing ratio (mol/mol)</option>
    193205<option value="visc"          >Air viscosity estimation (N s m-2)</option>
     206<option value="pbl"           >(beta) Convective PBL height (m)</option>
     207<option value="stress"        >(beta) Surf. wind stress (Kg/m/s2)</option>
     208<option value="ar"            >(beta) Ar vol.mix.rat. (mol/mol)</option>
     209<option value="updraft"       >(beta) Max PBL updraft wind (m/s)</option>
     210<option value="downdraft"     >(beta) Max PBL downdraft wind (m/s)</option>
     211<option value="pblwvar"       >(beta) PBL vert wind variance (m2/s2)</option>
     212<option value="pblhvar"       >(beta) PBL eddy vert heat flux (m/s/K)</option>
    194213</select>
    195214<br />
     
    221240<option value="co"            >[CO] vol. mixing ratio (mol/mol)</option>
    222241<option value="visc"          >Air viscosity estimation (N s m-2)</option>
     242<option value="pbl"           >(beta) Convective PBL height (m)</option>
     243<option value="stress"        >(beta) Surf. wind stress (Kg/m/s2)</option>
     244<option value="ar"            >(beta) Ar vol.mix.rat. (mol/mol)</option>
     245<option value="updraft"       >(beta) Max PBL updraft wind (m/s)</option>
     246<option value="downdraft"     >(beta) Max PBL downdraft wind (m/s)</option>
     247<option value="pblwvar"       >(beta) PBL vert wind variance (m2/s2)</option>
     248<option value="pblhvar"       >(beta) PBL eddy vert heat flux (m/s/K)</option>
    223249</select>
    224250<br />
     
    250276<option value="co"            >[CO] vol. mixing ratio (mol/mol)</option>
    251277<option value="visc"          >Air viscosity estimation (N s m-2)</option>
     278<option value="pbl"           >(beta) Convective PBL height (m)</option>
     279<option value="stress"        >(beta) Surf. wind stress (Kg/m/s2)</option>
     280<option value="ar"            >(beta) Ar vol.mix.rat. (mol/mol)</option>
     281<option value="updraft"       >(beta) Max PBL updraft wind (m/s)</option>
     282<option value="downdraft"     >(beta) Max PBL downdraft wind (m/s)</option>
     283<option value="pblwvar"       >(beta) PBL vert wind variance (m2/s2)</option>
     284<option value="pblhvar"       >(beta) PBL eddy vert heat flux (m/s/K)</option>
    252285</select>
    253286</td>
     
    257290<input type="radio" name="dpi" value="80" checked> medium
    258291<input type="radio" name="dpi" value="160"> high
     292<input type="radio" name="dpi" value="eps"> eps
    259293</li>
    260294<li> Set colormap
  • trunk/UTIL/PYTHON/mcd/proto/martian_time.js

    r821 r859  
    462462Convert2Ls();
    463463PlaceValues(0.,0.);
    464 DefaultSpaceTime()
     464DefaultSpaceTime();
    465465}
    466466
     
    469469document.calendar.submit();
    470470}
     471
Note: See TracChangeset for help on using the changeset viewer.