Skip to content

Commit 534e619

Browse files
authored
include right and body video frames
1 parent 2da2885 commit 534e619

File tree

1 file changed

+132
-108
lines changed

1 file changed

+132
-108
lines changed

dlc/overview_plot_dlc.py

Lines changed: 132 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import numpy as np
22
import alf.io
3-
#from oneibl.one import ONE
3+
#pip install ONE-api
44
from one.api import ONE
55
from pathlib import Path
66
import pandas as pd
@@ -53,6 +53,8 @@ def get_repeated_sites():
5353
return eids
5454

5555

56+
57+
5658
def check_progress():
5759

5860
one = ONE()
@@ -304,98 +306,115 @@ def plot_paw_on_image(eid, video_type='left', XYs = None):
304306
ys = XYs[point][1][0::ds[video_type]]
305307

306308
plt.scatter(xs,ys, alpha = 0.05, s = 2,
307-
label = point, color = Cs[point])
308-
309-
310-
# plot whisker pad rectangle
311-
mloc = get_mean_positions(XYs)
312-
p_nose = np.array(mloc['nose_tip'])
313-
p_pupil = np.array(mloc['pupil_top_r'])
314-
315-
# heuristic to find whisker area in side videos:
316-
# square with side length half the distance
317-
# between nose and pupil and anchored on midpoint
318-
319-
p_anchor = np.mean([p_nose,p_pupil],axis=0)
320-
squared_dist = np.sum((p_nose-p_pupil)**2, axis=0)
321-
dist = np.sqrt(squared_dist)
322-
whxy = [int(dist/2), int(dist/3),
323-
int(p_anchor[0] - dist/4), int(p_anchor[1])]
324-
325-
rect = patches.Rectangle((whxy[2], whxy[3]), whxy[0], whxy[1],
326-
linewidth=1,
327-
edgecolor='lime',
328-
facecolor='none')
329-
ax = plt.gca()
330-
ax.add_patch(rect)
331-
309+
label = point, color = Cs[point])
310+
332311
plt.axis('off')
333312
plt.tight_layout()
334313
plt.imshow(r,cmap='gray')
335-
plt.tight_layout()
336-
337-
# plot eye region zoom as inset in upper right corner
338-
pivot = np.nanmean(XYs['pupil_top_r'], axis=1)
339-
x0 = int(pivot[0]) - 33
340-
x1 = int(pivot[0]) + 33
341-
y0 = int(pivot[1]) - 28
342-
y1 = int(pivot[1]) + 38
343-
344-
axins = ax.inset_axes([0.65, 0.6, 0.5, 0.5])
345-
axins.spines['bottom'].set_color('white')
346-
axins.spines['top'].set_color('white')
347-
axins.spines['right'].set_color('white')
348-
axins.spines['left'].set_color('white')
349-
axins.imshow(r, cmap='gray', origin="lower")
314+
plt.tight_layout()
315+
316+
317+
if video_type != 'body':
350318

