diff --git a/docs/source/_static/html/tutorials/behavior.html b/docs/source/_static/html/tutorials/behavior.html
index 14c85489..f53a16ba 100644
--- a/docs/source/_static/html/tutorials/behavior.html
+++ b/docs/source/_static/html/tutorials/behavior.html
@@ -43,7 +43,7 @@
.S7 { margin: 3px 10px 5px 4px; padding: 0px; line-height: 25px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 20px; font-weight: 700; text-align: left; }
.S8 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 1px solid rgb(217, 217, 217); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 4px; padding: 6px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace, Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px; }
.S9 { border-left: 1px solid rgb(217, 217, 217); border-right: 1px solid rgb(217, 217, 217); border-top: 0px none rgb(33, 33, 33); border-bottom: 1px solid rgb(217, 217, 217); border-radius: 0px 0px 4px 4px; padding: 0px 45px 4px 13px; line-height: 18.004px; min-height: 0px; white-space: nowrap; color: rgb(33, 33, 33); font-family: Menlo, Monaco, Consolas, "Courier New", monospace, Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 14px; }
-.S10 { margin: 15px 10px 5px 4px; padding: 0px; line-height: 18px; min-height: 0px; white-space: pre-wrap; color: rgb(33, 33, 33); font-family: Helvetica, Arial, sans-serif, Helvetica, Arial, sans-serif; font-style: normal; font-size: 17px; font-weight: 700; text-align: left; }
Behavior Data
This tutorial will guide you in writing behavioral data to NWB.
Creating an NWB File
Create an NWBFile object with the required fields (session_description, identifier, and session_start_time) and additional metadata.
'session_description', 'mouse in open exploration',...
'identifier', 'Mouse5_Day3', ...
'session_start_time', datetime(2018, 4, 25, 2, 30, 3, 'TimeZone', 'local'), ...
'general_experimenter', 'My Name', ... % optional
'general_session_id', 'session_1234', ... % optional
'general_institution', 'University of My Institution', ... % optional
'general_related_publications', 'DOI:10.1016/j.neuron.2016.12.011'); % optional
Position: Storing position measured over time
position = types.core.Position();
position.add('SpatialSeries', position_spatial_series);
Create a Behavior Processing Module
Create a processing module called "behavior" for storing behavioral data in the NWBFile, then add the Position object to the processing module. behavior_processing_module = types.core.ProcessingModule('description', 'stores behavioral data.');
behavior_processing_module.add("Position", position);
nwb.processing.add("behavior", behavior_processing_module);
CompassDirection: Storing view angle measured over time
Analogous to how position can be stored, we can create a SpatialSeries object for representing the view angle of the subject. For direction data reference_frame indicates the zero direction, for instance in this case "straight ahead" is 0 radians.
view_angle_data = linspace(0, 4, 50);
direction_spatial_series = types.core.SpatialSeries( ...
'description', 'View angle of the subject measured in radians.', ...
'data', view_angle_data, ...
'timestamps', timestamps, ...
'reference_frame', 'straight ahead', ...
'data_unit', 'radians' ...
direction = types.core.CompassDirection();
direction.add('SpatialSeries', direction_spatial_series);
We can add a CompassDirection object to the behavior processing module the same way we have added the position data. behavior_processing_module.add('CompassDirection', direction);
BehaviorTimeSeries: Storing continuous behavior data
BehavioralTimeSeries is an interface for storing continuous behavior data, such as the speed of a subject. speed_data = linspace(0, 0.4, 50);
speed_time_series = types.core.TimeSeries( ...
'starting_time', 1.0, ... % NB: Important to set starting_time when using starting_time_rate
'starting_time_rate', 10.0, ... % Hz
'description', 'he speed of the subject measured over time.', ...
behavioral_time_series = types.core.BehavioralTimeSeries();
behavioral_time_series.add('speed', speed_time_series);
% Add behavioral_time_series to the processing module
behavior_processing_module.add('BehavioralTimeSeries', behavioral_time_series);
BehavioralEvents: Storing behavioral events
BehavioralEvents is an interface for storing behavioral events. We can use it for storing the timing and amount of rewards (e.g. water amount) or lever press times. reward_amount = [1.0, 1.5, 1.0, 1.5];
event_timestamps = [1.0, 2.0, 5.0, 6.0];
time_series = types.core.TimeSeries( ...
'data', reward_amount, ...
'timestamps', event_timestamps, ...
'description', 'The water amount the subject received as a reward.', ...
behavioral_events = types.core.BehavioralEvents();
behavioral_events.add('lever_presses', time_series);
% Add behavioral_events to the processing module
behavior_processing_module.add('BehavioralEvents', behavioral_events);
Storing only the timestamps of the events is possible with the ndx-events NWB extension. You can also add labels associated with the events with this extension. You can find information about installation and example usage here. BehavioralEpochs: Storing intervals of behavior data
BehavioralEpochs is for storing intervals of behavior data. BehavioralEpochs uses IntervalSeries to represent the time intervals. Create an IntervalSeries object that represents the time intervals when the animal was running. IntervalSeries uses 1 to indicate the beginning of an interval and -1 to indicate the end. run_intervals = types.core.IntervalSeries( ...
'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 = types.core.BehavioralEpochs();
behavioral_epochs.add('running', run_intervals);
sleep_intervals = types.core.IntervalSeries( ...
'description', 'Intervals when the animal was sleeping', ...
'data', [1, -1, 1, -1], ...
'timestamps', [15.0, 30.0, 60.0, 95.0] ...
behavioral_epochs.add('sleeping', sleep_intervals);
% Add behavioral_epochs to the processing module
behavior_processing_module.add('BehavioralEpochs', behavioral_epochs);
Another approach: TimeIntervals
sleep_intervals = types.core.TimeIntervals( ...
'description', 'Intervals when the animal was sleeping.', ...
'colnames', {'start_time', 'stop_time', 'stage'} ...
sleep_intervals.addRow('start_time', 0.3, 'stop_time', 0.35, 'stage', 1);
sleep_intervals.addRow('start_time', 0.7, 'stop_time', 0.9, 'stage', 2);
sleep_intervals.addRow('start_time', 1.3, 'stop_time', 3.0, 'stage', 3);
nwb.intervals.add('sleep_intervals', sleep_intervals);
EyeTracking: Storing continuous eye-tracking data of gaze direction
EyeTracking is for storing eye-tracking data which represents direction of gaze as measured by an eye tracking algorithm. An EyeTracking object holds one or more SpatialSeries objects that represent the gaze direction over time extracted from a video. eye_position_data = [linspace(-20, 30, 50); linspace(30, -20, 50)];
right_eye_position = types.core.SpatialSeries( ...
'description', 'The position of the right eye measured in degrees.', ...
'data', eye_position_data, ...
'starting_time', 1.0, ... % NB: Important to set starting_time when using starting_time_rate
'starting_time_rate', 50.0, ... % Hz
'reference_frame', '(0,0) is middle', ...
'data_unit', 'degrees' ...
left_eye_position = types.core.SpatialSeries( ...
'description', 'The position of the right eye measured in degrees.', ...
'data', eye_position_data, ...
'starting_time', 1.0, ... % NB: Important to set starting_time when using starting_time_rate
'starting_time_rate', 50.0, ... % Hz
'reference_frame', '(0,0) is middle', ...
'data_unit', 'degrees' ...
eye_tracking = types.core.EyeTracking();
eye_tracking.add('right_eye_position', right_eye_position);
eye_tracking.add('left_eye_position', left_eye_position);
behavior_processing_module.add('EyeTracking', eye_tracking);
PupilTracking: Storing continuous eye-tracking data of pupil size
PupilTracking is for storing eye-tracking data which represents pupil size. PupilTracking holds one or more TimeSeries objects that can represent different features such as the dilation of the pupil measured over time by a pupil tracking algorithm. pupil_diameter = types.core.TimeSeries( ...
'description', 'Pupil diameter extracted from the video of the right eye.', ...
'data', linspace(0.001, 0.002, 50), ...
'starting_time', 1.0, ... % NB: Important to set starting_time when using starting_time_rate
'starting_time_rate', 20.0, ... % Hz
'data_unit', 'meters' ...
pupil_tracking = types.core.PupilTracking();
pupil_tracking.add('pupil_diameter', pupil_diameter);
behavior_processing_module.add('PupilTracking', pupil_tracking);
Writing the behavior data to an NWB file
All of the above commands build an NWBFile object in-memory. To write this file, use nwbExport. % Save to tutorials/tutorial_nwb_files folder
nwbFilePath = misc.getTutorialNwbFilePath('behavior_tutorial.nwb');
nwbExport(nwb, nwbFilePath);
fprintf('Exported NWB file to "%s"\n', 'behavior_tutorial.nwb')
Exported NWB file to "behavior_tutorial.nwb"
-
-
-