From eef19341e2bb04f78dfa2fbda6a31eba4c857886 Mon Sep 17 00:00:00 2001 From: dimitargeorgiev Date: Mon, 18 Dec 2023 14:06:17 +0000 Subject: [PATCH] added tolist method to SpectralObject class --- src/ramanspy/core.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ramanspy/core.py b/src/ramanspy/core.py index d2b9cfe..8b3604d 100644 --- a/src/ramanspy/core.py +++ b/src/ramanspy/core.py @@ -172,6 +172,14 @@ def band(self, spectral_band: Number) -> np.ndarray: # Return the slice across that band return self.spectral_data[..., closest_band_index] + def tolist(self) -> list[Spectrum]: + """ + Returns the spectral object as a list of Spectrum objects. + """ + unfolded_spectral_data = self.spectral_data.reshape(-1, self.spectral_length) + + return [Spectrum(spectral_data, self.spectral_axis) for spectral_data in unfolded_spectral_data] + class Spectrum(SpectralContainer): """