-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmorphio.py
More file actions
53 lines (42 loc) · 1.88 KB
/
morphio.py
File metadata and controls
53 lines (42 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""Extension module to process morphology files with MorphIO and morph-tool."""
# LICENSE HEADER MANAGED BY add-license-header
# Copyright (c) 2023-2025 Blue Brain Project, EPFL.
#
# This file is part of dir-content-diff.
# See https://github.com/BlueBrain/dir-content-diff for further info.
#
# SPDX-License-Identifier: Apache-2.0
# LICENSE HEADER MANAGED BY add-license-header
from dir_content_diff import register_comparator
from dir_content_diff.base_comparators import BaseComparator
from dir_content_diff.util import import_error_message
try:
from morph_tool import diff
from morphio.mut import Morphology
except ImportError: # pragma: no cover
import_error_message(__name__)
class MorphologyComparator(BaseComparator):
"""Comparator for morphology files."""
def load(self, path, **kwargs):
"""Load a morphology file into a :class:`morphio.Morphology` object."""
return Morphology(path, **kwargs)
def diff(self, ref, comp, *args, **kwargs):
"""Compare data from two morphology files.
Args:
ref_path (str): The path to the reference morphology file.
comp_path (str): The path to the compared morphology file.
*args: See :func:`morph_tool.diff` for details.
**kwargs: See :func:`morph_tool.diff` for details.
Returns:
bool or list(str): ``False`` if the morphologies are considered as equal or a list of
strings explaining why they are not considered as equal.
"""
diffs = diff(ref, comp, *args, **kwargs)
if not diffs:
return False
return [diffs.info]
def register(force=False):
"""Register morphology file extensions."""
register_comparator(".asc", MorphologyComparator(), force=force)
register_comparator(".h5", MorphologyComparator(), force=force)
register_comparator(".swc", MorphologyComparator(), force=force)