pyRadPlan 0.0.2__tar.gz → 0.2.0__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.
Files changed (204) hide show
  1. {pyradplan-0.0.2 → pyradplan-0.2.0}/LICENSE +28 -28
  2. pyradplan-0.2.0/PKG-INFO +139 -0
  3. pyradplan-0.2.0/README.md +95 -0
  4. pyradplan-0.2.0/docs/conf.py +55 -0
  5. pyradplan-0.2.0/examples/carbon_pencilbeam.py +62 -0
  6. pyradplan-0.2.0/examples/helium_pencilbeam.py +51 -0
  7. {pyradplan-0.0.2 → pyradplan-0.2.0}/examples/import_matrad_patient.py +97 -102
  8. pyradplan-0.2.0/examples/photon_pencilbeam.py +64 -0
  9. pyradplan-0.2.0/examples/proton_pencilbeam.py +60 -0
  10. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/__init__.py +43 -34
  11. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/core/__init__.py +15 -15
  12. pyradplan-0.2.0/pyRadPlan/core/_exceptions.py +5 -0
  13. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/core/_grids.py +231 -231
  14. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/core/datamodel.py +70 -68
  15. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/core/np2sitk.py +146 -147
  16. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/core/resample.py +130 -130
  17. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/cst/__init__.py +15 -15
  18. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/cst/_cst.py +360 -307
  19. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/cst/_voi.py +620 -603
  20. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/ct/__init__.py +4 -4
  21. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/ct/_ct.py +516 -525
  22. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/ct/_hlut.py +27 -27
  23. pyradplan-0.2.0/pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
  24. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dij/__init__.py +5 -4
  25. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dij/_dij.py +373 -410
  26. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/__init__.py +8 -6
  27. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/_calc_dose.py +83 -64
  28. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/engines/__init__.py +17 -17
  29. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_base.py +607 -591
  30. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_base_pencilbeam.py +840 -806
  31. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +997 -1015
  32. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_factory.py +107 -108
  33. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_hongpb.py +73 -75
  34. pyradplan-0.2.0/pyRadPlan/dose/engines/_svdpb.py +363 -0
  35. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/geometry/__init__.py +9 -7
  36. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/geometry/lps.py +125 -122
  37. pyradplan-0.2.0/pyRadPlan/io/__init__.py +4 -0
  38. pyradplan-0.2.0/pyRadPlan/io/_matlab_file_handler.py +31 -0
  39. pyradplan-0.2.0/pyRadPlan/io/_patient_loader.py +113 -0
  40. pyradplan-0.2.0/pyRadPlan/io/matfile.py +35 -0
  41. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/machines/__init__.py +19 -19
  42. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/machines/_base.py +163 -164
  43. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/machines/_ions.py +527 -528
  44. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/machines/_load.py +55 -48
  45. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/machines/_photons.py +219 -220
  46. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/machines/_validate.py +61 -61
  47. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/matRad/__init__.py +18 -18
  48. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/matRad/_engine.py +36 -36
  49. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/matRad/_matlab.py +26 -26
  50. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/matRad/_octave.py +51 -51
  51. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/optimization/__init__.py +12 -12
  52. pyradplan-0.2.0/pyRadPlan/optimization/_fluence_optimization.py +47 -0
  53. pyradplan-0.2.0/pyRadPlan/optimization/objectives/__init__.py +37 -0
  54. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_eud.py +50 -0
  55. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_factory.py +92 -0
  56. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_max_dvh.py +54 -0
  57. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_mean.py +50 -0
  58. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_min_dvh.py +54 -0
  59. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_objective.py +176 -0
  60. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_squared_dev.py +43 -0
  61. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_squared_over.py +45 -0
  62. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_squared_under.py +45 -0
  63. pyradplan-0.2.0/pyRadPlan/optimization/objectives/_std.py +36 -0
  64. pyradplan-0.2.0/pyRadPlan/optimization/problems/__init__.py +16 -0
  65. pyradplan-0.2.0/pyRadPlan/optimization/problems/_factory.py +144 -0
  66. pyradplan-0.2.0/pyRadPlan/optimization/problems/_nonlin_fluence.py +229 -0
  67. pyradplan-0.2.0/pyRadPlan/optimization/problems/_optiprob.py +295 -0
  68. pyradplan-0.2.0/pyRadPlan/optimization/problems/_simple_least_squares.py +118 -0
  69. pyradplan-0.2.0/pyRadPlan/optimization/solvers/__init__.py +27 -0
  70. pyradplan-0.2.0/pyRadPlan/optimization/solvers/_base_solvers.py +122 -0
  71. pyradplan-0.2.0/pyRadPlan/optimization/solvers/_factory.py +74 -0
  72. pyradplan-0.2.0/pyRadPlan/optimization/solvers/_ipopt.py +112 -0
  73. pyradplan-0.2.0/pyRadPlan/optimization/solvers/_scipy_solver.py +73 -0
  74. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/plan/__init__.py +3 -3
  75. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/plan/_plans.py +361 -360
  76. pyradplan-0.2.0/pyRadPlan/quantities/__init__.py +42 -0
  77. pyradplan-0.2.0/pyRadPlan/quantities/_base.py +186 -0
  78. pyradplan-0.2.0/pyRadPlan/quantities/_dose.py +31 -0
  79. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/raytracer/__init__.py +4 -4
  80. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/raytracer/_base.py +290 -289
  81. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/raytracer/_perf.py +227 -227
  82. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/raytracer/_siddon.py +396 -428
  83. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/scenarios/__init__.py +119 -102
  84. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/scenarios/_base.py +380 -374
  85. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/scenarios/_nominal.py +126 -126
  86. pyradplan-0.2.0/pyRadPlan/stf/__init__.py +23 -0
  87. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/stf/_beam.py +194 -195
  88. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/stf/_beamlet.py +112 -106
  89. pyradplan-0.2.0/pyRadPlan/stf/_exceptions.py +10 -0
  90. pyradplan-0.2.0/pyRadPlan/stf/_generate_stf.py +24 -0
  91. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/stf/_rangeshifter.py +39 -40
  92. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/stf/_ray.py +219 -201
  93. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/stf/_steeringinformation.py +185 -181
  94. {pyradplan-0.0.2/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/__init__.py +26 -29
  95. {pyradplan-0.0.2/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_base.py +207 -226
  96. {pyradplan-0.0.2/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_externalbeam.py +204 -162
  97. pyradplan-0.2.0/pyRadPlan/stf/generators/_factory.py +110 -0
  98. {pyradplan-0.0.2/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_ions.py +276 -255
  99. {pyradplan-0.0.2/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_photons.py +141 -125
  100. pyradplan-0.2.0/pyRadPlan/util/__init__.py +8 -0
  101. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/util/helpers.py +257 -209
  102. pyradplan-0.2.0/pyRadPlan/visualization/__init__.py +5 -0
  103. pyradplan-0.2.0/pyRadPlan/visualization/_plot_slice.py +105 -0
  104. pyradplan-0.2.0/pyRadPlan.egg-info/PKG-INFO +139 -0
  105. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan.egg-info/SOURCES.txt +44 -40
  106. pyradplan-0.2.0/pyRadPlan.egg-info/requires.txt +34 -0
  107. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan.egg-info/top_level.txt +0 -1
  108. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyproject.toml +165 -123
  109. {pyradplan-0.0.2 → pyradplan-0.2.0}/setup.cfg +4 -4
  110. pyradplan-0.2.0/test/conftest.py +14 -0
  111. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/core/test_coordinates.py +46 -46
  112. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/core/test_np2sitk.py +176 -178
  113. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/core/test_resample.py +45 -45
  114. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/cst/conftest.py +61 -57
  115. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/cst/test_VOI.py +422 -422
  116. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/cst/test_cst.py +253 -144
  117. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/ct/test_ct.py +218 -218
  118. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/ct/test_hlut.py +10 -10
  119. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/dose/test_dose_particle.py +231 -234
  120. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/dose/test_dose_photon.py +20 -22
  121. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/geometry/test_lps.py +96 -96
  122. pyradplan-0.2.0/test/optimization/test_fluence_optiprob.py +23 -0
  123. pyradplan-0.2.0/test/optimization/test_ipopt_solver.py +39 -0
  124. pyradplan-0.2.0/test/optimization/test_objectives.py +251 -0
  125. pyradplan-0.2.0/test/optimization/test_problem_factory.py +59 -0
  126. pyradplan-0.2.0/test/optimization/test_scipy_solver.py +33 -0
  127. pyradplan-0.2.0/test/optimization/test_solver_factory.py +31 -0
  128. pyradplan-0.2.0/test/quantities/test_dose_quantity.py +108 -0
  129. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/stf/test_beamlet.py +53 -53
  130. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/stf/test_stf.py +207 -205
  131. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/stf/test_stf_gen.py +316 -295
  132. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_dij.py +241 -238
  133. pyradplan-0.2.0/test/test_fileHandling.py +68 -0
  134. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_grid.py +148 -148
  135. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_helpers.py +93 -65
  136. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_machine_model.py +155 -155
  137. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_matlabEngine.py +28 -30
  138. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_octaveEngine.py +28 -30
  139. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_plan.py +157 -158
  140. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_raytracersiddon.py +104 -104
  141. {pyradplan-0.0.2 → pyradplan-0.2.0}/test/test_scenarios.py +204 -198
  142. pyradplan-0.2.0/test/visualization/test_plot_slice.py +85 -0
  143. pyradplan-0.0.2/.gitignore +0 -175
  144. pyradplan-0.0.2/.gitlab-ci.yml +0 -80
  145. pyradplan-0.0.2/.gitmodules +0 -4
  146. pyradplan-0.0.2/.pre-commit-config.yaml +0 -16
  147. pyradplan-0.0.2/CONTRIBUTING.md +0 -19
  148. pyradplan-0.0.2/PKG-INFO +0 -67
  149. pyradplan-0.0.2/README.md +0 -30
  150. pyradplan-0.0.2/examples/carbon_pencilbeam.py +0 -87
  151. pyradplan-0.0.2/examples/helium_pencilbeam.py +0 -80
  152. pyradplan-0.0.2/examples/photon_pencilbeam.py +0 -66
  153. pyradplan-0.0.2/examples/proton_pencilbeam.py +0 -80
  154. pyradplan-0.0.2/pyRadPlan/core/_exceptions.py +0 -9
  155. pyradplan-0.0.2/pyRadPlan/dose/engines/_svdpb.py +0 -275
  156. pyradplan-0.0.2/pyRadPlan/io/.gitkeep +0 -0
  157. pyradplan-0.0.2/pyRadPlan/io/__init__.py +0 -3
  158. pyradplan-0.0.2/pyRadPlan/io/matLabFileHandler.py +0 -25
  159. pyradplan-0.0.2/pyRadPlan/io/matRad.py +0 -22
  160. pyradplan-0.0.2/pyRadPlan/io/readHLUT.py +0 -17
  161. pyradplan-0.0.2/pyRadPlan/io/temp_files/cst.mat +0 -0
  162. pyradplan-0.0.2/pyRadPlan/io/temp_files/ct.mat +0 -0
  163. pyradplan-0.0.2/pyRadPlan/io/temp_files/pln.mat +0 -0
  164. pyradplan-0.0.2/pyRadPlan/io/temp_files/stf_with_separate_rays.mat +0 -0
  165. pyradplan-0.0.2/pyRadPlan/matRad/.gitkeep +0 -0
  166. pyradplan-0.0.2/pyRadPlan/optimization/_fluenceOptimizer.py +0 -312
  167. pyradplan-0.0.2/pyRadPlan/optimization/_fluence_optimization.py +0 -57
  168. pyradplan-0.0.2/pyRadPlan/optimization/components/__init__.py +0 -3
  169. pyradplan-0.0.2/pyRadPlan/optimization/components/_optimizationProblem.py +0 -162
  170. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_EUD.py +0 -93
  171. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/__init__.py +0 -19
  172. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_doseUniformity.py +0 -81
  173. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_maxDVH.py +0 -92
  174. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_meanDose.py +0 -80
  175. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_minDVH.py +0 -92
  176. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_objectiveClass.py +0 -98
  177. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_squaredDeviation.py +0 -82
  178. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_squaredOverdosing.py +0 -84
  179. pyradplan-0.0.2/pyRadPlan/optimization/components/objectives/_squaredUnderdosing.py +0 -84
  180. pyradplan-0.0.2/pyRadPlan/optimization/projections/__init__.py +0 -5
  181. pyradplan-0.0.2/pyRadPlan/optimization/projections/_backProjection.py +0 -59
  182. pyradplan-0.0.2/pyRadPlan/optimization/projections/_constantRBEProjection.py +0 -26
  183. pyradplan-0.0.2/pyRadPlan/optimization/projections/_doseProjection.py +0 -25
  184. pyradplan-0.0.2/pyRadPlan/optimization/solvers/__init__.py +0 -18
  185. pyradplan-0.0.2/pyRadPlan/optimization/solvers/_ipopt.py +0 -89
  186. pyradplan-0.0.2/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -120
  187. pyradplan-0.0.2/pyRadPlan/stf/_exceptions.py +0 -14
  188. pyradplan-0.0.2/pyRadPlan/stf/_generate_stf.py +0 -23
  189. pyradplan-0.0.2/pyRadPlan/stf/base_matrad.py +0 -6
  190. pyradplan-0.0.2/pyRadPlan/stf/hlutLibrary/matRad_default.hlut +0 -10
  191. pyradplan-0.0.2/pyRadPlan/stf/loadHLUT.py +0 -63
  192. pyradplan-0.0.2/pyRadPlan/util/__init__.py +0 -0
  193. pyradplan-0.0.2/pyRadPlan.egg-info/PKG-INFO +0 -67
  194. pyradplan-0.0.2/pyRadPlan.egg-info/requires.txt +0 -27
  195. pyradplan-0.0.2/test/test_fileHandling.py +0 -37
  196. pyradplan-0.0.2/test/test_objectives.py +0 -371
  197. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  198. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
  199. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/data/machines/photons_Generic.mat +0 -0
  200. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
  201. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/data/phantoms/TG119.mat +0 -0
  202. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan/data/stf/matRad_stf.mat +0 -0
  203. /pyradplan-0.0.2/pyRadPlan/data/stf/matrad_stf_onebeam.mat → /pyradplan-0.2.0/pyRadPlan/data/stf/matRad_stf_onebeam.mat +0 -0
  204. {pyradplan-0.0.2 → pyradplan-0.2.0}/pyRadPlan.egg-info/dependency_links.txt +0 -0
@@ -1,28 +1,28 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2024, DKFZ
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, DKFZ
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,139 @@
1
+ Metadata-Version: 2.2
2
+ Name: pyRadPlan
3
+ Version: 0.2.0
4
+ Summary: A python interface and reimplementation to matRad
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
+ 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>
7
+ Project-URL: Homepage, https://git.dkfz.de
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: scipy>=1.13.0
15
+ Requires-Dist: numpy>=1.26.0
16
+ Requires-Dist: pymatreader>=1.0.0
17
+ Requires-Dist: h5py>=3.11.0
18
+ Requires-Dist: regex>=2024.5.15
19
+ Requires-Dist: pydicom>=2.4.4
20
+ Requires-Dist: numba>=0.60.0
21
+ Requires-Dist: matplotlib>=3.9.2
22
+ Requires-Dist: pydantic>=2.10
23
+ Requires-Dist: numpydantic>=1.6.0
24
+ Requires-Dist: SimpleITK>=2.4.0
25
+ Requires-Dist: tqdm>=4.0.0
26
+ Requires-Dist: pint>=0.24.0
27
+ Provides-Extra: matlab
28
+ Requires-Dist: matlabengine; extra == "matlab"
29
+ Provides-Extra: octave
30
+ Requires-Dist: oct2py; extra == "octave"
31
+ Provides-Extra: gui
32
+ Requires-Dist: PyQt5; extra == "gui"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest; extra == "dev"
35
+ Requires-Dist: coverage; extra == "dev"
36
+ Requires-Dist: pytest-cov; extra == "dev"
37
+ Requires-Dist: pre-commit; extra == "dev"
38
+ Requires-Dist: sphinx; extra == "dev"
39
+ Requires-Dist: numpydoc; extra == "dev"
40
+ Requires-Dist: pydata-sphinx-theme; extra == "dev"
41
+ Requires-Dist: sphinx-design; extra == "dev"
42
+ Requires-Dist: autodoc_pydantic; extra == "dev"
43
+ Requires-Dist: sphinx-autodoc-typehints; extra == "dev"
44
+
45
+ # pyRadPlan
46
+ pyRadPlan is an open-source radiotherapy treatment planning toolkit designed for interoperability with [matRad](http://www.matRad.org).
47
+
48
+ Development is lead by the [Radiotherapy Optimization group](https://www.dkfz.de/radopt) at the [German Cancer Research Center (DKFZ)](https://www.dkfz.de)
49
+
50
+ ## Concept and Goals
51
+ pyRadPlan is a multi-modality treatment planning toolkit in python born from the established Matlab-based toolkit [matRad](http://www.matRad.org). As such, pyRadPlan aims to provide a framework as well as tools for combining dose calculation with optimization with focus on ion planning.
52
+
53
+ ### Data Structures
54
+ pyRadPlan uses a similar datastructure and workflow concept as in matRad, while trying to ensure that the corresponding datastructures can be easily imported and exported from/to matRad. This facilitates the application of either algortihms from matRad or native pyRadPlan at any stage of the treatment planning workflow.
55
+
56
+ To enforce valid datastructures, we perform validation and serialization with [`pydantic`](https://docs.pydantic.dev/latest/).
57
+ Datastructures and algorithms rely mostly on [`SimpleITK`](https://simpleitk.readthedocs.io), [`numpy`](https://numpy.org/), and [`scipy`](https://scipy.org/) for internal data representation and processing.
58
+
59
+ ### Scripting and API
60
+
61
+ #### Minimal Script using the Top-Level API
62
+ A minimal script is very similar to matRad's example [`matRad.m`](https://github.com/e0404/matRad) script:
63
+ ```python
64
+ from importlib import resources
65
+ import pymatreader
66
+ from pyRadPlan import load_patient, IonPlan, generate_stf, calc_dose_influence, fluence_optimization
67
+
68
+ # Read patient from provided TG119.mat file and validate data
69
+ tg119_path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
70
+ ct, cst = load_patient(tg119_path)
71
+
72
+ # Create a plan object
73
+ pln = IonPlan(radiation_mode="protons", machine="Generic")
74
+
75
+ # Generate Steering Geometry ("stf")
76
+ stf = generate_stf(ct, cst, pln)
77
+
78
+ # Calculate Dose Influence Matrix ("dij")
79
+ dij = calc_dose_influence(ct, cst, stf, pln)
80
+
81
+ # Fluence Optimization (objectives loaded from "cst")
82
+ fluence = fluence_optimization(ct, cst, stf, dij, pln)
83
+
84
+ # Result
85
+ result = dij.compute_result_ct_grid(fluence)
86
+ ```
87
+
88
+ This script uses the top-level API exposed when importing pyRadPlan. The top-level functions are designed to take the main data structures as input and configure the corresponding workflow step via the `Plan` using the attribute dictionaries `pln.prop*`:
89
+
90
+ | Plan property | API function | Description | ID |
91
+ | -------- | ------- | ------ | ------- |
92
+ | `prop_stf` | `generate_stf` | Create beam Geometry | generator |
93
+ | `prop_dose_calc` | `calc_dose_influence`, `calc_dose_forward` | Calculate dose matrix / distribution | engine |
94
+ | `prop_opt` | `fluence_optimization` | Optimization of beam fluences | problem
95
+
96
+ The Plan properties are dictionaries. Based on their content, the top-level-api will choose the correct implementation and configure the corresponding settings. The ID can be used in the corresponding `pln.prop*` dictionary to identify a specific implementation. E.g., `pln.prop_stf = {"generator": "IMPT"}` will select the IMPT Geometry Generator if compatible to the plan. pyRadPlan will try to set all provided configuration parameters in the dictionary and use default parameters and implementations if no keys are provided.
97
+
98
+ The top level api is designed to require minimal programming experience and to run the same planning workflows with different configurations by just changing the corresponding plan object.
99
+
100
+ #### Low-level API
101
+ Instead of using above top-level workflow functions and a central plan configuration, one can also built custom workflows instantiating the necessary algorithm objects directly, for example:
102
+
103
+ ```python
104
+ ...
105
+ from pyRadPlan.stf import StfGeneratorIMPT
106
+ # Create a plan object
107
+ pln = IonPlan(radiation_mode="protons", machine="Generic")
108
+
109
+ # Equivalent Top Level API configuration
110
+ # pln.prop_stf = {"gantry_angles": [90, 270], "couch_angles": [0, 0], "generator": "IMPT"}
111
+ # stf = generate_stf(ct,cst,pln)
112
+
113
+ # Low level:
114
+ stf_gen = StfGeneratorIMPT()
115
+ stf_gen.gantry_angles = [90, 270]
116
+ stf_gen.couch_angles = [0, 0]
117
+ stf = stf_gen.generate(ct,cst)
118
+ ```
119
+
120
+ If you are interested in helping with development, get in touch, read the contributing guidelines, and the developer note below.
121
+
122
+ ## Contributing & Notes for Developers
123
+ pyRadPlan development uses unit-testing and code formatting via pre-commit hooks to ensure clean code.
124
+ If you are a developer or want to contribute, make sure to clone the latest state via git. Then, we strongly suggest to create a virtual python environment with a suitable version and do an editable installation of pyRadPlan in dev mode: `pip install -e .[dev]`
125
+
126
+ > **Note**
127
+ > If you are using venv to create a virtual environment in the project's root folder, we suggest to name it `.venv` as this folder will be automatically excluded by all formatters and linters
128
+
129
+ This will install an editable pyRadPlan module including `pytest` and `pre-commit` in addition to the standard modules.
130
+ - **pytest** is used to run unit tests before publishing the code. Run on the test folder via `pytest test`, or choose any test file following the pytest syntax. We encourage writing at least fundamental unit tests for new code. Will also install `coverage` and the pytest extension to monitor coverage.
131
+ - **pre-commit** allows for automatic code formatting to ensure following of PEPs (mainly PEP8 and PEP257).
132
+
133
+ After successfully running `pip install -e .[dev]` check in the console that `pre-commit --version` provides a correct response.
134
+ Afterwards run `pre-commit install`. This reads the `.pre-commit_config.yaml` and adds a hook to your git repository, which whenever a commit is made the changed files are reformatted to ensure the PEP standards.
135
+
136
+ ### Matlab / Octave Files & Engine
137
+ If you want to interface via matRad, the simplest way is to write mat files using scipy's `savemat` and load them in matRad. To save a datastructure such that it can be read into Matlab and interpreted by matRad, you can call `to_matrad` on the structure and then pass the resulting dictionary to `savemat`.
138
+ You can also install the matlab engine by appending `[matlab]` to the pip install command. However, as there is some compatibility matrix for what matlabengine version is suitable for your Matlab installation, it might be better to not install the latest version but instead install the correct matlabengine manually before.
139
+ To use Octave via oct2py, analogously append `[octave]`.
@@ -0,0 +1,95 @@
1
+ # pyRadPlan
2
+ pyRadPlan is an open-source radiotherapy treatment planning toolkit designed for interoperability with [matRad](http://www.matRad.org).
3
+
4
+ Development is lead by the [Radiotherapy Optimization group](https://www.dkfz.de/radopt) at the [German Cancer Research Center (DKFZ)](https://www.dkfz.de)
5
+
6
+ ## Concept and Goals
7
+ pyRadPlan is a multi-modality treatment planning toolkit in python born from the established Matlab-based toolkit [matRad](http://www.matRad.org). As such, pyRadPlan aims to provide a framework as well as tools for combining dose calculation with optimization with focus on ion planning.
8
+
9
+ ### Data Structures
10
+ pyRadPlan uses a similar datastructure and workflow concept as in matRad, while trying to ensure that the corresponding datastructures can be easily imported and exported from/to matRad. This facilitates the application of either algortihms from matRad or native pyRadPlan at any stage of the treatment planning workflow.
11
+
12
+ To enforce valid datastructures, we perform validation and serialization with [`pydantic`](https://docs.pydantic.dev/latest/).
13
+ Datastructures and algorithms rely mostly on [`SimpleITK`](https://simpleitk.readthedocs.io), [`numpy`](https://numpy.org/), and [`scipy`](https://scipy.org/) for internal data representation and processing.
14
+
15
+ ### Scripting and API
16
+
17
+ #### Minimal Script using the Top-Level API
18
+ A minimal script is very similar to matRad's example [`matRad.m`](https://github.com/e0404/matRad) script:
19
+ ```python
20
+ from importlib import resources
21
+ import pymatreader
22
+ from pyRadPlan import load_patient, IonPlan, generate_stf, calc_dose_influence, fluence_optimization
23
+
24
+ # Read patient from provided TG119.mat file and validate data
25
+ tg119_path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
26
+ ct, cst = load_patient(tg119_path)
27
+
28
+ # Create a plan object
29
+ pln = IonPlan(radiation_mode="protons", machine="Generic")
30
+
31
+ # Generate Steering Geometry ("stf")
32
+ stf = generate_stf(ct, cst, pln)
33
+
34
+ # Calculate Dose Influence Matrix ("dij")
35
+ dij = calc_dose_influence(ct, cst, stf, pln)
36
+
37
+ # Fluence Optimization (objectives loaded from "cst")
38
+ fluence = fluence_optimization(ct, cst, stf, dij, pln)
39
+
40
+ # Result
41
+ result = dij.compute_result_ct_grid(fluence)
42
+ ```
43
+
44
+ This script uses the top-level API exposed when importing pyRadPlan. The top-level functions are designed to take the main data structures as input and configure the corresponding workflow step via the `Plan` using the attribute dictionaries `pln.prop*`:
45
+
46
+ | Plan property | API function | Description | ID |
47
+ | -------- | ------- | ------ | ------- |
48
+ | `prop_stf` | `generate_stf` | Create beam Geometry | generator |
49
+ | `prop_dose_calc` | `calc_dose_influence`, `calc_dose_forward` | Calculate dose matrix / distribution | engine |
50
+ | `prop_opt` | `fluence_optimization` | Optimization of beam fluences | problem
51
+
52
+ The Plan properties are dictionaries. Based on their content, the top-level-api will choose the correct implementation and configure the corresponding settings. The ID can be used in the corresponding `pln.prop*` dictionary to identify a specific implementation. E.g., `pln.prop_stf = {"generator": "IMPT"}` will select the IMPT Geometry Generator if compatible to the plan. pyRadPlan will try to set all provided configuration parameters in the dictionary and use default parameters and implementations if no keys are provided.
53
+
54
+ The top level api is designed to require minimal programming experience and to run the same planning workflows with different configurations by just changing the corresponding plan object.
55
+
56
+ #### Low-level API
57
+ Instead of using above top-level workflow functions and a central plan configuration, one can also built custom workflows instantiating the necessary algorithm objects directly, for example:
58
+
59
+ ```python
60
+ ...
61
+ from pyRadPlan.stf import StfGeneratorIMPT
62
+ # Create a plan object
63
+ pln = IonPlan(radiation_mode="protons", machine="Generic")
64
+
65
+ # Equivalent Top Level API configuration
66
+ # pln.prop_stf = {"gantry_angles": [90, 270], "couch_angles": [0, 0], "generator": "IMPT"}
67
+ # stf = generate_stf(ct,cst,pln)
68
+
69
+ # Low level:
70
+ stf_gen = StfGeneratorIMPT()
71
+ stf_gen.gantry_angles = [90, 270]
72
+ stf_gen.couch_angles = [0, 0]
73
+ stf = stf_gen.generate(ct,cst)
74
+ ```
75
+
76
+ If you are interested in helping with development, get in touch, read the contributing guidelines, and the developer note below.
77
+
78
+ ## Contributing & Notes for Developers
79
+ pyRadPlan development uses unit-testing and code formatting via pre-commit hooks to ensure clean code.
80
+ If you are a developer or want to contribute, make sure to clone the latest state via git. Then, we strongly suggest to create a virtual python environment with a suitable version and do an editable installation of pyRadPlan in dev mode: `pip install -e .[dev]`
81
+
82
+ > **Note**
83
+ > If you are using venv to create a virtual environment in the project's root folder, we suggest to name it `.venv` as this folder will be automatically excluded by all formatters and linters
84
+
85
+ This will install an editable pyRadPlan module including `pytest` and `pre-commit` in addition to the standard modules.
86
+ - **pytest** is used to run unit tests before publishing the code. Run on the test folder via `pytest test`, or choose any test file following the pytest syntax. We encourage writing at least fundamental unit tests for new code. Will also install `coverage` and the pytest extension to monitor coverage.
87
+ - **pre-commit** allows for automatic code formatting to ensure following of PEPs (mainly PEP8 and PEP257).
88
+
89
+ After successfully running `pip install -e .[dev]` check in the console that `pre-commit --version` provides a correct response.
90
+ Afterwards run `pre-commit install`. This reads the `.pre-commit_config.yaml` and adds a hook to your git repository, which whenever a commit is made the changed files are reformatted to ensure the PEP standards.
91
+
92
+ ### Matlab / Octave Files & Engine
93
+ If you want to interface via matRad, the simplest way is to write mat files using scipy's `savemat` and load them in matRad. To save a datastructure such that it can be read into Matlab and interpreted by matRad, you can call `to_matrad` on the structure and then pass the resulting dictionary to `savemat`.
94
+ You can also install the matlab engine by appending `[matlab]` to the pip install command. However, as there is some compatibility matrix for what matlabengine version is suitable for your Matlab installation, it might be better to not install the latest version but instead install the correct matlabengine manually before.
95
+ To use Octave via oct2py, analogously append `[octave]`.
@@ -0,0 +1,55 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ # -- Project information -----------------------------------------------------
7
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
+ import os
9
+ import sys
10
+
11
+ print(os.path.abspath("../pyRadPlan"))
12
+ sys.path.insert(0, os.path.abspath("../pyRadPlan")) # Adjust to your source folder
13
+
14
+ project = "pyRadPlan"
15
+ copyright = "2024, e0404"
16
+ author = "e0404"
17
+ release = "0.0.1"
18
+
19
+ # -- General configuration ---------------------------------------------------
20
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
21
+
22
+ extensions = [
23
+ "sphinx.ext.autodoc",
24
+ "sphinx.ext.viewcode",
25
+ "sphinx.ext.napoleon",
26
+ "numpydoc",
27
+ "sphinx_autodoc_typehints",
28
+ "sphinxcontrib.autodoc_pydantic",
29
+ "sphinx_design",
30
+ ]
31
+
32
+ templates_path = ["_templates"]
33
+ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
34
+
35
+ add_module_names = False
36
+
37
+
38
+ # -- Options for HTML output -------------------------------------------------
39
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
40
+
41
+ html_theme = "pydata_sphinx_theme"
42
+ html_static_path = ["_static"]
43
+
44
+ autodoc_type_aliases = {
45
+ "npt.ArrayLike": "npt.ArrayLike",
46
+ }
47
+
48
+ autodoc_default_options = {
49
+ "no-module": True, # Suppress the module/package labels
50
+ }
51
+
52
+ numpydoc_class_members_toctree = False
53
+
54
+ # disable show json as it otherwises crashes the documentation building at the moment
55
+ autodoc_pydantic_model_show_json = False
@@ -0,0 +1,62 @@
1
+ import logging
2
+
3
+ try:
4
+ from importlib import resources # Standard from Python 3.9+
5
+ except ImportError:
6
+ import importlib_resources as resources # Backport for older versions
7
+
8
+ import numpy as np
9
+
10
+ from pyRadPlan import (
11
+ IonPlan,
12
+ load_patient,
13
+ generate_stf,
14
+ calc_dose_influence,
15
+ fluence_optimization,
16
+ plot_slice,
17
+ )
18
+
19
+ logging.basicConfig(level=logging.INFO)
20
+
21
+ # Read patient from provided TG119.mat file and validate data
22
+ path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
23
+ ct, cst = load_patient(path)
24
+
25
+ # Create a plan object
26
+ pln = IonPlan(radiation_mode="carbon", machine="Generic")
27
+ pln.prop_stf = {"bixel_width": 4}
28
+ pln.prop_dose_calc = {"calc_bio_dose": True}
29
+ pln.prop_opt = {"solver": "scipy"}
30
+
31
+ # Generate Steering Geometry ("stf")
32
+ stf = generate_stf(ct, cst, pln)
33
+
34
+ # Calculate Dose Influence Matrix ("dij")
35
+ dij = calc_dose_influence(ct, cst, stf, pln)
36
+
37
+ # Optimize
38
+ fluence = fluence_optimization(ct, cst, stf, dij, pln)
39
+
40
+ # Result
41
+ result = dij.compute_result_ct_grid(fluence)
42
+
43
+ # Choose a slice to visualize
44
+ view_slice = int(np.round(ct.size[2] / 2))
45
+
46
+ # Visualize
47
+ plot_slice(
48
+ ct=ct,
49
+ cst=cst,
50
+ overlay=result["physical_dose"],
51
+ view_slice=view_slice,
52
+ plane="axial",
53
+ overlay_unit="Gy",
54
+ )
55
+ plot_slice(
56
+ ct=ct,
57
+ cst=cst,
58
+ overlay=result["effect"],
59
+ view_slice=view_slice,
60
+ plane="axial",
61
+ overlay_unit="dimensionless",
62
+ )
@@ -0,0 +1,51 @@
1
+ import logging
2
+
3
+ try:
4
+ from importlib import resources # Standard from Python 3.9+
5
+ except ImportError:
6
+ import importlib_resources as resources # Backport for older versions
7
+ import numpy as np
8
+
9
+ from pyRadPlan import (
10
+ IonPlan,
11
+ load_patient,
12
+ generate_stf,
13
+ calc_dose_influence,
14
+ fluence_optimization,
15
+ plot_slice,
16
+ )
17
+
18
+ logging.basicConfig(level=logging.INFO)
19
+
20
+ # Read patient from provided TG119.mat file and validate data
21
+ path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
22
+ ct, cst = load_patient(path)
23
+
24
+ # Create a plan object
25
+ pln = IonPlan(radiation_mode="helium", machine="Generic")
26
+ pln.prop_stf = {"bixel_width": 4}
27
+
28
+ # Generate Steering Geometry ("stf")
29
+ stf = generate_stf(ct, cst, pln)
30
+
31
+ # Calculate Dose Influence Matrix ("dij")
32
+ dij = calc_dose_influence(ct, cst, stf, pln)
33
+
34
+ # Optimize
35
+ fluence = fluence_optimization(ct, cst, stf, dij, pln)
36
+
37
+ # Result
38
+ result = dij.compute_result_ct_grid(fluence)
39
+
40
+ # Choose a slice to visualize
41
+ view_slice = int(np.round(ct.size[2] / 2))
42
+
43
+ # Visualize
44
+ plot_slice(
45
+ ct=ct,
46
+ cst=cst,
47
+ overlay=result["physical_dose"],
48
+ view_slice=view_slice,
49
+ plane="axial",
50
+ overlay_unit="Gy",
51
+ )
@@ -1,102 +1,97 @@
1
- """
2
- Example of importing a patient from a MatRad file and visualizing the CT,
3
- VOIs with matplotlib.
4
-
5
- Also produces a simple beam configuration and visualizes the resulting radiological depth cubes by
6
- calling the RayTracer.
7
- """
8
-
9
- # Standard Library Imports
10
- from importlib import resources
11
- import logging
12
-
13
- # Third Party Imports from pyRadPlan requirements
14
- import pymatreader
15
- import numpy as np
16
- import SimpleITK as sitk
17
- import matplotlib.pyplot as plt
18
-
19
- # pyRadPlan Module Imports
20
- from pyRadPlan.ct import validate_ct, default_hlut
21
- from pyRadPlan.cst import validate_cst
22
- from pyRadPlan.plan import IonPlan
23
- from pyRadPlan.stf import StfGeneratorIMPT
24
- from pyRadPlan.raytracer import RayTracerSiddon
25
-
26
- # Configure the Logger to show you debug information
27
- logging.basicConfig(level=logging.INFO)
28
- logging.getLogger("pyRadPlan").setLevel(logging.DEBUG)
29
-
30
- # We use importlib resources to load the TG119.mat file from the pyRadPlan.data.phantoms package
31
- files = resources.files("pyRadPlan.data.phantoms")
32
- path = files.joinpath("TG119.mat")
33
- tmp = pymatreader.read_mat(path)
34
-
35
- # The validation functions for ct and cst allow us to create valid CTs and StructureSets
36
- ct = validate_ct(tmp["ct"])
37
- cst = validate_cst(tmp["cst"], ct=ct)
38
-
39
- # Choose a slice to visualize
40
- view_slice = int(np.round(ct.size[2] / 2))
41
-
42
- # We store images as sitk.Image objects, but we can easily convert them to numpy arrays for
43
- # matplotlib. Taking a "view" here means we do not perform a deep copy of the image data.
44
- cube_hu = sitk.GetArrayViewFromImage(ct.cube_hu)
45
- plt.imshow(cube_hu[view_slice, :, :], cmap="gray")
46
-
47
- # Now let's visualize the VOIs from the StructureSet.
48
- for v, voi in enumerate(cst.vois):
49
- mask = sitk.GetArrayViewFromImage(voi.mask)
50
- plt.imshow(
51
- (v + 1) * mask[view_slice, :, :],
52
- cmap="jet",
53
- alpha=0.5 * (mask[view_slice, :, :] > 0),
54
- vmin=1,
55
- vmax=len(cst.vois),
56
- )
57
-
58
- # Since we want to do planning, we create a plan object.
59
- # We choose protons as the radiation mode and a Generic machine included with pyRadPlan
60
- pln = IonPlan(radiation_mode="protons", machine="Generic")
61
-
62
- # We use the StfGeneratorIMPT to create a simple beam configuration
63
- # with a single beam at 0 degrees
64
- stfgen = StfGeneratorIMPT(pln)
65
- stfgen.bixel_width = 5.0
66
- stfgen.gantry_angles = [90.0]
67
-
68
- # We generate the beam geometry on the CT and CST
69
- stf = stfgen.generate(ct, cst)
70
-
71
- # Now let's look at the water equivalent path length for our beam.
72
- # For that, we use a default HU->rSP table to convert our CT to water-equivalent thickness and then
73
- # call a voxel-wise RayTracing algorithm (proposed by Siddon) to calculate the radiological depth.
74
- rt = RayTracerSiddon([ct.compute_wet(default_hlut())])
75
- rad_depth_cubes = rt.trace_cubes(stf[0])
76
-
77
- # We could write the image if we want, but we don't do this by default.
78
- # sitk.WriteImage(ct.compute_wet(default_hlut()), "wet.nrrd")
79
- # sitk.WriteImage(rad_depth_cubes[0], "rad_depth_cubes.nrrd")
80
-
81
- # Let's see about our range of radiological depths
82
- rd_np = sitk.GetArrayFromImage(rad_depth_cubes[0])
83
- rd_np.ravel()[np.isnan(rd_np.ravel())] = 0
84
- min_rad_depth = np.min(rd_np)
85
- max_rad_depth = np.nanmax(rd_np)
86
- print(f"Minimum rad depth: {min_rad_depth}" f"Maximum rad depth: {max_rad_depth}")
87
-
88
- # Now we do visualization of the corresponding slice of our WEPL cube
89
- rad_depth_slice = rd_np[view_slice, :, :]
90
-
91
- plt.imshow(
92
- rad_depth_slice,
93
- cmap="jet",
94
- alpha=0.5 * (rad_depth_slice > 0.0),
95
- vmin=min_rad_depth,
96
- vmax=max_rad_depth,
97
- )
98
-
99
- # And finally, output!
100
- plt.draw()
101
- plt.pause(0.001)
102
- plt.show()
1
+ """
2
+ Example of importing a patient from a MatRad file and visualizing the CT,
3
+ VOIs with matplotlib.
4
+
5
+ Also produces a simple beam configuration and visualizes the resulting radiological depth cubes by
6
+ calling the RayTracer.
7
+ """
8
+
9
+ # Standard Library Imports
10
+ import logging
11
+
12
+ try:
13
+ from importlib import resources # Standard from Python 3.9+
14
+ except ImportError:
15
+ import importlib_resources as resources # Backport for older versions
16
+
17
+ # Third Party Imports from pyRadPlan requirements
18
+
19
+ import numpy as np
20
+ import SimpleITK as sitk
21
+ import matplotlib.pyplot as plt
22
+
23
+ # pyRadPlan Module Imports
24
+ from pyRadPlan.ct import default_hlut
25
+ from pyRadPlan.plan import IonPlan
26
+ from pyRadPlan.stf.generators import StfGeneratorIMPT
27
+ from pyRadPlan.raytracer import RayTracerSiddon
28
+ from pyRadPlan.visualization import plot_slice
29
+ from pyRadPlan.io import load_patient
30
+
31
+ # Configure the Logger to show you debug information
32
+ logging.basicConfig(level=logging.INFO)
33
+ logging.getLogger("pyRadPlan").setLevel(logging.DEBUG)
34
+
35
+ # Read patient from provided TG119.mat file and validate data
36
+ path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
37
+ ct, cst = load_patient(path)
38
+
39
+ # Choose a slice to visualize
40
+ view_slice = int(np.round(ct.size[2] / 2))
41
+
42
+ # We store images as sitk.Image objects, but we can easily convert them to numpy arrays for
43
+ # matplotlib. Taking a "view" here means we do not perform a deep copy of the image data.
44
+ cube_hu = sitk.GetArrayViewFromImage(ct.cube_hu)
45
+ plt.imshow(cube_hu[view_slice, :, :], cmap="gray")
46
+
47
+ # Now let's visualize the VOIs from the StructureSet.
48
+ for v, voi in enumerate(cst.vois):
49
+ mask = sitk.GetArrayViewFromImage(voi.mask)
50
+ plt.imshow(
51
+ (v + 1) * mask[view_slice, :, :],
52
+ cmap="jet",
53
+ alpha=0.5 * (mask[view_slice, :, :] > 0),
54
+ vmin=1,
55
+ vmax=len(cst.vois),
56
+ )
57
+
58
+ # Since we want to do planning, we create a plan object.
59
+ # We choose protons as the radiation mode and a Generic machine included with pyRadPlan
60
+ pln = IonPlan(radiation_mode="protons", machine="Generic")
61
+
62
+ # We use the StfGeneratorIMPT to create a simple beam configuration
63
+ # with a single beam at 0 degrees
64
+ stfgen = StfGeneratorIMPT(pln)
65
+ stfgen.bixel_width = 5.0
66
+ stfgen.gantry_angles = [90.0]
67
+
68
+ # We generate the beam geometry on the CT and CST
69
+ stf = stfgen.generate(ct, cst)
70
+
71
+ # Now let's look at the water equivalent path length for our beam.
72
+ # For that, we use a default HU->rSP table to convert our CT to water-equivalent thickness and then
73
+ # call a voxel-wise RayTracing algorithm (proposed by Siddon) to calculate the radiological depth.
74
+ rt = RayTracerSiddon([ct.compute_wet(default_hlut())])
75
+ rad_depth_cubes = rt.trace_cubes(stf[0])
76
+
77
+ # We could write the image if we want, but we don't do this by default.
78
+ # sitk.WriteImage(ct.compute_wet(default_hlut()), "wet.nrrd")
79
+ # sitk.WriteImage(rad_depth_cubes[0], "rad_depth_cubes.nrrd")
80
+
81
+ # Let's see about our range of radiological depths
82
+ rd_np = sitk.GetArrayFromImage(rad_depth_cubes[0])
83
+ rd_np.ravel()[np.isnan(rd_np.ravel())] = 0
84
+ min_rad_depth = np.min(rd_np)
85
+ max_rad_depth = np.nanmax(rd_np)
86
+ print(f"Minimum rad depth: {min_rad_depth}Maximum rad depth: {max_rad_depth}")
87
+
88
+ # Visualize
89
+ plot_slice(
90
+ ct=ct,
91
+ cst=cst,
92
+ overlay=rd_np,
93
+ view_slice=view_slice,
94
+ plane="axial",
95
+ overlay_unit="mm",
96
+ overlay_rel_threshold=1e-3,
97
+ )