Skip to content
Merged
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
4 changes: 2 additions & 2 deletions caiman/source_extraction/cnmf/estimates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ def save_NWB(self,
# Add processing results

# Create the module as 'ophys' unless it is taken and append 'ophysX' instead
ophysmodules = [s[5:] for s in list(nwbfile.modules) if s.startswith('ophys')]
ophysmodules = [s[5:] for s in nwbfile.processing if s.startswith('ophys')]
if any('' in s for s in ophysmodules):
if any([s for s in ophysmodules if s.isdigit()]):
nummodules = max([int(s) for s in ophysmodules if s.isdigit()])+1
Expand All @@ -1619,7 +1619,7 @@ def save_NWB(self,
img_seg = ImageSegmentation()
mod.add(img_seg)
fl = Fluorescence()
mod.add_data_interface(fl)
mod.add(fl)
# mot_crct = MotionCorrection()
# mod.add_data_interface(mot_crct)

Expand Down
19 changes: 19 additions & 0 deletions caiman/tests/test_hdf5.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env python

from datetime import datetime, timezone
import numpy as np
import numpy.testing as npt
import os
from pynwb import NWBHDF5IO
from scipy.sparse import csc_matrix
from caiman.source_extraction.cnmf.estimates import Estimates
from caiman.utils import utils
from caiman.paths import get_tempdir

Expand Down Expand Up @@ -47,5 +51,20 @@ def test_save_and_load_dict_to_hdf5():
_recursively_assert_array_equal(dict_to_save, loaded)


def test_save_nwb_estimates(tmp_path):
traces = np.array([[1., 3., 2.]])
estimates = Estimates(A=csc_matrix([[1.], [0.], [0.], [0.]]), b=np.ones((4, 1)),
C=traces, f=np.ones_like(traces), dims=(2, 2))
estimates.YrA = np.zeros_like(traces)
estimates.r_values = np.array([0.9])
estimates.SNR_comp = np.array([3.])
filename = tmp_path / 'estimates.nwb'
estimates.save_NWB(filename, session_start_time=datetime.now(timezone.utc))

with NWBHDF5IO(filename, 'r') as io:
fluorescence = io.read().processing['ophys']['Fluorescence']
npt.assert_array_equal(fluorescence.roi_response_series['RoiResponseSeries'].data[:], traces.T)


if __name__ == '__main__':
test_save_and_load_dict_to_hdf5()
Loading