Skip to content

Commit 2485213

Browse files
committed
add support for directly give npz file as arg
1 parent 05f94e4 commit 2485213

1 file changed

Lines changed: 42 additions & 11 deletions

File tree

src/cardiotensor/scripts/visualize_streamlines.py

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55
CLI tool to visualize cardiac streamlines from a .npz file using FURY.
66
Supports coloring by helix angle or elevation, custom colormaps,
77
and optional screenshot export.
8+
9+
Now accepts either:
10+
1) a .conf file (as before, reads OUTPUT_PATH/streamlines.npz), or
11+
2) a direct path to streamlines .npz
812
"""
913

1014
import argparse
15+
import sys
1116
from pathlib import Path
1217

1318
import matplotlib.pyplot as plt
@@ -20,18 +25,22 @@
2025
def script():
2126
parser = argparse.ArgumentParser(
2227
description=(
23-
"Visualize cardiac streamlines from a .npz file.\n"
24-
"Streamlines are typically generated by Cardiotensor.\n"
25-
"You can color them by helix angle (HA) or elevation angle,\n"
26-
"adjust rendering style, crop regions, and save screenshots."
28+
"Visualize cardiac streamlines.\n"
29+
"Pass either a .conf file (will use OUTPUT_PATH/streamlines.npz) "
30+
"or pass a streamlines .npz file directly.\n"
31+
"You can color by helix angle (HA) or elevation angle, adjust rendering, crop, "
32+
"and save screenshots."
2733
),
2834
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
2935
)
3036

3137
parser.add_argument(
32-
"conf_file",
38+
"input_path",
3339
type=Path,
34-
help="Path to configuration file (.conf) containing OUTPUT_PATH with streamlines.npz.",
40+
help=(
41+
"Path to either a configuration file (.conf) containing OUTPUT_PATH, "
42+
"or directly to a streamlines .npz file."
43+
),
3544
)
3645
parser.add_argument(
3746
"--color-by",
@@ -142,10 +151,32 @@ def script():
142151
)
143152
chosen_cmap = helix_angle_cmap
144153

145-
# Read conf file only in CLI
146-
params = read_conf_file(args.conf_file)
147-
output_dir = Path(params.get("OUTPUT_PATH", "./output"))
148-
streamlines_file = output_dir / "streamlines.npz"
154+
# Resolve streamlines file depending on input type
155+
if not args.input_path.exists():
156+
print(f"❌ Input path not found: {args.input_path}")
157+
sys.exit(1)
158+
159+
suffix = args.input_path.suffix.lower()
160+
161+
if suffix == ".conf":
162+
# Read conf file and construct path to streamlines.npz
163+
params = read_conf_file(args.input_path)
164+
output_dir = Path(params.get("OUTPUT_PATH", "./output"))
165+
streamlines_file = output_dir / "streamlines.npz"
166+
if not streamlines_file.exists():
167+
print(
168+
f"❌ streamlines.npz not found at: {streamlines_file}\n"
169+
f"(Derived from OUTPUT_PATH in {args.input_path})"
170+
)
171+
sys.exit(1)
172+
elif suffix == ".npz":
173+
# Direct .npz provided
174+
streamlines_file = args.input_path
175+
else:
176+
print(
177+
"❌ Unsupported input. Provide either a .conf file or a streamlines .npz file."
178+
)
179+
sys.exit(1)
149180

150181
# Compute crop bounds if provided
151182
crop_bounds = None
@@ -156,7 +187,7 @@ def script():
156187
tuple(args.crop_z or [-float("inf"), float("inf")]),
157188
)
158189

159-
# Call Python function
190+
# Call visualization
160191
visualize_streamlines(
161192
streamlines_file=streamlines_file,
162193
color_by=args.color_by,

0 commit comments

Comments
 (0)