Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Jun 1, 2021
1 parent 819ca10 commit b0a9128
Show file tree
Hide file tree
Showing 33 changed files with 169 additions and 169 deletions.
2 changes: 1 addition & 1 deletion skued/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main(args=None):


def main_diffshow(fname):
""" Display an interactive window """
"""Display an interactive window"""
if not WITH_PYQTGRAPH:
print(
"PyQtGraph is required for this functionality. You can install PyQtGraph either with \
Expand Down
26 changes: 13 additions & 13 deletions skued/baseline/tests/test_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@


def test_zero_level():
""" baseline computed at the zero-th level should not affect the array """
"""baseline computed at the zero-th level should not affect the array"""
array = np.random.random(size=(101,))
assert np.allclose(array, baseline_dwt(array, max_iter=5, level=0))


def test_approx_rec():
""" Test that the underlying _dwt_approx_rec function is working properly """
"""Test that the underlying _dwt_approx_rec function is working properly"""

arr = np.random.random(size=(102,))
rec_arr = _dwt_approx_rec(arr, level=2, wavelet="db6", mode="constant", axis=-1)
Expand All @@ -45,19 +45,19 @@ def test_approx_rec():


def test_trivial_case_1d():
""" The baseline for a 1d array of zeros should be zeros """
"""The baseline for a 1d array of zeros should be zeros"""
arr = np.zeros(shape=(101,))
assert np.allclose(arr, baseline_dwt(arr, max_iter=10, level=None))


def test_trivial_case_2d():
""" The baseline for a 2d array of zeros should be zeros """
"""The baseline for a 2d array of zeros should be zeros"""
arr = np.zeros((21, 31, 5))
assert np.allclose(arr, baseline_dwt(arr, max_iter=10, level=None, axis=(0, 1)))


def test_1d_along_axis():
""" Test that iterating over array rows and baseline_dwt along axis are equivalent """
"""Test that iterating over array rows and baseline_dwt along axis are equivalent"""
block = np.random.random(size=(21, 51))

# Iterate over rows
Expand All @@ -72,13 +72,13 @@ def test_1d_along_axis():


def test_zero_level():
""" baseline computed at the zero-th level should not affect the array """
"""baseline computed at the zero-th level should not affect the array"""
array = np.random.random(size=(101,))
assert np.allclose(array, baseline_dt(array, max_iter=5, level=0))


def test_approx_rec():
""" Test that the underlying _dwt_approx_rec function is working properly """
"""Test that the underlying _dwt_approx_rec function is working properly"""

arr = np.random.random(size=(102,))
rec_arr = _dt_approx_rec(
Expand All @@ -104,29 +104,29 @@ def test_approx_rec():


def test_trivial_case():
""" The baseline for an array of zeros should be zeros """
"""The baseline for an array of zeros should be zeros"""
arr = np.zeros(shape=(101,))
assert np.allclose(arr, baseline_dt(arr, max_iter=10, level=None))


def test_positive_baseline():
""" Test that the baseline is never negative """
"""Test that the baseline is never negative"""
arr = 10 * np.random.random(size=(128,))
baseline = baseline_dt(arr, max_iter=10)

assert np.all(np.greater_equal(baseline, 0))


def test_baseline_limit():
""" Test that the baseline is never more than the original signal """
"""Test that the baseline is never more than the original signal"""
arr = 10 * np.random.random(size=(128,))
baseline = baseline_dt(arr, max_iter=10)

assert np.all(np.greater_equal(arr, baseline))


def test_final_shape():
""" Test that baseline_dt returns an array of the same shape as input """
"""Test that baseline_dt returns an array of the same shape as input"""

arr = np.random.random(size=(101,))
b = baseline_dt(arr, max_iter=10, level=None)
Expand All @@ -146,7 +146,7 @@ def test_final_shape():


def test_2d_along_axis():
""" Test that iterating over array rows and baseline_dt along axis are equivalent """
"""Test that iterating over array rows and baseline_dt along axis are equivalent"""
block = np.random.random(size=(21, 51))

# Iterate over rows
Expand All @@ -161,7 +161,7 @@ def test_2d_along_axis():


def test_background_regions():
""" Test that background_regions is used correctly along certain axes """
"""Test that background_regions is used correctly along certain axes"""
block = np.random.random(size=(21, 51))

baseline_params = {"max_iter": 50, "background_regions": [(..., range(0, 3))]}
Expand Down
16 changes: 8 additions & 8 deletions skued/baseline/tests/test_dtcwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


def test_first_stage():
""" Test of perfect reconstruction of first stage wavelets. """
"""Test of perfect reconstruction of first stage wavelets."""
array = np.sin(np.arange(0, 10, step=0.01))
for wavelet in available_first_stage_filters():
# Using waverec and wavedec instead of dwt and idwt because parameters
Expand All @@ -27,7 +27,7 @@ def test_first_stage():


def gen_input(n_dimensions):
""" Generate random array with the appropriate dimensions """
"""Generate random array with the appropriate dimensions"""
shape = {1: (100,), 2: (50, 50), 3: (10, 10, 10)}[n_dimensions]
return np.random.random(size=shape)

Expand All @@ -37,7 +37,7 @@ def gen_input(n_dimensions):

@multidim
def test_perfect_reconstruction_level_0(n_dimensions):
""" Test perfect reconstruction for a 0-level decomposition """
"""Test perfect reconstruction for a 0-level decomposition"""
array = gen_input(n_dimensions)
coeffs = dtcwt(data=array, level=0, first_stage="sym6", wavelet="qshift1")
reconstructed = idtcwt(coeffs=coeffs, first_stage="sym6", wavelet="qshift1")
Expand All @@ -46,7 +46,7 @@ def test_perfect_reconstruction_level_0(n_dimensions):

@multidim
def test_perfect_reconstruction_level_1(n_dimensions):
""" Test perfect reconstruction for a single decomposition level """
"""Test perfect reconstruction for a single decomposition level"""
array = gen_input(n_dimensions)
for first_stage in available_first_stage_filters():
coeffs = dtcwt(data=array, level=1, first_stage=first_stage, wavelet="qshift1")
Expand All @@ -58,7 +58,7 @@ def test_perfect_reconstruction_level_1(n_dimensions):

@multidim
def test_perfect_reconstruction_multilevel(n_dimensions):
""" Test perfect reconstruction for all levels, for all first_stage wavelets, for all DT wavelets """
"""Test perfect reconstruction for all levels, for all first_stage wavelets, for all DT wavelets"""
array = gen_input(n_dimensions)

for first_stage in available_first_stage_filters():
Expand All @@ -81,7 +81,7 @@ def test_perfect_reconstruction_multilevel(n_dimensions):

@multidim
def test_axis(n_dimensions):
""" Test perfect reconstruction along all axes """
"""Test perfect reconstruction along all axes"""
array = gen_input(n_dimensions)
for axis in range(0, array.ndim):
coeffs = dtcwt(
Expand All @@ -99,7 +99,7 @@ def test_axis(n_dimensions):

@multidim
def test_axis_limits(n_dimensions):
""" Test that an exception is raised for an invalid 'axis' parameter """
"""Test that an exception is raised for an invalid 'axis' parameter"""
array = gen_input(n_dimensions)
with pytest.raises(ValueError):
coeffs = dtcwt(
Expand All @@ -113,7 +113,7 @@ def test_axis_limits(n_dimensions):

@multidim
def test_even_length_along_axis(n_dimensions):
""" Test that an exception is raised when array is not even along transform axis """
"""Test that an exception is raised when array is not even along transform axis"""
with pytest.raises(ValueError):
dtcwt(
data=np.zeros((17, 8)),
Expand Down
2 changes: 1 addition & 1 deletion skued/fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __ua_function__(method, args, kwargs):


def with_skued_fft(f):
""" Ensure the use of the SkuedPocketFFTBackend whenever the `scipy.fft` module is used. """
"""Ensure the use of the SkuedPocketFFTBackend whenever the `scipy.fft` module is used."""

@wraps(f)
def newf(*args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion skued/image/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def hypot(*args):
""" Generalized np.hypot """
"""Generalized np.hypot"""
return np.sqrt(np.sum(np.square(args)))


Expand Down
2 changes: 1 addition & 1 deletion skued/image/powder.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def azimuthal_average(image, center, mask=None, angular_bounds=None, trim=True):


def _trim_bounds(arr):
""" Returns the bounds which would be used in numpy.trim_zeros """
"""Returns the bounds which would be used in numpy.trim_zeros"""
first = 0
for i in arr:
if i != 0.0:
Expand Down
14 changes: 7 additions & 7 deletions skued/image/tests/test_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def circle_image(shape, center, radii, intensities):
""" Creates an image with circle or thickness 2 """
"""Creates an image with circle or thickness 2"""
im = np.zeros(shape=shape, dtype=float)
xx, yy = np.ogrid[0 : shape[0], 0 : shape[1]]
xx, yy = xx - center[0], yy - center[1]
Expand All @@ -36,7 +36,7 @@ def camera():


def test_ialign_trivial():
""" Test alignment of identical images """
"""Test alignment of identical images"""
aligned = tuple(ialign([camera() for _ in range(5)]))

assert len(aligned) == 5
Expand All @@ -62,15 +62,15 @@ def test_ialign_misaligned_canned_images():


def test_align_no_side_effects():
""" Test that aligned images are not modified in-place """
"""Test that aligned images are not modified in-place"""
im = np.array(camera()[0:64, 0:64])
im.setflags(write=False)
aligned = align(im, reference=im, fill_value=np.nan)
assert im.dtype == camera().dtype


def test_align_no_mask():
""" Test that alignment of images with no masks works """
"""Test that alignment of images with no masks works"""
reference = camera()
image = ndi.shift(camera(), shift=(-7, 12))
aligned = align(image, reference=reference)
Expand All @@ -79,7 +79,7 @@ def test_align_no_mask():


def test_align_with_mask():
""" Test that alignment of images with no masks works """
"""Test that alignment of images with no masks works"""
reference = camera()
image = ndi.shift(camera(), shift=(-7, 12))

Expand All @@ -92,7 +92,7 @@ def test_align_with_mask():


def test_itrack_peak_trivial():
""" Test that shift is identically zero for images that are identical """
"""Test that shift is identically zero for images that are identical"""
# Array prototype is just zeros
# with a 'peak' in the center
prototype = np.zeros(shape=(17, 17))
Expand All @@ -105,7 +105,7 @@ def test_itrack_peak_trivial():


def test_itrack_peak_length():
""" Test that shifts yielded by itrack_peak are as numerous as the number of input pictures """
"""Test that shifts yielded by itrack_peak are as numerous as the number of input pictures"""
images = [np.random.random(size=(4, 4)) for _ in range(20)]
shifts = list(itrack_peak(images, row_slice=np.s_[:], col_slice=np.s_[:]))

Expand Down
2 changes: 1 addition & 1 deletion skued/image/tests/test_calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_powder_calq_simulation_3_peaks():


def test_detector_scattvectors_center():
""" Test that the placement of the center is working as intended. """
"""Test that the placement of the center is working as intended."""
qx, qy, qz = detector_scattvectors(
keV=200,
camera_length=1,
Expand Down
8 changes: 4 additions & 4 deletions skued/image/tests/test_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def diff_pattern_sc(center):
""" Simulate a single-crystal diffraction pattern """
"""Simulate a single-crystal diffraction pattern"""
r, c = center

cryst = Crystal.from_database("BaTiO3_cubic")
Expand All @@ -34,7 +34,7 @@ def diff_pattern_sc(center):


def test_autocenter_trivial():
""" Test that autocenter() finds the center of perfect gaussian at (0,0) """
"""Test that autocenter() finds the center of perfect gaussian at (0,0)"""
im = np.zeros(shape=(256, 256), dtype=float)
center = np.asarray(im.shape) / 2
rows, cols = np.indices(im.shape)
Expand All @@ -44,7 +44,7 @@ def test_autocenter_trivial():


def test_autocenter_no_side_effects():
""" Test that autocenter() does not modify the inputs """
"""Test that autocenter() does not modify the inputs"""
im = np.random.random(size=(256, 256))
mask = np.ones_like(im, dtype=bool)

Expand All @@ -58,7 +58,7 @@ def test_autocenter_no_side_effects():
@pytest.mark.parametrize("rc", range(-10, 10, 2))
@pytest.mark.parametrize("cc", range(-10, 10, 2))
def test_autocenter_gaussian_shifted(rc, cc):
""" Test that autocenter() finds the center of a shifted gaussian """
"""Test that autocenter() finds the center of a shifted gaussian"""
im = np.zeros(shape=(128, 128), dtype=float)
rows, cols = np.indices(im.shape)
center = np.array([64 + rc, 64 + cc])
Expand Down
4 changes: 2 additions & 2 deletions skued/image/tests/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


def diff_pattern_sc():
""" Simulate a single-crystal diffraction pattern """
"""Simulate a single-crystal diffraction pattern"""
cryst = Crystal.from_database("C")
rr, cc = np.indices((DIFF_PATTERN_SIZE, DIFF_PATTERN_SIZE))
rr -= rr.shape[1] // 2
Expand All @@ -32,7 +32,7 @@ def diff_pattern_sc():


def test_bragg_peaks():
""" Test that the `bragg_peaks` function finds all Bragg peaks. """
"""Test that the `bragg_peaks` function finds all Bragg peaks."""
kx, ky, I, cryst = diff_pattern_sc()
kk = np.sqrt(kx ** 2 + ky ** 2)

Expand Down
Loading

0 comments on commit b0a9128

Please sign in to comment.