Skip to content

Commit

Permalink
Merge pull request #7 from int-brain-lab/neuromodulatorsExtraction
Browse files Browse the repository at this point in the history
Several fixes
  • Loading branch information
k1o0 authored Mar 12, 2024
2 parents 2f3d927 + 6663843 commit 465d3b5
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 51 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ pip install -e .
- `projects/task_extractor_map.json` - Map custom task protocols to Bpod trials extractor class
- `projects/task_type_procedures.json` - Associate Alyx procedures to a custom task protocol
- `projects/_template.py` - Example for creating a custom Bpod extractor, QC or DAQ sync task
- `projects/_extraction_tasks.py` - Where to import pipeline tasks so they are readable by ibllib
- `projects/extraction_tasks.py` - Where to import pipeline tasks so they are readable by ibllib
21 changes: 0 additions & 21 deletions examples/neuromodulators.py

This file was deleted.

8 changes: 6 additions & 2 deletions iblrig_custom_tasks/_sp_passiveVideo/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
from collections import defaultdict
import logging
import warnings

import pandas as pd
from pybpodapi.protocol import Bpod
Expand All @@ -19,8 +20,11 @@
# this allows the CI and automated tests to import the file and make sure it is valid without having vlc
try:
import vlc
except (ModuleNotFoundError, FileNotFoundError):
_logger.error(f'VLC not installed. Please install VLC to use this task. {__file__}')
except ModuleNotFoundError:
warnings.warn(
'Please install extra dependencies for _sp_passiveVideo: '
'pip install "project_extraction[passiveVideo] @ '
'git+https://github.com/int-brain-lab/project_extraction.git"', RuntimeWarning)


class Player:
Expand Down
9 changes: 3 additions & 6 deletions iblrig_custom_tasks/samuel_cuedBiasedChoiceWorld/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pybpodapi.protocol import StateMachine

import iblrig.misc
from iblrig.path_helper import load_pydantic_yaml, HardwareSettings
from iblrig.base_choice_world import BiasedChoiceWorldSession
from iblrig.hardware import SOFTCODE
from iblutil.util import setup_logger
Expand All @@ -19,15 +18,13 @@ class Session(BiasedChoiceWorldSession):
protocol_name = 'samuel_cuedBiasedChoiceWorld'

def __init__(self, *args, delay_secs=0, **kwargs): #SP _init_ should be the same as biasedChoiceWorld, so should it be specified?
super().__init__(**kwargs)

# loads in the settings in order to determine the main sync and thus the pipeline extractor tasks
hardware_settings = load_pydantic_yaml(HardwareSettings, kwargs.get('file_hardware_settings'))
hardware_settings.update(kwargs.get('hardware_settings', {}))
is_main_sync = hardware_settings.get('MAIN_SYNC', False)
is_main_sync = self.hardware_settings.get('MAIN_SYNC', False)
trials_task = 'CuedBiasedTrials' if is_main_sync else 'CuedBiasedTrialsTimeline'
self.extractor_tasks = ['TrialRegisterRaw', trials_task, 'TrainingStatus']

super().__init__(**kwargs)

