Skip to content

Commit

Permalink
Add test for bidirectional SBX movie loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbb committed Jan 18, 2025
1 parent 38dc06a commit e63a98a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions caiman/tests/test_sbx.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def test_load_2d():
assert data_2d.ndim == 3, 'Loaded 2D data has wrong dimensionality'
assert data_2d.shape == SHAPE_2D, 'Loaded 2D data has wrong shape'
assert data_2d.shape == (meta_2d['num_frames'], *meta_2d['frame_size']), 'Shape in metadata does not match loaded data'
assert meta_2d['frame_rate'] == 15.625, 'Frame rate in metadata is incorrect (unidirectional)'
npt.assert_array_equal(data_2d[0, 0, :10], [712, 931, 1048, 825, 1383, 882, 601, 798, 1022, 966], 'Loaded 2D data has wrong values')

data_2d_movie = cm.load(file_2d)
Expand All @@ -37,6 +38,23 @@ def test_load_2d():
npt.assert_array_almost_equal(data_2d_movie, data_2d, err_msg='Movie loaded with cm.load has wrong values')


def test_load_2d_bidi():
file_2d_bidi = os.path.join(TESTDATA_PATH, '2d_sbx_bidi.sbx')
data_2d_bidi = sbx_utils.sbxread(file_2d_bidi)
meta_2d_bidi = sbx_utils.sbx_meta_data(file_2d_bidi)

assert data_2d_bidi.ndim == 3, 'Loaded 2D bidirectional data has wrong dimensionality'
assert data_2d_bidi.shape == SHAPE_2D, 'Loaded 2D bidirectional data has wrong shape'
assert data_2d_bidi.shape == (meta_2d_bidi['num_frames'], *meta_2d_bidi['frame_size']), 'Shape in metadata does not match loaded data'
assert meta_2d_bidi['frame_rate'] == 31.25, 'Frame rate in metadata is incorrect (bidirectional)'
npt.assert_array_equal(data_2d_bidi[0, 0, :10], [2833, 1538, 1741, 1837, 2079, 2038, 1946, 1631, 2260, 2073], 'Loaded 2D bidirectional data has wrong values')

data_2d_bidi_movie = cm.load(file_2d_bidi)
assert data_2d_bidi_movie.ndim == data_2d_bidi.ndim, 'Movie loaded with cm.load has wrong dimensionality'
assert data_2d_bidi_movie.shape == data_2d_bidi.shape, 'Movie loaded with cm.load has wrong shape'
npt.assert_array_almost_equal(data_2d_bidi_movie, data_2d_bidi, err_msg='Movie loaded with cm.load has wrong values')


def test_load_3d():
file_3d = os.path.join(TESTDATA_PATH, '3d_sbx_1.sbx')
data_3d = sbx_utils.sbxread(file_3d)
Expand All @@ -45,6 +63,7 @@ def test_load_3d():
assert data_3d.ndim == 4, 'Loaded 3D data has wrong dimensionality'
assert data_3d.shape == SHAPE_3D, 'Loaded 3D data has wrong shape'
assert data_3d.shape == (meta_3d['num_frames'], *meta_3d['frame_size'], meta_3d['num_planes']), 'Shape in metadata does not match loaded data'
assert meta_3d['frame_rate'] == 15.625 / meta_3d['num_planes'], 'Frame rate in metadata is incorrect (bidirectional 3D)'
npt.assert_array_equal(data_3d[0, 0, :10, 0], [2167, 2525, 1713, 1747, 1887, 1741, 1873, 1244, 1747, 1637], 'Loaded 2D data has wrong values')

data_3d_movie = cm.load(file_3d, is3D=True)
Expand Down
Binary file added testdata/2d_sbx_bidi.mat
Binary file not shown.
Binary file added testdata/2d_sbx_bidi.sbx
Binary file not shown.

0 comments on commit e63a98a

Please sign in to comment.