Skip to content

Commit 07c1bbd

Browse files
committed
add insertion by id
1 parent b4f613c commit 07c1bbd

File tree

4 files changed

+161
-64
lines changed

4 files changed

+161
-64
lines changed

needles2/coverageUI.ui

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,25 @@
4545
<rect>
4646
<x>10</x>
4747
<y>10</y>
48-
<width>10</width>
48+
<width>40</width>
4949
<height>30</height>
5050
</rect>
5151
</property>
5252
<property name="text">
53-
<string>x:</string>
53+
<string>ml:</string>
5454
</property>
5555
</widget>
5656
<widget class="QLabel" name="ytitle_label">
5757
<property name="geometry">
5858
<rect>
5959
<x>10</x>
6060
<y>40</y>
61-
<width>10</width>
61+
<width>40</width>
6262
<height>30</height>
6363
</rect>
6464
</property>
6565
<property name="text">
66-
<string>y:</string>
66+
<string>ap:</string>
6767
</property>
6868
</widget>
6969
<widget class="QLabel" name="dtitle_label">
@@ -318,19 +318,19 @@
318318
<widget class="QLineEdit" name="x_label">
319319
<property name="geometry">
320320
<rect>
321-
<x>30</x>
321+
<x>50</x>
322322
<y>15</y>
323-
<width>80</width>
323+
<width>61</width>
324324
<height>20</height>
325325
</rect>
326326
</property>
327327
</widget>
328328
<widget class="QLineEdit" name="y_label">
329329
<property name="geometry">
330330
<rect>
331-
<x>30</x>
331+
<x>50</x>
332332
<y>45</y>
333-
<width>80</width>
333+
<width>61</width>
334334
<height>20</height>
335335
</rect>
336336
</property>

needles2/mainUI.ui

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>1426</width>
9+
<width>1521</width>
1010
<height>908</height>
1111
</rect>
1212
</property>
@@ -19,8 +19,8 @@
1919
<rect>
2020
<x>350</x>
2121
<y>10</y>
22-
<width>491</width>
23-
<height>271</height>
22+
<width>500</width>
23+
<height>400</height>
2424
</rect>
2525
</property>
2626
</widget>
@@ -48,49 +48,75 @@
4848
<property name="geometry">
4949
<rect>
5050
<x>350</x>
51-
<y>300</y>
52-
<width>491</width>
53-
<height>271</height>
51+
<y>450</y>
52+
<width>500</width>
53+
<height>400</height>
5454
</rect>
5555
</property>
5656
</widget>
5757
<widget class="PlotWidget" name="fig_horizontal">
5858
<property name="geometry">
5959
<rect>
60-
<x>350</x>
61-
<y>590</y>
62-
<width>491</width>
63-
<height>271</height>
60+
<x>880</x>
61+
<y>450</y>
62+
<width>500</width>
63+
<height>400</height>
6464
</rect>
6565
</property>
6666
</widget>
6767
<widget class="PlotWidget" name="fig_top">
6868
<property name="geometry">
6969
<rect>
70-
<x>860</x>
70+
<x>880</x>
7171
<y>10</y>
72-
<width>351</width>
73-
<height>411</height>
72+
<width>500</width>
73+
<height>400</height>
7474
</rect>
7575
</property>
7676
</widget>
7777
<widget class="PlotWidget" name="fig_probe">
7878
<property name="geometry">
7979
<rect>
80-
<x>1240</x>
80+
<x>1400</x>
8181
<y>10</y>
82-
<width>171</width>
82+
<width>101</width>
8383
<height>841</height>
8484
</rect>
8585
</property>
8686
</widget>
87+
<widget class="QLabel" name="per_title_label">
88+
<property name="geometry">
89+
<rect>
90+
<x>20</x>
91+
<y>530</y>
92+
<width>101</width>
93+
<height>16</height>
94+
</rect>
95+
</property>
96+
<property name="text">
97+
<string>Coverage increase</string>
98+
</property>
99+
</widget>
100+
<widget class="QLabel" name="per_label">
101+
<property name="geometry">
102+
<rect>
103+
<x>130</x>
104+
<y>530</y>
105+
<width>47</width>
106+
<height>13</height>
107+
</rect>
108+
</property>
109+
<property name="text">
110+
<string/>
111+
</property>
112+
</widget>
87113
</widget>
88114
<widget class="QMenuBar" name="menubar">
89115
<property name="geometry">
90116
<rect>
91117
<x>0</x>
92118
<y>0</y>
93-
<width>1426</width>
119+
<width>1521</width>
94120
<height>21</height>
95121
</rect>
96122
</property>

needles2/probe_model.py

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
class ProbeModel:
23-
def __init__(self, one=None, ba=None):
23+
def __init__(self, one=None, ba=None, lazy=False):
2424

2525
self.one = one or ONE()
2626
self.ba = ba or AllenAtlas(25)
@@ -31,10 +31,14 @@ def __init__(self, one=None, ba=None):
3131
'Resolved': {},
3232
'Best': {}}
3333
self.ins = {}
34+
self.cvol = None
35+
self.cvol_flat = None
36+
self.initialised = False
3437

