API Reference

This is the class and function reference page of SpecDAL.

Spectrum

class specdal.containers.spectrum.Spectrum(name=None, filepath=None, measurement=None, measure_type='pct_reflect', metadata=None, interpolated=False, stitched=False, jump_corrected=False, verbose=False)

Class that represents a single spectrum

name: string
Name of the spectrum.
filepath: string (optional)
Path to the file to read from.
measurement: pandas.Series
Spectral measurement
metadata: OrderedDict
Metadata associated with spectrum

Spectrum object stores a single spectral measurement using pandas.Series with index named: “wavelength”.

get_pct_reflect(dataframe)

Helper function to calculate pct_reflect from other columns

pd.Series object for pct_reflect

interpolate(spacing=1, method='slinear')
jump_correct(splices, reference, method='additive')
read(filepath, measure_type, verbose=False)

Read measurement from a file.

stitch(method='mean')

Collection

class specdal.containers.collection.Collection(name, directory=None, spectra=None, measure_type='pct_reflect', metadata=None, flags=None)

Represents a dataset consisting of a collection of spectra

append(spectrum)

insert spectrum to the collection

data

Get measurements as a Pandas.DataFrame

data_with_meta(data=True, fields=None)

Get dataframe with additional columns for metadata fields

data: boolean
whether to return the measurement data or not
fields: list
names of metadata fields to include as columns. If None, all the metadata will be included.

pd.DataFrame: self.data with additional columns

flags

A dict of flags for each spectrum in the collection

groupby(separator, indices, filler=None)

Group the spectra using a separator pattern

OrderedDict consisting of specdal.Collection objects for each group
key: group name value: collection object
interpolate(spacing=1, method='slinear')
jump_correct(splices, reference, method='additive')
max(append=False, ignore_flagged=True)
mean(append=False, ignore_flagged=True)
median(append=False, ignore_flagged=True)
min(append=False, ignore_flagged=True)
plot(*args, **kwargs)
read(directory, measure_type='pct_reflect', ext=['.asd', '.sed', '.sig', '.pico', '.light'], recursive=False, verbose=False)

read all files in a path matching extension

spectra

A list of Spectrum objects in the collection

std(append=False, ignore_flagged=True)
stitch(method='max')
to_csv(*args, **kwargs)
specdal.containers.collection.df_to_collection(df, name, measure_type='pct_reflect')

Create a collection from a pandas.DataFrame

df: pandas.DataFrame
Must have spectrum.name as index and metadata or wavelengths as columns
name: string
Name to assign to collection

c: specdal.Collection object

Operators

Specdal’s operators perform on both pandas and specdal objects. In the following operations, pandas series and dataframes correspond to specdal’s spectrum and collection, respectively.

specdal.operators.get_column_types(df)

Returns a tuple (wvl_cols, meta_cols), given a dataframe.

Wavelength column is defined as columns with a numerical name (i.e. decimal). Everything else is considered metadata column.

specdal.operators.stitch(series, method='max')

Stitch the regions with overlapping wavelength

series: pandas.Series object

method: string
How to compute final value in case of overlap. “mean”,”median”,”min”, or “max”.
specdal.operators.interpolate(series, spacing=1, method='slinear')

Interpolate the array into given spacing

series: pandas.Series object

spacing: int
wavelength spacing to interpolate at (in nm)
method: string
“slinear” or “cubic”
specdal.operators.derivative(series)

Calculate the spectral derivative. Not Implemented Yet.

specdal.operators.proximal_join(base_df, rover_df, on='gps_time_tgt', direction='nearest')

Perform proximal join and return a new dataframe.

base_df: pandas.DataFrame
DataFrame of reference measurements
rover_df: pandas.DataFrame
DataFrame of target measurements
proximal: pandas.DataFrame object
proximally processed dataset ( rover_df / base_df )

As a side-effect, the rover dataframe is sorted by the key Both base_df and rover_df must have the column specified by on. This column must be the same type in base and rover.

specdal.operators.jump_correct(series, splices, reference, method='additive')

Correct for jumps in non-overlapping wavelengths

