Skip to content

Commit

Permalink
Add test for round trip of pad & unpad with fft & ifft
Browse files Browse the repository at this point in the history
  • Loading branch information
santisoler committed Nov 6, 2021
1 parent 3ca5118 commit 35e1d33
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions xrft/tests/test_padding.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import numpy.testing as npt

from ..padding import pad, _pad_coordinates, unpad, _pad_width_to_slice
from ..xrft import fft, ifft


@pytest.fixture
Expand Down Expand Up @@ -202,3 +203,30 @@ def test_unpad_pop_pad_width_attributes(sample_da_2d, pad_width_arg):
# Check if unpadded doesn't have the pad_width attribtues
for dim in unpadded.coords:
assert "pad_width" not in unpadded.coords[dim].attrs


@pytest.mark.parametrize(
"pad_width",
(
{"x": 4, "y": 3},
{"x": 4},
{"y": 3},
{"x": (4, 3), "y": 3},
{"x": (4, 3), "y": (5, 3)},
{"x": (4, 3)},
{"y": (5, 3)},
),
)
def test_unpad_ifft_fft_pad_round_trip(sample_da_2d, pad_width):
"""
Test if the round trip with padding and unpadding works
This test passes a custom ``pad_width`` to the ``unpad`` function because
the ``fft`` doesn't support keeping the ``pad_width`` attribute on the
coordinates (at least for now).
"""
da_padded = pad(sample_da_2d, pad_width, constant_values=0)
da_fft = fft(da_padded, true_phase=True)
da_ifft = ifft(da_fft, true_phase=True)
da_unpadded = unpad(da_ifft, pad_width=pad_width)
xrt.assert_allclose(sample_da_2d, da_unpadded)

0 comments on commit 35e1d33

Please sign in to comment.