GrandSpectralPipe#
- class sleepeegpy.pipeline.GrandSpectralPipe(*, pipes, output_dir)[source]#
Bases:
SpectrumPlots
The pipeline element combining results from multiple subjects.
Contains methods for computing and plotting combined PSD and topomaps, per sleep stage.
Methods:
For each sleep stage creates a
mne.time_frequency.SpectrumArray
object.Spectral parametrization by FOOOF - fitting oscillations & one over f.
Plot PSD per sleep stage.
Plots topomap for a sleep stage and a frequency band.
Plots topomap collage for multiple sleep stages and bands.
Saves SleepSpectrum objects to h5 files.
Attributes:
Stores SpectralPipes for multiple subjects.
Path to the directory where the output will be saved.
Representative raw object to infer montage
Instances of
fooof.FOOOFGroup
per sleep stage.Instances of
SleepSpectrum
per sleep stage.-
pipes:
Iterable
[SpectralPipe
][source]# Stores SpectralPipes for multiple subjects.
- plot_psds(picks, psd_range=(-40, 60), freq_range=(0, 60), dB=True, xscale='linear', axis=None, plot_sensors=False, save=False, legend_args=None, **plot_kwargs)[source]#
Plot PSD per sleep stage.
- Parameters:
picks (
Iterable
[str
] |str
) – Channels to plot PSDs for. Refer tomne.io.Raw.pick()
.psd_range (
tuple
) – Range of y axis on PSD plot. Defaults to (-40, 60).freq_range (
tuple
) – Range of x axis on PSD plot. Defaults to (0, 40).dB – Whether transform PSD to dB. Defaults to True.
xscale (
str
) – Scale of the X axis, check available values atmatplotlib.axes.Axes.set_xscale()
. Defaults to “linear”.axis (
axis
) – Instance ofmatplotlib.axes.Axes
. Defaults to None.plot_sensors (
bool
) – Whether to plot sensor map showing which channels were used for computing PSD. Defaults to False.save (
bool
) – Whether to save the figure. Defaults to False.**plot_kwargs – Arguments passed to the
matplotlib.pyplot.plot()
. Have no effect if axis is provided.Defaults to None.
- plot_topomap(stage='REM', band={'Delta': (0, 4)}, dB=False, axis=None, save=False, topomap_args=None, cbar_args=None)[source]#
Plots topomap for a sleep stage and a frequency band.
- Parameters:
stage (
str
) – One of the sleep_stages keys. Defaults to “REM”.band (
dict
) – Name-value pair - with name=arbitrary name and value=(l_freq, h_freq). Defaults to {“Delta”: (0, 4)}.dB (
bool
) – Whether transform PSD to dB. Defaults to False.axis (
axis
) – Instance ofmatplotlib.axes.Axes
. Defaults to None.save (
bool
) – Whether to save the figure. Defaults to False.topomap_args (
dict
) – Arguments passed tomne.viz.plot_topomap()
.Defaults to None.cbar_args (
dict
) – Arguments passed tomatplotlib.pyplot.colorbar()
.Defaults to None.
- plot_topomap_collage(stages_to_plot='all', bands={'Alpha': (8, 12.49), 'Beta': (12.5, 29.99), 'Delta': (0, 3.99), 'Gamma': (30, 60), 'Sigma': (12.5, 15), 'Theta': (4, 7.99)}, dB=False, low_percentile=5, high_percentile=95, fig=None, save=False, topomap_args=None, cbar_args=None)[source]#
Plots topomap collage for multiple sleep stages and bands.
- Parameters:
stages_to_plot (
tuple
) – Tuple of strings representing names from sleep_stages, e.g., (“REM”, “N1”). If set to “all” plots every stage provided in sleep_stages. Defaults to “all”.bands (
dict
) – Dict of name-value pairs - with name=arbitrary name and value=(l_freq, h_freq). Defaults to { “Delta”: (0, 3.99), “Theta”: (4, 7.99), “Alpha”: (8, 12.49), “Sigma”: (12.5, 15), “Beta”: (12.5, 29.99), “Gamma”: (30, 60), }.dB (
bool
) – Whether transform PSD to dB. Defaults to False.sleep_stages – Mapping between sleep stages names and their integer representations. Defaults to {“Wake”: 0, “N1”: 1, “N2”: 2, “N3”: 3, “REM”: 4}.
low_percentile (
float
) – Set min color value by percentile of the band data. Defaults to 5.high_percentile (
float
) – Set max color value by percentile of the band data. Defaults to 95.fig (
figure
) – Instance ofmpl:matplotlib.pyplot.figure
. Defaults to None.save (
bool
) – Whether to save the figure. Defaults to False.topomap_args (
dict
) – Arguments passed tomne.viz.plot_topomap()
. Defaults to None.cbar_args (
dict
) – Arguments passed tomatplotlib.pyplot.colorbar()
. Defaults to None.
- save_psds(overwrite)[source]#
Saves SleepSpectrum objects to h5 files.
- Parameters:
overwrite – Whether to overwrite existing spectrum files.
-
psds:
dict
# Instances of
SleepSpectrum
per sleep stage.
-
fooofs:
dict
[source]# Instances of
fooof.FOOOFGroup
per sleep stage.
- compute_psd(sleep_stages={'N1': 1, 'N2': 2, 'N3': 3, 'REM': 4, 'Wake': 0}, reference=None, fmin=0, fmax=60, average='mean', picks='eeg', reject_by_annotation=True, save=False, overwrite=False, **psd_kwargs)[source]#
For each sleep stage creates a
mne.time_frequency.SpectrumArray
object.- Parameters:
sleep_stages (
dict
) – Sleep stages mapping in hypnogram. Defaults to {“Wake”: 0, “N1”: 1, “N2”: 2, “N3”: 3, “REM”: 4}.reference (
UnionType
[Iterable
[str
],str
,None
]) – Which eeg reference to compute PSD with. If None, the reference isn’t changed. Defaults to None.fmin (
float
) – Lower frequency bound. Defaults to 0.fmax (
float
) – Upper frequency bound. Defaults to 60.picks (
str
|Iterable
[str
]) – Channels to compute spectra for. Refer tomne.io.Raw.pick()
. Defaults to “eeg”.reject_by_annotation (
bool
) – Whether to not use the annotations for the spectra computation. Defaults to True.save (
bool
) – Whether to save the spectra in .h5 files. Defaults to False.overwrite (
bool
) – Whether to overwrite the file. Defaults to False.**psd_kwargs – Additional arguments passed to
mne.time_frequency.psd_array_welch()
- parametrize(picks, freq_range, average_ch=False, **kwargs)[source]#
Spectral parametrization by FOOOF - fitting oscillations & one over f.
- Parameters:
picks – Channels to use in parametrization.
freq_range – Range of frequencies to parametrize. If None, set to bandpass filter boundaries. Defaults to None.
average_ch – Whether to average psds over channels. If False will be averaged over subjects. Defaults to False.
**kwargs – Arguments passed to
fooof.FOOOFGroup
.
-
pipes: