Skip to content

Commit

Permalink
implement suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaehne committed Oct 21, 2024
1 parent fe8345b commit ecf514f
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 40 deletions.
2 changes: 1 addition & 1 deletion conda_environment_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ dependencies:
- pytest-cov
- pytest-faulthandler
- pytest-xdist
- hyperspy[speed]
- hyperspy-base
- setuptools-scm

3 changes: 1 addition & 2 deletions doc/user_guide/fitting_luminescence.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Signal variance (noise)
=======================

TODO: Documentation on variance handling in the context of fitting,
in particular using :external:meth:`estimate_poissonian_noise_variance()
<hyperspy.api.signals.BaseSignal.estimate_poissonian_noise_variance>`
in particular using :external:meth:`~hyperspy.api.signals.BaseSignal.estimate_poissonian_noise_variance`

For a detailed discussion, see [Tappy]_
17 changes: 8 additions & 9 deletions doc/user_guide/signal_axis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ occurs in particular when converting a wavelength scale to energy (eV) or
wavenumbers (e.g. for Raman shifts).

The conversion of the signal axis can be performed using the functions
:meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_eV`,
:meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_invcm` and
:meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_raman_shift`
(alias for :meth:`~.signals.luminescence_spectrum.LumiSpectrum.to_invcm_relative`).
:meth:`~.signals.common_luminescence.CommonLumi.to_eV`,
:meth:`~.signals.common_luminescence.CommonLumi.to_invcm` and
:meth:`~.signals.common_luminescence.CommonLumi.to_raman_shift`
(alias for :meth:`~.signals.common_luminescence.CommonLumi.to_invcm_relative`).
If the unit of the signal axis is set, the functions can handle wavelengths in
either nm or µm.

Expand Down Expand Up @@ -123,7 +123,7 @@ renormalization is automatically performed by LumiSpy if ``jacobian=True``.
In particular, homoscedastic (constant) noise will consequently become
heteroscedastic (changing as a function of the signal axis vector). Therefore,
if the ``metadata.Signal.Noise_properties.variance`` attribute is a constant,
it is converted into a :external:class:` BaseSignal <hyperspy.api.signals.BaseSignal>`
it is converted into a :external:class:`hyperspy.api.signals.BaseSignal`
object before the transformation.

See the section on :ref:`fitting_variance` for more general information on data variance
Expand All @@ -136,8 +136,7 @@ in the context of model fitting and the HyperSpy documentation on `
``metadata.Signal.Noise_properties.Variance_linear_model`` are reset to
their default values (``gain_factor=1``, ``gain_offset=0`` and ``correlation_factor=1``).
Should these values deviate from the defaults, make sure to run
:external:meth:`estimate_poissonian_noise_variance()
<hyperspy.api.signals.BaseSignal.estimate_poissonian_noise_variance>`
:external:meth:`~hyperspy.api.signals.BaseSignal.estimate_poissonian_noise_variance`
prior to the transformation.


Expand All @@ -147,8 +146,8 @@ Interpolation to uniform axes
=============================

As a number of HyperSpy tools are not supporting non-uniform axes, e.g. the
:meth:`rebin() <hyperspy.api.signals.BaseSignal.rebin>` function, the HyperSpy function
:meth:`interpolate_on_axis() <hyperspy.api.signals.BaseSignal.interpolate_on_axis>`
:meth:`~hyperspy.api.signals.BaseSignal.rebin` function, the HyperSpy function
:meth:`~hyperspy.api.signals.BaseSignal.interpolate_on_axis`
provides a possibility to convert a signal with a non-uniform axis to one with
a uniform axis. This function takes the argument ``"uniform"``, which will create
a signal with the same number of data points, but a uniform axes spacing and
Expand Down
34 changes: 17 additions & 17 deletions doc/user_guide/signal_tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Peak identification
HyperSpy provides functions to find the positions of maxima or minima in a
dataset:

- :external:meth:`indexmax() <hyperspy.api.signals.BaseSignal.indexmax>` -
- :external:meth:`~hyperspy.api.signals.BaseSignal.indexmax` -
return the index of the maximum value along a given axis.
- :external:meth:`indexmin() <hyperspy.api.signals.BaseSignal.indexmin>` -
- :external:meth:`~hyperspy.api.signals.BaseSignal.indexmin` -
return the index of the minimum value along a given axis.
- :external:meth:`valuemax() <hyperspy.api.signals.BaseSignal.valuemax>` -
- :external:meth:`~hyperspy.api.signals.BaseSignal.valuemax` -
return the position/coordinates of the maximum value along a given axis in
calibrated units.
- :external:meth:`valuemin() <hyperspy.api.signals.BaseSignal.valuemin>` -
- :external:meth:`~hyperspy.api.signals.BaseSignal.valuemin` -
return the position/coordinates of the minimum value along a given axis in
calibrated units.

Expand All @@ -69,7 +69,7 @@ the operation and return a new signal containing the result.

A much more powerful method to identify peaks is using the **peak finding routine**
based on the downward zero-crossings of the first derivative of a signal:
:external:meth:`find_peaks1D_ohaver() <hyperspy.api.signals.Signal1D.find_peaks1D_ohaver>`.
:external:meth:`~hyperspy.api.signals.Signal1D.find_peaks1D_ohaver`.
This function can find multiple peaks in a dataset and has a number of parameters
for fine-tuning the sensitivity, etc.

Expand All @@ -87,7 +87,7 @@ Peak Width

