MCPcopy Index your code
hub / github.com/pydata/xarray / test_autocov

Function test_autocov

xarray/tests/test_computation.py:1758–1768  ·  view source on GitHub ↗
(n: int, dim: str | None, arrays)

Source from the content-addressed store, hash-verified

1756@pytest.mark.parametrize("n", range(5))
1757@pytest.mark.parametrize("dim", [None, "time", "x", ["time", "x"]])
1758def test_autocov(n: int, dim: str | None, arrays) -> None:
1759 da = arrays[n]
1760
1761 # Testing that the autocovariance*(N-1) is ~=~ to the variance matrix
1762 # 1. Ignore the nans
1763 valid_values = da.notnull()
1764 # Because we're using ddof=1, this requires > 1 value in each sample
1765 da = da.where(valid_values.sum(dim=dim) > 1)
1766 expected = ((da - da.mean(dim=dim)) ** 2).sum(dim=dim, skipna=True, min_count=1)
1767 actual = xr.cov(da, da, dim=dim) * (valid_values.sum(dim) - 1)
1768 assert_allclose(actual, expected)
1769
1770
1771def test_complex_cov() -> None:

Callers

nothing calls this directly

Calls 6

assert_allcloseFunction · 0.90
covMethod · 0.80
notnullMethod · 0.45
whereMethod · 0.45
sumMethod · 0.45
meanMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…