Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions docs/source/_static/html/tutorials/behavior.html

Large diffs are not rendered by default.

50 changes: 25 additions & 25 deletions docs/source/_static/html/tutorials/intro.html

Large diffs are not rendered by default.

61 changes: 36 additions & 25 deletions docs/source/_static/html/tutorials/read_demo_dandihub.html

Large diffs are not rendered by default.

Binary file modified tutorials/behavior.mlx
Binary file not shown.
Binary file modified tutorials/intro.mlx
Binary file not shown.
36 changes: 18 additions & 18 deletions tutorials/private/mcode/behavior.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@
% |SpatialSeries|> objects.

position = types.core.Position();
position.spatialseries.set('SpatialSeries', position_spatial_series);
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 <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/Position.html
% |Position|> object to the processing module.

behavior_processing_module = types.core.ProcessingModule('description', 'stores behavioral data.');
behavior_processing_module.nwbdatainterface.set("Position", position);
nwb.processing.set("behavior", behavior_processing_module);
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 <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/SpatialSeries.html
% |SpatialSeries|> object for representing the view angle of the subject.
Expand All @@ -77,13 +77,13 @@
'data_unit', 'radians' ...
);
direction = types.core.CompassDirection();
direction.spatialseries.set('spatial_series', direction_spatial_series);
direction.add('SpatialSeries', direction_spatial_series);
%%
% We can add a <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/CompassDirection.html
% |CompassDirection|> object to the behavior processing module the same way we
% have added the position data.

behavior_processing_module.nwbdatainterface.set('CompassDirection', direction);
behavior_processing_module.add('CompassDirection', direction);
%% BehaviorTimeSeries: Storing continuous behavior data
% <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/BehavioralTimeSeries.html
% |BehavioralTimeSeries|> is an interface for storing continuous behavior data,
Expand All @@ -100,10 +100,10 @@
);

behavioral_time_series = types.core.BehavioralTimeSeries();
behavioral_time_series.timeseries.set('speed', speed_time_series);
behavioral_time_series.add('speed', speed_time_series);

% Add behavioral_time_series to the processing module
behavior_processing_module.nwbdatainterface.set('BehavioralTimeSeries', behavioral_time_series);
behavior_processing_module.add('BehavioralTimeSeries', behavioral_time_series);
%% BehavioralEvents: Storing behavioral events
% <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/BehavioralEvents.html
% |BehavioralEvents|> is an interface for storing behavioral events. We can use
Expand All @@ -121,10 +121,10 @@
);

behavioral_events = types.core.BehavioralEvents();
behavioral_events.timeseries.set('lever_presses', time_series);
behavioral_events.add('lever_presses', time_series);

% Add behavioral_events to the processing module
behavior_processing_module.nwbdatainterface.set('BehavioralEvents', behavioral_events);
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
Expand All @@ -146,7 +146,7 @@
);

behavioral_epochs = types.core.BehavioralEpochs();
behavioral_epochs.intervalseries.set('running', run_intervals);
behavioral_epochs.add('running', run_intervals);
%%
% You can add more than one <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/IntervalSeries.html
% |IntervalSeries|> to a <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/BehavioralEpochs.html
Expand All @@ -157,10 +157,10 @@
'data', [1, -1, 1, -1], ...
'timestamps', [15.0, 30.0, 60.0, 95.0] ...
);
behavioral_epochs.intervalseries.set('sleeping', sleep_intervals);
behavioral_epochs.add('sleeping', sleep_intervals);

% Add behavioral_epochs to the processing module
behavior_processing_module.nwbdatainterface.set('BehavioralEpochs', behavioral_epochs);
behavior_processing_module.add('BehavioralEpochs', behavioral_epochs);
% Another approach: TimeIntervals
% Using <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/TimeIntervals.html
% |TimeIntervals|> to represent time intervals is often preferred over <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/BehavioralEpochs.html
Expand All @@ -179,7 +179,7 @@
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.set('sleep_intervals', sleep_intervals);
nwb.intervals.add('sleep_intervals', sleep_intervals);
%% EyeTracking: Storing continuous eye-tracking data of gaze direction
% <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/EyeTracking.html
% |EyeTracking|> is for storing eye-tracking data which represents direction of
Expand Down Expand Up @@ -209,10 +209,10 @@
);

eye_tracking = types.core.EyeTracking();
eye_tracking.spatialseries.set('right_eye_position', right_eye_position);
eye_tracking.spatialseries.set('left_eye_position', left_eye_position);
eye_tracking.add('right_eye_position', right_eye_position);
eye_tracking.add('left_eye_position', left_eye_position);

behavior_processing_module.nwbdatainterface.set('EyeTracking', eye_tracking);
behavior_processing_module.add('EyeTracking', eye_tracking);
%% PupilTracking: Storing continuous eye-tracking data of pupil size
% <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/PupilTracking.html
% |PupilTracking|> is for storing eye-tracking data which represents pupil size.
Expand All @@ -230,9 +230,9 @@
);

pupil_tracking = types.core.PupilTracking();
pupil_tracking.timeseries.set('pupil_diameter', pupil_diameter);
pupil_tracking.add('pupil_diameter', pupil_diameter);

