pyRadPlan 0.3.1__tar.gz → 0.3.2__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 (210) hide show
  1. {pyradplan-0.3.1 → pyradplan-0.3.2}/PKG-INFO +2 -2
  2. pyradplan-0.3.2/examples/pencilbeam_photon_forward.py +187 -0
  3. pyradplan-0.3.2/examples/proton_mimicking.py +108 -0
  4. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/_grids.py +3 -3
  5. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/cst/_cst.py +4 -4
  6. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/cst/_voi.py +10 -2
  7. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dij/_dij.py +5 -0
  8. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base.py +2 -2
  9. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base_pencilbeam.py +4 -0
  10. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_fredmc.py +55 -27
  11. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_svdpb.py +84 -30
  12. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/__init__.py +8 -0
  13. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/base/__init__.py +6 -0
  14. pyradplan-0.3.2/pyRadPlan/machines/base/_beam_modifier.py +393 -0
  15. pyradplan-0.3.2/pyRadPlan/machines/photons/_calculate_machine_scale.py +86 -0
  16. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/__init__.py +3 -0
  17. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_objective.py +66 -4
  18. pyradplan-0.3.2/pyRadPlan/optimization/objectives/_squared_mimicking.py +49 -0
  19. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_optiprob.py +30 -11
  20. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/raytracer/_base.py +14 -2
  21. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/__init__.py +13 -1
  22. pyradplan-0.3.2/pyRadPlan/stf/_beamlet.py +403 -0
  23. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/_ray.py +7 -2
  24. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/generators/__init__.py +7 -1
  25. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_externalbeam.py +73 -0
  26. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_factory.py +1 -0
  27. pyradplan-0.3.2/pyRadPlan/stf/generators/_photons.py +258 -0
  28. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan.egg-info/PKG-INFO +2 -2
  29. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan.egg-info/SOURCES.txt +6 -0
  30. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyproject.toml +7 -5
  31. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/cst/test_VOI.py +51 -0
  32. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/cst/test_cst.py +26 -0
  33. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/dose/test_fred.py +1 -2
  34. pyradplan-0.3.2/test/machines/test_beam_modifiers.py +302 -0
  35. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/optimization/test_objectives.py +93 -46
  36. pyradplan-0.3.2/test/stf/test_beamlet.py +274 -0
  37. pyradplan-0.3.1/pyRadPlan/stf/_beamlet.py +0 -112
  38. pyradplan-0.3.1/pyRadPlan/stf/generators/_photons.py +0 -141
  39. pyradplan-0.3.1/test/stf/test_beamlet.py +0 -53
  40. {pyradplan-0.3.1 → pyradplan-0.3.2}/LICENSE +0 -0
  41. {pyradplan-0.3.1 → pyradplan-0.3.2}/README.md +0 -0
  42. {pyradplan-0.3.1 → pyradplan-0.3.2}/docs/conf.py +0 -0
  43. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/intro_minimal_photons.py +0 -0
  44. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/intro_minimal_protons.py +0 -0
  45. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/mc_fred.py +0 -0
  46. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/pencilbeam_carbon.py +0 -0
  47. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/pencilbeam_helium.py +0 -0
  48. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/pencilbeam_photon.py +0 -0
  49. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/pencilbeam_proton.py +0 -0
  50. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/pencilbeam_proton_let.py +0 -0
  51. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/pencilbeam_vhee.py +0 -0
  52. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/raytracer_rad_depth.py +0 -0
  53. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/utils_matrad.py +0 -0
  54. {pyradplan-0.3.1 → pyradplan-0.3.2}/examples/utils_plotting.py +0 -0
  55. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/__init__.py +0 -0
  56. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/analysis/__init__.py +0 -0
  57. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/analysis/_dvh.py +0 -0
  58. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/__init__.py +0 -0
  59. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/_exceptions.py +0 -0
  60. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/datamodel.py +0 -0
  61. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/np2sitk.py +0 -0
  62. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/resample.py +0 -0
  63. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/__init__.py +0 -0
  64. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/compat.py +0 -0
  65. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/helpers.py +0 -0
  66. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/typing.py +0 -0
  67. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/cst/__init__.py +0 -0
  68. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/ct/__init__.py +0 -0
  69. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/ct/_ct.py +0 -0
  70. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/ct/_hlut.py +0 -0
  71. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/data/machines/VHEE_Focused.mat +0 -0
  72. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/data/machines/VHEE_Generic.mat +0 -0
  73. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  74. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
  75. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/data/machines/photons_Generic.mat +0 -0
  76. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
  77. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/data/phantoms/TG119.mat +0 -0
  78. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dij/__init__.py +0 -0
  79. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dij/_compose_beam_dijs.py +0 -0
  80. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/__init__.py +0 -0
  81. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/_calc_dose.py +0 -0
  82. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/__init__.py +0 -0
  83. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base_montecarlo.py +0 -0
  84. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +0 -0
  85. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_factory.py +0 -0
  86. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_hongpb.py +0 -0
  87. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/geometry/__init__.py +0 -0
  88. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/geometry/lps.py +0 -0
  89. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/io/__init__.py +0 -0
  90. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/io/_matlab_file_handler.py +0 -0
  91. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/io/_patient_loader.py +0 -0
  92. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/io/matfile.py +0 -0
  93. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/_load.py +0 -0
  94. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/_validate.py +0 -0
  95. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/base/_base.py +0 -0
  96. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/base/_external_beam.py +0 -0
  97. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/base/_factory.py +0 -0
  98. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/base/_internal_beam.py +0 -0
  99. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/__init__.py +0 -0
  100. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_base.py +0 -0
  101. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_cutoff.py +0 -0
  102. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_emittance.py +0 -0
  103. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_energy.py +0 -0
  104. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_focus.py +0 -0
  105. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_ions.py +0 -0
  106. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_vhee.py +0 -0
  107. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/__init__.py +0 -0
  108. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/_base.py +0 -0
  109. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/_ions.py +0 -0
  110. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/_vhee.py +0 -0
  111. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/photons/__init__.py +0 -0
  112. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/photons/_base.py +0 -0
  113. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/photons/_linac.py +0 -0
  114. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/machines/photons/_svd_kernel.py +0 -0
  115. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/matRad/__init__.py +0 -0
  116. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/matRad/_engine.py +0 -0
  117. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/matRad/_matlab.py +0 -0
  118. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/matRad/_octave.py +0 -0
  119. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/__init__.py +0 -0
  120. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/_fluence_optimization.py +0 -0
  121. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_eud.py +0 -0
  122. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_factory.py +0 -0
  123. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_max_dvh.py +0 -0
  124. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_mean.py +0 -0
  125. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_min_dvh.py +0 -0
  126. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_squared_dev.py +0 -0
  127. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_squared_over.py +0 -0
  128. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_squared_under.py +0 -0
  129. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_std.py +0 -0
  130. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/__init__.py +0 -0
  131. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_factory.py +0 -0
  132. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_nonlin_fluence.py +0 -0
  133. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_simple_least_squares.py +0 -0
  134. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/__init__.py +0 -0
  135. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_base_solvers.py +0 -0
  136. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_factory.py +0 -0
  137. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_ipopt.py +0 -0
  138. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -0
  139. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/plan/__init__.py +0 -0
  140. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/plan/_plans.py +0 -0
  141. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/quantities/__init__.py +0 -0
  142. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/quantities/_base.py +0 -0
  143. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/quantities/_dose.py +0 -0
  144. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/quantities/_let_x_dose.py +0 -0
  145. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/raytracer/__init__.py +0 -0
  146. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/raytracer/_numba_perf.py +0 -0
  147. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/raytracer/_siddon.py +0 -0
  148. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/scenarios/__init__.py +0 -0
  149. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/scenarios/_base.py +0 -0
  150. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/scenarios/_nominal.py +0 -0
  151. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/_beam.py +0 -0
  152. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/_exceptions.py +0 -0
  153. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/_generate_stf.py +0 -0
  154. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/_rangeshifter.py +0 -0
  155. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/_steeringinformation.py +0 -0
  156. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_base.py +0 -0
  157. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_ions.py +0 -0
  158. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_vhee.py +0 -0
  159. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/util/__init__.py +0 -0
  160. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/util/helpers.py +0 -0
  161. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/util/keyboard_listener.py +0 -0
  162. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/visualization/__init__.py +0 -0
  163. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/visualization/_plot_multiple_slices.py +0 -0
  164. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan/visualization/_plot_slice.py +0 -0
  165. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan.egg-info/dependency_links.txt +0 -0
  166. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan.egg-info/requires.txt +0 -0
  167. {pyradplan-0.3.1 → pyradplan-0.3.2}/pyRadPlan.egg-info/top_level.txt +0 -0
  168. {pyradplan-0.3.1 → pyradplan-0.3.2}/setup.cfg +0 -0
  169. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/analysis/test_dvh.py +0 -0
  170. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/analysis/test_qi.py +0 -0
  171. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/compute/test_math_interp1d.py +0 -0
  172. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/compute/test_math_quantile.py +0 -0
  173. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/compute/test_namespace_conversion.py +0 -0
  174. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/conftest.py +0 -0
  175. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/core/test_coordinates.py +0 -0
  176. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/core/test_datamodel.py +0 -0
  177. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/core/test_np2sitk.py +0 -0
  178. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/core/test_resample.py +0 -0
  179. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/cst/conftest.py +0 -0
  180. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/ct/test_ct.py +0 -0
  181. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/ct/test_hlut.py +0 -0
  182. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/data/test_validate_test_data.py +0 -0
  183. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/dose/conftest.py +0 -0
  184. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/dose/test_dose_engine_base.py +0 -0
  185. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/dose/test_factory.py +0 -0
  186. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/dose/test_hongpb.py +0 -0
  187. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/dose/test_pb_geodist.py +0 -0
  188. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/dose/test_svdpb.py +0 -0
  189. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/geometry/test_lps.py +0 -0
  190. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/optimization/test_fluence_optiprob.py +0 -0
  191. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/optimization/test_ipopt_solver.py +0 -0
  192. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/optimization/test_problem_factory.py +0 -0
  193. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/optimization/test_scipy_solver.py +0 -0
  194. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/optimization/test_solver_factory.py +0 -0
  195. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/quantities/test_dose_quantity.py +0 -0
  196. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/quantities/test_let_dose_quantity.py +0 -0
  197. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/stf/test_stf.py +0 -0
  198. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/stf/test_stf_gen.py +0 -0
  199. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_dij.py +0 -0
  200. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_fileHandling.py +0 -0
  201. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_grid.py +0 -0
  202. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_helpers.py +0 -0
  203. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_machine_model.py +0 -0
  204. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_matlabEngine.py +0 -0
  205. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_octaveEngine.py +0 -0
  206. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_plan.py +0 -0
  207. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_raytracersiddon.py +0 -0
  208. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/test_scenarios.py +0 -0
  209. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/visualization/test_plot_multiple_slices.py +0 -0
  210. {pyradplan-0.3.1 → pyradplan-0.3.2}/test/visualization/test_plot_slice.py +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyRadPlan
