Skip to content

Commit 1a498dd

Browse files
authored
Merge pull request #33 from int-brain-lab/princeton
Princeton
2 parents c924da9 + efe875d commit 1a498dd

File tree

6 files changed

+206
-341
lines changed

6 files changed

+206
-341
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Bpod extractor for alejandro's FPLOptoChoiceWorld and FPROptoChoiceWorld task.
2+
3+
This is the same as biasedChoiceWorld with the addition of one dataset, `trials.laserStimulation`; The trials which the
4+
laser was on. For th FPLOptoChoiceWorld protocol the laser was on when the stimulus was on the left hand side and for
5+
the FPROptoChoiceWorld protocol the laser was on when the stimulus was on the right hand side of the screen
6+
7+
"""
8+
import numpy as np
9+
from ibllib.io.extractors.base import BaseBpodTrialsExtractor, run_extractor_classes
10+
from ibllib.io.extractors.bpod_trials import BiasedTrials
11+
12+
13+
class TrialsFPLROpto(BaseBpodTrialsExtractor):
14+
var_names = BiasedTrials.var_names + ('laser_stimulation', 'laser_intervals',)
15+
save_names = BiasedTrials.save_names + ('_ibl_trials.laserStimulation.npy', '_ibl_trials.laserIntervals.npy',)
16+
17+
def _extract(self, extractor_classes=None, **kwargs) -> dict:
18+
19+
# Extract common biased choice world datasets
20+
out, _ = run_extractor_classes(
21+
[BiasedTrials], session_path=self.session_path, bpod_trials=self.bpod_trials,
22+
settings=self.settings, save=False, task_collection=self.task_collection)
23+
24+
# Extract laser stimulation dataset
25+
laser_stimulation = np.zeros_like(out['table']['contrastLeft'])
26+
laser_intervals = np.full((out['table']['contrastLeft'].size, 2), np.nan)
27+
if 'FPR' in self.settings['PYBPOD_PROTOCOL']:
28+
idx = ~np.isnan(out['table']['contrastRight'])
29+
elif 'FPL' in self.settings['PYBPOD_PROTOCOL']:
30+
idx = ~np.isnan(out['table']['contrastLeft'])
31+
32+
laser_stimulation[idx] = 1
33+
# Laser stimulated at goCue for 200 ms
34+
laser_intervals[idx, 0] = out['table']['goCue_times'][idx]
35+
laser_intervals[idx, 1] = out['table']['goCue_times'][idx] + 200 / 1e3
36+
37+
out['laser_stimulation'] = laser_stimulation
38+
out['laser_intervals'] = laser_intervals
39+
40+
return {k: out[k] for k in self.var_names} # Ensures all datasets present and ordered

projects/biased_fibrephotometry.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,14 @@ def sync_timestamps(daq_data, fp_data, trials):
511511
mask = state.isin(CHANNELS['L470'])
512512
if ttl_interval == 40:
513513
frame_number = fp_data['FrameCounter'][mask]
514+
elif ttl_interval == 20:
515+
frame_number = fp_data['FrameCounter'][mask]
514516
elif ttl_interval == 10:
515517
frame_number = fp_data['FrameCounter']
518+
elif ttl_interval == 25:
519+
frame_number = fp_data['FrameCounter']
520+
elif ttl_interval == 50:
521+
frame_number = fp_data['FrameCounter'][mask]
516522

517523
ttl_diff = np.diff(daq_data.loc[daq_data['photometry_ttl'] == 1].index)
518524
while ttl_diff.max() > ttl_interval * 3:
@@ -531,16 +537,23 @@ def sync_timestamps(daq_data, fp_data, trials):
531537
daq_data.loc[np.where(daq_data['bpod'].diff() == -1)[0], 'ttl_off'] = 1
532538
daq_data.loc[np.where(daq_data['bpod'].diff() == 1)[0], 'ttl_duration'] = \
533539
daq_data.loc[daq_data['ttl_off'] == 1].index - daq_data.loc[daq_data['ttl_on'] == 1].index
534-
# Valve and error tones have pulses > 100
535-
daq_data.loc[daq_data['ttl_duration'] > 100, 'feedback_times'] = 1
540+
# Valve and error tones have pulses > 105
541+
daq_data.loc[daq_data['ttl_duration'] > 105, 'feedback_times'] = 1
536542

537543
n_daq_trials = (daq_data['feedback_times'] == 1).sum()
538544
if n_daq_trials == trials['feedback_times'].size:
539545
daq_data.loc[daq_data['feedback_times'] == 1, 'bpod_times'] = trials['feedback_times']
540546
elif n_daq_trials - trials['feedback_times'].size == 1:
541547
daq_data.loc[daq_data['feedback_times'] == 1, 'bpod_times'] = np.r_[trials['feedback_times'], np.nan]
542548
else:
543-
assert n_daq_trials == trials['feedback_times'].size, "Trials don't match up"
549+
trial_diff = n_daq_trials - trials['feedback_times'].size
550+
nan_trials = np.where(trials.choice == 0)[0]
551+
if len(nan_trials) == -1 * trial_diff:
552+
feedback_times = np.delete(trials['feedback_times'], nan_trials)
553+
assert len(feedback_times) == n_daq_trials, "Trials don't match up"
554+
daq_data.loc[daq_data['feedback_times'] == 1, 'bpod_times'] = feedback_times
555+
else:
556+
assert n_daq_trials == trials['feedback_times'].size, "Trials don't match up"
544557

545558
daq_data['bpod_times'].interpolate(inplace=True)
546559
# Set values after last pulse to nan

projects/ephys_bandit.py

Lines changed: 0 additions & 244 deletions
This file was deleted.

projects/task_extractor_map.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"samuel_cuedBiasedChoiceWorld": "BiasedTrials",
33
"_iblrig_tasks_neuromodulatorChoiceWorld": "projects.neuromodulators.TrialsTableNeuromodulator",
4-
"nate_optoBiasedChoiceWorld": "projects.nate_optoBiasedChoiceWorld.TrialsOpto"
4+
"nate_optoBiasedChoiceWorld": "projects.nate_optoBiasedChoiceWorld.TrialsOpto",
5+
"FPChoiceWorld": "BiasedTrials",
6+
"FPROptoChoiceWorld": "projects.alejandro_FPLROptoChoiceWorld.TrialsFPLROpto",
7+
"FPLOptoChoiceWorld": "projects.alejandro_FPLROptoChoiceWorld.TrialsFPLROpto",
8+
"_bandit_biasedChoiceWorld": "projects.training_bandit.TrialsBandit",
9+
"_bandit_100_0_biasedChoiceWorld": "projects.training_bandit.TrialsBandit",
10+
"_bandit_alllaser_cued_ephysChoiceWorld": "projects.training_bandit.TrialsLaserBandit"
511
}

0 commit comments

Comments
 (0)