Example #1
0
 def test_03_alignments_disagree(self):
     alignments = {
         '2020-06-26T16:40:14_Karolina_Socha':
         self.alignments['2020-06-26T16:40:14_Karolina_Socha'],
         '2020-06-12T00:39:15_nate':
         self.alignments['2020-06-12T00:39:15_nate']
     }
     trajectory = copy.deepcopy(self.trajectory)
     trajectory.update({'json': alignments})
     traj = one.alyx.rest('trajectories',
                          'update',
                          id=self.prev_traj_id,
                          data=trajectory)
     traj_id = traj['id']
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
     align_qc.load_data(prev_alignments=traj['json'],
                        xyz_picks=np.array(self.xyz_picks) / 1e6,
                        cluster_chns=self.cluster_chns)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
     assert (insertion['json']['qc'] == 'NOT_SET')
     assert (insertion['json']['extended_qc']['alignment_count'] == 2)
     assert (insertion['json']['extended_qc']['alignment_stored'] ==
             '2020-06-26T16:40:14_Karolina_Socha')
     assert (insertion['json']['extended_qc']['alignment_resolved'] == 0)
     assert (insertion['json']['extended_qc']['alignment_qc'] < 0.8)
     traj = one.alyx.rest('trajectories',
                          'list',
                          probe_id=self.probe_id,
                          provenance='Ephys aligned histology track')
     assert (traj_id == traj[0]['id'])
Example #2
0
 def test_05_not_latest_alignments_agree(self):
     alignments = copy.deepcopy(self.alignments)
     trajectory = copy.deepcopy(self.trajectory)
     trajectory.update({'json': alignments})
     traj = one.alyx.rest('trajectories',
                          'update',
                          id=self.prev_traj_id,
                          data=trajectory)
     assert (self.prev_traj_id == traj['id'])
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     align_qc.load_data(prev_alignments=traj['json'],
                        xyz_picks=np.array(self.xyz_picks) / 1e6,
                        cluster_chns=self.cluster_chns)
     align_qc.resolved = 0
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
     assert (insertion['json']['qc'] == 'NOT_SET')
     assert (insertion['json']['extended_qc']['alignment_count'] == 4)
     assert (insertion['json']['extended_qc']['alignment_stored'] ==
             '2020-06-19T10:52:36_noam.roth')
     assert (insertion['json']['extended_qc']['alignment_resolved'] == 1)
     assert (
         insertion['json']['extended_qc']['alignment_resolved_by'] == 'qc')
     assert (insertion['json']['extended_qc']['alignment_qc'] > 0.8)
     assert (np.isclose(insertion['json']['extended_qc']['alignment_qc'],
                        0.952319))
     traj = one.alyx.rest('trajectories',
                          'list',
                          probe_id=self.probe_id,
                          provenance='Ephys aligned histology track')
     assert (self.prev_traj_id != traj[0]['id'])
Example #3
0
    def setUpClass(cls) -> None:
        data = np.load(Path(
            Path(__file__).parent.parent.joinpath(
                'fixtures', 'qc', 'data_alignmentqc_manual.npz')),
                       allow_pickle=True)
        cls.xyz_picks = (data['xyz_picks'] * 1e6).tolist()
        cls.alignments = data['alignments'].tolist()
        cls.cluster_chns = data['cluster_chns']

        data = np.load(Path(
            Path(__file__).parent.parent.joinpath(
                'fixtures', 'qc', 'data_alignmentqc_existing.npz')),
                       allow_pickle=True)
        insertion = data['insertion'].tolist()
        insertion['json'] = {'xyz_picks': cls.xyz_picks}
        probe_insertion = one.alyx.rest('insertions', 'create', data=insertion)
        cls.probe_id = probe_insertion['id']
        cls.probe_name = probe_insertion['name']
        cls.trajectory = data['trajectory'].tolist()
        cls.trajectory.update({'probe_insertion': cls.probe_id})
        cls.trajectory.update({'json': cls.alignments})
        cls.traj = one.alyx.rest('trajectories', 'create', data=cls.trajectory)

        align_qc = AlignmentQC(cls.probe_id,
                               one=one,
                               brain_atlas=brain_atlas,
                               channels=False)
        align_qc.load_data(prev_alignments=cls.traj['json'],
                           xyz_picks=np.array(cls.xyz_picks) / 1e6,
                           cluster_chns=cls.cluster_chns)
        cls.file_paths = align_qc.resolve_manual('2020-09-28T15:57:25_mayo',
                                                 update=True,
                                                 upload_alyx=True,
                                                 upload_flatiron=True)
        print(cls.file_paths)
