Skip to content

Commit

Permalink
Merge pull request #33 from int-brain-lab/princeton
Browse files Browse the repository at this point in the history
Princeton
  • Loading branch information
mayofaulkner authored Jan 29, 2025
2 parents c924da9 + efe875d commit 1a498dd
Show file tree
Hide file tree
Showing 6 changed files with 206 additions and 341 deletions.
40 changes: 40 additions & 0 deletions projects/alejandro_FPLROptoChoiceWorld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Bpod extractor for alejandro's FPLOptoChoiceWorld and FPROptoChoiceWorld task.
This is the same as biasedChoiceWorld with the addition of one dataset, `trials.laserStimulation`; The trials which the
laser was on. For th FPLOptoChoiceWorld protocol the laser was on when the stimulus was on the left hand side and for
the FPROptoChoiceWorld protocol the laser was on when the stimulus was on the right hand side of the screen
"""
import numpy as np
from ibllib.io.extractors.base import BaseBpodTrialsExtractor, run_extractor_classes
from ibllib.io.extractors.bpod_trials import BiasedTrials


class TrialsFPLROpto(BaseBpodTrialsExtractor):
var_names = BiasedTrials.var_names + ('laser_stimulation', 'laser_intervals',)
save_names = BiasedTrials.save_names + ('_ibl_trials.laserStimulation.npy', '_ibl_trials.laserIntervals.npy',)

def _extract(self, extractor_classes=None, **kwargs) -> dict:

# 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)

# Extract laser stimulation dataset
laser_stimulation = np.zeros_like(out['table']['contrastLeft'])
laser_intervals = np.full((out['table']['contrastLeft'].size, 2), np.nan)
if 'FPR' in self.settings['PYBPOD_PROTOCOL']:
idx = ~np.isnan(out['table']['contrastRight'])
elif 'FPL' in self.settings['PYBPOD_PROTOCOL']:
idx = ~np.isnan(out['table']['contrastLeft'])

laser_stimulation[idx] = 1
# Laser stimulated at goCue for 200 ms
laser_intervals[idx, 0] = out['table']['goCue_times'][idx]
laser_intervals[idx, 1] = out['table']['goCue_times'][idx] + 200 / 1e3

out['laser_stimulation'] = laser_stimulation
out['laser_intervals'] = laser_intervals

return {k: out[k] for k in self.var_names} # Ensures all datasets present and ordered
19 changes: 16 additions & 3 deletions projects/biased_fibrephotometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,14 @@ def sync_timestamps(daq_data, fp_data, trials):
mask = state.isin(CHANNELS['L470'])
if ttl_interval == 40:
frame_number = fp_data['FrameCounter'][mask]
elif ttl_interval == 20:
frame_number = fp_data['FrameCounter'][mask]
elif ttl_interval == 10:
frame_number = fp_data['FrameCounter']
elif ttl_interval == 25:
frame_number = fp_data['FrameCounter']
elif ttl_interval == 50:
frame_number = fp_data['FrameCounter'][mask]

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

n_daq_trials = (daq_data['feedback_times'] == 1).sum()
if n_daq_trials == trials['feedback_times'].size:
daq_data.loc[daq_data['feedback_times'] == 1, 'bpod_times'] = trials['feedback_times']
elif n_daq_trials - trials['feedback_times'].size == 1:
daq_data.loc[daq_data['feedback_times'] == 1, 'bpod_times'] = np.r_[trials['feedback_times'], np.nan]
else:
assert n_daq_trials == trials['feedback_times'].size, "Trials don't match up"
trial_diff = n_daq_trials - trials['feedback_times'].size
nan_trials = np.where(trials.choice == 0)[0]
if len(nan_trials) == -1 * trial_diff:
feedback_times = np.delete(trials['feedback_times'], nan_trials)
assert len(feedback_times) == n_daq_trials, "Trials don't match up"
daq_data.loc[daq_data['feedback_times'] == 1, 'bpod_times'] = feedback_times
else:
assert n_daq_trials == trials['feedback_times'].size, "Trials don't match up"

daq_data['bpod_times'].interpolate(inplace=True)
# Set values after last pulse to nan
Expand Down
244 changes: 0 additions & 244 deletions projects/ephys_bandit.py

This file was deleted.

8 changes: 7 additions & 1 deletion projects/task_extractor_map.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"samuel_cuedBiasedChoiceWorld": "BiasedTrials",
"_iblrig_tasks_neuromodulatorChoiceWorld": "projects.neuromodulators.TrialsTableNeuromodulator",
"nate_optoBiasedChoiceWorld": "projects.nate_optoBiasedChoiceWorld.TrialsOpto"
"nate_optoBiasedChoiceWorld": "projects.nate_optoBiasedChoiceWorld.TrialsOpto",
"FPChoiceWorld": "BiasedTrials",
"FPROptoChoiceWorld": "projects.alejandro_FPLROptoChoiceWorld.TrialsFPLROpto",
"FPLOptoChoiceWorld": "projects.alejandro_FPLROptoChoiceWorld.TrialsFPLROpto",
"_bandit_biasedChoiceWorld": "projects.training_bandit.TrialsBandit",
"_bandit_100_0_biasedChoiceWorld": "projects.training_bandit.TrialsBandit",
"_bandit_alllaser_cued_ephysChoiceWorld": "projects.training_bandit.TrialsLaserBandit"
}
Loading

0 comments on commit 1a498dd

Please sign in to comment.