3
- Version: 0.3.1
3
+ Version: 0.3.2
4
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>, Samir Schulz <samirshivaji.schulz@dkfz-heidelberg.de>
5
+ Author-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>, Tobias Becher <t.becher@dkfz-heidelberg.de>, Lina Bucher <lina.bucher@dkfz-heidelberg.de>, Antonios Kontopoulos <antonios.kontopoulos@dkfz-heidelberg.de>, Julius Laub <julius.laub@dkfz-heidelberg.de>, Florian Leininger <florian.leininger@dkfz-heidelberg.de>, Tim Ortkamp <tim.ortkamp@kit.edu>, Victoria Santiago Aguilar <victoria.santiagoaguilar@dkfz-heidelberg.de>, Goran Stanic <goran.stanic@dkfz-heidelberg.de>, Samir Schulz <samirshivaji.schulz@dkfz-heidelberg.de>
6
6
  Maintainer-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>, Florian Leininger <florian.leininger@dkfz-heidelberg.de>, Tobias Becher <t.becher@dkfz-heidelberg.de>, Tim Ortkamp <tim.ortkamp@kit.edu>
7
7
  Project-URL: Homepage, https://git.dkfz.de
8
8
  Classifier: Programming Language :: Python :: 3
@@ -0,0 +1,187 @@
1
+ # %% [markdown]
2
+ """# Example for photon dose calculation using pencilbeam engine."""
3
+ # %% [markdown]
4
+ # This example demonstrates how to use the pyRadPlan library to perform photon dose calculations.
5
+
6
+ # To display this script in a Jupyter Notebook, you need to install jupytext via pip and run the following command.
7
+ # This will create a .ipynb file in the same directory:
8
+
9
+ # ```bash
10
+ # pip install jupytext
11
+ # jupytext --to notebook path/to/this/file/pencilbeam_photon_forward.py
12
+
13
+ # %%
14
+ # Import necessary libraries
15
+ import logging
16
+
17
+ import numpy as np
18
+
19
+ import matplotlib.pyplot as plt
20
+
21
+ from pyRadPlan import (
22
+ PhotonPlan,
23
+ generate_stf,
24
+ calc_dose_forward,
25
+ plot_slice,
26
+ load_tg119,
27
+ )
28
+
29
+ from pyRadPlan.machines import create_bld
30
+ from pyRadPlan.stf import FieldShapeAsBLD, FieldShapeComposite
31
+
32
+ from pyRadPlan.machines.photons._calculate_machine_scale import calculate_machine_scale
33
+
34
+ logging.basicConfig(level=logging.INFO)
35
+
36
+
37
+ resolution = 1.0
38
+
39
+ leaf_width = 5
40
+ positions = [ # L-form for testing direction
41
+ [0, 0],
42
+ [-20, 20],
43
+ [-20, 10],
44
+ [-20, 0],
45
+ [-20, 0],
46
+ [-20, 0],
47
+ [-20, 0],
48
+ [-20, 0],
49
+ [-20, 0],
50
+ [0, 0],
51
+ ]
52
+ number_of_elements = len(positions)
53
+ boundaries = np.arange(
54
+ -int(number_of_elements / 2) * leaf_width, int(number_of_elements / 2) * leaf_width, leaf_width
55
+ )
56
+
57
+ mlc_information = {
58
+ "device_type": "MLC",
59
+ "device_orientation": "X",
60
+ "leaf_position_boundaries": boundaries,
61
+ "leaf_positions": positions,
62
+ "leaf_width": leaf_width,
63
+ "leaf_leakage": 0.1,
64
+ }
65
+ mlc_x = create_bld(mlc_information)
66
+ mask_mlc_x = mlc_x.calculate_transmission_mask(resolution)
67
+
68
+ jaw_info = {
69
+ "device_type": "JAW",
70
+ "device_orientation": "X",
71
+ "positions": [-20, 10],
72
+ "field_width": 70,
73
+ "leakage": 0.1,
74
+ }
75
+ jaw_x = create_bld(jaw_info)
76
+ jaw_info["field_width"] = mask_mlc_x.shape[0] * resolution
77
+ jaw_x_matching_field_width = create_bld(jaw_info)
78
+ mask_jaw_x = jaw_x_matching_field_width.calculate_transmission_mask(resolution)
79
+
80
+ mask = mask_mlc_x * mask_jaw_x
81
+
82
+ half_size = jaw_info["field_width"]
83
+ extent = [-half_size, half_size, -half_size, half_size]
84
+
85
+ fig, axes = plt.subplots(1, 3, figsize=(15, 5))
86
+
87
+ axes[0].imshow(mask_jaw_x, cmap="gray", origin="lower", extent=extent)
88
+ axes[0].set_title("Jaw Mask (IEC DICOM)")
89
+ axes[0].set_xlabel("X (mm)")
90
+ axes[0].set_ylabel("Y (mm)")
91
+
92
+ axes[1].imshow(mask_mlc_x, cmap="gray", origin="lower", extent=extent)
93
+ axes[1].set_title("MLC Mask (IEC DICOM)")
94
+ axes[1].set_xlabel("X (mm)")
95
+ axes[1].set_ylabel("Y (mm)")
96
+
97
+ axes[2].imshow(mask, cmap="gray", origin="lower", extent=extent)
98
+ axes[2].set_title("Combined Mask (IEC DICOM)")
99
+ axes[2].set_xlabel("X (mm)")
100
+ axes[2].set_ylabel("Y (mm)")
101
+
102
+ plt.tight_layout()
103
+ plt.show()
104
+
105
+ # %%
106
+ # pyRadPlan internally defines "field shapes" to represent the shape of the beamlets.
107
+ mlc_shape = FieldShapeAsBLD(energy=6.0, bld=mlc_x, resolution=resolution)
108
+ jaw_shape = FieldShapeAsBLD(energy=6.0, bld=jaw_x_matching_field_width, resolution=resolution)
109
+ combined_shape = FieldShapeComposite(energy=6.0, shapes=[mlc_shape, jaw_shape])
110
+
111
+ # Now plot the field shapes to verify their geometry in LPS BEV coordinates
112
+ fig, axes = plt.subplots(1, 3, figsize=(15, 5))
113
+ axes[0].imshow(jaw_shape.mask, cmap="gray", origin="lower", extent=extent)
114
+ axes[0].set_title("Jaw Field Shape (LPS BEV)")
115
+ axes[0].set_xlabel("X (mm)")
116
+ axes[0].set_ylabel("Y (mm)")
117
+
118
+ axes[1].imshow(mlc_shape.mask, cmap="gray", origin="lower", extent=extent)
119
+ axes[1].set_title("MLC Field Shape (LPS BEV)")
120
+ axes[1].set_xlabel("X (mm)")
121
+ axes[1].set_ylabel("Y (mm)")
122
+
123
+ axes[2].imshow(combined_shape.mask, cmap="gray", origin="lower", extent=extent)
124
+ axes[2].set_title("Combined Field Shape (LPS BEV)")
125
+ axes[2].set_xlabel("X (mm)")
126
+ axes[2].set_ylabel("Y (mm)")
127
+
128
+ plt.tight_layout()
129
+ plt.show()
130
+
131
+ # %%
132
+ # Load TG119 (provided within pyRadPlan)
133
+ ct, cst = load_tg119()
134
+
135
+ # %% [markdown]
136
+ # In this section, we create a photon therapy plan using the ParticleHongPencilBeamEngine.
137
+ # %%
138
+ # Create a plan object
139
+ pln = PhotonPlan(machine="Generic")
140
+ num_of_beams = 1
141
+ pln.prop_stf = {
142
+ "gantry_angles": np.linspace(0, 360, num_of_beams, endpoint=False),
143
+ "couch_angles": np.zeros((num_of_beams,)), # np.array([0, 270]),
144
+ "generator": "photonSingleBixel",
145
+ "field_based": True,
146
+ # "field_shape": np.rot90(mask, k=-1), #TODO: Rotation correct? Should automatically be done in ShapeFromBLD?
147
+ "blds": [mlc_x, jaw_x],
148
+ "resolution": 0.5,
149
+ "energy": 6,
150
+ }
151
+
152
+ # Generate Steering Geometry ("stf")
153
+ stf = generate_stf(ct, cst, pln)
154
+
155
+ # Machine Calibration: Calculate the conversion factor between MU and weights
156
+ machine = "Generic"
157
+ ct_dim = [64, 64, 64]
158
+ ct_resolution = [2.0, 2.0, 2.0]
159
+ num_of_ct_scen = 1
160
+
161
+ weights = calculate_machine_scale(machine, ct_dim, ct_resolution, num_of_ct_scen)
162
+
163
+ # Apply weights to the rays in the stf
164
+ for beam in stf.beams:
165
+ for ray in beam.rays:
166
+ for beamlet in ray.beamlets:
167
+ beamlet.weight *= weights
168
+
169
+ # Calculate Dose Influence Matrix ("dij")
170
+ dij = calc_dose_forward(ct, cst, stf, pln)
171
+
172
+
173
+ # %% [markdown]
174
+ # Visualize the results
175
+ # %%
176
+ # Choose a slice to visualize
177
+ view_slice = int(np.round(ct.size[1] / 2))
178
+
179
+ # Visualize
180
+ plot_slice(
181
+ ct=ct,
182
+ cst=cst,
183
+ overlay=dij["physical_dose"],
184
+ view_slice=view_slice,
185
+ plane="coronal",
186
+ overlay_unit="Gy",
187
+ )
@@ -0,0 +1,108 @@
1
+ # %% [markdown]
2
+ """# Example for proton dose mimicking of an existing dose distribution."""
3
+ # %% [markdown]
4
+ # This example demonstrates how to use the perform dose mimicking on an existing dose distribution.
5
+
6
+ # To display this script in a Jupyter Notebook, you need to install jupytext via pip and run the following command.
7
+ # This will create a .ipynb file in the same directory:
8
+
9
+ # ```bash
10
+ # pip install jupytext
11
+ # jupytext --to notebook path/to/this/file/pencilbeam_proton.py
12
+
13
+ # %%
14
+ # Import necessary libraries
15
+ import logging
16
+
17
+ import numpy as np
18
+ import SimpleITK as sitk
19
+
20
+ from pyRadPlan import (
21
+ IonPlan,
22
+ generate_stf,
23
+ calc_dose_influence,
24
+ fluence_optimization,
25
+ plot_slice,
26
+ load_tg119,
27
+ xp_utils,
28
+ )
29
+
30
+ from pyRadPlan.optimization.objectives import (
31
+ SquaredDeviation,
32
+ SquaredOverdosing,
33
+ MeanDose,
34
+ SquaredMimicking,
35
+ )
36
+
37
+
38
+ xp_utils.PREFER_GPU = False
39
+ xp_utils.PREFERRED_CPU_ARRAY_BACKEND = "numpy"
40
+ logging.basicConfig(level=logging.INFO)
41
+
42
+ # %%
43
+ # Load TG119 (provided within pyRadPlan)
44
+ ct, cst = load_tg119()
45
+
46
+ # %% [markdown]
47
+ # In this section, we create a proton therapy plan using the ParticleHongPencilBeamEngine.
48
+ # %%
49
+ # Create a plan object
50
+ pln = IonPlan(radiation_mode="protons", machine="Generic")
51
+ pln.prop_opt = {"solver": "scipy"}
52
+ pln.prop_dose_calc = {"dose_grid": ct.grid}
53
+
54
+ # Generate Steering Geometry ("stf")
55
+ stf = generate_stf(ct, cst, pln)
56
+
57
+ # Calculate Dose Influence Matrix ("dij")
58
+ dij = calc_dose_influence(ct, cst, stf, pln)
59
+
60
+ # %%
61
+ # Optimize a standard plan
62
+ # Optimization
63
+ cst.vois[0].objectives = [SquaredOverdosing(priority=10.0, d_max=1.0)] # OAR
64
+ cst.vois[1].objectives = [SquaredDeviation(priority=100.0, d_ref=3.0)] # Target
65
+ cst.vois[2].objectives = [
66
+ MeanDose(priority=1.0, d_ref=0.0),
67
+ SquaredOverdosing(priority=10.0, d_max=2.0),
68
+ ] # BODY
69
+
70
+ # Calculate optimized fluence
71
+ fluence = fluence_optimization(ct, cst, stf, dij, pln)
72
+
73
+ # Compute the result on the CT grid
74
+ result = dij.compute_result_ct_grid(fluence)
75
+
76
+ # %%
77
+ # Now let's mimick a reference dose distribution from the reference plan with noise
78
+ noise_stdev = 0.02
79
+ reference_dose = sitk.SpeckleNoise(result["physical_dose"], noise_stdev)
80
+
81
+ # Let's mimick the noisy dose distribution by using the SquaredMimicking objective.
82
+ cst.vois[1].objectives = [] # Target
83
+ cst.vois[0].objectives = [] # OAR
84
+ cst.vois[2].objectives = [SquaredMimicking(priority=1000.0, d_ref=reference_dose)] # BODY
85
+
86
+ # Calculate optimized fluence
87
+ fluence_mimicked = fluence_optimization(ct, cst, stf, dij, pln)
88
+
89
+ # Compute the result on the CT grid
90
+ result_mimicked = dij.compute_result_ct_grid(fluence_mimicked)
91
+
92
+ # %% [markdown]
93
+ # Visualize the results
94
+ # %%
95
+ # Choose a slice to visualize
96
+ view_slice = int(np.round(ct.size[2] / 2))
97
+
98
+ # Visualize
99
+ plot_slice(
100
+ ct=ct,
101
+ cst=cst,
102
+ overlay=result_mimicked["physical_dose"],
103
+ view_slice=view_slice,
104
+ plane="axial",
105
+ overlay_unit="Gy",
106
+ )
107
+
108
+ # %%
@@ -43,21 +43,21 @@ class Grid(PyRadPlanBaseModel):
43
43
 