self.task_params["SESSION_DELAY_START"] = delay_secs
# init behaviour data
self.movement_left = self.device_rotary_encoder.THRESHOLD_EVENTS[
Expand Down
5 changes: 5 additions & 0 deletions projects/_template.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""Template boilerplate code for custom task protocol data extraction.
For an example of how to modify Bpod trials extraction (with either Bpod only or unchanged DAQ time alignment) check out
'projects.neuromodulators'. For an example of custom task QC, see 'projects.samuel_cuedBiasedChoiceWorld'.
"""
from collections import OrderedDict

from ibllib.pipes.tasks import Pipeline
Expand Down
3 changes: 1 addition & 2 deletions projects/extraction_tasks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
"""
Custom behaviour extractor tasks for personal projects.
The task class name(s) should be added to the
The task class name(s) should be added to the imports
NB: This may need changing in the future if one of these modules requires optional dependencies.
"""
from projects.neuromodulators import ChoiceWorldNeuromodulators
from projects.samuel_cuedBiasedChoiceWorld import CuedBiasedTrials, CuedBiasedTrialsTimeline
from projects.nate_optoBiasedChoiceWorld import OptoTrialsNidq, OptoTrialsBpod
27 changes: 14 additions & 13 deletions projects/neuromodulators.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import numpy as np
from ibllib.io.extractors.biased_trials import BiasedTrials
from ibllib.pipes.behavior_tasks import ChoiceWorldTrialsBpod
from ibllib.io.extractors.base import BaseBpodTrialsExtractor, run_extractor_classes


class ChoiceWorldNeuromodulators(ChoiceWorldTrialsBpod):
def _run(self, update=True):
"""
Extracts an iblrig training session
"""
save_path = self.session_path.joinpath(self.output_collection)
extractor = TrialsTableNeuromodulator(session_path=self.session_path, task_collection=self.task_collection, save_path=save_path)
out, fil = extractor.extract()
return fil
class TrialsTableNeuromodulator(BaseBpodTrialsExtractor):
"""Extract neuromodulator task events.
Include a couple custom trial variables in `var_names` property.
class TrialsTableNeuromodulator(BiasedTrials):
NB: In order to save to file and register these variables, we would need a custom ibllib.pipes.tasks.Task with
the correct output file names.
"""
save_names = BiasedTrials.save_names + (None, None)
var_names = BiasedTrials.var_names + ('omit_feedback', 'exit_state')

def _extract(self, *args, **kwargs):
out = super(TrialsTableNeuromodulator, self)._extract(*args, **kwargs)
# Extract common biased choice world datasets
out, _ = run_extractor_classes(
[BiasedTrials], session_path=self.session_path, bpod_trials=self.bpod_trials,
settings=self.settings, save=False, task_collection=self.task_collection)
out[0]['omit_feedback'] = np.array([t['omit_feedback'] for t in self.bpod_trials])
out[0]['exit_state'] = np.array([t['behavior_data']['States timestamps']['exit_state'][0][0] for t in self.bpod_trials])
return out
return {k: out[k] for k in self.var_names} # Ensures all datasets present and ordered
8 changes: 4 additions & 4 deletions projects/samuel_cuedBiasedChoiceWorld.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def check_stimOn_goCue_delays(self, data, audio_output='harp', **_):
class CuedBiasedTrialsTimeline(ChoiceWorldTrialsTimeline):
"""Behaviour task for aligning cuedBiased task to Timeline."""

def _run_qc(self, trials_data=None, update=True, QC=TaskQC, **kwargs):
def run_qc(self, trials_data=None, update=True, QC=TaskQC, **kwargs):
"""
Run task QC.
Expand All @@ -82,13 +82,13 @@ def _run_qc(self, trials_data=None, update=True, QC=TaskQC, **kwargs):
ibllib.qc.base.QC
The QC object.
"""
return super()._run_qc(trials_data=trials_data, update=update, QC=QC)
return super().run_qc(trials_data=trials_data, update=update, QC=QC)


class CuedBiasedTrials(ChoiceWorldTrialsBpod):
"""Behaviour task for extracting Bpod-only cuedBiased task."""

def _run_qc(self, trials_data=None, update=True, QC=TaskQC, **kwargs):
def run_qc(self, trials_data=None, update=True, QC=TaskQC, **kwargs):
"""
Run task QC.
Expand All @@ -106,4 +106,4 @@ def _run_qc(self, trials_data=None, update=True, QC=TaskQC, **kwargs):
ibllib.qc.base.QC
The QC object.
"""
return super()._run_qc(trials_data=trials_data, update=update, QC=QC)
return super().run_qc(trials_data=trials_data, update=update, QC=QC)
1 change: 1 addition & 0 deletions projects/task_extractor_map.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"samuel_cuedBiasedChoiceWorld": "BiasedTrials",
"_iblrig_tasks_neuromodulatorChoiceWorld": "projects.neuromodulators.TrialsTableNeuromodulator",
"nate_optoBiasedChoiceWorld": "projects.nate_optoBiasedChoiceWorld.TrialsOpto"
}
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ build-backend = "setuptools.build_meta"

[project]
name = "project_extraction"
version = "0.2.2"
version = "0.2.3"
description = "Custom extractors for satellite tasks"
dynamic = [ "readme" ]
keywords = [ "IBL", "neuro-science" ]
requires-python = "~=3.10"
license = { file = "LICENSE" }
dependencies = [ "python-vlc" ]

[project.optional-dependencies]
passiveVideo = [ "python-vlc" ]

[tool.setuptools]
include-package-data = true
Expand Down

0 comments on commit 465d3b5

Please sign in to comment.