In [1]:
from specdal import Collection, Spectrum, read
from matplotlib import pyplot as plt
Manual way of loading files into Collection object:
In [2]:
import os
datadir = "/home/young/data/specdal/aidan_data2/ASD/"
c = Collection(name='myFirst')
for f in sorted(os.listdir(datadir))[1:11]:
spectrum = Spectrum(filepath=os.path.join(datadir, f))
c.append(spectrum)
We can access spectra by name:
In [3]:
print(type(c["ACPA_F_A_SU_20160617_00000"]))
print(c["ACPA_F_A_SU_20160617_00000"])
As a list:
In [4]:
print(type(c.spectra))
for s in c.spectra[0:2]:
print(s)
As a DataFrame:
In [5]:
print(type(c.data))
c.data.head()
Out[5]:
Like the Spectrum class, Collection also provides wrappers around pandas.DataFrame methods. We can easily plot a collection as follows:
In [6]:
c.plot(legend=False, ylim=(0, 0.5))
plt.show()
If you look closely, there are jumps at wavelengths 1000, and 1800
In [7]:
c.plot(legend=False, xlim=(900, 1100), ylim=(0.4, 0.5))
plt.show()
Spectrum objects provide jump_correct() method to deal with this. Collection class provides the same method which iterates through the spectrum objects and applies the jump correction.
We could similarly apply other spectral transformations such as resampling and overlap stitching on the entire collection.
In [8]:
c.jump_correct(splices=[1000, 1800], reference=0)
c.plot(legend=False, ylim=(0, 0.5))
c.plot(legend=False, xlim=(900, 1100), ylim=(0.4, 0.5))
plt.show()
We can easily calculate aggregate functions (mean, median, min/max, std, etc.), which will return a Spectrum object:
In [9]:
mean = c.mean()
print(type(mean))
mean.plot()
plt.show()
In [12]:
c.std(append=True) # append the spectrum to the original collection
c.plot(legend=False)
plt.show()