Exemple #1
0
def test_isotropic_ps_slope(chunk, N=512, dL=1.0, amp=1e1, s=-3.0):
    """Test the spectral slope of isotropic power spectrum."""

    theta = synthetic_field_xr(
        N,
        dL,
        amp,
        s,
        other_dim_sizes=[10],
        dim_order=True,
    )

    if chunk:
        theta = theta.chunk({"d0": 2})

    iso_ps = xrft.isotropic_power_spectrum(
        theta, dim=["y", "x"], detrend="constant", density=True
    ).mean("d0")
    npt.assert_almost_equal(np.ma.masked_invalid(iso_ps).mask.sum(), 0.0)
    y_fit, a, b = xrft.fit_loglog(iso_ps.freq_r.values[4:], iso_ps.values[4:])
    npt.assert_allclose(a, s, atol=0.1)

    iso_ps_sequal = np.zeros((len(theta.d0), int(N / 4)))
    for i in range(len(theta.d0)):
        iso_ps_sequal[i] = xrft.isotropic_power_spectrum(
            theta.isel(d0=i), detrend="constant", density=True
        )
    npt.assert_almost_equal(iso_ps.values, iso_ps_sequal.mean(axis=0))
Exemple #2
0
def test_isotropic_ps_slope(N=512, dL=1., amp=1e1, s=-3.):
    """Test the spectral slope of isotropic power spectrum."""

    theta = xr.DataArray(_synthetic_field(N, dL, amp, s),
                        dims=['y', 'x'],
                        coords={'y':range(N), 'x':range(N)})
    iso_ps = xrft.isotropic_powerspectrum(theta, detrend='constant',
                                         density=True)
    npt.assert_almost_equal(np.ma.masked_invalid(iso_ps[1:]).mask.sum(), 0.)
    y_fit, a, b = xrft.fit_loglog(iso_ps.freq_r.values[4:],
                                 iso_ps.values[4:])

    npt.assert_allclose(a, s, atol=.1)
Exemple #3
0
def test_isotropic_ps_slope(N=512, dL=1., amp=1e1, s=-3.):
    """Test the spectral slope of isotropic power spectrum."""

    theta = xr.DataArray(synthetic_field(N, dL, amp, s),
                        dims=['y', 'x'],
                        coords={'y':range(N), 'x':range(N)})
    iso_ps = xrft.isotropic_power_spectrum(theta, detrend='constant',
                                         density=True)
    npt.assert_almost_equal(np.ma.masked_invalid(iso_ps[1:]).mask.sum(), 0.)
    y_fit, a, b = xrft.fit_loglog(iso_ps.freq_r.values[4:],
                                 iso_ps.values[4:])

    npt.assert_allclose(a, s, atol=.1)