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 14, 2024
1 parent 88d1c3d commit 731df23
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
11 changes: 7 additions & 4 deletions lumispy/hyperspy_extension.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ signals:
lazy: True
module: lumispy.signals.luminescence_transient

TransientSpectrumCasting:
signal_type: TransientSpec
TransientSpectrumCasting: # allows casting to either Luminescence or Transient when dimensionality is reduced
signal_type: TransientSpectrum
signal_type_aliases:
- TransientSpec
- TRLumiSpec
- TR luminescence spectrum
- time-resolved luminescence spectrum
Expand All @@ -162,8 +163,9 @@ signals:
hidden: True
module: lumispy.signals.luminescence_transientspec
LumiTransientSpectrum:
signal_type: TransientSpec
signal_type: TransientSpectrum
signal_type_aliases:
- TransientSpec
- TRLumiSpec
- TR luminescence spectrum
- time-resolved luminescence spectrum
Expand All @@ -172,8 +174,9 @@ signals:
lazy: False
module: lumispy.signals.luminescence_transientspec
LazyLumiTransientSpectrum:
signal_type: TransientSpec
signal_type: TransientSpectrum
signal_type_aliases:
- TransientSpec
- TRLumiSpec
- TR luminescence spectrum
- time-resolved luminescence spectrum
Expand Down
3 changes: 3 additions & 0 deletions lumispy/signals/luminescence_transient.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class LumiTransient(Signal1D, CommonTransient):
_signal_type = "Transient"
_signal_dimension = 1

def __init(self, *args, **kwargs):
super().__init__(*args, **kwargs)


class LazyLumiTransient(LazySignal, LumiTransient):
"""**General lazy 1D luminescence signal class (transient/time resolved)**"""
Expand Down
45 changes: 27 additions & 18 deletions lumispy/signals/luminescence_transientspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
-------------------------------------------------
"""

import pint

from hyperspy.signals import Signal1D, Signal2D
from hyperspy._signals.lazy import LazySignal

Expand All @@ -30,34 +32,41 @@


class TransientSpectrumCasting(Signal1D, CommonLumi, CommonTransient):
"""**1D signal class for casting reduced LumiTransientSpectrum to either Luminescence or Transient**"""
"""**Hidden signal class**
1D version of ``TransientSpectrum`` signal class for casting
``LumiTransientSpectrum` to either ``Luminescence`` or ``Transient``
when the signal dimensionality is reduced.
Example:
--------
>>> s = LumiTransientSpectrum(np.random.random((10, 10, 10, 10))) * 2
>>> s.axes_manager.signal_axes[-1].units = 'ps'
>>> s.axes_manager.signal_axes[0].units = 'nm'
>>> s.sum(axis=-1)
>>> s
<LumiSpectrum, title: , dimensions: (10, 10|10)>
"""

_signal_type = "TransientSpec"
_signal_type = "TransientSpectrum"
_signal_dimension = 1

def __init__(self, *args, **kwargs):
if hasattr(self, "axes_manager") and self.axes_manager[-1].units in [
"fs",
"ps",
"ns",
"µs",
"mus",
"ms",
"s",
]:
self.metadata.Signal.signal_type = "Transient"
self.__class__ = LumiTransient
self.__init__(*args, **kwargs)
ureg = pint.UnitRegistry()
if (
hasattr(self, "axes_manager")
and ureg(self.axes_manager.signal_axes[-1].units).dimensionality
== ureg("s").dimensionality
):
self.set_signal_type("Transient")
else:
self.metadata.Signal.signal_type = "Luminescence"
self.__class__ = LumiSpectrum
self.__init__(*args, **kwargs)
self.set_signal_type("Luminescence")


class LumiTransientSpectrum(Signal2D, CommonLumi, CommonTransient):
"""**2D luminescence signal class (spectrum+transient/time resolved dimensions)**"""

_signal_type = "TransientSpec"
_signal_type = "TransientSpectrum"
_signal_dimension = 2


Expand Down
4 changes: 4 additions & 0 deletions lumispy/tests/signals/test_common_luminescence.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ def test_remove_negative(self):
def test_scale_by_exposure(self):
s1 = LumiSpectrum(np.ones((10, 10, 10)))
s2 = LumiTransientSpectrum(np.ones((10, 10, 10, 10)))
s2.axes_manager.signal_axes[-1].units = "ns"
s2.axes_manager.signal_axes[0].units = "nm"
s4 = LumiSpectrum(np.ones((10)))
s2.metadata.set_item("Acquisition_instrument.Detector.integration_time", 2)
s2.metadata.set_item("Signal.quantity", "Intensity (Counts)")
Expand Down Expand Up @@ -98,6 +100,8 @@ def test_scale_by_exposure(self):
def test_normalize(self):
s1 = LumiSpectrum(np.random.random((10, 10, 10))) * 2
s2 = LumiTransientSpectrum(np.random.random((10, 10, 10, 10))) * 2
s2.axes_manager.signal_axes[-1].units = "ps"
s2.axes_manager.signal_axes[0].units = "nm"
s3 = LumiSpectrum(np.random.random((10, 10))) * 2
s4 = LumiSpectrum(np.random.random((10))) * 2
s4.metadata.set_item("Signal.quantity", "Intensity (counts)")
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies = [
"hyperspy >= 1.7", # earlier versions do not provide non-uniform axes
"numpy",
"scipy",
"pint>=0.10",
]
keywords = [
"CL",
Expand Down

0 comments on commit 731df23

Please sign in to comment.