hoa-tools 1.0.2b1__py3-none-any.whl → 1.0.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hoa-tools might be problematic. Click here for more details.
- hoa_tools/_version.py +2 -2
- hoa_tools/dataset.py +16 -0
- hoa_tools/registration.py +41 -7
- {hoa_tools-1.0.2b1.dist-info → hoa_tools-1.0.4.dist-info}/METADATA +3 -1
- {hoa_tools-1.0.2b1.dist-info → hoa_tools-1.0.4.dist-info}/RECORD +8 -8
- {hoa_tools-1.0.2b1.dist-info → hoa_tools-1.0.4.dist-info}/WHEEL +1 -1
- {hoa_tools-1.0.2b1.dist-info → hoa_tools-1.0.4.dist-info}/licenses/LICENSE.md +0 -0
- {hoa_tools-1.0.2b1.dist-info → hoa_tools-1.0.4.dist-info}/top_level.txt +0 -0
hoa_tools/_version.py
CHANGED
hoa_tools/dataset.py
CHANGED
|
@@ -17,6 +17,7 @@ from typing import Literal
|
|
|
17
17
|
|
|
18
18
|
import dask.array.core
|
|
19
19
|
import gcsfs
|
|
20
|
+
import networkx as nx
|
|
20
21
|
import numpy as np
|
|
21
22
|
import xarray as xr
|
|
22
23
|
import zarr.core
|
|
@@ -41,6 +42,9 @@ class Dataset(HOAMetadata):
|
|
|
41
42
|
def __str__(self) -> str:
|
|
42
43
|
return f"Dataset(name={self.name})"
|
|
43
44
|
|
|
45
|
+
def __hash__(self) -> int:
|
|
46
|
+
return hash(self.name)
|
|
47
|
+
|
|
44
48
|
def _organ_str(self) -> str:
|
|
45
49
|
"""
|
|
46
50
|
Get name of organ, with organ context appended if present.
|
|
@@ -114,6 +118,18 @@ class Dataset(HOAMetadata):
|
|
|
114
118
|
]
|
|
115
119
|
return sorted(parents, key=lambda c: c.name)
|
|
116
120
|
|
|
121
|
+
def get_registered(self) -> set["Dataset"]:
|
|
122
|
+
"""
|
|
123
|
+
Get a set of all datasets that are registered (even indirectly) to this dataset.
|
|
124
|
+
"""
|
|
125
|
+
import hoa_tools.registration
|
|
126
|
+
|
|
127
|
+
dataset_names = nx.node_connected_component(
|
|
128
|
+
hoa_tools.registration.Inventory._graph.to_undirected(), # noqa: SLF001
|
|
129
|
+
self.name,
|
|
130
|
+
)
|
|
131
|
+
return {get_dataset(name) for name in dataset_names}
|
|
132
|
+
|
|
117
133
|
@property
|
|
118
134
|
def _remote_fmt(self) -> Literal["n5", "zarr"]:
|
|
119
135
|
if self.data.gcs_url.startswith("n5://"):
|
hoa_tools/registration.py
CHANGED
|
@@ -8,6 +8,10 @@ in units of micro-meters (μm).
|
|
|
8
8
|
Transforms are defined using the `SimpleITK` library.
|
|
9
9
|
"""
|
|
10
10
|
|
|
11
|
+
import itertools
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
import networkx as nx
|
|
11
15
|
import numpy as np
|
|
12
16
|
import SimpleITK as sitk
|
|
13
17
|
|
|
@@ -28,13 +32,18 @@ class RegistrationInventory:
|
|
|
28
32
|
"""
|
|
29
33
|
Create registration inventory.
|
|
30
34
|
"""
|
|
31
|
-
self.
|
|
35
|
+
self._graph: nx.DiGraph[Any] = nx.DiGraph()
|
|
32
36
|
|
|
33
37
|
def __contains__(self, item: tuple[Dataset, Dataset]) -> bool:
|
|
34
38
|
"""
|
|
35
39
|
Check for existence of registration between two datasets.
|
|
36
40
|
"""
|
|
37
|
-
|
|
41
|
+
try:
|
|
42
|
+
nx.shortest_path(self._graph, item[0].name, item[1].name)
|
|
43
|
+
except nx.exception.NetworkXNoPath:
|
|
44
|
+
return False
|
|
45
|
+
else:
|
|
46
|
+
return True
|
|
38
47
|
|
|
39
48
|
def get_registration(
|
|
40
49
|
self, *, source_dataset: Dataset, target_dataset: Dataset
|
|
@@ -42,7 +51,28 @@ class RegistrationInventory:
|
|
|
42
51
|
"""
|
|
43
52
|
Get a registration.
|
|
44
53
|
"""
|
|
45
|
-
|
|
54
|
+
try:
|
|
55
|
+
path = nx.shortest_path(
|
|
56
|
+
self._graph, source_dataset.name, target_dataset.name
|
|
57
|
+
)
|
|
58
|
+
except nx.exception.NetworkXNoPath:
|
|
59
|
+
msg = (
|
|
60
|
+
f"No registration path between {source_dataset.name} and "
|
|
61
|
+
f"{target_dataset.name}"
|
|
62
|
+
)
|
|
63
|
+
raise ValueError(msg) from None
|
|
64
|
+
|
|
65
|
+
transforms: list[sitk.Transform] = [
|
|
66
|
+
self._graph[p1][p2]["transform"] for p1, p2 in itertools.pairwise(path)
|
|
67
|
+
]
|
|
68
|
+
if len(transforms) == 1:
|
|
69
|
+
return transforms[0]
|
|
70
|
+
|
|
71
|
+
ndim = 3
|
|
72
|
+
t = sitk.CompositeTransform(ndim) # type: ignore[no-untyped-call]
|
|
73
|
+
for transform in transforms:
|
|
74
|
+
t.AddTransform(transform) # type: ignore[no-untyped-call]
|
|
75
|
+
return t
|
|
46
76
|
|
|
47
77
|
def add_registration(
|
|
48
78
|
self,
|
|
@@ -59,16 +89,20 @@ class RegistrationInventory:
|
|
|
59
89
|
This will override any already defined transforms for these two datasets.
|
|
60
90
|
|
|
61
91
|
"""
|
|
62
|
-
self.
|
|
63
|
-
|
|
64
|
-
|
|
92
|
+
self._graph.add_edge(
|
|
93
|
+
source_dataset.name, target_dataset.name, transform=transform
|
|
94
|
+
)
|
|
95
|
+
self._graph.add_edge(
|
|
96
|
+
target_dataset.name,
|
|
97
|
+
source_dataset.name,
|
|
98
|
+
transform=transform.GetInverse(), # type: ignore[no-untyped-call]
|
|
65
99
|
)
|
|
66
100
|
|
|
67
101
|
def _clear(self) -> None:
|
|
68
102
|
"""
|
|
69
103
|
Remove all registrations.
|
|
70
104
|
"""
|
|
71
|
-
self.
|
|
105
|
+
self._graph = nx.DiGraph()
|
|
72
106
|
|
|
73
107
|
|
|
74
108
|
def build_transform(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hoa-tools
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4
|
|
4
4
|
Summary: Tools for working with the Human Organ Atlas
|
|
5
5
|
Author-email: David Stansby <d.stansby@ucl.ac.uk>
|
|
6
6
|
License: Copyright (c) 2024, David Stansby
|
|
@@ -44,6 +44,7 @@ Description-Content-Type: text/markdown
|
|
|
44
44
|
License-File: LICENSE.md
|
|
45
45
|
Requires-Dist: dask[array]
|
|
46
46
|
Requires-Dist: gcsfs>2023
|
|
47
|
+
Requires-Dist: networkx>=3
|
|
47
48
|
Requires-Dist: pandas>=2
|
|
48
49
|
Requires-Dist: pydantic>=2
|
|
49
50
|
Requires-Dist: simpleitk
|
|
@@ -56,6 +57,7 @@ Requires-Dist: pre-commit; extra == "dev"
|
|
|
56
57
|
Requires-Dist: ruff; extra == "dev"
|
|
57
58
|
Requires-Dist: jupyterlab; extra == "dev"
|
|
58
59
|
Requires-Dist: jupytext; extra == "dev"
|
|
60
|
+
Requires-Dist: types-networkx; extra == "dev"
|
|
59
61
|
Requires-Dist: pandas-stubs; extra == "dev"
|
|
60
62
|
Requires-Dist: datamodel-code-generator; extra == "dev"
|
|
61
63
|
Provides-Extra: docs
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
hoa_tools/__init__.py,sha256=wc7Yn5CXR3hxr2JyV3eEyCx3p8UZdknXDFJPSthKE_g,87
|
|
2
2
|
hoa_tools/_n5.py,sha256=NGDJBbuyp1scGZ9fjuH7QqAQBpax9nxg2MhwhnV698M,310
|
|
3
|
-
hoa_tools/_version.py,sha256=
|
|
4
|
-
hoa_tools/dataset.py,sha256=
|
|
3
|
+
hoa_tools/_version.py,sha256=rXTOeD0YpRo_kJ2LqUiMnTKEFf43sO_PBvJHDh0SQUA,511
|
|
4
|
+
hoa_tools/dataset.py,sha256=0pIuht5wePO0OXxRhj8ylgncf9PcwsfJJsl5uYXLcNo,9604
|
|
5
5
|
hoa_tools/inventory.py,sha256=44IbE1eLFTetAeCadpBFYXXIwcX5fagq76zSMLWBOmE,613
|
|
6
6
|
hoa_tools/metadata.py,sha256=HGdhjoaUZ2oW9EguO7iuoSU22XLPvPZyIUPvvjoNtbE,22851
|
|
7
7
|
hoa_tools/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
hoa_tools/registration.py,sha256=
|
|
8
|
+
hoa_tools/registration.py,sha256=BXxJYMHh6pngwTnjcx7phryWb_b0LHsXxsOvUk_es7k,3481
|
|
9
9
|
hoa_tools/types.py,sha256=X8GzZXknwgmtTLWR2d_JxEfoavXAQ1zVrf8BaNdevSw,1452
|
|
10
10
|
hoa_tools/voi.py,sha256=t6XAPMpS70W5OphWr3U4j8eXMVElR1OuuzJCoDLs7zc,7868
|
|
11
11
|
hoa_tools/data/metadata/metadata/A186_lung_right_VOI-3_4.26um_bm18.json,sha256=XsMNYpnxvwqUt0h56gfhoXW5XCgBOXdiWzaIxJ_qov8,7550
|
|
@@ -191,8 +191,8 @@ hoa_tools/data/metadata/metadata/S-20-29_lung_left_VOI-02_6.5um_bm05.json,sha256
|
|
|
191
191
|
hoa_tools/data/metadata/metadata/S-20-29_lung_left_VOI-04_6.5um_bm05.json,sha256=BncVFzcPaqrGiBWSEo46L_xbkr-od21Vr7j4XqZUEE8,6116
|
|
192
192
|
hoa_tools/data/metadata/metadata/S-20-29_lung_left_VOI-05_6.5um_bm05.json,sha256=iseb551Vq9B-sHCYWprmbso4XXeb-o2-bFsMlyTyjE8,6118
|
|
193
193
|
hoa_tools/data/metadata/metadata/S-20-29_lung_left_complete-organ_25.31um_bm05.json,sha256=sjNcr9XX7aDDjFMf8yScq4CU53mudSwsExZV7pqXBxQ,5875
|
|
194
|
-
hoa_tools-1.0.
|
|
195
|
-
hoa_tools-1.0.
|
|
196
|
-
hoa_tools-1.0.
|
|
197
|
-
hoa_tools-1.0.
|
|
198
|
-
hoa_tools-1.0.
|
|
194
|
+
hoa_tools-1.0.4.dist-info/licenses/LICENSE.md,sha256=CU-KGODbkoeDUXYPeLgpicDrFTffLQECao-wTKJrXFU,1480
|
|
195
|
+
hoa_tools-1.0.4.dist-info/METADATA,sha256=YhOFzXOVcCBMfeJRyphYn7mCHJN0EJOWsQ7zDMb4CjA,5136
|
|
196
|
+
hoa_tools-1.0.4.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
|
197
|
+
hoa_tools-1.0.4.dist-info/top_level.txt,sha256=NkWbNX-2byZN6hcVyowOVv0aiRNdH0uXpOkA0SFHDgY,10
|
|
198
|
+
hoa_tools-1.0.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|