.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/domain/plot_behavior.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_domain_plot_behavior.py: .. _behavior_basics: Behavior Data ================================== This tutorial will demonstrate the usage of the :py:mod:`pynwb.behavior` module for adding behavioral data to an :py:class:`~pynwb.file.NWBFile`. .. seealso:: You can learn more about the :py:class:`~pynwb.file.NWBFile` format in the :ref:`basics` tutorial. The examples below follow this general workflow for adding behavior data to an :py:class:`~pynwb.file.NWBFile`: * create an object: * :py:class:`~pynwb.base.TimeSeries` for continuous time series data, * :py:class:`~pynwb.behavior.SpatialSeries` for continuous spatial data (e.g. position, direction relative to some reference frame), * :py:class:`~pynwb.misc.IntervalSeries` or :py:class:`~pynwb.epoch.TimeIntervals` for time intervals * store that object inside a behavior interface object: * :py:class:`~pynwb.behavior.Position` for position measured over time * :py:class:`~pynwb.behavior.CompassDirection` for view angle measured over time * :py:class:`~pynwb.behavior.BehavioralTimeSeries` for continuous time series data * :py:class:`~pynwb.behavior.BehavioralEpochs` for behavioral intervals (e.g. sleep intervals) * :py:class:`~pynwb.behavior.PupilTracking` for eye-tracking data of pupil size * :py:class:`~pynwb.behavior.EyeTracking` for eye-tracking data of gaze direction * :py:class:`~pynwb.event.EventsTable` for behavioral events (e.g. reward times) * create a behavior processing module for the :py:class:`~pynwb.file.NWBFile` and add the interface object(s) to it The following examples will reference variables that may not be defined within the block they are used in. For clarity, we define them here: .. GENERATED FROM PYTHON SOURCE LINES 38-59 .. code-block:: Python from datetime import datetime from uuid import uuid4 import numpy as np from dateutil.tz import tzlocal from pynwb import NWBHDF5IO, NWBFile, TimeSeries from pynwb.behavior import ( BehavioralEpochs, BehavioralTimeSeries, CompassDirection, EyeTracking, Position, PupilTracking, SpatialSeries, ) from pynwb.epoch import TimeIntervals from pynwb.event import EventsTable from pynwb.misc import IntervalSeries .. GENERATED FROM PYTHON SOURCE LINES 61-66 Create an NWB File ------------------ Create an :py:class:`~pynwb.file.NWBFile` object with the required fields (``session_description``, ``identifier``, ``session_start_time``) and additional metadata. .. GENERATED FROM PYTHON SOURCE LINES 66-82 .. code-block:: Python nwbfile = NWBFile( session_description="my first synthetic recording", identifier=str(uuid4()), session_start_time=datetime.now(tzlocal()), experimenter=[ "Baggins, Bilbo", ], lab="Bag End Laboratory", institution="University of Middle Earth at the Shire", experiment_description="I went on an adventure to reclaim vast treasures.", session_id="LONELYMTN001", ) nwbfile .. raw:: html

root (NWBFile)

session_description: my first synthetic recording
identifier: 04179427-9564-4f32-912e-81eb217eccd4
session_start_time2026-05-23 20:01:35.717143+00:00
timestamps_reference_time2026-05-23 20:01:35.717143+00:00
file_create_date
02026-05-23 20:01:35.717418+00:00
experimenter
0: Baggins, Bilbo
experiment_description: I went on an adventure to reclaim vast treasures.
session_id: LONELYMTN001
lab: Bag End Laboratory
institution: University of Middle Earth at the Shire