splices: list
list of wavelength values where jumps occur
reference: int
position of the reference band (0-based)

Readers

Specdal’s readers parse a variety of input formats into the common specdal.containers.spectrum.Spectrum data type. Readers are used internally py Specturm and Collection when constructed with the filename argument, but can also be used individually.

specdal.readers.read(filepath, read_data=True, read_metadata=True, verbose=False)

Calls a reader function based on the extension of the passed filename. .asd: read_asd .sig: read_sig .sed: read_sed .pico: read_pico

specdal.readers.asd.read_asd(filepath, read_data=True, read_metadata=True, verbose=False)

Read asd file for data and metadata

2-tuple of (pd.DataFrame, OrderedDict) for data, metadata

specdal.readers.sig.read_sig(filepath, read_data=True, read_metadata=True, verbose=False)

Read asd file for data and metadata

2-tuple of (pd.DataFrame, OrderedDict) for data, metadata

specdal.readers.sed.read_sed(filepath, read_data=True, read_metadata=True, verbose=False)

Read sed file for data and metadata

2-tuple of (pd.DataFrame, OrderedDict) for data, metadata

specdal.readers.pico.read_pico(filepath, read_data=True, read_metadata=True, verbose=False)

Read pico file for data and metadata

2-tuple of (pd.DataFrame, OrderedDict) for data, metadata

Filters

Specdal’s filters operate on Collection objects, splitting them into “good” and “bad” spectra based on certain criteria.

specdal.filters.filter_std(collection, wavelength0, wavelength1, std_thresh, group='mean')

Filter the spectra from collection that have a standard deviation outside a certain threshold.

collection: specdal.containers.collection.Collection
the collection to filter
wavelength0: float
the starting wavelength to filter
wavelength1: float
the ending wavelength to filter
std_thresh: float
remove spectra outside of std_thresh standard deviations from the mean
group: string
if there are multiple data points between wavelength0 and wavelength1, average them this way. Options: “mean”, “median”, “min”, “max”
good: specdal.containers.Collection
A new collection made of the spectra that passed the filter
bad: specdal.containers.Collection
A new collection made of the spectra that failed the filter
specdal.filters.filter_white(collection, wavelength0=0, wavelength1=10000, group='mean')

Filter white reference spectra from collection

good: specdal.containers.Collection
A new collection made of the spectra that passed the filter
bad: specdal.containers.Collection
A new collection made of the spectra that failed the filter
specdal.filters.filter_threshold(collection, wavelength0, wavelength1, low, high, group='mean')

Filter the spectra from collection that have a value outside of (low,high). Parameters ———- collection: specdal.containers.collection.Collection

the collection to filter
wavelength0: float
the starting wavelength to filter
wavelength1: float
the ending wavelength to filter
low: float
minimum allowed value between wavelength0 and wavelength1
high: float
maximum allowed value between wavelength0 and wavelength1
group: string
if there are multiple data points between wavelength0 and wavelength1, average them this way. Options: “mean”, “median”, “min”, “max”
good: specdal.containers.Collection
A new collection made of the spectra that passed the filter
bad: specdal.containers.Collection
A new collection made of the spectra that failed the filter

GUI

Specdal provides a Tkinter-based GUI for plotting and manually flagging spectra from Collections.

class specdal.gui.viewer.ColorPickerDialog(parent, start_color=(0, 0, 0))
class specdal.gui.viewer.PlotConfigDialog(parent, xlim=(0, 1), ylim=(0, 1), title='', xlabel='', ylabel='')
class specdal.gui.viewer.ToolBar(canvas_, parent, ax)
home()

Override home method to return to home of most recent plot

class specdal.gui.viewer.Viewer(parent, collection=None, with_toolbar=True)
jump_correct()

Only performs jump correction on 1000 and 1800 wvls and 1 reference

save_flag()

save flag to self.flag_filepath

save_flag_as()

modify self.flag_filepath and call save_flag()

stitch()

Can’t stitch one spectrum and plot the collection

update()

Update the plot

update_selected(to_add=None)

Update, only on flaged