Example #4
0
    def test_03_manual_resolution_not_latest(self):
        align_qc = AlignmentQC(self.probe_id,
                               one=one,
                               brain_atlas=brain_atlas,
                               channels=False)
        align_qc.load_data(prev_alignments=self.traj['json'],
                           xyz_picks=np.array(self.xyz_picks) / 1e6,
                           cluster_chns=self.cluster_chns)
        align_qc.resolve_manual('2020-09-28T10:03:06_alejandro',
                                update=True,
                                upload_alyx=True,
                                upload_flatiron=False,
                                force=True)
        insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
        assert (insertion['json']['qc'] == 'NOT_SET')
        assert (insertion['json']['extended_qc']['alignment_count'] == 3)
        assert (insertion['json']['extended_qc']['alignment_stored'] ==
                '2020-09-28T10:03:06_alejandro')
        assert (insertion['json']['extended_qc']['alignment_resolved'] == 1)
        assert (insertion['json']['extended_qc']['alignment_resolved_by'] ==
                'experimenter')
        assert (insertion['json']['extended_qc']['alignment_qc'] < 0.8)
        assert (np.isclose(insertion['json']['extended_qc']['alignment_qc'],
                           0.604081))

        traj = one.alyx.rest('trajectories',
                             'list',
                             probe_id=self.probe_id,
                             provenance='Ephys aligned histology track')
        assert (self.prev_traj_id != traj[0]['id'])
Example #5
0
    def _05_not_latest_alignments_agree(self):
        alignments = copy.deepcopy(self.alignments)
        trajectory = copy.deepcopy(self.trajectory)
        trajectory.update({'json': alignments})
        traj = one.alyx.rest('trajectories',
                             'update',
                             id=self.prev_traj_id,
                             data=trajectory)
        self.assertEqual(self.prev_traj_id, traj['id'])
        align_qc = AlignmentQC(self.probe_id,
                               one=one,
                               brain_atlas=brain_atlas,
                               channels=False)
        align_qc.load_data(prev_alignments=traj['json'],
                           xyz_picks=np.array(self.xyz_picks) / 1e6,
                           cluster_chns=self.cluster_chns,
                           depths=SITES_COORDINATES[:, 1],
                           chn_coords=SITES_COORDINATES)
        align_qc.resolved = 0
        align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)

        _verify(self,
                alignment_resolved='qc',
                alignment_qc=0.952319,
                alignment_count=4,
                alignment_stored='2020-06-19T10:52:36_noam.roth',
                trajectory_created=True)
Example #6
0
    def _04_alignments_agree(self):
        alignments = {
            '2020-06-19T10:52:36_noam.roth':
            self.alignments['2020-06-19T10:52:36_noam.roth'],
            '2020-06-12T00:39:15_nate':
            self.alignments['2020-06-12T00:39:15_nate']
        }
        trajectory = copy.deepcopy(self.trajectory)
        trajectory.update({'json': alignments})
        traj = one.alyx.rest('trajectories',
                             'update',
                             id=self.prev_traj_id,
                             data=trajectory)
        assert (self.prev_traj_id == traj['id'])
        align_qc = AlignmentQC(self.probe_id,
                               one=one,
                               brain_atlas=brain_atlas,
                               channels=False)
        align_qc.load_data(cluster_chns=self.cluster_chns,
                           depths=SITES_COORDINATES[:, 1],
                           chn_coords=SITES_COORDINATES)
        align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)

        _verify(self,
                alignment_resolved='qc',
                alignment_qc=0.952319,
                trajectory_created=False,
                alignment_count=2,
                alignment_stored='2020-06-19T10:52:36_noam.roth')
