示例#1
0
def plot_reg(pts_reg, nm, clev=0.2, xsample=1, ysample=1,
             axlims=(5, 32, 60, 100), cline=None, color='0.3', alpha=1.0,
             markersize=2):
    """Plot regression of grid point indices onto large-scale index."""
    var = pts_reg[nm]['m']
    mask = pts_reg[nm]['pts_mask']
    xname = atm.get_coord(mask, 'lon', 'name')
    yname = atm.get_coord(mask, 'lat', 'name')
    atm.contourf_latlon(var, clev=clev, axlims=axlims, extend='both')
    atm.stipple_pts(mask, xname=xname, yname=yname, xsample=xsample,
                    ysample=ysample, color=color, alpha=alpha,
                    markersize=markersize)
    if cline is not None:
        atm.contour_latlon(var, clev=[cline], axlims=axlims, colors='b',
                           linewidths=2)
    fix_axes(axlims)
def plot_all_WLH(wlh, y=0, axlims=(0,50,50,180), cmap='jet', clines=True):
    onset = wlh['onset']
    Rsq = wlh['Rsq']
    lat = wlh['lat']
    lon = wlh['lon']
    kmax = wlh['smoothing_kmax']
    years=wlh['years']
    if wlh['climatology']:
        titlestr = 'CMAP %d-%d Climatology' % (years.min(), years.max())
    else:
        onset = onset[y]
        Rsq = Rsq[y]
        titlestr = 'CMAP %d' % years[y]

    # Note:  add 1 to pentad indices to index from 1-73 for comparison
    # with Wang & LinHo
    onset = onset + 1

    # Calculate onset dates from pentads
    nlat, nlon = onset.shape
    onset_date = np.nan * np.ones((nlat, nlon))
    for i in range(nlat):
        for j in range(nlon):
            jday = atm.pentad_to_jday(onset[i, j], pmin=1)
            mon, day = atm.jday_to_mmdd(jday)
            onset_date[i, j] = 100*mon + day
    # -- Smooth with cubic spline
    # lat_i = np.arange(-89.5, 90, 0.5)
    # lon_i = np.arange(0, 360, 0.5)
    lat_i = np.arange(-90, 90, 4.)
    lon_i = np.arange(0, 360, 4.)
    onset_date = atm.interp_latlon(onset_date, lat_i, lon_i, lat, lon, order=3)
    clev_date = [501, 511, 521, 601, 611, 621, 701, 711]
    clev_label = {}
    for d in clev_date:
        clev_label[d] = '%02d-%02d' % (d//100, d%100)

    # Plot maps
    manual = False
    plt.figure(figsize=(14,10))
    cmin, cmax = 20, 55
    plt.subplot(211)
    _, pc = atm.pcolor_latlon(onset, lat, lon, cmap=cmap, axlims=axlims)
    pc.set_clim(cmin, cmax)
    if clines:
        _, cs = atm.contour_latlon(onset_date, lat_i, lon_i, clev=clev_date,
                                   axlims=axlims)
        plt.clabel(cs, clev_date, fmt=clev_label, manual=manual)
        plt.title(titlestr + ' Onset Pentad & Day')
    else:
        plt.title(titlestr + ' Onset Pentad')

    plt.subplot(212)
    clev = np.arange(0, 1.1, 0.025)
    _, pc = atm.pcolor_latlon(Rsq, lat, lon, cmap=cmap, axlims=axlims)
    pc.set_clim(0., 1.)
    plt.title('$R^2$ for kmax = %d' % kmax)
示例#3
0
def pts_clim(index_pts, nm, clev_bar=10, clev_std=np.arange(0, 21, 1),
             axlims=(5, 32, 60, 100), cmap='spectral', res='c',
             label_locs=None, inline_spacing=2):
    """Plot climatological mean and standard deviation of grid point indices."""
    varbar = index_pts[nm].mean(dim='year')
    varstd = index_pts[nm].std(dim='year')
    lat1, lat2, lon1, lon2 = axlims
    m = atm.init_latlon(lat1, lat2, lon1, lon2, resolution=res)
    m = atm.contourf_latlon(varstd, m=m, clev=clev_std, axlims=axlims, cmap=cmap,
                            symmetric=False, colorbar=False, extend='max')
    m.colorbar(ticks=np.arange(0, 21, 2))
    _, cs = atm.contour_latlon(varbar, clev=clev_bar, axlims=axlims, colors='k',
                               linewidths=2)
    cs_opts = {'fmt' : '%.0f', 'fontsize' : 9,
               'inline_spacing' : inline_spacing}
    if label_locs is not None:
        cs_opts['manual'] = label_locs
    plt.clabel(cs, **cs_opts)
    fix_axes(axlims)
示例#4
0
# ======================================================================
# PLOTS
# ======================================================================

# ----------------------------------------------------------------------
# Map showing averaging regions
axlims = (-45, 45, 0, 150)
mask = {}
for n in [50, 100]:
    mask1 = ds_howi[n]['mask']
    mask[n] = xray.DataArray(mask1.astype(float), dims=mask1.dims,
                             coords=mask1.coords)

plt.figure(figsize=(10, 7))
m, cs = atm.contour_latlon(mask[100], clev=[0.99], colors='red', axlims=axlims)

_, cs2 = atm.contour_latlon(mask[50], m=m, clev=[0.99], colors='red',
                            linestyles='dashed')

latlon = index['TT'].attrs['north']
atm.geobox(latlon[0],  latlon[1], latlon[2], latlon[3], m=m, color='green',
           label='TT (T200-600)')

latlon = index['TT'].attrs['south']
atm.geobox(latlon[0],  latlon[1], latlon[2], latlon[3], m=m, color='green')

latlon = index['OCI'].attrs['latlon']
atm.geobox(latlon[0],  latlon[1], latlon[2], latlon[3], m=m, color='blue',
           label='OCI (U850)')