Skip to content

Commit 982ce01

Browse files
committed
Merge branch 'release/2.10.3'
2 parents e4a4f88 + 3d253f8 commit 982ce01

File tree

5 files changed

+50
-38
lines changed

5 files changed

+50
-38
lines changed

brainbox/behavior/dlc.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,17 @@ def plot_motion_energy_hist(camera_dict, trials_df):
458458
motion_energy = zscore(camera_dict[cam]['motion_energy'], nan_policy='omit')
459459
try:
460460
start_idx = insert_idx(camera_dict[cam]['times'], start_window)
461+
end_idx = np.array(start_idx + int(WINDOW_LEN * SAMPLING[cam]), dtype='int64')
462+
me_all = [motion_energy[start_idx[i]:end_idx[i]] for i in range(len(start_idx))]
463+
me_all = [m for m in me_all if len(m) > 0]
464+
times = np.arange(len(me_all[0])) / SAMPLING[cam] + WINDOW_LAG
465+
me_mean = np.mean(me_all, axis=0)
466+
me_std = np.std(me_all, axis=0) / np.sqrt(len(me_all))
467+
plt.plot(times, me_mean, label=f'{cam} cam', color=colors[cam], linewidth=2)
468+
plt.fill_between(times, me_mean + me_std, me_mean - me_std, color=colors[cam], alpha=0.2)
461469
except ValueError:
462-
logger.error("Camera.times are outside of the trial windows")
463-
raise
464-
end_idx = np.array(start_idx + int(WINDOW_LEN * SAMPLING[cam]), dtype='int64')
465-
me_all = [motion_energy[start_idx[i]:end_idx[i]] for i in range(len(start_idx))]
466-
times = np.arange(len(me_all[0])) / SAMPLING[cam] + WINDOW_LAG
467-
me_mean = np.mean(me_all, axis=0)
468-
me_std = np.std(me_all, axis=0) / np.sqrt(len(me_all))
469-
plt.plot(times, me_mean, label=f'{cam} cam', color=colors[cam], linewidth=2)
470-
plt.fill_between(times, me_mean + me_std, me_mean - me_std, color=colors[cam], alpha=0.2)
470+
logger.error(f"{cam}Camera camera.times are outside of the trial windows")
471+
missing_data.append(cam)
471472
except AttributeError:
472473
logger.warning(f"Cannot load motion energy and/or times data for {cam} camera")
473474
missing_data.append(cam)
@@ -484,7 +485,7 @@ def plot_motion_energy_hist(camera_dict, trials_df):
484485
if len(missing_data) > 0:
485486
ax = plt.gca()
486487
ax.text(.95, .35, f"Data incomplete for\n{' and '.join(missing_data)} camera", color='r', fontsize=10,
487-
horizontalalignment='right', verticalalignment='center', transform=ax.transAxes)
488+
fontweight='bold', horizontalalignment='right', verticalalignment='center', transform=ax.transAxes)
488489
return plt.gca()
489490

490491

ibllib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.10.2"
1+
__version__ = "2.10.3"
22
import warnings
33

44
from ibllib.misc import logger_config

ibllib/dsp/voltage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def decompress_destripe_cbin(sr_file, output_file=None, h=None, wrot=None, appen
335335
butter_kwargs, k_kwargs, spatial_fcn = _get_destripe_parameters(sr.fs, butter_kwargs, k_kwargs, k_filter)
336336
h = sr.geometry if h is None else h
337337
ncv = h['sample_shift'].size # number of channels
338-
output_file = sr.file_bin.with_suffix('.bin') if output_file is None else output_file
338+
output_file = sr.file_bin.with_suffix('.bin') if output_file is None else Path(output_file)
339339
assert output_file != sr.file_bin
340340
taper = np.r_[0, scipy.signal.windows.cosine((SAMPLES_TAPER - 1) * 2), 0]
341341
# create the FFT stencils
@@ -481,8 +481,8 @@ def my_function(i_chunk, n_chunk):
481481
rms_data = np.frombuffer(rms_data, dtype=np.float32)
482482
assert(rms_data.shape[0] == time_data.shape[0] * ncv)
483483
rms_data = rms_data.reshape(time_data.shape[0], ncv)
484-
np.save(Path(sr_file).parent.joinpath('_iblqc_ephysTimeRmsAP.rms.npy'), rms_data)
485-
np.save(Path(sr_file).parent.joinpath('_iblqc_ephysTimeRmsAP.timestamps.npy'), time_data)
484+
np.save(output_file.parent.joinpath('_iblqc_ephysTimeRmsAP.rms.npy'), rms_data)
485+
np.save(output_file.parent.joinpath('_iblqc_ephysTimeRmsAP.timestamps.npy'), time_data)
486486

487487

488488
def rcoeff(x, y):

ibllib/pipes/ephys_preprocessing.py

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,27 +1068,28 @@ class EphysPostDLC(tasks.Task):
10681068
# the following are required for the DLC plot only
10691069
# they are not strictly required, some plots just might be skipped
10701070
# 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),
1071+
('_iblrig_bodyCamera.raw.mp4', 'raw_video_data', True),
1072+
('_iblrig_leftCamera.raw.mp4', 'raw_video_data', True),
1073+
('_iblrig_rightCamera.raw.mp4', 'raw_video_data', True),
1074+
('rightROIMotionEnergy.position.npy', 'alf', True),
1075+
('leftROIMotionEnergy.position.npy', 'alf', True),
1076+
('bodyROIMotionEnergy.position.npy', 'alf', True),
1077+
('_ibl_trials.choice.npy', 'alf', True),
1078+
('_ibl_trials.feedbackType.npy', 'alf', True),
1079+
('_ibl_trials.feedback_times.npy', 'alf', True),
1080+
('_ibl_trials.stimOn_times.npy', 'alf', True),
1081+
('_ibl_wheel.position.npy', 'alf', True),
1082+
('_ibl_wheel.timestamps.npy', 'alf', True),
10831083
],
10841084
# More files are required for all panels of the DLC QC plot to function
10851085
'output_files': [('_ibl_leftCamera.features.pqt', 'alf', True),
10861086
('_ibl_rightCamera.features.pqt', 'alf', True),
10871087
('licks.times.npy', 'alf', True),
1088-
('dlc_qc_plot.png', 'snapshot', False)]
1088+
# ('dlc_qc_plot.png', 'snapshot', False)
1089+
]
10891090
}
10901091

