Skip to content

Commit ec77d7e

Browse files
committed
Merge branch 'postdlc_local' into develop
2 parents 2a0d0c7 + b28485e commit ec77d7e

File tree

6 files changed

+174
-95
lines changed

6 files changed

+174
-95
lines changed

brainbox/behavior/dlc.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,12 @@ def plot_wheel_position(wheel_position, wheel_time, trials_df):
350350

351351
plt.axvline(x=0, linestyle='--', c='k', label='stimOn')
352352
plt.axhline(y=-0.26, linestyle='--', c='g', label='reward')
353+
plt.axhline(y=0.26, linestyle='--', c='g', label='reward')
353354
plt.ylim([-0.27, 0.27])
354355
plt.xlabel('time [sec]')
355-
plt.ylabel('wheel position [rad]')
356+
plt.ylabel('wheel position diff to first value [rad]')
356357
plt.legend(loc='center right')
357-
plt.title('Wheel position')
358+
plt.title('Wheel position trial avg\n(and individual trials)')
358359
plt.tight_layout()
359360

360361
return plt.gca()
@@ -406,7 +407,7 @@ def plot_lick_hist(lick_times, trials_df):
406407
plt.plot(times, pd.DataFrame.from_dict(dict(zip(correct.index, incorrect.values))).mean(axis=1),
407408
c='gray', label='incorrect trial')
408409
plt.axvline(x=0, label='feedback', linestyle='--', c='purple')
409-
plt.title('Lick events')
410+
plt.title('Lick events trial avg')
410411
plt.xlabel('time [sec]')
411412
plt.ylabel('lick events [a.u.]')
412413
plt.legend(loc='lower right')
@@ -479,7 +480,7 @@ def plot_motion_energy_hist(camera_dict, trials_df):
479480
plt.xlabel('time [sec]')
480481
plt.axvline(x=0, label='stimOn', linestyle='--', c='k')
481482
plt.legend(loc='lower right')
482-
plt.title('Motion Energy')
483+
plt.title('Motion Energy trial avg\n(+/- std)')
483484
if len(missing_data) > 0:
484485
ax = plt.gca()
485486
ax.text(.95, .35, f"Data incomplete for\n{' and '.join(missing_data)} camera", color='r', fontsize=10,
@@ -523,7 +524,7 @@ def plot_speed_hist(dlc_df, cam_times, trials_df, feature='paw_r', cam='left', l
523524
plt.plot(times, pd.DataFrame.from_dict(dict(zip(incorrect.index, incorrect.values))).mean(axis=1),
524525
c='gray', label='incorrect trial')
525526
plt.axvline(x=0, label='stimOn', linestyle='--', c='r')
526-
plt.title(f'{feature.split("_")[0].capitalize()} speed ({cam} cam)')
527+
plt.title(f'{feature.capitalize()} speed trial avg\n({cam.upper()} cam)')
527528
plt.xticks([-0.5, 0, 0.5, 1, 1.5])
528529
plt.xlabel('time [sec]')
529530
plt.ylabel('speed [px/sec]')
@@ -559,8 +560,8 @@ def plot_pupil_diameter_hist(pupil_diameter, cam_times, trials_df, cam='left'):
559560
plt.plot(times, pupil_mean, label=align_to.split("_")[0], color=color)
560561
plt.fill_between(times, pupil_mean + pupil_std, pupil_mean - pupil_std, color=color, alpha=0.5)
561562
plt.axvline(x=0, linestyle='--', c='k')
562-
plt.title(f'Pupil diameter ({cam} cam)')
563+
plt.title(f'Pupil diameter trial avg\n({cam.upper()} cam)')
563564
plt.xlabel('time [sec]')
564565
plt.xticks([-0.5, 0, 0.5, 1, 1.5])
565-
plt.ylabel('pupil diameter [px]')
566+
plt.ylabel('z-scored smoothed pupil diameter [px]')
566567
plt.legend(loc='lower right', title='aligned to')

ibllib/pipes/ephys_preprocessing.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,6 @@ def _run(self, cams=None, overwrite=False):
10551055
class EphysPostDLC(tasks.Task):
10561056
"""
10571057
The post_dlc task takes dlc traces as input and computes useful quantities, as well as qc.
1058-
1059-
For creating the full dlc_qc_plot, several other inputs are required that can be found in the docstring of
1060-
:py:func:ibllib.plots.figures.dlc_qc_plot
10611058
"""
10621059
io_charge = 90
10631060
level = 3
@@ -1067,11 +1064,28 @@ class EphysPostDLC(tasks.Task):
10671064
('_ibl_rightCamera.dlc.pqt', 'alf', True),
10681065
('_ibl_rightCamera.times.npy', 'alf', True),
10691066
('_ibl_leftCamera.times.npy', 'alf', True),
1070-
('_ibl_bodyCamera.times.npy', 'alf', True)],
1067+
('_ibl_bodyCamera.times.npy', 'alf', True),
1068+
# the following are required for the DLC plot only
1069+
# they are not strictly required, some plots just might be skipped
1070+
# In particular the raw videos don't need to be downloaded as they can be streamed
1071+
('_iblrig_bodyCamera.raw.mp4', 'raw_video_data', False),
1072+
('_iblrig_leftCamera.raw.mp4', 'raw_video_data', False),
1073+
('_iblrig_rightCamera.raw.mp4', 'raw_video_data', False),
1074+
('rightROIMotionEnergy.position.npy', 'alf', False),
1075+
('leftROIMotionEnergy.position.npy', 'alf', False),
1076+
('bodyROIMotionEnergy.position.npy', 'alf', False),
1077+
('_ibl_trials.choice.npy', 'alf', False),
1078+
('_ibl_trials.feedbackType.npy', 'alf', False),
1079+
('_ibl_trials.feedback_times.npy', 'alf', False),
1080+
('_ibl_trials.stimOn_times.npy', 'alf', False),
1081+
('_ibl_wheel.position.npy', 'alf', False),
1082+
('_ibl_wheel.timestamps.npy', 'alf', False),
1083+
],
10711084
# More files are required for all panels of the DLC QC plot to function
10721085
'output_files': [('_ibl_leftCamera.features.pqt', 'alf', True),
10731086
('_ibl_rightCamera.features.pqt', 'alf', True),
1074-
('licks.times.npy', 'alf', True)]
1087+
('licks.times.npy', 'alf', True),
1088+
('dlc_qc_plot.png', 'snapshot', False)]
10751089
}
10761090

