예제 #1
0
def bootstrap_ssh(ssha, niter, tw, order, simlen=10000):
    """
    Generate [niter] white and red noise maps,
    then passes a low-pass filter through them

    Parameters
    ----------
    ssha : ARRAY[time x lat x lon]
        SSH anomalies
    niter : INT
        # of white noise timeseries to generate
    tw : INT
        Low pass filter cutoff time window
    order : INT
        Order of the low-pass filter
    simlen : INT, optional
        Total length of generated wn timeseries (before truncation). The default is 10000.

    Returns
    -------
    wnout : ARRAY [niter x time x lat x lon]
        White Noise Maps
    rnout : ARRAY [niter x time x lat x lon]
        Red Noise Maps
    ar1m : [lat x lon]
        AR1 Coefficients
    neffm : [lat x lon]
        Effective DOF
    """

    # Get Dimensions
    ntime, nlat, nlon = ssha.shape

    # Make land/ice mask
    msk = ssha.copy()
    msk = msk.sum(0)
    msk[~np.isnan(msk)] = 1

    # Calculate Stdev
    aviso_std = ssha.std(0)

    # Preallocate
    wnout = np.zeros((niter, ntime, nlat, nlon)) * np.nan
    rnout = np.zeros((niter, ntime, nlat, nlon)) * np.nan

    # Loop for each interation
    for it in tqdm(range(niter)):

        # Create white noise timeseries
        wn = np.random.normal(0, 1, (simlen, nlat5, nlon5))
        wn *= msk[None, :, :]

        # Create scaled form of timeseries
        wnstd = wn.copy()
        wnstd *= aviso_std[None, :, :]

        # Get stddev and AR1 for red noise timeseries
        rnstd, ar1m, neffm = slutil.return_ar1_model(ssha, simlen)

        # Select the last n points (match sample size of aviso)
        wnstd = wnstd[-ntime:, :, :]
        rnstd = rnstd[-ntime:, :, :]

        # Low Pass Filter The Timeseries
        wnlp = slutil.lp_butter(wnstd, tw, order)
        rnlp = slutil.lp_butter(rnstd, tw, order)

        # Apply Save the results
        wnout[it, ...] = wnlp
        rnout[it, ...] = rnlp

    return wnout, rnout, ar1m, neffm
예제 #2
0
# ----------------------
#%% Design Low Pass Filter
# ----------------------

# ---
# Apply LP Filter
# ---
# Filter Parameters and Additional plotting options
dt = 24 * 3600 * 30
M = 5
xtk = [1 / (10 * 12 * dt), 1 / (24 * dt), 1 / (12 * dt), 1 / (3 * dt), 1 / dt]
xtkl = ['decade', '2-yr', 'year', 'season', 'month']
order = 5
tw = 15  # filter size for time dim
sla_lp = slutil.lp_butter(ssha, tw, order)

#% Remove NaN points and Examine Low pass filter
slars = sla_lp.reshape(ntimer, nlat5 * nlon5)

# ---
# Locate points where values are all zero
# ---
tsum = slars.sum(0)
zero_pts = np.where(tsum == 0)[0]
ptmap = np.array(tsum == 0)
slars[:, zero_pts] = np.nan
ptmap = ptmap.reshape(nlat5, nlon5)
# Map removed points
fig, ax = plt.subplots(
    1, 1, subplot_kw={'projection': ccrs.PlateCarree(central_longitude=0)})
예제 #3
0
maxar1 = np.nanmax(sshac[1, :, :])  # Find Maximum Autocorrelation
# ----------------------
#%% Design Low Pass Filter
# ----------------------

# ---
# Apply LP Filter
# ---
# Filter Parameters and Additional plotting options
dt = 24 * 3600 * 30
M = 5
xtk = [1 / (10 * 12 * dt), 1 / (24 * dt), 1 / (12 * dt), 1 / (3 * dt), 1 / dt]
xtkl = ['decade', '2-yr', 'year', 'season', 'month']
order = 5
tw = 15  # filter size for time dim
sla_lp = slutil.lp_butter(ssha, tw, order)

#% Remove NaN points and Examine Low pass filter
slars = sla_lp.reshape(ntimer, nlat5 * nlon5)

# ---
# Locate points where values are all zero
# ---
tsum = slars.sum(0)
zero_pts = np.where(tsum == 0)[0]
ptmap = np.array(tsum == 0)
slars[:, zero_pts] = np.nan
ptmap = ptmap.reshape(nlat5, nlon5)
# Map removed points
fig, ax = plt.subplots(
    1, 1, subplot_kw={'projection': ccrs.PlateCarree(central_longitude=0)})