Changeset 391


Ignore:
Timestamp:
Nov 16, 2011, 3:11:06 PM (13 years ago)
Author:
acolaitis
Message:

PYTHON. Corrected the way missing values are handled for 2D plots. They now don't affect plot boundary computations, do not provok color gradient near plot boundary edges. Moreover, mean function has been modified to return a value when averaging over a missing value and a real value.

Location:
trunk/UTIL/PYTHON
Files:
3 edited

Legend:

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

    r388 r391  
    1212        import numpy as np
    1313        if field is None: return None
    14         else: return np.array(field).mean(axis=axis)
     14        else:
     15           if type(field).__name__=='MaskedArray':
     16              field.set_fill_value(np.NaN)
     17              zout=np.ma.array(field).mean(axis=axis)
     18#              np.ma.masked_invalid(zout)
     19              zout.set_fill_value(np.NaN)
     20              return zout.filled()
     21           else:
     22              return np.array(field).mean(axis=axis)
    1523
    1624def deg ():
     
    2735
    2836# A.C. routine to compute saturation temperature
     37# Be Carefull, when asking for tsat-t, this routine outputs a masked array.
     38# To be correctly handled, this call to tsat must be done before the call to
     39# reduce_field, which handles correctly masked array with the new mean() function.
    2940def get_tsat(pressure,temp=None,zlon=None,zlat=None,zalt=None,ztime=None):
    3041    import math as mt
     
    5566      output=np.zeros(np.array(temp).shape)
    5667      vardim=get_dim(zlon,zlat,zalt,ztime,temp)
    57 #      m=np.ma.masked_where(temp[temp == -1],temp,copy=False)
    58 #      print temp
    59 #      mindex=np.ma.nonzero(m.mask)
    60 #      print mindex[0]
    6168      if 'altitude' not in vardim.keys():
    6269         print 'no altitude coordinate in temperature field for Tsat computation'
     
    103110           exit()
    104111        i=i+1
    105     m=np.ma.masked_where(temp == 0,temp,copy=False)
    106     zoutput=np.ma.array(output,mask=m.mask)#,fill_value=-999999)
    107     zout=zoutput.filled()
    108     return zout
     112    m=np.ma.masked_invalid(temp,copy=False)
     113    zoutput=np.ma.array(output,mask=m.mask,fill_value=np.NaN)
     114#    zout=zoutput.filled()
     115    return zoutput
    109116
    110117# A.C. Dirty routine to determine where are the axis of a variable
  • trunk/UTIL/PYTHON/myplot.py

    r385 r391  
    128128    from scipy import integrate
    129129    if yint:
    130        output = integrate.trapz(input,x=vert,axis=ax)
     130       if type(input).__name__=='MaskedArray':
     131          input.set_fill_value([np.NaN])
     132          output = integrate.trapz(input.filled(),x=vert,axis=ax)
     133       else:
     134          output = integrate.trapz(input.filled(),x=vert,axis=ax)
    131135    else:
    132136       output = mean(input,axis=ax)
  • trunk/UTIL/PYTHON/planetoplot.py

    r388 r391  
    170170          print "computing Tsat-T, I ASSUME Z-AXIS IS PRESSURE"
    171171          tt=getfield(nc,var)
    172           tt.set_fill_value([0])
    173           all_var[k]=get_tsat(vert,tt,zlon=lon,zlat=lat,zalt=vert,ztime=time)
     172          if type(tt).__name__=='MaskedArray':
     173             tt.set_fill_value([np.NaN])
     174             tinput=tt.filled()
     175          else:
     176             tinput=tt
     177          all_var[k]=get_tsat(vert,tinput,zlon=lon,zlat=lat,zalt=vert,ztime=time)
    174178      else:
    175179         if var: all_var[k] = getfield(nc,var)
Note: See TracChangeset for help on using the changeset viewer.