Skip to content

Commit 3f76faf

Browse files
committed
personnal project prototype
1 parent 96c3c60 commit 3f76faf

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

ibllib/projects/__init__.py

Whitespace-only changes.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
from collections import OrderedDict
2+
3+
import numpy as np
4+
from ibllib.io.extractors import ephys_fpga
5+
from ibllib.dsp.utils import sync_timestamps
6+
from ibllib.plots import squares, vertical_lines
7+
from ibllib.pipes import tasks
8+
9+
from ibllib.pipes.ephys_preprocessing import (
10+
EphysRegisterRaw, EphysPulses, RawEphysQC, EphysAudio, EphysMtscomp, EphysVideoCompress,
11+
EphysCellsQc, EphysDLC, SpikeSorting)
12+
13+
LASER_PULSE_DURATION_SECS = .5
14+
LASER_PROBABILITY = .8
15+
DISPLAY = True
16+
17+
18+
class EphysPassiveOptoTrials(tasks.Task):
19+
cpu = 1
20+
io_charge = 90
21+
level = 1
22+
23+
def _run(self):
24+
sync, sync_map = ephys_fpga.get_main_probe_sync(self.session_path)
25+
bpod = ephys_fpga.get_sync_fronts(sync, sync_map['bpod'])
26+
laser_ttl = ephys_fpga.get_sync_fronts(sync, sync_map['laser_ttl'])
27+
t_bpod = bpod['times'][bpod['polarities'] == 1]
28+
t_laser = laser_ttl['times'][laser_ttl['polarities'] == 1]
29+
_, _, ibpod, ilaser = sync_timestamps(t_bpod, t_laser, return_indices=True)
30+
31+
if DISPLAY:
32+
for ch in np.arange(3):
33+
ch0 = ephys_fpga.get_sync_fronts(sync, 16 + ch)
34+
squares(ch0['times'], ch0['polarities'], yrange=[-.5 + ch, .5 + ch])
35+
vertical_lines(t_bpod[ibpod], ymax=4)
36+
37+
trial_starts = t_bpod
38+
trial_starts[ibpod] = t_laser[ilaser]
39+
ntrials = trial_starts.size
40+
41+
laser_intervals = np.zeros((ntrials, 2)) * np.nan
42+
laser_intervals[ibpod, 0] = t_laser[ilaser]
43+
laser_intervals[ibpod, 1] = t_laser[ilaser] + LASER_PULSE_DURATION_SECS
44+
intervals = np.zeros((ntrials, 2)) * np.nan
45+
intervals[:, 0] = trial_starts
46+
intervals[:, 1] = np.r_[trial_starts[1:], np.nan]
47+
alf_path = self.session_path.joinpath('alf')
48+
alf_path.mkdir(parents=True, exist_ok=True)
49+
50+
out_files = [
51+
alf_path.joinpath("_ibl_trials.laser_probability.npy"),
52+
alf_path.joinpath("_ibl_trials.laser_intervals.npy"),
53+
alf_path.joinpath("_ibl_trials.intervals.npy"),
54+
]
55+
np.save(alf_path.joinpath("_ibl_trials.laser_intervals.npy"), laser_intervals)
56+
np.save(alf_path.joinpath("_ibl_trials.laser_probability.npy"), trial_starts * 0 + LASER_PROBABILITY)
57+
np.save(alf_path.joinpath("_ibl_trials.intervals.npy"), intervals)
58+
59+
return out_files
60+
61+
62+
class EphysPassiveOptoPipeline(tasks.Pipeline):
63+
label = __name__
64+
65+
def __init__(self, session_path=None, **kwargs):
66+
super(EphysPassiveOptoPipeline, self).__init__(session_path, **kwargs)
67+
tasks = OrderedDict()
68+
self.session_path = session_path
69+
# level 0
70+
tasks["EphysRegisterRaw"] = EphysRegisterRaw(self.session_path)
71+
tasks["EphysPulses"] = EphysPulses(self.session_path)
72+
tasks["EphysRawQC"] = RawEphysQC(self.session_path)
73+
tasks["EphysAudio"] = EphysAudio(self.session_path)
74+
tasks["EphysMtscomp"] = EphysMtscomp(self.session_path)
75+
# level 1
76+
tasks["SpikeSorting"] = SpikeSorting(
77+
self.session_path, parents=[tasks["EphysMtscomp"], tasks["EphysPulses"]])
78+
tasks["EphysPassiveOptoTrials"] = EphysPassiveOptoTrials(self.session_path, parents=[tasks["EphysPulses"]])
79+
tasks["EphysVideoCompress"] = EphysVideoCompress(
80+
self.session_path, parents=[tasks["EphysPulses"]])
81+
# level 2
82+
tasks["EphysCellsQc"] = EphysCellsQc(self.session_path, parents=[tasks["SpikeSorting"]])
83+
tasks["EphysDLC"] = EphysDLC(self.session_path, parents=[tasks["EphysVideoCompress"]])
84+
self.tasks = tasks
85+
86+
87+
#
88+
# from one.api import ONE
89+
#
90+
# one = ONE()
91+
# session_path = Path("/mnt/s0/Data/Subjects/KS056/2021-07-18/001")
92+
#
93+
# session_path = "/mnt/iblserver2/ephys_recordings/KS056/2021-07-18/001"
94+
#
95+
# pipeline = EphysPassiveOptoPipeline(session_path, one=one)
96+
# pipeline.run()

0 commit comments

Comments
 (0)