.. GENERATED FROM PYTHON SOURCE LINES 83-91 SpatialSeries: Storing continuous spatial data ---------------------------------------------- :py:class:`~pynwb.behavior.SpatialSeries` is a subclass of :py:class:`~pynwb.base.TimeSeries` that represents data in space, such as the spatial direction, e.g., of gaze or travel, or position of an animal over time. Create data that corresponds to x, y position over time. .. GENERATED FROM PYTHON SOURCE LINES 91-96 .. code-block:: Python position_data = np.array([np.linspace(0, 10, 50), np.linspace(0, 8, 50)]).T position_data.shape .. rst-class:: sphx-glr-script-out .. code-block:: none (50, 2) .. GENERATED FROM PYTHON SOURCE LINES 97-108 In :py:class:`~pynwb.behavior.SpatialSeries` ``data``, the first dimension is always time (in seconds), the second dimension represents the x, y position (in meters). .. note:: :py:class:`~pynwb.behavior.SpatialSeries` data should be stored as one continuous stream, as it is acquired, not by trial as is often reshaped for analysis. Data can be trial-aligned on-the-fly using the trials table. See the :ref:`time_intervals` tutorial for further information. For position data ``reference_frame`` indicates the zero-position, e.g. the 0,0 point might be the bottom-left corner of an enclosure, as viewed from the tracking camera. .. GENERATED FROM PYTHON SOURCE LINES 108-121 .. code-block:: Python timestamps = np.linspace(0, 50) / 200 position_spatial_series = SpatialSeries( name="SpatialSeries", description="Position (x, y) in an open field.", data=position_data, timestamps=timestamps, reference_frame="(0,0) is bottom left corner", ) position_spatial_series .. raw:: html

SpatialSeries

resolution: -1.0
comments: no comments
description: Position (x, y) in an open field.
conversion: 1.0
offset: 0.0
unit: meters
data
NumPy array
Data typefloat64
Shape(50, 2)
Array size800.00 bytes
timestamps
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps_unit: seconds
interval: 1
reference_frame: (0,0) is bottom left corner


.. GENERATED FROM PYTHON SOURCE LINES 122-129 Position: Storing position measured over time --------------------------------------------- To help data analysis and visualization tools know that this :py:class:`~pynwb.behavior.SpatialSeries` object represents the position of the subject, store the :py:class:`~pynwb.behavior.SpatialSeries` object inside a :py:class:`~pynwb.behavior.Position` object, which can hold one or more :py:class:`~pynwb.behavior.SpatialSeries` objects. .. GENERATED FROM PYTHON SOURCE LINES 129-132 .. code-block:: Python position = Position(spatial_series=position_spatial_series) .. GENERATED FROM PYTHON SOURCE LINES 133-142 .. seealso:: You can learn more about the :py:class:`~pynwb.behavior.SpatialSeries` data type and :py:class:`~pynwb.behavior.Position` interface in the :ref:`basic_spatialseries` tutorial. .. seealso:: You can learn more about best practices that can be applied to :py:class:`~pynwb.behavior.SpatialSeries` at `NWB Best Practices `_. .. GENERATED FROM PYTHON SOURCE LINES 145-151 Create a Behavior Processing Module ----------------------------------- Create a processing module called ``"behavior"`` for storing behavioral data in the :py:class:`~pynwb.file.NWBFile` using the :py:meth:`~pynwb.file.NWBFile.create_processing_module` method, and then add the :py:class:`~pynwb.behavior.Position` object to the processing module. .. GENERATED FROM PYTHON SOURCE LINES 151-159 .. code-block:: Python behavior_module = nwbfile.create_processing_module( name="behavior", description="Processed behavioral data" ) behavior_module.add(position) .. raw:: html

Position

SpatialSeries (SpatialSeries)
resolution: -1.0
comments: no comments
description: Position (x, y) in an open field.
conversion: 1.0
offset: 0.0
unit: meters
data
NumPy array
Data typefloat64
Shape(50, 2)
Array size800.00 bytes
timestamps
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps_unit: seconds
interval: 1
reference_frame: (0,0) is bottom left corner


