Ignore:
Timestamp:
Nov 14, 2011, 4:14:44 PM (13 years ago)
Author:
acolaitis
Message:

PYTHON.

Added new option: --yint, to switch the way vertical coordinates are treated when --vert z1,z2 is specified.

Without specifying --yint, a simple average of the field is done along the vertical coordinate:
mean(vert[z1,z2])

When specifying --yint, a trapezoidal integration of the field is performed along the vertical coordinate.
It is worth mentionning that this operation greatly depends on the "quality" of the z-axis data. By default, z-axis values
stored in the netcdf file for GCM is an approximation. We recommend using zrecast on the file to get trusty values of altitude.
This can be simply done by specifying -i 4 in the plot command (for gcm).

File:
1 edited

Legend:

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

    r376 r382  
    5656    return field
    5757
    58 ## Author: AS + TN
    59 def reducefield (input,d4=None,d3=None,d2=None,d1=None):
     58## Author: AS + TN + AC
     59def reducefield (input,d4=None,d3=None,d2=None,d1=None,yint=False,alt=None):
    6060    ### we do it the reverse way to be compliant with netcdf "t z y x" or "t y x" or "y x"
    6161    ### it would be actually better to name d4 d3 d2 d1 as t z y x
     
    9797        elif max(d2) >= shape[2]: error = True
    9898        elif max(d1) >= shape[3]: error = True
    99         elif d4 is not None and d3 is not None and d2 is not None and d1 is not None: 
    100             output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[d2,:],axis=0); output = mean(output[d1],axis=0)
     99        elif d4 is not None and d3 is not None and d2 is not None and d1 is not None:
     100             output = mean(input[d4,:,:,:],axis=0); output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3]); output = mean(output[d2,:],axis=0); output = mean(output[d1],axis=0)
    101101        elif d4 is not None and d3 is not None and d2 is not None:
    102             output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[d2,:],axis=0)
     102            output = mean(input[d4,:,:,:],axis=0); output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3]); output = mean(output[d2,:],axis=0)
    103103        elif d4 is not None and d3 is not None and d1 is not None:
    104             output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[:,d1],axis=1)
     104            output = mean(input[d4,:,:,:],axis=0); output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3]); output = mean(output[:,d1],axis=1)
    105105        elif d4 is not None and d2 is not None and d1 is not None:
    106106            output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)
    107107        elif d3 is not None and d2 is not None and d1 is not None:
    108             output = mean(input[:,d3,:,:],axis=1); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)
    109         elif d4 is not None and d3 is not None:  output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0)
     108            output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt[d3]); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1)
     109        elif d4 is not None and d3 is not None:  output = mean(input[d4,:,:,:],axis=0); output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3])
    110110        elif d4 is not None and d2 is not None:  output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,d2,:],axis=1)
    111111        elif d4 is not None and d1 is not None:  output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,:,d1],axis=2)
    112         elif d3 is not None and d2 is not None:  output = mean(input[:,d3,:,:],axis=1); output = mean(output[:,d2,:],axis=1)
    113         elif d3 is not None and d1 is not None:  output = mean(input[:,d3,:,:],axis=1); output = mean(output[:,:,d1],axis=0)
     112        elif d3 is not None and d2 is not None:  output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt[d3]); output = mean(output[:,d2,:],axis=1)
     113        elif d3 is not None and d1 is not None:  output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt[d3]); output = mean(output[:,:,d1],axis=0)
    114114        elif d2 is not None and d1 is not None:  output = mean(input[:,:,d2,:],axis=2); output = mean(output[:,:,d1],axis=2)
    115115        elif d1 is not None:                     output = mean(input[:,:,:,d1],axis=3)
    116116        elif d2 is not None:                     output = mean(input[:,:,d2,:],axis=2)
    117         elif d3 is not None:                     output = mean(input[:,d3,:,:],axis=1)
     117        elif d3 is not None:                     output = reduce_zaxis(input[:,d3,:,:],ax=0,yint=yint,vert=alt[d3])
    118118        elif d4 is not None:                     output = mean(input[d4,:,:,:],axis=0)
    119119    dimension = np.array(output).ndim
     
    121121    print 'dim,shape: ',dimension,shape
    122122    return output, error
     123
     124## Author: AC
     125
     126def reduce_zaxis (input,ax=None,yint=False,vert=None):
     127    from mymath import max,mean
     128    from scipy import integrate
     129    if yint:
     130       output = integrate.trapz(input,x=vert,axis=ax)
     131    else:
     132       output = mean(input,axis=ax)
     133    return output
    123134
    124135## Author: AS + TN
     
    578589             "ALBBARE":      "%.2f",\
    579590             "TAU":          "%.1f",\
     591             "CO2":          "%.2f",\
    580592             #### T.N.
    581593             "TEMP":         "%.0f",\
     
    617629             "ALBBARE":      "spectral",\
    618630             "TAU":          "YlOrBr_r",\
     631             "CO2":          "YlOrBr_r",\
    619632             #### T.N.
    620633             "MTOT":         "Jet",\
Note: See TracChangeset for help on using the changeset viewer.