44
44
  @computed_field
45
45
  @property
46
- def x(self) -> float:
46
+ def x(self) -> NDArray:
47
47
  """Return the x coordinates in the LPS world system."""
48
48
  x = np.arange(self.dimensions[0]) * self.resolution["x"] + self.origin[0]
49
49
  return x
50
50
 
51
51
  @computed_field
52
52
  @property
53
- def y(self) -> float:
53
+ def y(self) -> NDArray:
54
54
  """Return the y coordinates in the LPS world system."""
55
55
  y = np.arange(self.dimensions[1]) * self.resolution["y"] + self.origin[1]
56
56
  return y
57
57
 
58
58
  @computed_field
59
59
  @property
60
- def z(self) -> float:
60
+ def z(self) -> NDArray:
61
61
  """Return the z coordinates in the LPS world system."""
62
62
  z = np.arange(self.dimensions[2]) * self.resolution["z"] + self.origin[2]
63
63
  return z
@@ -38,15 +38,15 @@ class StructureSet(PyRadPlanBaseModel):
38
38
  arr = vdata_item[3]
39
39
  # return only one scenario (3D) else: Multi-Scenario (4D)
40
40
  return (
41
- [np.asarray(arr.astype(int).tolist())]
41
+ [np.asarray(arr, dtype=int).ravel()]
42
42
  if not isinstance(arr, list)
43
- else [a.astype(int).tolist() for a in arr]
43
+ else [np.asarray(a, dtype=int).ravel() for a in arr]
44
44
  )