35-
# for histology get the insertions and compute the trajectory from them. Means only one
36-
# long query to alyx and use xyz picks for channels and coverage lower down. More complicated
37-
# but will speed things up
38+
if not lazy:
39+
self.initialise()
40+
41+
def initialise(self):
3842
self.get_traj_for_provenance(provenance='Histology track', django=['x__isnull,False'])
3943
self.get_traj_for_provenance(provenance='Ephys aligned histology track')
4044
self.get_traj_for_provenance(provenance='Ephys aligned histology track',
@@ -45,6 +49,7 @@ def __init__(self, one=None, ba=None):
4549
self.traj['Resolved']['is_best'] = np.arange(len(self.traj['Resolved']['traj']))
4650

4751
self.get_insertions_with_xyz()
52+
self.initialised = True
4853

4954
@staticmethod
5055
def get_traj_info(traj):
@@ -171,20 +176,40 @@ def compute_coverage(self, all_channels):
171176
kernel = sum(np.meshgrid(template, template, template))
172177
kernel = 1 - fcn_cosine(DIST_FCN)(np.sqrt(kernel))
173178
#
174-
cvol = fftconvolve(cvol, kernel)
179+
cvol = fftconvolve(cvol, kernel, mode='same')
175180
end = time.time()
176181
print(end-start)
182+
self.cvol = cvol
183+
self.cvol_flat = cvol.flatten()
177184

178185
return cvol
179186

187+
def grid_coverage(self, all_channels, spacing):
188+
cov, bc = histology.coverage_grid(all_channels, spacing, self.ba)
189+
190+
return cov, bc
191+
180192
def add_coverage(self, traj):
181193

182-
cov, xyz = histology.coverage([traj], self.ba)
194+
cov, xyz, flatixyz = histology.coverage([traj], self.ba)
195+
if self.cvol_flat is not None:
196+
idx = np.where(cov.flatten()[flatixyz] > 0.1)[0]
197+
idx_sig = np.where(self.cvol_flat[flatixyz][idx] > 0.1)[0].shape[0]
198+
per_new_coverage = (1 - idx_sig / idx.shape[0]) * 100
199+
else:
200+
per_new_coverage = np.nan
183201

184-
return cov, xyz
202+
return cov, xyz, per_new_coverage
185203

204+
def insertion_by_id(self, ins_id):
205+
traj = self.one.alyx.rest('trajectories', 'list', probe_insertion=ins_id)
206+
ins = self.one.alyx.rest('insertions', 'list', id=ins_id)[0]
207+
val = [PROV_2_VAL[tr['provenance']] for tr in traj]
208+
best_traj = traj[np.argmax(val)]
186209

187-
def get_channels(self, traj, depths = None):
210+
return best_traj, ins
211+
212+
def get_channels(self, traj, ins=None, depths=None):
188213
if depths is None:
189214
depths = SITES_COORDINATES[:, 1]
190215
if traj['provenance'] == 'Planned' or traj['provenance'] == 'Micro-manipulator':
@@ -194,15 +219,21 @@ def get_channels(self, traj, depths = None):
194219
xyz_channels = histology.interpolate_along_track(xyz, (depths +
195220
TIP_SIZE_UM) / 1e6)
196221
else:
197-
ins_idx = np.where(traj['probe_insertion'] == self.ins['ids'])[0][0]
198-
xyz = np.array(self.ins['insertions'][ins_idx]['json']['xyz_picks']) / 1e6
222+
if ins is None:
223+
ins_idx = np.where(traj['probe_insertion'] == self.ins['ids'])[0][0]
224+
xyz = np.array(self.ins['insertions'][ins_idx]['json']['xyz_picks']) / 1e6
225+
else:
226+
xyz = np.array(ins['json']['xyz_picks']) / 1e6
199227
if traj['provenance'] == 'Histology track':
200228
xyz = xyz[np.argsort(xyz[:, 2]), :]
201229
xyz_channels = histology.interpolate_along_track(xyz, (depths +
202230
TIP_SIZE_UM) / 1e6)
203231
else:
204-
align_key = (self.ins['insertions'][ins_idx]['json']['extended_qc']
205-
['alignment_stored'])
232+
if ins is None:
233+
align_key = (self.ins['insertions'][ins_idx]['json']['extended_qc']
234+
['alignment_stored'])
235+
else:
236+
align_key = ins['json']['extended_qc']['alignment_stored']
206237
feature = traj['json'][align_key][0]
207238
track = traj['json'][align_key][1]
208239
ephysalign = EphysAlignment(xyz, depths, track_prev=track,
@@ -212,12 +243,13 @@ def get_channels(self, traj, depths = None):
212243

213244
return xyz_channels
214245

215-
def get_brain_regions(self, traj):
246+
def get_brain_regions(self, traj, ins=None, mapping='Allen'):
216247
depths = SITES_COORDINATES[:, 1]
217-
xyz_channels = self.get_channels(traj, depths)
248+
xyz_channels = self.get_channels(traj, ins=ins, depths=depths)
218249
(region, region_label,
219250
region_colour, _) = EphysAlignment.get_histology_regions(xyz_channels, depths,
220-
brain_atlas=self.ba)
251+
brain_atlas=self.ba,
252+
mapping=mapping)
221253
return region, region_label, region_colour
222254

223255

0 commit comments

Comments
 (0)