351-
for point in XYs:# ['paw_l','paw_r']:
352-
if point in ['tube_bottom', 'tube_top']:
353-
continue
354-
355-
# downsample; normalise number of points to be the same
356-
# across all sessions
357-
xs = XYs[point][0][0::ds[video_type]]
358-
ys = XYs[point][1][0::ds[video_type]]
359-
360-
axins.scatter(xs,ys, alpha = 0.05, s = 0.1,
361-
label = point, color = Cs[point])
362-
axins.set_xlim(x0, x1)
363-
axins.set_ylim(y1, y0)
364-
axins.set_xticklabels('')
365-
axins.set_yticklabels('')
366-
#ax.indicate_inset_zoom(axins, edgecolor="white")
367-
368-
# plot tongue region zoom as inset in llower right corner
369-
p1 = np.nanmean(XYs['tube_top'], axis=1)
370-
p2 = np.nanmean(XYs['tube_bottom'], axis=1)
371-
pivot = np.nanmean([p1,p2], axis=0)
372-
x0 = int(pivot[0]) - 60
373-
x1 = int(pivot[0]) + 100
374-
y0 = int(pivot[1]) - 100
375-
y1 = int(pivot[1]) + 60
376-
377-
axins = ax.inset_axes([0.65, 0.1, 0.5, 0.5])
378-
axins.spines['bottom'].set_color('white')
379-
axins.spines['top'].set_color('white')
380-
axins.spines['right'].set_color('white')
381-
axins.spines['left'].set_color('white')
382-
axins.imshow(r, cmap='gray', origin="upper")
383-
384-
for point in XYs:# ['paw_l','paw_r']:
385-
if point in ['tube_bottom', 'tube_top']:
386-
continue
387-
# downsample; normalise number of points to be the same
388-
# across all sessions
389-
xs = XYs[point][0][0::ds[video_type]]
390-
ys = XYs[point][1][0::ds[video_type]]
391-
392-
axins.scatter(xs,ys, alpha = 0.05, s = 0.01,
393-
label = point, color = Cs[point])
394-
axins.set_xlim(x0, x1)
395-
axins.set_ylim(y1, y0)
396-
axins.set_xticklabels('')
397-
axins.set_yticklabels('')
398-
#ax.indicate_inset_zoom(axins, edgecolor="white")
319+
if video_type == 'left':
320+
fa = 1
321+
elif video_type == 'right':
322+
fa = 0.5
323+
324+
# plot whisker pad rectangle
325+
mloc = get_mean_positions(XYs)
326+
p_nose = np.array(mloc['nose_tip'])
327+
p_pupil = np.array(mloc['pupil_top_r'])
328+
329+
# heuristic to find whisker area in side videos:
330+
# square with side length half the distance
331+
# between nose and pupil and anchored on midpoint
332+
333+
p_anchor = np.mean([p_nose,p_pupil],axis=0)
334+
squared_dist = np.sum((p_nose-p_pupil)**2, axis=0)
335+
dist = np.sqrt(squared_dist)
336+
whxy = [int(dist/2), int(dist/3),
337+
int(p_anchor[0] - dist/4), int(p_anchor[1])]
338+
339+
rect = patches.Rectangle((whxy[2], whxy[3]), whxy[0], whxy[1],
340+
linewidth=1,
341+
edgecolor='lime',
342+
facecolor='none')
343+
ax = plt.gca()
344+
ax.add_patch(rect)
345+
346+
347+
348+
# plot eye region zoom as inset in upper right corner
349+
pivot = np.nanmean(XYs['pupil_top_r'], axis=1)
350+
x0 = int(pivot[0] - 33 * fa)
351+
x1 = int(pivot[0] + 33 * fa)
352+
y0 = int(pivot[1] - 28 * fa)
353+
y1 = int(pivot[1] + 38 * fa)
354+
355+
if video_type == 'right':
356+
axins = ax.inset_axes([0, -0.5, 0.5, 0.5])
357+
elif video_type == 'left':
358+
axins = ax.inset_axes([0.5, -0.5, 0.5, 0.5])
359+
360+
axins.spines['bottom'].set_color('white')
361+
axins.spines['top'].set_color('white')
362+
axins.spines['right'].set_color('white')
363+
axins.spines['left'].set_color('white')
364+
axins.imshow(r, cmap='gray', origin="lower")
365+
366+
for point in XYs:# ['paw_l','paw_r']:
367+
if point in ['tube_bottom', 'tube_top']:
368+
continue
369+
370+
# downsample; normalise number of points to be the same
371+
# across all sessions
372+
xs = XYs[point][0][0::ds[video_type]]
373+
ys = XYs[point][1][0::ds[video_type]]
374+
375+
axins.scatter(xs,ys, alpha = 1, s = 0.001,
376+
label = point, color = Cs[point])
377+
axins.set_xlim(x0, x1)
378+
axins.set_ylim(y1, y0)
379+
axins.set_xticklabels('')
380+
axins.set_yticklabels('')
381+
#ax.indicate_inset_zoom(axins, edgecolor="white")
382+
383+
# plot tongue region zoom as inset in llower right corner
384+
p1 = np.nanmean(XYs['tube_top'], axis=1)
385+
p2 = np.nanmean(XYs['tube_bottom'], axis=1)
386+
pivot = np.nanmean([p1,p2], axis=0)
387+
x0 = int(pivot[0] - 60 * fa)
388+
x1 = int(pivot[0] + 100 * fa)
389+
y0 = int(pivot[1] - 100 * fa)
390+
y1 = int(pivot[1] + 60 * fa)
391+
392+
if video_type == 'right':
393+
axins = ax.inset_axes([0.5, -0.5, 0.5, 0.5])
394+
elif video_type == 'left':
395+
axins = ax.inset_axes([0, -0.5, 0.5, 0.5])
396+
397+
axins.spines['bottom'].set_color('white')
398+
axins.spines['top'].set_color('white')
399+
axins.spines['right'].set_color('white')
400+
axins.spines['left'].set_color('white')
401+
axins.imshow(r, cmap='gray', origin="upper")
402+
403+
for point in XYs:# ['paw_l','paw_r']:
404+
if point in ['tube_bottom', 'tube_top']:
405+
continue
406+
# downsample; normalise number of points to be the same
407+
# across all sessions
408+
xs = XYs[point][0][0::ds[video_type]]
409+
ys = XYs[point][1][0::ds[video_type]]
410+
411+
axins.scatter(xs,ys, alpha = 1, s = 0.001,
412+
label = point, color = Cs[point])
413+
axins.set_xlim(x0, x1)
414+
axins.set_ylim(y1, y0)
415+
axins.set_xticklabels('')
416+
axins.set_yticklabels('')
417+
#ax.indicate_inset_zoom(axins, edgecolor="white")
399418

