Skip to content

Commit

Permalink
Merge pull request #1071 from CSSFrancis/clean-up
Browse files Browse the repository at this point in the history
Clean up for 0.18.0
  • Loading branch information
CSSFrancis committed May 9, 2024
2 parents c4e73b7 + 7a7c799 commit f925337
Show file tree
Hide file tree
Showing 17 changed files with 56 additions and 85 deletions.
2 changes: 1 addition & 1 deletion doc/bibliography.bib
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ @article{Kottler:07
pages = {1175--1181},
publisher = {OSA},
title = {{A two-directional approach for grating based differential phase contrast imaging using hard x-rays}},
url = {http://www.opticsexpress.org/abstract.cfm?URI=oe-15-3-1175},
url = {https://doi.org/10.1364/OE.15.001175},
volume = {15},
year = {2007}
}
Expand Down
2 changes: 1 addition & 1 deletion doc/user_guide/open_datasets_workflows.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
===========================
z===========================
Open datasets and workflows
===========================

Expand Down
3 changes: 0 additions & 3 deletions examples/plotting/README.rst

This file was deleted.

8 changes: 0 additions & 8 deletions examples/plotting/making_a_gif.py

This file was deleted.

8 changes: 4 additions & 4 deletions examples/processing/azimuthal_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import numpy as np

nano_crystals = pxm.data.mgo_nanocrystals(lazy=True)
nano_crystals.calibrate(
nano_crystals.calibration(
center=None
) # set the center to None to use center of the diffraction patterns
nano_crystals1d = nano_crystals.get_azimuthal_integral1d(npt=100, inplace=False)
Expand Down Expand Up @@ -49,15 +49,15 @@
We only show the 1D case here, but the same applies for the 2D case as well!
"""

nano_crystals.calibrate.detector(
nano_crystals.calibration.detector(
pixel_size=0.001,
detector_distance=0.125,
beam_energy=200,
center=None,
units="k_A^-1",
) # set the center= None to use the center of the diffraction patterns
nano_crystals1d_200 = nano_crystals.get_azimuthal_integral1d(npt=100, inplace=False)
nano_crystals.calibrate.detector(
nano_crystals.calibration.detector(
pixel_size=0.001,
detector_distance=0.075,
beam_energy=80,
Expand All @@ -84,7 +84,7 @@
affine = np.array(
[[0.9, 0.1, 0], [0.1, 0.9, 0], [0, 0, 1]]
) # Just a random affine transformation for illustration
nano_crystals.calibrate(mask=mask, affine=affine)
nano_crystals.calibration(mask=mask, affine=affine)
nano_crystals.get_azimuthal_integral2d(
npt=100, npt_azim=360, inplace=False
).sum().plot()
Expand Down
2 changes: 1 addition & 1 deletion examples/processing/background_subtraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
# Set the center of the diffraction pattern to its default,
# i.e. the middle of the image

s.calibrate.center = None
s.calibration.center = None

# %%
# Transform to polar coordinates
Expand Down
22 changes: 0 additions & 22 deletions examples/processing/calibrating.py

This file was deleted.

18 changes: 9 additions & 9 deletions examples/standards/pixel_coodinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@


s = pxm.signals.Diffraction2D(disk((10)))
s.calibrate.center = None
print(s.calibrate.center)
s.calibration.center = None
print(s.calibration.center)

# %%

Expand All @@ -27,13 +27,13 @@

# From the plot above you can see that hyperspy automatically sets the axes ticks to be centered
# on each pixel. This means that for a 21x21 pixel image, the center is at (-10, -10) in pixel coordinates.
# if we change the scale using the calibrate function it will automatically adjust the center. Here it is
# if we change the scale using the calibration function it will automatically adjust the center. Here it is
# now (-1, -1)

s.calibrate.scale = 0.1
s.calibrate.units = "nm$^{-1}$"
s.calibration.scale = 0.1
s.calibration.units = "nm$^{-1}$"
s.plot(axes_ticks=True)
print(s.calibrate.center)
print(s.calibration.center)


# %%
Expand All @@ -54,9 +54,9 @@
# Now consider the case where we have non-linear axes. In this case the center is still (10,10)
# but things are streatched based on the effects of the Ewald Sphere.

s.calibrate.beam_energy = 200
s.calibrate.detector(pixel_size=0.1, detector_distance=3)
print(s.calibrate.center)
s.calibration.beam_energy = 200
s.calibration.detector(pixel_size=0.1, detector_distance=3)
print(s.calibration.center)
s.plot()

az = s.get_azimuthal_integral2d(npt=30)
Expand Down
6 changes: 3 additions & 3 deletions examples/virtual_imaging/creating_a_segmented_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@


dp = pxm.data.tilt_boundary_data()
dp.calibrate.center = None # Center the diffraction patterns
dp.calibrate.scale = 0.1 # Scale the diffraction patterns in reciprocal space
dp.calibration.center = None # Center the diffraction patterns
dp.calibration.scale = 0.1 # Scale the diffraction patterns in reciprocal space


# Visualizing the virtual detector
Expand All @@ -26,7 +26,7 @@
npt_azim=8,
radial_range=(1, 5),
azimuthal_range=(-np.pi, np.pi),
affine=dp.calibrate.affine,
affine=dp.calibration.affine,
)[:, :, ::-1]
poly = hs.plot.markers.Polygons(verts=cp, edgecolor="w", facecolor="none")
dp.plot()
Expand Down
2 changes: 1 addition & 1 deletion examples/virtual_imaging/interactive_virtual_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Also we can do the same with a 1D signal
s = pxm.data.dummy_data.get_cbed_signal()
s.calibrate(center=None)
s.calibration(center=None)
s1d = s.get_azimuthal_integral1d(npt=100, mean=True)
span = hs.roi.SpanROI(left=15.5, right=20)
s1d.plot_integrated_intensity(span)
Expand Down
2 changes: 1 addition & 1 deletion examples/virtual_imaging/other_virtual_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
radius=4, include_labels=True
)
c = pxm.data.dummy_data.get_cbed_signal()
c.calibrate(center=None)
c.calibration(center=None)
c.plot()
for r in rois:
r.add_widget(c, axes=(2, 3))
Expand Down
2 changes: 1 addition & 1 deletion pyxem/generators/calibration_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class CalibrationGenerator:
@deprecated(
since="0.18.0",
removal="1.0.0",
alternative="pyxem.signals.Diffraction2D.calibrate",
alternative="pyxem.signals.Diffraction2D.calibration",
)
def __init__(
self, diffraction_pattern=None, grating_image=None, calibration_standard=None
Expand Down
22 changes: 12 additions & 10 deletions pyxem/signals/diffraction2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def __init__(self, *args, **kwargs):
Passed to the __init__ of Signal2D
"""
super().__init__(*args, **kwargs)
self.calibrate = Calibration(self)
self.calibration = Calibration(self)

def apply_affine_transformation(
self, D, order=1, keep_dtype=False, inplace=True, *args, **kwargs
Expand Down Expand Up @@ -1781,7 +1781,7 @@ def ai(self):
@deprecated(
since="0.18",
removal="1.0.0",
alternative="pyxem.signals.diffraction2d.calibrate",
alternative="pyxem.signals.diffraction2d.calibration",
)
def set_ai(
self, center=None, wavelength=None, affine=None, radial_range=None, **kwargs
Expand Down Expand Up @@ -1916,11 +1916,11 @@ def get_azimuthal_integral1d(
if not usepyfai:
# get_slices1d should be sped up in the future by
# getting rid of shapely and using numba on the for loop
indexes, facts, factor_slices, radial_range = self.calibrate.get_slices1d(
indexes, facts, factor_slices, radial_range = self.calibration.get_slices1d(
npt, radial_range=radial_range
)
if mask is None:
mask = self.calibrate.mask
mask = self.calibration.mask
integration = self.map(
_slice_radial_integrate1d,
indexes=indexes,
Expand Down Expand Up @@ -2064,11 +2064,13 @@ def get_azimuthal_integral2d(
if not usepyfai:
# get_slices2d should be sped up in the future by
# getting rid of shapely and using numba on the for loop
slices, factors, factors_slice, radial_range = self.calibrate.get_slices2d(
npt,
npt_azim,
radial_range=radial_range,
azimuthal_range=azimuth_range,
slices, factors, factors_slice, radial_range = (
self.calibration.get_slices2d(
npt,
npt_azim,
radial_range=radial_range,
azimuthal_range=azimuth_range,
)
)
if self._gpu and CUPY_INSTALLED: # pragma: no cover
from pyxem.utils._azimuthal_integrations import (
Expand All @@ -2093,7 +2095,7 @@ def get_azimuthal_integral2d(
)
else:
if mask is None:
mask = self.calibrate.mask
mask = self.calibration.mask
integration = self.map(
_slice_radial_integrate,
slices=slices,
Expand Down
18 changes: 9 additions & 9 deletions pyxem/tests/signals/test_diffraction2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def test_1d_azimuthal_integral_2th_units(self, ones, unit):
np.testing.assert_array_equal(az.data[0:8], np.ones(8))

def test_1d_azimuthal_integral_pyxem(self, ones):
ones.calibrate.center = None
ones.calibrate.scale = 0.2
ones.calibration.center = None
ones.calibration.scale = 0.2
az = ones.get_azimuthal_integral1d(
npt=10,
method="splitpixel_pyxem",
Expand All @@ -137,8 +137,8 @@ def test_1d_azimuthal_integral_pyxem(self, ones):
assert az is None

def test_1d_azimuthal_integral_pyxem(self, ones):
ones.calibrate.center = None
ones.calibrate.scale = 0.2
ones.calibration.center = None
ones.calibration.scale = 0.2
az = ones.get_azimuthal_integral1d(
npt=10,
method="splitpixel_pyxem",
Expand Down Expand Up @@ -335,15 +335,15 @@ class TestVariance:
@pytest.fixture
def ones(self):
ones_diff = Diffraction2D(data=np.ones(shape=(10, 10, 10, 10)))
ones_diff.calibrate(scale=0.1, center=None)
ones_diff.calibration(scale=0.1, center=None)
return ones_diff

@pytest.fixture
def ones_zeros(self):
data = np.ones(shape=(10, 10, 10, 10))
data[0:10:2, :, :, :] = 2
ones_diff = Diffraction2D(data=data)
ones_diff.calibrate(scale=0.1, center=None)
ones_diff.calibration(scale=0.1, center=None)
return ones_diff

@pytest.fixture
Expand All @@ -355,7 +355,7 @@ def bulls_eye_noisy(self):
rng = default_rng(seed=1)
data = rng.poisson(lam=data)
ones_diff = Diffraction2D(data=data)
ones_diff.calibrate(scale=0.1, center=None)
ones_diff.calibration(scale=0.1, center=None)
return ones_diff

def test_FEM_Omega(self, ones, ones_zeros):
Expand Down Expand Up @@ -579,7 +579,7 @@ def test_2d_azimuthal_integral_sum(self, ones):
)

def test_internal_azimuthal_integration(self, ring):
ring.calibrate(scale=1)
ring.calibration(scale=1)
az = ring.get_azimuthal_integral2d(npt=40, npt_azim=100, radial_range=(0, 40))
ring_sum = np.sum(az.data, axis=1)
assert ring_sum.shape == (40,)
Expand Down Expand Up @@ -653,7 +653,7 @@ def test_internal_azimuthal_integration_data_range(self, corner, shape):
def test_azimuthal_integration_range(
self, arange, azimuthal_range, expected_output
):
arange.calibrate.center = None # set center
arange.calibration.center = None # set center
quadrant = arange.get_azimuthal_integral2d(
npt=10, npt_azim=10, azimuth_range=azimuthal_range, mean=True
)
Expand Down
10 changes: 5 additions & 5 deletions pyxem/tests/utils/test_calibration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def test_get_slices2d(self, calibration):

def test_get_slices_and_factors(self):
s = Diffraction2D(np.zeros((100, 100)))
s.calibrate(scale=0.1, center=None)
slices, factors, factor_slices = s.calibrate._get_slices_and_factors(
s.calibration(scale=0.1, center=None)
slices, factors, factor_slices = s.calibration._get_slices_and_factors(
npt=100, npt_azim=360, radial_range=(0, 4), azimuthal_range=(0, 2 * np.pi)
)
# check that the number of pixels for each radial slice is the same
Expand All @@ -147,7 +147,7 @@ def test_get_slices_and_factors(self):
# n = npt_azim
all_sum = np.sum(sum_factors)
assert np.allclose(all_sum, 3.1415 * 40**2, atol=1)
slices, factors, factor_slices = s.calibrate._get_slices_and_factors(
slices, factors, factor_slices = s.calibration._get_slices_and_factors(
npt=100, npt_azim=360, radial_range=(0, 15), azimuthal_range=(0, 2 * np.pi)
)
# check that the number of pixels for each radial slice is the same
Expand All @@ -161,8 +161,8 @@ def test_get_slices_and_factors(self):

def test_get_slices_and_factors1d(self):
s = Diffraction2D(np.zeros((100, 100)))
s.calibrate(scale=0.1, center=None)
slices, factors, factor_slices, _ = s.calibrate.get_slices1d(
s.calibration(scale=0.1, center=None)
slices, factors, factor_slices, _ = s.calibration.get_slices1d(
100, radial_range=(0, 4)
)
# check that the number of pixels for each radial slice is the same
Expand Down
4 changes: 2 additions & 2 deletions pyxem/tests/utils/test_ransac_ellipse_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def test_determine_ellipse_rotated(self, execution_number):
center, affine = ret.determine_ellipse(
s, mask=mask, use_ransac=False, num_points=2000
)
s.calibrate(
s.calibration(
center=center, affine=affine, scale=0.1, units="k_nm^-1", beam_energy=200
)
s_az = s.get_azimuthal_integral2d(npt=100)
Expand All @@ -949,7 +949,7 @@ def test_determine_ellipse_ring(self, rot):
mask = np.zeros_like(s.data, dtype=bool)
mask[100 - 20 : 100 + 20, 100 - 20 : 100 + 20] = True
center, affine = ret.determine_ellipse(s, mask=mask, use_ransac=False)
s.calibrate(
s.calibration(
center=center, affine=affine, scale=0.1, units="k_nm^-1", beam_energy=200
)
s_az = s.get_azimuthal_integral2d(npt=100)
Expand Down
10 changes: 6 additions & 4 deletions pyxem/utils/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def detector(
This sets the signal axes to be a `~hyperspy.axes.DataAxis` instead of a UniformAxis to
account for the Ewald sphere curvature. This is the most accurate method of calibration
but requires a known beam energy/wavelength and detector distance or to calibrate the
but requires a known beam energy/wavelength and detector distance or to calibration the
experimental configuration with a known standard.
Parameters
Expand Down Expand Up @@ -493,7 +493,7 @@ def center(self, center=None):
if not self.flat_ewald:
raise ValueError(
"To set the center of a curved ewald sphere "
"use the s.calibrate.detector method"
"use the s.calibration.detector method"
)
if center is None:
for ax in self.signal.axes_manager.signal_axes:
Expand Down Expand Up @@ -533,7 +533,7 @@ def to_pyfai(self):
)
if pixel_size is None or dist is None:
raise ValueError(
"The dector must be first initialized with the s.calibrate.detector method"
"The dector must be first initialized with the s.calibration.detector method"
)
detector = Detector(
pixel1=pixel_size,
Expand All @@ -552,7 +552,9 @@ def to_pyfai(self):


@deprecated(
since="0.18.0", removal="1.0.0", alternative="pyxem.signals.Diffraction2D.calibrate"
since="0.18.0",
removal="1.0.0",
alternative="pyxem.signals.Diffraction2D.calibration",
)
def find_diffraction_calibration(
patterns,
Expand Down

0 comments on commit f925337

Please sign in to comment.