|
7 | 7 | from numpy.typing import ArrayLike |
8 | 8 | from probeinterface import Probe |
9 | 9 | from spikeinterface.core import BaseRecording, BaseRecordingSegment, BaseSorting, Templates |
10 | | -from multiprocessing.shared_memory import SharedMemory |
11 | | -from spikeinterface.core.core_tools import make_shared_array |
12 | 10 |
|
13 | 11 |
|
14 | 12 | def interpolate_templates(templates_array, source_locations, dest_locations, interpolation_method="cubic"): |
@@ -260,85 +258,6 @@ def precompute_displacements(self, displacements, **interpolation_kwargs): |
260 | 258 | self.displacements = displacements |
261 | 259 |
|
262 | 260 |
|
263 | | -class SharedMemoryDriftingTemplates(DriftingTemplates): |
264 | | - |
265 | | - def __init__( |
266 | | - self, |
267 | | - shm_name, |
268 | | - shape, |
269 | | - dtype, |
270 | | - templates_array_moved=None, |
271 | | - displacements=None, |
272 | | - main_shm_owner=True, |
273 | | - **static_kwargs, |
274 | | - ): |
275 | | - |
276 | | - assert len(shape) == 4 |
277 | | - assert shape[0] > 0, "SharedMemoryTemplates only supported with no empty templates" |
278 | | - |
279 | | - self.shm = SharedMemory(shm_name, create=False) |
280 | | - templates_array_moved = np.ndarray(shape=shape, dtype=dtype, buffer=self.shm.buf) |
281 | | - self.static_kwargs = static_kwargs |
282 | | - DriftingTemplates.__init__( |
283 | | - self, templates_array_moved=templates_array_moved, displacements=displacements, **self.static_kwargs |
284 | | - ) |
285 | | - |
286 | | - # this is very important for the shm.unlink() |
287 | | - # only the main instance need to call it |
288 | | - # all other instances that are loaded from dict are not the main owner |
289 | | - self.main_shm_owner = main_shm_owner |
290 | | - |
291 | | - self._kwargs = dict( |
292 | | - shm_name=shm_name, |
293 | | - shape=shape, |
294 | | - displacements=self.displacements, |
295 | | - static_kwargs=self.static_kwargs, |
296 | | - channel_ids=self.channel_ids, |
297 | | - # this ensure that all dump/load will not be main shm owner |
298 | | - main_shm_owner=False, |
299 | | - ) |
300 | | - |
301 | | - def __del__(self): |
302 | | - self.shm.close() |
303 | | - if self.main_shm_owner: |
304 | | - self.shm.unlink() |
305 | | - |
306 | | - @staticmethod |
307 | | - def from_drifting_templates(drifting_templates): |
308 | | - assert ( |
309 | | - drifting_templates.templates_array_moved is not None |
310 | | - ), "drifting_templates must have precomputed displacements" |
311 | | - data = drifting_templates.templates_array_moved |
312 | | - shm_templates, shm = make_shared_array(data.shape, data.dtype) |
313 | | - shm_templates[:] = data |
314 | | - static_kwargs = drifting_templates.to_dict() |
315 | | - init_kwargs = { |
316 | | - "templates_array": np.asarray(static_kwargs["templates_array"]), |
317 | | - "sparsity_mask": ( |
318 | | - None if static_kwargs["sparsity_mask"] is None else np.asarray(static_kwargs["sparsity_mask"]) |
319 | | - ), |
320 | | - "channel_ids": np.asarray(static_kwargs["channel_ids"]), |
321 | | - "unit_ids": np.asarray(static_kwargs["unit_ids"]), |
322 | | - "sampling_frequency": static_kwargs["sampling_frequency"], |
323 | | - "nbefore": static_kwargs["nbefore"], |
324 | | - "is_scaled": static_kwargs["is_scaled"], |
325 | | - "probe": ( |
326 | | - static_kwargs["probe"] if static_kwargs["probe"] is None else Probe.from_dict(static_kwargs["probe"]) |
327 | | - ), |
328 | | - } |
329 | | - shared_drifting_templates = SharedMemoryDriftingTemplates( |
330 | | - shm.name, |
331 | | - data.shape, |
332 | | - data.dtype, |
333 | | - shm_templates, |
334 | | - drifting_templates.displacements, |
335 | | - main_shm_owner=True, |
336 | | - **init_kwargs, |
337 | | - ) |
338 | | - shm.close() |
339 | | - return shared_drifting_templates |
340 | | - |
341 | | - |
342 | 261 | def make_linear_displacement(start, stop, num_step=10): |
343 | 262 | """ |
344 | 263 | Generates 2D linear displacements between `start` and `stop` positions (included in returned displacements). |
|
0 commit comments