Changeset 753


Ignore:
Timestamp:
Aug 2, 2012, 11:52:55 AM (12 years ago)
Author:
acolaitis
Message:

Python. Minor updates to enrichment factor computation, made compatible with Yuan Lian et al 2012. (this is old, just commiting uncommited stuff)

Location:
trunk/UTIL/PYTHON
Files:
2 edited

Legend:

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

    r724 r753  
    130130# Compute the enrichment factor of non condensible gases
    131131# 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
     135def enrichment_factor(nc,lon,lat,time):
    133136    import numpy as np
     137    from myplot import reducefield
    134138    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"
    141141    if "ps" in varinfile: ps=getfield(nc,'ps')
    142142    else: print "error, you need ps var in your file"
    143     dimension = len(nc.variables['co2'].dimensions)
    144     if dimension == 3:
    145       znz,zny,znx = np.array(co2).shape
     143    dimension = len(nc.variables['co2col'].dimensions)
     144    if dimension == 2:
     145      zny,znx = np.array(co2col).shape
    146146      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
    150148    mmrarcol = np.zeros([znt,zny,znx])
    151     meanar = np.zeros([znt])
    152     pplev = np.zeros([znt,znz+1,zny,znx])
    153149    enfact = np.zeros([znt,zny,znx])
    154150    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
    171166    return enfact
    172167
     
    236231    if dimension == 2:
    237232        #### 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=None
     233        if unidim==1: d2=d4 ; d1=d3 ; d4 = None ; d3 = None
    239234        if mesharea is None: mesharea=np.ones(shape)
    240235        if   max(d2) >= shape[0]: error = True
     
    631626    if typefile in ['meso']:
    632627        if '9999' not in getattr(nc,'START_DATE') :   
    633             ## regular mesoscale  
     628            ## regular mesoscale
    634629            [lon2d,lat2d] = getcoord2d(nc) 
    635630        else:                     
     
    10561051             "TAU":          "YlOrBr_r",\
    10571052             "CO2":          "YlOrBr_r",\
     1053             "MIXED":        "GnBu",\
    10581054             #### T.N.
    10591055             "MTOT":         "spectral",\
  • trunk/UTIL/PYTHON/planetoplot.py

    r748 r753  
    337337      ### ------------ 4. Enrichment factor
    338338      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)
    340340      else:
    341341      ### ideally only this line should be here
Note: See TracChangeset for help on using the changeset viewer.