Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the morphologies properly. #5

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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