Package: ndx-miniscope
ndx-miniscope Extension for NWBThis is a Neurodata Extension (NDX) for Neurodata Without Borders (NWB) 2.0 for Miniscope acquisition data.Miniscopeextends theDevicecore NWB neurodata_type by including additional metadata for the Miniscope.
Depending on the version of the acquisition software the data structure can be quite different.Miniscope V4 formatThe data recorded by the software is saved in a folder structure similar to this:C6-J588_Disc5/ (main folder)
    ├── 15_03_28/ (subfolder corresponding to the recording time)
    │   ├── Miniscope/ (subfolder containing the microscope video stream)
    │   │   ├── 0.avi (microscope video)
    │   │   ├── metaData.json (metadata for the microscope device)
    │   │   └── timeStamps.csv (timing of this video stream)
    │   ├── BehavCam_2/ (subfolder containing the behavioral video stream)
    │   │   ├── 0.avi (bevavioral video)
    │   │   ├── metaData.json (metadata for the behavioral camera)
    │   │   └── timeStamps.csv (timing of this video stream)
    │   └── metaData.json (metadata for the recording, such as the start time)
    ├── 15_06_28/
    │   ├── Miniscope/
    │   ├── BehavCam_2/
    │   └── metaData.json
    └── 15_12_28/Miniscope V3 formatThe Miniscope V3 acquisition software generally outputs the following files:msCam[##].avibehavCam[##].avitimestamp.datsettings_and_notes.datpythonInstallationGet most recent release:pipinstallndx-miniscopeInstall latest:gitclonehttps://github.com/catalystneuro/ndx-miniscope.gitcdndx-miniscope
pipinstall-e.The following code demonstrates the usage of this extension to convert Miniscope acquisition data into NWB.Usagefromdatetimeimportdatetimefromdateutil.tzimporttzlocalimportglobimportosfrompynwbimportNWBFile,NWBHDF5IOfrompynwb.imageimportImageSeriesfromnatsortimportnatsortedfromndx_miniscope.utilsimport(add_miniscope_device,get_starting_frames,get_timestamps,read_miniscope_config,read_notes,)# The main folder that contains subfolders with the Miniscope datafolder_path="C6-J588_Disc5/"# Create the NWBFilesession_start_time=datetime(2017,4,15,12,tzinfo=tzlocal())nwbfile=NWBFile(session_description="session_description",identifier="identifier",session_start_time=session_start_time,)# Load the miscroscope settingsminiscope_folder_path="C6-J588_Disc5/15_03_28/Miniscope/"miniscope_metadata=read_miniscope_config(folder_path=miniscope_folder_path)# Create the Miniscope device with the microscope metadata and add it to NWBadd_miniscope_device(nwbfile=nwbfile,device_metadata=miniscope_metadata)# Load the behavioral camera settingsbehavcam_folder_path="C6-J588_Disc5/15_03_28/BehavCam_2/"behavcam_metadata=read_miniscope_config(folder_path=behavcam_folder_path)# Create the Miniscope device with the behavioral camera metadata and add it to NWBadd_miniscope_device(nwbfile=nwbfile,device_metadata=behavcam_metadata)# Loading the timestampsbehavcam_timestamps=get_timestamps(folder_path=folder_path,file_pattern="BehavCam*/timeStamps.csv")# Load the starting frames of the video files# Note this function requires to have `cv2` installedstarting_frames=get_starting_frames(folder_path=folder_path,video_file_pattern="*/BehavCam*/*.avi")# Legacy usage for Miniscope V3ms_files=natsorted(glob(os.path.join(folder_path,'msCam*.avi')))nwbfile.add_acquisition(ImageSeries(name='OnePhotonSeries',# this is not recommended since pynwb has native OnePhotonSeriesformat='external',external_file=[os.path.split(x)[1]forxinms_files],timestamps=get_timestamps(folder_path=folder_path,cam_num=1),starting_frame=get_starting_frames(folder_path=folder_path,video_file_pattern="msCam*.avi"),))behav_files=natsorted(glob(os.path.join(folder_path,'behavCam*.avi')))nwbfile.add_acquisition(ImageSeries(name='behaviorCam',format='external',external_file=[os.path.split(x)[1]forxinbehav_files],timestamps=get_timestamps(folder_path=folder_path,cam_num=2),starting_frame=get_starting_frames(folder_path=folder_path,video_file_pattern="behavCam*.avi"),))annotations=read_notes(folder_path=folder_path)ifannotationsisnotNone:nwbfile.add_acquisition(annotations)save_path=os.path.join(folder_path,"test_out.nwb")withNWBHDF5IO(save_path,"w")asio:io.write(nwbfile)# test readwithNWBHDF5IO(save_path,"r")asio:nwbfile_in=io.read()MATLAB:Installationgitclonehttps://github.com/bendichter/ndx-miniscope.gitgenerateExtension('path/to/ndx-miniscope/spec');Usageunder construction...