Commit ·
5d49e4f
1
Parent(s): 0fde458
Remove the last reconstruction script
Browse filestue-cardiac/reconstruct.py was the only one of its kind left in the corpus.
The reconstruction scripts live in the OpenH-RF repo, next to the pipelines
they run; the corpus keeps the data cards and recipes.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
- tue-cardiac/reconstruct.py +0 -104
tue-cardiac/reconstruct.py
DELETED
|
@@ -1,104 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""Reconstruct one track/frame from a TU/e Cardiac multi-track zea file."""
|
| 3 |
-
|
| 4 |
-
from __future__ import annotations
|
| 5 |
-
|
| 6 |
-
import os
|
| 7 |
-
|
| 8 |
-
os.environ.setdefault("KERAS_BACKEND", "jax")
|
| 9 |
-
os.environ.setdefault("MPLBACKEND", "Agg")
|
| 10 |
-
|
| 11 |
-
import argparse
|
| 12 |
-
from pathlib import Path
|
| 13 |
-
|
| 14 |
-
import matplotlib.pyplot as plt
|
| 15 |
-
import numpy as np
|
| 16 |
-
import zea
|
| 17 |
-
from zea import Config, File, Pipeline
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
HERE = Path(__file__).resolve().parent
|
| 21 |
-
PIPELINE_FOR_TRACK = {
|
| 22 |
-
"focused_fund": "pipeline.yaml",
|
| 23 |
-
"focused_harm": "pipeline_harmonic.yaml",
|
| 24 |
-
"wide_fund": "pipeline.yaml",
|
| 25 |
-
"wide_harm": "pipeline_harmonic.yaml",
|
| 26 |
-
"planewave": "pipeline.yaml",
|
| 27 |
-
"diverging": "pipeline.yaml",
|
| 28 |
-
"hadamard": "pipeline_hadamard.yaml",
|
| 29 |
-
"random": "pipeline_random.yaml",
|
| 30 |
-
}
|
| 31 |
-
TRACKS = tuple(PIPELINE_FOR_TRACK)
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
def main() -> int:
|
| 35 |
-
parser = argparse.ArgumentParser(description=__doc__)
|
| 36 |
-
parser.add_argument("zea_file", type=Path)
|
| 37 |
-
parser.add_argument("--track", required=True, choices=TRACKS)
|
| 38 |
-
parser.add_argument("--frame", type=int, default=0)
|
| 39 |
-
parser.add_argument("--pipeline", type=Path, default=None)
|
| 40 |
-
parser.add_argument("--output", type=Path, default=None)
|
| 41 |
-
parser.add_argument("--device", default=None, help="e.g. cpu, cuda:0, auto:1")
|
| 42 |
-
args = parser.parse_args()
|
| 43 |
-
|
| 44 |
-
pipeline_path = args.pipeline or HERE / "pipelines" / PIPELINE_FOR_TRACK[args.track]
|
| 45 |
-
output_path = args.output or HERE / "reference" / (
|
| 46 |
-
f"{args.zea_file.stem}_{args.track}_frame-{args.frame:03d}.png"
|
| 47 |
-
)
|
| 48 |
-
output_path.parent.mkdir(parents=True, exist_ok=True)
|
| 49 |
-
|
| 50 |
-
zea.init_device(device=args.device, verbose=False)
|
| 51 |
-
config = Config.from_path(str(pipeline_path))
|
| 52 |
-
pipeline = Pipeline.from_config(config)
|
| 53 |
-
|
| 54 |
-
with File(str(args.zea_file)) as handle:
|
| 55 |
-
labels = list(handle.track_labels)
|
| 56 |
-
if args.track not in labels:
|
| 57 |
-
raise ValueError(f"track {args.track!r} not found; available tracks: {labels}")
|
| 58 |
-
track = handle.tracks[labels.index(args.track)]
|
| 59 |
-
n_frames = int(track.data.raw_data.shape[0])
|
| 60 |
-
if not 0 <= args.frame < n_frames:
|
| 61 |
-
raise ValueError(f"frame {args.frame} outside 0..{n_frames - 1}")
|
| 62 |
-
parameters = track.load_parameters(**config.parameters)
|
| 63 |
-
raw = track.data.raw_data[args.frame : args.frame + 1]
|
| 64 |
-
|
| 65 |
-
inputs = pipeline.prepare_parameters(parameters)
|
| 66 |
-
outputs = pipeline(**{pipeline.key: raw}, **inputs)
|
| 67 |
-
image = np.asarray(outputs[pipeline.output_key])[0]
|
| 68 |
-
dynamic_range = tuple(config.parameters.dynamic_range)
|
| 69 |
-
|
| 70 |
-
# Scan conversion leaves pixels outside the polar sector undefined. Render
|
| 71 |
-
# those expected out-of-sector values at the display floor.
|
| 72 |
-
image = np.nan_to_num(
|
| 73 |
-
image,
|
| 74 |
-
nan=dynamic_range[0],
|
| 75 |
-
neginf=dynamic_range[0],
|
| 76 |
-
posinf=dynamic_range[1],
|
| 77 |
-
)
|
| 78 |
-
|
| 79 |
-
extent = getattr(parameters, "extent_imshow", None)
|
| 80 |
-
if extent is not None:
|
| 81 |
-
extent = np.asarray(extent) * 1e3
|
| 82 |
-
zea.visualize.set_mpl_style()
|
| 83 |
-
figure, axis = plt.subplots(figsize=(6, 6))
|
| 84 |
-
rendered = axis.imshow(
|
| 85 |
-
image,
|
| 86 |
-
extent=extent,
|
| 87 |
-
cmap="gray",
|
| 88 |
-
vmin=dynamic_range[0],
|
| 89 |
-
vmax=dynamic_range[1],
|
| 90 |
-
aspect="auto",
|
| 91 |
-
)
|
| 92 |
-
axis.set_xlabel("Lateral (mm)")
|
| 93 |
-
axis.set_ylabel("Depth (mm)")
|
| 94 |
-
axis.set_title(f"{args.zea_file.stem} — {args.track} — frame {args.frame}")
|
| 95 |
-
figure.colorbar(rendered, ax=axis, label="dB")
|
| 96 |
-
figure.tight_layout()
|
| 97 |
-
figure.savefig(output_path, dpi=150, bbox_inches="tight", metadata={})
|
| 98 |
-
plt.close(figure)
|
| 99 |
-
print(f"saved {output_path}")
|
| 100 |
-
return 0
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
if __name__ == "__main__":
|
| 104 |
-
raise SystemExit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|