Example #7
0
    def _03_alignments_disagree(self):
        alignments = {
            '2020-06-26T16:40:14_Karolina_Socha':
            self.alignments['2020-06-26T16:40:14_Karolina_Socha'],
            '2020-06-12T00:39:15_nate':
            self.alignments['2020-06-12T00:39:15_nate']
        }
        trajectory = copy.deepcopy(self.trajectory)
        trajectory.update({'json': alignments})
        traj = one.alyx.rest('trajectories',
                             'update',
                             id=self.prev_traj_id,
                             data=trajectory)
        align_qc = AlignmentQC(self.probe_id,
                               one=one,
                               brain_atlas=brain_atlas,
                               channels=False)
        align_qc.load_data(prev_alignments=traj['json'],
                           xyz_picks=np.array(self.xyz_picks) / 1e6,
                           cluster_chns=self.cluster_chns,
                           depths=SITES_COORDINATES[:, 1],
                           chn_coords=SITES_COORDINATES)
        align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)

        _verify(self,
                alignment_qc=0.782216,
                alignment_resolved=False,
                alignment_count=2,
                alignment_stored='2020-06-26T16:40:14_Karolina_Socha',
                trajectory_created=False)
Example #8
0
 def test_04_alignments_agree(self):
     alignments = {
         '2020-06-19T10:52:36_noam.roth':
         self.alignments['2020-06-19T10:52:36_noam.roth'],
         '2020-06-12T00:39:15_nate':
         self.alignments['2020-06-12T00:39:15_nate']
     }
     trajectory = copy.deepcopy(self.trajectory)
     trajectory.update({'json': alignments})
     traj = one.alyx.rest('trajectories',
                          'update',
                          id=self.prev_traj_id,
                          data=trajectory)
     assert (self.prev_traj_id == traj['id'])
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     align_qc.load_data(cluster_chns=self.cluster_chns)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
     assert (insertion['json']['qc'] == 'NOT_SET')
     assert (insertion['json']['extended_qc']['alignment_count'] == 2)
     assert (insertion['json']['extended_qc']['alignment_stored'] ==
             '2020-06-19T10:52:36_noam.roth')
     assert (insertion['json']['extended_qc']['alignment_resolved'] == 1)
     assert (
         insertion['json']['extended_qc']['alignment_resolved_by'] == 'qc')
     assert (insertion['json']['extended_qc']['alignment_qc'] > 0.8)
     traj = one.alyx.rest('trajectories',
                          'list',
                          probe_id=self.probe_id,
                          provenance='Ephys aligned histology track')
     assert (self.prev_traj_id == traj[0]['id'])
Example #9
0
 def test_01_no_alignments(self):
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
     assert (insertion['json']['qc'] == 'NOT_SET')
     assert (len(insertion['json']['extended_qc']) == 0)
Example #10
0
 def _01_no_alignments(self):
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     insertion = one.alyx.get(f'/insertions/{self.probe_id}', clobber=True)
     self.assertEqual('NOT_SET', insertion['json']['qc'])
     self.assertTrue(len(insertion['json']['extended_qc']) == 0)
Example #11
0
    def update_qc(self, upload_alyx=True, upload_flatiron=True):
        # if resolved just update the alignment_number
        align_qc = AlignmentQC(self.probe_id, one=self.one, brain_atlas=self.brain_atlas)
        align_qc.load_data(prev_alignments=self.alignments, xyz_picks=self.xyz_picks,
                           depths=self.chn_depths, cluster_chns=self.cluster_chns)
        results = align_qc.run(update=True, upload_alyx=upload_alyx,
                               upload_flatiron=upload_flatiron)
        align_qc.update_experimenter_evaluation(prev_alignments=self.alignments)

        self.resolved = results['alignment_resolved']

        return self.resolved
Example #12
0
 def test_02_one_alignment(self):
     alignments = {'2020-06-26T16:40:14_Karolina_Socha':
                   self.alignments['2020-06-26T16:40:14_Karolina_Socha']}
     trajectory = copy.deepcopy(self.trajectory)
     trajectory.update({'json': alignments})
     _ = one.alyx.rest('trajectories', 'create', data=trajectory)
     align_qc = AlignmentQC(self.probe_id, one=one, brain_atlas=brain_atlas, channels=False)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
     assert (insertion['json']['qc'] == 'NOT_SET')
     assert (insertion['json']['extended_qc']['alignment_count'] == 1)
     assert (insertion['json']['extended_qc']['alignment_stored'] ==
             '2020-06-26T16:40:14_Karolina_Socha')
     assert (insertion['json']['extended_qc']['alignment_resolved'] == 0)
