Changeset 701 for trunk/UTIL


Ignore:
Timestamp:
Jun 11, 2012, 4:17:57 PM (13 years ago)
Author:
acolaitis
Message:

PYTHON. Added possibility to call for variable <<-v enfact>> - enrichment factor - given that you have co2, ap, bp and ps fields in your file. This will give you the enrichment factor of non condensible gases, ranging from 0 (no enrichment) to X (enrichment by a factor X compared to the mean non condensible gases mass mixing ratio (which is also computed for the relevant time step)).

Location:
trunk/UTIL/PYTHON
Files:
2 edited

Legend:

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

    r687 r701  
    125125       zvint=zv
    126126    return np.sqrt(zuint**2 + zvint**2)
     127
     128## Author: AC
     129# Compute the enrichment factor of non condensible gases
     130# The corresponding variable to call is enfact
     131def enrichment_factor(nc):
     132    import numpy as np
     133    varinfile = nc.variables.keys()
     134    if "co2" in varinfile: co2=getfield(nc,'co2')
     135    else: print "error, you need co2 var in your file"
     136    if "ap" in varinfile: ap=getfield(nc,'ap')
     137    else: print "error, you need ap var in your file"
     138    if "bp" in varinfile: bp=getfield(nc,'bp')
     139    else: print "error, you need bp var in your file"
     140    if "ps" in varinfile: ps=getfield(nc,'ps')
     141    else: print "error, you need ps var in your file"
     142    dimension = len(nc.variables['co2'].dimensions)
     143    if dimension == 3:
     144      znz,zny,znx = np.array(co2).shape
     145      znt=1
     146    elif dimension == 4: znt,znz,zny,znx = np.array(co2).shape
     147    co2col = np.zeros([znt,zny,znx])
     148    arcol = np.zeros([znt,zny,znx])
     149    mmrarcol = np.zeros([znt,zny,znx])
     150    meanar = np.zeros([znt])
     151    pplev = np.zeros([znt,znz+1,zny,znx])
     152    enfact = np.zeros([znt,zny,znx])
     153    grav=3.72
     154    for zz in np.arange(znz):
     155      pplev[:,zz,:,:] = ap[zz]+bp[zz]*ps[:,:,:]
     156    pplev[:,znz,:,:]=0.
     157
     158    for zz in np.arange(znz):
     159      co2col[:,:,:] = co2col[:,:,:] + co2[:,zz,:,:]*(pplev[:,zz,:,:]-pplev[:,zz+1,:,:])/grav
     160      arcol[:,:,:] = arcol[:,:,:] + (1.-co2[:,zz,:,:])*(pplev[:,zz,:,:]-pplev[:,zz+1,:,:])/grav
     161
     162    mmrarcol = arcol/(arcol + co2col)
     163    for xx in np.arange(znx):
     164      for yy in np.arange(zny):
     165          meanar[:] = meanar[:] + mmrarcol[:,yy,xx]
     166    meanar = meanar/(znx*zny)
     167
     168    enfact =-(meanar - mmrarcol)/meanar
     169    return enfact
    127170
    128171## Author: AC
     
    947990             "TAU":          "%.1f",\
    948991             "CO2":          "%.2f",\
     992             "ENFACT":       "%.1f",\
    949993             #### T.N.
    950994             "TEMP":         "%.0f",\
  • trunk/UTIL/PYTHON/planetoplot.py

    r687 r701  
    7979                       zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\
    8080                       getname,localtime,check_localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds,\
    81                        windamplitude,slopeamplitude,deltat0t1
     81                       windamplitude,slopeamplitude,deltat0t1,enrichment_factor
    8282    from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img
    8383    import matplotlib as mpl
     
    155155    ### we get the names of variables to be read. in case only one available, we choose this one.
    156156      varname=var[vvv]
    157       if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet','slopexy','SLOPEXY','deltat','DELTAT']))):
     157      if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet','slopexy','SLOPEXY','deltat','DELTAT'])) and not ((typefile in ['gcm']) and (varname in ['enfact']))):
    158158          if len(varinfile) == 1:   varname = varinfile[0]
    159159          else:                     varname = False
     
    299299      #####################
    300300      ##### SPECIFIC CASES
     301      ##### note : we could probably call those via a "toolbox" in myplot.
    301302      ##### 1. saturation temperature
    302303      if varname in ["temp","t","T_nadir_nit","T_nadir_day","temp_day","temp_night"] and tsat:
     
    310311      elif ((varname in ['slopexy','SLOPEXY']) and (typefile in ['meso']) and (varname not in nc.variables)):
    311312          all_var[k]=slopeamplitude(nc)
     313      #### 3. Near surface instability
    312314      elif ((varname in ['DELTAT','deltat']) and (typefile in ['meso']) and (varname not in nc.variables)):
    313315          all_var[k]=deltat0t1(nc)
     316      #### 4. Enrichment factor
     317      elif ((typefile in ['gcm']) and (varname in ['enfact'])):
     318          all_var[k]=enrichment_factor(nc)
    314319      else:
    315320      ##### GENERAL STUFF HERE
Note: See TracChangeset for help on using the changeset viewer.