400419
except:
401420

@@ -406,7 +425,17 @@ def plot_paw_on_image(eid, video_type='left', XYs = None):
406425
fontsize=10,transform=ax.transAxes)
407426
plt.tight_layout()
408427
#plt.show()
409-
#plt.legend(loc='lower right')
428+
plt.title(video_type)
429+
430+
431+
def plot_paw_on_imageL(eid):
432+
plot_paw_on_image(eid, video_type='left')
433+
434+
def plot_paw_on_imageR(eid):
435+
plot_paw_on_image(eid, video_type='right')
436+
437+
def plot_paw_on_imageB(eid):
438+
plot_paw_on_image(eid, video_type='body')
410439

411440

412441
def paw_speed_PSTH(eid):
@@ -1205,7 +1234,9 @@ def plot_all(eid):
12051234
matplotlib.rcParams.update({'font.size': 10})
12061235
# report eid = '4a45c8ba-db6f-4f11-9403-56e06a33dfa4'
12071236

1208-
panels = {'plot_paw_on_image':plot_paw_on_image,
1237+
panels = {'plot_paw_on_imageL':plot_paw_on_imageL,
1238+
'plot_paw_on_imageR':plot_paw_on_imageR,
1239+
'plot_paw_on_imageB':plot_paw_on_imageB,
12091240
'plot_wheel_position':plot_wheel_position,
12101241
'paw_speed_PSTH':paw_speed_PSTH,
12111242
'plot_licks':plot_licks,
@@ -1215,11 +1246,11 @@ def plot_all(eid):
12151246
'motion_energy_PSTH':motion_energy_PSTH}
12161247

12171248
nrows = 2
1218-
ncols = 4
1249+
ncols = int(np.ceil(len(panels)/2))
12191250

12201251
plt.ioff()
12211252

1222-
plt.figure(figsize=(15,10))
1253+
plt.figure(figsize=(17,10))
12231254

12241255
k = 1
12251256
for panel in panels:
@@ -1244,7 +1275,7 @@ def plot_all(eid):
12441275
task = one.alyx.rest('tasks', 'list', session=eid, name='EphysDLC')[0]
12451276
det = one.get_details(eid, True)['extended_qc']
12461277
p = one.path_from_eid(eid)
1247-
s1 = ' '.join([str(p).split('/')[i] for i in [4,6,7,8]])
1278+
s1 = '_'.join([str(p).split('/')[i] for i in [4,6,7,8]])
12481279

12491280
dlc_qcs = [ 'time_trace_length_match',
12501281
'trace_all_nan',
@@ -1276,12 +1307,16 @@ def plot_all(eid):
12761307

12771308
s2 = ' '.join(l)
12781309

1310+
ntrials = len(one.load_object(eid, 'trials')['goCue_times'])
1311+
12791312

1280-
plt.suptitle(s1+', DLC version: '+str(task['version'])+' \n '+s2,
1313+
plt.suptitle(s1+'#Trials:'+str(ntrials)+', DLC version: '
1314+
+str(task['version'])+' \n '+s2,
12811315
backgroundcolor= 'white', fontsize=6)
12821316
plt.tight_layout(rect=[0, 0.03, 1, 0.95])
12831317
#plt.savefig(f'/home/mic/reproducible_dlc/overviewJune/{eid}.png')
1284-
plt.savefig(f'/home/mic/reproducible_dlc/all_DLC/{eid}.png')
1318+
#plt.savefig(f'/home/mic/reproducible_dlc/all_DLC/{s1}_{eid}.png')
1319+
plt.savefig(f'/home/mic/reproducible_dlc/repro/{s1}_{eid}.png')
12851320
plt.close()
12861321

12871322

@@ -1307,16 +1342,5 @@ def inspection():
13071342
input("Press Enter to continue...")
13081343
plt.close()
13091344

1310-
1311-
def get_all_sess_with_ME():
1312-
one = ONE()
1313-
# get all bwm sessions with dlc
1314-
all_sess = one.alyx.rest('sessions', 'list',
1315-
project='ibl_neuropixel_brainwide_01',
1316-
task_protocol="ephys",
1317-
dataset_types='camera.ROIMotionEnergy')
1318-
1319-
eids = [s['url'].split('/')[-1] for s in all_sess]
1320-
1321-
return eids
1345+
13221346

0 commit comments

Comments
 (0)