behavior_processing_module.nwbdatainterface.set('PupilTracking', pupil_tracking);
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 <https://matnwb.readthedocs.io/en/latest/pages/functions/nwbExport.html
Expand Down
11 changes: 5 additions & 6 deletions tutorials/private/mcode/intro.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
);

% Add the AnnotationSeries to the NWBFile's stimulus group
nwb.stimulus_presentation.set('Airpuffs', annotations)
nwb.stimulus_presentation.add('Airpuffs', annotations)
%% Behavior
% SpatialSeries and Position
% Many types of data have special data types in NWB. To store the spatial position
Expand Down Expand Up @@ -170,10 +170,10 @@

% add the Position object (that holds the SpatialSeries object) to the module
% and name the Position object "Position"
behavior_module.nwbdatainterface.set('Position', position);
behavior_module.add('Position', position);

% add the processing module to the NWBFile object, and name the processing module "behavior"
nwb.processing.set('behavior', behavior_module);
nwb.processing.add('behavior', behavior_module);
% Trials
% Trials are stored in a <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/TimeIntervals.html
% |*TimeIntervals*|> object which is a subclass of <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/hdmf_common/DynamicTable.html
Expand Down Expand Up @@ -207,7 +207,7 @@

% If you have multiple trials tables, you will need to use custom names for
% each one:
nwb.intervals.set('custom_intervals_table_name', trials);
nwb.intervals.add('custom_intervals_table_name', trials);
%% Write
% Now, to write the NWB file that we have built so far:

Expand All @@ -229,8 +229,7 @@
% |*Position*|> object contains our <https://matnwb.readthedocs.io/en/latest/pages/neurodata_types/core/SpatialSeries.html
% |*SpatialSeries*|> object named |'SpatialSeries'|.

read_spatial_series = read_nwbfile.processing.get('behavior'). ...
nwbdatainterface.get('Position').spatialseries.get('SpatialSeries')
read_spatial_series = read_nwbfile.processing.behavior.Position.SpatialSeries
% Reading Data
% Counter to normal MATLAB workflow, data arrays are read passively from the
% file. Calling |*read_spatial_series.data*| does not read the data values, but
Expand Down
25 changes: 15 additions & 10 deletions tutorials/private/mcode/read_demo_dandihub.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
% <https://nwb-overview.readthedocs.io/en/latest/file_read/file_read.html#reading-with-matnwb
% NWB Overview Documentation>
%% Download the Dataset
% Use the pre-installed |dandi| Python package to download the dataset to the
% user-local dandisets folder:
% Use the |dandi| Python package to download the dataset to the user-local dandisets
% folder. If you are running this livescript on DandiHub, the |dandi| package
% is already pre-installed. On a local environment, you need to install the |dandi|
% package in the python environment returned by running |pyenv()| in MATLAB. For
% more details on using Python from MATLAB, please refer to the <https://se.mathworks.com/help/matlab/matlab_external/install-supported-python-implementation.html
% MATLAB documentation>.

environment = "Local";
environment = "Local"; % Local or DandiHub
switch environment
case "DandiHub"
targetFolder = "/home/jovyan/dandisets/000004";
Expand All @@ -36,18 +40,19 @@

nwb.stimulus_presentation
%%
% This results shows us that |nwb.stimulus_presentation| is a |Set| object that
% contains a single data object called |StimulusPresentation|, which is an |OpticalSeries|
% neurodata type. Use the |get| method to return this |OpticalSeries|. |Set| objects
% store a collection of other NWB objects.
% This result shows that |nwb.stimulus_presentation| is a |Set| object. In MatNWB,
% a |Set| object stores a collection of other NWB objects. In this case, the |Set|
% contains a single data object named |StimulusPresentation|, which is of the
% |OpticalSeries| neurodata type. You can use dot notation of the form |Set.objectName|
% to access this |OpticalSeries|:

nwb.stimulus_presentation.get('StimulusPresentation')
nwb.stimulus_presentation.StimulusPresentation
%%
% |OpticalSeries| is a neurodata type that stores information about visual stimuli
% presented to subjects. This print out shows all of the attributes in the |OpticalSeries|
% object named |StimulusPresentation|. The images are stored in |StimulusPresentation.data|

StimulusImageData = nwb.stimulus_presentation.get('StimulusPresentation').data
StimulusImageData = nwb.stimulus_presentation.StimulusPresentation.data
%%
% When calling a data object directly, the data is not read but instead a |DataStub|
% is returned. This is because data is read "lazily" in MatNWB. Instead of reading
Expand All @@ -73,7 +78,7 @@
% arguments. We will use this approach to read all of the image display timestamps
% into memory.

stimulus_times = nwb.stimulus_presentation.get('StimulusPresentation').timestamps.load();
stimulus_times = nwb.stimulus_presentation.StimulusPresentation.timestamps.load();
%% Quick PSTH and raster
% Here, I will pull out spike times of a particular unit, align them to the
% image display times, and finally display the results.
Expand Down
Binary file modified tutorials/read_demo_dandihub.mlx
Binary file not shown.