Skip to content

Commit

Permalink
Cache the morphologies properly. (#5)
Browse files Browse the repository at this point in the history
Rather than loading the morphologies for every step, this will cache the
untransformed morphologies between steps, lessening the IO load.
  • Loading branch information
matz-e authored Oct 18, 2024
1 parent 37f271c commit c34b2a0
Showing 1 changed file with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"""

from abc import ABCMeta, abstractmethod
import functools
import inspect
import os.path

Expand All @@ -19,7 +20,7 @@
import numpy as np

from connectome_manipulator import access_functions
from connectome_manipulator import log
from connectome_manipulator import log, profiler
from connectome_manipulator import utils
from connectome_manipulator.access_functions import get_enumeration_map

Expand Down Expand Up @@ -92,16 +93,24 @@ def __init__(self, nodes, writer=None, split_index=0, split_total=1):
self.nodes[1].config.get("alternate_morphologies"),
)

@profiler.profileit(name="morphology_reading")
def _get_tgt_morphs(self, morph_ext, tgt_node_sel):
"""Access function (incl. transformation!), using specified format (swc/h5/...)"""
morpho_dir = self.morpho_helper.get_morphology_dir(morph_ext)
collection = Collection(morpho_dir, [f".{morph_ext}"])
result = access_functions.get_nodes(self.nodes[1], tgt_node_sel)
return self._transform(
self._get_cached_morphs(morph_ext, tuple(result[Node.MORPHOLOGY])),
tgt_node_sel,
)

morphologies = []
for morpho_name in result[Node.MORPHOLOGY]:
morphologies.append(collection.load(morpho_name, mutable=True))
return self._transform(morphologies, tgt_node_sel)
@functools.lru_cache(maxsize=10)
def _get_cached_morphs(self, morph_ext, basenames):
"""Cached access function to get the untransformed morphologies."""
morpho_dir = self.morpho_helper.get_morphology_dir(morph_ext)
collection = Collection(morpho_dir, [f".{morph_ext}"])
morphologies = [None] * len(basenames)
for idx in collection.argsort(basenames):
morphologies[idx] = collection.load(basenames[idx], mutable=True)
return morphologies

def _transform(self, morphs, node_sel):
rotations = access_functions.orientations(self.nodes[1], node_sel)
Expand Down

0 comments on commit c34b2a0

Please sign in to comment.