Пример #1
0
def contourf_latday(var,
                    is_precip=False,
                    clev=None,
                    cticks=None,
                    climits=None,
                    nc_pref=40,
                    grp=None,
                    xlims=(-120, 200),
                    xticks=np.arange(-120, 201, 30),
                    ylims=(-60, 60),
                    yticks=np.arange(-60, 61, 20),
                    dlist=None,
                    grid=False,
                    ind_nm='onset',
                    xlabels=True):
    """Create a filled contour plot of data on latitude-day grid.
    """
    var = atm.subset(var, {'lat': ylims})
    vals = var.values.T
    lat = atm.get_coord(var, 'lat')
    days = atm.get_coord(var, 'dayrel')
    if var.min() < 0:
        symmetric = True
    else:
        symmetric = False
    if is_precip:
        cmap = 'PuBuGn'
        extend = 'max'
    else:
        cmap = 'RdBu_r'
        extend = 'both'

    if clev == None:
        cint = atm.cinterval(vals, n_pref=nc_pref, symmetric=symmetric)
        clev = atm.clevels(vals, cint, symmetric=symmetric)
    elif len(atm.makelist(clev)) == 1:
        if is_precip:
            clev = np.arange(0, 10 + clev / 2.0, clev)
        else:
            clev = atm.clevels(vals, clev, symmetric=symmetric)

    plt.contourf(days, lat, vals, clev, cmap=cmap, extend=extend)
    plt.colorbar(ticks=cticks)
    plt.clim(climits)
    atm.ax_lims_ticks(xlims, xticks, ylims, yticks)
    plt.grid(grid)

    if dlist is not None:
        for d0 in dlist:
            plt.axvline(d0, color='k')
    if xlabels:
        plt.gca().set_xticklabels(xticks)
        plt.xlabel('Days Since ' + ind_nm.capitalize())
    else:
        plt.gca().set_xticklabels([])
    if grp is not None and grp.col == 0:
        plt.ylabel('Latitude')

    return None
Пример #2
0
def contourf_latday(var, clev=None, title='', nc_pref=40, grp=None,
                    xlims=(-120, 200), xticks=np.arange(-120, 201, 30),
                    ylims=(-60, 60), yticks=np.arange(-60, 61, 20),
                    ssn_length=None):
    vals = var.values.T
    lat = atm.get_coord(var, 'lat')
    days = atm.get_coord(var, 'dayrel')
    if var.name.lower() == 'precip':
        cmap = 'hot_r'
        extend = 'max'
    else:
        cmap = 'RdBu_r'
        extend = 'both'
    if clev == None:
        symmetric = atm.symm_colors(vals)
        cint = atm.cinterval(vals, n_pref=nc_pref, symmetric=symmetric)
        clev = atm.clevels(vals, cint, symmetric=symmetric)
    cticks_dict = {'precip' : np.arange(0, 13, 2),
                   'T200' : np.arange(-208, 227, 2),
                   'U200' : np.arange(-60, 61, 10),
                   'PSI500' : np.arange(-800, 801, 200)}
    cticks = cticks_dict.get(var.name)
    plt.contourf(days, lat, vals, clev, cmap=cmap, extend=extend)
    plt.colorbar(ticks=cticks)
    fmt_axes(xlims, xticks, ylims, yticks)
    plt.grid()
    plt.title(title)
    plt.axvline(0, color='k')
    if ssn_length is not None:
        plt.axvline(ssn_length, color='k')
    if grp is not None and grp.row == grp.ncol - 1:
        plt.xlabel('Rel Day')
    if grp is not None and grp.col == 0:
        plt.ylabel('Latitude')
