Skip to content

Commit

Permalink
Merge branch 'develop' into multiEnv
Browse files Browse the repository at this point in the history
  • Loading branch information
k1o0 committed Jun 19, 2024
2 parents 5bbe29a + 2d27e48 commit 5686fcd
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 23 deletions.
43 changes: 33 additions & 10 deletions ibllib/io/extractors/ephys_passive.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,39 @@ def _load_passive_session_fixtures(session_path: str, task_collection: str = 'ra
return fixture


def _load_task_protocol(session_path: str, task_collection: str = 'raw_passive_data') -> str:
def _load_task_version(session_path: str, task_collection: str = 'raw_passive_data') -> str:
"""Find the IBL rig version used for the session
:param session_path: the path to a session
:type session_path: str
:return: ibl rig task protocol version
:rtype: str
FIXME This function has a misleading name
"""
settings = rawio.load_settings(session_path, task_collection=task_collection)
ses_ver = settings["IBLRIG_VERSION"]

return ses_ver


def skip_task_replay(session_path: str, task_collection: str = 'raw_passive_data') -> bool:
"""Find whether the task replay portion of the passive stimulus has been shown
:param session_path: the path to a session
:type session_path: str
:param task_collection: collection containing task data
:type task_collection: str
:return: whether or not the task replay has been run
:rtype: bool
"""

settings = rawio.load_settings(session_path, task_collection=task_collection)
# Attempt to see if SKIP_EVENT_REPLAY is available, if not assume we do have task replay
skip_replay = settings.get('SKIP_EVENT_REPLAY', False)

return skip_replay


def _load_passive_stim_meta() -> dict:
"""load_passive_stim_meta Loads the passive protocol metadata
Expand Down Expand Up @@ -536,7 +553,7 @@ def extract_task_replay(
bpod = ephys_fpga.get_sync_fronts(sync, sync_map["bpod"], tmin=treplay[0], tmax=treplay[1])
passiveValve_intervals = _extract_passiveValve_intervals(bpod)

task_version = _load_task_protocol(session_path, task_collection)
task_version = _load_task_version(session_path, task_collection)
audio = ephys_fpga.get_sync_fronts(sync, sync_map["audio"], tmin=treplay[0], tmax=treplay[1])
passiveTone_intervals, passiveNoise_intervals = _extract_passiveAudio_intervals(audio, task_version)

Expand Down Expand Up @@ -588,7 +605,7 @@ def extract_replay_debug(
passiveValve_intervals = _extract_passiveValve_intervals(bpod)
plot_valve_times(passiveValve_intervals, ax=ax)

task_version = _load_task_protocol(session_path, task_collection)
task_version = _load_task_version(session_path, task_collection)
audio = ephys_fpga.get_sync_fronts(sync, sync_map["audio"], tmin=treplay[0])
passiveTone_intervals, passiveNoise_intervals = _extract_passiveAudio_intervals(audio, task_version)
plot_audio_times(passiveTone_intervals, passiveNoise_intervals, ax=ax)
Expand Down Expand Up @@ -647,13 +664,19 @@ def _extract(self, sync_collection: str = 'raw_ephys_data', task_collection: str
log.error(f"Failed to extract RFMapping datasets: {e}")
passiveRFM_times = None

try:
(passiveGabor_df, passiveStims_df,) = extract_task_replay(
self.session_path, sync_collection=sync_collection, task_collection=task_collection, sync=sync,
sync_map=sync_map, treplay=treplay)
except Exception as e:
log.error(f"Failed to extract task replay stimuli: {e}")
skip_replay = skip_task_replay(self.session_path, task_collection)
if not skip_replay:
try:
(passiveGabor_df, passiveStims_df,) = extract_task_replay(
self.session_path, sync_collection=sync_collection, task_collection=task_collection, sync=sync,
sync_map=sync_map, treplay=treplay)
except Exception as e:
log.error(f"Failed to extract task replay stimuli: {e}")
passiveGabor_df, passiveStims_df = (None, None)
else:
# If we don't have task replay then we set the treplay intervals to NaN in our passivePeriods_df dataset
passiveGabor_df, passiveStims_df = (None, None)
passivePeriods_df.taskReplay = np.NAN

if plot:
f, ax = plt.subplots(1, 1)
Expand Down
20 changes: 10 additions & 10 deletions ibllib/pipes/behavior_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ def signature(self):
signature = {
'input_files': [],
'output_files': [('_iblrig_taskSettings.raw.*', self.collection, True),
('_iblrig_encoderEvents.raw*', self.collection, True),
('_iblrig_encoderPositions.raw*', self.collection, True),
('_iblrig_encoderTrialInfo.raw*', self.collection, True),
('_iblrig_stimPositionScreen.raw*', self.collection, True),
('_iblrig_syncSquareUpdate.raw*', self.collection, True),
('_iblrig_encoderEvents.raw*', self.collection, False),
('_iblrig_encoderPositions.raw*', self.collection, False),
('_iblrig_encoderTrialInfo.raw*', self.collection, False),
('_iblrig_stimPositionScreen.raw*', self.collection, False),
('_iblrig_syncSquareUpdate.raw*', self.collection, False),
('_iblrig_RFMapStim.raw*', self.collection, True)]
}
return signature


class PassiveTask(base_tasks.BehaviourTask):
class PassiveTaskNidq(base_tasks.BehaviourTask):
priority = 90
job_size = 'small'

Expand All @@ -208,10 +208,10 @@ def signature(self):
(f'_{self.sync_namespace}_sync.times.*', self.sync_collection, True),
('*.wiring.json', self.sync_collection, False),
('*.meta', self.sync_collection, False)],
'output_files': [('_ibl_passiveGabor.table.csv', self.output_collection, True),
'output_files': [('_ibl_passiveGabor.table.csv', self.output_collection, False),
('_ibl_passivePeriods.intervalsTable.csv', self.output_collection, True),
('_ibl_passiveRFM.times.npy', self.output_collection, True),
('_ibl_passiveStims.table.csv', self.output_collection, True)]
('_ibl_passiveStims.table.csv', self.output_collection, False)]
}
return signature

Expand Down Expand Up @@ -240,10 +240,10 @@ def signature(self):
(f'_{self.sync_namespace}_sync.channels.*', self.sync_collection, False),
(f'_{self.sync_namespace}_sync.polarities.*', self.sync_collection, False),
(f'_{self.sync_namespace}_sync.times.*', self.sync_collection, False)],
'output_files': [('_ibl_passiveGabor.table.csv', self.output_collection, True),
'output_files': [('_ibl_passiveGabor.table.csv', self.output_collection, False),
('_ibl_passivePeriods.intervalsTable.csv', self.output_collection, True),
('_ibl_passiveRFM.times.npy', self.output_collection, True),
('_ibl_passiveStims.table.csv', self.output_collection, True)]
('_ibl_passiveStims.table.csv', self.output_collection, False)]
}
return signature

Expand Down
2 changes: 1 addition & 1 deletion ibllib/pipes/dynamic_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def make_pipeline(session_path, **pkwargs):
# - choice_world_habituation
if 'passiveChoiceWorld' in protocol:
registration_class = btasks.PassiveRegisterRaw
behaviour_class = btasks.PassiveTask
behaviour_class = getattr(btasks, 'PassiveTask' + sync_label.capitalize())
compute_status = False
elif 'habituation' in protocol:
registration_class = btasks.HabituationRegisterRaw
Expand Down
4 changes: 2 additions & 2 deletions ibllib/tests/qc/test_task_qc_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ibllib.pipes.ephys_preprocessing import EphysTrials
from ibllib.pipes.training_preprocessing import TrainingTrials
from ibllib.pipes.behavior_tasks import HabituationTrialsBpod, ChoiceWorldTrialsNidq, ChoiceWorldTrialsBpod, PassiveTask
from ibllib.pipes.behavior_tasks import HabituationTrialsBpod, ChoiceWorldTrialsNidq, ChoiceWorldTrialsBpod, PassiveTaskNidq
from ibllib.qc.task_qc_viewer.task_qc import get_bpod_trials_task, show_session_task_qc, QcFrame
from ibllib.qc.task_metrics import TaskQC
from ibllib.tests import TEST_DB
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_show_session_task_qc(self, trials_tasks_mock, run_app_mock):
self.assertRaises(TypeError, show_session_task_qc, session_path, one=self.one, protocol_number=-2)
self.assertRaises(ValueError, show_session_task_qc, session_path, one=self.one, protocol_number=1)

passive_task = PassiveTask('foo/bar', protocol='_iblrig_passiveChoiceWorld', protocol_number=0)
passive_task = PassiveTaskNidq('foo/bar', protocol='_iblrig_passiveChoiceWorld', protocol_number=0)
trials_tasks_mock.return_value = [passive_task]
self.assertRaises(ValueError, show_session_task_qc, session_path, one=self.one, protocol_number=0)
self.assertRaises(ValueError, show_session_task_qc, session_path, one=self.one)
Expand Down

0 comments on commit 5686fcd

Please sign in to comment.