45
45
 
46
46
  def create_mask(idx):
47
47
  # Create the ITK mask for a given index list.
48
48
  tmp_mask = np.zeros((ct.size[2], ct.size[0], ct.size[1]), dtype=np.uint8)
49
- tmp_mask.flat[np.asarray(idx) - 1] = 1
49
+ tmp_mask.flat[idx - 1] = 1
50
50
  tmp_mask = np.swapaxes(tmp_mask, 1, 2)
51
51
  mask_image = sitk.GetImageFromArray(tmp_mask)
52
52
  mask_image.CopyInformation(ct.cube_hu)
@@ -349,7 +349,7 @@ class StructureSet(PyRadPlanBaseModel):
349
349
  stats.Execute(labeled)
350
350
 
351
351
  # Step 3: Identify label with largest number of pixels
352
- largest_label = max(stats.GetLabels(), key=lambda label: stats.GetNumberOfPixels(label))
352
+ largest_label = max(stats.GetLabels(), key=stats.GetNumberOfPixels)
353
353
 
354
354
  # Step 4: Create binary mask of largest component
355
355
  body_segmentation = sitk.Equal(labeled, largest_label)
@@ -366,11 +366,19 @@ class VOI(PyRadPlanBaseModel, ABC):
366
366
  raise ValueError("new_ct must be a CT object")
