1- from typing import Any
1+ import logging
22
33import matplotlib .pyplot as plt
44import networkx as nx
55from ome_zarr_models ._utils import TransformGraph
66from ome_zarr_models ._v06 .coordinate_transforms import (
77 CoordinateSystemIdentifier ,
8- Transform ,
98 Sequence ,
9+ Transform ,
1010)
11- from pydantic import ValidationError
12- import logging
1311from ome_zarr_models ._v06 .coordinate_transforms import (
1412 Sequence as SequenceTransformation ,
1513)
14+ from pydantic import ValidationError
1615
1716
1817def transform_graph_to_networkx (tgraph : TransformGraph ) -> nx .DiGraph :
@@ -125,9 +124,7 @@ def _get_name_of_subgraph(
125124 f"Ambiguous coordinate system name '{ cs_identifier } ' found in both root and subgraph '{ path_name } '. Use full identifier."
126125 )
127126 if cs_identifier not in nodes and cs_path_name not in nodes :
128- raise ValueError (
129- f"Coordinate system '{ cs_identifier } ' not found in graph nodes."
130- )
127+ raise ValueError (f"Coordinate system '{ cs_identifier } ' not found in graph nodes." )
131128 if cs_path_name in nodes :
132129 return cs_path_name
133130 return cs_identifier
@@ -159,9 +156,7 @@ def _add_transform_and_inverse_transformation_edges(
159156 pass
160157
161158
162- def draw_graph (
163- g : nx .DiGraph , figsize : tuple [int , int ] = (12 , 8 ), with_edge_labels : bool = True
164- ) -> None :
159+ def draw_graph (g : nx .DiGraph , figsize : tuple [int , int ] = (12 , 8 ), with_edge_labels : bool = True ) -> None :
165160 """
166161 Draw a NetworkX graph showing all nodes and edges with their names.
167162
@@ -219,9 +214,7 @@ def draw_graph(
219214 plt .show ()
220215
221216
222- def get_relative_path (
223- graph : nx .DiGraph , source_coordinate_system : str , target_coordinate_system : str
224- ) -> list [str ]:
217+ def get_relative_path (graph : nx .DiGraph , source_coordinate_system : str , target_coordinate_system : str ) -> list [str ]:
225218 cost_key = "cost"
226219 """
227220 Get the relative path from one node to another in the transformation graph.
@@ -270,14 +263,10 @@ def create_sequence_transformation_from_graph_walk(
270263 edge_transformation = graph .get_edge_data (source , target )["transformation" ]
271264 transformations .append (edge_transformation )
272265
273- return Sequence (
274- input = walk [0 ], output = walk [- 1 ], transformations = tuple (transformations )
275- )
266+ return Sequence (input = walk [0 ], output = walk [- 1 ], transformations = tuple (transformations ))
276267
277268
278- def get_node (
279- path : str | None = None , name : str | None = None
280- ) -> str | CoordinateSystemIdentifier :
269+ def get_node (path : str | None = None , name : str | None = None ) -> str | CoordinateSystemIdentifier :
281270 if path is None and name is None :
282271 raise ValueError ("Both path and name of the coordinate system cannot be None" )
283272 if path is None :
@@ -287,17 +276,13 @@ def get_node(
287276 return CoordinateSystemIdentifier (path = path , name = name )
288277
289278
290- def find_walks_in_graph (
291- graph , src_path , src_name , tgt_path , tgt_name
292- ) -> list [str | CoordinateSystemIdentifier ]:
279+ def find_walks_in_graph (graph , src_path , src_name , tgt_path , tgt_name ) -> list [str | CoordinateSystemIdentifier ]:
293280 src_node = get_node (src_path , src_name )
294281 tgt_node = get_node (tgt_path , tgt_name )
295282
296283 graph_walk = list (nx .all_shortest_paths (graph , src_node , tgt_node ))
297284 if not graph_walk :
298- raise ValueError (
299- f"No path found from { src_node } to { tgt_node } in the transformation graph."
300- )
285+ raise ValueError (f"No path found from { src_node } to { tgt_node } in the transformation graph." )
301286 if len (graph_walk ) > 1 :
302287 logging .warning (
303288 f"Multiple paths found from { src_node } to { tgt_node } in the transformation graph. Using the first one."
0 commit comments