Skip to content

Commit f292278

Browse files
committed
Report snapshot probe: re-usable subclass for all snapshots linked to a pid
1 parent 1d45f57 commit f292278

File tree

2 files changed

+54
-10
lines changed

2 files changed

+54
-10
lines changed

ibllib/plots/figures.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import matplotlib.pyplot as plt
1212

1313
from ibllib.dsp import voltage
14-
from ibllib.plots.snapshot import ReportSnapshot
14+
from ibllib.plots.snapshot import ReportSnapshotProbe
1515
from one.api import ONE
1616
import one.alf.io as alfio
1717
from one.alf.exceptions import ALFObjectNotFound
@@ -22,7 +22,7 @@
2222
logger = logging.getLogger('ibllib')
2323

2424

25-
class BadChannelsAp(ReportSnapshot):
25+
class SpikeSorting(ReportSnapshotProbe):
2626
"""
2727
Plots raw electrophysiology AP band
2828
:param session_path: session path
@@ -34,20 +34,44 @@ class BadChannelsAp(ReportSnapshot):
3434
'output_files': [] # see setUp method for declaration of inputs
3535
}
3636

37-
def __init__(self, session_path, probe_id, **kwargs):
38-
self.content_type = 'probeinsertion'
39-
self.pid = probe_id
40-
super(BadChannelsAp, self).__init__(session_path, probe_id, content_type=self.content_type, **kwargs)
37+
def _run(self):
38+
"""runs for initiated PID, streams data, destripe and check bad channels"""
39+
assert self.pid
40+
41+
def get_probe_signature(self):
42+
input_signature = [('spikes.times.npy', f'alf/{self.pname}', True),
43+
('spikes.amps.npy', f'alf/{self.pname}', True),
44+
('spikes.depths.npy', f'alf/{self.pname}', True)]
45+
output_signature = [('spike_sorting_raster.png', f'snapshot/{self.pname}', True)]
46+
self.signature = {'input_files': input_signature, 'output_file': output_signature}
47+
48+
49+
class BadChannelsAp(ReportSnapshotProbe):
50+
"""
51+
Plots raw electrophysiology AP band
52+
task = BadChannelsAp(pid, one=one=one)
53+
:param session_path: session path
54+
:param probe_id: str, UUID of the probe insertion for which to create the plot
55+
:param **kwargs: keyword arguments passed to tasks.Task
56+
"""
57+
signature = {
58+
'input_files': [], # see setUp method for declaration of inputs
59+
'output_files': [] # see setUp method for declaration of inputs
60+
}
4161

4262
@staticmethod
43-
def spike_sorting_signature(pname=None):
63+
def get_probe_signature(pname=None):
4464
pname = pname if pname is not None else "probe*"
4565
input_signature = [('*ap.meta', f'raw_ephys_data/{pname}', True),
4666
('*ap.ch', f'raw_ephys_data/{pname}', False),
4767
('*ap.cbin', f'raw_ephys_data/{pname}', False)]
48-
output_signature = [('destripe.png', f'snapshot/{pname}', True),
49-
('highpass.png', f'snapshot/{pname}', True)]
50-
return input_signature, output_signature
68+
output_signature = [('raw_ephys_bad_channels.png', f'snapshot/{pname}', True),
69+
('raw_ephys_bad_channels_highpass.png', f'snapshot/{pname}', True),
70+
('raw_ephys_bad_channels_highpass.png', f'snapshot/{pname}', True),
71+
('raw_ephys_bad_channels_destripe.png', f'snapshot/{pname}', True),
72+
('raw_ephys_bad_channels_difference.png', f'snapshot/{pname}', True),
73+
]
74+
return {'input_files': input_signature, 'output_files': output_signature}
5175

5276
def _run(self):
5377
"""runs for initiated PID, streams data, destripe and check bad channels"""

ibllib/plots/snapshot.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import requests
33
import traceback
44
import json
5+
import abc
56

67
from one.api import ONE
78
from ibllib.pipes import tasks
@@ -33,6 +34,25 @@ def register_images(self, widths=None, function=None):
3334
return snapshot.register_images(self.outputs, jsons=jsons, texts=texts, widths=widths)
3435

3536

37+
class ReportSnapshotProbe(ReportSnapshot):
38+
39+
def __init__(self, pid, one=None, **kwargs):
40+
assert one
41+
self.one = one
42+
self.content_type = 'probeinsertion'
43+
self.pid = pid
44+
self.eid, self.pname = self.one.pid2eid(self.pid)
45+
self.session_path = self.one.eid2path(self.eid)
46+
self.signature = self.get_probe_signature()
47+
super(ReportSnapshotProbe, self).__init__(self.session_path, object_id=pid, content_type=self.content_type, **kwargs)
48+
49+
@abc.abstractmethod
50+
def get_probe_signature(pname=None):
51+
# method that gets input and output signatures from the probe name. The format is a dictionary as follows:
52+
# return {'input_files': input_signature, 'output_files': output_signature}
53+
pass
54+
55+
3656
class Snapshot:
3757
"""
3858
A class to register images in form of Notes, linked to an object on Alyx.

0 commit comments

Comments
 (0)