Example #1
0
def test_interp_lower_frequency(dset2):
    new_freq = np.linspace(0.01, 0.5, 25)
    dsi = regrid_spec(dset2, freq=new_freq)
    assert dsi.spec.oned().isel(site=0, time=0).isel(freq=0) > 0
    new_freq = np.linspace(0.0, 0.5, 25)
    dsi = regrid_spec(dset2, freq=new_freq)
    assert dsi.spec.oned().isel(site=0, time=0).isel(freq=0) == 0
Example #2
0
    def interp(self, freq=None, dir=None, maintain_m0=True):
        """Interpolate onto new spectral basis.

        Args:
            - freq (DataArray, 1darray): Frequencies of interpolated spectra (Hz).
            - dir (DataArray, 1darray): Directions of interpolated spectra (deg).
            - maintain_m0 (bool): Ensure variance is conserved in interpolated spectra.

        Returns:
            - dsi (DataArray): Regridded spectra.

        Note:
            - All freq below lowest freq are interpolated assuming :math:`E_d(f=0)=0`.
            - :math:`Ed(f)` is set to zero for new freq above the highest freq in dset.
            - Only the 'linear' method is currently supported.

        """
        return regrid_spec(self._obj, freq, dir, maintain_m0=maintain_m0)
Example #3
0
def test_interp_upper_direction(dset2):
    dset = dset2.sortby("dir").isel(dir=slice(None, -1))
    new_dir = np.arange(0.0, 360, 10)
    dsi = regrid_spec(dset, dir=new_dir)
    assert dsi.spec.dir.max() > dset.spec.dir.max()
Example #4
0
def test_interp_lower_direction(dset2):
    dset = dset2.sortby("dir").isel(dir=slice(1, None))
    new_dir = np.arange(0.0, 360, 10)
    dsi = regrid_spec(dset, dir=new_dir)
    assert dsi.spec.dir.min() < dset.spec.dir.min()
Example #5
0
def test_interp_higher_frequency(dset2):
    new_freq = np.linspace(0.01, 0.5, 25)
    dsi = regrid_spec(dset2, freq=new_freq)
    assert dsi.where(dsi.freq > dset2.freq.max(), drop=True).spec.hs().sum() == 0
Example #6
0
def test_not_maintain_m0(dset):
    new_freq = np.linspace(0, 0.5, 25)
    new_dir = np.arange(0, 360, 5)
    dsi = regrid_spec(dset, dir=new_dir, freq=new_freq, maintain_m0=False)
    assert dset.spec.hs().values != pytest.approx(dsi.spec.hs().values)
Example #7
0
def test_interp_dir(dset):
    new_dir = np.arange(0, 360, 5)
    dsi = regrid_spec(dset, dir=new_dir)
    assert dset.spec.freq.equals(dsi.spec.freq)
    assert np.array_equal(dsi.spec.dir, new_dir)
Example #8
0
def test_interp_freq(dset):
    new_freq = np.linspace(0, 0.5, 25)
    dsi = regrid_spec(dset, freq=new_freq)
    assert dset.spec.dir.equals(dsi.spec.dir)
    assert np.array_equal(dsi.spec.freq, new_freq)
Example #9
0
def test_specarray_interp(dset):
    new_freq = np.linspace(0, 0.5, 25)
    new_dir = np.arange(0, 360, 5)
    dsi1 = regrid_spec(dset, dir=new_dir, freq=new_freq)
    dsi2 = dset.spec.interp(dir=new_dir, freq=new_freq)
    dsi1.equals(dsi2)