.. GENERATED FROM PYTHON SOURCE LINES 160-163 .. seealso:: You can read more about the basic concepts of processing modules in the :ref:`modules_overview` tutorial. .. GENERATED FROM PYTHON SOURCE LINES 165-174 CompassDirection: Storing view angle measured over time ------------------------------------------------------- Analogous to how position can be stored, we can create a :py:class:`~pynwb.behavior.SpatialSeries` object for representing the view angle of the subject. For direction data ``reference_frame`` indicates the zero-axes, for instance “straight-ahead” might be a specific pixel on the monitor, or some other point in space. The unit of measurement for the :py:class:`~pynwb.behavior.SpatialSeries` object should be radians or degrees. .. GENERATED FROM PYTHON SOURCE LINES 174-190 .. code-block:: Python view_angle_data = np.linspace(0, 4, 50) direction_spatial_series = SpatialSeries( name="SpatialSeries", description="View angle of the subject measured in radians.", data=view_angle_data, timestamps=timestamps, reference_frame="straight ahead", unit="radians", ) direction = CompassDirection( spatial_series=direction_spatial_series, name="CompassDirection" ) .. GENERATED FROM PYTHON SOURCE LINES 191-193 We can add a :py:class:`~pynwb.behavior.CompassDirection` object to the ``behavior`` processing module the same way as we have added the position data: .. GENERATED FROM PYTHON SOURCE LINES 193-197 .. code-block:: Python behavior_module.add(direction) .. raw:: html

CompassDirection

SpatialSeries (SpatialSeries)
resolution: -1.0
comments: no comments
description: View angle of the subject measured in radians.
conversion: 1.0
offset: 0.0
unit: radians
data
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps_unit: seconds
interval: 1
reference_frame: straight ahead


.. GENERATED FROM PYTHON SOURCE LINES 198-203 BehavioralTimeSeries: Storing continuous behavior data ------------------------------------------------------ :py:class:`~pynwb.behavior.BehavioralTimeSeries` is an interface for storing continuous behavior data, such as the speed of a subject. .. GENERATED FROM PYTHON SOURCE LINES 203-221 .. code-block:: Python speed_data = np.linspace(0, 0.4, 50) speed_time_series = TimeSeries( name="speed", data=speed_data, timestamps=timestamps, description="The speed of the subject measured over time.", unit="m/s", ) behavioral_time_series = BehavioralTimeSeries( time_series=speed_time_series, name="BehavioralTimeSeries", ) behavior_module.add(behavioral_time_series) .. raw:: html

BehavioralTimeSeries

speed (TimeSeries)
resolution: -1.0
comments: no comments
description: The speed of the subject measured over time.
conversion: 1.0
offset: 0.0
unit: m/s
data
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps_unit: seconds
interval: 1


.. GENERATED FROM PYTHON SOURCE LINES 222-237 EventsTable: Storing behavioral events -------------------------------------- :py:class:`~pynwb.event.EventsTable` is for storing behavioral events such as the timing and amount of rewards (e.g., water amount) or lever press times. EventsTable is stored in ``NWBFile.events``. .. note:: :py:class:`~pynwb.behavior.BehavioralEvents` is deprecated. Use :py:class:`~pynwb.event.EventsTable` instead. Create an :py:class:`~pynwb.event.EventsTable` to store reward delivery events. The required ``timestamp`` column stores the time of each event in seconds from the session start time. Additional columns can be added to store metadata about each event, such as the amount of reward delivered. .. GENERATED FROM PYTHON SOURCE LINES 237-248 .. code-block:: Python reward_events = EventsTable( name="reward_events", description="Times and amounts of water rewards delivered to the animal.", ) reward_events.add_column(name="amount_ml", description="Volume of water reward in mL.") reward_events.add_event(timestamp=12.5, amount_ml=0.05) reward_events.add_event(timestamp=27.3, amount_ml=0.05) reward_events.add_event(timestamp=44.1, amount_ml=0.10) .. GENERATED FROM PYTHON SOURCE LINES 249-252 Add the :py:class:`~pynwb.event.EventsTable` to the :py:class:`~pynwb.file.NWBFile` using :py:meth:`~pynwb.file.NWBFile.add_events_table`. Events tables are stored in ``NWBFile.events``. .. GENERATED FROM PYTHON SOURCE LINES 252-255 .. code-block:: Python nwbfile.add_events_table(reward_events) .. raw:: html

