Changeset 398 for trunk/UTIL/PYTHON


Ignore:
Timestamp:
Nov 18, 2011, 1:51:41 PM (13 years ago)
Author:
acolaitis
Message:

PYTHON:

  • Improved handling of missing values NaN by min() and max() functions
  • Added the possibility to change the viewing angle of "ortho" projections by using --blat. Default is meanlat. (remember than in spstere and npstere projections, blat already controls the boundling latitude)
  • Changed colorbar of "operation" plots to RdBu_r, whatever the colorbar of other plots are. The thinking behind this is that this is a symmetrical colorbar, which is very usefull for difference plots. (could be changed for other operations.)
Location:
trunk/UTIL/PYTHON
Files:
3 edited

Legend:

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

    r395 r398  
    22        import numpy as np
    33        if field is None: return None
     4        if type(field).__name__=='MaskedArray':
     5              field.set_fill_value(np.NaN)
     6              return np.ma.array(field).min(axis=axis)
     7        elif (np.isnan(np.sum(field)) and (type(field).__name__ not in 'MaskedArray')):
     8              return np.ma.masked_invalid(field).min(axis=axis)
    49        else: return np.array(field).min(axis=axis)
    510
     
    712        import numpy as np
    813        if field is None: return None
     14        if type(field).__name__=='MaskedArray':
     15              field.set_fill_value(np.NaN)
     16              return np.ma.array(field).max(axis=axis)
     17        elif (np.isnan(np.sum(field)) and (type(field).__name__ not in 'MaskedArray')):
     18              return np.ma.masked_invalid(field).max(axis=axis)
    919        else: return np.array(field).max(axis=axis)
    1020
     
    1626              field.set_fill_value(np.NaN)
    1727              zout=np.ma.array(field).mean(axis=axis)
    18 #              np.ma.masked_invalid(zout)
    1928              zout.set_fill_value(np.NaN)
     29              return zout.filled()
     30           elif (np.isnan(np.sum(field)) and (type(field).__name__ not in 'MaskedArray')):
     31              zout=np.ma.masked_invalid(field).mean(axis=axis)
     32              zout.set_fill_value([np.NaN])
    2033              return zout.filled()
    2134           else:
  • trunk/UTIL/PYTHON/myplot.py

    r396 r398  
    488488    meanlat = 0.5*(wlat[0]+wlat[1])
    489489    if blat is None:
     490        ortholat=meanlat
    490491        if   wlat[0] >= 80.:   blat =  40.
    491492        elif wlat[1] <= -80.:  blat = -40.
    492493        elif wlat[1] >= 0.:    blat = wlat[0]
    493494        elif wlat[0] <= 0.:    blat = wlat[1]
     495    else:  ortholat=blat
    494496    #print "blat ", blat
    495497    h = 50.  ## en km
     
    498500                              llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1])
    499501    elif char == "moll":    m = Basemap(rsphere=radius,projection='moll',lon_0=meanlon)
    500     elif char == "ortho":   m = Basemap(rsphere=radius,projection='ortho',lon_0=meanlon,lat_0=meanlat)
     502    elif char == "ortho":   m = Basemap(rsphere=radius,projection='ortho',lon_0=meanlon,lat_0=ortholat)
    501503    elif char == "lcc":     m = Basemap(rsphere=radius,projection='lcc',lat_1=meanlat,lat_0=meanlat,lon_0=meanlon,\
    502504                              llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1])
     
    605607             "T_NADIR_DAY":  "%.0f",\
    606608             "T_NADIR_NIT":  "%.0f",\
     609             "TEMP_DAY":     "%.0f",\
     610             "TEMP_NIGHT":   "%.0f",\
    607611             "tpot":         "%.0f",\
    608612             "TSURF":        "%.0f",\
  • trunk/UTIL/PYTHON/planetoplot.py

    r395 r398  
    178178
    179179      ##### SPECIFIC
    180       if varname in ["temp","t","T_nadir_nit","T_nadir_day"] and tsat:
     180      if varname in ["temp","t","T_nadir_nit","T_nadir_day","temp_day","temp_night"] and tsat:
    181181          tt=getfield(nc,varname) ; print "computing Tsat-T, I ASSUME Z-AXIS IS PRESSURE"
    182182          if type(tt).__name__=='MaskedArray':  tt.set_fill_value([np.NaN]) ; tinput=tt.filled()
     
    329329                  zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax)
    330330               if colorb in ["def","nobar"]:   palette = get_cmap(name=defcolorb(fvar.upper()))
     331               elif (fileref is not None) and (index_f is numplot-1): palette = get_cmap(name="RdBu_r")
    331332               else:                           palette = get_cmap(name=colorb)
    332333               ##### 2D field
     
    357358                 if colorb != 'nobar' and varname != 'HGT' :       
    358359                     if (fileref is not None) and (index_f is numplot-1):
    359                         colorbar(fraction=0.05,pad=0.03,format="%.2f",\
     360                        colorbar(fraction=0.05,pad=0.03,format="%.3f",\
    360361                                           ticks=np.linspace(zevmin,zevmax,num=min([ticks/2+1,20])),\
    361362                                           extend='neither',spacing='proportional')
Note: See TracChangeset for help on using the changeset viewer.