Example #13
0
 def test_01_normal_computation(self):
     align_qc = AlignmentQC(self.probe_id, one=one, brain_atlas=brain_atlas, channels=False)
     align_qc.load_data(prev_alignments=self.traj['json'],
                        xyz_picks=np.array(self.xyz_picks) / 1e6,
                        cluster_chns=self.cluster_chns)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     insertion = one.alyx.rest('insertions', 'read', id=self.probe_id)
     assert (insertion['json']['qc'] == 'NOT_SET')
     assert (insertion['json']['extended_qc']['alignment_count'] == 3)
     assert (insertion['json']['extended_qc']['alignment_stored'] ==
             '2020-09-28T15:57:25_mayo')
     assert (insertion['json']['extended_qc']['alignment_resolved'] == 0)
     assert (insertion['json']['extended_qc']['alignment_qc'] < 0.8)
     traj = one.alyx.rest('trajectories', 'list', probe_id=self.probe_id,
                          provenance='Ephys aligned histology track')
     assert(self.prev_traj_id == traj[0]['id'])
Example #14
0
 def _01_normal_computation(self):
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     align_qc.load_data(prev_alignments=self.traj['json'],
                        xyz_picks=np.array(self.xyz_picks) / 1e6,
                        cluster_chns=self.cluster_chns,
                        depths=SITES_COORDINATES[:, 1],
                        chn_coords=SITES_COORDINATES)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     _verify(self,
             alignment_resolved=False,
             alignment_stored='2020-09-28T15:57:25_mayo',
             alignment_count=3,
             trajectory_created=False,
             alignment_qc=0.604081)
Example #15
0
 def _02_one_alignment(self):
     alignments = {
         '2020-06-26T16:40:14_Karolina_Socha':
         self.alignments['2020-06-26T16:40:14_Karolina_Socha']
     }
     trajectory = copy.deepcopy(self.trajectory)
     trajectory.update({'json': alignments})
     _ = one.alyx.rest('trajectories', 'create', data=trajectory)
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     align_qc.run(update=True, upload_alyx=True, upload_flatiron=False)
     _verify(self,
             alignment_count=1,
             alignment_stored='2020-06-26T16:40:14_Karolina_Socha',
             alignment_resolved=False)
Example #16
0
 def _03_manual_resolution_not_latest(self):
     align_qc = AlignmentQC(self.probe_id,
                            one=one,
                            brain_atlas=brain_atlas,
                            channels=False)
     align_qc.load_data(prev_alignments=self.traj['json'],
                        xyz_picks=np.array(self.xyz_picks) / 1e6,
                        cluster_chns=self.cluster_chns,
                        depths=SITES_COORDINATES[:, 1],
                        chn_coords=SITES_COORDINATES)
     align_qc.resolve_manual('2020-09-28T10:03:06_alejandro',
                             update=True,
                             upload_alyx=True,
                             upload_flatiron=False,
                             force=True)
     _verify(self,
             alignment_resolved='experimenter',
             alignment_stored='2020-09-28T10:03:06_alejandro',
             alignment_count=3,
             trajectory_created=True,
             alignment_qc=0.604081)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 28 08:57:24 2020

@author: guido
"""


from oneibl.one import ONE
one = ONE()
probe_id = one.alyx.rest('insertions', 'list', subject='SWC_014', date='2019-12-10', name='probe01')[0]['id']

traj = one.alyx.rest('trajectories', 'list', probe_insertion=probe_id, provenance='Ephys aligned histology track')[0]
alignment_keys = traj['json'].keys()
print(alignment_keys)

from ibllib.qc.alignment_qc import AlignmentQC

align_key = "2020-06-15T10:03:50_guido"  # change this to your chosen alignment key
align_qc = AlignmentQC(probe_id, one=one)
align_qc.resolve_manual(align_key)


from oneibl.one import ONE
one = ONE()
probe_id = one.alyx.rest('insertions', 'list', subject='SWC_014', date='2019-12-10', name='probe01')[0]['id']
align_key =  '2020-06-15T10:03:50_guido'
from ibllib.qc.alignment_qc import AlignmentQC
align_qc = AlignmentQC(probe_id, one=one)
align_qc.resolve_manual(align_key, force=True)