From c33cb63a163f0c9d6eca8ecf149a65f118408fc6 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Thu, 31 Oct 2024 13:21:47 -0700 Subject: [PATCH 1/4] add initial docs for decomposition series --- docs/gallery/domain/ecephys.py | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/gallery/domain/ecephys.py b/docs/gallery/domain/ecephys.py index 3f239eb77..d943278b6 100644 --- a/docs/gallery/domain/ecephys.py +++ b/docs/gallery/domain/ecephys.py @@ -32,6 +32,7 @@ from pynwb import NWBHDF5IO, NWBFile from pynwb.ecephys import LFP, ElectricalSeries +from pynwb.misc import DecompositionSeries ####################### # Creating and Writing NWB files @@ -241,6 +242,40 @@ ) ecephys_module.add(lfp) +#################### +# In some cases, you may want to further process the LFP data and decompose the signal into different frequency bands +# to use for other downstream analyses. You can store the processed data from these spectral analyses using a +# :py:class:`~pynwb.misc.DecompositionSeries` object. This object allows you to include metadata about the frequency +# bands and metric used (e.g., power, phase, amplitude), as well as link the decomposed data to the original +# :py:class:`~pynwb.base.TimeSeries` signal the data was derived from. + +####################### +# .. note:: When adding data to :py:class:`~pynwb.misc.DecompositionSeries`, the ``data`` argument is assumed to be +# 3D where the first dimension is time, the second dimension is channels, and the third dimension is bands. + + +bands = dict(theta=(4.0, 12.0), + beta=(12.0, 30.0), + gamma=(30.0, 80.0)) # in Hz +phase_data = np.random.randn(50, 12, len(bands)) # 50 samples, 12 channels, 3 frequency bands + +decomp_series = DecompositionSeries(name="theta", + data=phase_data, + metric='phase', + rate=200.0, + source_channels=all_table_region, + source_timeseries=lfp_electrical_series) + +for band_name, band_limits in bands.items(): + decomp_series.add_band(band_name=band_name, band_limits=band_limits) # TODO - band_mean/band_std are currently required + +ecephys_module.add(decomp_series) + +####################### +# The frequency band information can also be viewed as a pandas DataFrame. + +decomp_series.bands.to_dataframe() + #################### # .. _units_electrode: # From ec3a8e6cd62d3692b260a67a370e7dbf20f82d6f Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:47:23 -0800 Subject: [PATCH 2/4] remove old comment --- docs/gallery/domain/ecephys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/gallery/domain/ecephys.py b/docs/gallery/domain/ecephys.py index d943278b6..0105d225a 100644 --- a/docs/gallery/domain/ecephys.py +++ b/docs/gallery/domain/ecephys.py @@ -267,7 +267,7 @@ source_timeseries=lfp_electrical_series) for band_name, band_limits in bands.items(): - decomp_series.add_band(band_name=band_name, band_limits=band_limits) # TODO - band_mean/band_std are currently required + decomp_series.add_band(band_name=band_name, band_limits=band_limits) ecephys_module.add(decomp_series) From 725050e0a66e0e9edbadec629f91cc3970bdbae8 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Thu, 7 Nov 2024 14:03:05 -0800 Subject: [PATCH 3/4] update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16e504659..ec0d6875b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## PyNWB 2.8.3 (Upcoming) +### Documentation and tutorial enhancements +- Added a documentation example for `DecompositionSeries`. @stephprince [#1981](https://github.com/NeurodataWithoutBorders/pynwb/pull/1981) + ### Performance - Cache global type map to speed import 3X. @sneakers-the-rat [#1931](https://github.com/NeurodataWithoutBorders/pynwb/pull/1931) From 00ee6a3033bb6a9814f912557c6160f3d8ca97a8 Mon Sep 17 00:00:00 2001 From: Steph Prince <40640337+stephprince@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:40:57 -0800 Subject: [PATCH 4/4] update example to pass validation --- docs/gallery/domain/ecephys.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/gallery/domain/ecephys.py b/docs/gallery/domain/ecephys.py index 0105d225a..9ef84c717 100644 --- a/docs/gallery/domain/ecephys.py +++ b/docs/gallery/domain/ecephys.py @@ -260,6 +260,7 @@ phase_data = np.random.randn(50, 12, len(bands)) # 50 samples, 12 channels, 3 frequency bands decomp_series = DecompositionSeries(name="theta", + description="phase of bandpass filtered LFP data", data=phase_data, metric='phase', rate=200.0, @@ -267,7 +268,7 @@ source_timeseries=lfp_electrical_series) for band_name, band_limits in bands.items(): - decomp_series.add_band(band_name=band_name, band_limits=band_limits) + decomp_series.add_band(band_name=band_name, band_limits=band_limits, band_mean=np.nan, band_stdev=np.nan) ecephys_module.add(decomp_series)