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.
Files changed (137) hide show
  1. examples/carbon_pencilbeam.py +87 -0
  2. examples/helium_pencilbeam.py +80 -0
  3. examples/import_matrad_patient.py +102 -0
  4. examples/photon_pencilbeam.py +66 -0
  5. examples/proton_pencilbeam.py +80 -0
  6. pyRadPlan/GUI.py +5 -0
  7. pyRadPlan/__init__.py +34 -0
  8. pyRadPlan/core/__init__.py +15 -0
  9. pyRadPlan/core/_exceptions.py +9 -0
  10. pyRadPlan/core/_grids.py +231 -0
  11. pyRadPlan/core/datamodel.py +68 -0
  12. pyRadPlan/core/np2sitk.py +147 -0
  13. pyRadPlan/core/resample.py +130 -0
  14. pyRadPlan/cst/__init__.py +15 -0
  15. pyRadPlan/cst/_cst.py +307 -0
  16. pyRadPlan/cst/_voi.py +603 -0
  17. pyRadPlan/ct/__init__.py +4 -0
  18. pyRadPlan/ct/_ct.py +525 -0
  19. pyRadPlan/ct/_hlut.py +27 -0
  20. pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  21. pyRadPlan/data/machines/helium_Generic.mat +0 -0
  22. pyRadPlan/data/machines/photons_Generic.mat +0 -0
  23. pyRadPlan/data/machines/protons_Generic.mat +0 -0
  24. pyRadPlan/data/phantoms/TG119.mat +0 -0
  25. pyRadPlan/data/stf/matRad_stf.mat +0 -0
  26. pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
  27. pyRadPlan/dij/__init__.py +4 -0
  28. pyRadPlan/dij/_dij.py +410 -0
  29. pyRadPlan/dose/__init__.py +6 -0
  30. pyRadPlan/dose/_calc_dose.py +64 -0
  31. pyRadPlan/dose/engines/__init__.py +17 -0
  32. pyRadPlan/dose/engines/_base.py +591 -0
  33. pyRadPlan/dose/engines/_base_pencilbeam.py +806 -0
  34. pyRadPlan/dose/engines/_base_pencilbeam_particle.py +1015 -0
  35. pyRadPlan/dose/engines/_factory.py +108 -0
  36. pyRadPlan/dose/engines/_hongpb.py +75 -0
  37. pyRadPlan/dose/engines/_svdpb.py +275 -0
  38. pyRadPlan/geometry/__init__.py +7 -0
  39. pyRadPlan/geometry/lps.py +122 -0
  40. pyRadPlan/io/.gitkeep +0 -0
  41. pyRadPlan/io/__init__.py +3 -0
  42. pyRadPlan/io/matLabFileHandler.py +25 -0
  43. pyRadPlan/io/matRad.py +22 -0
  44. pyRadPlan/io/readHLUT.py +17 -0
  45. pyRadPlan/io/temp_files/cst.mat +0 -0
  46. pyRadPlan/io/temp_files/ct.mat +0 -0
  47. pyRadPlan/io/temp_files/pln.mat +0 -0
  48. pyRadPlan/io/temp_files/stf_with_separate_rays.mat +0 -0
  49. pyRadPlan/machines/__init__.py +19 -0
  50. pyRadPlan/machines/_base.py +164 -0
  51. pyRadPlan/machines/_ions.py +528 -0
  52. pyRadPlan/machines/_load.py +48 -0
  53. pyRadPlan/machines/_photons.py +220 -0
  54. pyRadPlan/machines/_validate.py +61 -0
  55. pyRadPlan/matRad/.gitkeep +0 -0
  56. pyRadPlan/matRad/__init__.py +18 -0
  57. pyRadPlan/matRad/_engine.py +36 -0
  58. pyRadPlan/matRad/_matlab.py +26 -0
  59. pyRadPlan/matRad/_octave.py +51 -0
  60. pyRadPlan/optimization/__init__.py +12 -0
  61. pyRadPlan/optimization/_fluenceOptimizer.py +312 -0
  62. pyRadPlan/optimization/_fluence_optimization.py +57 -0
  63. pyRadPlan/optimization/components/__init__.py +3 -0
  64. pyRadPlan/optimization/components/_optimizationProblem.py +162 -0
  65. pyRadPlan/optimization/components/objectives/_EUD.py +93 -0
  66. pyRadPlan/optimization/components/objectives/__init__.py +19 -0
  67. pyRadPlan/optimization/components/objectives/_doseUniformity.py +81 -0
  68. pyRadPlan/optimization/components/objectives/_maxDVH.py +92 -0
  69. pyRadPlan/optimization/components/objectives/_meanDose.py +80 -0
  70. pyRadPlan/optimization/components/objectives/_minDVH.py +92 -0
  71. pyRadPlan/optimization/components/objectives/_objectiveClass.py +98 -0
  72. pyRadPlan/optimization/components/objectives/_squaredDeviation.py +82 -0
  73. pyRadPlan/optimization/components/objectives/_squaredOverdosing.py +84 -0
  74. pyRadPlan/optimization/components/objectives/_squaredUnderdosing.py +84 -0
  75. pyRadPlan/optimization/projections/__init__.py +5 -0
  76. pyRadPlan/optimization/projections/_backProjection.py +59 -0
  77. pyRadPlan/optimization/projections/_constantRBEProjection.py +26 -0
  78. pyRadPlan/optimization/projections/_doseProjection.py +25 -0
  79. pyRadPlan/optimization/solvers/__init__.py +18 -0
  80. pyRadPlan/optimization/solvers/_ipopt.py +89 -0
  81. pyRadPlan/optimization/solvers/_scipy_solver.py +120 -0
  82. pyRadPlan/plan/__init__.py +3 -0
  83. pyRadPlan/plan/_plans.py +360 -0
  84. pyRadPlan/raytracer/__init__.py +4 -0
  85. pyRadPlan/raytracer/_base.py +289 -0
  86. pyRadPlan/raytracer/_perf.py +227 -0
  87. pyRadPlan/raytracer/_siddon.py +428 -0
  88. pyRadPlan/scenarios/__init__.py +102 -0
  89. pyRadPlan/scenarios/_base.py +374 -0
  90. pyRadPlan/scenarios/_nominal.py +126 -0
  91. pyRadPlan/stf/__init__.py +29 -0
  92. pyRadPlan/stf/_base.py +226 -0
  93. pyRadPlan/stf/_beam.py +195 -0
  94. pyRadPlan/stf/_beamlet.py +106 -0
  95. pyRadPlan/stf/_exceptions.py +14 -0
  96. pyRadPlan/stf/_externalbeam.py +162 -0
  97. pyRadPlan/stf/_generate_stf.py +23 -0
  98. pyRadPlan/stf/_ions.py +255 -0
  99. pyRadPlan/stf/_photons.py +125 -0
  100. pyRadPlan/stf/_rangeshifter.py +40 -0
  101. pyRadPlan/stf/_ray.py +201 -0
  102. pyRadPlan/stf/_steeringinformation.py +181 -0
  103. pyRadPlan/stf/base_matrad.py +6 -0
  104. pyRadPlan/stf/hlutLibrary/matRad_default.hlut +10 -0
  105. pyRadPlan/stf/loadHLUT.py +63 -0
  106. pyRadPlan/util/__init__.py +0 -0
  107. pyRadPlan/util/helpers.py +209 -0
  108. pyRadPlan-0.0.1.dist-info/LICENSE +28 -0
  109. pyRadPlan-0.0.1.dist-info/METADATA +70 -0
  110. pyRadPlan-0.0.1.dist-info/RECORD +137 -0
  111. pyRadPlan-0.0.1.dist-info/WHEEL +5 -0
  112. pyRadPlan-0.0.1.dist-info/top_level.txt +3 -0
  113. test/core/test_coordinates.py +46 -0
  114. test/core/test_np2sitk.py +178 -0
  115. test/core/test_resample.py +45 -0
  116. test/cst/conftest.py +57 -0
  117. test/cst/test_VOI.py +422 -0
  118. test/cst/test_cst.py +144 -0
  119. test/ct/test_ct.py +218 -0
  120. test/ct/test_hlut.py +10 -0
  121. test/dose/test_dose_particle.py +234 -0
  122. test/dose/test_dose_photon.py +22 -0
  123. test/geometry/test_lps.py +96 -0
  124. test/stf/test_beamlet.py +53 -0
  125. test/stf/test_stf.py +205 -0
  126. test/stf/test_stf_gen.py +295 -0
  127. test/test_dij.py +238 -0
  128. test/test_fileHandling.py +37 -0
  129. test/test_grid.py +148 -0
  130. test/test_helpers.py +65 -0
  131. test/test_machine_model.py +155 -0
  132. test/test_matlabEngine.py +30 -0
  133. test/test_objectives.py +371 -0
  134. test/test_octaveEngine.py +30 -0
  135. test/test_plan.py +158 -0
  136. test/test_raytracersiddon.py +104 -0
  137. test/test_scenarios.py +198 -0
