Skip to content

Commit

Permalink
update tutorial and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
stephprince committed Jan 11, 2024
1 parent 93a2c63 commit 554e78d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
40 changes: 30 additions & 10 deletions docs/gallery/domain/plot_icephys.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,31 @@
)

#####################################################################
# Adding stimulus templates
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#
# One predefined subcategory column is the ``stimulus_template`` column in the stimuli table. This column is
# used to store template waveforms of stimuli in addition to the actual recorded stimulus that is stored in the
# ``stimulus`` column. Similar to the ``stimulus`` and ``response`` columns, we can specify a relevant
# time range.
# ``stimulus`` column. The ``stimulus_template`` column contains an idealized version of the template waveform used as
# the stimulus. This can be useful as a noiseless version of the stimulus for data analysis or to validate that the
# recorded stimulus matches the expected waveform of the template. Similar to the ``stimulus`` and ``response``
# columns, we can specify a relevant time range.

stimulus_template = VoltageClampStimulusSeries(
name="ccst",
data=[0, 1, 2, 3, 4],
starting_time=0.0,
rate=10e3,
electrode=electrode,
gain=0.02,
)
nwbfile.add_stimulus_template(stimulus_template)

nwbfile.intracellular_recordings.add_column(
name="stimulus_template",
data=[TimeSeriesReference(0, 5, stimulus), # (start_index, index_count, stimulus_template)
TimeSeriesReference(1, 3, stimulus),
TimeSeriesReference.empty(stimulus)], # if there was no data for that recording, use an empty reference
data=[TimeSeriesReference(0, 5, stimulus_template), # (start_index, index_count, stimulus_template)
TimeSeriesReference(1, 3, stimulus_template),
TimeSeriesReference.empty(stimulus_template)], # if there was no data for that recording, use empty reference
description="Column storing the reference to the stimulus template for the recording (rows).",
category="stimuli",
col_cls=TimeSeriesReferenceVectorData
Expand All @@ -478,18 +493,23 @@
rowindex = nwbfile.add_intracellular_recording(
electrode=electrode,
stimulus=stimulus,
stimulus_template=stimulus, # the full time range of the stimulus template will be used unless specified
stimulus_template=stimulus_template, # the full time range of the stimulus template will be used unless specified
recording_tag='A4',
recording_lab_data={'location': 'Isengard'},
electrode_metadata={'voltage_threshold': 0.14},
id=13,
)

#####################################################################
# .. note:: If a stimulus template column exists but there is no stimulus template data for that recording, then the
# stimulus template will be internally set to the provided stimulus or response TimeSeries and the start_index
# and index_count for the missing parameter are set to -1. The missing values will be represented via masked
# numpy arrays.
# .. note:: If a stimulus template column exists but there is no stimulus template data for that recording, then
# :py:meth:`~pynwb.file.NWBFile.add_intracellular_recording` will internally set the stimulus template to the
# provided stimulus or response TimeSeries and the start_index and index_count for the missing parameter are
# set to -1. The missing values will be represented via masked numpy arrays.

#####################################################################
# .. note:: Since stimulus templates are often reused across many recordings, the timestamps in the templates are not
# usually aligned with the recording nor with the reference time of the file. The timestamps often start
# at 0 and are relative to the time of the application of the stimulus.

#####################################################################
# Add a simultaneous recording
Expand Down
13 changes: 6 additions & 7 deletions src/pynwb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,12 @@ def empty(cls, timeseries):
When missing data needs to be represented, NWB defines ``None`` for the complex data type ``(idx_start,
count, TimeSeries)`` as (-1, -1, TimeSeries) for storage. The exact timeseries object will technically not
matter since the empty reference is a way of indicating a NaN value. in a
:py:class:`~pynwb.base.TimeSeriesReferenceVectorData` column.
An example, where this functionality is used is :py:class:`~pynwb.icephys.IntracellularRecordingsTable`
where only one of stimulus or response data was recorded. In such cases, the timeseries object for the
empty stimulus :py:class:`~pynwb.base.TimeSeriesReference` could be set to the response series, or
vice versa.
matter since the empty reference is a way of indicating a NaN value in a
:py:class:`~pynwb.base.TimeSeriesReferenceVectorData` column.
An example where this functionality is used is :py:class:`~pynwb.icephys.IntracellularRecordingsTable`
where only one of stimulus or response data was recorded. In such cases, the timeseries object for the
empty stimulus :py:class:`~pynwb.base.TimeSeriesReference` could be set to the response series, or vice versa.
:returns: Returns :py:class:`~pynwb.base.TimeSeriesReference`
"""
Expand Down

0 comments on commit 554e78d

Please sign in to comment.