Changeset 761 for trunk/UTIL/PYTHON/mcd/mcd.py
- Timestamp:
- Aug 19, 2012, 12:19:59 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/mcd/mcd.py
r723 r761 60 60 def getextvarlab(self,num): 61 61 whichfield = { \ 62 91: "Pressure (Pa)", \ 63 92: "Density (kg/m3)", \ 64 93: "Temperature (K)", \ 65 94: "W-E wind component (m/s)", \ 66 95: "S-N wind component (m/s)", \ 62 67 1: "Radial distance from planet center (m)",\ 63 68 2: "Altitude above areoid (Mars geoid) (m)",\ … … 111 116 50: "Air viscosity estimation (N s m-2)" 112 117 } 113 if num not in whichfield: errormess("Incorrect subscript in extvar.")118 if num not in whichfield: myplot.errormess("Incorrect subscript in extvar.") 114 119 return whichfield[num] 120 121 def convertlab(self,num): 122 ## a conversion from text inquiries to extvar numbers. to be completed. 123 if num == "p": num = 91 124 elif num == "rho": num = 92 125 elif num == "t": num = 93 126 elif num == "u": num = 94 127 elif num == "v": num = 95 128 elif num == "tsurf": num = 15 129 elif num == "topo": num = 4 130 elif num == "h": num = 13 131 elif num == "ps": num = 19 132 elif num == "tau": num = 36 133 elif num == "mtot": num = 40 134 elif num == "icetot": num = 42 135 elif num == "ps_ddv": num = 22 136 elif num == "h2ovap": num = 41 137 elif num == "h2oice": num = 43 138 elif num == "cp": num = 8 139 elif num == "rho_ddv": num = 10 140 elif num == "tsurfmx": num = 16 141 elif num == "tsurfmn": num = 17 142 elif num == "lwdown": num = 31 143 elif num == "swdown": num = 32 144 elif num == "lwup": num = 33 145 elif num == "swup": num = 34 146 elif num == "o3": num = 44 147 elif num == "o": num = 46 148 elif num == "co": num = 48 149 elif num == "visc": num = 50 150 elif num == "co2ice": num = 35 151 elif not isinstance(num, np.int): myplot.errormess("field reference not found.") 152 return num 115 153 116 154 ################### … … 126 164 self.datekey,self.xdate,self.loct,self.dset,self.dust, \ 127 165 self.perturkey,self.seedin,self.gwlength,self.extvarkey ) 166 ## we use the end of extvar (unused) to store meanvar. this is convenient for getextvar(lab) 167 self.extvar[90] = self.pres ; self.extvar[91] = self.dens 168 self.extvar[92] = self.temp ; self.extvar[93] = self.zonwind ; self.extvar[94] = self.merwind 128 169 129 170 def printset(self): … … 139 180 def printcoord(self): 140 181 # print requested space-time coordinates 141 print "----------------------------------------------------------------"142 182 print "LAT",self.lat,"LON",self.lon,"LOCT",self.loct,"XDATE",self.xdate 143 print "----------------------------------------------------------------"144 183 145 184 def printmeanvar(self): … … 153 192 def printextvar(self,num): 154 193 # print extra MCD variables 155 print self.getextvarlab(num) + " ---> " + str(self.extvar[num-1]) 194 num = self.convertlab(num) 195 print self.getextvarlab(num) + " ..... " + str(self.extvar[num-1]) 156 196 157 197 def printallextvar(self): 158 198 # print all extra MCD variables 159 199 for i in range(50): self.printextvar(i+1) 200 201 def htmlprinttabextvar(self,tabtodo): 202 print "Results from the Mars Climate Database" 203 print "<ul>" 204 for i in range(len(tabtodo)): print "<li>" ; self.printextvar(tabtodo[i]) ; print "</li>" 205 print "</ul>" 206 print "<hr>" 207 print "SETTINGS<br />" 208 self.printcoord() 209 self.printset() 160 210 161 211 def printmcd(self): … … 163 213 self.update() 164 214 self.printcoord() 215 print "-------------------------------------------" 165 216 self.printmeanvar() 166 217 … … 187 238 def definefield(self,choice): 188 239 ### for analysis or plot purposes, set field and field label from user-defined choice 189 ### --- choice can be a MCD number for extvar 190 if isinstance(choice, np.int): field = self.getextvar(choice); fieldlab = self.getextvarlab(choice) 191 else: 192 if choice == "t": field = self.temptab ; fieldlab="Temperature (K)" 193 elif choice == "p": field = self.prestab ; fieldlab="Pressure (Pa)" 194 elif choice == "rho": field = self.denstab ; fieldlab="Density (kg/m3)" 195 elif choice == "u": field = self.zonwindtab ; fieldlab="W-E wind component (m/s)" 196 elif choice == "v": field = self.merwindtab ; fieldlab="S-N wind component (m/s)" 197 elif choice == "tsurf": field = self.getextvar(15); fieldlab="Surface temperature (K)" 198 elif choice == "topo": field = self.getextvar(4) ; fieldlab="Topography (m)" 199 elif choice == "h": field = self.getextvar(13); fieldlab = "Scale height (m)" 200 elif choice == "ps": field = self.getextvar(19); fieldlab = "Surface pressure (Pa)" 201 elif choice == "olr": field = self.getextvar(33); fieldlab = "Outgoing longwave radiation (W/m2)" 202 elif choice == "tau": field = self.getextvar(36); fieldlab = "Dust optical depth" 203 elif choice == "mtot": field = self.getextvar(40); fieldlab = "Water vapor column (kg/m2)" 204 elif choice == "icetot": field = self.getextvar(42); fieldlab = "Water ice column (kg/m2)" 205 elif choice == "ps_ddv": field = self.getextvar(22); fieldlab = "Surface pressure RMS day to day variations (Pa)" 206 else: errormess("field reference not found.") 240 choice = self.convertlab(choice) 241 field = self.getextvar(choice); fieldlab = self.getextvarlab(choice) 207 242 return field,fieldlab 208 243 … … 214 249 ## fill in subscript i in output arrays 215 250 ## (arrays must have been correctly defined through prepare) 216 if self.prestab is None: errormess("arrays must be prepared first through self.prepare")251 if self.prestab is None: myplot.errormess("arrays must be prepared first through self.prepare") 217 252 self.prestab[i] = self.pres ; self.denstab[i] = self.dens ; self.temptab[i] = self.temp 218 253 self.zonwindtab[i] = self.zonwind ; self.merwindtab[i] = self.merwind … … 238 273 for i in range(nd): self.lat = self.xcoord[i] ; self.update() ; self.put1d(i) 239 274 240 def profile(self,nd=20,start=0.,end=1 00000.,tabperso=None):275 def profile(self,nd=20,start=0.,end=120000.,tabperso=None): 241 276 ### retrieve an altitude slice (profile) 242 277 self.xlabel = "Altitude (m)" … … 253 288 for i in range(nd): self.xdate = self.xcoord[i] ; self.update() ; self.put1d(i) 254 289 255 def latlon(self,ndx=37,startx=-180.,endx=180.,ndy=19,starty=-90.,endy=90.):256 ### retrieve a latitude/longitude slice257 self.xlabel = "East longitude (degrees)" ; self.ylabel = "North latitude (degrees)"258 self.prepare(ndx=ndx,ndy=ndy)259 self.xcoord = np.linspace(startx,endx,ndx) ; self.ycoord = np.linspace(starty,endy,ndy)260 for i in range(ndx):261 for j in range(ndy):262 self.lon = self.xcoord[i] ; self.lat = self.ycoord[j] ; self.update() ; self.put2d(i,j)263 264 290 def makeplot1d(self,choice,vertplot=0): 265 291 ### one 1D plot is created for the user-defined variable in choice. … … 268 294 else: ordo = self.xcoord ; absc = field ; absclab = fieldlab ; ordolab = self.xlabel 269 295 mpl.plot(absc,ordo,'-bo') ; mpl.ylabel(ordolab) ; mpl.xlabel(absclab) #; mpl.xticks(query.xcoord) 296 mpl.figtext(0.5, 0.01, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center') 270 297 271 298 def plot1d(self,tabtodo,vertplot=0): … … 280 307 ################### 281 308 309 def latlon(self,ndx=37,startx=-180.,endx=180.,ndy=19,starty=-90.,endy=90.,fixedlt=False): 310 ### retrieve a latitude/longitude slice 311 ### default is: local time is not fixed. user-defined local time is at longitude 0. 312 self.xlabel = "East longitude (degrees)" ; self.ylabel = "North latitude (degrees)" 313 self.prepare(ndx=ndx,ndy=ndy) 314 self.xcoord = np.linspace(startx,endx,ndx) ; self.ycoord = np.linspace(starty,endy,ndy) 315 if not fixedlt: umst = self.loct 316 for i in range(ndx): 317 for j in range(ndy): 318 self.lon = self.xcoord[i] ; self.lat = self.ycoord[j] 319 if not fixedlt: self.loct = (umst + self.lon/15.) % 24 320 self.update() ; self.put2d(i,j) 321 if not fixedlt: self.loct = umst 322 282 323 def put2d(self,i,j): 283 324 ## fill in subscript i,j in output arrays 284 325 ## (arrays must have been correctly defined through prepare) 285 if self.prestab is None: errormess("arrays must be prepared first through self.prepare")326 if self.prestab is None: myplot.errormess("arrays must be prepared first through self.prepare") 286 327 self.prestab[i,j] = self.pres ; self.denstab[i,j] = self.dens ; self.temptab[i,j] = self.temp 287 328 self.zonwindtab[i,j] = self.zonwind ; self.merwindtab[i,j] = self.merwind … … 289 330 self.extvartab[i,j,1:100] = self.extvar[0:99] ## note: var numbering according to MCD manual is kept 290 331 291 def makemap2d(self,choice,incwind=False ):332 def makemap2d(self,choice,incwind=False,fixedlt=False): 292 333 ### one 2D map is created for the user-defined variable in choice. 293 self.latlon( ) ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d)334 self.latlon(fixedlt=fixedlt) ## a map is implicitely a lat-lon plot. otherwise it is a plot (cf. makeplot2d) 294 335 (field, fieldlab) = self.definefield(choice) 295 336 if incwind: … … 299 340 else: 300 341 myplot.maplatlon(self.xcoord,self.ycoord,field,title=fieldlab,proj="moll") 301 302 def map2d(self,tabtodo,incwind=False): 342 mpl.figtext(0.5, 0.0, "Mars Climate Database (c) LMD/OU/IAA/ESA/CNES", ha='center') 343 344 def map2d(self,tabtodo,incwind=False,fixedlt=False): 303 345 ### complete 2D figure with possible multiplots 304 346 if isinstance(tabtodo,np.str): tabtodo=[tabtodo] ## so that asking one element without [] is possible. 305 347 if isinstance(tabtodo,np.int): tabtodo=[tabtodo] ## so that asking one element without [] is possible. 306 348 fig = mpl.figure() ; subv,subh = myplot.definesubplot( len(tabtodo) , fig ) 307 for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind )308 309 ### TODO: makeplot2d, plot2d, passer plot settings , vecteurs, plot loct pas fixe310 349 for i in range(len(tabtodo)): mpl.subplot(subv,subh,i+1) ; self.makemap2d(tabtodo[i],incwind=incwind,fixedlt=fixedlt) 350 351 ### TODO: makeplot2d, plot2d, passer plot settings 352
Note: See TracChangeset
for help on using the changeset viewer.