示例#1
0
    def test_indexing_error(self):
        """ Test that fft2freq correctly raises ValueError for invalid indexing. """
        extent_x = np.linspace(0, 1)
        extent_y = np.linspace(3, 4, num=47)

        with self.assertRaises(ValueError):
            fft2freq([1, 2], [1, 2], indexing="ab")
示例#2
0
def test_shape():
    """ Test that the output from fft2freq has the same shape as the input. """
    extent_x = np.linspace(0, 1)
    extent_y = np.linspace(3, 4, num=47)

    for indexing in {"ij", "xy"}:
        x, y = np.meshgrid(extent_x, extent_y, indexing=indexing)
        kx, ky = fft2freq(x, y, indexing=indexing)
        assert x.shape == kx.shape
        assert y.shape == ky.shape
示例#3
0
    def test_shape(self):
        """ Test that the output from fft2freq has the same shape as the input. """
        extent_x = np.linspace(0, 1)
        extent_y = np.linspace(3, 4, num=47)

        for indexing in {"ij", "xy"}:
            with self.subTest("Indexing {}".format(indexing)):
                x, y = np.meshgrid(extent_x, extent_y, indexing=indexing)
                kx, ky = fft2freq(x, y, indexing=indexing)
                self.assertTupleEqual(x.shape, kx.shape)
                self.assertTupleEqual(y.shape, ky.shape)
示例#4
0
def test_vs_fftfreq():
    """ Test that the results make sense with respect to 1D case """
    extent_x = np.arange(0, 10, step=0.1)
    extent_y = np.arange(3, 4, step=0.1)

    for indexing in {"ij", "xy"}:
        x, y = np.meshgrid(extent_x, extent_y, indexing=indexing)
        kx, ky = fft2freq(x, y, indexing=indexing)

        # same array creates from the 1d case
        kx_1d = np.fft.fftfreq(len(extent_x), d=0.1)
        ky_1d = np.fft.fftfreq(len(extent_y), d=0.1)
        kx2, ky2 = np.meshgrid(kx_1d, ky_1d, indexing=indexing)

        assert np.allclose(kx, kx2)
        assert np.allclose(ky, ky2)