For asymmetric peaks, :ref:`fitted functions <fitting_luminescence>` may not provide
an accurate description of the peak, in particular the peak width. The function
:external:meth:`estimate_peak_width() <hyperspy.api.signals.Signal1D.estimate_peak_width>`
:external:meth:`~hyperspy.api.signals.Signal1D.estimate_peak_width`
determines the **width of a peak** at a certain fraction of its maximum value. The
default value ``factor=0.5`` returns the full width at half maximum (FWHM).

Expand Down Expand Up @@ -158,23 +158,23 @@ Signal statistics and analytical operations
===========================================

**Standard statistical operations** can be performed on the data or a subset of the
data, notably these include
:external:meth:`max() <hyperspy.api.signals.BaseSignal.max>`,
:external:meth:`min() <hyperspy.api.signals.BaseSignal.min>`,
:external:meth:`sum() <hyperspy.api.signals.BaseSignal.sum>`,
:external:meth:`mean() <hyperspy.api.signals.BaseSignal.mean>`,
:external:meth:`std() <hyperspy.api.signals.BaseSignal.std>`, and
:external:meth:`var() <hyperspy.api.signals.BaseSignal.var>`. Variations of
data using HyperSpy methods, notably these include
:external:meth:`~hyperspy.api.signals.BaseSignal.max`,
:external:meth:`~hyperspy.api.signals.BaseSignal.min`,
:external:meth:`~hyperspy.api.signals.BaseSignal.sum`,
:external:meth:`~hyperspy.api.signals.BaseSignal.mean`,
:external:meth:`~hyperspy.api.signals.BaseSignal.std`, and
:external:meth:`~hyperspy.api.signals.BaseSignal.var`. Variations of
all these functions exist that ignore missing values (NaN) if present, e.g.
:external:meth:`nanmax() <hyperspy.api.signals.BaseSignal.nanmax>`.
:external:meth:`~hyperspy.api.signals.BaseSignal.nanmax`.

**Integration** along a specified signal axis is performed using the function
:external:meth:`integrate1D() <hyperspy.api.signals.BaseSignal.integrate1D()>`.
:external:meth:`~hyperspy.api.signals.BaseSignal.integrate1D()`.

The numerical **derivative** of a signal can be calculated using the function
:external:meth:`derivative() <hyperspy.api.signals.BaseSignal.derivative()>`,
:external:meth:`~hyperspy.api.signals.BaseSignal.derivative()`,
while the *n*-th order **discrete difference** can be calculated using
:external:meth:`diff() <hyperspy.api.signals.BaseSignal.diff()>`.
:external:meth:`~hyperspy.api.signals.BaseSignal.diff()`.

These functions take the ``axis`` keyword to define along which axis to perform
the operation and return a new signal containing the result:
Expand Down
30 changes: 20 additions & 10 deletions doc/user_guide/streak_images.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ wavelength axis can be transformed to e.g. a :ref:`energy_axis`.

.. Note::

For streak images, not all tools available for :class:`Signal2D
<hyperspy.api.signals.Signal2D>` will work. However, in particular
For streak images, not all tools available for :class:`hyperspy.api.signals.Signal2D`
will work. However, in particular
:external+hyperspy:ref:`peak_finding-label`
can be helpful to identify local maxima in the images.

Expand All @@ -27,25 +27,35 @@ assign the correct 1D signal class: Either :class:`~.signals.luminescence_spectr
:class:`~.signals.luminescence_transient.LumiTransient`. Such a reduction of the signal dimensionality
can be done for example by slicing the signal with
:external+hyperspy:ref:`numpy-style indexing <signal.indexing>` or by using
functions such as :external:meth:`sum() <hyperspy.api.signals.BaseSignal.sum>`
and :external:meth:`integrate1D() <hyperspy.api.signals.BaseSignal.integrate1D>`
functions such as :external:meth:`~hyperspy.api.signals.BaseSignal.sum`
and :external:meth:`~hyperspy.api.signals.BaseSignal.integrate1D`

In the following image, the spectrum summed over all times is obtained from the
streak image by:

.. code-block:: python
>>> s.sum(axis='Time')
>>> # Or alternatively:
>>> s.sum(axis=-1)
import lumispy as lum
import numpy as np
data = np.arange(10*20).reshape(10, 20)
s = lum.signals.LumiTransientSpectrum(data)
s.axes_manager[-1].name = "Time"
s.axes_manager[-1].units = "ns"
s.axes_manager[-2].name = "Wavelength"
s.axes_manager[-2].units = "nm"
s.sum(axis='Time')
# Or alternatively:
s.sum(axis=-1)
Similarly, the transient summed over all wavelengths is obtained by:

.. code-block:: python
>>> s.sum(axis='Wavelength')
>>> # Or alternatively:
>>> s.sum(axis=-2)
s.sum(axis='Wavelength')
# Or alternatively:
s.sum(axis=-2)
.. image:: images/streakmap.svg
:width: 700
Expand Down
2 changes: 1 addition & 1 deletion upcoming_changes/205.new.rst
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Implement correct casting of :class:`~.signals.luminescence_transientspec.LumiTransientSpectrum` to either :class:`~.signals.luminescence_spectrum.LumiSpectrum` or :class:`~.signals.luminescence_transient.LumiTransient` when the signal dimension is reduced
Implement correct casting of :class:`~.signals.luminescence_transientspec.LumiTransientSpectrum` to either :class:`~.signals.luminescence_spectrum.LumiSpectrum` or :class:`~.signals.luminescence_transient.LumiTransient` when the signal dimension is reduced - previously, a :class:`~hyperspy.api.signals.Signal1D` object was returned.

0 comments on commit ecf514f

Please sign in to comment.