pyRadPlan 0.2.2__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyradplan-0.2.2/pyRadPlan.egg-info → pyradplan-0.2.4}/PKG-INFO +4 -3
- {pyradplan-0.2.2 → pyradplan-0.2.4}/examples/import_matrad_patient.py +1 -0
- pyradplan-0.2.4/examples/proton_let_optimization.py +61 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/core/_grids.py +8 -8
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/core/np2sitk.py +27 -11
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/core/resample.py +9 -4
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/ct/_ct.py +20 -10
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dij/_compose_beam_dijs.py +1 -1
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dij/_dij.py +49 -10
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/engines/_base.py +11 -6
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/engines/_base_pencilbeam.py +107 -28
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +7 -3
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/engines/_svdpb.py +1 -1
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/problems/_optiprob.py +2 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/plan/_plans.py +13 -42
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/quantities/__init__.py +4 -3
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/quantities/_base.py +5 -11
- pyradplan-0.2.4/pyRadPlan/quantities/_let_x_dose.py +29 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/raytracer/_base.py +24 -12
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/raytracer/_perf.py +6 -6
- pyradplan-0.2.4/pyRadPlan/raytracer/_siddon.py +427 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/scenarios/__init__.py +29 -38
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/scenarios/_base.py +159 -168
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/scenarios/_nominal.py +22 -21
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/_beam.py +5 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/_ray.py +6 -24
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/_steeringinformation.py +33 -0
- pyradplan-0.2.4/pyRadPlan/visualization/_plot_slice.py +184 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4/pyRadPlan.egg-info}/PKG-INFO +4 -3
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan.egg-info/SOURCES.txt +10 -2
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan.egg-info/requires.txt +1 -1
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyproject.toml +2 -2
- pyradplan-0.2.4/test/conftest.py +43 -0
- pyradplan-0.2.4/test/core/test_datamodel.py +49 -0
- pyradplan-0.2.4/test/data/test_validate_test_data.py +127 -0
- pyradplan-0.2.4/test/dose/conftest.py +78 -0
- pyradplan-0.2.4/test/dose/test_dose_engine_base.py +114 -0
- pyradplan-0.2.4/test/dose/test_factory.py +31 -0
- pyradplan-0.2.4/test/dose/test_hongpb.py +93 -0
- pyradplan-0.2.4/test/dose/test_svdpb.py +32 -0
- pyradplan-0.2.4/test/quantities/test_let_dose_quantity.py +108 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/stf/test_stf.py +59 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_plan.py +12 -4
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_scenarios.py +14 -7
- pyradplan-0.2.4/test/visualization/test_plot_slice.py +156 -0
- pyradplan-0.2.2/pyRadPlan/raytracer/_siddon.py +0 -396
- pyradplan-0.2.2/pyRadPlan/visualization/_plot_slice.py +0 -105
- pyradplan-0.2.2/test/conftest.py +0 -15
- pyradplan-0.2.2/test/dose/test_dose_particle.py +0 -231
- pyradplan-0.2.2/test/dose/test_dose_photon.py +0 -20
- pyradplan-0.2.2/test/visualization/test_plot_slice.py +0 -85
- {pyradplan-0.2.2 → pyradplan-0.2.4}/LICENSE +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/README.md +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/docs/conf.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/examples/carbon_pencilbeam.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/examples/helium_pencilbeam.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/examples/photon_pencilbeam.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/examples/proton_pencilbeam.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/core/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/core/_exceptions.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/core/datamodel.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/cst/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/cst/_cst.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/cst/_voi.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/ct/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/ct/_hlut.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/machines/photons_Generic.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/phantoms/TG119.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/stf/matRad_stf.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/stf/matRad_stf_onebeam.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dij/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/_calc_dose.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/engines/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/engines/_factory.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/dose/engines/_hongpb.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/geometry/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/geometry/lps.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/io/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/io/_matlab_file_handler.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/io/_patient_loader.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/io/matfile.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/machines/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/machines/_base.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/machines/_ions.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/machines/_load.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/machines/_photons.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/machines/_validate.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/matRad/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/matRad/_engine.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/matRad/_matlab.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/matRad/_octave.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/_fluence_optimization.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_eud.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_factory.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_max_dvh.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_mean.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_min_dvh.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_objective.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_squared_dev.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_squared_over.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_squared_under.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/objectives/_std.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/problems/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/problems/_factory.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/problems/_nonlin_fluence.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/problems/_simple_least_squares.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/solvers/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/solvers/_base_solvers.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/solvers/_factory.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/solvers/_ipopt.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/plan/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/quantities/_dose.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/raytracer/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/_beamlet.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/_exceptions.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/_generate_stf.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/_rangeshifter.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/generators/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/generators/_base.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/generators/_externalbeam.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/generators/_factory.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/generators/_ions.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/stf/generators/_photons.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/util/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/util/helpers.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan/visualization/__init__.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan.egg-info/dependency_links.txt +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/pyRadPlan.egg-info/top_level.txt +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/setup.cfg +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/core/test_coordinates.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/core/test_np2sitk.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/core/test_resample.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/cst/conftest.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/cst/test_VOI.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/cst/test_cst.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/ct/test_ct.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/ct/test_hlut.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/geometry/test_lps.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/optimization/test_fluence_optiprob.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/optimization/test_ipopt_solver.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/optimization/test_objectives.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/optimization/test_problem_factory.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/optimization/test_scipy_solver.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/optimization/test_solver_factory.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/quantities/test_dose_quantity.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/stf/test_beamlet.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/stf/test_stf_gen.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_dij.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_fileHandling.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_grid.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_helpers.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_machine_model.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_matlabEngine.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_octaveEngine.py +0 -0
- {pyradplan-0.2.2 → pyradplan-0.2.4}/test/test_raytracersiddon.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pyRadPlan
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A python interface and reimplementation to matRad
|
|
5
5
|
Author-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>, Goran Stanic <goran.stanic@dkfz-heidelberg.de>, Tim Ortkamp <tim.ortkamp@kit.edu>, Tobias Becher <t.becher@dkfz-heidelberg.de>, Lina Bucher <lina.bucher@dkfz-heidelberg.de>, Florian Leininger <florian.leininger@dkfz-heidelberg.de>, Antonios Kontopoulos <antonios.kontopoulos@dkfz-heidelberg.de>
|
|
6
6
|
Maintainer-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>, Goran Stanic <goran.stanic@dkfz-heidelberg.de>, Tim Ortkamp <tim.ortkamp@kit.edu>, Tobias Becher <t.becher@dkfz-heidelberg.de>
|
|
@@ -19,7 +19,7 @@ Requires-Dist: regex>=2024.5.15
|
|
|
19
19
|
Requires-Dist: pydicom>=2.4.4
|
|
20
20
|
Requires-Dist: numba>=0.60.0
|
|
21
21
|
Requires-Dist: matplotlib>=3.9.2
|
|
22
|
-
Requires-Dist: pydantic
|
|
22
|
+
Requires-Dist: pydantic<2.11,>=2.10
|
|
23
23
|
Requires-Dist: numpydantic>=1.6.0
|
|
24
24
|
Requires-Dist: SimpleITK>=2.4.0
|
|
25
25
|
Requires-Dist: tqdm>=4.0.0
|
|
@@ -41,6 +41,7 @@ Requires-Dist: pydata-sphinx-theme; extra == "dev"
|
|
|
41
41
|
Requires-Dist: sphinx-design; extra == "dev"
|
|
42
42
|
Requires-Dist: autodoc_pydantic; extra == "dev"
|
|
43
43
|
Requires-Dist: sphinx-autodoc-typehints; extra == "dev"
|
|
44
|
+
Dynamic: license-file
|
|
44
45
|
|
|
45
46
|
# pyRadPlan
|
|
46
47
|
[](https://github.com/e0404/pyRadPlan/actions/workflows/tests.yml)
|
|
@@ -73,6 +73,7 @@ stf = stfgen.generate(ct, cst)
|
|
|
73
73
|
# For that, we use a default HU->rSP table to convert our CT to water-equivalent thickness and then
|
|
74
74
|
# call a voxel-wise RayTracing algorithm (proposed by Siddon) to calculate the radiological depth.
|
|
75
75
|
rt = RayTracerSiddon([ct.compute_wet(default_hlut())])
|
|
76
|
+
rt.debug_core_performance = True
|
|
76
77
|
rad_depth_cubes = rt.trace_cubes(stf[0])
|
|
77
78
|
|
|
78
79
|
# We could write the image if we want, but we don't do this by default.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
from pyRadPlan import (
|
|
6
|
+
IonPlan,
|
|
7
|
+
generate_stf,
|
|
8
|
+
calc_dose_influence,
|
|
9
|
+
fluence_optimization,
|
|
10
|
+
plot_slice,
|
|
11
|
+
load_tg119,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
from pyRadPlan.optimization.objectives import SquaredDeviation, SquaredOverdosing, MeanDose
|
|
15
|
+
|
|
16
|
+
logging.basicConfig(level=logging.INFO)
|
|
17
|
+
|
|
18
|
+
# Read patient from provided TG119.mat file and validate data
|
|
19
|
+
ct, cst = load_tg119()
|
|
20
|
+
|
|
21
|
+
# Create a plan object
|
|
22
|
+
pln = IonPlan(radiation_mode="protons", machine="Generic")
|
|
23
|
+
pln.prop_opt = {"solver": "scipy"}
|
|
24
|
+
|
|
25
|
+
# Generate Steering Geometry ("stf")
|
|
26
|
+
stf = generate_stf(ct, cst, pln)
|
|
27
|
+
|
|
28
|
+
# Calculate Dose Influence Matrix ("dij")
|
|
29
|
+
dij = calc_dose_influence(ct, cst, stf, pln)
|
|
30
|
+
|
|
31
|
+
# Optimization
|
|
32
|
+
cst.vois[1].objectives = [SquaredDeviation(priority=100.0, d_ref=3.0)] # Target
|
|
33
|
+
cst.vois[0].objectives = [
|
|
34
|
+
SquaredOverdosing(priority=10.0, d_max=1.0),
|
|
35
|
+
SquaredOverdosing(priority=5.0, d_max=1.0, quantity="let_dose"),
|
|
36
|
+
] # OAR
|
|
37
|
+
cst.vois[2].objectives = [
|
|
38
|
+
MeanDose(priority=1.0, d_ref=0.0),
|
|
39
|
+
SquaredOverdosing(priority=10.0, d_max=2.0),
|
|
40
|
+
] # BODY
|
|
41
|
+
fluence = fluence_optimization(ct, cst, stf, dij, pln)
|
|
42
|
+
|
|
43
|
+
# Result
|
|
44
|
+
result = dij.compute_result_ct_grid(fluence)
|
|
45
|
+
|
|
46
|
+
# Choose a slice to visualize
|
|
47
|
+
view_slice = int(np.round(ct.size[2] / 2))
|
|
48
|
+
|
|
49
|
+
# Visualize
|
|
50
|
+
plot_slice(
|
|
51
|
+
ct=ct,
|
|
52
|
+
cst=cst,
|
|
53
|
+
overlay=result["physical_dose"],
|
|
54
|
+
view_slice=view_slice,
|
|
55
|
+
)
|
|
56
|
+
plot_slice(
|
|
57
|
+
ct=ct,
|
|
58
|
+
cst=cst,
|
|
59
|
+
overlay=result["let"],
|
|
60
|
+
view_slice=view_slice,
|
|
61
|
+
)
|
|
@@ -76,9 +76,9 @@ class Grid(PyRadPlanBaseModel):
|
|
|
76
76
|
raise ValueError("resolution must have keys 'x', 'y', 'z'")
|
|
77
77
|
|
|
78
78
|
# Check if all resolution values are positive floats. If not, try to cast them to float
|
|
79
|
-
for
|
|
80
|
-
if
|
|
81
|
-
raise ValueError(f"resolution values must be positive floats, got {
|
|
79
|
+
for _, v in value.items():
|
|
80
|
+
if v <= 0:
|
|
81
|
+
raise ValueError(f"resolution values must be positive floats, got {v}")
|
|
82
82
|
|
|
83
83
|
return value
|
|
84
84
|
|
|
@@ -93,11 +93,12 @@ class Grid(PyRadPlanBaseModel):
|
|
|
93
93
|
# Check if all dimensions values are positive integers. If not, try to cast them to int
|
|
94
94
|
for dim in value:
|
|
95
95
|
try:
|
|
96
|
-
|
|
96
|
+
tmpdim = int(dim)
|
|
97
97
|
except ValueError:
|
|
98
98
|
raise ValueError(f"dimension value could not be casted into int, got {dim}")
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
|
|
100
|
+
if tmpdim <= 0:
|
|
101
|
+
raise ValueError(f"dimension values must be positive integers, got {tmpdim}")
|
|
101
102
|
|
|
102
103
|
return value
|
|
103
104
|
|
|
@@ -162,8 +163,7 @@ class Grid(PyRadPlanBaseModel):
|
|
|
162
163
|
],
|
|
163
164
|
) -> Self:
|
|
164
165
|
"""
|
|
165
|
-
Create a resampled grid covering the original grid in
|
|
166
|
-
resolution.
|
|
166
|
+
Create a resampled grid covering the original grid in new resolution.
|
|
167
167
|
|
|
168
168
|
Parameters
|
|
169
169
|
----------
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
"""
|
|
2
|
-
types.
|
|
3
|
-
"""
|
|
1
|
+
"""Helpers for conversion between numpy and SimpleITK."""
|
|
4
2
|
|
|
5
3
|
from typing import Literal
|
|
6
4
|
import SimpleITK as sitk
|
|
@@ -82,7 +80,10 @@ def linear_indices_to_sitk_mask(
|
|
|
82
80
|
|
|
83
81
|
|
|
84
82
|
def linear_indices_to_grid_coordinates(
|
|
85
|
-
indices: np.ndarray,
|
|
83
|
+
indices: np.ndarray,
|
|
84
|
+
grid: Grid,
|
|
85
|
+
index_type: Literal["numpy", "sitk"] = "numpy",
|
|
86
|
+
dtype: np.dtype = np.float64,
|
|
86
87
|
) -> np.ndarray:
|
|
87
88
|
"""
|
|
88
89
|
Convert linear indices to gridcoordinates.
|
|
@@ -96,6 +97,8 @@ def linear_indices_to_grid_coordinates(
|
|
|
96
97
|
index_type : Literal["numpy", "sitk"], optional
|
|
97
98
|
The ordering of the indices. Can be 'sitk' for Fortran-like index
|
|
98
99
|
ordering or 'numpy' for C-like index ordering. Default is 'numpy'.
|
|
100
|
+
dtype : np.dtype, optional
|
|
101
|
+
The data type of the output coordinates. Default is np.float64.
|
|
99
102
|
|
|
100
103
|
Returns
|
|
101
104
|
-------
|
|
@@ -103,17 +106,25 @@ def linear_indices_to_grid_coordinates(
|
|
|
103
106
|
A 2D numpy array of image coordinates.
|
|
104
107
|
"""
|
|
105
108
|
|
|
109
|
+
# this is a manual reimplementation of np.unravel_index
|
|
110
|
+
# to avoid the overhead of creating a tuple of arrays
|
|
106
111
|
if index_type == "numpy":
|
|
107
|
-
|
|
112
|
+
_, d1, d2 = grid.dimensions[::-1]
|
|
113
|
+
order = [0, 1, 2]
|
|
108
114
|
elif index_type == "sitk":
|
|
109
|
-
|
|
115
|
+
_, d1, d2 = grid.dimensions
|
|
116
|
+
order = [2, 1, 0]
|
|
110
117
|
else:
|
|
111
118
|
raise ValueError("Invalid index type. Must be 'numpy' or 'sitk'.")
|
|
112
119
|
|
|
113
|
-
v = np.
|
|
120
|
+
v = np.empty((3, np.asarray(indices).size), dtype=dtype)
|
|
121
|
+
tmp, v[order[0]] = np.divmod(indices, d2)
|
|
122
|
+
v[order[2]], v[order[1]] = np.divmod(tmp, d1)
|
|
114
123
|
|
|
115
|
-
spacing_diag = np.diag(
|
|
116
|
-
|
|
124
|
+
spacing_diag = np.diag(
|
|
125
|
+
[grid.resolution["x"], grid.resolution["y"], grid.resolution["z"]]
|
|
126
|
+
).astype(dtype)
|
|
127
|
+
origin = grid.origin.astype(dtype)
|
|
117
128
|
|
|
118
129
|
physical_point = origin + np.matmul(np.matmul(grid.direction, spacing_diag), v).T
|
|
119
130
|
|
|
@@ -121,7 +132,10 @@ def linear_indices_to_grid_coordinates(
|
|
|
121
132
|
|
|
122
133
|
|
|
123
134
|
def linear_indices_to_image_coordinates(
|
|
124
|
-
indices: np.ndarray,
|
|
135
|
+
indices: np.ndarray,
|
|
136
|
+
image: sitk.Image,
|
|
137
|
+
index_type: Literal["numpy", "sitk"] = "numpy",
|
|
138
|
+
dtype: np.dtype = np.float64,
|
|
125
139
|
) -> np.ndarray:
|
|
126
140
|
"""
|
|
127
141
|
Convert linear indices to image coordinates.
|
|
@@ -135,6 +149,8 @@ def linear_indices_to_image_coordinates(
|
|
|
135
149
|
index_type : Literal["numpy", "sitk"], optional
|
|
136
150
|
The ordering of the indices. Can be 'sitk' for Fortran-like index
|
|
137
151
|
ordering or 'numpy' for C-like index ordering. Default is 'numpy'.
|
|
152
|
+
dtype : np.dtype, optional
|
|
153
|
+
The data type of the output coordinates. Default is np.float64.
|
|
138
154
|
|
|
139
155
|
Returns
|
|
140
156
|
-------
|
|
@@ -143,4 +159,4 @@ def linear_indices_to_image_coordinates(
|
|
|
143
159
|
"""
|
|
144
160
|
|
|
145
161
|
grid = Grid.from_sitk_image(image)
|
|
146
|
-
return linear_indices_to_grid_coordinates(indices, grid, index_type)
|
|
162
|
+
return linear_indices_to_grid_coordinates(indices, grid, index_type, dtype=dtype)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"""Image / Grid Resampling."""
|
|
2
|
+
|
|
1
3
|
import numpy as np
|
|
2
4
|
import SimpleITK as sitk
|
|
3
5
|
from ._grids import Grid
|
|
@@ -11,8 +13,9 @@ def resample_image(
|
|
|
11
13
|
target_grid: Grid = None,
|
|
12
14
|
) -> sitk.Image: # also accept sitk images and grid points. Can be dealt with with kwargs
|
|
13
15
|
"""
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
Resample an sitk Image.
|
|
17
|
+
|
|
18
|
+
Use target resolution, reference image, dimensions, or Grid as input.
|
|
16
19
|
|
|
17
20
|
Parameters
|
|
18
21
|
----------
|
|
@@ -70,8 +73,10 @@ def resample_numpy_array(
|
|
|
70
73
|
target_grid: Grid = None,
|
|
71
74
|
) -> np.ndarray:
|
|
72
75
|
"""
|
|
73
|
-
|
|
74
|
-
|
|
76
|
+
Resample a numpy grid.
|
|
77
|
+
|
|
78
|
+
Use target resolution, reference image, dimensions, or Grid as input.
|
|
79
|
+
|
|
75
80
|
We convert the numpy array to an sitk.Image, so the dimensions will be
|
|
76
81
|
switched. More exactly,
|
|
77
82
|
the numpy array will be index i,j,k <-> z,y,x, which will converted to
|
|
@@ -91,6 +91,9 @@ class CT(PyRadPlanBaseModel, ABC):
|
|
|
91
91
|
if cube_hu is None:
|
|
92
92
|
raise ValueError("HU cube not present in dictionary.")
|
|
93
93
|
|
|
94
|
+
if isinstance(cube_hu, sitk.Image) and "origin" not in data:
|
|
95
|
+
data["origin"] = cube_hu.GetOrigin()
|
|
96
|
+
|
|
94
97
|
if isinstance(cube_hu, np.ndarray):
|
|
95
98
|
# Now we do check if it is matRad data
|
|
96
99
|
if data.get("cubeDim", None) is not None:
|
|
@@ -133,16 +136,6 @@ class CT(PyRadPlanBaseModel, ABC):
|
|
|
133
136
|
is4d = cube_hu.GetDimension() == 4
|
|
134
137
|
# Now we parse the rest of the data if additional data is available in the dictionary
|
|
135
138
|
|
|
136
|
-
# TODO: Either set up a Grid or check for x/y/z to do the data management
|
|
137
|
-
if "origin" in data:
|
|
138
|
-
data["cube_hu"].SetOrigin(data["origin"])
|
|
139
|
-
|
|
140
|
-
elif all(key in data for key in ("x", "y", "z")):
|
|
141
|
-
origin = np.array([data["x"][0], data["y"][0], data["z"][0]], dtype=float)
|
|
142
|
-
if is4d:
|
|
143
|
-
origin = np.append(origin, [0.0])
|
|
144
|
-
data["cube_hu"].SetOrigin(origin)
|
|
145
|
-
|
|
146
139
|
if "direction" in data:
|
|
147
140
|
data["cube_hu"].SetDirection(data["direction"])
|
|
148
141
|
|
|
@@ -153,6 +146,23 @@ class CT(PyRadPlanBaseModel, ABC):
|
|
|
153
146
|
else:
|
|
154
147
|
cube_hu.SetSpacing([resolution["x"], resolution["y"], resolution["z"]])
|
|
155
148
|
|
|
149
|
+
# TODO: Either set up a Grid or check for x/y/z to do the data management
|
|
150
|
+
if "origin" in data:
|
|
151
|
+
data["cube_hu"].SetOrigin(data["origin"])
|
|
152
|
+
|
|
153
|
+
else:
|
|
154
|
+
data["cube_hu"].SetOrigin(
|
|
155
|
+
-np.array(data["cube_hu"].GetSize())
|
|
156
|
+
/ 2.0
|
|
157
|
+
* np.array(data["cube_hu"].GetSpacing())
|
|
158
|
+
)
|
|
159
|
+
if is4d:
|
|
160
|
+
data["cube_hu"].SetOrigin(np.append(data["cube_hu"].GetOrigin(), [0.0]))
|
|
161
|
+
# elif all(key in data for key in ("x", "y", "z")):
|
|
162
|
+
# origin = np.array([data["x"][0], data["y"][0], data["z"][0]], dtype=float)
|
|
163
|
+
# if is4d:
|
|
164
|
+
# origin = np.append(origin, [0.0])
|
|
165
|
+
# data["cube_hu"].SetOrigin(origin)
|
|
156
166
|
return data
|
|
157
167
|
|
|
158
168
|
@computed_field
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Contains the dij class as a (collection of) influence matrices."""
|
|
2
2
|
|
|
3
|
-
from typing import Any, Union, Annotated, cast
|
|
3
|
+
from typing import Any, Union, Annotated, Optional, cast
|
|
4
4
|
from pydantic import (
|
|
5
5
|
Field,
|
|
6
6
|
field_validator,
|
|
@@ -41,15 +41,17 @@ class Dij(PyRadPlanBaseModel):
|
|
|
41
41
|
ct_grid: Annotated[Grid, Field(default=None)]
|
|
42
42
|
|
|
43
43
|
physical_dose: Annotated[NDArray, Field(default=None)]
|
|
44
|
-
let_dose: Annotated[NDArray, Field(default=None)]
|
|
44
|
+
let_dose: Annotated[NDArray, Field(default=None, alias="mLETDose")]
|
|
45
45
|
alpha_dose: Annotated[NDArray, Field(default=None)]
|
|
46
46
|
sqrt_beta_dose: Annotated[NDArray, Field(default=None)]
|
|
47
47
|
|
|
48
48
|
num_of_beams: Annotated[int, Field(default=None)]
|
|
49
49
|
|
|
50
|
-
bixel_num: Annotated[
|
|
51
|
-
ray_num: Annotated[
|
|
52
|
-
beam_num: Annotated[
|
|
50
|
+
bixel_num: Annotated[NDArray, Field(default=None)]
|
|
51
|
+
ray_num: Annotated[NDArray, Field(default=None)]
|
|
52
|
+
beam_num: Annotated[NDArray, Field(default=None)]
|
|
53
|
+
|
|
54
|
+
rad_depth_cubes: Optional[list[NDArray]] = Field(default=None)
|
|
53
55
|
|
|
54
56
|
@computed_field
|
|
55
57
|
@property
|
|
@@ -62,7 +64,7 @@ class Dij(PyRadPlanBaseModel):
|
|
|
62
64
|
def num_of_voxels(self) -> int:
|
|
63
65
|
"""Number of voxels in the dose influence matrix."""
|
|
64
66
|
return self.physical_dose.flat[0].shape[0]
|
|
65
|
-
|
|
67
|
+
|
|
66
68
|
@computed_field
|
|
67
69
|
@property
|
|
68
70
|
def quantities(self) -> list[str]:
|
|
@@ -109,11 +111,30 @@ class Dij(PyRadPlanBaseModel):
|
|
|
109
111
|
if mat.shape[0] != info.data["dose_grid"].num_voxels:
|
|
110
112
|
raise ValueError(f"{info.field_name} shape inconsistent with ct grid")
|
|
111
113
|
|
|
114
|
+
if info.context and "from_matRad" in info.context and info.context["from_matRad"]:
|
|
115
|
+
if v is not None:
|
|
116
|
+
for i in range(v.size):
|
|
117
|
+
shape = (
|
|
118
|
+
int(info.data["dose_grid"].dimensions[2]),
|
|
119
|
+
int(info.data["dose_grid"].dimensions[0]),
|
|
120
|
+
int(info.data["dose_grid"].dimensions[1]),
|
|
121
|
+
)
|
|
122
|
+
v.flat[i] = swap_orientation_sparse_matrix(
|
|
123
|
+
v.flat[i],
|
|
124
|
+
shape,
|
|
125
|
+
(1, 2), # (65, 100, 100) example
|
|
126
|
+
)
|
|
127
|
+
if v.flat[i] is not None and not isinstance(v.flat[i], sp.csc_matrix):
|
|
128
|
+
v.flat[i] = sp.csc_matrix(v.flat[i])
|
|
129
|
+
else:
|
|
130
|
+
v = np.array([0])
|
|
131
|
+
return [[v]] # TODO
|
|
132
|
+
|
|
112
133
|
return v
|
|
113
134
|
|
|
114
135
|
@field_validator("dose_grid", "ct_grid", mode="before")
|
|
115
136
|
@classmethod
|
|
116
|
-
def validate_grid(cls, grid: Union[Grid, dict]) -> Union[Grid, dict]:
|
|
137
|
+
def validate_grid(cls, grid: Union[Grid, dict], info: ValidationInfo) -> Union[Grid, dict]:
|
|
117
138
|
"""
|
|
118
139
|
Validate grid dictionaries.
|
|
119
140
|
|
|
@@ -123,7 +144,14 @@ class Dij(PyRadPlanBaseModel):
|
|
|
123
144
|
"""
|
|
124
145
|
# Check if it is a dictionary and then try to create a Grid object
|
|
125
146
|
if isinstance(grid, dict):
|
|
126
|
-
|
|
147
|
+
if info.context and "from_matRad" in info.context and info.context["from_matRad"]:
|
|
148
|
+
grid["dimensions"] = np.array(
|
|
149
|
+
[grid["dimensions"][1], grid["dimensions"][0], grid["dimensions"][2]]
|
|
150
|
+
)
|
|
151
|
+
# TODO: might swap offset and resolution
|
|
152
|
+
grid = Grid.model_validate(grid)
|
|
153
|
+
else:
|
|
154
|
+
grid = Grid.model_validate(grid)
|
|
127
155
|
return grid
|
|
128
156
|
|
|
129
157
|
@field_validator("beam_num", mode="before")
|
|
@@ -184,7 +212,6 @@ class Dij(PyRadPlanBaseModel):
|
|
|
184
212
|
context = info.context
|
|
185
213
|
if context and context.get("matRad") == "mat-file":
|
|
186
214
|
return value.to_matrad(context=context["matRad"])
|
|
187
|
-
|
|
188
215
|
return handler(value, info)
|
|
189
216
|
|
|
190
217
|
@field_serializer("physical_dose", "let_dose", "alpha_dose", "sqrt_beta_dose")
|
|
@@ -204,6 +231,18 @@ class Dij(PyRadPlanBaseModel):
|
|
|
204
231
|
)
|
|
205
232
|
if value.flat[i] is not None and not isinstance(value.flat[i], sp.csc_matrix):
|
|
206
233
|
value.flat[i] = sp.csc_matrix(value.flat[i])
|
|
234
|
+
# return 0 if value is None. savemat() cant handle 'None'
|
|
235
|
+
elif context and context.get("matRad") == "mat-file" and value is None:
|
|
236
|
+
value = np.array([0])
|
|
237
|
+
return value
|
|
238
|
+
|
|
239
|
+
@field_serializer("rad_depth_cubes")
|
|
240
|
+
def rad_depth_cubes_serializer(self, value: np.ndarray, info: SerializationInfo) -> np.ndarray:
|
|
241
|
+
context = info.context
|
|
242
|
+
if context and context.get("matRad") == "mat-file" and value is not None:
|
|
243
|
+
# TODO: it might be necessary to rotate the cube!
|
|
244
|
+
return value
|
|
245
|
+
# return 0 if value is None. savemat() cant handle 'None'
|
|
207
246
|
elif context and context.get("matRad") == "mat-file" and value is None:
|
|
208
247
|
value = np.array([0])
|
|
209
248
|
return value
|
|
@@ -253,7 +292,7 @@ class Dij(PyRadPlanBaseModel):
|
|
|
253
292
|
if self.physical_dose is None:
|
|
254
293
|
raise ValueError("Physical dose must be calculated for dose-weighted let")
|
|
255
294
|
|
|
256
|
-
indices = out["physical_dose"] > 0.
|
|
295
|
+
indices = out["physical_dose"] > 0.05 * np.max(out["physical_dose"])
|
|
257
296
|
|
|
258
297
|
let_dose = self.let_dose.flat[scenario_index] @ intensity
|
|
259
298
|
out["let"] = np.zeros_like(let_dose)
|
|
@@ -470,12 +470,7 @@ class DoseEngineBase(ABC):
|
|
|
470
470
|
dij["ct_grid"] = ct.grid
|
|
471
471
|
|
|
472
472
|
if self.dose_grid is None:
|
|
473
|
-
logger.info(
|
|
474
|
-
"Dose grid not set. Using default resolution: x=%f, y=%f, z=%f",
|
|
475
|
-
ct.grid.resolution["x"],
|
|
476
|
-
ct.grid.resolution["y"],
|
|
477
|
-
ct.grid.resolution["z"],
|
|
478
|
-
)
|
|
473
|
+
logger.info("Dose Grid not set. Using default resolution.")
|
|
479
474
|
self.dose_grid = ct.grid.resample({"x": 5.0, "y": 5.0, "z": 5.0})
|
|
480
475
|
|
|
481
476
|
if not isinstance(self.dose_grid, Grid):
|
|
@@ -484,6 +479,16 @@ class DoseEngineBase(ABC):
|
|
|
484
479
|
except ValidationError:
|
|
485
480
|
self.dose_grid = ct.grid.resample(self.dose_grid["resolution"])
|
|
486
481
|
|
|
482
|
+
logger.info(
|
|
483
|
+
"Dose Grid has Dimensions (%d,%d,%d) with resolution x=%f, y=%f, z=%f.",
|
|
484
|
+
self.dose_grid.dimensions[0],
|
|
485
|
+
self.dose_grid.dimensions[1],
|
|
486
|
+
self.dose_grid.dimensions[2],
|
|
487
|
+
self.dose_grid.resolution["x"],
|
|
488
|
+
self.dose_grid.resolution["y"],
|
|
489
|
+
self.dose_grid.resolution["z"],
|
|
490
|
+
)
|
|
491
|
+
|
|
487
492
|
dij["dose_grid"] = self.dose_grid
|
|
488
493
|
|
|
489
494
|
# Meta information for dij #TODO: Change dij Model in future
|