Skip to content

Commit

Permalink
attempt to feature extraction in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
anilbey committed Apr 4, 2024
1 parent b5fc0e5 commit 64e62e1
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions bluepyefe/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
"""
import logging
from multiprocessing import Pool
import numpy
import matplotlib.pyplot as plt
import pathlib
Expand Down Expand Up @@ -172,6 +173,12 @@ def read_recordings(
f"the available stimuli names"
)

def extract_efeatures_helper(self, recording_id, efeatures, efeature_names, efel_settings):
"""Helper function to compute efeatures for a single recording."""
self.recordings[recording_id].compute_efeatures(
efeatures, efeature_names, efel_settings)
return self.recordings[recording_id]

def extract_efeatures(
self,
protocol_name,
Expand All @@ -192,10 +199,17 @@ def extract_efeatures(
is to be extracted several time on different sections
of the same recording.
"""
recording_ids = self.get_recordings_id_by_protocol_name(protocol_name)

# Run in parallel via multiprocessing
with Pool(maxtasksperchild=1) as pool:
tasks = [
(rec_id, efeatures, efeature_names, efel_settings)
for rec_id in recording_ids
]
results = pool.starmap(self.extract_efeatures_helper, tasks)

for i in self.get_recordings_id_by_protocol_name(protocol_name):
self.recordings[i].compute_efeatures(
efeatures, efeature_names, efel_settings)
self.recordings = results

def compute_relative_amp(self):
"""Compute the relative current amplitude for all the recordings as a
Expand Down

0 comments on commit 64e62e1

Please sign in to comment.