Skip to content

Commit ed73643

Browse files
authored
include raw qc fails in suptitle
1 parent 5803409 commit ed73643

File tree

1 file changed

+75
-55
lines changed

1 file changed

+75
-55
lines changed

dlc/overview_plot_dlc.py

Lines changed: 75 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ def get_repeated_sites():
5353
return eids
5454

5555

56+
def get_bwm_sessions():
57+
one = ONE()
58+
traj_traced = one.alyx.rest('trajectories', 'list', provenance='Planned',
59+
django='probe_insertion__session__project__name__'
60+
'icontains,ibl_neuropixel_brainwide_01,'
61+
'probe_insertion__session__qc__lt,50,'
62+
'probe_insertion__session__extended_qc__behavior,1,'
63+
'probe_insertion__json__extended_qc__tracing_exists,True,'
64+
'~probe_insertion__session__extended_qc___task_stimOn_goCue_delays__lt,0.9,'
65+
'~probe_insertion__session__extended_qc___task_response_feedback_delays__lt,0.9,'
66+
'~probe_insertion__session__extended_qc___task_response_stimFreeze_delays__lt,0.9,'
67+
'~probe_insertion__session__extended_qc___task_wheel_move_before_feedback__lt,0.9,'
68+
'~probe_insertion__session__extended_qc___task_wheel_freeze_during_quiescence__lt,0.9,'
69+
'~probe_insertion__session__extended_qc___task_error_trial_event_sequence__lt,0.9,'
70+
'~probe_insertion__session__extended_qc___task_correct_trial_event_sequence__lt,0.9,'
71+
'~probe_insertion__session__extended_qc___task_n_trial_events__lt,0.9,'
72+
'~probe_insertion__session__extended_qc___task_reward_volumes__lt,0.9,'
73+
'~probe_insertion__session__extended_qc___task_reward_volume_set__lt,0.9,'
74+
'~probe_insertion__session__extended_qc___task_stimulus_move_before_goCue__lt,0.9,'
75+
'~probe_insertion__session__extended_qc___task_audio_pre_trial__lt,0.9')
76+
eids = [[x['session']['id'],x['probe_name']] for x in traj_traced]
77+
return eids
5678

5779

5880
def check_progress():
@@ -162,26 +184,8 @@ def get_dlc_XYs(eid, video_type):
162184

163185
#video_type = 'left'
164186
one = ONE()
165-
dataset_types = ['alf/_ibl_leftCamera.dlc.pqt',
166-
'alf/_ibl_leftCamera.times.npy']
167-
168-
a = one.list_datasets(eid)
169-
if not all([u in a for u in dataset_types]):
170-
print('not all data available')
171-
return
172-
173-
local_path = one.eid2path(eid)
174-
alf_path = local_path / 'alf'
175-
176-
cam0 = alf.io.load_object(
177-
alf_path,
178-
'%sCamera' %
179-
video_type,
180-
namespace='ibl')
181-
182-
Times = cam0['times']
183-
184-
cam = cam0['dlc']
187+
Times = one.load_dataset(eid,f'alf/_ibl_{video_type}Camera.times.npy')
188+
cam = one.load_dataset(eid,f'alf/_ibl_{video_type}Camera.dlc.pqt')
185189
points = np.unique(['_'.join(x.split('_')[:-1]) for x in cam.keys()])
186190

187191
# Set values to nan if likelyhood is too low # for pqt: .to_numpy()
@@ -196,35 +200,23 @@ def get_dlc_XYs(eid, video_type):
196200
XYs[point] = np.array(
197201
[x, y])
198202

199-
return Times, XYs
200-
203+
return Times, XYs
201204

205+
# a = one.list_datasets(eid)
206+
# if not all([u in a for u in dataset_types]):
207+
# print('not all data available')
208+
# return
209+
202210
def get_ME(eid, video_type):
203211

204212
#video_type = 'left'
205-
one = ONE()
206-
dataset_types = [f'alf/{video_type}Camera.ROIMotionEnergy.npy',
207-
f'alf/_ibl_{video_type}Camera.times.npy']
208-
209-
a = one.list_datasets(eid)
210-
if not all([u in a for u in dataset_types]):
211-
print('not all data available')
212-
return
213-
214-
local_path = one.eid2path(eid)
215-
alf_path = local_path / 'alf'
213+
one = ONE()
216214

217-
cam0 = alf.io.load_object(
218-
alf_path,
219-
'%sCamera' %
220-
video_type,
221-
namespace='ibl')
222-
223-
ME = np.load(alf_path / f'{video_type}Camera.ROIMotionEnergy.npy')
224-
225-
Times = cam0['times']
215+
216+
Times = one.load_dataset(eid,f'alf/_ibl_{video_type}Camera.times.npy')
217+
ME = one.load_dataset(eid,f'alf/{video_type}Camera.ROIMotionEnergy.npy')
226218

227-
return Times, ME
219+
return Times, ME
228220

229221

230222

@@ -267,7 +259,10 @@ def get_example_images(eid):
267259
def get_mean_positions(XYs):
268260
mloc = {} # mean locations
269261
for point in XYs:
270-
mloc[point] = [int(np.nanmean(XYs[point][0])), int(np.nanmean(XYs[point][1]))]
262+
if point in ['tube_bottom', 'tube_top']:
263+
continue
264+
mloc[point] = [int(np.nanmean(XYs[point][0])),
265+
int(np.nanmean(XYs[point][1]))]
271266
return mloc
272267