pyRadPlan/dij/_dij.py ADDED
@@ -0,0 +1,410 @@
1
+ """
2
+ This module contains the dij class, which represents a (collection of)
3
+ influence matrices.
4
+ """
5
+
6
+ from typing import Any, Union, Annotated, cast
7
+ from pydantic import (
8
+ Field,
9
+ field_validator,
10
+ ValidationInfo,
11
+ computed_field,
12
+ field_serializer,
13
+ SerializationInfo,
14
+ )
15
+ from numpydantic import NDArray
16
+
17
+ import numpy as np
18
+ import SimpleITK as sitk
19
+ import scipy.sparse as sp
20
+
21
+ from pyRadPlan.core import Grid
22
+ from pyRadPlan.core import PyRadPlanBaseModel
23
+
24
+
25
+ class Dij(PyRadPlanBaseModel):
26
+ """
27
+ Represents a Collection of Dose (or other quantity) Influence Matrices
28
+ (DIJ) for a given plan.
29
+
30
+ Attributes:
31
+ -----------
32
+ resolution : dict[str, Any]
33
+ Voxel resolution in each dimension ('x', 'y', 'z').
34
+ physical_dose : scipy.sparse.sparray
35
+ Physical dose matrix.
36
+ total_num_of_bixels : int
37
+ Total number of bixels in the matrix.
38
+ num_of_voxels : int
39
+ Total number of voxels in the matrix.
40
+ """
41
+
42
+ dose_grid: Annotated[Grid, Field(default=None)]
43
+ ct_grid: Annotated[Grid, Field(default=None)]
44
+
45
+ physical_dose: Annotated[NDArray, Field(default=None)]
46
+ let_dose: Annotated[NDArray, Field(default=None)]
47
+ alpha_dose: Annotated[NDArray, Field(default=None)]
48
+ sqrt_beta_dose: Annotated[NDArray, Field(default=None)]
49
+
50
+ num_of_beams: Annotated[int, Field(default=None)]
51
+
52
+ bixel_num: Annotated[np.ndarray, Field(default=None)]
53
+ ray_num: Annotated[np.ndarray, Field(default=None)]
54
+ beam_num: Annotated[np.ndarray, Field(default=None)]
55
+
56
+ @computed_field
57
+ @property
58
+ def total_num_of_bixels(self) -> int:
59
+ """Number of bixels / beamlets in the dose influence matrix."""
60
+ return int(self.bixel_num.size)
61
+
62
+ @computed_field
63
+ @property
64
+ def num_of_voxels(self) -> int:
65
+ """Number of voxels in the dose influence matrix."""
66
+ return self.physical_dose.flat[0].shape[0]
67
+
68
+ @field_validator("physical_dose", "let_dose", "alpha_dose", "sqrt_beta_dose", mode="before")
69
+ @classmethod
70
+ def validate_matrices(cls, v: Any, info: ValidationInfo) -> np.ndarray:
71
+ """
72
+ Validates the physical dose matrix.
73
+
74
+ Raises:
75
+ ValueError: if physical dose is not a 2D numpy array.
76
+ """
77
+
78
+ if v is None:
79
+ return v
80
+
81
+ if isinstance(v, (sp.spmatrix, sp.sparray)) or (
82
+ isinstance(v, np.ndarray) and v.dtype != np.dtype(object)
83
+ ):
84
+ tmp = np.empty((1,), dtype=object)
85
+ tmp[0] = v
86
+ v = tmp
87
+
88
+ if isinstance(v, list):
89
+ v = np.asarray(v, dtype=object)
90
+
91
+ for i in range(v.size):
92
+ if v.flat[i] is not None:
93
+ mat = v.flat[i]
94
+ if not isinstance(mat, (sp.spmatrix, sp.sparray, np.ndarray)) or not np.issubdtype(
95
+ mat.dtype, np.number
96
+ ):
97
+ raise ValueError(f"{info.field_name} must be a numeric array.")
98
+ if not mat.ndim == 2:
99
+ raise ValueError(f"{info.field_name} must be a 2D array.")
100
+ if not mat.shape == mat.shape:
101
+ raise ValueError(f"{info.field_name} must have consistent number of voxels.")
102
+
103
+ if mat.shape[0] != info.data["dose_grid"].num_voxels:
104
+ raise ValueError(f"{info.field_name} shape inconsistent with ct grid")
105
+
106
+ return v
107
+
108
+ @field_validator("dose_grid", "ct_grid", mode="before")
109
+ @classmethod
110
+ def validate_grid(cls, grid: Union[Grid, dict]) -> Union[Grid, dict]:
111
+ """
112
+ Validates grid dictionaries.
113
+
114
+ Raises:
115
+ ValueError:
116
+ """
117
+ # Check if it is a dictionary and then try to create a Grid object
118
+ if isinstance(grid, dict):
119
+ grid = Grid.model_validate(grid)
120
+ return grid
121
+
122
+ @field_validator("beam_num", "ray_num", "bixel_num", mode="after")
123
+ @classmethod
124
+ def validate_numbering_arrays(cls, v: np.ndarray, info: ValidationInfo) -> np.ndarray:
125
+ """
126
+ Validates the numbering arrays.
127
+
128
+ Raises:
129
+ ValueError: inconsistent numbering arrays.
130
+ """
131
+ # Check if the numbering arrays have the correct shape
132
+ if info.data.get("physical_dose") is not None:
133
+ dij_matrices = cast(np.ndarray, info.data["physical_dose"])
134
+ for i in range(dij_matrices.size):
135
+ if dij_matrices.flat[i] is not None:
136
+ mat = cast(Union[sp.spmatrix, sp.sparray, np.ndarray], dij_matrices.flat[i])
137
+
138
+ bix_num = mat.shape[1]
139
+
140
+ if v.ndim != 1:
141
+ raise ValueError("Numbering arrays must be 1-dimensional")
142
+
143
+ if v.size != bix_num:
144
+ raise ValueError(
145
+ "Numbering arrays shape inconsistent with number of bixels"
146
+ )
147
+
148
+ return v
149
+
150
+ @field_validator("beam_num")
151
+ @classmethod
152
+ def validate_unique_indices_in_beam_num(
153
+ cls, v: np.ndarray, info: ValidationInfo
154
+ ) -> np.ndarray:
155
+ """
156
+ Validates the number of unique indices in beam_num.
157
+
158
+ Raises:
159
+ ValueError: Number of unique indices does not match number of beams.
160
+ """
161
+ num_of_beams = info.data["num_of_beams"]
162
+ if len(np.unique(v)) != num_of_beams:
163
+ raise ValueError(
164
+ "Number of unique indices in beam_num does not match number of beams."
165
+ )
166
+ return v
167
+
168
+ # Serialization
169
+ @field_serializer("dose_grid", "ct_grid")
170
+ def grid_serializer(self, value: Grid, info: SerializationInfo) -> dict:
171
+ context = info.context
172
+ if context and context.get("matRad") == "mat-file":
173
+ return value.to_matrad(context=context["matRad"])
174
+
175
+ @field_serializer("physical_dose", "let_dose", "alpha_dose", "sqrt_beta_dose")
176
+ def physical_dose_serializer(self, value: np.ndarray, info: SerializationInfo) -> np.ndarray:
177
+ context = info.context
178
+ if context and context.get("matRad") == "mat-file" and value is not None:
179
+ for i in range(value.size):
180
+ if value.flat[i] is not None and not isinstance(value.flat[i], sp.csc_matrix):
181
+ value.flat[i] = sp.csc_matrix(value.flat[i])
182
+ return value
183
+
184
+ @field_serializer("bixel_num", "ray_num", "beam_num")
185
+ def numbering_arrays_serializer(
186
+ self, value: np.ndarray, info: SerializationInfo
187
+ ) -> np.ndarray:
188
+ context = info.context
189
+ if context and context.get("matRad") == "mat-file":
190
+ return value.reshape(-1, 1)
191
+ return value
192
+
193
+ def to_matrad(self, context: str = "mat-file") -> Any:
194
+ """
195
+ Converts the Dij object to matRad-compatible dictionary with
196
+ camelCase keys.
197
+ """
198
+ dij_dict = super().to_matrad(context=context)
199
+ return dij_dict
200
+
201
+ def get_result_arrays_from_intensity(
202
+ self, intensity: np.ndarray, scenario_index: int = 0
203
+ ) -> dict[str, np.ndarray]:
204
+ """
205
+ Applies the intensity to the dose influence matrix.
206
+
207
+ Parameters
208
+ ----------
209
+ intensity : np.ndarray
210
+ The intensity to apply to the dose influence matrix.
211
+ scenario_index : int
212
+ The scenario index to apply the intensity to.
213
+
214
+ Returns
215
+ -------
216
+ dict[str,sitk.Image]
217
+ A dictionary containing the quantity images for each scenario.
218
+ """
219
+
220
+ out = {}
221
+
222
+ # TODO: implement quantity system to select the corresponding quantities automatically
223
+ if self.physical_dose is not None:
224
+ out["physical_dose"] = self.physical_dose.flat[scenario_index] @ intensity
225
+
226
+ if self.let_dose is not None:
227
+ if self.physical_dose is None:
228
+ raise ValueError("Physical dose must be calculated for dose-weighted let")
229
+
230
+ indices = out["physical_dose"] > 0.0
231
+
232
+ let_dose = self.let_dose.flat[scenario_index] @ intensity
233
+ out["let"] = np.zeros_like(let_dose)
234
+ out["let"][indices] = let_dose[indices] / out["physical_dose"][indices]
235
+
236
+ if self.alpha_dose is not None and self.sqrt_beta_dose is not None:
237
+ out["effect"] = (
238
+ self.alpha_dose.flat[scenario_index] @ intensity
239
+ + (self.sqrt_beta_dose.flat[scenario_index] @ intensity) ** 2
240
+ )
241
+
242
+ return out
243
+
244
+ def compute_result_dose_grid(
245
+ self, intensities: np.ndarray, scenario_index: int = 0
246
+ ) -> dict[str, sitk.Image]:
247
+ """
248
+ Applies the intensity to the dose influence matrix to get result
249
+ cubes on the dose grid.
250
+
251
+ Parameters
252
+ ----------
253
+ intensity : np.ndarray
254
+ The intensity to apply to the dose influence matrix.
255
+ scenario_index : int
256
+ The scenario index to apply the intensity to.
257
+
258
+ Returns
259
+ -------
260
+ dict[str,sitk.Image]
261
+ A dictionary containing the quantity images for each scenario.
262
+ """
263
+
264
+ out = self.get_result_arrays_from_intensity(intensities, scenario_index=scenario_index)
265
+ # Create a sitk image for each scenario
266
+
267
+ for key, value in out.items():
268
+ # Create a sitk image for each scenario
269
+ out[key] = sitk.GetImageFromArray(value.reshape(self.dose_grid.dimensions[::-1]))
270
+ out[key].SetOrigin(self.dose_grid.origin)
271
+ out[key].SetSpacing(self.dose_grid.resolution_vector)
272
+ out[key].SetDirection(self.dose_grid.direction.ravel())
273
+
274
+ return out
275
+
276
+ def compute_result_ct_grid(
277
+ self, intensities: np.ndarray, scenario_index: int = 0
278
+ ) -> dict[str, sitk.Image]:
279
+ """
280
+ Applies the intensity to the dose influence matrix to get results on
281
+ the CT grid.
282
+
283
+ Parameters
284
+ ----------
285
+ intensity : np.ndarray
286
+ The intensity to apply to the dose influence matrix.
287
+ scenario_index : int
288
+ The scenario index to apply the intensity to.
289
+
290
+ Returns
291
+ -------
292
+ dict[str,sitk.Image]
293
+ A dictionary containing the quantity images for each scenario.
294
+ """
295
+
296
+ out = self.compute_result_dose_grid(intensities, scenario_index=scenario_index)
297
+ # Create a sitk image for each scenario
298
+
299
+ for key, value in out.items():
300
+ # Create a sitk image for each scenario
301
+ resampler = sitk.ResampleImageFilter()
302
+ resampler.SetInterpolator(sitk.sitkLinear)
303
+ resampler.SetOutputDirection(self.ct_grid.direction.ravel())
304
+ resampler.SetOutputOrigin(self.ct_grid.origin)
305
+ resampler.SetOutputSpacing(self.ct_grid.resolution_vector)
306
+ resampler.SetSize(self.ct_grid.dimensions)
307
+ out[key] = resampler.Execute(value)
308
+
309
+ return out
310
+
311
+
312
+ def create_dij(data: Union[dict[str, Any], Dij, None] = None, **kwargs) -> Dij:
313
+ """
314
+ Factory function to create a Plan object.
315
+
316
+ Parameters
317
+ ----------
318
+ data : Union[dict[str, Any], Dij, None]
319
+ Dictionary containing the data to create the Dij object.
320
+ **kwargs
321
+ Arbitrary keyword arguments.
322
+
323
+ Returns
324
+ -------
325
+ Dij
326
+ A Dij object.
327
+
328
+ Raises
329
+ ------
330
+ ValueError
331
+ If ..???
332
+ """
333
+
334
+ if data:
335
+ # If data is already a Dij object, return it directly
336
+ if isinstance(data, Dij):
337
+ return data
338
+
339
+ return Dij.model_validate(data)
340
+
341
+ return Dij(**kwargs)
342
+
343
+
344
+ def validate_dij(dij: Union[dict[str, Any], Dij, None] = None, **kwargs) -> Dij:
345
+ """
346
+ Validates and creates a Dij object.
347
+ Synonym to create_dij but should be used in validation context.
348
+
349
+ Parameters
350
+ ----------
351
+ dij : Union[dict[str, Any], Dij, None], optional
352
+ Dictionary containing the data to create the Dij object, by default None.
353
+ **kwargs
354
+ Arbitrary keyword arguments.
355
+
356
+ Returns
357
+ -------
358
+ Dij
359
+ A validated Dij object.
360
+
361
+ Raises
362
+ ------
363
+ ValueError
364
+ If ... ???
365
+ """
366
+ return create_dij(dij, **kwargs)
367
+
368
+
369
+ if __name__ == "__main__":
370
+ # Implements an example usage of the Dij class.
371
+ import numpy as np
372
+ import pyRadPlan.io.matRad as matRadIO
373
+
374
+ # Consider a dictionary of dij information in camelCase
375
+ dose_information = {
376
+ "ctGrid": {
377
+ "resolution": {"x": 3.0, "y": 3.0, "z": 3.0},
378
+ "dimensions": (167, 167, 107),
379
+ "numOfVoxels": 167 * 167 * 107,
380
+ },
381
+ "doseGrid": {
382
+ "resolution": {"x": 3.0, "y": 3.0, "z": 3.0},
383
+ "dimensions": (167, 167, 107),
384
+ "numOfVoxels": 167 * 167 * 107,
385
+ },
386
+ "numOfBeams": 2,
387
+ "numOfScenarios": 1,
388
+ "numOfRaysPerBeam": [255, 255],
389
+ "totalNumOfBixels": 6506,
390
+ "totalNumOfRays": 510,
391
+ "bixelNum": np.ones(6506),
392
+ "rayNum": np.ones(6506),
393
+ "beamNum": np.ones(6506),
394
+ "minMu": np.ones(6506),
395
+ "maxMu": np.ones(6506),
396
+ "numOfParticlesPerMu": np.ones(6506),
397
+ "physicalDose": sp.csr_matrix((167 * 167 * 107, 6506), dtype=float),
398
+ }
399
+
400
+ dose_information["beamNum"][3000:] = 2
401
+ # We create the DIJ object with mdoel validate
402
+ dij = create_dij(**dose_information)
403
+ # # print the dataclass
404
+ # print(dij)
405
+ # # turn it into a snake_case style dictionary
406
+ # print(dij.model_dump())
407
+
408
+ dij_to_matrad = dij.to_matrad(context="mat-file")
409
+
410
+ matRadIO.save("dij.mat", {"dij": dij_to_matrad})
@@ -0,0 +1,6 @@
1
+ from ._calc_dose import calc_dose_influence, calc_dose_forward
2
+
3
+ __all__ = [
4
+ "calc_dose_influence",
5
+ "calc_dose_forward",
6
+ ]
@@ -0,0 +1,64 @@
1
+ from typing import Union
2
+ from pyRadPlan.stf import validate_stf, SteeringInformation
3
+ from pyRadPlan.ct import validate_ct, CT
4
+ from pyRadPlan.cst import validate_cst, StructureSet
5
+ from pyRadPlan.plan import validate_pln, Plan
6
+ from pyRadPlan.dij import Dij
7
+
8
+ from .engines import get_engine
9
+
10
+
11
+ def calc_dose_influence(
12
+ ct: Union[CT, dict],
13
+ cst: Union[StructureSet, dict],
14
+ stf: Union[SteeringInformation, dict],
15
+ pln: Union[Plan, dict],
16
+ ) -> Dij:
17
+ """
18
+ Calculate the dose influence matrix.
19
+
20
+ Parameters
21
+ ----------
22
+ ct : CT
23
+ A CT object.
24
+ cst : CST
25
+ A CST object.
26
+ stf : STF
27
+ A STF object.
28
+
29
+ Returns
30
+ -------
31
+ Dij
32
+ A Dij object.
33
+ """
34
+
35
+ ct = validate_ct(ct)
36
+ cst = validate_cst(cst, ct=ct)
37
+ stf = validate_stf(stf)
38
+ pln = validate_pln(pln)
39
+
40
+ engine = get_engine(pln)
41
+
42
+ dij = engine.calc_dose_influence(ct, cst, stf)
43
+ return dij
44
+
45
+
46
+ def calc_dose_forward(ct, cst, stf):
47
+ """
48
+ Calculate the dose forward matrix.
49
+
50
+ Parameters
51
+ ----------
52
+ ct : CT
53
+ A CT object.
54
+ cst : CST
55
+ A CST object.
56
+ stf : STF
57
+ A STF object.
58
+
59
+ Returns
60
+ -------
61
+ PlanResult
62
+ A PlanResult object.
63
+ """
64
+ raise NotImplementedError("This function is not implemented yet.")
@@ -0,0 +1,17 @@
1
+ from ._base import DoseEngineBase
2
+ from ._svdpb import PhotonPencilBeamSVDEngine
3
+ from ._hongpb import ParticleHongPencilBeamEngine
4
+
5
+ from ._factory import get_engine, get_available_engines, register_engine
6
+
7
+ register_engine(PhotonPencilBeamSVDEngine)
8
+ register_engine(ParticleHongPencilBeamEngine)
9
+
10
+ __all__ = [
11
+ "DoseEngineBase",
12
+ "PhotonPencilBeamSVDEngine",
13
+ " ParticleHongPencilBeamEngine",
14
+ "get_engine",
15
+ "get_available_engines",
16
+ "register_engine",
17
+ ]