• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

int-brain-lab / iblrig / 9031936551

10 May 2024 12:05PM UTC coverage: 48.538% (+1.7%) from 46.79%
9031936551

Pull #643

github

53c3e3
web-flow
Merge 3c8214f78 into ec2d8e4fe
Pull Request #643: 8.19.0

377 of 1073 new or added lines in 38 files covered. (35.14%)

977 existing lines in 19 files now uncovered.

3253 of 6702 relevant lines covered (48.54%)

0.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

43.08
/iblrig_tasks/_iblrig_tasks_passiveChoiceWorld/task.py
1
import logging
2✔
2
import sys
2✔
3
import time
2✔
4
from pathlib import Path
2✔
5

6
import pandas as pd
2✔
7

8
import iblrig.misc
2✔
9
from iblrig.base_choice_world import ChoiceWorldSession
2✔
10

11
log = logging.getLogger('iblrig.task')
2✔
12

13

14
class Session(ChoiceWorldSession):
2✔
15
    protocol_name = '_iblrig_tasks_passiveChoiceWorld'
2✔
16

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

25
    @staticmethod
2✔
26
    def extra_parser():
2✔
27
        """:return: argparse.parser()"""
28
        parser = super(Session, Session).extra_parser()
2✔
29
        parser.add_argument(
2✔
30
            '--session_template_id',
31
            option_strings=['--session_template_id'],
32
            dest='session_template_id',
33
            default=0,
34
            type=int,
35
            help='pre-generated session index (zero-based)',
36
        )
37
        return parser
2✔
38

39
    def start_hardware(self):
2✔
UNCOV
40
        if not self.is_mock:
×
UNCOV
41
            self.start_mixin_frame2ttl()
×
42
            self.start_mixin_bpod()
×
43
            self.start_mixin_valve()
×
UNCOV
44
            self.start_mixin_sound()
×
45
            self.start_mixin_bonsai_cameras()
×
UNCOV
46
            self.start_mixin_bonsai_microphone()
×
47
            self.start_mixin_rotary_encoder()
×
48

49
    def get_state_machine_trial(self, *args, **kwargs):
2✔
50
        pass
2✔
51

52
    def next_trial(self):
2✔
53
        pass
2✔
54

55
    def _run(self):
2✔
56
        """
57
        This is the method that runs the task with the actual state machine
58
        :return:
59
        """
60
        self.trigger_bonsai_cameras()
×
61
        log.info('Starting spontaneous activity followed by receptive field mapping')
×
62
        # Run the passive part i.e. spontaneous activity and RFMapping stim
63
        self.run_passive_visual_stim(sa_time='00:10:00')
×
64
        # Then run the replay of task events: V for valve, T for tone, N for noise, G for gratings
65
        log.info('Starting replay of task stims')
×
66

UNCOV
67
        action_show_stim = self.bpod.actions['bonsai_show_stim'][1]
×
UNCOV
68
        action_hide_stim = self.bpod.actions['bonsai_hide_stim'][1]
×
UNCOV
69
        byte_show_stim = self.bpod.serial_messages[action_show_stim]['message'][-1]
×
UNCOV
70
        byte_hide_stim = self.bpod.serial_messages[action_hide_stim]['message'][-1]
×
71

UNCOV
72
        if not self.is_mock:
×
UNCOV
73
            self.start_mixin_bonsai_visual_stimulus()
×
NEW
74
        for trial_num, trial in self.trials_table.iterrows():
×
NEW
75
            self.trial_num = trial_num
×
UNCOV
76
            log.info(f'Delay: {trial.stim_delay}; ID: {trial.stim_type}; Count: {self.trial_num}/300')
×
UNCOV
77
            sys.stdout.flush()
×
UNCOV
78
            time.sleep(trial.stim_delay)
×
UNCOV
79
            if trial.stim_type == 'V':
×
UNCOV
80
                self.valve_open(self.reward_time)
×
UNCOV
81
            elif trial.stim_type == 'T':
×
UNCOV
82
                self.sound_play_tone(state_timer=0.102)
×
UNCOV
83
            elif trial.stim_type == 'N':
×
UNCOV
84
                self.sound_play_noise(state_timer=0.510)
×
UNCOV
85
            elif trial.stim_type == 'G':
×
86
                # this will send the current trial info to the visual stim
87
                # we need to make sure Bonsai is in a state to display stimuli
UNCOV
88
                self.send_trial_info_to_bonsai()
×
UNCOV
89
                self.bonsai_visual_udp_client.send_message(r'/re', byte_show_stim)
×
UNCOV
90
                time.sleep(0.3)
×
UNCOV
91
                self.bonsai_visual_udp_client.send_message(r'/re', byte_hide_stim)
×
UNCOV
92
            if self.paths.SESSION_FOLDER.joinpath('.stop').exists():
×
UNCOV
93
                self.paths.SESSION_FOLDER.joinpath('.stop').unlink()
×
UNCOV
94
                break
×
95

96

97
if __name__ == '__main__':  # pragma: no cover
98
    # python .\iblrig_tasks\_iblrig_tasks_spontaneous\task.py --subject mysubject
99
    kwargs = iblrig.misc.get_task_arguments(parents=[Session.extra_parser()])
100
    sess = Session(**kwargs)
101
    sess.run()
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc