Skip to content

VTT -> PyTheraTwin : Web UI, code restructure, better comments + doctoring, general cleanup, dosimetry batch system, CPU profiler#20

Open
peteryazdi wants to merge 38 commits into
mainfrom
dev
Open

VTT -> PyTheraTwin : Web UI, code restructure, better comments + doctoring, general cleanup, dosimetry batch system, CPU profiler#20
peteryazdi wants to merge 38 commits into
mainfrom
dev

Conversation

@peteryazdi
Copy link
Copy Markdown
Collaborator

added/adjusted:

  • changed all VTT to PyTheraTwin
  • web ui with run_server.py
  • safe guard to ensure config and ct are correct before run, plus a dedicated safe guard in web ui
  • more organized json files for paths, config, isotopes, etc
  • src has more dir for cleaner system
  • readme updated
  • cleaned docstrings, comments, general labelling of variables, etc
  • built a script for general use
  • have a CPU profiler
  • stages can all now be on or off (either web ui buttons or CLI flags)
  • dosimetry does batches with its uncertainty outputs for faster simulation
  • synthetic lesions now uses tumor_1,tumor_2, or tumor_rest from PBPK PyCNO
  • using all of total seg tasks now, built a grouping system that works best with PBPK and having parent labels (ie. kidney_right + kidney_left -> kidney), also dedicated own safe guard, dedicated in pipeline_roi_naming_map.json
  • built a fingerprint script to help with reruns!
  • built a util dir in src for repeated functions
  • got rid of TOM stuff for now
  • user can set now xy dim and z dim spacing in config for resizing the input CT ( faster run but lower res)
  • ran through Claude and Chat AI to clean code, fix any logical errors, etc!

peteryazdi and others added 8 commits May 14, 2026 14:13
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Web UI implementation, fixed alot of bugs, computational performance profiler
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR renames and restructures the pipeline into PyTheraTwin, introducing a web UI launcher, new shared utilities, and a persistent rerun-safety / provenance system so cached outputs can be reused only when CT + config + upstream dependencies still match.

Changes:

  • Adds a web UI server entrypoint (run_server.py) and new developer-controlled option/path JSONs for the UI + runtime config injection.
  • Refactors pipeline stages and shared utilities (segmentation/ROI unification, PBPK TACs, SIMIND/OpenGATE helpers, NIfTI/DICOM utilities).
  • Introduces persistent rerun metadata, file fingerprinting, and optional per-stage CPU/RAM profiling.

Reviewed changes

Copilot reviewed 39 out of 44 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/utils/tac_utils.py Adds shared PBPK/TAC helpers (VOI-name resolution + cumulated activity integration).
src/utils/simind_runtime_utils.py Adds SIMIND runtime helpers (env, templates, calibration, projection aggregation).
src/utils/simind_projection_utils.py Adds SIMIND projection/header I/O helpers for post-processing.
src/utils/resize_utils.py Centralizes CT/seg downsampling grid resolution logic for SIMIND/OpenGATE.
src/utils/opengate_utils.py Adds SimpleITK/OpenGATE resampling and HU-table discovery helpers.
src/utils/nifti_utils.py Adds shared NIfTI load/save + axis/spacing helpers (nibabel + SimpleITK).
src/utils/lesion_utils.py Adds geometry/sampling utilities for synthetic lesion placement.
src/utils/label_utils.py Adds canonical ROI/PBPK metadata loaders and ROI→VOI mapping from the new ROI map.
src/utils/dicom_utils.py Adds optional DICOM height/weight extraction helper.
src/utils/body_mask_utils.py Adds shared “body outline” masking for post-processing stages.
src/tests/validate_ct.py Adds preflight CT path validation + batch CT discovery helpers.
src/stages/segmentation_stage.py Refactors segmentation to be data-driven from the new ROI map; adds rerun-guard metadata and overlap-resolution logging.
src/stages/pbpk_tac_stage.py Refactors PBPK stage to use ROI-map-driven observables/VOIs + isotope config JSON; adds rerun-guard metadata and optional DICOM HW extraction.
src/stages/dosemap_postprocess_stage.py Refactors dose post-processing to use shared TAC helpers, apply body masking, record per-ROI contributions, and add rerun-guard metadata.
src/io/stage_metadata.py Introduces persistent stage-metadata helpers used by rerun guards.
src/io/runtime_config.py Adds runtime config loading + injection + validation helpers to keep main.py simpler.
src/io/rerun_snapshots.py Adds per-stage config snapshot builders for rerun compatibility checks.
src/io/rerun_guard.py Adds shared rerun-safety checks with fingerprint comparisons and conflict errors.
src/io/rerun_fingerprints.py Adds SHA256 fingerprinting for files/dirs plus JSON normalization/digest helpers.
src/io/profiler.py Adds optional per-stage CPU/RAM sampling profiler (psutil-based).
src/io/pipeline_logging.py Centralizes terminal/log reporting (banners, summaries, stage completion logging).
src/io/context.py Updates the shared Context structure to include CT identity + stage skip state + reorganized fields.
src/io/config_paths.py Adds pipeline path injection/stripping from src/data/pipeline_paths.json.
src/data/tdt_map.json Removes legacy TDT label map JSON.
src/data/pipeline_paths.json Adds developer-controlled paths and per-phase/stage naming defaults.
src/data/pipeline_options.json Adds developer-controlled dropdown option lists for the web UI (ROIs, collimators, recon params, etc.).
src/data/isotope_config.json Adds isotope half-life/attenuation/nuclear config shared across stages.
run_server.py Adds web UI launcher that installs deps if missing, manages port conflicts, and runs uvicorn.
README.md Updates documentation for PyTheraTwin, new UI/CLI workflows, outputs, and ROI configuration files.
environment.yml Renames conda env and adds psutil for profiling.
config_template.json Replaces/updates config template to match new stage keys/fields and ROI conventions.
.gitignore Updates ignored outputs/temp files for the renamed pipeline and web UI artifacts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +119 to +133
cmd = (
f"{simind_exe} jaszak calib"
f"/fi:{isotope}"
f"/cc:{collimator}"
"/29:1"
"/15:5"
"/fa:11"
"/fa:15"
"/fa:14"
)
result = subprocess.run(
cmd,
shell=True,
cwd=output_dir,
stdout=subprocess.DEVNULL,
Comment on lines +71 to +75
def read_sensitivity_from_calibration_file(calibration_file: str) -> float:
"""Read sensitivity (counts/s/MBq) from SIMIND ``calib.res``."""
with open(calibration_file, "r", encoding="utf-8") as fh:
lines = fh.readlines()
return float(lines[70].strip().split(":")[-1].strip().split()[0])
Comment thread src/utils/dicom_utils.py
Comment on lines +36 to +41
candidates = []
try:
for fp in sorted(Path(dicom_dir).rglob("*")):
if fp.is_file():
candidates.append(str(fp))
except Exception:
Comment thread src/utils/resize_utils.py
Comment on lines +59 to +67
if xyz_spacing_mm is None:
return None

sx, sy, sz = int(current_size_xyz[0]), int(current_size_xyz[1]), int(current_size_xyz[2])
spx, spy, spz = float(current_spacing_xyz_mm[0]), float(current_spacing_xyz_mm[1]), float(current_spacing_xyz_mm[2])

target_spx = float(xyz_spacing_mm[0])
target_spy = float(xyz_spacing_mm[1])
target_spz = float(xyz_spacing_mm[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants