Skip to content

Commit 4ea0827

Browse files
committed
Add method for adding new atlases
1 parent 40136f0 commit 4ea0827

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/neuromaps_prime/graph/core.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,33 @@ def add_transform(
127127
weight=transform.weight,
128128
)
129129

130+
def add_atlas(self, atlas: SurfaceAtlas | VolumeAtlas) -> None:
131+
"""Regiser an atlas to a graph node and a cache entry.
132+
133+
Args:
134+
resource: SurfaceAtlas or VolumeAtlas to add to existing node.
135+
136+
Raises:
137+
TypeError: If atlas is not SurfaceAtlas or VolumeAtlas.
138+
ValueError: If atlas space is not present in the graph.
139+
"""
140+
if not isinstance(atlas, (SurfaceAtlas, VolumeAtlas)):
141+
raise TypeError(f"Unsupported atlas type: {type(atlas)}")
142+
143+
node_name = atlas.space
144+
if node_name not in self.nodes:
145+
raise ValueError(
146+
f"Node '{node_name}' not found. Available nodes: {sorted(self.nodes)}"
147+
)
148+
149+
node_data = self.nodes[node_name]["data"]
150+
if isinstance(atlas, SurfaceAtlas):
151+
node_data.surfaces.append(atlas)
152+
self._cache.add_surface_atlas(atlas)
153+
else:
154+
node_data.volumes.append(atlas)
155+
self._cache.add_volume_atlas(atlas)
156+
130157
# Validation
131158
def validate_spaces(self, source: str, target: str) -> None:
132159
"""Assert that both source and target exist as nodes in the graph.
@@ -323,7 +350,6 @@ def search_surface_transforms(
323350
)
324351

325352
# Density helpers
326-
327353
def find_common_density(self, mid_space: str, target_space: str) -> str:
328354
"""Find the highest density shared between mid_space and target_space.
329355

0 commit comments

Comments
 (0)