reward_events (EventsTable)

description: Times and amounts of water rewards delivered to the animal.
columns
timestamp
The time that each event occurred, in seconds, from the session start time.
amount_ml
Volume of water reward in mL.
table
timestamp amount_ml
id
0 12.5 0.05
1 27.3 0.05
2 44.1 0.10


.. GENERATED FROM PYTHON SOURCE LINES 256-265 BehavioralEpochs: Storing intervals of behavior data ---------------------------------------------------- :py:class:`~pynwb.behavior.BehavioralEpochs` is for storing intervals of behavior data. :py:class:`~pynwb.behavior.BehavioralEpochs` uses :py:class:`~pynwb.misc.IntervalSeries` to represent behavioral epochs. Create :py:class:`~pynwb.misc.IntervalSeries` object that represents the time intervals when the animal was running. :py:class:`~pynwb.misc.IntervalSeries` uses 1 to indicate the beginning of an interval and -1 to indicate the end. .. GENERATED FROM PYTHON SOURCE LINES 265-278 .. code-block:: Python run_intervals = IntervalSeries( name="running", description="Intervals when the animal was running.", data=[1, -1, 1, -1, 1, -1], timestamps=[0.5, 1.5, 3.5, 4.0, 7.0, 7.3], ) behavioral_epochs = BehavioralEpochs(name="BehavioralEpochs") behavioral_epochs.add_interval_series(run_intervals) .. raw:: html

running (IntervalSeries)

resolution: -1.0
comments: no comments
description: Intervals when the animal was running.
conversion: 1.0
offset: 0.0
unit: n/a
data
0: 1
1: -1
2: 1
3: -1
4: 1
5: -1
timestamps
0: 0.5
1: 1.5
2: 3.5
3: 4.0
4: 7.0
5: 7.3
timestamps_unit: seconds
interval: 1


.. GENERATED FROM PYTHON SOURCE LINES 279-281 you can add more than one :py:class:`~pynwb.misc.IntervalSeries` to a :py:class:`~pynwb.behavior.BehavioralEpochs` .. GENERATED FROM PYTHON SOURCE LINES 281-292 .. code-block:: Python sleep_intervals = IntervalSeries( name="sleeping", description="Intervals when the animal was sleeping.", data=[1, -1, 1, -1], timestamps=[15.0, 30.0, 60.0, 95.0], ) behavioral_epochs.add_interval_series(sleep_intervals) behavior_module.add(behavioral_epochs) .. raw:: html

BehavioralEpochs

running (IntervalSeries)
resolution: -1.0
comments: no comments
description: Intervals when the animal was running.
conversion: 1.0
offset: 0.0
unit: n/a
data
0: 1
1: -1
2: 1
3: -1
4: 1
5: -1
timestamps
0: 0.5
1: 1.5
2: 3.5
3: 4.0
4: 7.0
5: 7.3
timestamps_unit: seconds
interval: 1
sleeping (IntervalSeries)
resolution: -1.0
comments: no comments
description: Intervals when the animal was sleeping.
conversion: 1.0
offset: 0.0
unit: n/a
data
0: 1
1: -1
2: 1
3: -1
timestamps
0: 15.0
1: 30.0
2: 60.0
3: 95.0
timestamps_unit: seconds
interval: 1


