From 995fee46f53fbb32b709395cdc87ad27f2864151 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Wed, 8 May 2024 09:56:04 -0500 Subject: [PATCH 1/3] Documentation: Remove empty examples --- doc/user_guide/open_datasets_workflows.rst | 2 +- examples/plotting/README.rst | 3 --- examples/plotting/making_a_gif.py | 8 -------- examples/processing/calibrating.py | 22 ---------------------- 4 files changed, 1 insertion(+), 34 deletions(-) delete mode 100644 examples/plotting/README.rst delete mode 100644 examples/plotting/making_a_gif.py delete mode 100644 examples/processing/calibrating.py diff --git a/doc/user_guide/open_datasets_workflows.rst b/doc/user_guide/open_datasets_workflows.rst index c14a36e67..15d226c2b 100644 --- a/doc/user_guide/open_datasets_workflows.rst +++ b/doc/user_guide/open_datasets_workflows.rst @@ -1,4 +1,4 @@ -=========================== +z=========================== Open datasets and workflows =========================== diff --git a/examples/plotting/README.rst b/examples/plotting/README.rst deleted file mode 100644 index 65308cd96..000000000 --- a/examples/plotting/README.rst +++ /dev/null @@ -1,3 +0,0 @@ -Plotting -=============== -Below is a gallery of examples on how to make nice plots with Matplotlib from hyperspy/ pyxem signals. \ No newline at end of file diff --git a/examples/plotting/making_a_gif.py b/examples/plotting/making_a_gif.py deleted file mode 100644 index 0835907e7..000000000 --- a/examples/plotting/making_a_gif.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -============ -Making a Gif -============ - -This example shows how to create a gif from a series of images. Here we use the "hyperspy" idea of a -signal and navigation axes to create a series of images -""" diff --git a/examples/processing/calibrating.py b/examples/processing/calibrating.py deleted file mode 100644 index 1e729b9a9..000000000 --- a/examples/processing/calibrating.py +++ /dev/null @@ -1,22 +0,0 @@ -""" -Calibrating a dataset -===================== - -There are two different ways to calibrate a dataset in pyxem and depending on what -kind of data you have you may need to use each of these methods. - -The first method is to basically ignore the Ewald sphere effects. This is the -easiest method but not the most correct. For a 200+ keV microscope the assumption -that the Ewald sphere is flat is not a bad one. For lower energy microscopes -this assumption is not as great but still not terrible. For x-ray data with longer -wavelengths this assumption starts to break down. -""" - -# import pyxem as pxm - -# al = pxm.data.al_peaks() - -# determine the pixel size from one peak - -# al.calibrate(scale=0.1, center=None, units="k_nm^-1") -# al.plot() From 8adc389d94eb7c4604d8b2d231176a8b6e229e31 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Wed, 8 May 2024 10:02:00 -0500 Subject: [PATCH 2/3] Refactor: calibrate-->calibration to not interfere with hyperspy namespace --- examples/processing/azimuthal_integration.py | 8 +++---- examples/processing/background_subtraction.py | 2 +- examples/standards/pixel_coodinates.py | 18 +++++++-------- .../creating_a_segmented_detector.py | 6 ++--- .../interactive_virtual_images.py | 2 +- .../virtual_imaging/other_virtual_imaging.py | 2 +- pyxem/generators/calibration_generator.py | 2 +- pyxem/signals/diffraction2d.py | 22 ++++++++++--------- pyxem/tests/signals/test_diffraction2d.py | 18 +++++++-------- pyxem/tests/utils/test_calibration_utils.py | 10 ++++----- .../tests/utils/test_ransac_ellipse_tools.py | 4 ++-- pyxem/utils/calibration.py | 10 +++++---- 12 files changed, 54 insertions(+), 50 deletions(-) diff --git a/examples/processing/azimuthal_integration.py b/examples/processing/azimuthal_integration.py index 3687a56f3..7877c9abd 100644 --- a/examples/processing/azimuthal_integration.py +++ b/examples/processing/azimuthal_integration.py @@ -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) @@ -49,7 +49,7 @@ 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, @@ -57,7 +57,7 @@ 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, @@ -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() diff --git a/examples/processing/background_subtraction.py b/examples/processing/background_subtraction.py index 2548bcc14..502a9afeb 100644 --- a/examples/processing/background_subtraction.py +++ b/examples/processing/background_subtraction.py @@ -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 diff --git a/examples/standards/pixel_coodinates.py b/examples/standards/pixel_coodinates.py index 0abdab543..b665f442b 100644 --- a/examples/standards/pixel_coodinates.py +++ b/examples/standards/pixel_coodinates.py @@ -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) # %% @@ -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) # %% @@ -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) diff --git a/examples/virtual_imaging/creating_a_segmented_detector.py b/examples/virtual_imaging/creating_a_segmented_detector.py index 23788ccf9..ab40cf97b 100644 --- a/examples/virtual_imaging/creating_a_segmented_detector.py +++ b/examples/virtual_imaging/creating_a_segmented_detector.py @@ -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 @@ -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() diff --git a/examples/virtual_imaging/interactive_virtual_images.py b/examples/virtual_imaging/interactive_virtual_images.py index ea6f0cc5b..032fef8bf 100644 --- a/examples/virtual_imaging/interactive_virtual_images.py +++ b/examples/virtual_imaging/interactive_virtual_images.py @@ -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) diff --git a/examples/virtual_imaging/other_virtual_imaging.py b/examples/virtual_imaging/other_virtual_imaging.py index db742aa83..7aeda5149 100644 --- a/examples/virtual_imaging/other_virtual_imaging.py +++ b/examples/virtual_imaging/other_virtual_imaging.py @@ -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)) diff --git a/pyxem/generators/calibration_generator.py b/pyxem/generators/calibration_generator.py index 010ff9db7..3b5129e8a 100644 --- a/pyxem/generators/calibration_generator.py +++ b/pyxem/generators/calibration_generator.py @@ -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 diff --git a/pyxem/signals/diffraction2d.py b/pyxem/signals/diffraction2d.py index d70cba91e..54e793bad 100644 --- a/pyxem/signals/diffraction2d.py +++ b/pyxem/signals/diffraction2d.py @@ -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 @@ -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 @@ -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, @@ -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 ( @@ -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, diff --git a/pyxem/tests/signals/test_diffraction2d.py b/pyxem/tests/signals/test_diffraction2d.py index 893ee9f8b..ed5d5dd60 100644 --- a/pyxem/tests/signals/test_diffraction2d.py +++ b/pyxem/tests/signals/test_diffraction2d.py @@ -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", @@ -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", @@ -335,7 +335,7 @@ 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 @@ -343,7 +343,7 @@ 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 @@ -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): @@ -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,) @@ -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 ) diff --git a/pyxem/tests/utils/test_calibration_utils.py b/pyxem/tests/utils/test_calibration_utils.py index 7dacdcc45..ad9f84a03 100644 --- a/pyxem/tests/utils/test_calibration_utils.py +++ b/pyxem/tests/utils/test_calibration_utils.py @@ -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 @@ -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 @@ -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 diff --git a/pyxem/tests/utils/test_ransac_ellipse_tools.py b/pyxem/tests/utils/test_ransac_ellipse_tools.py index 2d0c6780f..e230d8bb4 100644 --- a/pyxem/tests/utils/test_ransac_ellipse_tools.py +++ b/pyxem/tests/utils/test_ransac_ellipse_tools.py @@ -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) @@ -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) diff --git a/pyxem/utils/calibration.py b/pyxem/utils/calibration.py index 0f9fc57f8..11350b72f 100644 --- a/pyxem/utils/calibration.py +++ b/pyxem/utils/calibration.py @@ -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 @@ -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: @@ -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, @@ -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, From 7a7c7997998d749f0500289ddc17be57abadb300 Mon Sep 17 00:00:00 2001 From: Carter Francis Date: Wed, 8 May 2024 10:36:35 -0500 Subject: [PATCH 3/3] Documentation: Fix broken link --- doc/bibliography.bib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/bibliography.bib b/doc/bibliography.bib index 79b06c93d..3e247826b 100644 --- a/doc/bibliography.bib +++ b/doc/bibliography.bib @@ -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} }