def single_WLH(cmap_file, yrmin, yrmax, lat0, lon0, loc_nm, kmax, kann,
               onset_min=20):
    # Single grid point and single year/climatology
    precip = precipdat.read_cmap(cmap_file, yrmin, yrmax)
    if yrmax > yrmin:
        precip = precip.mean(axis=0)
        titlestr = 'CMAP %d-%d' % (yrmin, yrmax)
    else:
        precip = precip[0]
        titlestr = 'CMAP %d' % yrmin

    latval, ilat0 = atm.find_closest(precip.lat, lat0)
    lonval, ilon0 = atm.find_closest(precip.lon, lon0)
    d = 1.25
    latstr = atm.latlon_labels(latval+d, 'lat', '%.1f', deg_symbol=False)
    lonstr = atm.latlon_labels(lonval+d, 'lon', '%.1f', deg_symbol=False)
    titlestr = '%s %s (%s, %s)' % (titlestr, loc_nm, latstr, lonstr)

    pcp = precip[:, ilat0, ilon0]
    pcp_sm, Rsq = atm.fourier_smooth(pcp, kmax)
    pcp_ann, Rsq_ann = atm.fourier_smooth(pcp, kann)
    i_onset, i_retreat, i_peak = onset_WLH_1D(pcp_sm, threshold, onset_min)

    plot_single_WLH(pcp, pcp_sm, pcp_ann, Rsq, Rsq_ann, i_onset, i_retreat, i_peak, kmax, kann, titlestr)

    return pcp, pcp_sm, pcp_ann, Rsq, Rsq_ann, i_onset, i_retreat, i_peak
Exemplo n.º 2
0
nharm = 3  # Number of harmonics to plot

spec1 = Fourier(y, dt, t)
spec1 = test_fourier(spec1, ntrunc)
spec2 = fromscratch(y, dt, ntrunc, spec1.t)
plot_fourier(spec1, nharm, ntrunc)
plot_fourier(spec2, nharm, ntrunc)

# ----------------------------------------------------------------------

with xray.open_dataset(cmap_file) as ds:
    ds.load()

#lat0, lon0 = 12.5, 90.0
lat0, lon0 = 11.25, 91.25
latval, ilat0 = atm.find_closest(ds.lat, lat0)
lonval, ilon0 = atm.find_closest(ds.lon, lon0)
cmap = ds['precip'].sel(lat=latval, lon=lonval)

npentad = 73  # pentads/year
dt = 5.0 / 365
nyears = 1
precip = cmap[:nyears * npentad]
y = precip.values
ntrunc = 12
nharm = 3

spec1 = Fourier(y, dt)
spec1 = test_fourier(spec1, ntrunc)
spec2 = fromscratch(y, dt, ntrunc, spec1.t)
plot_fourier(spec1, nharm, ntrunc)
Exemplo n.º 3
0
for nm in varnms:
    print(nm)
    var = atm.subset(databar[nm], {'dayrel' : (-npre, npost)})
    lat = atm.get_coord(var, 'lat')
    if nm == 'PSI':
        var = atm.subset(var, {'lat' : (-25, 10)})
        latname = atm.get_coord(var, 'lat', 'name')
        pname = atm.get_coord(var, 'plev', 'name')
        var_out = var.max(dim=latname).max(dim=pname)
        tseries['PSIMAX'] = atm.rolling_mean(var_out, nroll, center=True)
    else:
        for lat0 in lat_extract:
            lat0_str = atm.latlon_labels(lat0, 'lat', deg_symbol=False)
            key = nm + '_' + lat0_str
            val, ind = atm.find_closest(lat, lat0)
            var_out = atm.squeeze(var[:, ind])
            tseries[key] = atm.rolling_mean(var_out, nroll, center=True)

# ----------------------------------------------------------------------
# Functions for plotting

fmt_axes = atm.ax_lims_ticks
clear_labels = atm.clear_labels
to_dataset = atm.to_dataset

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
Exemplo n.º 4
0
for nm in ['GPCP', 'PRECTOT']:
    ts[nm] = atm.mean_over_geobox(data[nm], lat1, lat2, lon1, lon2)
ts['MFC'] = utils.daily_rel2onset(index_all['CHP_MFC']['daily_ts'],
                                  index[ind_nm], npre, npost)
ts['CMFC'] = utils.daily_rel2onset(index_all['CHP_MFC']['tseries'],
                                   index[ind_nm], npre, npost)


# Extract variables at specified latitudes
for nm, lat0 in lat_extract.iteritems():
    var = atm.dim_mean(data[nm], 'lon', lon1, lon2)
    lat = atm.get_coord(var, 'lat')
    lat0_str = atm.latlon_labels(lat0, 'lat', deg_symbol=False)
    # key = nm + '_' + lat0_str
    key = nm
    lat_closest, _ = atm.find_closest(lat, lat0)
    print '%s %.2f %.2f' % (nm, lat0, lat_closest)
    ts[key] = atm.subset(var, {'lat' : (lat_closest, None)}, squeeze=True)

# Compute climatology and smooth with rolling mean
if 'year' in ts.dims:
    ts = ts.mean(dim='year')
if nroll is not None:
    for nm in ts.data_vars:
        ts[nm] = atm.rolling_mean(ts[nm], nroll, center=True)
tseries = atm.subset(ts, {'dayrel' : (-npre, npost)})


# Smooth latitude-dayrel data with rolling mean
for nm in data:
    daydim = atm.get_coord(data[nm], 'dayrel', 'dim')
nharm = 3 # Number of harmonics to plot

spec1 = Fourier(y, dt, t)
spec1 = test_fourier(spec1, ntrunc)
spec2 = fromscratch(y, dt, ntrunc, spec1.t)
plot_fourier(spec1, nharm, ntrunc)
plot_fourier(spec2, nharm, ntrunc)

# ----------------------------------------------------------------------

with xray.open_dataset(cmap_file) as ds:
    ds.load()

#lat0, lon0 = 12.5, 90.0
lat0, lon0 = 11.25, 91.25
latval, ilat0 = atm.find_closest(ds.lat, lat0)
lonval, ilon0 = atm.find_closest(ds.lon, lon0)
cmap = ds['precip'].sel(lat=latval, lon=lonval)

npentad = 73 # pentads/year
dt = 5.0/365
nyears = 1
precip = cmap[:nyears*npentad]
y = precip.values
ntrunc = 12
nharm = 3

spec1 = Fourier(y, dt)
spec1 = test_fourier(spec1, ntrunc)
spec2 = fromscratch(y, dt, ntrunc, spec1.t)
plot_fourier(spec1, nharm, ntrunc)