1091-
def _run(self, overwrite=False, run_qc=True, plot_qc=True):
1092+
def _run(self, overwrite=True, run_qc=True, plot_qc=True):
10921093
"""
10931094
Run the EphysPostDLC task. Returns a list of file locations for the output files in signature. The created plot
10941095
(dlc_qc_plot.png) is not returned, but saved in session_path/snapshots and uploaded to Alyx as a note.
@@ -1121,18 +1122,24 @@ def _run(self, overwrite=False, run_qc=True, plot_qc=True):
11211122
dlc = pd.read_parquet(dlc_file)
11221123
dlc_thresh = likelihood_threshold(dlc, 0.9)
11231124
# try to load respective camera times
1124-
dlc_t = np.load(next(Path(self.session_path).joinpath('alf').glob(f'_ibl_{cam}Camera.times.*npy')))
1125-
times = True
1126-
if dlc_t.shape[0] == 0:
1127-
_logger.error(f'camera.times empty for {cam} camera. '
1128-
f'Computations using camera.times will be skipped')
1125+
try:
1126+
dlc_t = np.load(next(Path(self.session_path).joinpath('alf').glob(f'_ibl_{cam}Camera.times.*npy')))
1127+
times = True
1128+
if dlc_t.shape[0] == 0:
1129+
_logger.error(f'camera.times empty for {cam} camera. '
1130+
f'Computations using camera.times will be skipped')
1131+
self.status = -1
1132+
times = False
1133+
elif dlc_t.shape[0] < len(dlc_thresh):
1134+
_logger.error(f'Camera times shorter than DLC traces for {cam} camera. '
1135+
f'Computations using camera.times will be skipped')
1136+
self.status = -1
1137+
times = 'short'
1138+
except StopIteration:
11291139
self.status = -1
11301140
times = False
1131-
elif dlc_t.shape[0] < len(dlc_thresh):
1132-
_logger.error(f'Camera times shorter than DLC traces for {cam} camera. '
1141+
_logger.error(f'No camera.times for {cam} camera. '
11331142
f'Computations using camera.times will be skipped')
1134-
self.status = -1
1135-
times = 'short'
11361143
# These features are only computed from left and right cam
11371144
if cam in ('left', 'right'):
11381145
features = pd.DataFrame()
@@ -1161,7 +1168,7 @@ def _run(self, overwrite=False, run_qc=True, plot_qc=True):
11611168
output_files.append(features_file)
11621169

11631170
# For all cams, compute DLC qc if times available
1164-
if times is True or times == 'short' and run_qc:
1171+
if run_qc is True and times in [True, 'short']:
11651172
# Setting download_data to False because at this point the data should be there
11661173
qc = DlcQC(self.session_path, side=cam, one=self.one, download_data=False)
11671174
qc.run(update=True)

release_notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Release Note 2.10
22

3+
## Release Note 2.10.3 2022-03-09
4+
- Fixes to EphysPostDLC
5+
- Small change to storing in dsp.voltage.decompress_destripe_cbin function
6+
37
## Release Note 2.10.2 2022-02-28
48
- Small fixes to local server task queues
59

0 commit comments

Comments
 (0)