Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit 88f089a

Browse files
authored
feat: repetitions support for ScalaNWBReader (#194)
1 parent 7cd403b commit 88f089a

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

bluepyefe/nwbreader.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def read(self):
103103

104104

105105
class ScalaNWBReader(NWBReader):
106+
106107
def read(self):
107108
""" Read and format the content of the NWB file
108109
@@ -112,6 +113,11 @@ def read(self):
112113

113114
data = []
114115

116+
if self.repetition:
117+
repetitions_content = self.content['general']['intracellular_ephys']['intracellular_recordings']['repetition']
118+
if isinstance(self.repetition, (int, str)):
119+
self.repetition = [int(self.repetition)]
120+
115121
for sweep in list(self.content['acquisition'].keys()):
116122
key_current = sweep.replace('Series', 'StimulusSeries')
117123
try:
@@ -132,12 +138,23 @@ def read(self):
132138
if key_current not in self.content['stimulus']['presentation']:
133139
continue
134140

135-
data.append(self._format_nwb_trace(
136-
voltage=self.content['acquisition'][sweep]['data'],
137-
current=self.content['stimulus']['presentation'][key_current]['data'],
138-
start_time=self.content["acquisition"][sweep]["starting_time"],
139-
trace_name=sweep,
140-
))
141+
if self.repetition:
142+
sweep_id = int(sweep.split("_")[-1])
143+
if (int(repetitions_content[sweep_id]) in self.repetition):
144+
data.append(self._format_nwb_trace(
145+
voltage=self.content['acquisition'][sweep]['data'],
146+
current=self.content['stimulus']['presentation'][key_current]['data'],
147+
start_time=self.content['acquisition'][sweep]["starting_time"],
148+
trace_name=sweep,
149+
repetition=int(repetitions_content[sweep_id])
150+
))
151+
else:
152+
data.append(self._format_nwb_trace(
153+
voltage=self.content['acquisition'][sweep]['data'],
154+
current=self.content['stimulus']['presentation'][key_current]['data'],
155+
start_time=self.content["acquisition"][sweep]["starting_time"],
156+
trace_name=sweep,
157+
))
141158

142159
return data
143160

bluepyefe/reader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,15 @@ def nwb_reader(in_data):
206206
with h5py.File(in_data["filepath"], "r") as content:
207207
if "data_organization" in content:
208208
reader = BBPNWBReader(
209-
content,
210-
target_protocols,
211-
in_data.get("repetition", None),
212-
in_data.get("v_file", None)
209+
content=content,
210+
target_protocols=target_protocols,
211+
v_file=in_data.get("v_file", None),
212+
repetition=in_data.get("repetition", None),
213213
)
214214
elif "timeseries" in content["acquisition"].keys():
215215
reader = AIBSNWBReader(content, target_protocols)
216216
else:
217-
reader = ScalaNWBReader(content, target_protocols)
217+
reader = ScalaNWBReader(content, target_protocols, repetition=in_data.get("repetition", None))
218218

219219
data = reader.read()
220220

0 commit comments

Comments
 (0)