|
31 | 31 | from dateutil.tz import tzlocal |
32 | 32 |
|
33 | 33 | from pynwb import NWBHDF5IO, NWBFile |
| 34 | + |
34 | 35 | from pynwb.ecephys import LFP, ElectricalSeries, SpikeEventSeries |
| 36 | +from pynwb.misc import DecompositionSeries |
35 | 37 |
|
36 | 38 | ####################### |
37 | 39 | # Creating and Writing NWB files |
|
247 | 249 | ) |
248 | 250 | ecephys_module.add(lfp) |
249 | 251 |
|
| 252 | +#################### |
| 253 | +# In some cases, you may want to further process the LFP data and decompose the signal into different frequency bands |
| 254 | +# to use for other downstream analyses. You can store the processed data from these spectral analyses using a |
| 255 | +# :py:class:`~pynwb.misc.DecompositionSeries` object. This object allows you to include metadata about the frequency |
| 256 | +# bands and metric used (e.g., power, phase, amplitude), as well as link the decomposed data to the original |
| 257 | +# :py:class:`~pynwb.base.TimeSeries` signal the data was derived from. |
| 258 | + |
| 259 | +####################### |
| 260 | +# .. note:: When adding data to :py:class:`~pynwb.misc.DecompositionSeries`, the ``data`` argument is assumed to be |
| 261 | +# 3D where the first dimension is time, the second dimension is channels, and the third dimension is bands. |
| 262 | + |
| 263 | + |
| 264 | +bands = dict(theta=(4.0, 12.0), |
| 265 | + beta=(12.0, 30.0), |
| 266 | + gamma=(30.0, 80.0)) # in Hz |
| 267 | +phase_data = np.random.randn(50, 12, len(bands)) # 50 samples, 12 channels, 3 frequency bands |
| 268 | + |
| 269 | +decomp_series = DecompositionSeries(name="theta", |
| 270 | + description="phase of bandpass filtered LFP data", |
| 271 | + data=phase_data, |
| 272 | + metric='phase', |
| 273 | + rate=200.0, |
| 274 | + source_channels=all_table_region, |
| 275 | + source_timeseries=lfp_electrical_series) |
| 276 | + |
| 277 | +for band_name, band_limits in bands.items(): |
| 278 | + decomp_series.add_band(band_name=band_name, band_limits=band_limits, band_mean=np.nan, band_stdev=np.nan) |
| 279 | + |
| 280 | +ecephys_module.add(decomp_series) |
| 281 | + |
| 282 | +####################### |
| 283 | +# The frequency band information can also be viewed as a pandas DataFrame. |
| 284 | + |
| 285 | +decomp_series.bands.to_dataframe() |
| 286 | + |
250 | 287 | #################### |
251 | 288 | # .. _units_electrode: |
252 | 289 | # |
|
0 commit comments