Skip to content

Commit

Permalink
Rename to crop_signal
Browse files Browse the repository at this point in the history
  • Loading branch information
ericpre committed Sep 28, 2023
1 parent 40fb434 commit cc026c5
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
26 changes: 13 additions & 13 deletions doc/user_guide/signal1d.rst
Expand Up @@ -12,32 +12,32 @@ signals in the Signal1D class.
Cropping
--------

The :py:meth:`~._signals.signal1d.Signal1D.crop_signal1D` crops the
The :py:meth:`~._signals.signal1d.Signal1D.crop_signal` crops the
spectral energy range *in-place*. If no parameter is passed, a user interface
appears in which to crop the one dimensional signal. For example:

.. code-block:: python
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
s.crop_signal1D(5, 15) # s is cropped in place
>>> s = hs.datasets.example_signals.EDS_TEM_Spectrum()
>>> s.crop_signal(5, 15) # s is cropped in place
Additionally, cropping in HyperSpy can be performed using the :ref:`Signal
indexing <signal.indexing>` syntax. For example, the following crops a spectrum
to the 5 keV-15 keV region:

.. code-block:: python
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
sc = s.isig[5.:15.] # s is not cropped, sc is a "cropped view" of s
>>> s = hs.datasets.example_signals.EDS_TEM_Spectrum()
>>> sc = s.isig[5.:15.] # s is not cropped, sc is a "cropped view" of s
It is possible to crop interactively using :ref:`roi-label`. For example:

.. code-block:: python
s = hs.datasets.example_signals.EDS_TEM_Spectrum()
roi = hs.roi.SpanROI(left=5, right=15)
s.plot()
sc = roi.interactive(s)
>>> s = hs.datasets.example_signals.EDS_TEM_Spectrum()
>>> roi = hs.roi.SpanROI(left=5, right=15)
>>> s.plot()
>>> sc = roi.interactive(s)
.. _interactive_signal1d_cropping_image:

Expand All @@ -60,7 +60,7 @@ The :py:meth:`~._signals.signal1d.Signal1D.remove_background` method provides
background removal capabilities through both a CLI and a GUI. The GUI displays
an interactive preview of the remainder after background subtraction. Currently,
the following background types are supported: Doniach, Exponential, Gaussian,
Lorentzian, Polynomial, Power law (default), Offset, Skew normal, Split Voigt
Lorentzian, Polynomial, Power law (default), Offset, Skew normal, Split Voigt
and Voigt. By default, the background parameters are estimated using analytical
approximations (keyword argument ``fast=True``). The fast option is not accurate
for most background types - except Gaussian, Offset and Power law -
Expand All @@ -72,8 +72,8 @@ Example of usage:

.. code-block:: python
s = hs.datasets.artificial_data.get_core_loss_eels_signal(add_powerlaw=True)
s.remove_background(zero_fill=False)
>>> s = hs.datasets.artificial_data.get_core_loss_eels_signal(add_powerlaw=True)
>>> s.remove_background(zero_fill=False)
.. figure:: images/signal_1d_remove_background.png
:align: center
Expand Down Expand Up @@ -177,7 +177,7 @@ For asymmetric peaks, `fitted functions <model.fitting>` may not provide
an accurate description of the peak, in particular the peak width. The function
:py:meth:`~._signals.signal1d.Signal1D.estimate_peak_width`
determines the width of a peak at a certain fraction of its maximum value.


Other methods
-------------
Expand Down
4 changes: 2 additions & 2 deletions doc/user_guide/signal2d.rst
Expand Up @@ -69,13 +69,13 @@ the scheduler of the :ref:`dask backend <dask_backends>`.
Cropping a Signal2D
-------------------

The :py:meth:`~._signals.signal2d.Signal2D.crop_signal2D` method crops the
The :py:meth:`~._signals.signal2d.Signal2D.crop_signal` method crops the
image *in-place* e.g.:

