Changeset 753
- Timestamp:
- Aug 2, 2012, 11:52:55 AM (12 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/myplot.py
r724 r753 130 130 # Compute the enrichment factor of non condensible gases 131 131 # The corresponding variable to call is enfact 132 def enrichment_factor(nc): 132 # enrichment factor is computed as in Yuan Lian et al. 2012 133 # i.e. you need to have VL2 site at LS 135 in your data 134 # this only requires co2col so that you can concat.nc at low cost 135 def enrichment_factor(nc,lon,lat,time): 133 136 import numpy as np 137 from myplot import reducefield 134 138 varinfile = nc.variables.keys() 135 if "co2" in varinfile: co2=getfield(nc,'co2') 136 else: print "error, you need co2 var in your file" 137 if "ap" in varinfile: ap=getfield(nc,'ap') 138 else: print "error, you need ap var in your file" 139 if "bp" in varinfile: bp=getfield(nc,'bp') 140 else: print "error, you need bp var in your file" 139 if "co2col" in varinfile: co2col=getfield(nc,'co2col') 140 else: print "error, you need co2col var in your file" 141 141 if "ps" in varinfile: ps=getfield(nc,'ps') 142 142 else: print "error, you need ps var in your file" 143 dimension = len(nc.variables['co2 '].dimensions)144 if dimension == 3:145 zn z,zny,znx = np.array(co2).shape143 dimension = len(nc.variables['co2col'].dimensions) 144 if dimension == 2: 145 zny,znx = np.array(co2col).shape 146 146 znt=1 147 elif dimension == 4: znt,znz,zny,znx = np.array(co2).shape 148 co2col = np.zeros([znt,zny,znx]) 149 arcol = np.zeros([znt,zny,znx]) 147 elif dimension == 3: znt,zny,znx = np.array(co2col).shape 150 148 mmrarcol = np.zeros([znt,zny,znx]) 151 meanar = np.zeros([znt])152 pplev = np.zeros([znt,znz+1,zny,znx])153 149 enfact = np.zeros([znt,zny,znx]) 154 150 grav=3.72 155 for zz in np.arange(znz): 156 pplev[:,zz,:,:] = ap[zz]+bp[zz]*ps[:,:,:] 157 pplev[:,znz,:,:]=0. 158 159 for zz in np.arange(znz): 160 co2col[:,:,:] = co2col[:,:,:] + co2[:,zz,:,:]*(pplev[:,zz,:,:]-pplev[:,zz+1,:,:])/grav 161 arcol[:,:,:] = arcol[:,:,:] + (1.-co2[:,zz,:,:])*(pplev[:,zz,:,:]-pplev[:,zz+1,:,:])/grav 162 163 mmrarcol = arcol/(arcol + co2col) 164 for xx in np.arange(znx): 165 for yy in np.arange(zny): 166 meanar[:] = meanar[:] + mmrarcol[:,yy,xx] 167 meanar = meanar/(znx*zny) 168 for tt in np.arange(znt): 169 enfact[tt,:,:] =-(meanar[tt] - mmrarcol[tt,:,:])/meanar[tt] 170 151 mmrarcol[:,:,:] = 1. - grav*co2col[:,:,:]/ps[:,:,:] 152 # Computation with reference argon mmr at VL2 Ls 135 (as in Yuan Lian et al 2012) 153 lonvl2=np.zeros([1,2]) 154 latvl2=np.zeros([1,2]) 155 timevl2=np.zeros([1,2]) 156 lonvl2[0,0]=-180 157 lonvl2[0,1]=180 158 latvl2[:,:]=48.16 159 timevl2[:,:]=135. 160 indexlon = getsindex(lonvl2,0,lon) 161 indexlat = getsindex(latvl2,0,lat) 162 indextime = getsindex(timevl2,0,time) 163 mmrvl2, error = reducefield( mmrarcol, d4=indextime, d1=indexlon, d2=indexlat) 164 print "VL2 Ls 135 mmr arcol:", mmrvl2 165 enfact[:,:,:] = mmrarcol[:,:,:]/mmrvl2 171 166 return enfact 172 167 … … 236 231 if dimension == 2: 237 232 #### this is needed for 1d-type files (where dim=2 but axes are time-vert and not lat-lon) 238 if unidim == 1: d2=d4 ; d1=d3 ; d4=None ; d3=None233 if unidim==1: d2=d4 ; d1=d3 ; d4 = None ; d3 = None 239 234 if mesharea is None: mesharea=np.ones(shape) 240 235 if max(d2) >= shape[0]: error = True … … 631 626 if typefile in ['meso']: 632 627 if '9999' not in getattr(nc,'START_DATE') : 633 ## regular mesoscale 628 ## regular mesoscale 634 629 [lon2d,lat2d] = getcoord2d(nc) 635 630 else: … … 1056 1051 "TAU": "YlOrBr_r",\ 1057 1052 "CO2": "YlOrBr_r",\ 1053 "MIXED": "GnBu",\ 1058 1054 #### T.N. 1059 1055 "MTOT": "spectral",\ -
trunk/UTIL/PYTHON/planetoplot.py
r748 r753 337 337 ### ------------ 4. Enrichment factor 338 338 elif ((typefile in ['gcm']) and (varname in ['enfact'])): 339 all_var[k]=enrichment_factor(nc )339 all_var[k]=enrichment_factor(nc,lon,lat,time) 340 340 else: 341 341 ### ideally only this line should be here
Note: See TracChangeset
for help on using the changeset viewer.