ndx-whisk is an NWB extension to store whisker tracking measurements. It is intended to convert .whiskers
and .measurements
files generated by whisk (Janelia Whisker Tracker), or saved to hdf5
with WhiskiWrap, but can be used with other whisker tracking methods.
pip install ndx-whisk
See test script test_whiskermeasurement.py
in src/pynwb/tests
.
from pynwb import NWBHDF5IO, NWBFile
from ndx_whisk import WhiskerMeasurementTable
import numpy as np
# Load your data
whisker_data = read_whisker_measurement_table('tracked_data.whiskers')
# Create a WhiskerMeasurementTable
whisker_meas = WhiskerMeasurementTable(
name='name',
description='description'
)
# Add data to the WhiskerMeasurementTable
for i in range(np.shape(whisker_data['frame_id'])[0]):
whisker_meas.add_row({k: whisker_data[k][i] for k in whisker_data.keys()})
# Set up a NWB file
nwbfile = set_up_nwbfile()
path = 'tracked_data.nwb'
# Add a ProcessingModule for behavioral data
behavior_module = nwbfile.create_processing_module(
name="behavior", description="Processed behavioral data"
)
# Add the WhiskerMeasurementTable
nwbfile.processing['behavior'].add(whisker_meas)
# Save to NWB file
with NWBHDF5IO(path, mode='w') as io:
io.write(nwbfile)
This extension was created using ndx-template.