Skip to content

Commit 892c53c

Browse files
authored
Merge pull request Quasars#41 from ngergihun/addchannel
[ENH] Add channel to NeaSpectra
2 parents 470360b + 9393e8f commit 892c53c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

pySNOM/spectra.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ def parameters(self):
9191
"""Property - scantype (ScanType Enum name)"""
9292
return self._parameters
9393

94+
def add_channel(self, values, channelname, zerofilling=1):
95+
"""Adds a new channel to data dictionary"""
96+
if channelname not in list(self._data.keys()):
97+
self._data[channelname] = np.reshape(
98+
values,
99+
(
100+
int(self.parameters["PixelArea"][0]),
101+
int(self.parameters["PixelArea"][1]),
102+
int(self.parameters["PixelArea"][2]*zerofilling),
103+
),
104+
)
105+
else:
106+
raise ValueError
94107

95108
class SingleChannelSpectrum(NeaSpectrum):
96109
def __init__(
@@ -228,6 +241,10 @@ def reshape_spectrum_data(data, params):
228241
spectral_depth = len(np.unique(data["Index"]))
229242
elif "Omega" in allchannels:
230243
spectral_depth = len(np.unique(data["Omega"]))
244+
elif "Wavenumber" in allchannels:
245+
spectral_depth = len(np.unique(data["Wavenumber"]))
246+
elif "Wavelength" in allchannels:
247+
spectral_depth = len(np.unique(data["Wavelength"]))
231248
else:
232249
spectral_depth = params["PixelArea"][2] * n
233250

pySNOM/tests/test_spectra.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ def test_pointspectrum_object(self):
2020
np.testing.assert_string_equal(s.scantype, "Point")
2121
np.testing.assert_equal(np.shape(s.data["O2A"])[0], 2048)
2222

23+
def test_add_channel(self):
24+
f = "datasets/testspectrum_singlepoint.txt"
25+
file_reader = readers.NeaSpectralReader(os.path.join(pySNOM.__path__[0], f))
26+
data, params = file_reader.read()
27+
28+
newchannel = np.zeros(np.shape(data["O3A"]))
29+
s = spectra.NeaSpectrum(data, params)
30+
s.add_channel(newchannel, "O6A",zerofilling=2)
31+
32+
np.testing.assert_almost_equal(s.data["O6A"][0], 0)
33+
34+
2335
def test_multipointspectrum_object(self):
2436
f = "datasets/testspectrum_multipoint.txt"
2537
file_reader = readers.NeaSpectralReader(os.path.join(pySNOM.__path__[0], f))

0 commit comments

Comments
 (0)