.. GENERATED FROM PYTHON SOURCE LINES 293-300 Using :py:class:`~pynwb.epoch.TimeIntervals` representing time intervals is often preferred over :py:class:`~pynwb.behavior.BehavioralEpochs` and :py:class:`~pynwb.misc.IntervalSeries`. :py:class:`~pynwb.epoch.TimeIntervals` is a subclass of :py:class:`~hdmf.common.table.DynamicTable` which offers flexibility for tabular data by allowing the addition of optional columns which are not defined in the standard. Create a :py:class:`~pynwb.epoch.TimeIntervals` object that represents the time intervals when the animal was sleeping. .. GENERATED FROM PYTHON SOURCE LINES 300-315 .. code-block:: Python sleep_intervals = TimeIntervals( name="sleep_intervals", description="Intervals when the animal was sleeping.", ) sleep_intervals.add_column(name="stage", description="The stage of sleep.") sleep_intervals.add_row(start_time=0.3, stop_time=0.35, stage=1) sleep_intervals.add_row(start_time=0.7, stop_time=0.9, stage=2) sleep_intervals.add_row(start_time=1.3, stop_time=3.0, stage=3) nwbfile.add_time_intervals(sleep_intervals) .. raw:: html

sleep_intervals (TimeIntervals)

description: Intervals when the animal was sleeping.
columns
start_time
Start time of epoch, in seconds
stop_time
Stop time of epoch, in seconds
stage
The stage of sleep.
table
start_time stop_time stage
id
0 0.3 0.35 1
1 0.7 0.90 2
2 1.3 3.00 3


.. GENERATED FROM PYTHON SOURCE LINES 316-324 PupilTracking: Storing continuous eye-tracking data of pupil size ------------------------------------------------------------------- :py:class:`~pynwb.behavior.PupilTracking` is for storing eye-tracking data which represents pupil size. :py:class:`~pynwb.behavior.PupilTracking` holds one or more :py:class:`~pynwb.base.TimeSeries` objects that can represent different features such as the dilation of the pupil measured over time by a pupil tracking algorithm. .. GENERATED FROM PYTHON SOURCE LINES 324-337 .. code-block:: Python pupil_diameter = TimeSeries( name="pupil_diameter", description="Pupil diameter extracted from the video of the right eye.", data=np.linspace(0.001, 0.002, 50), timestamps=timestamps, unit="meters", ) pupil_tracking = PupilTracking(time_series=pupil_diameter, name="PupilTracking") behavior_module.add(pupil_tracking) .. raw:: html

PupilTracking

pupil_diameter (TimeSeries)
resolution: -1.0
comments: no comments
description: Pupil diameter extracted from the video of the right eye.
conversion: 1.0
offset: 0.0
unit: meters
data
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps_unit: seconds
interval: 1


.. GENERATED FROM PYTHON SOURCE LINES 338-346 EyeTracking: Storing continuous eye-tracking data of gaze direction ------------------------------------------------------------------- :py:class:`~pynwb.behavior.EyeTracking` is for storing eye-tracking data which represents direction of gaze as measured by an eye tracking algorithm. An :py:class:`~pynwb.behavior.EyeTracking` object holds one or more :py:class:`~pynwb.behavior.SpatialSeries` objects that represents the vertical and horizontal gaze positions extracted from a video. .. GENERATED FROM PYTHON SOURCE LINES 346-360 .. code-block:: Python right_eye_position = np.linspace(-20, 30, 50) right_eye_positions = SpatialSeries( name="right_eye_position", description="The position of the right eye measured in degrees.", data=right_eye_position, timestamps=timestamps, reference_frame="bottom left", unit="degrees", ) eye_tracking = EyeTracking(name="EyeTracking", spatial_series=right_eye_positions) .. GENERATED FROM PYTHON SOURCE LINES 361-363 We can add another :py:class:`~pynwb.behavior.SpatialSeries` representing the position of the left eye in degrees. .. GENERATED FROM PYTHON SOURCE LINES 363-380 .. code-block:: Python left_eye_position = np.linspace(-2, 20, 50) left_eye_positions = SpatialSeries( name="left_eye_position", description="The position of the left eye measured in degrees.", data=left_eye_position, timestamps=timestamps, reference_frame="bottom left", unit="degrees", ) eye_tracking.add_spatial_series(spatial_series=left_eye_positions) behavior_module.add(eye_tracking) .. raw:: html