367
367
 
368
368
  if self.mask.GetDimension() == 3:
369
- new_mask = sitk.Resample(self.mask, new_ct.cube_hu)
369
+ new_mask = sitk.Resample(
370
+ self.mask, new_ct.cube_hu, interpolator=sitk.sitkNearestNeighbor
371
+ )
370
372
  elif self.mask.GetDimension() == 4:
371
373
  new_mask = []
372
374
  for i in range(self.mask.GetSize()[-1]):
373
- new_mask.append(sitk.Resample(self.mask[:, :, :, i], new_ct.cube_hu))
375
+ new_mask.append(
376
+ sitk.Resample(
377
+ self.mask[:, :, :, i],
378
+ new_ct.cube_hu,
379
+ interpolator=sitk.sitkNearestNeighbor,
380
+ )
381
+ )
374
382
  new_mask = sitk.JoinSeries(new_mask)
375
383
  else:
376
384
  raise ValueError("Sanity check failed -- mask has invalid dimensions")
@@ -286,6 +286,11 @@ class Dij(PyRadPlanBaseModel):
286
286
 
287
287
  dij_dict = super().to_matrad(context=context)
288
288
 
289
+ # Replace None values with np.array([0]) for savemat compatibility
290
+ for key, value in dij_dict.items():
291
+ if value is None:
292
+ dij_dict[key] = np.array([0])
293
+
289
294
  return dij_dict
290
295
 
291
296
  def get_result_arrays_from_intensity(
@@ -27,7 +27,7 @@ from pyRadPlan.stf import SteeringInformation, validate_stf
27
27
  from pyRadPlan.plan import Plan, validate_pln
28
28
  from pyRadPlan.dij import Dij, validate_dij
29
29
  from pyRadPlan.scenarios import create_scenario_model, ScenarioModel
30
- from pyRadPlan.machines import load_machine_from_mat, validate_machine
30
+ from pyRadPlan.machines import load_machine_from_mat, validate_machine, Machine
31
31
 
32
32
  logger = logging.getLogger(__name__)
33
33
 
@@ -91,7 +91,7 @@ class DoseEngineBase(ABC):
91
91
  self._ct_grid = None
92
92
 
93
93
  # Protected properties with public get access
94
- self._machine = None # base data defined in machine file
94
+ self._machine: Machine = None # base data defined in machine file
95
95
  self._timers = None # timers of dose calc
96
96
  self._num_of_columns_dij = None # number of columns in the dij struct
97
97
  self._vox_world_coords = None # ct voxel coordinates in world
@@ -296,6 +296,7 @@ class PencilBeamEngineAbstract(DoseEngineBase):
296
296
  wed_cube_trace = self.cube_wed
297
297
 
298
298
  self._raytracer = RayTracerSiddon([wed_cube_trace])
299
+ self._raytracer.lateral_cut_off = self.geometric_lateral_cutoff
299
300
 
300
301
  return dij
301
302
 
@@ -389,6 +390,9 @@ class PencilBeamEngineAbstract(DoseEngineBase):
389
390
  start_time = time.time()
390
391
 
391
392
  self._raytracer.debug_core_performance = True
393
+ self._raytracer.lateral_cut_off = beam_info["beam"].get(
394
+ "effective_lateral_cut_off", self._effective_lateral_cutoff
395
+ )
392
396
  rad_depth_cubes = self._raytracer.trace_cubes(beam_info["beam"])
393
397
  self._raytracer.debug_core_performance = False
394
398
 
@@ -25,7 +25,7 @@ import os
25
25
  import shutil
26
26
  import subprocess
27
27
  import tempfile
28
- from typing import Any, Union
28
+ from typing import Any, Union, cast
29
29
  import time
30
30
  import textwrap
31
31
  from pathlib import Path
@@ -34,13 +34,16 @@ import numpy as np
34
34
  import SimpleITK as sitk
35
35
  from scipy import sparse
36
36
 
37
- from pyRadPlan.ct import CT, resample_ct
38
- from pyRadPlan.cst import StructureSet
39
- from pyRadPlan.dij import Dij
40
- from pyRadPlan.plan import Plan
41
- from pyRadPlan.stf import SteeringInformation
37
+ from ...core import Grid
38
+ from ...ct import CT, resample_ct
39
+ from ...cst import StructureSet
40
+ from ...dij import Dij
41
+ from ...plan import Plan
42
+ from ...stf import SteeringInformation, Beam
43
+ from ...util import swap_orientation_sparse_matrix
44
+ from ...machines.particles import IonAccelerator
45
+
42
46
  from ._base_montecarlo import MonteCarloEngineAbstract
43
- from pyRadPlan.util import swap_orientation_sparse_matrix
44
47
 
45
48
  logger = logging.getLogger(__name__)
46
49
 
@@ -321,6 +324,10 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
321
324
 
322
325
  resampled_ct.cube_hu = sitk.Cast(resampled_ct.cube_hu, sitk.sitkInt16)
323
326
 
327
+ # Force Origin to (0,0,0) and Direction to Identity to match matRad behavior
328
+ resampled_ct.cube_hu.SetOrigin((0.0, 0.0, 0.0))
329
+ resampled_ct.cube_hu.SetDirection((1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0))
330
+
324
331
  sitk.WriteImage(resampled_ct.cube_hu, file_path)
325
332
 
326
333
  max_ct_hu_value = sitk.GetArrayFromImage(resampled_ct.cube_hu).max()
@@ -566,7 +573,7 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
566
573
  else:
567
574
  fields = [("F" + str(n)) for n in list(range(field_counter))]
568
575
  file.write(
569
- "def: plan = {{ 'SAD': {}, 'Fields': [{}] }}".format(
576
+ "def: plan = {{ 'SAD': {}, 'Fields': [{}] }}\n".format(
570
577
  field["BAMS_to_iso"], ", ".join(fields)
571
578
  )
572
579
  )
@@ -603,7 +610,7 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
603
610
  The transformed isocenter coordinates in FRED's coordinate system.
604
611
  """
605
612
 
606
- dose_grid = dij["dose_grid"]
613
+ dose_grid: Grid = dij["dose_grid"]
607
614
  dose_grid_resolution = np.array(
608
615
  [
609
616
  dose_grid.resolution["x"],
@@ -787,7 +794,7 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
787
794
  "CA": beam.couch_angle,
788
795
  "field_extent": [],
789
796
  "ISO": (str(n / 10) for n in fred_iso),
790
- "BAMS_to_iso": self._machine.bams_to_iso_dist / 10,
797
+ "BAMS_to_iso": cast(IonAccelerator, self._machine).bams_to_iso_dist / 10,
791
798
  "layers": self._generate_layers_fred(beam, b),
792
799
  }
793
800
  fwhm_max = max(
@@ -806,7 +813,7 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
806
813
 
807
814
  return beams_fred
808
815
 
809
- def _generate_layers_fred(self, beam, beam_index) -> list[dict]:
816
+ def _generate_layers_fred(self, beam: Beam, beam_index: int) -> list[dict]:
810
817
  """
811
818
  Generate the FRED-compatible layers for a beam.
812
819
 
@@ -823,24 +830,37 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
823
830
  A list of dictionaries containing the layer data for FRED.
824
831
  """
825
832
  layers_fred = []
833
+ bams_to_iso = cast(IonAccelerator, self._machine).bams_to_iso_dist / 10
834
+
835
+ # Linear projection of BEV source (x,y) points to plane at BAMStoISO distance
836
+ def get_point_at_bams(target, source, distance, bams_to_iso):
837
+ return (target - source) * (-bams_to_iso) / distance + source
826
838
 
827
839
  for key, value in beam.energy_layers.items():
828
840
  pb_fred = []
829
841
  for i in range(len(value["beamlet_idx"])):
830
842
  target_point = beam.rays[value["rays_idx"][i]].target_point_bev / 10
831
- source_point = beam.source_point_bev / 10
843
+ # source_point = beam.source_point_bev / 10 #seems to not be needed in FRED
832
844
  ray_position = beam.rays[value["rays_idx"][i]].ray_pos_bev / 10
833
845
  distance = target_point[1] - ray_position[1]
834
846
 
847
+ # Project the spot to the entrance plane (BAMStoISO distance)
848
+ ray_pos_z_proj = get_point_at_bams(
849
+ target_point[2], ray_position[2], distance, bams_to_iso
850
+ )
851
+ ray_pos_x_proj = get_point_at_bams(
852
+ target_point[0], ray_position[0], distance, bams_to_iso
853
+ )
854
+
835
855
  pb_dict = {
836
856
  "ID": i,
837
857
  "fieldID": beam_index,
838
858
  "particle": beam.radiation_mode,
839
859
  "T": value["full_energy"],
840
- "position_bev": [str(ray_position[2]), str(ray_position[0]), str(0)],
860
+ "position_bev": [str(ray_pos_z_proj), str(ray_pos_x_proj), str(0)],
841
861
  "divergence": [
842
- str((target_point[2] - source_point[2]) / distance),
843
- str((target_point[0] - target_point[0]) / distance),
862
+ str((target_point[2] - ray_position[2]) / distance),
863
+ str((target_point[0] - ray_position[0]) / distance),
844
864
  str(1),
845
865
  ],
846
866
  "weight": beam.rays[value["rays_idx"][i]]
@@ -854,10 +874,11 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
854
874
 
855
875
  pb_fred.append(pb_dict)
856
876
 
857
- emittance = self._machine.foci[value["full_energy"]][0].emittance
877
+ emittance = cast(IonAccelerator, self._machine).foci[value["full_energy"]][0].emittance
858
878
  layer_dict = {
859
879
  "energy": value["full_energy"],
860
- "ESpread": self._machine.spectra[value["full_energy"]].fwhm / 2.355,
880
+ "ESpread": cast(IonAccelerator, self._machine).spectra[value["full_energy"]].fwhm
881
+ / 2.355,
861
882
  "FWHM": (
862
883
  2.355
863
884
  * (2 * emittance.sigma_x * emittance.sigma_y)
@@ -1117,13 +1138,21 @@ class ParticleFredMCEngine(MonteCarloEngineAbstract):
1117
1138
  capture_output=not self.print_output,
1118
1139
  )
1119
1140
  except subprocess.CalledProcessError as e:
1120
- stderr_msg = e.stderr.decode() if e.stderr else "No error details available"
1141
+ stdout_msg = e.stdout.decode(errors="ignore") if e.stdout else ""
1142
+ stderr_msg = e.stderr.decode(errors="ignore") if e.stderr else ""
1121
1143
  logger.error(
1122
- "FRED execution failed with return code %s. Reason: %s",
1144
+ "FRED execution failed with return code %s. stdout:\n%s\nstderr:\n%s",
1123
1145
  e.returncode,
1124
- stderr_msg,
1146
+ stdout_msg,
1147
+ stderr_msg or "No error details available",
1125
1148
  )
1126
1149
  raise SystemExit("Aborting...")
1150
+ except FileNotFoundError as e:
1151
+ logger.error(
1152
+ "FRED executable not found: %s. Ensure 'fred' is in PATH.",
1153
+ e,
1154
+ )
1155
+ raise SystemExit("Aborting... FRED not found")
1127
1156
  else:
1128
1157
  t_end = time.time()
1129
1158
  logger.info("Done in %f seconds.", t_end - t_start)
@@ -1254,12 +1283,11 @@ def read_sparse_dij_bin_v20(f_name: str) -> sparse.csc_array:
1254
1283
  for _ in range(number_of_beamlets):
1255
1284
  # Read beamlet header
1256
1285
  _ = np.frombuffer(f.read(4), dtype=np.int32)[0] # bix_num (unused)
1257
- num_vox = np.frombuffer(f.read(4), dtype=np.int32)[0]
1286
+ num_vox = int(np.frombuffer(f.read(4), dtype=np.int32)[0])
1258
1287
  beamlet_counter += 1
1259
1288
 
1260
1289
  # Update indptr
1261
- indptr.append(indptr[-1] + num_vox)
1262
-
1290
+ indptr.append(int(indptr[-1]) + num_vox)
1263
1291
  # Read voxel indices
1264
1292
  curr_voxel_indices = np.frombuffer(f.read(4 * num_vox), dtype=np.uint32)
1265
1293
  all_voxel_inds_list.append(curr_voxel_indices)
@@ -1275,7 +1303,7 @@ def read_sparse_dij_bin_v20(f_name: str) -> sparse.csc_array:
1275
1303
  # Concatenate the lists into single NumPy arrays
1276
1304
  all_values = np.concatenate(all_values_list)
1277
1305
  all_voxel_inds = np.concatenate(all_voxel_inds_list)
1278
- indptr = np.array(indptr, dtype=np.int32)
1306
+ indptr = np.array(indptr, dtype=np.int64)
1279
1307
 
1280
1308
  total_voxels = int(np.prod(dims))
1281
1309
  dij_matrix = sparse.csc_array(
@@ -1315,12 +1343,12 @@ def read_sparse_dij_bin_v21(f_name: str) -> sparse.csc_array:
1315
1343
  for _ in range(number_of_beamlets):
1316
1344
  # Read beamlet header
1317
1345
  _ = np.frombuffer(f.read(4), dtype=np.uint32)[0] # bix_num
1318
- num_vox = np.frombuffer(f.read(4), dtype=np.int32)[0]
1346
+ num_vox = int(np.frombuffer(f.read(4), dtype=np.int32)[0])
1319
1347
 
1320
1348
  beamlet_counter += 1
1321
1349
 
1322
1350
  # Update indptr
1323
- indptr.append(indptr[-1] + num_vox)
1351
+ indptr.append(int(indptr[-1]) + num_vox)
1324
1352
 
1325
1353
  # Read voxel indices
1326
1354
  curr_voxel_indices = np.frombuffer(f.read(4 * num_vox), dtype=np.uint32)
@@ -1347,7 +1375,7 @@ def read_sparse_dij_bin_v21(f_name: str) -> sparse.csc_array:
1347
1375
  # Concatenate the lists into single NumPy arrays
1348
1376
  all_values = np.concatenate(all_values_list)
1349
1377
  all_voxel_inds = np.concatenate(all_voxel_inds_list)
1350
- indptr = np.array(indptr, dtype=np.int32)
1378
+ indptr = np.array(indptr, dtype=np.int64)
1351
1379
 
1352
1380
  total_voxels = int(np.prod(dims))
1353
1381
  dij_matrix = sparse.csc_array(