Skip to content

Commit

Permalink
mpciROIs.uuids (#663)
Browse files Browse the repository at this point in the history
* mpciROIs.uuids
* Added tests
  • Loading branch information
k1o0 authored Oct 18, 2023
1 parent bfa88e5 commit eab63da
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
5 changes: 3 additions & 2 deletions brainbox/behavior/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,16 @@ class TrainingStatus(IntFlag):
... assert TrainingStatus[status.upper()] in ~TrainingStatus.FAILED, 'Subject untrained'
... assert TrainingStatus[status.upper()] in TrainingStatus.TRAINED ^ TrainingStatus.READY
# Get the next training status
Get the next training status
>>> next(member for member in sorted(TrainingStatus) if member > TrainingStatus[status.upper()])
<TrainingStatus.READY4RECORDING: 128>
Notes
-----
- ~TrainingStatus.TRAINED means any status but trained 1a or trained 1b.
- A subject may acheive both TRAINED_1A and TRAINED_1B within a single session, therefore it
is possible to have skipped the TRAINED_1A session status.
is possible to have skipped the TRAINED_1A session status.
"""
UNTRAINABLE = auto()
UNBIASABLE = auto()
Expand Down
1 change: 1 addition & 0 deletions ibllib/io/extractors/mesoscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def get_wheel_positions(self, ticks=WHEEL_TICKS, radius=WHEEL_RADIUS_CM, coding=
moves = extract_wheel_moves(wheel['timestamps'], wheel['position'])

if display:
assert self.bpod_trials, 'no bpod trials to compare'
fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
bpod_ts = self.bpod_trials['wheel_timestamps']
bpod_pos = self.bpod_trials['wheel_position']
Expand Down
6 changes: 6 additions & 0 deletions ibllib/pipes/mesoscope_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def signature(self):
('mpciROIs.stackPos.npy', 'alf/FOV*', True),
('mpciROIs.mpciROITypes.npy', 'alf/FOV*', True),
('mpciROIs.cellClassifier.npy', 'alf/FOV*', True),
('mpciROIs.uuids.csv', 'alf/FOV*', True),
('mpciROITypes.names.tsv', 'alf/FOV*', True),
('mpciROIs.masks.npy', 'alf/FOV*', True),
('mpciROIs.neuropilMasks.npy', 'alf/FOV*', True),
Expand Down Expand Up @@ -328,6 +329,11 @@ def _rename_outputs(self, suite2p_dir, frameQC_names, frameQC, rename_dict=None)
np.save(fov_dir.joinpath('mpciROIs.stackPos.npy'), np.asarray([(*s['med'], 0) for s in stat], dtype=int))
np.save(fov_dir.joinpath('mpciROIs.cellClassifier.npy'), np.asarray(iscell[:, 1], dtype=float))
np.save(fov_dir.joinpath('mpciROIs.mpciROITypes.npy'), np.asarray(iscell[:, 0], dtype=np.int16))
# clusters uuids
uuid_list = ['uuids'] + list(map(str, [uuid.uuid4() for _ in range(len(iscell))]))
with open(fov_dir.joinpath('mpciROIs.uuids.csv'), 'w+') as fid:
fid.write('\n'.join(uuid_list))

pd.DataFrame([(0, 'no cell'), (1, 'cell')], columns=['roi_values', 'roi_labels']
).to_csv(fov_dir.joinpath('mpciROITypes.names.tsv'), sep='\t', index=False)
# ROI and neuropil masks
Expand Down
4 changes: 4 additions & 0 deletions ibllib/tests/extractors/test_ephys_trials.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ def test_align_to_trial(self):
desired_out = np.array([4, 13, np.nan, 33, np.nan])
self.assertTrue(np.allclose(desired_out, t_event_nans, equal_nan=True, atol=0, rtol=0))

# test errors
self.assertRaises(ValueError, ephys_fpga._assign_events_to_trial, np.array([0., 2., 1.]), t_event)
self.assertRaises(ValueError, ephys_fpga._assign_events_to_trial, t_trial_start, np.array([0., 2., 1.]))

def test_wheel_trace_from_sync(self):
pos_ = - np.array([-1, 0, -1, -2, -1, -2]) * (np.pi / ephys_fpga.WHEEL_TICKS)
ta = np.array([1, 2, 3, 4, 5, 6])
Expand Down
20 changes: 20 additions & 0 deletions ibllib/tests/test_mesoscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
from unittest import mock
import tempfile
import json
from itertools import chain
from pathlib import Path

from one.api import ONE
import numpy as np

from ibllib.pipes.mesoscope_tasks import MesoscopePreprocess, MesoscopeFOV, \
find_triangle, surface_normal, _nearest_neighbour_1d
from ibllib.io.extractors import mesoscope
from ibllib.tests import TEST_DB

# Mock suit2p which is imported in MesoscopePreprocess
Expand Down Expand Up @@ -248,3 +250,21 @@ def tearDown(self) -> None:
Here we return the mode back to the default after testing behaviour in offline mode.
"""
self.one.mode = 'auto'


class TestImagingMeta(unittest.TestCase):
"""Test raw imaging metadata versioning."""
def test_patch_imaging_meta(self):
"""Test for ibllib.io.extractors.mesoscope.patch_imaging_meta function."""
meta = {'version': '0.1.0', 'FOV': [{'roiUuid': None}, {'roiUUID': None}]}
new_meta = mesoscope.patch_imaging_meta(meta)
self.assertEqual(set(chain(*map(dict.keys, new_meta['FOV']))), {'roiUUID'})
meta = {'FOV': [
dict.fromkeys(['topLeftDeg', 'topRightDeg', 'bottomLeftDeg', 'bottomRightDeg']),
dict.fromkeys(['topLeftMM', 'topRightMM', 'bottomLeftMM', 'bottomRightMM'])
]}
new_meta = mesoscope.patch_imaging_meta(meta)
self.assertIn('channelSaved', new_meta)
self.assertCountEqual(new_meta['FOV'][0], ('Deg', 'MM'))
expected = ('topLeft', 'topRight', 'bottomLeft', 'bottomRight')
self.assertCountEqual(new_meta['FOV'][0]['MM'], expected)

0 comments on commit eab63da

Please sign in to comment.