273268

@@ -291,7 +286,7 @@ def plot_paw_on_image(eid, video_type='left', XYs = None):
291286
if XYs == None:
292287
_, XYs = get_dlc_XYs(eid, video_type)
293288

294-
Cs = dict(zip(XYs.keys(),Cs))
289+
Cs = dict(zip(XYs.keys(),Cs))
295290

296291
ds = {'body':3,'left':6,'right':15}
297292

@@ -306,7 +301,7 @@ def plot_paw_on_image(eid, video_type='left', XYs = None):
306301
ys = XYs[point][1][0::ds[video_type]]
307302

308303
plt.scatter(xs,ys, alpha = 0.05, s = 2,
309-
label = point, color = Cs[point])
304+
label = point, c = Cs[point])
310305

311306
plt.axis('off')
312307
plt.tight_layout()
@@ -373,7 +368,7 @@ def plot_paw_on_image(eid, video_type='left', XYs = None):
373368
ys = XYs[point][1][0::ds[video_type]]
374369

375370
axins.scatter(xs,ys, alpha = 1, s = 0.001,
376-
label = point, color = Cs[point])
371+
label = point, c = Cs[point])
377372
axins.set_xlim(x0, x1)
378373
axins.set_ylim(y1, y0)
379374
axins.set_xticklabels('')
@@ -1272,9 +1267,9 @@ def plot_all(eid):
12721267

12731268
# print QC outcome in title and DLC task version
12741269
one = ONE()
1275-
task = one.alyx.rest('tasks', 'list', session=eid, name='EphysDLC')[0]
1270+
12761271
det = one.get_details(eid, True)['extended_qc']
1277-
p = one.path_from_eid(eid)
1272+
p = one.eid2path(eid)
12781273
s1 = '_'.join([str(p).split('/')[i] for i in [4,6,7,8]])
12791274

12801275
dlc_qcs = [ 'time_trace_length_match',
@@ -1283,6 +1278,11 @@ def plot_all(eid):
12831278
'pupil_blocked',
12841279
'lick_detection']
12851280

1281+
raw_qcs = ['focus','position','brightness',
1282+
'resolution','timestamps','file_headers',
1283+
'wheel_alignment','camera_times','framerate',
1284+
'pin_state','dropped_frames']
1285+
12861286

12871287
qcs = ['task','behavior','videoLeft','videoRight','videoBody',
12881288
'dlcLeft','dlcRight','dlcBody']
@@ -1292,14 +1292,27 @@ def plot_all(eid):
12921292
try:
12931293
if det[q] == 'FAIL':
12941294

1295-
if 'dlc' in q:
1295+
if ('dlc' in q):
12961296
l.append('\n')
12971297
l.append(q+':'+str(det[q])+'-->')
12981298
video_type = q[3:]
12991299
for dlc_qc in dlc_qcs:
13001300
w = f'_dlc{video_type}_{dlc_qc}'
13011301
if not det[w]:
1302-
l.append(w+':'+str(det[w])+',')
1302+
l.append(w+':'+str(det[w])+',')
1303+
elif ('video' in q):
1304+
l.append('\n')
1305+
l.append(q+':'+str(det[q])+'-->')
1306+
video_type = q[5:]
1307+
for raw_qc in raw_qcs:
1308+
w = f'_video{video_type}_{raw_qc}'
1309+
if type(det[w]) == bool:
1310+
if (not det[w]):
1311+
l.append(w+':'+str(det[w])+',')
1312+
if type(det[w]) != bool:
1313+
if not det[w][0]:
1314+
l.append(w+':'+str(det[w])+',')
1315+
13031316
else:
13041317
l.append(q+':'+str(det[q])+',')
13051318
except:
@@ -1309,14 +1322,21 @@ def plot_all(eid):
13091322

13101323
ntrials = len(one.load_object(eid, 'trials')['goCue_times'])
13111324

1325+
task = one.alyx.rest('tasks', 'list', session=eid, name='EphysDLC')
13121326

1313-
plt.suptitle(s1+'#Trials:'+str(ntrials)+', DLC version: '
1314-
+str(task['version'])+' \n '+s2,
1315-
backgroundcolor= 'white', fontsize=6)
1327+
try:
1328+
plt.suptitle(s1+'#Trials:'+str(ntrials)+', DLC version: '
1329+
+str(task[0]['version'])+' \n '+s2,
1330+
backgroundcolor= 'white', fontsize=6)
1331+
except:
1332+
plt.suptitle(s1+'#Trials:'+str(ntrials)+', DLC version: ??'
1333+
+' \n '+s2,
1334+
backgroundcolor= 'white', fontsize=6)
1335+
13161336
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
13171337
#plt.savefig(f'/home/mic/reproducible_dlc/overviewJune/{eid}.png')
13181338
#plt.savefig(f'/home/mic/reproducible_dlc/all_DLC/{s1}_{eid}.png')
1319-
plt.savefig(f'/home/mic/reproducible_dlc/repro/{s1}_{eid}.png')
1339+
plt.savefig(f'/home/mic/reproducible_dlc/miles_QC_update/{s1}_{eid}.png')
13201340
plt.close()
13211341

13221342

0 commit comments

Comments
 (0)