10771091
def _run(self, overwrite=False, run_qc=True, plot_qc=True):
@@ -1080,7 +1094,7 @@ def _run(self, overwrite=False, run_qc=True, plot_qc=True):
10801094
(dlc_qc_plot.png) is not returned, but saved in session_path/snapshots and uploaded to Alyx as a note.
10811095
10821096
:param overwrite: bool, whether to recompute existing output files (default is False).
1083-
Note that the dlc_qc_plot will be computed even if overwrite = False
1097+
Note that the dlc_qc_plot will be (re-)computed even if overwrite = False
10841098
:param run_qc: bool, whether to run the DLC QC (default is True)
10851099
:param plot_qc: book, whether to create the dlc_qc_plot (default is True)
10861100
@@ -1092,7 +1106,7 @@ def _run(self, overwrite=False, run_qc=True, plot_qc=True):
10921106
else:
10931107
if exist and overwrite:
10941108
_logger.warning('EphysPostDLC outputs exist and overwrite=True, overwriting existing outputs.')
1095-
# Find all available dlc traces and dlc times
1109+
# Find all available dlc files
10961110
dlc_files = list(Path(self.session_path).joinpath('alf').glob('_ibl_*Camera.dlc.*'))
10971111
for dlc_file in dlc_files:
10981112
_logger.debug(dlc_file)
@@ -1177,7 +1191,7 @@ def _run(self, overwrite=False, run_qc=True, plot_qc=True):
11771191
fig_path = self.session_path.joinpath('snapshot', 'dlc_qc_plot.png')
11781192
if not fig_path.parent.exists():
11791193
fig_path.parent.mkdir(parents=True, exist_ok=True)
1180-
fig = dlc_qc_plot(self.one.path2eid(self.session_path), one=self.one)
1194+
fig = dlc_qc_plot(self.session_path, one=self.one)
11811195
fig.savefig(fig_path)
11821196
fig.clf()
11831197
snp = ReportSnapshot(self.session_path, session_id, one=self.one)

ibllib/pipes/tasks.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def run(self, **kwargs):
8181
# if taskid of one properties are not available, local run only without alyx
8282
use_alyx = self.one is not None and self.taskid is not None
8383
if use_alyx:
84+
# check that alyx user is logged in
85+
if not self.one.alyx.is_logged_in:
86+
self.one.alyx.authenticate()
8487
tdict = self.one.alyx.rest('tasks', 'partial_update', id=self.taskid,
8588
data={'status': 'Started'})
8689
self.log = ('' if not tdict['log'] else tdict['log'] +

0 commit comments

Comments
 (0)