Пример #3
0
def contourf_latday(var, clev=None, title='', nc_pref=40, grp=None,
                    xlims=(-120, 200), xticks=np.arange(-120, 201, 30),
                    ylims=(-60, 60), yticks=np.arange(-60, 61, 20),
                    dlist=None, grid=False):
    vals = var.values.T
    lat = atm.get_coord(var, 'lat')
    days = atm.get_coord(var, 'dayrel')
    if var.min() >= 0:
        cmap, extend, symmetric = 'PuBuGn', 'max', False
    else:
        cmap, extend, symmetric = 'RdBu_r', 'both', True
    if clev == None:
        cint = atm.cinterval(vals, n_pref=nc_pref, symmetric=symmetric)
        clev = atm.clevels(vals, cint, symmetric=symmetric)
    elif len(atm.makelist(clev)) == 1:
        if var.name == 'PREC':
            clev = np.arange(0, 10 + clev/2.0, clev)
        else:
            clev = atm.clevels(vals, clev, symmetric=symmetric)
    cticks_dict = {'PRECTOT' : np.arange(0, 13, 2),
                   'PREC' : np.arange(0, 11, 2),
                   'T200' : np.arange(-208, 227, 2),
                   'U200' : np.arange(-60, 61, 10),
                   'PSI500' : np.arange(-800, 801, 200)}
    cticks = cticks_dict.get(var.name)
    plt.contourf(days, lat, vals, clev, cmap=cmap, extend=extend)
    plt.colorbar(ticks=cticks)
    atm.ax_lims_ticks(xlims, xticks, ylims, yticks)
    plt.grid(grid)
    plt.title(title)
    if dlist is not None:
        for d0 in dlist:
            plt.axvline(d0, color='k')
    if grp is not None and grp.row == grp.ncol - 1:
        plt.xlabel('Rel Day')
    if grp is not None and grp.col == 0:
        plt.ylabel('Latitude')
Пример #4
0
def contour_londay(var, clev=None, grp=None,n_pref=40,
                   yticks=np.arange(-120, 201, 30)):
    lon = atm.get_coord(var, 'lon')
    days = atm.get_coord(var, 'dayrel')
    if clev is None:
        cint = atm.cinterval(var, n_pref=n_pref, symmetric=True)
        clev = atm.clevels(var, cint, symmetric=True)
    plt.contourf(lon, days, var, clev, cmap='RdBu_r', extend='both')
    plt.grid()
    plt.colorbar()
    #plt.gca().invert_yaxis()
    plt.yticks(yticks)
    plt.axhline(0, color='k')
    if grp is not None and grp.row == grp.nrow - 1:
        plt.xlabel('Longitude')
    if grp is not None and grp.col == 0:
        plt.ylabel('Rel Day')
Пример #5
0
def contourf_londay(var,
                    clev=None,
                    grp=None,
                    n_pref=40,
                    yticks=np.arange(-120, 201, 30)):
    """Create a filled contour plot of data on longitude-day grid.
    """
    lon = atm.get_coord(var, 'lon')
    days = atm.get_coord(var, 'dayrel')
    if clev is None:
        cint = atm.cinterval(var, n_pref=n_pref, symmetric=True)
        clev = atm.clevels(var, cint, symmetric=True)

    plt.contourf(lon, days, var, clev, cmap='RdBu_r', extend='both')
    plt.colorbar()
    plt.yticks(yticks)
    plt.axhline(0, color='0.5', linestyle='--', dashes=[6, 1])
    if grp is not None and grp.row == grp.nrow - 1:
        plt.xlabel('Longitude')
    if grp is not None and grp.col == 0:
        plt.ylabel('Days Since Onset')
Пример #6
0
def contourf_lat_time(lat, days, plotdata, clev=None, title='', cmap='RdBu_r',
                      onset_nm='', zero_line=False, ax=None):
    if ax is None:
        ax = plt.gca()
    vals = plotdata.values.T
    vals = np.ma.array(vals, mask=np.isnan(vals))
    ncont = 40
    symmetric = atm.symm_colors(plotdata)
    if clev == None:
        cint = atm.cinterval(vals, n_pref=ncont, symmetric=symmetric)
        clev = atm.clevels(vals, cint, symmetric=symmetric)
    cf = ax.contourf(days, lat, vals, clev, cmap=cmap)
    plt.colorbar(mappable=cf, ax=ax)
    #plot_colorbar(symmetric, ax=ax, mappable=cf)
    if symmetric and zero_line:
        ax.contour(days, lat, vals, [0], colors='k')
    ax.grid(True)
    ax.set_ylabel('Latitude')
    ax.set_xlabel('Day Relative to %s Onset' % onset_nm)
    ax.set_title(title)
    xmin, xmax = ax.get_xlim()
    if xmax > 60:
        ax.set_xticks(range(int(xmin), int(xmax) + 1, 30))
    plt.draw()
