Exemple #1
0
 def test_new_shape_one_size(self):
     """Make sure the new shape has the same dimensions when one is given."""
     oldshape = (10, 20, 30)
     data = rng.standard_normal(oldshape)
     newsize = 50
     newdata = fft_pad(data, newsize)
     assert (newsize, ) * newdata.ndim == newdata.shape
Exemple #2
0
 def test_new_shape_multiple(self):
     """Make sure the new shape has the same dimensions when one is given."""
     oldshape = (10, 20, 30, 40)
     data = rng.standard_normal(oldshape)
     newsize = (50, 40, 30, 100)
     newdata = fft_pad(data, newsize)
     assert newsize == newdata.shape
Exemple #3
0
 def test_new_shape_no_size(self):
     """Test the make a new shape with even and odd numbers when no size is specified, i.e. test auto padding."""
     oldshape = (2 * 17, 17)
     data = np.zeros(oldshape)
     newshape = tuple(next_fast_len(s) for s in oldshape)
     newdata = fft_pad(data)
     assert newshape == newdata.shape
Exemple #4
0
 def test_smaller_shape(self):
     """Test that cropping works as expected."""
     oldshape = rng.integers(10, 200)
     newshape = rng.integers(5, oldshape)
     data = np.ones(oldshape)
     assert data.shape == oldshape
     pad_data = fft_pad(data, newshape)
     assert pad_data.shape == newshape
Exemple #5
0
def test_padding_slices():
    """Make sure we can reverse things."""
    oldshape = tuple(rng.integers(64, 256 - 64, 2))
    newshape = tuple(rng.integers(s, s * 2) for s in oldshape)
    data = rng.standard_normal(oldshape)
    new_data = fft_pad(data, newshape)
    padding, slices = _padding_slices(newshape, oldshape)
    assert np.all(data == new_data[slices])
Exemple #6
0
 def test_right_position_multidimensional(self):
     """Make sure that center stays centered (for ffts) fuzzy test to see if I missed anything."""
     for i in range(10):
         dims = rng.integers(1, 4)
         oldshape = rng.integers(10, 100, dims)
         newshape = rng.integers(10, 100, dims)
         data = np.zeros(oldshape)
         zero_loc = (0, ) * dims
         data[zero_loc] = 1
         data_centered = ifftshift(data)
         data_padded = fft_pad(data_centered, newshape)
         assert fftshift(data_padded)[zero_loc] == 1
Exemple #7
0
 def test_right_position_cases(self):
     """Make sure that center stays centered (for ffts) all cases."""
     cases = (
         (14, 34),  # even -> even
         (14, 35),  # even -> odd
         (17, 34),  # odd -> even
         (17, 35),  # odd -> odd
     )
     # same cases
     same = ((34, 34), (35, 35))  # odd -> odd  # even -> even
     # try the cropping version too
     rev_cases = tuple((j, i) for i, j in cases)
     for oldshape, newshape in cases + same + rev_cases:
         data = np.zeros(oldshape)
         data[0] = 1
         data_centered = ifftshift(data)
         data_padded = fft_pad(data_centered, newshape)
         assert fftshift(data_padded)[0] == 1
Exemple #8
0
 def test_wrong_newshape(self):
     """Test newshape input."""
     with pytest.raises(ValueError):
         data = np.empty((12, 15))
         fft_pad(data, object)