|
31 | 31 | from dateutil.tz import tzlocal |
32 | 32 |
|
33 | 33 | from pynwb import NWBHDF5IO, NWBFile |
34 | | -from pynwb.ecephys import LFP, ElectricalSeries |
| 34 | +from pynwb.ecephys import LFP, ElectricalSeries, SpikeEventSeries |
35 | 35 |
|
36 | 36 | ####################### |
37 | 37 | # Creating and Writing NWB files |
|
244 | 244 | #################### |
245 | 245 | # .. _units_electrode: |
246 | 246 | # |
247 | | -# Spike Times |
248 | | -# ^^^^^^^^^^^ |
| 247 | +# Sorted spike times |
| 248 | +# ^^^^^^^^^^^^^^^^^^ |
249 | 249 | # |
250 | 250 | # Spike times are stored in the :py:class:`~pynwb.misc.Units` table, which is a subclass of |
251 | 251 | # :py:class:`~hdmf.common.table.DynamicTable`. Adding columns to the :py:class:`~pynwb.misc.Units` table is analogous |
|
272 | 272 |
|
273 | 273 | nwbfile.units.to_dataframe() |
274 | 274 |
|
| 275 | +#################### |
| 276 | +# Unsorted spike times |
| 277 | +# ^^^^^^^^^^^^^^^^^^^^ |
| 278 | +# |
| 279 | +# While the :py:class:`~pynwb.misc.Units` table is used to store spike times and waveform data for |
| 280 | +# spike-sorted, single-unit activity, you may also want to store spike times and waveform snippets of |
| 281 | +# unsorted spiking activity (e.g., multi-unit activity detected via threshold crossings during data acquisition). |
| 282 | +# This information can be stored using :py:class:`~pynwb.ecephys.SpikeEventSeries` objects. |
| 283 | + |
| 284 | +spike_snippets = np.random.rand(20, 3, 40) # 20 events, 3 channels, 40 samples per event |
| 285 | +shank0 = nwbfile.create_electrode_table_region( |
| 286 | + region=[0, 1, 2], |
| 287 | + description="shank0", |
| 288 | +) |
| 289 | + |
| 290 | + |
| 291 | +spike_events = SpikeEventSeries(name='SpikeEvents_Shank0', |
| 292 | + description="events detected with 100uV threshold", |
| 293 | + data=spike_snippets, |
| 294 | + timestamps=np.arange(20), |
| 295 | + electrodes=shank0) |
| 296 | +nwbfile.add_acquisition(spike_events) |
| 297 | + |
275 | 298 | ####################### |
276 | 299 | # Designating electrophysiology data |
277 | 300 | # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|
283 | 306 | # :py:mod:`API documentation <pynwb.ecephys>` and :ref:`basics` for more details on |
284 | 307 | # using these objects. |
285 | 308 | # |
286 | | -# For storing spike data, there are two options. Which one you choose depends on what data you have available. |
287 | | -# If you need to store the complete, continuous raw voltage traces, you should store the traces with |
| 309 | +# For storing unsorted spiking data, there are two options. Which one you choose depends on what data you |
| 310 | +# have available. If you need to store the complete, continuous raw voltage traces, you should store the traces with |
288 | 311 | # :py:class:`~pynwb.ecephys.ElectricalSeries` objects as :ref:`acquisition <basic_timeseries>` data, and use |
289 | 312 | # the :py:class:`~pynwb.ecephys.EventDetection` class for identifying the spike events in your raw traces. |
290 | 313 | # If you do not want to store the raw voltage traces and only the waveform 'snippets' surrounding spike events, |
291 | | -# you should use the :py:class:`~pynwb.ecephys.EventWaveform` class, which can store one or more |
292 | | -# :py:class:`~pynwb.ecephys.SpikeEventSeries` objects. |
| 314 | +# you should use :py:class:`~pynwb.ecephys.SpikeEventSeries` objects. |
293 | 315 | # |
294 | 316 | # The results of spike sorting (or clustering) should be stored in the top-level :py:class:`~pynwb.misc.Units` table. |
295 | | -# Note that it is not required to store spike waveforms in order to store spike events or mean waveforms--if you only |
296 | | -# want to store the spike times of clustered units you can use only the Units table. |
| 317 | +# The :py:class:`~pynwb.misc.Units` table can contain simply the spike times of sorted units, or you can also include |
| 318 | +# individual and mean waveform information in some of the optional, predefined :py:class:`~pynwb.misc.Units` table |
| 319 | +# columns: ``waveform_mean``, ``waveform_sd``, or ``waveforms``. |
297 | 320 | # |
298 | 321 | # For local field potential data, there are two options. Again, which one you choose depends on what data you |
299 | 322 | # have available. With both options, you should store your traces with :py:class:`~pynwb.ecephys.ElectricalSeries` |
|
0 commit comments