.. code-block:: python
>>> im = hs.datasets.example_signals.object_hologram()
>>> im.crop_signal2D(left=120, top=300, bottom=560) # im is cropped in-place
>>> im.crop_signal(left=120, top=300, bottom=560) # im is cropped in-place
Cropping in HyperSpy is performed using the :ref:`Signal indexing
Expand Down
4 changes: 2 additions & 2 deletions hyperspy/_signals/signal1d.py
Expand Up @@ -1215,8 +1215,8 @@ def remove_background(
remove_background.__doc__ %= (SHOW_PROGRESSBAR_ARG, DISPLAY_DT, TOOLKIT_DT)

@interactive_range_selector
def crop_signal1D(self, left_value=None, right_value=None,):
"""Crop in place the spectral dimension.
def crop_signal(self, left_value=None, right_value=None,):
"""Crop in place in the signal space.
Parameters
----------
Expand Down
9 changes: 5 additions & 4 deletions hyperspy/_signals/signal2d.py
Expand Up @@ -764,7 +764,7 @@ def align2D(
int(np.floor(_min1)) if _min1 < 0 else None,
int(np.ceil(_max1)) if _max1 > 0 else 0,
)
self.crop_signal2D(top, bottom, left, right)
self.crop_signal(top, bottom, left, right)
shifts = -shifts

self.events.data_changed.trigger(obj=self)
Expand Down Expand Up @@ -863,9 +863,10 @@ def _get_signal2d_scale(self, x0, y0, x1, y1, length):
scale = length / old_length
return scale

def crop_signal2D(self, top=None, bottom=None,
left=None, right=None, convert_units=False):
"""Crops an image in place.
def crop_signal(self, top=None, bottom=None, left=None, right=None,
convert_units=False):
"""
Crops in signal space and in place.
Parameters
----------
Expand Down
6 changes: 3 additions & 3 deletions hyperspy/tests/signals/test_2D.py
Expand Up @@ -211,7 +211,7 @@ def test_crop_image_unit_convertion_signal2D(self):
s.axes_manager[1].name = "y"
s.axes_manager[1].scale = 0.01
s.axes_manager[1].units = "µm"
s.crop_signal2D(0, 0.5, 0.0, 0.5)
s.crop_signal(0, 0.5, 0.0, 0.5)
np.testing.assert_almost_equal(s.axes_manager[0].scale, 0.01)
np.testing.assert_almost_equal(s.axes_manager[1].scale, 0.01)
assert s.axes_manager[0].units == "µm"
Expand All @@ -227,7 +227,7 @@ def test_crop_image_unit_convertion_signal2D(self):
s.axes_manager[1].name = "y"
s.axes_manager[1].scale = 0.01
s.axes_manager[1].units = "µm"
s.crop_signal2D(0, 0.5, 0.0, 0.5, convert_units=True)
s.crop_signal(0, 0.5, 0.0, 0.5, convert_units=True)
np.testing.assert_almost_equal(s.axes_manager[0].scale, 10.0)
np.testing.assert_almost_equal(s.axes_manager[1].scale, 10.0)
assert s.axes_manager[0].units == "nm"
Expand All @@ -243,7 +243,7 @@ def test_crop_image_unit_convertion_signal2D(self):
s.axes_manager[1].name = "y"
s.axes_manager[1].scale = 0.01
s.axes_manager[1].units = "µm"
s.crop_signal2D(0, 5.0, 0.0, 5.0, convert_units=True)
s.crop_signal(0, 5.0, 0.0, 5.0, convert_units=True)
np.testing.assert_almost_equal(s.axes_manager[0].scale, 0.01)
np.testing.assert_almost_equal(s.axes_manager[1].scale, 0.01)
assert s.axes_manager[0].units == "µm"
Expand Down
2 changes: 1 addition & 1 deletion upcoming_changes/3197.api.rst
@@ -1 +1 @@
Renamed ``Signal2D.crop_image`` to :meth:`~.api.signals.Signal2D.crop_signal2D`
Renamed ``Signal2D.crop_image`` to :meth:`~.api.signals.Signal2D.crop_signal`

0 comments on commit cc026c5

Please sign in to comment.