Пример #7
0
topo = atm.get_ps_clim(lat, lon) / 100
topo.units = 'hPa'

# ----------------------------------------------------------------------
# Correct for topography

u_orig = u
u = atm.correct_for_topography(u_orig, topo)

# ----------------------------------------------------------------------
# Zonal mean zonal wind
season = 'jjas'
lon1, lon2 = 60, 100
cint = 5
months = atm.season_months(season)

uplot = atm.subset(u, 'lon', lon1, lon2, 'mon', months)
uplot = uplot.mean(['lon', 'mon'])

ps_plot = atm.subset(topo, 'lon', lon1, lon2)
ps_plot = ps_plot.mean('lon')

plt.figure()
cs = atm.contour_latpres(uplot, clev=cint, topo=ps_plot)
clev = atm.clevels(uplot, cint, omitzero=True)
plt.clabel(cs, clev[::2], fmt='%02d')

plt.figure()
atm.contourf_latpres(uplot, clev=cint, topo=ps_plot)
# 1-d timeseries
var = data['U200'].sel(dayrel=day)
ts = atm.mean_over_geobox(var, 10, 30, 60, 100)
ts_reg = atm.Linreg(onset, ts)
ts_reg2 = atm.regress_field(ts, onset)
print(ts_reg.r, ts_reg2.r.values)
print(ts_reg.slope, ts_reg2.m.values)
print(ts_reg.p, ts_reg2.p.values)

# x-y data
regdays = [-60, -30, 0, 30, 60]
plotdays = [-60, -30]
clev_r = np.arange(-1.0, 1.01, 0.05)
for nm in varnms:
    print(nm)
    var = data[nm].sel(dayrel=regdays)
    reg_daily = atm.regress_field(var, onset, axis=0)
    for day in plotdays:
        reg = reg_daily.sel(dayrel=day)
        title = '%s day %d vs. Onset ' % (var.name, day)
        cint_m = atm.cinterval(reg.m)
        clev_m = atm.clevels(reg.m, cint_m, symmetric=True)
        plt.figure(figsize=(11, 8))
        plt.subplot(1, 2, 1)
        atm.contourf_latlon(reg['r'], clev=clev_r, cmap='RdBu_r')
        plt.title(title + ' - Corr Coeff')
        plt.subplot(1, 2, 2)
        atm.contourf_latlon(reg['m'], clev=clev_m, cmap='RdBu_r')
        plt.title(title + ' - Reg Coeff')
Пример #9
0
# 1-d timeseries
var = data['U200'].sel(dayrel=day)
ts = atm.mean_over_geobox(var, 10, 30, 60, 100)
ts_reg = atm.Linreg(onset, ts)
ts_reg2 = atm.regress_field(ts, onset)
print(ts_reg.r, ts_reg2.r.values)
print(ts_reg.slope, ts_reg2.m.values)
print(ts_reg.p, ts_reg2.p.values)

# x-y data
regdays = [-60, -30, 0, 30, 60]
plotdays = [-60, -30]
clev_r = np.arange(-1.0, 1.01, 0.05)
for nm in varnms:
    print(nm)
    var = data[nm].sel(dayrel=regdays)
    reg_daily = atm.regress_field(var, onset, axis=0)
    for day in plotdays:
        reg = reg_daily.sel(dayrel=day)
        title = '%s day %d vs. Onset ' % (var.name, day)
        cint_m = atm.cinterval(reg.m)
        clev_m = atm.clevels(reg.m, cint_m, symmetric=True)
        plt.figure(figsize=(11, 8))
        plt.subplot(1, 2, 1)
        atm.contourf_latlon(reg['r'], clev=clev_r, cmap='RdBu_r')
        plt.title(title + ' - Corr Coeff')
        plt.subplot(1, 2, 2)
        atm.contourf_latlon(reg['m'], clev=clev_m, cmap='RdBu_r')
        plt.title(title + ' - Reg Coeff')