pyRadPlan 0.0.1__py3-none-any.whl
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.
- examples/carbon_pencilbeam.py +87 -0
- examples/helium_pencilbeam.py +80 -0
- examples/import_matrad_patient.py +102 -0
- examples/photon_pencilbeam.py +66 -0
- examples/proton_pencilbeam.py +80 -0
- pyRadPlan/GUI.py +5 -0
- pyRadPlan/__init__.py +34 -0
- pyRadPlan/core/__init__.py +15 -0
- pyRadPlan/core/_exceptions.py +9 -0
- pyRadPlan/core/_grids.py +231 -0
- pyRadPlan/core/datamodel.py +68 -0
- pyRadPlan/core/np2sitk.py +147 -0
- pyRadPlan/core/resample.py +130 -0
- pyRadPlan/cst/__init__.py +15 -0
- pyRadPlan/cst/_cst.py +307 -0
- pyRadPlan/cst/_voi.py +603 -0
- pyRadPlan/ct/__init__.py +4 -0
- pyRadPlan/ct/_ct.py +525 -0
- pyRadPlan/ct/_hlut.py +27 -0
- pyRadPlan/data/machines/carbon_Generic.mat +0 -0
- pyRadPlan/data/machines/helium_Generic.mat +0 -0
- pyRadPlan/data/machines/photons_Generic.mat +0 -0
- pyRadPlan/data/machines/protons_Generic.mat +0 -0
- pyRadPlan/data/phantoms/TG119.mat +0 -0
- pyRadPlan/data/stf/matRad_stf.mat +0 -0
- pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
- pyRadPlan/dij/__init__.py +4 -0
- pyRadPlan/dij/_dij.py +410 -0
- pyRadPlan/dose/__init__.py +6 -0
- pyRadPlan/dose/_calc_dose.py +64 -0
- pyRadPlan/dose/engines/__init__.py +17 -0
- pyRadPlan/dose/engines/_base.py +591 -0
- pyRadPlan/dose/engines/_base_pencilbeam.py +806 -0
- pyRadPlan/dose/engines/_base_pencilbeam_particle.py +1015 -0
- pyRadPlan/dose/engines/_factory.py +108 -0
- pyRadPlan/dose/engines/_hongpb.py +75 -0
- pyRadPlan/dose/engines/_svdpb.py +275 -0
- pyRadPlan/geometry/__init__.py +7 -0
- pyRadPlan/geometry/lps.py +122 -0
- pyRadPlan/io/.gitkeep +0 -0
- pyRadPlan/io/__init__.py +3 -0
- pyRadPlan/io/matLabFileHandler.py +25 -0
- pyRadPlan/io/matRad.py +22 -0
- pyRadPlan/io/readHLUT.py +17 -0
- pyRadPlan/io/temp_files/cst.mat +0 -0
- pyRadPlan/io/temp_files/ct.mat +0 -0
- pyRadPlan/io/temp_files/pln.mat +0 -0
- pyRadPlan/io/temp_files/stf_with_separate_rays.mat +0 -0
- pyRadPlan/machines/__init__.py +19 -0
- pyRadPlan/machines/_base.py +164 -0
- pyRadPlan/machines/_ions.py +528 -0
- pyRadPlan/machines/_load.py +48 -0
- pyRadPlan/machines/_photons.py +220 -0
- pyRadPlan/machines/_validate.py +61 -0
- pyRadPlan/matRad/.gitkeep +0 -0
- pyRadPlan/matRad/__init__.py +18 -0
- pyRadPlan/matRad/_engine.py +36 -0
- pyRadPlan/matRad/_matlab.py +26 -0
- pyRadPlan/matRad/_octave.py +51 -0
- pyRadPlan/optimization/__init__.py +12 -0
- pyRadPlan/optimization/_fluenceOptimizer.py +312 -0
- pyRadPlan/optimization/_fluence_optimization.py +57 -0
- pyRadPlan/optimization/components/__init__.py +3 -0
- pyRadPlan/optimization/components/_optimizationProblem.py +162 -0
- pyRadPlan/optimization/components/objectives/_EUD.py +93 -0
- pyRadPlan/optimization/components/objectives/__init__.py +19 -0
- pyRadPlan/optimization/components/objectives/_doseUniformity.py +81 -0
- pyRadPlan/optimization/components/objectives/_maxDVH.py +92 -0
- pyRadPlan/optimization/components/objectives/_meanDose.py +80 -0
- pyRadPlan/optimization/components/objectives/_minDVH.py +92 -0
- pyRadPlan/optimization/components/objectives/_objectiveClass.py +98 -0
- pyRadPlan/optimization/components/objectives/_squaredDeviation.py +82 -0
- pyRadPlan/optimization/components/objectives/_squaredOverdosing.py +84 -0
- pyRadPlan/optimization/components/objectives/_squaredUnderdosing.py +84 -0
- pyRadPlan/optimization/projections/__init__.py +5 -0
- pyRadPlan/optimization/projections/_backProjection.py +59 -0
- pyRadPlan/optimization/projections/_constantRBEProjection.py +26 -0
- pyRadPlan/optimization/projections/_doseProjection.py +25 -0
- pyRadPlan/optimization/solvers/__init__.py +18 -0
- pyRadPlan/optimization/solvers/_ipopt.py +89 -0
- pyRadPlan/optimization/solvers/_scipy_solver.py +120 -0
- pyRadPlan/plan/__init__.py +3 -0
- pyRadPlan/plan/_plans.py +360 -0
- pyRadPlan/raytracer/__init__.py +4 -0
- pyRadPlan/raytracer/_base.py +289 -0
- pyRadPlan/raytracer/_perf.py +227 -0
- pyRadPlan/raytracer/_siddon.py +428 -0
- pyRadPlan/scenarios/__init__.py +102 -0
- pyRadPlan/scenarios/_base.py +374 -0
- pyRadPlan/scenarios/_nominal.py +126 -0
- pyRadPlan/stf/__init__.py +29 -0
- pyRadPlan/stf/_base.py +226 -0
- pyRadPlan/stf/_beam.py +195 -0
- pyRadPlan/stf/_beamlet.py +106 -0
- pyRadPlan/stf/_exceptions.py +14 -0
- pyRadPlan/stf/_externalbeam.py +162 -0
- pyRadPlan/stf/_generate_stf.py +23 -0
- pyRadPlan/stf/_ions.py +255 -0
- pyRadPlan/stf/_photons.py +125 -0
- pyRadPlan/stf/_rangeshifter.py +40 -0
- pyRadPlan/stf/_ray.py +201 -0
- pyRadPlan/stf/_steeringinformation.py +181 -0
- pyRadPlan/stf/base_matrad.py +6 -0
- pyRadPlan/stf/hlutLibrary/matRad_default.hlut +10 -0
- pyRadPlan/stf/loadHLUT.py +63 -0
- pyRadPlan/util/__init__.py +0 -0
- pyRadPlan/util/helpers.py +209 -0
- pyRadPlan-0.0.1.dist-info/LICENSE +28 -0
- pyRadPlan-0.0.1.dist-info/METADATA +70 -0
- pyRadPlan-0.0.1.dist-info/RECORD +137 -0
- pyRadPlan-0.0.1.dist-info/WHEEL +5 -0
- pyRadPlan-0.0.1.dist-info/top_level.txt +3 -0
- test/core/test_coordinates.py +46 -0
- test/core/test_np2sitk.py +178 -0
- test/core/test_resample.py +45 -0
- test/cst/conftest.py +57 -0
- test/cst/test_VOI.py +422 -0
- test/cst/test_cst.py +144 -0
- test/ct/test_ct.py +218 -0
- test/ct/test_hlut.py +10 -0
- test/dose/test_dose_particle.py +234 -0
- test/dose/test_dose_photon.py +22 -0
- test/geometry/test_lps.py +96 -0
- test/stf/test_beamlet.py +53 -0
- test/stf/test_stf.py +205 -0
- test/stf/test_stf_gen.py +295 -0
- test/test_dij.py +238 -0
- test/test_fileHandling.py +37 -0
- test/test_grid.py +148 -0
- test/test_helpers.py +65 -0
- test/test_machine_model.py +155 -0
- test/test_matlabEngine.py +30 -0
- test/test_objectives.py +371 -0
- test/test_octaveEngine.py +30 -0
- test/test_plan.py +158 -0
- test/test_raytracersiddon.py +104 -0
- test/test_scenarios.py +198 -0
test/test_scenarios.py
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import numpy as np
|
|
3
|
+
import SimpleITK as sitk
|
|
4
|
+
from pyRadPlan.scenarios import ScenarioModel, NominalScenario, create_scenario_model
|
|
5
|
+
from pyRadPlan.ct import CT
|
|
6
|
+
import pytest
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def helper_mvar_gauss(scenarioModel):
|
|
10
|
+
# Computes multivariate Gaussian probability for scenario model
|
|
11
|
+
# Can be used to test correct scenario probabilities. Also considers used
|
|
12
|
+
# ct phases for probability computation (uncorrelated)
|
|
13
|
+
|
|
14
|
+
sigma = np.diag(
|
|
15
|
+
np.hstack(
|
|
16
|
+
(
|
|
17
|
+
scenarioModel.shift_sd,
|
|
18
|
+
scenarioModel.range_abs_sd,
|
|
19
|
+
scenarioModel.range_rel_sd / 100.0,
|
|
20
|
+
)
|
|
21
|
+
)
|
|
22
|
+
** 2
|
|
23
|
+
)
|
|
24
|
+
d = sigma.shape[0]
|
|
25
|
+
cs = np.linalg.cholesky(sigma)
|
|
26
|
+
|
|
27
|
+
tmp_standardized = np.linalg.solve(cs, scenarioModel.scen_for_prob[:, 1:].T).T
|
|
28
|
+
p = (
|
|
29
|
+
(2 * np.pi) ** (-d / 2)
|
|
30
|
+
* np.exp(-0.5 * np.sum(tmp_standardized**2, axis=1))
|
|
31
|
+
/ np.prod(np.diag(cs))
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
# Now multiply with the phase probability
|
|
35
|
+
tmp_phase_prob = np.array(
|
|
36
|
+
[
|
|
37
|
+
[x[1] for x in scenarioModel.ct_scen_prob if x[0] == phase]
|
|
38
|
+
for phase in scenarioModel.scen_for_prob[:, 0]
|
|
39
|
+
]
|
|
40
|
+
)
|
|
41
|
+
p = p * tmp_phase_prob
|
|
42
|
+
|
|
43
|
+
return p
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@pytest.fixture
|
|
47
|
+
def sample_ct():
|
|
48
|
+
"""Create a sample SimpleITK image for testing."""
|
|
49
|
+
sample_array = np.random.rand(50, 100, 100) * 1000 # Random HU values
|
|
50
|
+
image = sitk.GetImageFromArray(sample_array)
|
|
51
|
+
image.SetOrigin((0, 0, 0))
|
|
52
|
+
image.SetSpacing((1, 1, 2))
|
|
53
|
+
image.SetDirection((1, 0, 0, 0, 1, 0, 0, 0, 1))
|
|
54
|
+
|
|
55
|
+
ct = CT(cube_hu=image)
|
|
56
|
+
return ct
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# Test Abstract Scenario Model
|
|
60
|
+
def test_scenario_model():
|
|
61
|
+
with pytest.raises(TypeError):
|
|
62
|
+
ScenarioModel()
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_nominal_scenario_construct():
|
|
66
|
+
scenario = NominalScenario()
|
|
67
|
+
assert isinstance(scenario, ScenarioModel)
|
|
68
|
+
assert isinstance(scenario, NominalScenario)
|
|
69
|
+
assert scenario.name == "Nominal Scenario"
|
|
70
|
+
assert scenario.short_name == "nomScen"
|
|
71
|
+
assert scenario.short_name == "nomScen"
|
|
72
|
+
assert scenario.ct_scen_prob == [(0, 1.0)]
|
|
73
|
+
assert scenario.num_of_ct_scen == 1
|
|
74
|
+
assert scenario.tot_num_scen == 1
|
|
75
|
+
assert scenario.tot_num_shift_scen == 1
|
|
76
|
+
assert scenario.tot_num_range_scen == 1
|
|
77
|
+
assert scenario.rel_range_shift == 0.0
|
|
78
|
+
assert scenario.abs_range_shift == 0.0
|
|
79
|
+
assert np.array_equal(scenario.iso_shift, np.array([[0.0, 0.0, 0.0]]))
|
|
80
|
+
assert scenario.max_abs_range_shift == 0.0
|
|
81
|
+
assert scenario.max_rel_range_shift == 0.0
|
|
82
|
+
assert np.array_equal(scenario.scen_mask, np.ones((1, 1, 1)).astype(bool))
|
|
83
|
+
assert np.array_equal(scenario.linear_mask, np.array([[0, 0, 0]]))
|
|
84
|
+
assert np.allclose(scenario.scen_prob, helper_mvar_gauss(scenario))
|
|
85
|
+
assert np.array_equal(
|
|
86
|
+
scenario.scen_for_prob,
|
|
87
|
+
np.hstack((np.zeros((1, 1), dtype=float), np.zeros((1, 5), dtype=float))),
|
|
88
|
+
)
|
|
89
|
+
assert np.array_equal(scenario.scen_weight, np.ones((1,), dtype=float))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_nominal_scenario_construct_with_ct(sample_ct):
|
|
93
|
+
scenario = NominalScenario(sample_ct)
|
|
94
|
+
assert isinstance(scenario, ScenarioModel)
|
|
95
|
+
assert isinstance(scenario, NominalScenario)
|
|
96
|
+
assert scenario.name == "Nominal Scenario"
|
|
97
|
+
assert scenario.short_name == "nomScen"
|
|
98
|
+
assert scenario.short_name == "nomScen"
|
|
99
|
+
assert scenario.ct_scen_prob == [(0, 1.0)]
|
|
100
|
+
assert scenario.num_of_ct_scen == 1
|
|
101
|
+
assert scenario.tot_num_scen == 1
|
|
102
|
+
assert scenario.tot_num_shift_scen == 1
|
|
103
|
+
assert scenario.tot_num_range_scen == 1
|
|
104
|
+
assert scenario.rel_range_shift == 0.0
|
|
105
|
+
assert scenario.abs_range_shift == 0.0
|
|
106
|
+
assert np.array_equal(scenario.iso_shift, np.array([[0.0, 0.0, 0.0]]))
|
|
107
|
+
assert scenario.max_abs_range_shift == 0.0
|
|
108
|
+
assert scenario.max_rel_range_shift == 0.0
|
|
109
|
+
assert np.array_equal(scenario.scen_mask, np.ones((1, 1, 1)).astype(bool))
|
|
110
|
+
assert np.array_equal(scenario.linear_mask, np.array([[0, 0, 0]]))
|
|
111
|
+
assert np.allclose(scenario.scen_prob, helper_mvar_gauss(scenario))
|
|
112
|
+
assert np.array_equal(
|
|
113
|
+
scenario.scen_for_prob,
|
|
114
|
+
np.hstack((np.zeros((1, 1), dtype=float), np.zeros((1, 5), dtype=float))),
|
|
115
|
+
)
|
|
116
|
+
assert np.array_equal(scenario.scen_weight, np.ones((1,), dtype=float))
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_nominal_scenario_list():
|
|
120
|
+
scenario = NominalScenario()
|
|
121
|
+
scenario.list_all_scenarios()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def test_nominal_scenario_creation_by_name():
|
|
125
|
+
scenario = create_scenario_model("nomScen")
|
|
126
|
+
assert isinstance(scenario, ScenarioModel)
|
|
127
|
+
assert isinstance(scenario, NominalScenario)
|
|
128
|
+
|
|
129
|
+
with pytest.raises(ValueError):
|
|
130
|
+
create_scenario_model("unknown")
|
|
131
|
+
|
|
132
|
+
with pytest.raises(NotImplementedError):
|
|
133
|
+
create_scenario_model("wcScen")
|
|
134
|
+
|
|
135
|
+
with pytest.raises(NotImplementedError):
|
|
136
|
+
create_scenario_model("impScen")
|
|
137
|
+
|
|
138
|
+
with pytest.raises(NotImplementedError):
|
|
139
|
+
create_scenario_model("rndScen")
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_nominal_scenario_creation_by_dict():
|
|
143
|
+
model_dict = {
|
|
144
|
+
"model": "nomScen",
|
|
145
|
+
"range_rel_sd": 5.0,
|
|
146
|
+
"range_abs_sd": 2.5,
|
|
147
|
+
"shift_sd": [3.0, 3.0, 3.0],
|
|
148
|
+
"ct_scen_prob": [(0, 0.5)],
|
|
149
|
+
"wc_sigma": 5.0,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
scenario = create_scenario_model(model_dict)
|
|
153
|
+
|
|
154
|
+
assert isinstance(scenario, ScenarioModel)
|
|
155
|
+
assert isinstance(scenario, NominalScenario)
|
|
156
|
+
assert scenario.range_rel_sd == 5.0
|
|
157
|
+
assert scenario.range_abs_sd == 2.5
|
|
158
|
+
assert np.array_equal(scenario.shift_sd, [3.0, 3.0, 3.0])
|
|
159
|
+
assert scenario.ct_scen_prob == [(0, 0.5)]
|
|
160
|
+
assert scenario.wc_sigma == 5.0
|
|
161
|
+
|
|
162
|
+
return_dict = scenario.to_dict()
|
|
163
|
+
|
|
164
|
+
assert return_dict == model_dict
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_nominal_scenario_creation_by_matrad_dict():
|
|
168
|
+
model_dict = {
|
|
169
|
+
"model": "nomScen",
|
|
170
|
+
"rangeRelSD": 5.0,
|
|
171
|
+
"rangeAbsSD": 2.5,
|
|
172
|
+
"shiftSD": [3.0, 3.0, 3.0],
|
|
173
|
+
"ctScenProb": [(0, 0.5)],
|
|
174
|
+
"wcSigma": 5.0,
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
scenario = create_scenario_model(model_dict)
|
|
178
|
+
|
|
179
|
+
assert isinstance(scenario, ScenarioModel)
|
|
180
|
+
assert isinstance(scenario, NominalScenario)
|
|
181
|
+
assert scenario.range_rel_sd == 5.0
|
|
182
|
+
assert scenario.range_abs_sd == 2.5
|
|
183
|
+
assert np.array_equal(scenario.shift_sd, [3.0, 3.0, 3.0])
|
|
184
|
+
assert scenario.ct_scen_prob == [(0, 0.5)]
|
|
185
|
+
assert scenario.wc_sigma == 5.0
|
|
186
|
+
|
|
187
|
+
return_dict = scenario.to_matrad()
|
|
188
|
+
|
|
189
|
+
assert return_dict == model_dict
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def test_nominal_scenario_extract_single_scenario():
|
|
193
|
+
scenario = NominalScenario()
|
|
194
|
+
assert isinstance(scenario.extract_single_scenario(0), ScenarioModel)
|
|
195
|
+
assert isinstance(scenario.extract_single_scenario(0), NominalScenario)
|
|
196
|
+
|
|
197
|
+
with pytest.raises(NotImplementedError):
|
|
198
|
+
scenario.extract_single_scenario(1)
|