diff --git a/tutorials/ecephys.mlx b/tutorials/ecephys.mlx index e8f63aab..ca95380d 100644 Binary files a/tutorials/ecephys.mlx and b/tutorials/ecephys.mlx differ diff --git a/tutorials/html/ecephys.html b/tutorials/html/ecephys.html index f7cc1abd..ec161ac2 100644 --- a/tutorials/html/ecephys.html +++ b/tutorials/html/ecephys.html @@ -104,7 +104,7 @@ Learn more! See the API documentation to learn what data types are available. MATLAB tutorials - Python tutorials

About This Tutorial

This tutorial describes storage of hypothetical data from extracellular electrophysiology experiments in NWB for the following data categories:

Before You Begin

It is recommended to first work through the Introduction to MatNWB tutorial, which demonstrates installing MatNWB and creating an NWB file with subject information, animal position, and trials, as well as writing and reading NWB files in MATLAB.
Important: The dimensions of timeseries data in MatNWB should be defined in the opposite order of how it is defined in the nwb-schemas. In NWB, time is always stored in the first dimension of the data, whereas in MatNWB time should be stored in the last dimension of the data. This is explained in more detail here: MatNWB <-> HDF5 Dimension Mapping.

Setting up the NWB File

An NWB file represents a single session of an experiment. Each file must have a session_description, identifier, and session_start_time. Create a new NWBFile object these required fields along with any additional metadata. In MatNWB, arguments are specified using MATLAB's keyword argument pair convention, where each argument name is followed by its value.
nwb = NwbFile( ...
'session_description', 'mouse in open exploration',...
'identifier', 'Mouse5_Day3', ...
'session_start_time', datetime(2018, 4, 25, 2, 30, 3, 'TimeZone', 'local'), ...
'timestamps_reference_time', datetime(2018, 4, 25, 3, 0, 45, 'TimeZone', 'local'), ...
'general_experimenter', 'Last Name, First 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
nwb
nwb =
NwbFile with properties: + Python tutorials

About This Tutorial

This tutorial describes storage of hypothetical data from extracellular electrophysiology experiments in NWB for the following data categories:
  • Raw voltage recording
  • Local field potential (LFP) and filtered electrical signals
  • Spike times

Before You Begin

It is recommended to first work through the Introduction to MatNWB tutorial, which demonstrates installing MatNWB and creating an NWB file with subject information, animal position, and trials, as well as writing and reading NWB files in MATLAB.
Important: The dimensions of timeseries data in MatNWB should be defined in the opposite order of how it is defined in the nwb-schemas. In NWB, time is always stored in the first dimension of the data, whereas in MatNWB time should be stored in the last dimension of the data. This is explained in more detail here: MatNWB <-> HDF5 Dimension Mapping.

Setting up the NWB File

An NWB file represents a single session of an experiment. Each file must have a session_description, identifier, and session_start_time. Create a new NWBFile object these required fields along with any additional metadata. In MatNWB, arguments are specified using MATLAB's keyword argument pair convention, where each argument name is followed by its value.
nwb = NwbFile( ...
'session_description', 'mouse in open exploration',...
'identifier', 'Mouse5_Day3', ...
'session_start_time', datetime(2018, 4, 25, 2, 30, 3, 'TimeZone', 'local'), ...
'timestamps_reference_time', datetime(2018, 4, 25, 3, 0, 45, 'TimeZone', 'local'), ...
'general_experimenter', 'Last Name, First 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
nwb
nwb =
NwbFile with properties: nwb_version: '2.7.0' file_create_date: [] @@ -155,899 +155,899 @@ stimulus_presentation: [0×1 types.untyped.Set] stimulus_templates: [0×1 types.untyped.Set] units: [] -

Electrode Information

In order to store extracellular electrophysiology data, you first must create an electrodes table describing the electrodes that generated this data. Extracellular electrodes are stored in an electrodes table, which is also a DynamicTable. electrodes has several required fields: x, y, z, impedance, location, filtering, and electrode_group.

Electrodes Table

Since this is a DynamicTable, we can add additional metadata fields. We will be adding a "label" column to the table.
numShanks = 4;
numChannelsPerShank = 3;
numChannels = numShanks * numChannelsPerShank;
 
electrodesDynamicTable = types.hdmf_common.DynamicTable(...
'colnames', {'location', 'group', 'group_name', 'label'}, ...
'description', 'all electrodes');
 
device = types.core.Device(...
'description', 'the best array', ...
'manufacturer', 'Probe Company 9000' ...
);
nwb.general_devices.set('array', device);
for iShank = 1:numShanks
shankGroupName = sprintf('shank%d', iShank);
electrodeGroup = types.core.ElectrodeGroup( ...
'description', sprintf('electrode group for %s', shankGroupName), ...
'location', 'brain area', ...
'device', types.untyped.SoftLink(device) ...
);
nwb.general_extracellular_ephys.set(shankGroupName, electrodeGroup);
for iElectrode = 1:numChannelsPerShank
electrodesDynamicTable.addRow( ...
'location', 'unknown', ...
'group', types.untyped.ObjectView(electrodeGroup), ...
'group_name', shankGroupName, ...
'label', sprintf('%s-electrode%d', shankGroupName, iElectrode));
end
end
electrodesDynamicTable.toTable() % Display the table
ans = 12×5 table
 idlocationgroupgroup_namelabel
10'unknown'1×1 ObjectView'shank1''shank1-electrode1'
21'unknown'1×1 ObjectView'shank1''shank1-electrode2'
32'unknown'1×1 ObjectView'shank1''shank1-electrode3'
43'unknown'1×1 ObjectView'shank2''shank2-electrode1'
54'unknown'1×1 ObjectView'shank2''shank2-electrode2'
65'unknown'1×1 ObjectView'shank2''shank2-electrode3'
76'unknown'1×1 ObjectView'shank3''shank3-electrode1'
87'unknown'1×1 ObjectView'shank3''shank3-electrode2'
98'unknown'1×1 ObjectView'shank3''shank3-electrode3'
109'unknown'1×1 ObjectView'shank4''shank4-electrode1'
1110'unknown'1×1 ObjectView'shank4''shank4-electrode2'
1211'unknown'1×1 ObjectView'shank4''shank4-electrode3'
nwb.general_extracellular_ephys_electrodes = electrodesDynamicTable;

Links

In the above loop, we create ElectrodeGroup objects. The electrodes table then uses an ObjectView in each row to link to the corresponding ElectrodeGroup object. An ObjectView is a construct that enables linking one neurodata type to another, allowing a neurodata type to reference another within the NWB file.

Recorded Extracellular Signals

Voltage data are stored using the ElectricalSeries class, a subclass of the TimeSeries class specialized for voltage data.

Referencing Electrodes

In order to create our ElectricalSeries object, we first need to reference a set of rows in the electrodes table to indicate which electrode (channel) each entry in the electrical series were recorded from. We will do this by creating a DynamicTableRegion, which is a type of link that allows you to reference specific rows of a DynamicTable, such as the electrodes table, using row indices.
Create a DynamicTableRegion that references all rows of the electrodes table.
electrode_table_region = types.hdmf_common.DynamicTableRegion( ...
'table', types.untyped.ObjectView(electrodesDynamicTable), ...
'description', 'all electrodes', ...
'data', (0:length(electrodesDynamicTable.id.data)-1)');

Raw Voltage Data

Now create an ElectricalSeries object to hold acquisition data collected during the experiment.
raw_electrical_series = types.core.ElectricalSeries( ...
'starting_time', 0.0, ... % seconds
'starting_time_rate', 30000., ... % Hz
'data', randn(numChannels, 3000), ... % nChannels x nTime
'electrodes', electrode_table_region, ...
'data_unit', 'volts');
This is the voltage data recorded directly from our electrodes, so it goes in the acquisition group.
nwb.acquisition.set('ElectricalSeries', raw_electrical_series);

Processed Extracellular Electrical Signals

LFP

LFP refers to data that has been low-pass filtered, typically below 300 Hz. This data may also be downsampled. Because it is filtered and potentially resampled, it is categorized as processed data. LFP data would also be stored in an ElectricalSeries. To help data analysis and visualization tools know that this ElectricalSeries object represents LFP data, we store it inside an LFP object and then place the LFP object in a ProcessingModule named 'ecephys'. This is analogous to how we stored the SpatialSeries object inside of a Position object and stored the Position object in a ProcessingModule named 'behavior' in the behavior tutorial
lfp_electrical_series = types.core.ElectricalSeries( ...
'starting_time', 0.0, ... % seconds
'starting_time_rate', 1000., ... % Hz
'data', randn(numChannels, 100), ... nChannels x nTime
'filtering', 'Low-pass filter at 300 Hz', ...
'electrodes', electrode_table_region, ...
'data_unit', 'volts');
 
lfp = types.core.LFP('ElectricalSeries', lfp_electrical_series);
 
ecephys_module = types.core.ProcessingModule(...
'description', 'extracellular electrophysiology');
 
ecephys_module.nwbdatainterface.set('LFP', lfp);
nwb.processing.set('ecephys', ecephys_module);

Other Types of Filtered Electrical Signals

If your acquired data is filtered for frequency ranges other than LFP—such as Gamma or Theta—you can store the result in an ElectricalSeries and encapsulate it within a FilteredEphys object instead of the LFP object.
% Generate filtered data
filtered_data = randn(50, 12); % 50 time points, 12 channels
filtered_data = permute(filtered_data, [2, 1]); % permute timeseries for matnwb
 
% Create an ElectricalSeries object
filtered_electrical_series = types.core.ElectricalSeries( ...
'description', 'Data filtered in the theta range', ...
'data', filtered_data, ...
'electrodes', electrode_table_region, ...
'filtering', 'Band-pass filtered between 4 and 8 Hz', ...
'starting_time', 0.0, ...
'starting_time_rate', 200.0 ...
);
 
% Create a FilteredEphys object and add the filtered electrical series
filtered_ephys = types.core.FilteredEphys();
filtered_ephys.electricalseries.set('FilteredElectricalSeries', filtered_electrical_series);
 
% Add the FilteredEphys object to the ecephys module
ecephys_module.nwbdatainterface.set('FilteredEphys', filtered_ephys);

Decomposition of LFP Data into Frequency Bands

In some cases, you may want to further process the LFP data and decompose the signal into different frequency bands for additional downstream analyses. You can then store the processed data from these spectral analyses using a DecompositionSeries object. This object allows you to include metadata about the frequency bands and metric used (e.g., power, phase, amplitude), as well as link the decomposed data to the original TimeSeries signal the data was derived from.
In this tutorial, the examples for FilteredEphys and DecompositionSeries may appear similar. However, the key difference is that DecompositionSeries is specialized for storing the results of spectral analyses of timeseries data in general, whereas FilteredEphys is defined specifically as a container for filtered electrical signals.
Note: When adding data to a DecompositionSeries, the data argument is assumed to be 3D where the first dimension is time, the second dimension is channels, and the third dimension is bands. As mentioned in the beginning of this tutorial, in MatNWB the data needs to be permuted because the dimensions are written to file in reverse order (See the dimensionMapNoDataPipes tutorial)
% Define the frequency bands of interest (in Hz):
band_names = {'theta'; 'beta'; 'gamma'};
band_mean = [8; 21; 55];
band_stdev = [2; 4.5; 12.5];
band_limits = [band_mean - 2*band_stdev, band_mean + 2*band_stdev];
 
% The bands should be added to the DecompositionSeries as a dynamic table
bands = table(band_names, band_mean, band_stdev, band_limits, ...
'VariableNames', {'band_names', 'band_mean', 'band_stdev', 'band_limits'})
bands = 3×4 table
 band_namesband_meanband_stdevband_limits
12
1'theta'82412
2'beta'214.50001230
3'gamma'5512.50003080
 
bands = util.table2nwb( bands );
 
% Generate random phase data for the demonstration.
phase_data = randn(50, 12, numel(band_names)); % 50 samples, 12 channels, 3 frequency bands
phase_data = permute(phase_data, [3,2,1]); % See dimensionMapNoDataPipes tutorial
 
decomp_series = types.core.DecompositionSeries(...
'data', phase_data, ...
'bands', bands, ...
'metric', 'phase', ...
'starting_time', 0.0, ... % seconds
'starting_time_rate', 1000.0, ... % Hz
'source_channels', electrode_table_region, ...
'source_timeseries', lfp_electrical_series);
 
% Add decomposition series to ecephys module
ecephys_module.nwbdatainterface.set('theta', decomp_series);

Spike Times and Extracellular Events

Sorted Spike Times

Spike times are stored in a Units table, a specialization of the DynamicTable class. The default Units table is located at /units in the HDF5 file. You can add columns to the Units table just like you did for electrodes and trials (see convertTrials). Here, we generate some random spike data and populate the table.
num_cells = 10;
spikes = cell(1, num_cells);
for iShank = 1:num_cells
spikes{iShank} = rand(1, randi([16, 28]));
end
spikes
spikes = 1×10 cell
 12345678910
11×24 double1×28 double1×22 double1×28 double1×21 double1×26 double1×16 double1×18 double1×24 double1×24 double

Ragged Arrays

Spike times are an example of a ragged array- it's like a matrix, but each row has a different number of elements. We can represent this type of data as an indexed column of the Units table. These indexed columns have two components, the VectorData object that holds the data and the VectorIndex object that holds the indices in the vector that indicate the row breaks. You can use the convenience function util.create_indexed_column to create these objects. For more information about ragged arrays, we refer you to the "Ragged Array Columns" section of the dynamic table tutorial.
[spike_times_vector, spike_times_index] = util.create_indexed_column(spikes);
 
nwb.units = types.core.Units( ...
'colnames', {'spike_times'}, ...
'description', 'units table', ...
'spike_times', spike_times_vector, ...
'spike_times_index', spike_times_index ...
);
 
nwb.units.toTable
ans = 10×2 table
 idspike_times
1124×1 double
2228×1 double
3322×1 double
4428×1 double
5521×1 double
6626×1 double
7716×1 double
8818×1 double
9924×1 double
101024×1 double

Unsorted Spike Times

While the Units table is used to store spike times and waveform data for spike-sorted, single-unit activity, you may also want to store spike times and waveform snippets of unsorted spiking activity. This is useful for recording multi-unit activity detected via threshold crossings during data acquisition. Such information can be stored using SpikeEventSeries objects.
% In the SpikeEventSeries the dimensions should be ordered as
% [num_events, num_channels, num_samples].
% Define spike snippets: 20 events, 3 channels, 40 samples per event.
spike_snippets = rand(20, 3, 40);
% Permute spike snippets (See dimensionMapNoDataPipes tutorial)
spike_snippets = permute(spike_snippets, [3,2,1])
spike_snippets =
spike_snippets(:,:,1) = - - 0.7910 0.0213 0.8335 - 0.8083 0.5109 0.0694 - 0.0414 0.1315 0.9237 - 0.6840 0.0158 0.8003 - 0.9652 0.0518 0.6909 - 0.4137 0.6962 0.6477 - 0.7065 0.4276 0.1037 - 0.0327 0.2995 0.3123 - 0.5643 0.7282 0.7042 - 0.3009 0.8131 0.9222 - 0.1623 0.8546 0.4080 - 0.3810 0.7375 0.5178 - 0.1005 0.8742 0.2635 - 0.9530 0.3118 0.5444 - 0.0115 0.0973 0.5146 - 0.1436 0.2857 0.3713 - 0.5966 0.3174 0.4652 - 0.0131 0.8012 0.6369 - 0.4585 0.6484 0.6865 - 0.5535 0.1510 0.3442 - 0.0254 0.5062 0.8555 - 0.7063 0.5182 0.6404 - 0.3815 0.1169 0.1685 - 0.8255 0.1120 0.3037 - 0.1461 0.4718 0.1424 - 0.8712 0.8092 0.7453 - 0.3177 0.3974 0.9020 - 0.4894 0.6920 0.5508 - 0.1267 0.0666 0.8641 - 0.9720 0.7211 0.6973 - 0.8166 0.9120 0.1665 - 0.4227 0.3168 0.6086 - 0.0780 0.9907 0.1200 - 0.0661 0.3271 0.7940 - 0.8019 0.9782 0.7975 - 0.4981 0.6964 0.9912 - 0.5068 0.4475 0.9353 - 0.4478 0.6194 0.5117 - 0.8898 0.5428 0.7175 - 0.8606 0.2924 0.9609 +

Electrode Information

In order to store extracellular electrophysiology data, you first must create an electrodes table describing the electrodes that generated this data. Extracellular electrodes are stored in an electrodes table, which is also a DynamicTable. electrodes has several required fields: x, y, z, impedance, location, filtering, and electrode_group.

Electrodes Table

Since this is a DynamicTable, we can add additional metadata fields. We will be adding a "label" column to the table.
numShanks = 4;
numChannelsPerShank = 3;
numChannels = numShanks * numChannelsPerShank;
 
electrodesDynamicTable = types.hdmf_common.DynamicTable(...
'colnames', {'location', 'group', 'group_name', 'label'}, ...
'description', 'all electrodes');
 
device = types.core.Device(...
'description', 'the best array', ...
'manufacturer', 'Probe Company 9000' ...
);
nwb.general_devices.set('array', device);
for iShank = 1:numShanks
shankGroupName = sprintf('shank%d', iShank);
electrodeGroup = types.core.ElectrodeGroup( ...
'description', sprintf('electrode group for %s', shankGroupName), ...
'location', 'brain area', ...
'device', types.untyped.SoftLink(device) ...
);
nwb.general_extracellular_ephys.set(shankGroupName, electrodeGroup);
for iElectrode = 1:numChannelsPerShank
electrodesDynamicTable.addRow( ...
'location', 'unknown', ...
'group', types.untyped.ObjectView(electrodeGroup), ...
'group_name', shankGroupName, ...
'label', sprintf('%s-electrode%d', shankGroupName, iElectrode));
end
end
electrodesDynamicTable.toTable() % Display the table
ans = 12×5 table
 idlocationgroupgroup_namelabel
10'unknown'1×1 ObjectView'shank1''shank1-electrode1'
21'unknown'1×1 ObjectView'shank1''shank1-electrode2'
32'unknown'1×1 ObjectView'shank1''shank1-electrode3'
43'unknown'1×1 ObjectView'shank2''shank2-electrode1'
54'unknown'1×1 ObjectView'shank2''shank2-electrode2'
65'unknown'1×1 ObjectView'shank2''shank2-electrode3'
76'unknown'1×1 ObjectView'shank3''shank3-electrode1'
87'unknown'1×1 ObjectView'shank3''shank3-electrode2'
98'unknown'1×1 ObjectView'shank3''shank3-electrode3'
109'unknown'1×1 ObjectView'shank4''shank4-electrode1'
1110'unknown'1×1 ObjectView'shank4''shank4-electrode2'
1211'unknown'1×1 ObjectView'shank4''shank4-electrode3'
nwb.general_extracellular_ephys_electrodes = electrodesDynamicTable;

Links

In the above loop, we create ElectrodeGroup objects. The electrodes table then uses an ObjectView in each row to link to the corresponding ElectrodeGroup object. An ObjectView is a construct that enables linking one neurodata type to another, allowing a neurodata type to reference another within the NWB file.

Recorded Extracellular Signals

Voltage data are stored using the ElectricalSeries class, a subclass of the TimeSeries class specialized for voltage data.

Referencing Electrodes

In order to create our ElectricalSeries object, we first need to reference a set of rows in the electrodes table to indicate which electrode (channel) each entry in the electrical series were recorded from. We will do this by creating a DynamicTableRegion, which is a type of link that allows you to reference specific rows of a DynamicTable, such as the electrodes table, using row indices.
Create a DynamicTableRegion that references all rows of the electrodes table.
electrode_table_region = types.hdmf_common.DynamicTableRegion( ...
'table', types.untyped.ObjectView(electrodesDynamicTable), ...
'description', 'all electrodes', ...
'data', (0:length(electrodesDynamicTable.id.data)-1)');

Raw Voltage Data

Now create an ElectricalSeries object to hold acquisition data collected during the experiment.
raw_electrical_series = types.core.ElectricalSeries( ...
'starting_time', 0.0, ... % seconds
'starting_time_rate', 30000., ... % Hz
'data', randn(numChannels, 3000), ... % nChannels x nTime
'electrodes', electrode_table_region, ...
'data_unit', 'volts');
This is the voltage data recorded directly from our electrodes, so it goes in the acquisition group.
nwb.acquisition.set('ElectricalSeries', raw_electrical_series);

Processed Extracellular Electrical Signals

LFP

LFP refers to data that has been low-pass filtered, typically below 300 Hz. This data may also be downsampled. Because it is filtered and potentially resampled, it is categorized as processed data. LFP data would also be stored in an ElectricalSeries. To help data analysis and visualization tools know that this ElectricalSeries object represents LFP data, we store it inside an LFP object and then place the LFP object in a ProcessingModule named 'ecephys'. This is analogous to how we stored the SpatialSeries object inside of a Position object and stored the Position object in a ProcessingModule named 'behavior' in the behavior tutorial
lfp_electrical_series = types.core.ElectricalSeries( ...
'starting_time', 0.0, ... % seconds
'starting_time_rate', 1000., ... % Hz
'data', randn(numChannels, 100), ... nChannels x nTime
'filtering', 'Low-pass filter at 300 Hz', ...
'electrodes', electrode_table_region, ...
'data_unit', 'volts');
 
lfp = types.core.LFP('ElectricalSeries', lfp_electrical_series);
 
ecephys_module = types.core.ProcessingModule(...
'description', 'extracellular electrophysiology');
 
ecephys_module.nwbdatainterface.set('LFP', lfp);
nwb.processing.set('ecephys', ecephys_module);

Other Types of Filtered Electrical Signals

If your acquired data is filtered for frequency ranges other than LFP—such as Gamma or Theta—you can store the result in an ElectricalSeries and encapsulate it within a FilteredEphys object instead of the LFP object.
% Generate filtered data
filtered_data = randn(50, 12); % 50 time points, 12 channels
filtered_data = permute(filtered_data, [2, 1]); % permute timeseries for matnwb
 
% Create an ElectricalSeries object
filtered_electrical_series = types.core.ElectricalSeries( ...
'description', 'Data filtered in the theta range', ...
'data', filtered_data, ...
'electrodes', electrode_table_region, ...
'filtering', 'Band-pass filtered between 4 and 8 Hz', ...
'starting_time', 0.0, ...
'starting_time_rate', 200.0 ...
);
 
% Create a FilteredEphys object and add the filtered electrical series
filtered_ephys = types.core.FilteredEphys();
filtered_ephys.electricalseries.set('FilteredElectricalSeries', filtered_electrical_series);
 
% Add the FilteredEphys object to the ecephys module
ecephys_module.nwbdatainterface.set('FilteredEphys', filtered_ephys);

Decomposition of LFP Data into Frequency Bands

In some cases, you may want to further process the LFP data and decompose the signal into different frequency bands for additional downstream analyses. You can then store the processed data from these spectral analyses using a DecompositionSeries object. This object allows you to include metadata about the frequency bands and metric used (e.g., power, phase, amplitude), as well as link the decomposed data to the original TimeSeries signal the data was derived from.
In this tutorial, the examples for FilteredEphys and DecompositionSeries may appear similar. However, the key difference is that DecompositionSeries is specialized for storing the results of spectral analyses of timeseries data in general, whereas FilteredEphys is defined specifically as a container for filtered electrical signals.
Note: When adding data to a DecompositionSeries, the data argument is assumed to be 3D where the first dimension is time, the second dimension is channels, and the third dimension is bands. As mentioned in the beginning of this tutorial, in MatNWB the data needs to be permuted because the dimensions are written to file in reverse order (See the dimensionMapNoDataPipes tutorial)
% Define the frequency bands of interest (in Hz):
band_names = {'theta'; 'beta'; 'gamma'};
band_mean = [8; 21; 55];
band_stdev = [2; 4.5; 12.5];
band_limits = [band_mean - 2*band_stdev, band_mean + 2*band_stdev];
 
% The bands should be added to the DecompositionSeries as a dynamic table
bands = table(band_names, band_mean, band_stdev, band_limits, ...
'VariableNames', {'band_name', 'band_mean', 'band_stdev', 'band_limits'})
bands = 3×4 table
 band_nameband_meanband_stdevband_limits
12
1'theta'82412
2'beta'214.50001230
3'gamma'5512.50003080
 
bands = util.table2nwb( bands );
 
% Generate random phase data for the demonstration.
phase_data = randn(50, 12, numel(band_names)); % 50 samples, 12 channels, 3 frequency bands
phase_data = permute(phase_data, [3,2,1]); % See dimensionMapNoDataPipes tutorial
 
decomp_series = types.core.DecompositionSeries(...
'data', phase_data, ...
'bands', bands, ...
'metric', 'phase', ...
'starting_time', 0.0, ... % seconds
'starting_time_rate', 1000.0, ... % Hz
'source_channels', electrode_table_region, ...
'source_timeseries', lfp_electrical_series);
 
% Add decomposition series to ecephys module
ecephys_module.nwbdatainterface.set('theta', decomp_series);

Spike Times and Extracellular Events

Sorted Spike Times

Spike times are stored in a Units table, a specialization of the DynamicTable class. The default Units table is located at /units in the HDF5 file. You can add columns to the Units table just like you did for electrodes and trials (see convertTrials). Here, we generate some random spike data and populate the table.
num_cells = 10;
spikes = cell(1, num_cells);
for iShank = 1:num_cells
spikes{iShank} = rand(1, randi([16, 28]));
end
spikes
spikes = 1×10 cell
 12345678910
11×24 double1×19 double1×20 double1×25 double1×22 double1×20 double1×22 double1×17 double1×21 double1×25 double

Ragged Arrays

Spike times are an example of a ragged array- it's like a matrix, but each row has a different number of elements. We can represent this type of data as an indexed column of the Units table. These indexed columns have two components, the VectorData object that holds the data and the VectorIndex object that holds the indices in the vector that indicate the row breaks. You can use the convenience function util.create_indexed_column to create these objects. For more information about ragged arrays, we refer you to the "Ragged Array Columns" section of the dynamic table tutorial.
[spike_times_vector, spike_times_index] = util.create_indexed_column(spikes);
 
nwb.units = types.core.Units( ...
'colnames', {'spike_times'}, ...
'description', 'units table', ...
'spike_times', spike_times_vector, ...
'spike_times_index', spike_times_index ...
);
 
nwb.units.toTable
ans = 10×2 table
 idspike_times
1124×1 double
2219×1 double
3320×1 double
4425×1 double
5522×1 double
6620×1 double
7722×1 double
8817×1 double
9921×1 double
101025×1 double

Unsorted Spike Times

While the Units table is used to store spike times and waveform data for spike-sorted, single-unit activity, you may also want to store spike times and waveform snippets of unsorted spiking activity. This is useful for recording multi-unit activity detected via threshold crossings during data acquisition. Such information can be stored using SpikeEventSeries objects.
% In the SpikeEventSeries the dimensions should be ordered as
% [num_events, num_channels, num_samples].
% Define spike snippets: 20 events, 3 channels, 40 samples per event.
spike_snippets = rand(20, 3, 40);
% Permute spike snippets (See dimensionMapNoDataPipes tutorial)
spike_snippets = permute(spike_snippets, [3,2,1])
spike_snippets =
spike_snippets(:,:,1) = + + 0.3732 0.7791 0.5937 + 0.7586 0.8887 0.6501 + 0.3051 0.4772 0.4288 + 0.4012 0.5913 0.3957 + 0.3939 0.3286 0.1415 + 0.5662 0.5443 0.2179 + 0.9869 0.4951 0.4386 + 0.7861 0.9518 0.4311 + 0.6751 0.4070 0.1629 + 0.4426 0.5435 0.8580 + 0.0396 0.6455 0.9119 + 0.9309 0.4391 0.6281 + 0.2086 0.5926 0.6285 + 0.9404 0.2170 0.2241 + 0.5310 0.3074 0.9547 + 0.3391 0.8501 0.5889 + 0.0462 0.7716 0.8651 + 0.0262 0.6235 0.9419 + 0.8849 0.0555 0.4975 + 0.4348 0.8429 0.5563 + 0.3528 0.4937 0.8508 + 0.5342 0.9424 0.9996 + 0.5746 0.0628 0.8755 + 0.4744 0.8553 0.9244 + 0.7230 0.6936 0.2125 + 0.4087 0.2393 0.7200 + 0.2982 0.4357 0.2804 + 0.1524 0.7107 0.3372 + 0.9375 0.9103 0.1958 + 0.7425 0.0687 0.4879 + 0.2087 0.0370 0.0393 + 0.1920 0.2053 0.4417 + 0.1422 0.4232 0.1870 + 0.8810 0.7692 0.7563 + 0.1456 0.9029 0.5702 + 0.2523 0.1514 0.7324 + 0.4195 0.4896 0.2667 + 0.3307 0.6090 0.6230 + 0.1701 0.9241 0.5880 + 0.5319 0.0420 0.6809 spike_snippets(:,:,2) = - 0.5338 0.3753 0.6193 - 0.1517 0.6080 0.1663 - 0.1934 0.6342 0.9882 - 0.9244 0.8932 0.3000 - 0.8507 0.4194 0.6482 - 0.5106 0.1159 0.7561 - 0.1162 0.3095 0.9177 - 0.9806 0.6443 0.8760 - 0.0513 0.4850 0.9481 - 0.8886 0.2191 0.6419 - 0.6883 0.4286 0.8974 - 0.8499 0.5069 0.4643 - 0.9019 0.3152 0.4006 - 0.2973 0.4501 0.0411 - 0.2026 0.1939 0.9824 - 0.6041 0.2842 0.5462 - 0.9371 0.5834 0.8635 - 0.4799 0.6260 0.2953 - 0.5238 0.7532 0.8461 - 0.6517 0.7502 0.3512 - 0.4229 0.1752 0.1634 - 0.7366 0.7801 0.9180 - 0.1957 0.2408 0.3131 - 0.9544 0.5748 0.1483 - 0.8544 0.0117 0.7080 - 0.7467 0.9576 0.2643 - 0.5438 0.0537 0.0843 - 0.9563 0.6243 0.4454 - 0.5092 0.1294 0.3496 - 0.4297 0.4393 0.2485 - 0.4890 0.8836 0.6625 - 0.1389 0.4318 0.3081 - 0.1869 0.0011 0.4418 - 0.9201 0.4152 0.0008 - 0.4235 0.6870 0.1545 - 0.9545 0.0976 0.9682 - 0.7207 0.6316 0.7971 - 0.9008 0.5584 0.7311 - 0.1453 0.9232 0.3198 - 0.5304 0.4056 0.1549 + 0.6946 0.9867 0.1621 + 0.2072 0.7996 0.6578 + 0.7396 0.9594 0.2076 + 0.5369 0.8403 0.3706 + 0.3963 0.8120 0.9353 + 0.0532 0.0624 0.7060 + 0.1420 0.1284 0.4933 + 0.9286 0.5055 0.6835 + 0.3156 0.7733 0.3820 + 0.4400 0.2803 0.6084 + 0.2611 0.6750 0.0324 + 0.0603 0.6302 0.9327 + 0.3091 0.1783 0.3724 + 0.5451 0.6656 0.4110 + 0.1974 0.1752 0.6761 + 0.9598 0.3204 0.7998 + 0.7463 0.9291 0.1296 + 0.1828 0.4812 0.6270 + 0.7885 0.1908 0.7519 + 0.1154 0.7749 0.6845 + 0.5216 0.3994 0.9655 + 0.2219 0.3672 0.2583 + 0.4704 0.8092 0.4067 + 0.9942 0.0751 0.1858 + 0.2373 0.5807 0.9973 + 0.6321 0.7136 0.1707 + 0.4648 0.7071 0.1290 + 0.6359 0.6416 0.3091 + 0.1669 0.8553 0.1380 + 0.7639 0.3221 0.2149 + 0.0145 0.3226 0.4020 + 0.5560 0.0633 0.2573 + 0.6934 0.7846 0.9890 + 0.5472 0.7723 0.0297 + 0.7413 0.4124 0.4747 + 0.9513 0.8615 0.3798 + 0.8774 0.0074 0.0822 + 0.2707 0.2008 0.6769 + 0.9066 0.2487 0.3473 + 0.9031 0.5947 0.2998 spike_snippets(:,:,3) = - 0.5092 0.9115 0.6848 - 0.0370 0.3598 0.5459 - 0.8909 0.2320 0.6210 - 0.1415 0.3598 0.3532 - 0.6650 0.7777 0.2036 - 0.0845 0.7893 0.6989 - 0.8263 0.5907 0.7732 - 0.7758 0.9209 0.6862 - 0.6141 0.4780 0.6086 - 0.4845 0.5522 0.5599 - 0.9572 0.1676 0.3414 - 0.1539 0.5025 0.8494 - 0.6809 0.5092 0.8636 - 0.9649 0.6492 0.5732 - 0.3245 0.6510 0.9502 - 0.3759 0.3767 0.4420 - 0.7450 0.5653 0.0341 - 0.8066 0.5285 0.6691 - 0.7006 0.0285 0.2575 - 0.4817 0.5484 0.8613 - 0.2185 0.3218 0.5705 - 0.4282 0.1795 0.8811 - 0.3090 0.8398 0.6193 - 0.0477 0.4053 0.8866 - 0.1156 0.5851 0.2542 - 0.8462 0.0158 0.3698 - 0.4941 0.9994 0.2657 - 0.6635 0.6725 0.1791 - 0.8944 0.2112 0.0403 - 0.3573 0.8075 0.2363 - 0.0931 0.0854 0.2321 - 0.4501 0.9337 0.2882 - 0.5619 0.6824 0.8621 - 0.5455 0.0936 0.0346 - 0.4649 0.7467 0.8067 - 0.0441 0.9981 0.1671 - 0.1436 0.4552 0.5099 - 0.9111 0.4916 0.9271 - 0.1548 0.1222 0.4906 - 0.3945 0.8146 0.5500 + 0.5451 0.8070 0.3206 + 0.6928 0.4280 0.8321 + 0.6805 0.9535 0.2361 + 0.2666 0.1868 0.4845 + 0.9815 0.7233 0.8900 + 0.7260 0.8210 0.3314 + 0.3164 0.7107 0.6713 + 0.4181 0.4670 0.0010 + 0.9741 0.2856 0.7074 + 0.4238 0.8375 0.8412 + 0.9819 0.8191 0.0949 + 0.4364 0.9326 0.4354 + 0.7310 0.9098 0.4869 + 0.4943 0.9199 0.3313 + 0.6452 0.6932 0.7494 + 0.0505 0.9546 0.9591 + 0.1264 0.4607 0.1279 + 0.9333 0.0234 0.7867 + 0.3341 0.3857 0.6957 + 0.7642 0.1095 0.0429 + 0.9580 0.4884 0.6948 + 0.6084 0.5523 0.8079 + 0.5066 0.6660 0.3920 + 0.0327 0.7744 0.8886 + 0.9240 0.5647 0.0658 + 0.5356 0.0641 0.7811 + 0.4054 0.5640 0.4154 + 0.9789 0.5963 0.8608 + 0.5668 0.1509 0.3670 + 0.7025 0.9988 0.9933 + 0.8613 0.4405 0.1464 + 0.1041 0.7715 0.3392 + 0.3661 0.3882 0.5087 + 0.7465 0.0436 0.0087 + 0.3572 0.4768 0.0233 + 0.9081 0.2854 0.6945 + 0.2392 0.3414 0.6361 + 0.6355 0.0123 0.6029 + 0.8906 0.9561 0.0998 + 0.8724 0.4231 0.8791 spike_snippets(:,:,4) = - 0.8651 0.0729 0.5703 - 0.7056 0.7361 0.0422 - 0.7220 0.4867 0.8848 - 0.7563 0.2299 0.4345 - 0.1388 0.6244 0.1856 - 0.4175 0.1199 0.3165 - 0.0970 0.6949 0.4674 - 0.6304 0.8521 0.2420 - 0.5424 0.2486 0.6067 - 0.1731 0.3253 0.6955 - 0.6922 0.3908 0.0253 - 0.3011 0.2044 0.2150 - 0.6281 0.9983 0.8887 - 0.5463 0.3738 0.2357 - 0.1263 0.2581 0.0286 - 0.5020 0.1082 0.0744 - 0.2669 0.0954 0.5680 - 0.3439 0.2201 0.8495 - 0.6176 0.9906 0.6916 - 0.2697 0.4133 0.1197 - 0.5944 0.7802 0.2287 - 0.4447 0.7085 0.0679 - 0.1947 0.6754 0.9432 - 0.4714 0.0661 0.0817 - 0.5271 0.9569 0.9435 - 0.8597 0.6655 0.0351 - 0.8275 0.0531 0.2852 - 0.2070 0.3484 0.4845 - 0.9358 0.0522 0.7680 - 0.6787 0.3460 0.3718 - 0.2934 0.3135 0.0939 - 0.9152 0.4345 0.1295 - 0.3650 0.2472 0.3402 - 0.1528 0.6372 0.5485 - 0.5785 0.9504 0.9111 - 0.5069 0.9808 0.3079 - 0.3256 0.3353 0.1383 - 0.5329 0.4452 0.8509 - 0.1127 0.6844 0.8668 - 0.7811 0.1499 0.4629 + 0.4854 0.2021 0.4178 + 0.1042 0.0572 0.5235 + 0.7787 0.8715 0.3109 + 0.0947 0.2513 0.3742 + 0.4724 0.0945 0.4348 + 0.7312 0.1811 0.7789 + 0.1908 0.4436 0.7879 + 0.3579 0.8552 0.1141 + 0.4405 0.4878 0.4577 + 0.7250 0.3002 0.0478 + 0.4961 0.2143 0.2460 + 0.3935 0.5856 0.3734 + 0.4304 0.8539 0.6590 + 0.4677 0.2888 0.9005 + 0.6995 0.0156 0.3576 + 0.8153 0.7794 0.9313 + 0.6333 0.6757 0.7350 + 0.5318 0.6517 0.2361 + 0.8009 0.7342 0.3832 + 0.2961 0.9837 0.3576 + 0.2021 0.9876 0.7297 + 0.9424 0.2764 0.0504 + 0.1479 0.1211 0.1844 + 0.4527 0.4286 0.2950 + 0.4787 0.1957 0.8230 + 0.4661 0.1299 0.0478 + 0.4762 0.0754 0.6567 + 0.4106 0.8626 0.7855 + 0.2155 0.7685 0.4191 + 0.8953 0.0073 0.6560 + 0.2029 0.2695 0.3976 + 0.1809 0.4246 0.5822 + 0.9363 0.5071 0.9302 + 0.3073 0.1328 0.5443 + 0.6552 0.0491 0.8480 + 0.3227 0.3559 0.1201 + 0.0361 0.0332 0.5380 + 0.0322 0.5357 0.4574 + 0.8864 0.4393 0.4757 + 0.3848 0.2086 0.7510 spike_snippets(:,:,5) = - 0.9833 0.1306 0.1439 - 0.2656 0.5451 0.9737 - 0.5678 0.3446 0.3483 - 0.0967 0.0733 0.2677 - 0.2653 0.9260 0.8876 - 0.3652 0.3403 0.3428 - 0.7242 0.2202 0.3057 - 0.8023 0.8464 0.9116 - 0.2288 0.7517 0.9695 - 0.7929 0.6289 0.9108 - 0.5254 0.5371 0.8497 - 0.9644 0.9208 0.5796 - 0.3907 0.0955 0.7351 - 0.8862 0.8287 0.5880 - 0.3508 0.8420 0.7759 - 0.9350 0.8327 0.3354 - 0.3336 0.4643 0.3187 - 0.3489 0.0708 0.8605 - 0.6006 0.7239 0.3991 - 0.3062 0.9719 0.1192 - 0.6141 0.9838 0.1967 - 0.0040 0.5215 0.8946 - 0.2364 0.0775 0.0065 - 0.7518 0.9408 0.8491 - 0.7013 0.8655 0.8282 - 0.9326 0.1311 0.8476 - 0.1252 0.0149 0.3416 - 0.9947 0.6125 0.6894 - 0.1763 0.6221 0.2775 - 0.7586 0.2494 0.6819 - 0.9048 0.7648 0.0505 - 0.2789 0.3761 0.7825 - 0.1195 0.3080 0.1136 - 0.3286 0.8026 0.9635 - 0.5285 0.2380 0.6579 - 0.4777 0.2527 0.4029 - 0.6137 0.4510 0.4112 - 0.3054 0.5817 0.7277 - 0.5103 0.9052 0.9271 - 0.8229 0.1610 0.4064 + 0.1860 0.0536 0.5940 + 0.2376 0.8684 0.8130 + 0.1716 0.3393 0.4770 + 0.0312 0.1379 0.6187 + 0.3256 0.6297 0.1215 + 0.8935 0.3748 0.4845 + 0.6420 0.1018 0.4572 + 0.1572 0.6465 0.1285 + 0.7944 0.8081 0.1087 + 0.3353 0.1870 0.9674 + 0.3222 0.3932 0.3531 + 0.8497 0.5727 0.3463 + 0.6986 0.6426 0.5585 + 0.7362 0.5711 0.3389 + 0.1066 0.8356 0.3358 + 0.9519 0.5272 0.1312 + 0.0989 0.9641 0.3374 + 0.5441 0.7474 0.6270 + 0.9346 0.6895 0.6218 + 0.7645 0.7542 0.8233 + 0.0604 0.9699 0.0417 + 0.1195 0.0637 0.8807 + 0.4555 0.7875 0.7380 + 0.3830 0.6953 0.0521 + 0.0568 0.6954 0.6580 + 0.3506 0.4798 0.0857 + 0.2994 0.7058 0.4222 + 0.3651 0.4766 0.6714 + 0.6819 0.1449 0.8841 + 0.7518 0.6569 0.8799 + 0.4554 0.0071 0.1870 + 0.1671 0.5957 0.8323 + 0.7819 0.1208 0.0767 + 0.5283 0.8852 0.1754 + 0.4018 0.9644 0.2548 + 0.3075 0.7336 0.8771 + 0.8817 0.0490 0.6314 + 0.9053 0.7864 0.7232 + 0.3306 0.1048 0.3259 + 0.4217 0.0060 0.3249 spike_snippets(:,:,6) = - 0.3054 0.2779 0.6491 - 0.5022 0.0909 0.5466 - 0.2294 0.5000 0.8570 - 0.4042 0.5115 0.9431 - 0.4964 0.2149 0.5783 - 0.4703 0.1227 0.4063 - 0.7156 0.5084 0.0977 - 0.1685 0.6039 0.9440 - 0.5246 0.4176 0.6435 - 0.1973 0.8868 0.0968 - 0.3190 0.5694 0.8356 - 0.9508 0.3955 0.3049 - 0.7104 0.8199 0.1919 - 0.5505 0.9165 0.1106 - 0.5106 0.9105 0.6328 - 0.1722 0.1372 0.2181 - 0.4067 0.5448 0.6478 - 0.9696 0.4703 0.5263 - 0.1818 0.4216 0.7169 - 0.2094 0.2752 0.8469 - 0.4900 0.4156 0.5015 - 0.9689 0.3503 0.3427 - 0.4425 0.7213 0.7925 - 0.1208 0.9218 0.1758 - 0.5253 0.4974 0.9133 - 0.5050 0.1665 0.3859 - 0.3676 0.0337 0.0437 - 0.9110 0.8914 0.5112 - 0.4501 0.4358 0.3669 - 0.8307 0.5862 0.6017 - 0.2800 0.0028 0.3824 - 0.9934 0.6645 0.1911 - 0.1871 0.5665 0.4545 - 0.5104 0.4363 0.3587 - 0.4477 0.1140 0.2533 - 0.0078 0.4282 0.6347 - 0.6320 0.1487 0.7152 - 0.4901 0.3613 0.0225 - 0.0841 0.3465 0.2337 - 0.2430 0.2622 0.4275 + 0.3607 0.6747 0.2823 + 0.8019 0.7234 0.6816 + 0.9769 0.9206 0.9695 + 0.8595 0.1186 0.5267 + 0.8213 0.5041 0.7992 + 0.6864 0.4441 0.3328 + 0.4342 0.7906 0.7966 + 0.2791 0.6789 0.6589 + 0.0677 0.1800 0.8605 + 0.9977 0.6627 0.8032 + 0.6905 0.0662 0.9176 + 0.6056 0.3628 0.2537 + 0.3349 0.6504 0.4738 + 0.3405 0.3380 0.9896 + 0.9532 0.6461 0.2478 + 0.6151 0.3351 0.3112 + 0.9391 0.4259 0.4215 + 0.1135 0.2030 0.1276 + 0.6935 0.5926 0.5615 + 0.9860 0.1078 0.4081 + 0.8066 0.0918 0.1500 + 0.3176 0.4185 0.3038 + 0.5564 0.0260 0.1120 + 0.2822 0.2521 0.1910 + 0.5111 0.1336 0.9303 + 0.9938 0.0073 0.2631 + 0.9386 0.2338 0.9264 + 0.8758 0.3476 0.6830 + 0.0299 0.3936 0.0800 + 0.5553 0.8059 0.5107 + 0.5919 0.3904 0.7407 + 0.3952 0.6322 0.8418 + 0.0015 0.1364 0.9954 + 0.6989 0.2713 0.1460 + 0.1746 0.6716 0.0101 + 0.3299 0.8212 0.8991 + 0.2970 0.9432 0.8047 + 0.9798 0.9383 0.8505 + 0.4682 0.5601 0.8434 + 0.4084 0.6759 0.9916 spike_snippets(:,:,7) = - 0.5203 0.4307 0.6524 - 0.7971 0.7307 0.9649 - 0.5900 0.5683 0.7583 - 0.4517 0.9439 0.4560 - 0.7591 0.4558 0.7293 - 0.5660 0.1464 0.6991 - 0.4934 0.6237 0.6178 - 0.8066 0.6757 0.4065 - 0.1988 0.2131 0.3927 - 0.9253 0.1590 0.2406 - 0.4513 0.2735 0.8884 - 0.3209 0.9513 0.4656 - 0.1497 0.7329 0.8223 - 0.8818 0.5569 0.8199 - 0.1966 0.0080 0.8479 - 0.2544 0.0254 0.1438 - 0.9411 0.2648 0.6022 - 0.9904 0.3270 0.8801 - 0.5011 0.0608 0.7151 - 0.4306 0.5025 0.6970 - 0.7600 0.0648 0.6352 - 0.8428 0.1614 0.4374 - 0.7337 0.1432 0.7528 - 0.7799 0.2674 0.2795 - 0.1125 0.0389 0.7427 - 0.6235 0.6113 0.4224 - 0.8652 0.3020 0.7012 - 0.0585 0.2901 0.6066 - 0.2551 0.6485 0.6733 - 0.3578 0.4431 0.8841 - 0.3194 0.8011 0.5885 - 0.8658 0.1362 0.9775 - 0.7267 0.8782 0.1815 - 0.9021 0.1424 0.9340 - 0.1541 0.2204 0.2235 - 0.3263 0.9738 0.1737 - 0.8442 0.1610 0.1785 - 0.0902 0.4908 0.3965 - 0.9395 0.1451 0.8357 - 0.5820 0.4252 0.1027 + 0.0571 0.8938 0.2892 + 0.3651 0.2947 0.0883 + 0.0048 0.5505 0.2311 + 0.0752 0.5008 0.0071 + 0.1115 0.1171 0.3412 + 0.2859 0.2660 0.7362 + 0.8617 0.7911 0.6713 + 0.7250 0.9561 0.2437 + 0.3928 0.7430 0.5275 + 0.4087 0.4779 0.9706 + 0.1443 0.3129 0.7893 + 0.5913 0.3437 0.1562 + 0.4039 0.9153 0.6639 + 0.1441 0.5124 0.6560 + 0.8561 0.5080 0.9686 + 0.4229 0.9691 0.2507 + 0.2713 0.5633 0.6792 + 0.0239 0.2525 0.9951 + 0.4989 0.3135 0.1867 + 0.6718 0.8556 0.8071 + 0.8666 0.1969 0.1976 + 0.1018 0.3002 0.1270 + 0.3555 0.5716 0.8467 + 0.7235 0.7092 0.0841 + 0.1264 0.0393 0.0440 + 0.7326 0.2412 0.5221 + 0.0684 0.3701 0.9379 + 0.3814 0.2398 0.9121 + 0.8694 0.0473 0.1581 + 0.5230 0.8057 0.0546 + 0.5274 0.3905 0.7978 + 0.2959 0.0482 0.5761 + 0.3504 0.3914 0.5200 + 0.8993 0.2229 0.4167 + 0.0838 0.4613 0.7469 + 0.8273 0.6824 0.5753 + 0.8421 0.8724 0.1875 + 0.3069 0.7149 0.9203 + 0.8881 0.0453 0.7021 + 0.8480 0.5593 0.0597 spike_snippets(:,:,8) = - 0.1236 0.6511 0.1434 - 0.6919 0.8788 0.5315 - 0.0110 0.2866 0.2883 - 0.6653 0.3658 0.7295 - 0.3830 0.3836 0.1894 - 0.0792 0.4844 0.6232 - 0.0429 0.0815 0.0893 - 0.9189 0.4935 0.6753 - 0.9430 0.6922 0.1165 - 0.6600 0.5560 0.4981 - 0.7278 0.3105 0.6180 - 0.2455 0.8558 0.8068 - 0.1648 0.5900 0.8158 - 0.7264 0.2944 0.9467 - 0.5387 0.3136 0.4850 - 0.2455 0.0724 0.9675 - 0.9792 0.7856 0.1285 - 0.0151 0.3191 0.4051 - 0.7201 0.2710 0.8689 - 0.6860 0.1948 0.5062 - 0.8377 0.2674 0.8979 - 0.3805 0.7267 0.2665 - 0.2113 0.5110 0.2891 - 0.2075 0.1331 0.1577 - 0.5781 0.8387 0.8078 - 0.0374 0.8755 0.9759 - 0.0858 0.7683 0.4930 - 0.9413 0.4375 0.2516 - 0.4598 0.0071 0.5345 - 0.3385 0.2310 0.6649 - 0.8964 0.7416 0.8791 - 0.9074 0.5103 0.8058 - 0.0780 0.2104 0.6698 - 0.1535 0.9910 0.7050 - 0.2712 0.3049 0.6195 - 0.0698 0.8990 0.2976 - 0.5451 0.3134 0.1452 - 0.6226 0.0632 0.5848 - 0.3860 0.4139 0.0877 - 0.2459 0.3314 0.7027 + 0.5469 0.2381 0.3206 + 0.1442 0.0464 0.9169 + 0.8726 0.4046 0.1317 + 0.3666 0.0378 0.7042 + 0.1399 0.5182 0.1363 + 0.9368 0.7287 0.7152 + 0.7624 0.0543 0.3947 + 0.7231 0.4113 0.6290 + 0.4949 0.3340 0.8478 + 0.6423 0.7035 0.9309 + 0.6111 0.9467 0.7805 + 0.0830 0.3386 0.1138 + 0.6171 0.0343 0.6772 + 0.5062 0.2758 0.3346 + 0.3766 0.5560 0.6250 + 0.1964 0.1594 0.8136 + 0.2617 0.4583 0.1110 + 0.0918 0.6463 0.7804 + 0.9457 0.4661 0.8166 + 0.1252 0.4231 0.8606 + 0.7374 0.7485 0.3757 + 0.1418 0.2033 0.9158 + 0.4184 0.0849 0.9580 + 0.4020 0.1756 0.7954 + 0.3852 0.2716 0.4669 + 0.4989 0.4680 0.5607 + 0.2454 0.1776 0.6862 + 0.0040 0.4639 0.3231 + 0.0427 0.0131 0.4277 + 0.3237 0.7697 0.2445 + 0.2296 0.8780 0.5891 + 0.4673 0.3589 0.6978 + 0.9605 0.5383 0.8642 + 0.6235 0.9730 0.8974 + 0.8655 0.3656 0.7443 + 0.2165 0.9781 0.7558 + 0.8414 0.3375 0.1513 + 0.6390 0.4023 0.5663 + 0.2621 0.5162 0.0405 + 0.8289 0.3021 0.8460 spike_snippets(:,:,9) = - 0.1862 0.3166 0.5625 - 0.6883 0.8583 0.6659 - 0.8207 0.2343 0.7708 - 0.4771 0.9836 0.6667 - 0.9927 0.8793 0.5623 - 0.5524 0.3897 0.6021 - 0.0158 0.0147 0.6756 - 0.5509 0.3765 0.1045 - 0.0319 0.8561 0.6120 - 0.6078 0.8196 0.1573 - 0.8092 0.9058 0.8133 - 0.1753 0.4625 0.3167 - 0.7093 0.0153 0.8247 - 0.0031 0.9350 0.7074 - 0.7463 0.7795 0.7193 - 0.6112 0.7431 0.8335 - 0.1113 0.7544 0.5980 - 0.1001 0.0113 0.5878 - 0.7874 0.3017 0.8858 - 0.3490 0.6528 0.4592 - 0.2282 0.9735 0.8830 - 0.5118 0.8896 0.5627 - 0.8384 0.6445 0.6133 - 0.7058 0.5834 0.9355 - 0.8892 0.4049 0.2107 - 0.7051 0.1832 0.5109 - 0.9029 0.6395 0.3890 - 0.2350 0.2461 0.1438 - 0.4924 0.8447 0.9080 - 0.3103 0.9046 0.0424 - 0.0415 0.4561 0.1136 - 0.9019 0.4703 0.8842 - 0.5687 0.0371 0.4397 - 0.1593 0.0056 0.3861 - 0.6538 0.0122 0.3605 - 0.1895 0.2687 0.9563 - 0.4757 0.9230 0.5992 - 0.5058 0.0182 0.8989 - 0.7973 0.6793 0.1926 - 0.9365 0.5756 0.1470 + 0.4691 0.7988 0.0529 + 0.9929 0.6395 0.6071 + 0.7489 0.2541 0.8289 + 0.0846 0.9819 0.9793 + 0.9771 0.4078 0.9797 + 0.8538 0.5584 0.8525 + 0.4623 0.2815 0.8258 + 0.6717 0.7234 0.3825 + 0.3005 0.7018 0.5217 + 0.0373 0.3626 0.3260 + 0.2694 0.0014 0.9328 + 0.0935 0.4851 0.9782 + 0.9277 0.7393 0.8915 + 0.4584 0.3471 0.7444 + 0.6188 0.9747 0.5640 + 0.9186 0.2859 0.3740 + 0.5948 0.5343 0.3207 + 0.9418 0.8765 0.9253 + 0.8842 0.1309 0.4301 + 0.3234 0.3499 0.1663 + 0.2283 0.5276 0.5893 + 0.3362 0.4110 0.4571 + 0.1672 0.0150 0.1694 + 0.5063 0.6239 0.0191 + 0.9739 0.8482 0.7000 + 0.9642 0.0519 0.1061 + 0.3678 0.6110 0.6649 + 0.2460 0.7439 0.6566 + 0.0136 0.4706 0.7010 + 0.8887 0.1154 0.8915 + 0.4598 0.1088 0.0265 + 0.4780 0.0377 0.1051 + 0.6038 0.4467 0.5940 + 0.5292 0.5928 0.9708 + 0.4460 0.6881 0.8970 + 0.3750 0.5452 0.6821 + 0.7657 0.2439 0.3457 + 0.9692 0.2747 0.4023 + 0.5081 0.2458 0.8449 + 0.2699 0.1724 0.6493 spike_snippets(:,:,10) = - 0.6774 0.8672 0.3929 - 0.7508 0.8390 0.1819 - 0.8385 0.0982 0.1049 - 0.8561 0.8053 0.5929 - 0.6299 0.8493 0.1438 - 0.4487 0.6291 0.9145 - 0.3847 0.4643 0.3373 - 0.5404 0.7072 0.0958 - 0.4907 0.5549 0.8605 - 0.7538 0.9238 0.0707 - 0.6480 0.6550 0.8500 - 0.2106 0.1632 0.5082 - 0.2997 0.4515 0.2181 - 0.5225 0.6085 0.4031 - 0.7164 0.0671 0.2393 - 0.4219 0.8559 0.8960 - 0.2255 0.7409 0.2879 - 0.1748 0.2214 0.3755 - 0.6444 0.8154 0.7101 - 0.8884 0.4719 0.3015 - 0.9329 0.2244 0.2333 - 0.9767 0.3629 0.4684 - 0.8712 0.7563 0.3301 - 0.1827 0.6614 0.8416 - 0.7168 0.9171 0.7254 - 0.0646 0.5612 0.5675 - 0.5051 0.9097 0.6379 - 0.6441 0.4000 0.2584 - 0.3448 0.8788 0.3373 - 0.7757 0.0176 0.1728 - 0.7208 0.7215 0.9140 - 0.2416 0.7711 0.6687 - 0.9054 0.5785 0.7456 - 0.0335 0.1418 0.4057 - 0.9318 0.0209 0.8280 - 0.4995 0.5503 0.6516 - 0.5591 0.8762 0.9773 - 0.4354 0.9011 0.0860 - 0.2329 0.4244 0.1117 - 0.0895 0.3846 0.8654 + 0.2646 0.4643 0.9420 + 0.2981 0.8982 0.9420 + 0.9444 0.8127 0.2281 + 0.0019 0.9399 0.6619 + 0.8383 0.3594 0.0589 + 0.3812 0.7412 0.3856 + 0.0461 0.3143 0.6805 + 0.2631 0.5349 0.8362 + 0.6679 0.2794 0.0747 + 0.6365 0.1144 0.1717 + 0.9935 0.8025 0.8176 + 0.2022 0.7851 0.6757 + 0.4380 0.6696 0.4313 + 0.6085 0.2422 0.5570 + 0.1107 0.3251 0.0433 + 0.9562 0.5477 0.2331 + 0.7087 0.1371 0.4938 + 0.7187 0.5549 0.4971 + 0.5788 0.5722 0.0299 + 0.6707 0.4923 0.2003 + 0.6433 0.4343 0.4186 + 0.4536 0.4802 0.5284 + 0.8884 0.5167 0.3753 + 0.7600 0.1937 0.3257 + 0.2230 0.4037 0.1190 + 0.6195 0.8798 0.7132 + 0.6905 0.4647 0.3077 + 0.2035 0.4971 0.3984 + 0.2586 0.8970 0.0824 + 0.3915 0.7657 0.8055 + 0.1682 0.0791 0.8345 + 0.0808 0.8050 0.3915 + 0.2290 0.9915 0.2723 + 0.1630 0.0845 0.3458 + 0.2780 0.0904 0.4128 + 0.2752 0.0924 0.5610 + 0.1138 0.8468 0.0026 + 0.1058 0.0355 0.9058 + 0.7652 0.2477 0.4562 + 0.9184 0.5650 0.4295 spike_snippets(:,:,11) = - 0.8347 0.4022 0.6120 - 0.3468 0.5189 0.4033 - 0.2546 0.6819 0.0986 - 0.7404 0.1464 0.7471 - 0.6433 0.2989 0.8645 - 0.9926 0.0527 0.3949 - 0.9637 0.2744 0.2190 - 0.7971 0.7036 0.4778 - 0.4520 0.5440 0.6679 - 0.3244 0.4465 0.5489 - 0.9640 0.3327 0.7965 - 0.5527 0.1972 0.7607 - 0.2490 0.6106 0.3055 - 0.8834 0.5081 0.0499 - 0.2723 0.1501 0.9294 - 0.2521 0.5971 0.5519 - 0.7322 0.9338 0.7382 - 0.0855 0.8082 0.5566 - 0.7416 0.1892 0.5572 - 0.2958 0.9147 0.6783 - 0.0851 0.4890 0.4612 - 0.3550 0.0450 0.2096 - 0.1819 0.2133 0.5934 - 0.9579 0.1414 0.7223 - 0.4275 0.6274 0.9427 - 0.0523 0.0421 0.6497 - 0.0685 0.9755 0.6641 - 0.5790 0.6845 0.7101 - 0.7696 0.1755 0.2687 - 0.7507 0.4235 0.1038 - 0.6559 0.8909 0.1183 - 0.6514 0.9716 0.1036 - 0.9478 0.7154 0.0593 - 0.7043 0.2236 0.8412 - 0.3663 0.5732 0.0736 - 0.1300 0.3943 0.1802 - 0.6451 0.1573 0.4161 - 0.8897 0.7446 0.7855 - 0.3715 0.4903 0.6490 - 0.5015 0.5459 0.3932 + 0.3360 0.2768 0.2706 + 0.5883 0.5018 0.6218 + 0.5947 0.7284 0.9354 + 0.5599 0.6084 0.1978 + 0.9211 0.8140 0.0545 + 0.7966 0.8976 0.2581 + 0.3007 0.5282 0.5474 + 0.8500 0.4486 0.2071 + 0.0512 0.4022 0.9222 + 0.6838 0.6349 0.0706 + 0.9257 0.6698 0.5748 + 0.2152 0.5339 0.8961 + 0.6102 0.5816 0.3377 + 0.3648 0.6726 0.8777 + 0.2972 0.3565 0.8838 + 0.2829 0.7476 0.3734 + 0.9157 0.7164 0.6893 + 0.8746 0.0111 0.0486 + 0.1815 0.0744 0.1274 + 0.8996 0.0554 0.3310 + 0.9089 0.8892 0.4710 + 0.2577 0.9764 0.5696 + 0.9031 0.9686 0.5731 + 0.7543 0.8753 0.5673 + 0.0123 0.9955 0.3922 + 0.5084 0.7922 0.4345 + 0.4505 0.1746 0.2203 + 0.7865 0.5427 0.2527 + 0.5117 0.9445 0.8626 + 0.4887 0.1589 0.7124 + 0.2850 0.8352 0.5718 + 0.0180 0.3309 0.5588 + 0.5399 0.5011 0.8363 + 0.4116 0.7307 0.3184 + 0.5524 0.4636 0.5660 + 0.7529 0.1027 0.1108 + 0.6302 0.5957 0.6093 + 0.0836 0.9445 0.1758 + 0.0951 0.9562 0.2351 + 0.0849 0.0117 0.7479 spike_snippets(:,:,12) = - 0.8950 0.7784 0.3370 - 0.3776 0.8958 0.1258 - 0.2153 0.5221 0.4411 - 0.9188 0.6917 0.9823 - 0.0532 0.3541 0.2336 - 0.6066 0.7796 0.6442 - 0.7270 0.2461 0.5945 - 0.2519 0.4929 0.5494 - 0.0581 0.7809 0.5255 - 0.2975 0.1215 0.7106 - 0.8214 0.1294 0.1760 - 0.4632 0.9377 0.6688 - 0.2908 0.8853 0.7457 - 0.1076 0.5625 0.0337 - 0.0972 0.5536 0.1822 - 0.1280 0.7994 0.4142 - 0.1412 0.1745 0.7949 - 0.3290 0.2348 0.6860 - 0.7861 0.2603 0.6156 - 0.4999 0.3998 0.9619 - 0.2821 0.8703 0.1428 - 0.9904 0.9902 0.9319 - 0.7028 0.0983 0.1120 - 0.8319 0.1780 0.2330 - 0.2656 0.7303 0.3022 - 0.9044 0.4930 0.4198 - 0.6919 0.8411 0.3521 - 0.1977 0.5059 0.4959 - 0.8080 0.3110 0.4749 - 0.7690 0.1746 0.0756 - 0.5096 0.2501 0.1510 - 0.9853 0.4394 0.0432 - 0.2593 0.5565 0.1624 - 0.9890 0.5731 0.9597 - 0.9599 0.0753 0.2030 - 0.5933 0.8058 0.7752 - 0.6314 0.7114 0.8213 - 0.8363 0.0528 0.3939 - 0.4076 0.7217 0.5043 - 0.1097 0.2343 0.2508 + 0.8269 0.0684 0.4439 + 0.7323 0.1734 0.0751 + 0.6568 0.2218 0.2693 + 0.5686 0.5931 0.7554 + 0.8733 0.5064 0.8141 + 0.6172 0.8727 0.9094 + 0.0136 0.5690 0.1943 + 0.8223 0.9764 0.9327 + 0.0876 0.5534 0.0578 + 0.3906 0.9969 0.1656 + 0.2662 0.9741 0.8474 + 0.2071 0.9988 0.7772 + 0.6265 0.1958 0.3806 + 0.2814 0.7539 0.9439 + 0.6970 0.4425 0.1954 + 0.5497 0.7827 0.0818 + 0.9411 0.2419 0.0642 + 0.3968 0.5786 0.3247 + 0.5858 0.5023 0.4566 + 0.4175 0.2451 0.5167 + 0.3272 0.8763 0.9273 + 0.9850 0.8327 0.0031 + 0.8648 0.6048 0.2515 + 0.7225 0.9099 0.5846 + 0.5928 0.7970 0.9333 + 0.9333 0.4034 0.3905 + 0.7934 0.0362 0.6215 + 0.6854 0.4067 0.6295 + 0.3693 0.6808 0.0589 + 0.2698 0.8693 0.6090 + 0.0236 0.6264 0.6358 + 0.7969 0.6779 0.1526 + 0.1936 1.0000 0.0233 + 0.4508 0.3273 0.7223 + 0.9213 0.7523 0.2685 + 0.3340 0.4351 0.9825 + 0.8270 0.3205 0.1033 + 0.4581 0.7766 0.6554 + 0.1236 0.8837 0.3875 + 0.3160 0.4216 0.8846 spike_snippets(:,:,13) = - 0.2949 0.5202 0.1211 - 0.5566 0.5845 0.5552 - 0.0722 0.6373 0.8406 - 0.9252 0.0517 0.5231 - 0.4902 0.5120 0.9631 - 0.2890 0.4406 0.8756 - 0.8333 0.0660 0.7129 - 0.7859 0.1514 0.2913 - 0.0624 0.2431 0.4692 - 0.9129 0.6801 0.7586 - 0.9633 0.8651 0.4898 - 0.9800 0.8840 0.2424 - 0.1020 0.8982 0.5261 - 0.6766 0.0988 0.9697 - 0.2313 0.1582 0.4006 - 0.0004 0.3593 0.5432 - 0.7084 0.5084 0.4525 - 0.7881 0.0612 0.4665 - 0.9016 0.5683 0.2416 - 0.9231 0.7142 0.3431 - 0.3189 0.6186 0.6160 - 0.5037 0.2760 0.5419 - 0.0237 0.7551 0.1368 - 0.6520 0.7281 0.4271 - 0.2760 0.1216 0.5721 - 0.8475 0.6912 0.3738 - 0.7810 0.0934 0.3155 - 0.6271 0.8286 0.1854 - 0.1149 0.9365 0.5787 - 0.7695 0.1150 0.0557 - 0.5477 0.5701 0.2503 - 0.4269 0.0165 0.1992 - 0.4939 0.9138 0.8500 - 0.9287 0.8734 0.5062 - 0.7151 0.2187 0.0008 - 0.2543 0.6974 0.4274 - 0.9483 0.7896 0.6908 - 0.7255 0.8452 0.2864 - 0.0348 0.5217 0.1593 - 0.5899 0.3122 0.1772 + 0.3545 0.3870 0.0442 + 0.0984 0.6191 0.7319 + 0.4817 0.1129 0.7033 + 0.2747 0.7700 0.5511 + 0.9428 0.1419 0.6388 + 0.4259 0.8899 0.2468 + 0.5116 0.7886 0.0778 + 0.4094 0.0737 0.5975 + 0.5140 0.1224 0.4620 + 0.5372 0.0651 0.4016 + 0.6660 0.9459 0.3132 + 0.4055 0.3468 0.6925 + 0.3096 0.0933 0.2572 + 0.4144 0.0373 0.5043 + 0.9139 0.3029 0.4919 + 0.3319 0.8805 0.7918 + 0.7234 0.9948 0.1098 + 0.0170 0.1829 0.1256 + 0.2830 0.1492 0.3176 + 0.2600 0.7454 0.1790 + 0.9421 0.7018 0.4925 + 0.4013 0.3687 0.5861 + 0.5564 0.1115 0.6931 + 0.5644 0.5759 0.5131 + 0.7829 0.3622 0.5733 + 0.4672 0.1752 0.3412 + 0.6831 0.0186 0.9405 + 0.6730 0.2138 0.3973 + 0.6319 0.7183 0.0820 + 0.5931 0.5956 0.3570 + 0.5988 0.1654 0.1494 + 0.5480 0.1904 0.6582 + 0.9045 0.6122 0.3443 + 0.4664 0.2166 0.3314 + 0.0590 0.6913 0.4432 + 0.6690 0.9421 0.0179 + 0.5997 0.5471 0.8197 + 0.9114 0.1852 0.7625 + 0.7377 0.3112 0.3322 + 0.1051 0.0307 0.9699 spike_snippets(:,:,14) = - 0.9771 0.4050 0.7480 - 0.0164 0.7490 0.3865 - 0.3992 0.3380 0.2018 - 0.4467 0.0394 0.6368 - 0.7589 0.7476 0.6173 - 0.3515 0.3967 0.4286 - 0.2178 0.9765 0.7002 - 0.8223 0.9313 0.6389 - 0.5271 0.3603 0.2278 - 0.6464 0.5478 0.1317 - 0.4060 0.4718 0.9555 - 0.0270 0.4830 0.8491 - 0.0169 0.4543 0.9645 - 0.3327 0.7379 0.5937 - 0.9158 0.2060 0.9178 - 0.7765 0.1282 0.4284 - 0.3668 0.5960 0.5725 - 0.8509 0.0220 0.6117 - 0.3111 0.9309 0.9131 - 0.6934 0.8826 0.2040 - 0.2483 0.4454 0.1425 - 0.5874 0.7093 0.7173 - 0.8735 0.5988 0.0476 - 0.0763 0.7666 0.8454 - 0.1493 0.6608 0.4174 - 0.5494 0.2831 0.4819 - 0.4071 0.2351 0.8550 - 0.7085 0.9237 0.4157 - 0.7682 0.6375 0.0323 - 0.0196 0.1156 0.2325 - 1.0000 0.7195 0.4628 - 0.1514 0.4361 0.4644 - 0.9657 0.9117 0.4204 - 0.6568 0.0403 0.5068 - 0.8954 0.0092 0.2470 - 0.0665 1.0000 0.5583 - 0.8023 0.3161 0.5107 - 0.4888 0.3307 0.9941 - 0.6054 0.8640 0.4672 - 0.3619 0.9700 0.5930 + 0.8738 0.2539 0.5170 + 0.2402 0.9058 0.8826 + 0.5606 0.2673 0.7385 + 0.4901 0.1698 0.0661 + 0.9379 0.7687 0.2550 + 0.3886 0.8274 0.8461 + 0.6457 0.2094 0.0937 + 0.1621 0.3068 0.3773 + 0.5236 0.8581 0.4598 + 0.0713 0.0281 0.4309 + 0.0261 0.3696 0.1999 + 0.2469 0.5367 0.7956 + 0.8040 0.6403 0.4242 + 0.0573 0.7759 0.3112 + 0.6276 0.5760 0.6602 + 0.6207 0.0823 0.4012 + 0.8178 0.4223 0.2240 + 0.4988 0.1640 0.9503 + 0.9282 0.9511 0.7333 + 0.9976 0.8312 0.1382 + 0.3378 0.5846 0.9600 + 0.0158 0.1242 0.9066 + 0.9885 0.3426 0.5408 + 0.0505 0.8228 0.2916 + 0.9758 0.7815 0.6794 + 0.3000 0.9950 0.0827 + 0.9738 0.6339 0.1007 + 0.1853 0.2731 0.0706 + 0.4156 0.1586 0.1189 + 0.6042 0.0076 0.5364 + 0.8413 0.5236 0.2999 + 0.9670 0.2042 0.8950 + 0.0941 0.8300 0.0252 + 0.3518 0.4673 0.2669 + 0.8261 0.7968 0.3462 + 0.2083 0.6459 0.9281 + 0.4527 0.4038 0.3700 + 0.9544 0.9912 0.0818 + 0.8993 0.6790 0.6198 + 0.3285 0.1273 0.1766 spike_snippets(:,:,15) = - 0.8285 0.2332 0.5170 - 0.8534 0.5185 0.1475 - 0.1406 0.4439 0.6468 - 0.6271 0.7734 0.2874 - 0.7247 0.1307 0.7292 - 0.8879 0.9477 0.5567 - 0.2379 0.0284 0.5833 - 0.1076 0.1909 0.3181 - 0.9581 0.8145 0.8141 - 0.0705 0.4884 0.9800 - 0.1540 0.4450 0.7869 - 0.8214 0.2924 0.8107 - 0.3680 0.9230 0.7764 - 0.6458 0.1220 0.8034 - 0.0179 0.1152 0.1233 - 0.6552 0.0921 0.4741 - 0.4289 0.4675 0.4627 - 0.5957 0.6017 0.0530 - 0.7899 0.0406 0.7737 - 0.2715 0.5865 0.3788 - 0.3688 0.0015 0.2919 - 0.8261 0.6455 0.1661 - 0.9652 0.1234 0.2829 - 0.9641 0.1551 0.6033 - 0.0687 0.3860 0.3001 - 0.0792 0.8179 0.7818 - 0.7146 0.3863 0.2066 - 0.1720 0.3922 0.6165 - 0.0660 0.6977 0.0619 - 0.3606 0.8087 0.4434 - 0.0506 0.2943 0.3097 - 0.8358 0.0611 0.0026 - 0.1669 0.6148 0.0415 - 0.5499 0.1266 0.6509 - 0.0248 0.1344 0.8819 - 0.4887 0.2018 0.2192 - 0.6738 0.0505 0.3670 - 0.9817 0.2910 0.5394 - 0.0308 0.4956 0.9864 - 0.4028 0.5162 0.1998 + 0.2518 0.2132 0.6517 + 0.4294 0.2029 0.5901 + 0.1920 0.6816 0.0450 + 0.7183 0.2932 0.3240 + 0.3578 0.0861 0.9851 + 0.3588 0.7868 0.3229 + 0.6010 0.2346 0.3567 + 0.3353 0.8160 0.9498 + 0.6412 0.4145 0.4684 + 0.7884 0.5874 0.5773 + 0.8174 0.3730 0.7253 + 0.6890 0.8826 0.1494 + 0.6320 0.2392 0.3984 + 0.2187 0.1697 0.5931 + 0.4682 0.2170 0.4543 + 0.3698 0.5491 0.1559 + 0.4286 0.7919 0.6831 + 0.6181 0.8617 0.6636 + 0.5057 0.3220 0.4828 + 0.0323 0.0533 0.3387 + 0.8523 0.6696 0.8105 + 0.0593 0.3572 0.5220 + 0.7963 0.7267 0.4698 + 0.1692 0.8722 0.9332 + 0.8412 0.7119 0.8153 + 0.2336 0.3204 0.5797 + 0.5893 0.7290 0.6995 + 0.0408 0.6390 0.3742 + 0.5699 0.7568 0.5696 + 0.1617 0.6294 0.5978 + 0.8506 0.3235 0.0180 + 0.5276 0.7121 0.4807 + 0.0257 0.5351 0.0431 + 0.8287 0.6561 0.6653 + 0.7459 0.8562 0.6875 + 0.3030 0.9366 0.7649 + 0.3332 0.1334 0.1270 + 0.9961 0.1659 0.6390 + 0.3319 0.7664 0.4069 + 0.5801 0.2167 0.8845 spike_snippets(:,:,16) = - 0.0632 0.4119 0.1498 - 0.7862 0.8745 0.7497 - 0.3152 0.5970 0.2680 - 0.9582 0.5279 0.0675 - 0.8466 0.0177 0.1343 - 0.0575 0.4940 0.0601 - 0.9653 0.0421 0.6708 - 0.3656 0.9654 0.3555 - 0.6427 0.6600 0.8240 - 0.5254 0.5350 0.7614 - 0.8651 0.4518 0.1316 - 0.3772 0.3970 0.1697 - 0.9844 0.6259 0.4263 - 0.7779 0.2904 0.9443 - 0.4432 0.5715 0.7672 - 0.4826 0.1578 0.9774 - 0.8992 0.2390 0.9241 - 0.5520 0.7640 0.5236 - 0.6074 0.4966 0.5190 - 0.8831 0.8285 0.8182 - 0.0123 0.3464 0.0066 - 0.8589 0.9798 0.5752 - 0.6037 0.3889 0.2671 - 0.4787 0.5672 0.1828 - 0.9966 0.1551 0.4506 - 0.4607 0.6693 0.8682 - 0.1410 0.9311 0.4041 - 0.8505 0.8780 0.9635 - 0.8570 0.6529 0.0714 - 0.3587 0.9783 0.4064 - 0.4781 0.3078 0.8497 - 0.4610 0.3308 0.1232 - 0.8942 0.0222 0.8837 - 0.2707 0.6125 0.0489 - 0.8865 0.2327 0.1457 - 0.5464 0.8523 0.6175 - 0.4665 0.8757 0.5159 - 0.1181 0.2201 0.9281 - 0.8407 0.2243 0.4280 - 0.7371 0.5195 0.5242 + 0.3617 0.4796 0.3849 + 0.2697 0.9468 0.2100 + 0.6193 0.7343 0.1739 + 0.9393 0.8904 0.9818 + 0.5152 0.3033 0.4682 + 0.7790 0.8632 0.9662 + 0.4675 0.4774 0.5807 + 0.5060 0.4397 0.1240 + 0.9510 0.8019 0.9094 + 0.0934 0.1602 0.6181 + 0.0969 0.6271 0.8978 + 0.2026 0.4344 0.6037 + 0.6735 0.9694 0.1817 + 0.3916 0.3344 0.9062 + 0.9732 0.7063 0.0107 + 0.2138 0.3680 0.3148 + 0.4871 0.1667 0.1139 + 0.6683 0.2919 0.4264 + 0.3876 0.0255 0.8798 + 0.5643 0.8564 0.2776 + 0.5715 0.9426 0.0235 + 0.6990 0.6762 0.3343 + 0.8093 0.2319 0.1015 + 0.3863 0.8508 0.8312 + 0.1336 0.2826 0.6013 + 0.9609 0.7174 0.9380 + 0.9554 0.7533 0.1771 + 0.4546 0.6906 0.3352 + 0.6678 0.1365 0.7942 + 0.4918 0.9342 0.2363 + 0.5866 0.6735 0.0328 + 0.7620 0.9728 0.0622 + 0.6156 0.4195 0.1368 + 0.8612 0.5185 0.0101 + 0.2808 0.2869 0.7742 + 0.4417 0.8612 0.8285 + 0.7203 0.2428 0.9894 + 0.8703 0.6190 0.7001 + 0.4393 0.1567 0.1823 + 0.7885 0.1806 0.0020 spike_snippets(:,:,17) = - 0.2248 0.9454 0.3343 - 0.2661 0.2714 0.5529 - 0.6409 0.5257 0.2509 - 0.9720 0.6149 0.1317 - 0.4660 0.5646 0.0069 - 0.6395 0.8293 0.7489 - 0.0363 0.0109 0.0759 - 0.1006 0.2261 0.0331 - 0.4483 0.7455 0.8873 - 0.4724 0.9053 0.7795 - 0.6163 0.1059 0.4694 - 0.5038 0.8689 0.7092 - 0.4000 0.2480 0.9829 - 0.2566 0.8716 0.0221 - 0.1963 0.2623 0.1946 - 0.8754 0.8960 0.0683 - 0.3214 0.5532 0.3871 - 0.3090 0.4612 0.3692 - 0.0949 0.9036 0.7243 - 0.5785 0.0853 0.4553 - 0.4080 0.4273 0.1826 - 0.2397 0.1025 0.2676 - 0.0112 0.4233 0.8566 - 0.6912 0.5644 0.1537 - 0.5037 0.1292 0.5835 - 0.8740 0.9701 0.2860 - 0.1776 0.8694 0.4239 - 0.0146 0.2931 0.1575 - 0.1438 0.2192 0.0534 - 0.1210 0.6226 0.3310 - 0.6808 0.5873 0.8866 - 0.0166 0.4711 0.0265 - 0.2377 0.0932 0.4810 - 0.4095 0.5646 0.3677 - 0.7206 0.4269 0.0106 - 0.4908 0.5084 0.7710 - 0.9168 0.9261 0.2838 - 0.0650 0.3080 0.7490 - 0.9420 0.4491 0.0547 - 0.6323 0.8976 0.8351 + 0.1959 0.5420 0.9105 + 0.9073 0.6598 0.9800 + 0.3511 0.7097 0.4335 + 0.6976 0.0432 0.8542 + 0.4499 0.8647 0.0570 + 0.6184 0.1866 0.5088 + 0.1193 0.2679 0.1645 + 0.6003 0.3598 0.0318 + 0.7014 0.7784 0.4366 + 0.2962 0.9476 0.4504 + 0.3308 0.3297 0.9279 + 0.2546 0.0680 0.8303 + 0.9917 0.5504 0.9679 + 0.8936 0.4322 0.1293 + 0.5590 0.5348 0.5241 + 0.4043 0.1695 0.9367 + 0.2596 0.0089 0.7440 + 0.3231 0.3334 0.0031 + 0.2933 0.8405 0.0099 + 0.3029 0.3807 0.3762 + 0.3166 0.8088 0.7310 + 0.4989 0.6476 0.8311 + 0.1168 0.6515 0.7213 + 0.2899 0.3840 0.6481 + 0.1497 0.6184 0.0411 + 0.0861 0.9320 0.1645 + 0.3731 0.4888 0.1075 + 0.3739 0.0245 0.9520 + 0.2799 0.4943 0.5538 + 0.2278 0.6777 0.3999 + 0.2515 0.1443 0.8072 + 0.5196 0.6802 0.8547 + 0.9614 0.4804 0.2351 + 0.3108 0.2935 0.7144 + 0.6170 0.7830 0.1604 + 0.3423 0.2268 0.9950 + 0.0840 0.1316 0.4855 + 0.9375 0.8720 0.7160 + 0.8194 0.4043 0.6775 + 0.2686 0.9371 0.0693 spike_snippets(:,:,18) = - 0.8528 0.8267 0.3742 - 0.7533 0.1331 0.9552 - 0.4917 0.0555 0.7208 - 0.8872 0.2577 0.6193 - 0.5457 0.5930 0.0307 - 0.1417 0.9495 0.2944 - 0.3786 0.4841 0.4944 - 0.8947 0.1513 0.0882 - 0.5805 0.2407 0.3165 - 0.4782 0.4752 0.6826 - 0.3881 0.8809 0.0212 - 0.1409 0.6620 0.2262 - 0.7749 0.3939 0.4166 - 0.7476 0.2595 0.6855 - 0.8465 0.2595 0.1188 - 0.5590 0.4504 0.5791 - 0.8377 0.9104 0.6629 - 0.6318 0.3158 0.3771 - 0.8022 0.9276 0.2942 - 0.2505 0.8024 0.0318 - 0.9150 0.5174 0.6685 - 0.0144 0.9595 0.8606 - 0.4961 0.8575 0.2233 - 0.5635 0.4358 0.9664 - 0.3172 0.9393 0.1256 - 0.1253 0.8188 0.1029 - 0.3440 0.3788 0.0650 - 0.7378 0.9603 0.1648 - 0.4810 0.1027 0.5597 - 0.0185 0.2453 0.5999 - 0.8983 0.2843 0.7902 - 0.9571 0.6531 0.9934 - 0.3729 0.3625 0.7644 - 0.8940 0.6779 0.7209 - 0.0921 0.6594 0.9088 - 0.1161 0.6699 0.5187 - 0.6088 0.3770 0.6351 - 0.6902 0.4612 0.4053 - 0.1904 0.8284 0.8358 - 0.0138 0.0373 0.1868 + 0.2044 0.8060 0.4559 + 0.3989 0.3477 0.0178 + 0.3788 0.1528 0.2253 + 0.4920 0.6866 0.6046 + 0.0173 0.5004 0.6817 + 0.4821 0.8199 0.8309 + 0.2736 0.1016 0.2971 + 0.9217 0.5541 0.4229 + 0.1621 0.0677 0.9017 + 0.5945 0.1912 0.6291 + 0.2916 0.5514 0.5131 + 0.2112 0.8000 0.3688 + 0.8284 0.4171 0.1074 + 0.8941 0.1970 0.8132 + 0.5454 0.1708 0.5964 + 0.0349 0.1684 0.5245 + 0.5870 0.6541 0.5613 + 0.7540 0.6592 0.1215 + 0.1668 0.6609 0.2367 + 0.6786 0.1693 0.0634 + 0.9586 0.3644 0.4699 + 0.3425 0.2172 0.2802 + 0.1701 0.9606 0.7301 + 0.9152 0.3249 0.7825 + 0.8650 0.4647 0.2678 + 0.7262 0.6912 0.9897 + 0.4532 0.6555 0.2157 + 0.7250 0.0509 0.3455 + 0.3804 0.2556 0.8391 + 0.6323 0.8273 0.0621 + 0.7440 0.9607 0.9505 + 0.5396 0.6674 0.5746 + 0.5364 0.2100 0.9133 + 0.5956 0.7204 0.8166 + 0.4304 0.9428 0.1365 + 0.2596 0.5669 0.2789 + 0.1343 0.4623 0.9535 + 0.2614 0.6911 0.2445 + 0.4018 0.0246 0.3004 + 0.0077 0.1523 0.3515 spike_snippets(:,:,19) = - 0.7833 0.3800 0.2596 - 0.4774 0.3225 0.9132 - 0.3767 0.5766 0.7866 - 0.5167 0.7333 0.2876 - 0.3313 0.6348 0.4921 - 0.9909 0.7142 0.0040 - 0.7992 0.8899 0.7669 - 0.1438 0.3450 0.1557 - 0.8615 0.5972 0.6849 - 0.2221 0.2920 0.8230 - 0.9428 0.8654 0.7775 - 0.5121 0.7407 0.5810 - 0.6163 0.4000 0.3330 - 0.3748 0.9231 0.6470 - 0.4877 0.7523 0.8188 - 0.4864 0.9930 0.0859 - 0.0486 0.4711 0.6532 - 0.3978 0.0564 0.0195 - 0.9749 0.1345 0.4348 - 0.4293 0.0039 0.9382 - 0.5667 0.6412 0.2270 - 0.5779 0.7878 0.6903 - 0.4924 0.9922 0.8492 - 0.6379 0.1296 0.5580 - 0.4197 0.5457 0.1361 - 0.4808 0.5291 0.6389 - 0.6873 0.0123 0.3525 - 0.9886 0.1202 0.7538 - 0.7048 0.8567 0.9505 - 0.3475 0.1045 0.1739 - 0.8209 0.6846 0.5388 - 0.0525 0.3191 0.7253 - 0.1306 0.5241 0.2333 - 0.6714 0.2183 0.1283 - 0.8935 0.1168 0.5805 - 0.8253 0.1419 0.3755 - 0.6320 0.2447 0.7466 - 0.0071 0.0700 0.8273 - 0.3107 0.5529 0.8195 - 0.2268 0.3851 0.4185 + 0.4796 0.1469 0.7166 + 0.7013 0.1920 0.6477 + 0.3507 0.7289 0.3165 + 0.8040 0.2512 0.8675 + 0.8645 0.4048 0.6909 + 0.6119 0.1603 0.0853 + 0.3848 0.3168 0.8677 + 0.7272 0.9591 0.4262 + 0.4190 0.5329 0.7629 + 0.8615 0.3420 0.3994 + 0.6660 0.7825 0.5770 + 0.0337 0.5107 0.3806 + 0.2774 0.0544 0.5483 + 0.3664 0.7206 0.4609 + 0.3950 0.5821 0.2499 + 0.8709 0.9255 0.2459 + 0.4484 0.3779 0.7865 + 0.5256 0.7493 0.3957 + 0.3331 0.4078 0.6649 + 0.0315 0.3368 0.5578 + 0.8973 0.6093 0.0103 + 0.8446 0.0363 0.2517 + 0.8092 0.1453 0.8943 + 0.7750 0.4485 0.2392 + 0.8051 0.5641 0.9237 + 0.5442 0.3667 0.5998 + 0.7352 0.7777 0.9312 + 0.4753 0.1060 0.7647 + 0.6985 0.3146 0.1770 + 0.9186 0.0215 0.0437 + 0.8929 0.5599 0.3737 + 0.6774 0.9312 0.5492 + 0.2597 0.3554 0.3777 + 0.3778 0.6063 0.0516 + 0.3313 0.3930 0.4723 + 0.3727 0.7249 0.9840 + 0.7936 0.9136 0.4857 + 0.4638 0.5821 0.0701 + 0.8432 0.2344 0.4754 + 0.5643 0.0735 0.2353 spike_snippets(:,:,20) = - 0.0803 0.5497 0.8134 - 0.2016 0.7139 0.9475 - 0.2989 0.6889 0.9147 - 0.4506 0.2072 0.5099 - 0.6934 0.8924 0.4041 - 0.9842 0.2183 0.5916 - 0.9099 0.1014 0.2588 - 0.3646 0.2869 0.1107 - 0.7892 0.5949 0.2686 - 0.8226 0.5505 0.3111 - 0.0764 0.4849 0.1924 - 0.2240 0.8471 0.8423 - 0.1020 0.2254 0.4194 - 0.8691 0.5801 0.1725 - 0.8217 0.0235 0.0745 - 0.6285 0.1380 0.2667 - 0.6437 0.4091 0.5609 - 0.6716 0.2623 0.3741 - 0.7291 0.8411 0.0698 - 0.4717 0.0125 0.4050 - 0.1205 0.4536 0.2174 - 0.1712 0.4339 0.4282 - 0.2948 0.1448 0.0394 - 0.8869 0.1695 0.8341 - 0.0986 0.4590 0.6105 - 0.2961 0.1109 0.6225 - 0.2111 0.6054 0.6792 - 0.9609 0.6630 0.4239 - 0.8231 0.0917 0.1793 - 0.9510 0.1655 0.7910 - 0.8841 0.3304 0.3527 - 0.7403 0.3570 0.1069 - 0.6682 0.3612 0.9556 - 0.7742 0.0715 0.6476 - 0.8029 0.4781 0.8936 - 0.8517 0.2079 0.6216 - 0.8403 0.8003 0.7215 - 0.5677 0.7792 0.8469 - 0.1805 0.0260 0.8686 - 0.4809 0.8847 0.0151 -
 
% Create electrode table region referencing electrodes 0, 1, and 2
shank0_table_region = types.hdmf_common.DynamicTableRegion( ...
'table', types.untyped.ObjectView(electrodesDynamicTable), ...
'description', 'shank0', ...
'data', (0:2)');
 
% Define spike event series for unsorted spike times
spike_events = types.core.SpikeEventSeries( ...
'data', spike_snippets, ...
'timestamps', (0:19)', ... % Timestamps for each event
'description', 'events detected with 100uV threshold', ...
'electrodes', shank0_table_region ...
);
 
% Add spike event series to NWB file acquisition
nwb.acquisition.set('SpikeEvents_Shank0', spike_events);

Detected Events

If you need to store the complete, continuous raw voltage traces, along with unsorted spike times, you should store the traces in ElectricalSeries objects in the acquisition group, and use the EventDetection class to identify the spike events in your raw traces.
% Create the EventDetection object
event_detection = types.core.EventDetection( ...
'detection_method', 'thresholding, 1.5 * std', ...
'source_electricalseries', types.untyped.SoftLink(raw_electrical_series), ...
'source_idx', [1000; 2000; 3000], ...
'times', [.033, .066, .099] ...
);
 
% Add the EventDetection object to the ecephys module
ecephys_module.nwbdatainterface.set('ThresholdEvents', event_detection);

Storing Spike Features (e.g Principal Components)

NWB also provides a way to store features of spikes, such as principal components, using the FeatureExtraction class.
% Generate random feature data (time x channel x feature)
features = rand(3, 12, 4); % 3 time points, 12 channels, 4 features
features = permute(features, [3,2,1]); % reverse dimension order for matnwb
 
% Create the FeatureExtraction object
feature_extraction = types.core.FeatureExtraction( ...
'description', {'PC1', 'PC2', 'PC3', 'PC4'}, ... % Feature descriptions
'electrodes', electrode_table_region, ... % DynamicTableRegion referencing the electrodes table
'times', [.033; .066; .099], ... % Column vector for times
'features', features ...
);
 
% Add the FeatureExtraction object to the ecephys module (if required)
ecephys_module.nwbdatainterface.set('PCA_features', feature_extraction);

Choosing NWB-Types for Electrophysiology Data (A Summary)

As mentioned above, ElectricalSeries objects are meant for storing electrical timeseries data like raw voltage signals or processed signals like LFP or other filtered signals. In addition to the ElectricalSeries class, NWB provides some more classes for storing event-based electropysiological data. We will briefly discuss them here, and refer the reader to the API documentation and the section on Extracellular Physiology in the "NWB Format Specification" for more details on using these objects.
For storing unsorted spiking data, there are two options. Which one you choose depends on what data you have available. If you need to store complete and/or continuous raw voltage traces, you should store the traces with ElectricalSeries objects as acquisition data, and use the EventDetection class for identifying the spike events in your raw traces. If you do not want to store the entire raw voltage traces, only the waveform ‘snippets’ surrounding spike events, you should use SpikeEventSeries objects.
The results of spike sorting (or clustering) should be stored in the top-level Units table. The Units table can hold just the spike times of sorted units or, optionally, include additional waveform information. You can use the optional predefined columns waveform_mean, waveform_sd, and waveforms in the Units table to store individual and mean waveform data.

Writing the NWB File

nwbExport(nwb, 'ecephys_tutorial.nwb')

Reading NWB Data

Data arrays are read passively from the file. Calling TimeSeries.data does not read the data values, but presents an HDF5 object that can be indexed to read data. This allows you to conveniently work with datasets that are too large to fit in RAM all at once. load with no input arguments reads the entire dataset:
nwb2 = nwbRead('ecephys_tutorial.nwb', 'ignorecache');
nwb2.processing.get('ecephys'). ...
nwbdatainterface.get('LFP'). ...
electricalseries.get('ElectricalSeries'). ...
data.load;

Accessing Data Regions

If all you need is a data region, you can index a DataStub object like you would any normal array in MATLAB, as shown below. When indexing the dataset this way, only the selected region is read from disk into RAM. This allows you to handle very large datasets that would not fit entirely into RAM.
% read section of LFP
nwb2.processing.get('ecephys'). ...
nwbdatainterface.get('LFP'). ...
electricalseries.get('ElectricalSeries'). ...
data(1:5, 1:10)
ans = 5×10
2.0421 -1.9417 0.3559 0.4354 0.6993 -1.4009 0.5222 0.0893 0.1243 1.2460 - 0.2329 0.4688 2.1159 1.2094 0.1735 -0.3315 0.1403 -2.0881 0.2840 -0.4077 - -0.0943 1.3933 -0.0871 -0.5193 -0.0920 -1.1307 0.8399 0.0975 -0.6912 -0.4536 - -1.4224 2.7602 1.1832 0.0075 0.6687 0.2074 0.5432 0.4366 0.0113 0.2925 - 0.9660 0.9444 -0.8471 1.0362 0.0652 -0.2155 0.6006 0.1602 0.7417 -1.3644 -
 
% You can use the getRow method of the table to load spike times of a specific unit.
% To get the values, unpack from the returned table.
nwb.units.getRow(1).spike_times{1}
ans = 24×1
0.1312 - 0.4211 - 0.2037 - 0.1021 - 0.1315 - 0.8392 - 0.9195 - 0.7023 - 0.0588 - 0.7331 + 0.6873 0.0605 0.9140 + 0.9657 0.0721 0.8518 + 0.8899 0.1328 0.6940 + 0.0387 0.6798 0.9621 + 0.4656 0.5908 0.2731 + 0.7438 0.5670 0.2736 + 0.3971 0.0360 0.3144 + 0.8050 0.7448 0.6957 + 0.0030 0.4603 0.2473 + 0.2465 0.6805 0.3513 + 0.8086 0.2980 0.2490 + 0.2352 0.3977 0.5605 + 0.2713 0.7731 0.5679 + 0.8310 0.7215 0.5309 + 0.7490 0.9698 0.8578 + 0.5483 0.1271 0.5879 + 0.3070 0.0921 0.7794 + 0.1199 0.8039 0.5579 + 0.9437 0.8100 0.8285 + 0.7219 0.4346 0.4720 + 0.7465 0.6658 0.1583 + 0.5633 0.8219 0.5985 + 0.3870 0.4728 0.3190 + 0.4641 0.8891 0.5325 + 0.8391 0.2668 0.5287 + 0.2010 0.5825 0.9167 + 0.9513 0.0738 0.1681 + 0.2306 0.2030 0.1066 + 0.9499 0.1480 0.6067 + 0.9601 0.6199 0.4368 + 0.9094 0.2456 0.3924 + 0.9030 0.7869 0.9830 + 0.1268 0.3279 0.8036 + 0.4003 0.7065 0.6491 + 0.6768 0.2883 0.4791 + 0.1409 0.1552 0.0926 + 0.7783 0.5634 0.3639 + 0.7050 0.2093 0.0664 + 0.2874 0.9361 0.8809 + 0.5040 0.0051 0.3799 +
 
% Create electrode table region referencing electrodes 0, 1, and 2
shank0_table_region = types.hdmf_common.DynamicTableRegion( ...
'table', types.untyped.ObjectView(electrodesDynamicTable), ...
'description', 'shank0', ...
'data', (0:2)');
 
% Define spike event series for unsorted spike times
spike_events = types.core.SpikeEventSeries( ...
'data', spike_snippets, ...
'timestamps', (0:19)', ... % Timestamps for each event
'description', 'events detected with 100uV threshold', ...
'electrodes', shank0_table_region ...
);
 
% Add spike event series to NWB file acquisition
nwb.acquisition.set('SpikeEvents_Shank0', spike_events);

Detected Events

If you need to store the complete, continuous raw voltage traces, along with unsorted spike times, you should store the traces in ElectricalSeries objects in the acquisition group, and use the EventDetection class to identify the spike events in your raw traces.
% Create the EventDetection object
event_detection = types.core.EventDetection( ...
'detection_method', 'thresholding, 1.5 * std', ...
'source_electricalseries', types.untyped.SoftLink(raw_electrical_series), ...
'source_idx', [1000; 2000; 3000], ...
'times', [.033, .066, .099] ...
);
 
% Add the EventDetection object to the ecephys module
ecephys_module.nwbdatainterface.set('ThresholdEvents', event_detection);

Storing Spike Features (e.g Principal Components)

NWB also provides a way to store features of spikes, such as principal components, using the FeatureExtraction class.
% Generate random feature data (time x channel x feature)
features = rand(3, 12, 4); % 3 time points, 12 channels, 4 features
features = permute(features, [3,2,1]); % reverse dimension order for matnwb
 
% Create the FeatureExtraction object
feature_extraction = types.core.FeatureExtraction( ...
'description', {'PC1', 'PC2', 'PC3', 'PC4'}, ... % Feature descriptions
'electrodes', electrode_table_region, ... % DynamicTableRegion referencing the electrodes table
'times', [.033; .066; .099], ... % Column vector for times
'features', features ...
);
 
% Add the FeatureExtraction object to the ecephys module (if required)
ecephys_module.nwbdatainterface.set('PCA_features', feature_extraction);

Choosing NWB-Types for Electrophysiology Data (A Summary)

As mentioned above, ElectricalSeries objects are meant for storing electrical timeseries data like raw voltage signals or processed signals like LFP or other filtered signals. In addition to the ElectricalSeries class, NWB provides some more classes for storing event-based electropysiological data. We will briefly discuss them here, and refer the reader to the API documentation and the section on Extracellular Physiology in the "NWB Format Specification" for more details on using these objects.
For storing unsorted spiking data, there are two options. Which one you choose depends on what data you have available. If you need to store complete and/or continuous raw voltage traces, you should store the traces with ElectricalSeries objects as acquisition data, and use the EventDetection class for identifying the spike events in your raw traces. If you do not want to store the entire raw voltage traces, only the waveform ‘snippets’ surrounding spike events, you should use SpikeEventSeries objects.
The results of spike sorting (or clustering) should be stored in the top-level Units table. The Units table can hold just the spike times of sorted units or, optionally, include additional waveform information. You can use the optional predefined columns waveform_mean, waveform_sd, and waveforms in the Units table to store individual and mean waveform data.

Writing the NWB File

nwbExport(nwb, 'ecephys_tutorial.nwb')

Reading NWB Data

Data arrays are read passively from the file. Calling TimeSeries.data does not read the data values, but presents an HDF5 object that can be indexed to read data. This allows you to conveniently work with datasets that are too large to fit in RAM all at once. load with no input arguments reads the entire dataset:
nwb2 = nwbRead('ecephys_tutorial.nwb', 'ignorecache');
nwb2.processing.get('ecephys'). ...
nwbdatainterface.get('LFP'). ...
electricalseries.get('ElectricalSeries'). ...
data.load;

Accessing Data Regions

If all you need is a data region, you can index a DataStub object like you would any normal array in MATLAB, as shown below. When indexing the dataset this way, only the selected region is read from disk into RAM. This allows you to handle very large datasets that would not fit entirely into RAM.
% read section of LFP
nwb2.processing.get('ecephys'). ...
nwbdatainterface.get('LFP'). ...
electricalseries.get('ElectricalSeries'). ...
data(1:5, 1:10)
ans = 5×10
0.9651 -0.8883 -0.0094 0.8173 -1.0690 0.1127 -1.4322 -1.0934 -1.5671 1.0822 + -0.6077 0.1766 0.1769 0.3961 -0.4618 -0.6057 0.4036 -0.8789 -1.2575 0.5712 + -0.1929 0.5733 -1.4192 -0.2441 1.7385 -0.8977 -0.4516 -0.9052 -0.1145 0.3583 + 0.2470 -0.4401 1.6814 -0.3924 -0.1789 0.1862 -0.4147 -0.1626 -0.4556 -0.1766 + 0.2099 -0.4356 -0.8001 -0.3095 -1.3299 0.1646 0.5666 1.0098 -0.4388 0.7080 +
 
% You can use the getRow method of the table to load spike times of a specific unit.
% To get the values, unpack from the returned table.
nwb.units.getRow(1).spike_times{1}
ans = 24×1
0.3390 + 0.8821 + 0.0155 + 0.9190 + 0.3082 + 0.1643 + 0.0970 + 0.8547 + 0.1262 + 0.3271

Learn more!

See the API documentation to learn what data types are available.

MATLAB tutorials

Python tutorials

See our tutorials for more details about your data type:
Check out other tutorials that teach advanced NWB topics: