pyRadPlan 0.1.0__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 (161) hide show
  1. {pyradplan-0.1.0/pyRadPlan.egg-info → pyradplan-0.2.0}/PKG-INFO +4 -5
  2. {pyradplan-0.1.0 → pyradplan-0.2.0}/README.md +3 -4
  3. pyradplan-0.2.0/examples/carbon_pencilbeam.py +62 -0
  4. pyradplan-0.2.0/examples/helium_pencilbeam.py +51 -0
  5. {pyradplan-0.1.0 → pyradplan-0.2.0}/examples/import_matrad_patient.py +17 -26
  6. {pyradplan-0.1.0 → pyradplan-0.2.0}/examples/photon_pencilbeam.py +10 -44
  7. {pyradplan-0.1.0 → pyradplan-0.2.0}/examples/proton_pencilbeam.py +11 -45
  8. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/__init__.py +6 -0
  9. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/core/__init__.py +2 -2
  10. pyradplan-0.2.0/pyRadPlan/core/_exceptions.py +5 -0
  11. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/ct/_ct.py +6 -9
  12. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/ct/_hlut.py +1 -1
  13. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dij/_dij.py +13 -74
  14. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/__init__.py +2 -0
  15. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_base.py +46 -52
  16. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_base_pencilbeam.py +28 -32
  17. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +23 -32
  18. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_hongpb.py +6 -8
  19. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_svdpb.py +25 -19
  20. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/geometry/__init__.py +2 -0
  21. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/geometry/lps.py +3 -0
  22. pyradplan-0.2.0/pyRadPlan/io/__init__.py +4 -0
  23. pyradplan-0.2.0/pyRadPlan/io/_matlab_file_handler.py +31 -0
  24. pyradplan-0.2.0/pyRadPlan/io/_patient_loader.py +113 -0
  25. pyradplan-0.2.0/pyRadPlan/io/matfile.py +35 -0
  26. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/_fluence_optimization.py +1 -2
  27. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/problems/_optiprob.py +3 -1
  28. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/solvers/_base_solvers.py +5 -13
  29. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/solvers/_ipopt.py +3 -0
  30. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/raytracer/_base.py +13 -10
  31. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/raytracer/_siddon.py +7 -40
  32. pyradplan-0.2.0/pyRadPlan/stf/__init__.py +23 -0
  33. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/stf/_beam.py +2 -2
  34. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/stf/_beamlet.py +2 -3
  35. pyradplan-0.2.0/pyRadPlan/stf/_exceptions.py +10 -0
  36. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/stf/_generate_stf.py +7 -11
  37. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/stf/_rangeshifter.py +2 -3
  38. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/stf/_ray.py +9 -13
  39. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/stf/_steeringinformation.py +6 -6
  40. {pyradplan-0.1.0/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/__init__.py +13 -16
  41. {pyradplan-0.1.0/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_base.py +5 -18
  42. {pyradplan-0.1.0/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_externalbeam.py +27 -5
  43. pyradplan-0.2.0/pyRadPlan/stf/generators/_factory.py +110 -0
  44. {pyradplan-0.1.0/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_ions.py +24 -11
  45. {pyradplan-0.1.0/pyRadPlan/stf → pyradplan-0.2.0/pyRadPlan/stf/generators}/_photons.py +6 -36
  46. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/util/helpers.py +3 -3
  47. pyradplan-0.2.0/pyRadPlan/visualization/__init__.py +5 -0
  48. pyradplan-0.2.0/pyRadPlan/visualization/_plot_slice.py +105 -0
  49. {pyradplan-0.1.0 → pyradplan-0.2.0/pyRadPlan.egg-info}/PKG-INFO +4 -5
  50. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan.egg-info/SOURCES.txt +13 -10
  51. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyproject.toml +3 -3
  52. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/core/test_coordinates.py +2 -6
  53. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/cst/test_cst.py +3 -3
  54. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/stf/test_stf.py +4 -6
  55. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/stf/test_stf_gen.py +29 -8
  56. pyradplan-0.2.0/test/test_fileHandling.py +68 -0
  57. pyradplan-0.2.0/test/visualization/test_plot_slice.py +85 -0
  58. pyradplan-0.1.0/examples/carbon_pencilbeam.py +0 -92
  59. pyradplan-0.1.0/examples/helium_pencilbeam.py +0 -84
  60. pyradplan-0.1.0/pyRadPlan/core/_exceptions.py +0 -9
  61. pyradplan-0.1.0/pyRadPlan/io/__init__.py +0 -3
  62. pyradplan-0.1.0/pyRadPlan/io/matLabFileHandler.py +0 -25
  63. pyradplan-0.1.0/pyRadPlan/io/matRad.py +0 -22
  64. pyradplan-0.1.0/pyRadPlan/io/readHLUT.py +0 -16
  65. pyradplan-0.1.0/pyRadPlan/stf/_exceptions.py +0 -14
  66. pyradplan-0.1.0/pyRadPlan/stf/base_matrad.py +0 -9
  67. pyradplan-0.1.0/pyRadPlan/stf/loadHLUT.py +0 -62
  68. pyradplan-0.1.0/test/test_fileHandling.py +0 -39
  69. {pyradplan-0.1.0 → pyradplan-0.2.0}/LICENSE +0 -0
  70. {pyradplan-0.1.0 → pyradplan-0.2.0}/docs/conf.py +0 -0
  71. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/core/_grids.py +0 -0
  72. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/core/datamodel.py +0 -0
  73. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/core/np2sitk.py +0 -0
  74. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/core/resample.py +0 -0
  75. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/cst/__init__.py +0 -0
  76. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/cst/_cst.py +0 -0
  77. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/cst/_voi.py +0 -0
  78. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/ct/__init__.py +0 -0
  79. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  80. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
  81. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/machines/photons_Generic.mat +0 -0
  82. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
  83. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/phantoms/TG119.mat +0 -0
  84. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/stf/matRad_stf.mat +0 -0
  85. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/stf/matRad_stf_onebeam.mat +0 -0
  86. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
  87. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dij/__init__.py +0 -0
  88. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/_calc_dose.py +0 -0
  89. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/engines/__init__.py +0 -0
  90. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/dose/engines/_factory.py +0 -0
  91. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/machines/__init__.py +0 -0
  92. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/machines/_base.py +0 -0
  93. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/machines/_ions.py +0 -0
  94. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/machines/_load.py +0 -0
  95. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/machines/_photons.py +0 -0
  96. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/machines/_validate.py +0 -0
  97. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/matRad/__init__.py +0 -0
  98. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/matRad/_engine.py +0 -0
  99. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/matRad/_matlab.py +0 -0
  100. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/matRad/_octave.py +0 -0
  101. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/__init__.py +0 -0
  102. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/__init__.py +0 -0
  103. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_eud.py +0 -0
  104. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_factory.py +0 -0
  105. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_max_dvh.py +0 -0
  106. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_mean.py +0 -0
  107. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_min_dvh.py +0 -0
  108. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_objective.py +0 -0
  109. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_squared_dev.py +0 -0
  110. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_squared_over.py +0 -0
  111. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_squared_under.py +0 -0
  112. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/objectives/_std.py +0 -0
  113. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/problems/__init__.py +0 -0
  114. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/problems/_factory.py +0 -0
  115. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/problems/_nonlin_fluence.py +0 -0
  116. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/problems/_simple_least_squares.py +0 -0
  117. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/solvers/__init__.py +0 -0
  118. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/solvers/_factory.py +0 -0
  119. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -0
  120. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/plan/__init__.py +0 -0
  121. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/plan/_plans.py +0 -0
  122. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/quantities/__init__.py +0 -0
  123. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/quantities/_base.py +0 -0
  124. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/quantities/_dose.py +0 -0
  125. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/raytracer/__init__.py +0 -0
  126. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/raytracer/_perf.py +0 -0
  127. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/scenarios/__init__.py +0 -0
  128. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/scenarios/_base.py +0 -0
  129. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/scenarios/_nominal.py +0 -0
  130. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan/util/__init__.py +0 -0
  131. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan.egg-info/dependency_links.txt +0 -0
  132. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan.egg-info/requires.txt +0 -0
  133. {pyradplan-0.1.0 → pyradplan-0.2.0}/pyRadPlan.egg-info/top_level.txt +0 -0
  134. {pyradplan-0.1.0 → pyradplan-0.2.0}/setup.cfg +0 -0
  135. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/conftest.py +0 -0
  136. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/core/test_np2sitk.py +0 -0
  137. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/core/test_resample.py +0 -0
  138. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/cst/conftest.py +0 -0
  139. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/cst/test_VOI.py +0 -0
  140. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/ct/test_ct.py +0 -0
  141. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/ct/test_hlut.py +0 -0
  142. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/dose/test_dose_particle.py +0 -0
  143. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/dose/test_dose_photon.py +0 -0
  144. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/geometry/test_lps.py +0 -0
  145. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/optimization/test_fluence_optiprob.py +0 -0
  146. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/optimization/test_ipopt_solver.py +0 -0
  147. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/optimization/test_objectives.py +0 -0
  148. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/optimization/test_problem_factory.py +0 -0
  149. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/optimization/test_scipy_solver.py +0 -0
  150. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/optimization/test_solver_factory.py +0 -0
  151. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/quantities/test_dose_quantity.py +0 -0
  152. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/stf/test_beamlet.py +0 -0
  153. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_dij.py +0 -0
  154. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_grid.py +0 -0
  155. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_helpers.py +0 -0
  156. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_machine_model.py +0 -0
  157. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_matlabEngine.py +0 -0
  158. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_octaveEngine.py +0 -0
  159. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_plan.py +0 -0
  160. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_raytracersiddon.py +0 -0
  161. {pyradplan-0.1.0 → pyradplan-0.2.0}/test/test_scenarios.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pyRadPlan
3
- Version: 0.1.0
3
+ Version: 0.2.0
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>
@@ -63,12 +63,11 @@ A minimal script is very similar to matRad's example [`matRad.m`](https://github
63
63
  ```python
64
64
  from importlib import resources
65
65
  import pymatreader
66
- from pyRadPlan import IonPlan, validate_ct, validate_cst, generate_stf, calc_dose_influence, fluence_optimization
66
+ from pyRadPlan import load_patient, IonPlan, generate_stf, calc_dose_influence, fluence_optimization
67
67
 
68
68
  # Read patient from provided TG119.mat file and validate data
69
- phantom = pymatreader.read_mat(resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat"))
70
- ct = validate_ct(phantom["ct"])
71
- cst = validate_cst(phantom["cst"], ct=ct)
69
+ tg119_path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
70
+ ct, cst = load_patient(tg119_path)
72
71
 
73
72
  # Create a plan object
74
73
  pln = IonPlan(radiation_mode="protons", machine="Generic")
@@ -19,12 +19,11 @@ A minimal script is very similar to matRad's example [`matRad.m`](https://github
19
19
  ```python
20
20
  from importlib import resources
21
21
  import pymatreader
22
- from pyRadPlan import IonPlan, validate_ct, validate_cst, generate_stf, calc_dose_influence, fluence_optimization
22
+ from pyRadPlan import load_patient, IonPlan, generate_stf, calc_dose_influence, fluence_optimization
23
23
 
24
24
  # Read patient from provided TG119.mat file and validate data
25
- phantom = pymatreader.read_mat(resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat"))
26
- ct = validate_ct(phantom["ct"])
27
- cst = validate_cst(phantom["cst"], ct=ct)
25
+ tg119_path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
26
+ ct, cst = load_patient(tg119_path)
28
27
 
29
28
  # Create a plan object
30
29
  pln = IonPlan(radiation_mode="protons", machine="Generic")
@@ -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
+ )
@@ -15,30 +15,26 @@ except ImportError:
15
15
  import importlib_resources as resources # Backport for older versions
16
16
 
17
17
  # Third Party Imports from pyRadPlan requirements
18
- import pymatreader
18
+
19
19
  import numpy as np
20
20
  import SimpleITK as sitk
21
21
  import matplotlib.pyplot as plt
22
22
 
23
23
  # pyRadPlan Module Imports
24
- from pyRadPlan.ct import validate_ct, default_hlut
25
- from pyRadPlan.cst import validate_cst
24
+ from pyRadPlan.ct import default_hlut
26
25
  from pyRadPlan.plan import IonPlan
27
- from pyRadPlan.stf import StfGeneratorIMPT
26
+ from pyRadPlan.stf.generators import StfGeneratorIMPT
28
27
  from pyRadPlan.raytracer import RayTracerSiddon
28
+ from pyRadPlan.visualization import plot_slice
29
+ from pyRadPlan.io import load_patient
29
30
 
30
31
  # Configure the Logger to show you debug information
31
32
  logging.basicConfig(level=logging.INFO)
32
33
  logging.getLogger("pyRadPlan").setLevel(logging.DEBUG)
33
34
 
34
- # We use importlib resources to load the TG119.mat file from the pyRadPlan.data.phantoms package
35
- files = resources.files("pyRadPlan.data.phantoms")
36
- path = files.joinpath("TG119.mat")
37
- tmp = pymatreader.read_mat(path)
38
-
39
- # The validation functions for ct and cst allow us to create valid CTs and StructureSets
40
- ct = validate_ct(tmp["ct"])
41
- cst = validate_cst(tmp["cst"], ct=ct)
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)
42
38
 
43
39
  # Choose a slice to visualize
44
40
  view_slice = int(np.round(ct.size[2] / 2))
@@ -89,18 +85,13 @@ min_rad_depth = np.min(rd_np)
89
85
  max_rad_depth = np.nanmax(rd_np)
90
86
  print(f"Minimum rad depth: {min_rad_depth}Maximum rad depth: {max_rad_depth}")
91
87
 
92
- # Now we do visualization of the corresponding slice of our WEPL cube
93
- rad_depth_slice = rd_np[view_slice, :, :]
94
-
95
- plt.imshow(
96
- rad_depth_slice,
97
- cmap="jet",
98
- alpha=0.5 * (rad_depth_slice > 0.0),
99
- vmin=min_rad_depth,
100
- vmax=max_rad_depth,
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,
101
97
  )
102
-
103
- # And finally, output!
104
- plt.draw()
105
- plt.pause(0.001)
106
- plt.show()
@@ -6,17 +6,14 @@ except ImportError:
6
6
  import importlib_resources as resources # Backport for older versions
7
7
 
8
8
  import numpy as np
9
- import SimpleITK as sitk
10
- import pymatreader
11
- import matplotlib.pyplot as plt
12
9
 
13
10
  from pyRadPlan import (
14
11
  PhotonPlan,
15
- validate_ct,
16
- validate_cst,
12
+ load_patient,
17
13
  generate_stf,
18
14
  calc_dose_influence,
19
15
  fluence_optimization,
16
+ plot_slice,
20
17
  )
21
18
 
22
19
  from pyRadPlan.optimization.objectives import SquaredDeviation, SquaredOverdosing, MeanDose
@@ -25,9 +22,7 @@ logging.basicConfig(level=logging.INFO)
25
22
 
26
23
  # Read patient from provided TG119.mat file and validate data
27
24
  path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
28
- tmp = pymatreader.read_mat(path)
29
- ct = validate_ct(tmp["ct"])
30
- cst = validate_cst(tmp["cst"], ct=ct)
25
+ ct, cst = load_patient(path)
31
26
 
32
27
  # Create a plan object
33
28
  pln = PhotonPlan(machine="Generic")
@@ -59,40 +54,11 @@ result = dij.compute_result_ct_grid(fluence)
59
54
  view_slice = int(np.round(ct.size[2] / 2))
60
55
 
61
56
  # Visualize
62
- cube_hu = sitk.GetArrayViewFromImage(ct.cube_hu)
63
- plt.imshow(cube_hu[view_slice, :, :], cmap="gray")
64
-
65
- plt.tick_params(
66
- axis="both",
67
- which="both",
68
- bottom=False,
69
- top=False,
70
- labelbottom=False,
71
- left=False,
72
- right=False,
73
- labelleft=False,
74
- )
75
-
76
- # Now let's visualize the VOIs from the StructureSet.
77
- for v, voi in enumerate(cst.vois):
78
- mask = sitk.GetArrayViewFromImage(voi.mask)
79
- cmap = plt.colormaps["cool"]
80
- color = cmap(v / len(cst.vois)) # Select color based on colormap 'cool'
81
- plt.contour(
82
- mask[view_slice, :, :],
83
- levels=[0.5],
84
- colors=[color],
85
- linewidths=1,
86
- )
87
- dose_array = sitk.GetArrayViewFromImage(result["physical_dose"])
88
- plt.imshow(
89
- dose_array[view_slice, :, :],
90
- cmap="jet",
91
- interpolation="nearest",
92
- alpha=0.5 * (dose_array[view_slice, :, :] > 0.02),
57
+ plot_slice(
58
+ ct=ct,
59
+ cst=cst,
60
+ overlay=result["physical_dose"],
61
+ view_slice=view_slice,
62
+ plane="axial",
63
+ overlay_unit="Gy",
93
64
  )
94
- plt.colorbar(label="dose [Gy]")
95
- plt.title(f"Photon Dose (Slice z={view_slice})")
96
- plt.show()
97
- plt.savefig(f"{pln.radiation_mode}_physical_dose.png")
98
- plt.clf()
@@ -6,17 +6,14 @@ except ImportError:
6
6
  import importlib_resources as resources # Backport for older versions
7
7
 
8
8
  import numpy as np
9
- import SimpleITK as sitk
10
- import pymatreader
11
- import matplotlib.pyplot as plt
12
9
 
13
10
  from pyRadPlan import (
14
11
  IonPlan,
15
- validate_ct,
16
- validate_cst,
17
12
  generate_stf,
18
13
  calc_dose_influence,
19
14
  fluence_optimization,
15
+ plot_slice,
16
+ load_patient,
20
17
  )
21
18
 
22
19
  from pyRadPlan.optimization.objectives import SquaredDeviation, SquaredOverdosing, MeanDose
@@ -25,13 +22,11 @@ logging.basicConfig(level=logging.INFO)
25
22
 
26
23
  # Read patient from provided TG119.mat file and validate data
27
24
  path = resources.files("pyRadPlan.data.phantoms").joinpath("TG119.mat")
28
- tmp = pymatreader.read_mat(path)
29
- ct = validate_ct(tmp["ct"])
30
- cst = validate_cst(tmp["cst"], ct=ct)
25
+ ct, cst = load_patient(path)
31
26
 
32
27
  # Create a plan object
33
28
  pln = IonPlan(radiation_mode="protons", machine="Generic")
34
- pln.prop_opt = {"solver": "ipopt"}
29
+ pln.prop_opt = {"solver": "scipy"}
35
30
 
36
31
  # Generate Steering Geometry ("stf")
37
32
  stf = generate_stf(ct, cst, pln)
@@ -55,40 +50,11 @@ result = dij.compute_result_ct_grid(fluence)
55
50
  view_slice = int(np.round(ct.size[2] / 2))
56
51
 
57
52
  # Visualize
58
- cube_hu = sitk.GetArrayViewFromImage(ct.cube_hu)
59
- plt.imshow(cube_hu[view_slice, :, :], cmap="gray")
60
-
61
- plt.tick_params(
62
- axis="both",
63
- which="both",
64
- bottom=False,
65
- top=False,
66
- labelbottom=False,
67
- left=False,
68
- right=False,
69
- labelleft=False,
70
- )
71
-
72
- # Now let's visualize the VOIs from the StructureSet.
73
- for v, voi in enumerate(cst.vois):
74
- mask = sitk.GetArrayViewFromImage(voi.mask)
75
- cmap = plt.colormaps["cool"]
76
- color = cmap(v / len(cst.vois)) # Select color based on colormap 'cool'
77
- plt.contour(
78
- mask[view_slice, :, :],
79
- levels=[0.5],
80
- colors=[color],
81
- linewidths=1,
82
- )
83
- dose_array = sitk.GetArrayViewFromImage(result["physical_dose"])
84
- plt.imshow(
85
- dose_array[view_slice, :, :],
86
- cmap="jet",
87
- interpolation="nearest",
88
- alpha=0.5 * (dose_array[view_slice, :, :] > 0.02),
53
+ plot_slice(
54
+ ct=ct,
55
+ cst=cst,
56
+ overlay=result["physical_dose"],
57
+ view_slice=view_slice,
58
+ plane="axial",
59
+ overlay_unit="Gy",
89
60
  )
90
- plt.colorbar(label="dose [Gy]")
91
- plt.title(f"Proton Dose (Slice z={view_slice})")
92
- plt.show()
93
- plt.savefig(f"{pln.radiation_mode}_physical_dose.png")
94
- plt.clf()
@@ -1,3 +1,5 @@
1
+ """pyRadPlan is a Python package for radiation therapy treatment planning.""" # noqa: N999
2
+
1
3
  from importlib.metadata import version, PackageNotFoundError
2
4
  import logging
3
5
 
@@ -8,6 +10,8 @@ from .stf._generate_stf import generate_stf
8
10
  from .stf import SteeringInformation, validate_stf
9
11
  from .dose._calc_dose import calc_dose_influence, calc_dose_forward
10
12
  from .optimization._fluence_optimization import fluence_optimization
13
+ from .visualization import plot_slice
14
+ from .io import load_patient
11
15
 
12
16
  try:
13
17
  __version__ = version(__name__)
@@ -34,4 +38,6 @@ __all__ = [
34
38
  "fluence_optimization",
35
39
  "SteeringInformation",
36
40
  "validate_stf",
41
+ "plot_slice",
42
+ "load_patient",
37
43
  ]
@@ -1,12 +1,12 @@
1
1
  """Core module with fundamental classes and functions for pyRadPlan."""
2
2
 
3
- from ._exceptions import PyRadPlanException
3
+ from ._exceptions import PyRadPlanError
4
4
  from .datamodel import PyRadPlanBaseModel
5
5
  from .resample import resample_image, resample_numpy_array
6
6
  from ._grids import Grid
7
7
 
8
8
  __all__ = [
9
- "PyRadPlanException",
9
+ "PyRadPlanError",
10
10
  "np2sitk",
11
11
  "resample_image",
12
12
  "resample_numpy_array",
@@ -0,0 +1,5 @@
1
+ """Contains custom exceptions for the pyRadPlan package."""
2
+
3
+
4
+ class PyRadPlanError(Exception):
5
+ """Exception for errors specifically thrown by PyRadPlan."""
@@ -1,5 +1,6 @@
1
- """Module for handling CT images in pyRadPlan. Defines a CT pydantic model and
2
- factories.
1
+ """Module for handling CT images in pyRadPlan.
2
+
3
+ Defines a CT pydantic model and factories.
3
4
  """
4
5
 
5
6
  import os
@@ -318,19 +319,15 @@ class CT(PyRadPlanBaseModel, ABC):
318
319
  -------
319
320
  np.ndarray
320
321
  The converted cube coordinates.
321
-
322
- Example Usage
323
- -------------
324
- >>> worlds_coords = beam.iso_center
325
322
  """
326
323
 
327
324
  return np.array(self.cube_hu.TransformPhysicalPointToIndex(world_coords))
328
325
 
329
326
  def compute_wet(self, hlut: np.ndarray) -> sitk.Image:
330
327
  """
331
- Compute the water equivalent thickness (WET) from the CT image and
332
- the
333
- Hounsfield Look-Up Table (HLUT).
328
+ Compute the water equivalent thickness (WET).
329
+
330
+ Uses a provided appropriate Hounsfield Look-Up Table (HLUT).
334
331
 
335
332
  Parameters
336
333
  ----------
@@ -2,7 +2,7 @@ import numpy as np
2
2
 
3
3
 
4
4
  def default_hlut(radiation_mode: str = None) -> np.ndarray:
5
- """Default HLUT by radiation mode.
5
+ """Return default HLUT by radiation mode.
6
6
 
7
7
  Parameters
8
8
  ----------
@@ -1,7 +1,4 @@
1
- """
2
- This module contains the dij class, which represents a (collection of)
3
- influence matrices.
4
- """
1
+ """Contains the dij class as a (collection of) influence matrices."""
5
2
 
6
3
  from typing import Any, Union, Annotated, cast
7
4
  from pydantic import (
@@ -26,8 +23,7 @@ from pyRadPlan.util import swap_orientation_sparse_matrix
26
23
 
27
24
  class Dij(PyRadPlanBaseModel):
28
25
  """
29
- Represents a Collection of Dose (or other quantity) Influence Matrices
30
- (DIJ) for a given plan.
26
+ Collection of Dose (or other quantity) Influence Matrices.
31
27
 
32
28
  Attributes
33
29
  ----------
@@ -71,7 +67,7 @@ class Dij(PyRadPlanBaseModel):
71
67
  @classmethod
72
68
  def validate_matrices(cls, v: Any, info: ValidationInfo) -> np.ndarray:
73
69
  """
74
- Validates the physical dose matrix.
70
+ Validate the physical dose matrix.
75
71
 
76
72
  Raises
77
73
  ------
@@ -112,7 +108,7 @@ class Dij(PyRadPlanBaseModel):
112
108
  @classmethod
113
109
  def validate_grid(cls, grid: Union[Grid, dict]) -> Union[Grid, dict]:
114
110
  """
115
- Validates grid dictionaries.
111
+ Validate grid dictionaries.
116
112
 
117
113
  Raises
118
114
  ------
@@ -127,7 +123,7 @@ class Dij(PyRadPlanBaseModel):
127
123
  @classmethod
128
124
  def validate_numbering_arrays(cls, v: np.ndarray, info: ValidationInfo) -> np.ndarray:
129
125
  """
130
- Validates the numbering arrays.
126
+ Validate the numbering arrays.
131
127
 
132
128
  Raises
133
129
  ------
@@ -158,7 +154,7 @@ class Dij(PyRadPlanBaseModel):
158
154
  cls, v: np.ndarray, info: ValidationInfo
159
155
  ) -> np.ndarray:
160
156
  """
161
- Validates the number of unique indices in beam_num.
157
+ Validate the number of unique indices in beam_num.
162
158
 
163
159
  Raises
164
160
  ------
@@ -213,10 +209,7 @@ class Dij(PyRadPlanBaseModel):
213
209
  return value
214
210
 
215
211
  def to_matrad(self, context: str = "mat-file") -> Any:
216
- """
217
- Converts the Dij object to matRad-compatible dictionary with
218
- camelCase keys.
219
- """
212
+ """Convert the Dij to matRad-compatible dictionary."""
220
213
 
221
214
  dij_dict = super().to_matrad(context=context)
222
215
 
@@ -226,7 +219,7 @@ class Dij(PyRadPlanBaseModel):
226
219
  self, intensity: np.ndarray, scenario_index: int = 0
227
220
  ) -> dict[str, np.ndarray]:
228
221
  """
229
- Applies the intensity to the dose influence matrix.
222
+ Compute result arrays from an intensity vector.
230
223
 
231
224
  Parameters
232
225
  ----------
@@ -269,8 +262,7 @@ class Dij(PyRadPlanBaseModel):
269
262
  self, intensities: np.ndarray, scenario_index: int = 0
270
263
  ) -> dict[str, sitk.Image]:
271
264
  """
272
- Applies the intensity to the dose influence matrix to get result
273
- cubes on the dose grid.
265
+ Compute results on the dose grid from intensity vector.
274
266
 
275
267
  Parameters
276
268
  ----------
@@ -301,8 +293,7 @@ class Dij(PyRadPlanBaseModel):
301
293
  self, intensities: np.ndarray, scenario_index: int = 0
302
294
  ) -> dict[str, sitk.Image]:
303
295
  """
304
- Applies the intensity to the dose influence matrix to get results on
305
- the CT grid.
296
+ Compute results on the CT grid from intensity vector.
306
297
 
307
298
  Parameters
308
299
  ----------
@@ -335,7 +326,7 @@ class Dij(PyRadPlanBaseModel):
335
326
 
336
327
  def create_dij(data: Union[dict[str, Any], Dij, None] = None, **kwargs) -> Dij:
337
328
  """
338
- Factory function to create a Plan object.
329
+ Create a Dij object from raw data or keyword arguments.
339
330
 
340
331
  Parameters
341
332
  ----------
@@ -348,11 +339,6 @@ def create_dij(data: Union[dict[str, Any], Dij, None] = None, **kwargs) -> Dij:
348
339
  -------
349
340
  Dij
350
341
  A Dij object.
351
-
352
- Raises
353
- ------
354
- ValueError
355
- If ..???
356
342
  """
357
343
 
358
344
  if data:
@@ -367,7 +353,8 @@ def create_dij(data: Union[dict[str, Any], Dij, None] = None, **kwargs) -> Dij:
367
353
 
368
354
  def validate_dij(dij: Union[dict[str, Any], Dij, None] = None, **kwargs) -> Dij:
369
355
  """
370
- Validates and creates a Dij object.
356
+ Validate and creates a Dij object.
357
+
371
358
  Synonym to create_dij but should be used in validation context.
372
359
 
373
360
  Parameters
@@ -382,53 +369,5 @@ def validate_dij(dij: Union[dict[str, Any], Dij, None] = None, **kwargs) -> Dij:
382
369
  Dij
383
370
  A validated Dij object.
384
371
 
385
- Raises
386
- ------
387
- ValueError
388
- If ... ???
389
372
  """
390
373
  return create_dij(dij, **kwargs)
391
-
392
-
393
- if __name__ == "__main__":
394
- # Implements an example usage of the Dij class.
395
- import numpy as np
396
- import pyRadPlan.io.matRad as matRadIO
397
-
398
- # Consider a dictionary of dij information in camelCase
399
- dose_information = {
400
- "ctGrid": {
401
- "resolution": {"x": 3.0, "y": 3.0, "z": 3.0},
402
- "dimensions": (167, 167, 107),
403
- "numOfVoxels": 167 * 167 * 107,
404
- },
405
- "doseGrid": {
406
- "resolution": {"x": 3.0, "y": 3.0, "z": 3.0},
407
- "dimensions": (167, 167, 107),
408
- "numOfVoxels": 167 * 167 * 107,
409
- },
410
- "numOfBeams": 2,
411
- "numOfScenarios": 1,
412
- "numOfRaysPerBeam": [255, 255],
413
- "totalNumOfBixels": 6506,
414
- "totalNumOfRays": 510,
415
- "bixelNum": np.ones(6506),
416
- "rayNum": np.ones(6506),
417
- "beamNum": np.ones(6506),
418
- "minMu": np.ones(6506),
419
- "maxMu": np.ones(6506),
420
- "numOfParticlesPerMu": np.ones(6506),
421
- "physicalDose": sp.csr_matrix((167 * 167 * 107, 6506), dtype=float),
422
- }
423
-
424
- dose_information["beamNum"][3000:] = 2
425
- # We create the DIJ object with mdoel validate
426
- dij = create_dij(**dose_information)
427
- # # print the dataclass
428
- # print(dij)
429
- # # turn it into a snake_case style dictionary
430
- # print(dij.model_dump())
431
-
432
- dij_to_matrad = dij.to_matrad(context="mat-file")
433
-
434
- matRadIO.save("dij.mat", {"dij": dij_to_matrad})
@@ -1,3 +1,5 @@
1
+ """Provide methods for calculation dose."""
2
+
1
3
  from ._calc_dose import calc_dose_influence, calc_dose_forward
2
4
 
3
5
  __all__ = [