From 8a4b213829a324c92d519ce2da5a2d05dec38ec5 Mon Sep 17 00:00:00 2001 From: jlaehne Date: Fri, 3 Jan 2025 10:58:44 +0100 Subject: [PATCH] add time2nav and spec2nav functions --- doc/user_guide/streak_images.rst | 5 ++ lumispy/hyperspy_extension.yaml | 12 +++-- lumispy/signals/luminescence_transientspec.py | 48 +++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/doc/user_guide/streak_images.rst b/doc/user_guide/streak_images.rst index 0b3113a19..dd3e63538 100644 --- a/doc/user_guide/streak_images.rst +++ b/doc/user_guide/streak_images.rst @@ -61,3 +61,8 @@ Similarly, the transient summed over all wavelengths is obtained by: :width: 700 :alt: Plot of a streak camera image and its one-dimensional representations obtained by summing over either the wavelength or time dimensions. + + +Iteration over the spectral or time dimension +============================================= + diff --git a/lumispy/hyperspy_extension.yaml b/lumispy/hyperspy_extension.yaml index 70c77c178..d0f12f0e0 100644 --- a/lumispy/hyperspy_extension.yaml +++ b/lumispy/hyperspy_extension.yaml @@ -21,6 +21,7 @@ signals: signal_type: Luminescence signal_type_aliases: - LuminescenceSpectrum + - LumiSpectrum signal_dimension: 1 dtype: real lazy: False @@ -29,6 +30,7 @@ signals: signal_type: Luminescence signal_type_aliases: - LuminescenceSpectrum + - LumiSpectrum signal_dimension: 1 dtype: real lazy: True @@ -132,9 +134,9 @@ signals: LumiTransient: signal_type: Transient signal_type_aliases: + - LumiTransient - TRLumi - TR luminescence - - time-resolved luminescence signal_dimension: 1 dtype: real lazy: False @@ -142,9 +144,9 @@ signals: LazyLumiTransient: signal_type: Transient signal_type_aliases: + - LumiTransient - TRLumi - TR luminescence - - time-resolved luminescence signal_dimension: 1 dtype: real lazy: True @@ -153,10 +155,10 @@ signals: TransientSpectrumCasting: # allows casting to either Luminescence or Transient when dimensionality is reduced signal_type: TransientSpectrum signal_type_aliases: + - LumiTransientSpectrum - TransientSpec - TRLumiSpec - TR luminescence spectrum - - time-resolved luminescence spectrum signal_dimension: 1 dtype: real lazy: False @@ -165,10 +167,10 @@ signals: LumiTransientSpectrum: signal_type: TransientSpectrum signal_type_aliases: + - LumiTransientSpectrum - TransientSpec - TRLumiSpec - TR luminescence spectrum - - time-resolved luminescence spectrum signal_dimension: 2 dtype: real lazy: False @@ -176,10 +178,10 @@ signals: LazyLumiTransientSpectrum: signal_type: TransientSpectrum signal_type_aliases: + - LumiTransientSpectrum - TransientSpec - TRLumiSpec - TR luminescence spectrum - - time-resolved luminescence spectrum signal_dimension: 2 dtype: real lazy: True diff --git a/lumispy/signals/luminescence_transientspec.py b/lumispy/signals/luminescence_transientspec.py index 214ce30ad..c26c0af1a 100644 --- a/lumispy/signals/luminescence_transientspec.py +++ b/lumispy/signals/luminescence_transientspec.py @@ -25,6 +25,7 @@ from hyperspy.signals import Signal1D, Signal2D from hyperspy._signals.lazy import LazySignal +from hyperspy.docstrings.signal import OPTIMIZE_ARG from lumispy.signals import LumiSpectrum, LumiTransient from lumispy.signals.common_luminescence import CommonLumi @@ -69,6 +70,53 @@ class LumiTransientSpectrum(Signal2D, CommonLumi, CommonTransient): _signal_type = "TransientSpectrum" _signal_dimension = 2 + def spec2nav(self, optimize=True): + """Return the streak image as signal with the spectral axis as navigation + axis and the time axis as signal axis. For efficient iteration over + transients as a function of the spectral positions (e.g. for fitting + transients). By default, the method ensures the data is stored optimally, + hence often making a copy of the data. + + Parameters + ---------- + %s + + See Also + -------- + lumispy.signals.LumiTransientSpectrum.time2nav + hyperspy.api.signals.BaseSignal.transpose + """ + s = self.transpose(signal_axes=[-1],optimize=optimize) + return s + + spec2nav.__doc__ %= ( + OPTIMIZE_ARG.replace("False", "True"), + ) + + def time2nav(self, optimize=True): + """Return the streak image as signal with the time axis as navigation + axis and the spectral axis as signal axis. For efficient iteration over + spectra as a function of time (e.g. for fitting spectra). By default, the + method ensures the data is stored optimally, hence often making a copy + of the data. + + Parameters + ---------- + %s + + See Also + -------- + lumispy.signals.LumiTransientSpectrum.time2nav + hyperspy.api.signals.BaseSignal.transpose + """ + s = self.transpose(signal_axes=[-2],optimize=optimize) + return s + #self.axes_manager.signal_axes[-1].navigate = True + #self.set_signal_type("LumiSpectrum") + + time2nav.__doc__ %= ( + OPTIMIZE_ARG.replace("False", "True"), + ) class LazyLumiTransientSpectrum(LazySignal, LumiTransientSpectrum): """**Lazy 2D luminescence signal class (spectral+transient/time resolved dimensions)**"""