Source code for ibllib.tests.extractors.test_mesoscope

"""Tests for ibllib.io.extractors.mesoscope module."""
import unittest
from itertools import repeat, chain

import numpy as np

from ibllib.io.extractors import mesoscope


[docs] class TestMesoscopeSyncTimeline(unittest.TestCase): """Tests for MesoscopeSyncTimeline extractor class."""
[docs] def setUp(self) -> None: """Simulate for meta data for 9 FOVs at 3 different depths. These simulated values match those from SP048/2024-02-05/001. """ n_lines_flyback = 75 self.n_lines = 512 self.n_FOV = 9 n_depths = 3 assert self.n_FOV > n_depths and self.n_FOV % n_depths == 0 reps = int(self.n_FOV / n_depths) start_depth = 60 delta_depth = 40 self.line_period = 4.158e-05 self.meta = { 'scanImageParams': {'hRoiManager': {'linePeriod': self.line_period, 'scanFrameRate': 13.6803}}, 'FOV': [] } nXnYnZ = [self.n_lines, self.n_lines, 1] for i, slice_id in enumerate(chain.from_iterable(map(lambda x: list(repeat(x, reps)), range(n_depths)))): offset = (i % n_depths) * (self.n_lines + n_lines_flyback) - ((i % n_depths) - 1) offset = offset or 1 # start at 1 for MATLAB indexing fov = {'slice_id': slice_id, 'Zs': start_depth + (delta_depth * slice_id), 'nXnYnZ': nXnYnZ, 'lineIdx': list(range(offset, self.n_lines + offset))} self.meta['FOV'].append(fov)
[docs] def test_get_timeshifts_multidepth(self): """Test MescopeSyncTimeline.get_timeshifts method. This tests output when given multiple FOVs at different depths. The tasks/mesoscope_tasks.py module in iblscripts more thoroughly tests single-depth imaging with real data. """ line_indices, fov_time_shifts, line_time_shifts = mesoscope.MesoscopeSyncTimeline.get_timeshifts(self.meta) expected = [np.array(x['lineIdx']) for x in self.meta['FOV']] self.assertTrue(np.all(x == y) for x, y in zip(expected, line_indices)) self.assertEqual(self.n_FOV, len(fov_time_shifts)) self.assertEqual(self.n_FOV, len(line_time_shifts)) self.assertTrue(all(len(x) == self.n_lines for x in line_time_shifts)) expected = self.line_period * np.arange(self.n_lines) for i, line_shifts in enumerate(line_time_shifts): with self.subTest(f'FOV == {i}'): self.assertEqual(self.n_lines, len(line_shifts)) np.testing.assert_almost_equal(expected, line_shifts) # NB: The following values are fixed for the setup parameters expected = [0., 0.02436588, 0.04873176, 0.07309781, 0.09746369, 0.12182957, 0.14619562, 0.1705615, 0.19492738] np.testing.assert_almost_equal(expected, fov_time_shifts)
if __name__ == '__main__': unittest.main()