int-brain-lab / iblrig

Main repository for IBL rig code
https://int-brain-lab.github.io/iblrig/
MIT License
22 stars 22 forks source link

passiveChoiceWorld without the passive stimuli #665

Open samupicard opened 6 months ago

samupicard commented 6 months ago

At the moment, passiveChoiceWorld follows a strict protocol described here

For chronic experiments we would like to get neural receptive fields every day, but we don't need the passive replay of the task stimuli (in fact, this may disrupt learning so we probably want to get rid of them altogether). We would also like to shorten the gray screen period (spontaneous activity).

I've quickly hacked the passiveChoiceWorld task for today's experiment (I have renamed this locally to passiveChoiceWorld_SP) but in the future it would be great to either:

  1. adjust the passiveChoiceWorld task protocol itself so that the passive replay can optionally be removed/shortened (if specified in task parameters) and to freely select the duration of grey screen (could also be a task parameter?).
  2. if changing an old protocol isn't desirable, creating a new one with the above features as free parameters (ideally, selectable in the wizzard) would be ok too.
samupicard commented 6 months ago

My current hack (just removing the lines controlling the passive replay)

import logging
import sys
import time
from pathlib import Path

import pandas as pd

import iblrig.misc
from iblrig.base_choice_world import ChoiceWorldSession

log = logging.getLogger('iblrig.task')

class Session(ChoiceWorldSession):
    protocol_name = '_iblrig_tasks_passiveChoiceWorld_SP'

    def __init__(self, *args, session_template_id=0, **kwargs):
        self.extractor_tasks = ['PassiveRegisterRaw', 'PassiveTask']
        super(ChoiceWorldSession, self).__init__(**kwargs)
        self.task_params.SESSION_TEMPLATE_ID = session_template_id
        all_trials = pd.read_parquet(Path(__file__).parent.joinpath('passiveChoiceWorld_trials_fixtures.pqt'))
        self.trials_table = all_trials[all_trials['session_id'] == self.task_params.SESSION_TEMPLATE_ID].copy()
        self.trials_table['reward_valve_time'] = self.compute_reward_time(amount_ul=self.trials_table['reward_amount'])

    @staticmethod
    def extra_parser():
        """:return: argparse.parser()"""
        parser = super(Session, Session).extra_parser()
        parser.add_argument(
            '--session_template_id',
            option_strings=['--session_template_id'],
            dest='session_template_id',
            default=0,
            type=int,
            help='pre-generated session index (zero-based)',
        )
        return parser

    def start_hardware(self):
        if not self.is_mock:
            self.start_mixin_frame2ttl()
            self.start_mixin_bpod()
            self.start_mixin_valve()
            self.start_mixin_sound()
            self.start_mixin_bonsai_cameras()
            self.start_mixin_bonsai_microphone()
            self.start_mixin_rotary_encoder()

    def get_state_machine_trial(self, *args, **kwargs):
        pass

    def next_trial(self):
        pass

    def _run(self):
        """
        This is the method that runs the task with the actual state machine
        :return:
        """
        self.trigger_bonsai_cameras()
        log.info('Starting spontaneous activity followed by receptive field mapping')
        # Run the passive part i.e. spontaneous activity and RFMapping stim
        self.run_passive_visual_stim(sa_time='00:01:00')
        # Do NOT run the replay of task events
        log.info('Skipping replay of task stims')

if __name__ == '__main__':  # pragma: no cover
    # python .\iblrig_tasks\_iblrig_tasks_spontaneous\task.py --subject mysubject
    kwargs = iblrig.misc.get_task_arguments(parents=[Session.extra_parser()])
    sess = Session(**kwargs)
    sess.run()
samupicard commented 5 months ago

@bimac @k1o0 i just realised that the PassiveRegisterRaw extractor fails on my custom-made task passiveChoiceWorld_SP above because it cannot find the raw data files produced by the passive task stimuli. Would it be possible to make an extractor that only looks at the RFMapStim.raw data?

bimac commented 5 months ago

678

k1o0 commented 5 months ago

@mayofaulkner to release ibllib with changes to PassiveRegisterRaw; also change extractor to use task parameters when saving replay phase of protocol

bimac commented 5 months ago

new task parameters:

'SPONTANEOUS_ACTIVITY_SECONDS': 600  # duration of spontaneous activity in seconds
'SKIP_EVENT_REPLAY': False  # skip the event replay block