EyeTracking

right_eye_position (SpatialSeries)
resolution: -1.0
comments: no comments
description: The position of the right eye measured in degrees.
conversion: 1.0
offset: 0.0
unit: degrees
data
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps_unit: seconds
interval: 1
reference_frame: bottom left
left_eye_position (SpatialSeries)
resolution: -1.0
comments: no comments
description: The position of the left eye measured in degrees.
conversion: 1.0
offset: 0.0
unit: degrees
data
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps
NumPy array
Data typefloat64
Shape(50,)
Array size400.00 bytes
timestamps_unit: seconds
interval: 1
reference_frame: bottom left


.. GENERATED FROM PYTHON SOURCE LINES 381-385 Writing the behavior data to an NWB file ---------------------------------------- As demonstrated in the :ref:`basic_writing` tutorial, we will use :py:class:`~pynwb.NWBHDF5IO` to write the file. .. GENERATED FROM PYTHON SOURCE LINES 385-389 .. code-block:: Python with NWBHDF5IO("behavioral_tutorial.nwb", "w") as io: io.write(nwbfile) .. GENERATED FROM PYTHON SOURCE LINES 390-400 Reading and accessing the behavior data --------------------------------------- To read the NWB file we just wrote, use another :py:class:`~pynwb.NWBHDF5IO` object, and use the :py:meth:`~pynwb.NWBHDF5IO.read` method to retrieve an :py:class:`~pynwb.file.NWBFile` object. We can access the behavior processing module by indexing ``nwbfile.processing`` with the name of the processing module ``"behavior"``. We can also inspect the objects hierarchy within this processing module with the ``.children`` attribute. .. GENERATED FROM PYTHON SOURCE LINES 400-407 .. code-block:: Python with NWBHDF5IO("behavioral_tutorial.nwb", "r") as io: read_nwbfile = io.read() behavior_module = read_nwbfile.processing["behavior"] print(f"Available data interfaces: {list(behavior_module.values())}") .. rst-class:: sphx-glr-script-out .. code-block:: none Available data interfaces: [BehavioralEpochs pynwb.behavior.BehavioralEpochs at 0x133102823270096 Fields: interval_series: { running , sleeping } , BehavioralTimeSeries pynwb.behavior.BehavioralTimeSeries at 0x133102823397840 Fields: time_series: { speed } , CompassDirection pynwb.behavior.CompassDirection at 0x133102755182160 Fields: spatial_series: { SpatialSeries } , EyeTracking pynwb.behavior.EyeTracking at 0x133102823189456 Fields: spatial_series: { left_eye_position , right_eye_position } , Position pynwb.behavior.Position at 0x133102823186896 Fields: spatial_series: { SpatialSeries } , PupilTracking pynwb.behavior.PupilTracking at 0x133102748748624 Fields: time_series: { pupil_diameter } ] .. GENERATED FROM PYTHON SOURCE LINES 408-415 For instance, we can access the :py:class:`~pynwb.behavior.SpatialSeries` data by referencing the names of the objects in the hierarchy that contain it. We can access the :py:class:`~pynwb.behavior.Position` object inside the ``behavior`` processing module by indexing it with the name of the :py:class:`~pynwb.behavior.Position` object, ``"Position"``. Then, we can access the :py:class:`~pynwb.behavior.SpatialSeries` object inside the :py:class:`~pynwb.behavior.Position` object by indexing it with the name of the :py:class:`~pynwb.behavior.SpatialSeries` object, ``"SpatialSeries"``. .. GENERATED FROM PYTHON SOURCE LINES 415-421 .. code-block:: Python with NWBHDF5IO("behavioral_tutorial.nwb", "r") as io: read_nwbfile = io.read() print(read_nwbfile.processing["behavior"]["Position"]["SpatialSeries"]) .. rst-class:: sphx-glr-script-out .. code-block:: none SpatialSeries pynwb.behavior.SpatialSeries at 0x133102757816016 Fields: comments: no comments conversion: 1.0 data: description: Position (x, y) in an open field. interval: 1 offset: 0.0 reference_frame: (0,0) is bottom left corner resolution: -1.0 timestamps: timestamps_unit: seconds unit: meters .. GENERATED FROM PYTHON SOURCE LINES 422-426 Data arrays are read passively from the file. Accessing the ``data`` attribute of the :py:class:`~pynwb.behavior.SpatialSeries` object does not read the data values, but presents an HDF5 object that can be indexed to read data. You can use the ``[:]`` operator to read the entire data array into memory. .. GENERATED FROM PYTHON SOURCE LINES 426-431 .. code-block:: Python with NWBHDF5IO("behavioral_tutorial.nwb", "r") as io: read_nwbfile = io.read() print(read_nwbfile.processing["behavior"]["Position"]["SpatialSeries"].data[:]) .. rst-class:: sphx-glr-script-out .. code-block:: none [[ 0. 0. ] [ 0.20408163 0.16326531] [ 0.40816327 0.32653061] [ 0.6122449 0.48979592] [ 0.81632653 0.65306122] [ 1.02040816 0.81632653] [ 1.2244898 0.97959184] [ 1.42857143 1.14285714] [ 1.63265306 1.30612245] [ 1.83673469 1.46938776] [ 2.04081633 1.63265306] [ 2.24489796 1.79591837] [ 2.44897959 1.95918367] [ 2.65306122 2.12244898] [ 2.85714286 2.28571429] [ 3.06122449 2.44897959] [ 3.26530612 2.6122449 ] [ 3.46938776 2.7755102 ] [ 3.67346939 2.93877551] [ 3.87755102 3.10204082] [ 4.08163265 3.26530612] [ 4.28571429 3.42857143] [ 4.48979592 3.59183673] [ 4.69387755 3.75510204] [ 4.89795918 3.91836735] [ 5.10204082 4.08163265] [ 5.30612245 4.24489796] [ 5.51020408 4.40816327] [ 5.71428571 4.57142857] [ 5.91836735 4.73469388] [ 6.12244898 4.89795918] [ 6.32653061 5.06122449] [ 6.53061224 5.2244898 ] [ 6.73469388 5.3877551 ] [ 6.93877551 5.55102041] [ 7.14285714 5.71428571] [ 7.34693878 5.87755102] [ 7.55102041 6.04081633] [ 7.75510204 6.20408163] [ 7.95918367 6.36734694] [ 8.16326531 6.53061224] [ 8.36734694 6.69387755] [ 8.57142857 6.85714286] [ 8.7755102 7.02040816] [ 8.97959184 7.18367347] [ 9.18367347 7.34693878] [ 9.3877551 7.51020408] [ 9.59183673 7.67346939] [ 9.79591837 7.83673469] [10. 8. ]] .. GENERATED FROM PYTHON SOURCE LINES 432-434 Alternatively, you can read only a portion of the data by indexing or slicing into the ``data`` attribute just like if you were indexing or slicing a numpy array. .. GENERATED FROM PYTHON SOURCE LINES 434-438 .. code-block:: Python with NWBHDF5IO("behavioral_tutorial.nwb", "r") as io: read_nwbfile = io.read() print(read_nwbfile.processing["behavior"]["Position"]["SpatialSeries"].data[:2]) .. rst-class:: sphx-glr-script-out .. code-block:: none [[0. 0. ] [0.20408163 0.16326531]] .. _sphx_glr_download_tutorials_domain_plot_behavior.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_behavior.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_behavior.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_behavior.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_