Link Search Menu Expand Document

NWB tutorial

This tutorial will show you how to export cell metrics to a NWB file and import them back from the file. CellExplorer still works with its regular Matlab structs in memory, but you can save (export) and load (import) the cell metrics from a nwb file.

You must install the matnwb toolset as well.

Table of contents

  1. Export the cell_metrics to NWB
    1. Saving metrics to nwb via saveCellMetrics
    2. Loading metrics from nwb via loadCellMetrics
  2. Saving metrics to nwb in ProcessCellMetrics
    1. Saving metrics to nwb in CellExplorer

Export the cell_metrics to NWB

  1. Load cell_metrics struct from a session into Matlab, e.g.:
cell_metrics = loadCellMetrics('basepath',pwd);
  1. Export the cell_metrics to NWB

The nwb naming should ideally follow the CellExplorer filename convention:

nwb_file = [cell_metrics.general.basename,'.cell_metrics.cellinfo.nwb'];

% Generate the nwb file
nwb = saveCellMetrics2nwb(cell_metrics,nwb_file);
  1. Import cell_metrics from NWB
cell_metrics = loadNwbCellMetrics(nwb_file);

% Now you may run CellExplorer: 
cell_metrics = CellExplorer('metrics',cell_metrics);

Saving metrics to nwb via saveCellMetrics

To save metrics to nwb with saveCellMetrics, all you have to do is specify the filename extension to be nwb:

nwb_file = [cell_metrics.general.basename,'.cellmetrics.cellinfo.nwb'];
saveCellMetrics(cell_metrics,nwb_file)

Loading metrics from nwb via loadCellMetrics

Cell metrics saved to a nwb file can also directly be loaded with loadCellMetrics, as long as you specify nwb as the file format:

cell_metrics = loadCellMetrics('fileFormat','nwb')

The script will determine the nwb filename from the basename and basepath, e.g.: basepath/basename.cell_metrics.cellinfo.nwb

Saving metrics to nwb in ProcessCellMetrics

To save the cell metrics directly to an nwb file in the processing module, you must provide the file format as an input to the call. The file format can also be set in the graphical interface by setting showGUI=true

cell_metrics = ProcessCellMetrics('session', session,'showGUI',true,'fileFormat','nwb');

Saving metrics to nwb in CellExplorer

You may also save directly to an nwb file in CellExplorer. From the File menu in CellExplorer, select Save As…, a save-dialog will appear, in which you may select .nwb as the file format.