def test_histology_get_brain_regions(self): # first part of the test is to check on an actual track file for file_track in self.path_tracks.rglob("*_pts.csv"): xyz = histology.load_track_csv(file_track) channels, ins = histology.get_brain_regions(xyz=xyz, brain_atlas=brain_atlas) # also check that it works from an insertion channels, ins2 = histology.get_brain_regions(xyz=ins.xyz, brain_atlas=brain_atlas) self.assertTrue(channels.acronym[-1] == 'VISpm1') self.assertTrue(channels.acronym[0] == 'APN') a = np.array([ins.x, ins.y, ins.z, ins.phi, ins.theta, ins.depth]) b = np.array([ins2.x, ins2.y, ins2.z, ins2.phi, ins2.theta, ins2.depth]) self.assertTrue(np.all(np.isclose(a, b)))
def compare_2_probes(dict1,dict2): ''' Given two probes in the following format, it calculates the cerror between the probes. Dict2 is compared to dict1 Dict format for Insertion function {'x': 544.0, 'y': 1285.0, 'z': 0.0, 'phi': 0.0, 'theta': 5.0, 'depth': 4501.0} INPUT: dict_1,dict_2: 2 dictionaries with probe coordinates OUTPUT: cecler: Comulative ecludian error r_miss: each channel that debiates from the intetion adds 1/divided by total number of channels. 1 is all are different r_out: number of unique regions in dict1 missed divided by total possible ''' # mean eucledian error dict_1_ins = atlas.Insertion.from_dict(dict1) dict1_regions, _, dict1_xyz = histology.get_brain_regions(dict_1_ins.xyz) dict_2_ins = atlas.Insertion.from_dict(dict2) dict2_regions, _, dict2_xyz = histology.get_brain_regions(dict_2_ins.xyz) cecler = 0 for i in range(len(dict1_xyz)): cecler += distance.euclidean(dict1_xyz[i,:], dict2_xyz[i,:]) mean_cecler = (cecler/len(dict1_xyz))*(10**6) #score areas missmatch r_miss = 0 for i in range(len(dict1_regions['id'])): r_miss += 1 - int(dict1_regions['id'][i] == dict2_regions['id'][i]) r_miss = r_miss/len(dict1_regions['id']) #percentage of regions totally missed r_out = (1 - len(np.intersect1d(np.unique(dict1_regions['id']), np.unique(dict2_regions['id'])))/ len(np.unique(dict1_regions['id']))) return mean_cecler, r_miss, r_out
environment installation guide https://github.com/int-brain-lab/iblenv ''' # Author: Olivier Winter import numpy as np from ibllib.pipes import histology import ibllib.atlas as atlas # === Parameters section (edit) === track_file = "/Users/gaelle/Downloads/electrodetracks_lic3/2019-08-27_lic3_002_probe00_pts.csv" FULL_BLOWN_GUI = True # set to False for simple matplotlib view # === Code (do not edit) === ba = atlas.AllenAtlas(res_um=25) xyz_picks = histology.load_track_csv(track_file) bl, ins = histology.get_brain_regions(xyz_picks) if FULL_BLOWN_GUI: from iblapps.histology import atlas_mpl mw, cax = atlas_mpl.viewatlas(ba, ap_um=np.mean(ins.xyz[:, 1]) * 1e6) else: cax = ba.plot_cslice(ap_coordinate=np.mean(ins.xyz[:, 1])) cax.plot(ins.xyz[:, 0] * 1e6, ins.xyz[:, 2] * 1e6) cax.plot(bl.xyz[:, 0] * 1e6, bl.xyz[:, 2] * 1e6, '*') # cax.plot(ba.bc.xscale * 1e6, ba.top[ba.bc.y2i(np.mean(ins.xyz[:, 1])), :] * 1e6) if FULL_BLOWN_GUI: mw.mpl_widget.draw()