コード例 #1
0
def test_corr_grid_and_ts_dask(ts_monthly_da, gridded_da_datetime):
    """Tests that correlation works between a grid and a time series with dask."""
    x = ts_monthly_da().chunk()
    y = gridded_da_datetime().chunk()
    expected = corr(x.load(), y.load(), dim='time')
    actual = corr(x, y, dim='time').compute()
    assert (expected == actual).all()
コード例 #2
0
def test_corr_two_grids_dask(gridded_da_float):
    """Tests that correlations between two grids work with dask."""
    x = gridded_da_float().chunk()
    y = gridded_da_float().chunk()
    expected = corr(x.load(), y.load(), dim='time')
    actual = corr(x, y, dim='time').compute()
    assert (expected == actual).all()
コード例 #3
0
def test_autocorr(gridded_da_float):
    """Tests that ``autocorr`` functions properly."""
    x = gridded_da_float()
    actual = autocorr(x, nlags=None)
    actual = autocorr(x, nlags=10)
    expected = xr.concat([corr(x, x, lead=i) for i in range(10)], 'lead')
    assert (actual.values == expected.values).all()
コード例 #4
0
def decorrelation_time(da, r=20, dim="time"):
    """Calculate the decorrelaton time of a time series.

    .. math::
        \\tau_{d} = 1 + 2 * \\sum_{k=1}^{r}(\\alpha_{k})^{k}

    Args:
        da (xarray object): Time series.
        r (optional int): Number of iterations to run the above formula.
        dim (optional str): Time dimension for xarray object.

    Returns:
        Decorrelation time of time series.

    Reference:
        * Storch, H. v, and Francis W. Zwiers. Statistical Analysis in Climate
          Research. Cambridge ; New York: Cambridge University Press, 1999.,
          p.373

    """
    one = xr.ones_like(da.isel({dim: 0}))
    one = one.where(da.isel({dim: 0}).notnull())
    return one + 2 * xr.concat(
        [corr(da, da, dim=dim, lead=i)**i
         for i in range(1, r)], "it").sum("it")
コード例 #5
0
def test_corr_return_p(gridded_da_float):
    """Tests that p-value is returned properly for correlation."""
    x = gridded_da_float()
    y = gridded_da_float()
    corrcoeff, pval = corr(x, y, dim='time', return_p=True)
    assert not (corrcoeff.isnull().any()) & (pval.isnull().any())
コード例 #6
0
def test_corr_two_grids(gridded_da_float):
    """Tests that correlations between two grids work."""
    x = gridded_da_float()
    y = gridded_da_float()
    corrcoeff = corr(x, y, dim='time')
    assert not corrcoeff.isnull().any()
コード例 #7
0
def test_corr_lag(gridded_da_float):
    """Tests negative lead for correlation."""
    x = gridded_da_float()
    y = gridded_da_float()
    corrcoeff = corr(x, y, dim='time', lead=-3)
    assert not corrcoeff.isnull().any()
コード例 #8
0
def test_corr_grid_and_ts(ts_monthly_da, gridded_da_datetime):
    """Tests that correlation works between a grid and a time series."""
    x = ts_monthly_da()
    y = gridded_da_datetime()
    corrcoeff = corr(x, y, dim='time')
    assert not corrcoeff.isnull().any()
コード例 #9
0
ファイル: test_stats_corr.py プロジェクト: lukegre/esmtools
def test_corr_lead(gridded_da_float):
    """Tests positive lead for correlation."""
    x = gridded_da_float()
    y = gridded_da_float()
    corrcoeff = corr(x, y, dim="time", lead=3)
    assert not corrcoeff.isnull().any()