pyRadPlan 0.3.3__tar.gz → 0.3.5__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 (212) hide show
  1. {pyradplan-0.3.3 → pyradplan-0.3.5}/PKG-INFO +3 -3
  2. {pyradplan-0.3.3 → pyradplan-0.3.5}/README.md +1 -1
  3. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/intro_minimal_photons.py +1 -1
  4. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/intro_minimal_protons.py +1 -1
  5. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/mc_fred.py +1 -1
  6. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/pencilbeam_carbon.py +1 -1
  7. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/pencilbeam_helium.py +1 -1
  8. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/pencilbeam_photon.py +1 -1
  9. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/pencilbeam_photon_forward.py +1 -1
  10. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/pencilbeam_proton.py +1 -1
  11. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/pencilbeam_proton_let.py +2 -2
  12. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/pencilbeam_vhee.py +1 -1
  13. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/proton_mimicking.py +3 -3
  14. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/raytracer_rad_depth.py +1 -1
  15. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/utils_plotting.py +13 -9
  16. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/analysis/_dvh.py +1 -1
  17. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/resample.py +19 -0
  18. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/xp_utils/helpers.py +52 -1
  19. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/cst/_cst.py +1 -1
  20. pyradplan-0.3.5/pyRadPlan/data/machines/photons_Generic.mat +0 -0
  21. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dij/_dij.py +69 -14
  22. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_base.py +1 -1
  23. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_base_pencilbeam.py +79 -37
  24. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +8 -5
  25. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_fredmc.py +1 -3
  26. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_hongpb.py +4 -1
  27. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_svdpb.py +22 -5
  28. pyradplan-0.3.5/pyRadPlan/dose/engines/kernels/_calc_geo_dists_kernel.py +232 -0
  29. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/base/_base.py +1 -3
  30. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/base/_beam_modifier.py +103 -57
  31. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/base/_external_beam.py +1 -1
  32. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/_base.py +2 -2
  33. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/_ions.py +2 -2
  34. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/photons/_linac.py +18 -5
  35. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_mean.py +1 -1
  36. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/problems/_nonlin_fluence.py +1 -1
  37. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/problems/_optiprob.py +2 -2
  38. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/solvers/_base_solvers.py +1 -1
  39. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/raytracer/_base.py +2 -2
  40. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/scenarios/_base.py +2 -2
  41. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/_beamlet.py +2 -2
  42. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/_steeringinformation.py +1 -1
  43. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/visualization/_plot_multiple_slices.py +26 -9
  44. pyradplan-0.3.5/pyRadPlan/visualization/_plot_slice.py +393 -0
  45. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan.egg-info/PKG-INFO +3 -3
  46. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan.egg-info/SOURCES.txt +2 -0
  47. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyproject.toml +8 -1
  48. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/cst/test_VOI.py +1 -1
  49. pyradplan-0.3.5/test/dose/test_base_pencilbeam.py +97 -0
  50. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/dose/test_fred.py +1 -1
  51. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/dose/test_hongpb.py +1 -1
  52. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/dose/test_svdpb.py +1 -1
  53. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/machines/test_beam_modifiers.py +1 -1
  54. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_dij.py +61 -0
  55. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_machine_model.py +4 -4
  56. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_scenarios.py +1 -1
  57. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/visualization/test_plot_multiple_slices.py +20 -19
  58. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/visualization/test_plot_slice.py +57 -10
  59. pyradplan-0.3.3/pyRadPlan/data/machines/photons_Generic.mat +0 -0
  60. pyradplan-0.3.3/pyRadPlan/visualization/_plot_slice.py +0 -214
  61. {pyradplan-0.3.3 → pyradplan-0.3.5}/LICENSE +0 -0
  62. {pyradplan-0.3.3 → pyradplan-0.3.5}/benchmark/bench_trace_cubes.py +0 -0
  63. {pyradplan-0.3.3 → pyradplan-0.3.5}/docs/conf.py +0 -0
  64. {pyradplan-0.3.3 → pyradplan-0.3.5}/examples/utils_matrad.py +0 -0
  65. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/__init__.py +0 -0
  66. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/analysis/__init__.py +0 -0
  67. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/__init__.py +0 -0
  68. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/_exceptions.py +0 -0
  69. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/_grids.py +0 -0
  70. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/datamodel.py +0 -0
  71. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/np2sitk.py +0 -0
  72. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/xp_utils/__init__.py +0 -0
  73. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/xp_utils/compat.py +0 -0
  74. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/core/xp_utils/typing.py +0 -0
  75. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/cst/__init__.py +0 -0
  76. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/cst/_voi.py +0 -0
  77. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/ct/__init__.py +0 -0
  78. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/ct/_ct.py +0 -0
  79. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/ct/_hlut.py +0 -0
  80. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/data/machines/VHEE_Focused.mat +0 -0
  81. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/data/machines/VHEE_Generic.mat +0 -0
  82. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  83. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
  84. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
  85. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/data/phantoms/TG119.mat +0 -0
  86. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dij/__init__.py +0 -0
  87. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dij/_compose_beam_dijs.py +0 -0
  88. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/__init__.py +0 -0
  89. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/_calc_dose.py +0 -0
  90. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/__init__.py +0 -0
  91. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_base_montecarlo.py +0 -0
  92. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/dose/engines/_factory.py +0 -0
  93. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/geometry/__init__.py +0 -0
  94. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/geometry/lps.py +0 -0
  95. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/io/__init__.py +0 -0
  96. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/io/_matlab_file_handler.py +0 -0
  97. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/io/_patient_loader.py +0 -0
  98. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/io/matfile.py +0 -0
  99. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/__init__.py +0 -0
  100. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/_load.py +0 -0
  101. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/_validate.py +0 -0
  102. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/base/__init__.py +0 -0
  103. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/base/_factory.py +0 -0
  104. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/base/_internal_beam.py +0 -0
  105. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/__init__.py +0 -0
  106. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/_beam_cutoff.py +0 -0
  107. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/_beam_emittance.py +0 -0
  108. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/_beam_energy.py +0 -0
  109. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/_beam_focus.py +0 -0
  110. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/_vhee.py +0 -0
  111. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/kernel/__init__.py +0 -0
  112. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/kernel/_base.py +0 -0
  113. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/kernel/_ions.py +0 -0
  114. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/particles/kernel/_vhee.py +0 -0
  115. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/photons/__init__.py +0 -0
  116. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/photons/_base.py +0 -0
  117. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/photons/_calculate_machine_scale.py +0 -0
  118. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/machines/photons/_svd_kernel.py +0 -0
  119. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/matRad/__init__.py +0 -0
  120. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/matRad/_engine.py +0 -0
  121. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/matRad/_matlab.py +0 -0
  122. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/matRad/_octave.py +0 -0
  123. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/__init__.py +0 -0
  124. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/_fluence_optimization.py +0 -0
  125. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/__init__.py +0 -0
  126. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_eud.py +0 -0
  127. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_factory.py +0 -0
  128. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_max_dvh.py +0 -0
  129. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_min_dvh.py +0 -0
  130. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_objective.py +0 -0
  131. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_squared_dev.py +0 -0
  132. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_squared_mimicking.py +0 -0
  133. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_squared_over.py +0 -0
  134. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_squared_under.py +0 -0
  135. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/objectives/_std.py +0 -0
  136. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/problems/__init__.py +0 -0
  137. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/problems/_factory.py +0 -0
  138. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/problems/_simple_least_squares.py +0 -0
  139. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/solvers/__init__.py +0 -0
  140. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/solvers/_factory.py +0 -0
  141. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/solvers/_ipopt.py +0 -0
  142. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -0
  143. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/plan/__init__.py +0 -0
  144. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/plan/_plans.py +0 -0
  145. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/quantities/__init__.py +0 -0
  146. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/quantities/_base.py +0 -0
  147. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/quantities/_dose.py +0 -0
  148. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/quantities/_let_x_dose.py +0 -0
  149. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/raytracer/__init__.py +0 -0
  150. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/raytracer/_numba_perf.py +0 -0
  151. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/raytracer/_siddon.py +0 -0
  152. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/scenarios/__init__.py +0 -0
  153. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/scenarios/_nominal.py +0 -0
  154. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/__init__.py +0 -0
  155. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/_beam.py +0 -0
  156. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/_exceptions.py +0 -0
  157. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/_generate_stf.py +0 -0
  158. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/_rangeshifter.py +0 -0
  159. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/_ray.py +0 -0
  160. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/generators/__init__.py +0 -0
  161. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/generators/_base.py +0 -0
  162. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/generators/_externalbeam.py +0 -0
  163. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/generators/_factory.py +0 -0
  164. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/generators/_ions.py +0 -0
  165. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/generators/_photons.py +0 -0
  166. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/stf/generators/_vhee.py +0 -0
  167. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/util/__init__.py +0 -0
  168. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/util/helpers.py +0 -0
  169. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/util/keyboard_listener.py +0 -0
  170. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan/visualization/__init__.py +0 -0
  171. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan.egg-info/dependency_links.txt +0 -0
  172. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan.egg-info/requires.txt +0 -0
  173. {pyradplan-0.3.3 → pyradplan-0.3.5}/pyRadPlan.egg-info/top_level.txt +0 -0
  174. {pyradplan-0.3.3 → pyradplan-0.3.5}/setup.cfg +0 -0
  175. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/analysis/test_dvh.py +0 -0
  176. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/analysis/test_qi.py +0 -0
  177. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/compute/test_math_interp1d.py +0 -0
  178. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/compute/test_math_quantile.py +0 -0
  179. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/compute/test_namespace_conversion.py +0 -0
  180. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/conftest.py +0 -0
  181. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/core/test_coordinates.py +0 -0
  182. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/core/test_datamodel.py +0 -0
  183. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/core/test_np2sitk.py +0 -0
  184. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/core/test_resample.py +0 -0
  185. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/cst/conftest.py +0 -0
  186. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/cst/test_cst.py +0 -0
  187. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/ct/test_ct.py +0 -0
  188. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/ct/test_hlut.py +0 -0
  189. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/data/test_validate_test_data.py +0 -0
  190. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/dose/conftest.py +0 -0
  191. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/dose/test_dose_engine_base.py +0 -0
  192. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/dose/test_factory.py +0 -0
  193. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/dose/test_pb_geodist.py +0 -0
  194. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/geometry/test_lps.py +0 -0
  195. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/optimization/test_fluence_optiprob.py +0 -0
  196. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/optimization/test_ipopt_solver.py +0 -0
  197. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/optimization/test_objectives.py +0 -0
  198. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/optimization/test_problem_factory.py +0 -0
  199. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/optimization/test_scipy_solver.py +0 -0
  200. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/optimization/test_solver_factory.py +0 -0
  201. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/quantities/test_dose_quantity.py +0 -0
  202. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/quantities/test_let_dose_quantity.py +0 -0
  203. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/stf/test_beamlet.py +0 -0
  204. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/stf/test_stf.py +0 -0
  205. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/stf/test_stf_gen.py +0 -0
  206. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_fileHandling.py +0 -0
  207. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_grid.py +0 -0
  208. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_helpers.py +0 -0
  209. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_matlabEngine.py +0 -0
  210. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_octaveEngine.py +0 -0
  211. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_plan.py +0 -0
  212. {pyradplan-0.3.3 → pyradplan-0.3.5}/test/test_raytracersiddon.py +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyRadPlan
3
- Version: 0.3.3
3
+ Version: 0.3.5
4
4
  Summary: A python interface and reimplementation to matRad
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>
5
+ Author-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>, Tobias Becher <t.becher@dkfz-heidelberg.de>, Lina Bucher <lina.bucher@dkfz-heidelberg.de>, Louis Ermeneux <louis.ermeneux@gmail.com>, 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>, Wilfrid Wangon Zekou <wangonwil@gmail.com>, Jennifer Josephine Hardt <jennifer.hardt@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
@@ -70,7 +70,7 @@ pyRadPlan is a multi-modality treatment planning toolkit in python born from the
70
70
  One of pyRadPlan's main goals is for its algorithms to be [Python Array API](https://data-apis.org/array-api/) conform as much as possible, to allow free choice of compute backends and devices (i.e., [`numpy`](https://numpy.org/), [`cupy`](https://cupy.dev/), [`pytorch`](https://pytorch.org/)). Further, its data structures (more precisely, their metadata) should be easily serializable for exchange with novel LLMs. This facilitate performant treatment planning research while enabling the integration of AI - such as deep neural networks implemented in [`pytorch`](https://pytorch.org/) or interaction with an LLM Agent via [`pydantic-ai`](https://ai.pydantic.dev/) - at every step of the treatment planning workflow.
71
71
 
72
72
  ### Data Structures
73
- 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.
73
+ 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 algorithms from matRad or native pyRadPlan at any stage of the treatment planning workflow.
74
74
 
75
75
  To enforce valid datastructures, we perform validation and serialization with [`pydantic`](https://docs.pydantic.dev/latest/).
76
76
  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.
@@ -19,7 +19,7 @@ pyRadPlan is a multi-modality treatment planning toolkit in python born from the
19
19
  One of pyRadPlan's main goals is for its algorithms to be [Python Array API](https://data-apis.org/array-api/) conform as much as possible, to allow free choice of compute backends and devices (i.e., [`numpy`](https://numpy.org/), [`cupy`](https://cupy.dev/), [`pytorch`](https://pytorch.org/)). Further, its data structures (more precisely, their metadata) should be easily serializable for exchange with novel LLMs. This facilitate performant treatment planning research while enabling the integration of AI - such as deep neural networks implemented in [`pytorch`](https://pytorch.org/) or interaction with an LLM Agent via [`pydantic-ai`](https://ai.pydantic.dev/) - at every step of the treatment planning workflow.
20
20
 
21
21
  ### Data Structures
22
- 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.
22
+ 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 algorithms from matRad or native pyRadPlan at any stage of the treatment planning workflow.
23
23
 
24
24
  To enforce valid datastructures, we perform validation and serialization with [`pydantic`](https://docs.pydantic.dev/latest/).
25
25
  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.
@@ -32,7 +32,7 @@ result = dij.compute_result_ct_grid(fluence)
32
32
 
33
33
  # Plot
34
34
  plot_slice(
35
- ct=ct,
35
+ image_volume=ct,
36
36
  cst=cst,
37
37
  overlay=result["physical_dose"],
38
38
  overlay_unit="Gy",
@@ -32,7 +32,7 @@ result = dij.compute_result_ct_grid(fluence)
32
32
 
33
33
  # Plot
34
34
  plot_slice(
35
- ct=ct,
35
+ image_volume=ct,
36
36
  cst=cst,
37
37
  overlay=result["physical_dose"],
38
38
  overlay_unit="Gy",
@@ -106,7 +106,7 @@ result_opt = dij.compute_result_ct_grid(fluence)
106
106
  view_slice = int(np.round(ct.size[2] / 2))
107
107
 
108
108
  plot_slice(
109
- ct=ct,
109
+ image_volume=ct,
110
110
  cst=cst,
111
111
  overlay=result_opt["physical_dose"],
112
112
  view_slice=view_slice,
@@ -60,7 +60,7 @@ view_slice = [int(np.round(ct.size[2] / 2))]
60
60
  # Use plot_distributions to visualize the biological effect and physical dose
61
61
  # use plot_slice() for single distributions
62
62
  plot_distributions(
63
- ct=ct,
63
+ image_volume=ct,
64
64
  cst=cst,
65
65
  overlays=[result["effect"], result["physical_dose"]],
66
66
  view_slice=view_slice,
@@ -68,7 +68,7 @@ view_slice = int(np.round(ct.size[2] / 2))
68
68
 
69
69
  # Visualize
70
70
  plot_slice(
71
- ct=ct,
71
+ image_volume=ct,
72
72
  cst=cst,
73
73
  overlay=result["physical_dose"],
74
74
  view_slice=view_slice,
@@ -72,7 +72,7 @@ view_slice = int(np.round(ct.size[2] / 2))
72
72
 
73
73
  # Visualize
74
74
  plot_slice(
75
- ct=ct,
75
+ image_volume=ct,
76
76
  cst=cst,
77
77
  overlay=result["physical_dose"],
78
78
  view_slice=view_slice,
@@ -178,7 +178,7 @@ view_slice = int(np.round(ct.size[1] / 2))
178
178
 
179
179
  # Visualize
180
180
  plot_slice(
181
- ct=ct,
181
+ image_volume=ct,
182
182
  cst=cst,
183
183
  overlay=dij["physical_dose"],
184
184
  view_slice=view_slice,
@@ -73,7 +73,7 @@ view_slice = int(np.round(ct.size[2] / 2))
73
73
 
74
74
  # Visualize
75
75
  plot_slice(
76
- ct=ct,
76
+ image_volume=ct,
77
77
  cst=cst,
78
78
  overlay=result["physical_dose"],
79
79
  view_slice=view_slice,
@@ -76,13 +76,13 @@ view_slice = int(np.round(ct.size[2] / 2))
76
76
 
77
77
  # Visualize
78
78
  plot_slice(
79
- ct=ct,
79
+ image_volume=ct,
80
80
  cst=cst,
81
81
  overlay=result["physical_dose"],
82
82
  view_slice=view_slice,
83
83
  )
84
84
  plot_slice(
85
- ct=ct,
85
+ image_volume=ct,
86
86
  cst=cst,
87
87
  overlay=result["let"],
88
88
  view_slice=view_slice,
@@ -81,7 +81,7 @@ view_slice = int(np.round(ct.size[2] / 2))
81
81
 
82
82
  # Visualize
83
83
  plot_slice(
84
- ct=ct,
84
+ image_volume=ct,
85
85
  cst=cst,
86
86
  overlay=result["physical_dose"],
87
87
  view_slice=view_slice,
@@ -74,11 +74,11 @@ fluence = fluence_optimization(ct, cst, stf, dij, pln)
74
74
  result = dij.compute_result_ct_grid(fluence)
75
75
 
76
76
  # %%
77
- # Now let's mimick a reference dose distribution from the reference plan with noise
77
+ # Now let's mimic a reference dose distribution from the reference plan with noise
78
78
  noise_stdev = 0.02
79
79
  reference_dose = sitk.SpeckleNoise(result["physical_dose"], noise_stdev)
80
80
 
81
- # Let's mimick the noisy dose distribution by using the SquaredMimicking objective.
81
+ # Let's mimic the noisy dose distribution by using the SquaredMimicking objective.
82
82
  cst.vois[1].objectives = [] # Target
83
83
  cst.vois[0].objectives = [] # OAR
84
84
  cst.vois[2].objectives = [SquaredMimicking(priority=1000.0, d_ref=reference_dose)] # BODY
@@ -97,7 +97,7 @@ view_slice = int(np.round(ct.size[2] / 2))
97
97
 
98
98
  # Visualize
99
99
  plot_slice(
100
- ct=ct,
100
+ image_volume=ct,
101
101
  cst=cst,
102
102
  overlay=result_mimicked["physical_dose"],
103
103
  view_slice=view_slice,
@@ -95,7 +95,7 @@ print(f"Minimum rad depth: {min_rad_depth}Maximum rad depth: {max_rad_depth}")
95
95
 
96
96
  # Visualize
97
97
  plot_slice(
98
- ct=ct,
98
+ image_volume=ct,
99
99
  cst=cst,
100
100
  overlay=rd_np,
101
101
  view_slice=view_slice,
@@ -54,11 +54,11 @@ result = dij.compute_result_ct_grid(fluence)
54
54
  # ### Visualizing a single slice with `plot_slice()`
55
55
  # %%
56
56
 
57
- # Visualize only ct and choosen quantity
58
- plot_slice(ct=ct, overlay=result["physical_dose"])
57
+ # Visualize only ct and chosen quantity
58
+ plot_slice(image_volume=ct, overlay=result["physical_dose"])
59
59
 
60
- # Visualize ct, cst and choosen quantity
61
- plot_slice(ct=ct, cst=cst, overlay=result["physical_dose"])
60
+ # Visualize ct, cst and chosen quantity
61
+ plot_slice(image_volume=ct, cst=cst, overlay=result["physical_dose"])
62
62
 
63
63
  # %% [markdown]
64
64
  # ## Visualze more abstract settings using `plot_slice()` <br>
@@ -79,7 +79,7 @@ plot_slice(ct=ct, cst=cst, overlay=result["physical_dose"])
79
79
  # %%
80
80
  # Feel free to change the parameters to see how they affect the plot.
81
81
  plot_slice(
82
- ct=ct,
82
+ image_volume=ct,
83
83
  cst=cst,
84
84
  overlay=result["physical_dose"],
85
85
  view_slice=64, # Visualize slice 10
@@ -94,7 +94,7 @@ plot_slice(
94
94
  )
95
95
 
96
96
  # %% [markdown]
97
- # ### Visualizing multiple overlays/quantites with `plot_distributions()`
97
+ # ### Visualizing multiple overlays/quantities with `plot_distributions()`
98
98
  # This function might be useful in cases you want to compare multiple overlays/quantities/beams side by side.
99
99
 
100
100
  # `plot_distributions()` has similar parameters to `plot_slice()`:
@@ -112,9 +112,13 @@ plot_slice(
112
112
  # - **use_global_max**: If True, uses the global maximum of the overlay for scaling
113
113
  # - **overlay_titles**: Custom titles for each overlay type (optional)
114
114
  # %%
115
+ plot_multiple_slices(
116
+ image_volume=ct,
117
+ )
118
+ # %%
115
119
  # Feel free to change the parameters to see how they affect the plot.
116
120
  plot_multiple_slices(
117
- ct=ct,
121
+ image_volume=ct,
118
122
  cst=cst,
119
123
  overlays=[result["physical_dose"], result["effect"]],
120
124
  view_slice=[64, 65], # Visualize slices 64 and 65
@@ -140,7 +144,7 @@ fig, axes = plt.subplots(2, 2, figsize=(12, 10))
140
144
  # Plot physical dose for both slices
141
145
  for i, slice_idx in enumerate(slices):
142
146
  plot_slice(
143
- ct=ct,
147
+ image_volume=ct,
144
148
  cst=cst,
145
149
  overlay=result["physical_dose"],
146
150
  view_slice=slice_idx, # Single slice
@@ -154,7 +158,7 @@ for i, slice_idx in enumerate(slices):
154
158
  # Plot biological effect for both slices
155
159
  for i, slice_idx in enumerate(slices):
156
160
  plot_slice(
157
- ct=ct,
161
+ image_volume=ct,
158
162
  cst=cst,
159
163
  overlay=result["effect"],
160
164
  view_slice=slice_idx, # Single slice
@@ -134,7 +134,7 @@ class DVH(PyRadPlanBaseModel):
134
134
  Notes
135
135
  -----
136
136
  The x ccoordinate (dose/quantity) corresponds to the histograms
137
- bin center for the differntial DVH. This is because the differential
137
+ bin center for the differential DVH. This is because the differential
138
138
  DVH captures the relative volume within a bin, thus the center
139
139
  represents the dose/quantity value for that bin best.
140
140
  Be aware of this difference to the cumulative DVH.
@@ -1,5 +1,7 @@
1
1
  """Image / Grid Resampling."""
2
2
 
3
+ from typing import Literal, Union
4
+
3
5
  import numpy as np
4
6
  import SimpleITK as sitk
5
7
  from ._grids import Grid
@@ -11,6 +13,7 @@ def resample_image(
11
13
  target_image: sitk.Image = None,
12
14
  target_grid_spacing: tuple[float, float, float] = None,
13
15
  target_grid: Grid = None,
16
+ extrapolate: Union[float, int, bool, Literal["nearest"]] = "nearest",
14
17
  ) -> sitk.Image: # also accept sitk images and grid points. Can be dealt with with kwargs
15
18
  """
16
19
  Resample an sitk Image.
@@ -23,6 +26,8 @@ def resample_image(
23
26
  The input image to be resampled.
24
27
  interpolator : sitk.InterpolatorEnum, optional
25
28
  The interpolator to use for resampling. Default is sitk.sitkBSpline.
29
+ extrapolate : Union[float, int, bool, Literal["nearest"], None], optional
30
+ The value to use for extrapolation outside the image boundaries. Default is None.
26
31
  target_image : sitk.Image, optional
27
32
  The reference image to resample to. Default is None.
28
33
  target_grid_spacing : tuple[float,float,float], optional
@@ -53,6 +58,18 @@ def resample_image(
53
58
  target_grid = image_grid.resample(target_grid_spacing)
54
59
 
55
60
  resample = sitk.ResampleImageFilter()
61
+ resample.UseNearestNeighborExtrapolatorOff()
62
+ if extrapolate == "nearest":
63
+ resample.UseNearestNeighborExtrapolatorOn()
64
+ elif isinstance(extrapolate, (int, float)):
65
+ resample.SetDefaultPixelValue(extrapolate)
66
+ elif extrapolate is False:
67
+ resample.SetDefaultPixelValue(0)
68
+ elif extrapolate is True:
69
+ resample.SetDefaultPixelValue(1)
70
+ else:
71
+ raise ValueError("Invalid value for 'extrapolate' parameter.")
72
+
56
73
  resample.SetOutputSpacing(target_grid.resolution_vector)
57
74
  resample.SetSize(target_grid.dimensions)
58
75
  resample.SetOutputDirection(target_grid.direction.ravel())
@@ -71,6 +88,7 @@ def resample_numpy_array(
71
88
  target_image: sitk.Image = None,
72
89
  target_grid_spacing: tuple[float, float, float] = None,
73
90
  target_grid: Grid = None,
91
+ extrapolate: Union[float, int, bool, Literal["nearest"]] = "nearest",
74
92
  ) -> np.ndarray:
75
93
  """
76
94
  Resample a numpy grid.
@@ -130,6 +148,7 @@ def resample_numpy_array(
130
148
  target_image=target_image,
131
149
  target_grid_spacing=target_grid_spacing,
132
150
  target_grid=target_grid,
151
+ extrapolate=extrapolate,
133
152
  )
134
153
 
135
154
  return sitk.GetArrayFromImage(resampled_array_sitk)
@@ -277,7 +277,7 @@ def _convert_scipy_sparse_for_namespace(
277
277
 
278
278
  if array_api_compat.is_cupy_namespace(xp_new) and cp is not None:
279
279
  try:
280
- # Access the copy constructur from the fmt string
280
+ # Access the copy constructor from the fmt string
281
281
  f_create = getattr(csp, fmt + "_matrix")
282
282
  except AttributeError:
283
283
  sparray = sparray.tocoo()
@@ -383,3 +383,54 @@ def is_sparse_array(arr: Any) -> bool:
383
383
  return True
384
384
 
385
385
  raise TypeError("Sparse check helper not implemented for type '{}'.".format(type(arr)))
386
+
387
+
388
+ def _rebuild_scipy_csc_in_namespace(
389
+ xp_new: ArrayNamespace,
390
+ data: Array,
391
+ indices: Array,
392
+ indptr: Array,
393
+ shape: tuple,
394
+ ) -> Union[scp.spmatrix, scp.sparray]:
395
+ """Reconstruct a CSC sparse matrix in *xp_new* from pre-converted component arrays.
396
+
397
+ This is a low-level helper used by :meth:`Dij.to_namespace` to avoid uploading
398
+ shared row-index arrays more than once when multiple dose quantities share the
399
+ same CSC index storage (as assembled by the pencil-beam engine).
400
+
401
+ Parameters
402
+ ----------
403
+ xp_new :
404
+ Target array namespace (numpy, cupy, torch, …).
405
+ data :
406
+ Non-zero values already in *xp_new*.
407
+ indices :
408
+ CSC row-index array already in *xp_new*.
409
+ indptr :
410
+ CSC column-pointer array already in *xp_new*.
411
+ shape :
412
+ Matrix shape ``(nrows, ncols)``.
413
+
414
+ Returns
415
+ -------
416
+ Sparse matrix compatible with *xp_new*.
417
+
418
+ Raises
419
+ ------
420
+ TypeError
421
+ If rebuilding is not yet supported for *xp_new*.
422
+ """
423
+ if array_api_compat.is_numpy_namespace(
424
+ xp_new
425
+ ) or array_api_compat.is_array_api_strict_namespace(xp_new):
426
+ return scp.csc_array((data, indices, indptr), shape=shape, copy=False)
427
+
428
+ if array_api_compat.is_cupy_namespace(xp_new) and cp is not None:
429
+ return csp.csc_matrix((data, indices, indptr), shape=shape)
430
+
431
+ if array_api_compat.is_torch_namespace(xp_new) and torch is not None:
432
+ return torch.sparse_csc_tensor(indptr, indices, data, size=shape)
433
+
434
+ raise TypeError(
435
+ f"Rebuilding a CSC sparse matrix in namespace '{xp_new.__name__}' is not yet supported."
436
+ )
@@ -292,7 +292,7 @@ class StructureSet(PyRadPlanBaseModel):
292
292
  curr_voi = self.vois[ix_voi].model_copy()
293
293
  curr_mask = curr_voi.mask
294
294
 
295
- # if the overlap prirority is higher than we need to apply overlap
295
+ # if the overlap priority is higher than we need to apply overlap
296
296
  if curr_voi.overlap_priority >= new_vois[ix_sorted[i - 1]].overlap_priority:
297
297
  if curr_voi.overlap_priority > new_vois[ix_sorted[i - 1]].overlap_priority:
298
298
  last_priority_mask = overlap_mask
@@ -29,6 +29,7 @@ from pyRadPlan.core import PyRadPlanBaseModel
29
29
  from pyRadPlan.util import swap_orientation_sparse_matrix
30
30
 
31
31
  from ..core.xp_utils import to_namespace
32
+ from ..core.xp_utils.helpers import _rebuild_scipy_csc_in_namespace
32
33
 
33
34
  InfluenceMatrixArray = Union[Array, sp.spmatrix, sp.sparray]
34
35
  InfluenceMatrixContainer = NDArray[Shape["*, ..."], object]
@@ -256,7 +257,7 @@ class Dij(PyRadPlanBaseModel):
256
257
  )
257
258
  if value.flat[i] is not None and not isinstance(value.flat[i], sp.csc_matrix):
258
259
  value.flat[i] = sp.csc_matrix(value.flat[i])
259
- # return 0 if value is None. savemat() cant handle 'None'
260
+ # return 0 if value is None. savemat() can't handle 'None'
260
261
  elif context and context.get("matRad") == "mat-file" and value is None:
261
262
  value = np.array([0])
262
263
  return value
@@ -267,7 +268,7 @@ class Dij(PyRadPlanBaseModel):
267
268
  if context and context.get("matRad") == "mat-file" and value is not None:
268
269
  # TODO: it might be necessary to rotate the cube!
269
270
  return value
270
- # return 0 if value is None. savemat() cant handle 'None'
271
+ # return 0 if value is None. savemat() can't handle 'None'
271
272
  elif context and context.get("matRad") == "mat-file" and value is None:
272
273
  value = np.array([0])
273
274
  return value
@@ -319,7 +320,7 @@ class Dij(PyRadPlanBaseModel):
319
320
  out["physical_dose"] = self.physical_dose.flat[scenario_index] @ intensity
320
321
  out["physical_dose_beam"] = []
321
322
 
322
- # !Note: This implementaion is faster than the intuitive:
323
+ # !Note: This implementation is faster than the intuitive:
323
324
  # out_example = self.physical_dose.flat[scenario_index]@(intensity*beam_mask)
324
325
  # Since slicing over the intensity vector reduces the matrix operation size.
325
326
  for i in range(self.num_of_beams):
@@ -471,23 +472,77 @@ class Dij(PyRadPlanBaseModel):
471
472
  Default is True.
472
473
  """
473
474
 
474
- # We need to check this deep copy, if it can be avoided (or does it even copy the full
475
- # NDArray object containers? Not sure)
476
- dij_copy = self.model_copy(deep=True)
475
+ # record memory addresses here, before model_copy would break the sharing.
476
+ _shared_idx_cache: dict[int, tuple | None] = {}
477
+ if keep_sparse_compat:
478
+ for q in self.quantities:
479
+ q_container = getattr(self, q)
480
+ if q_container is None:
481
+ continue
482
+ for i in range(q_container.size):
483
+ mat = q_container.flat[i]
484
+ if mat is not None and isinstance(mat, (sp.csc_matrix, sp.csc_array)):
485
+ _shared_idx_cache.setdefault(mat.indices.ctypes.data, None)
486
+
487
+ n_unique = len(_shared_idx_cache)
488
+ n_total = sum(
489
+ sum(
490
+ 1
491
+ for idx in range(getattr(self, q).size)
492
+ if getattr(self, q).flat[idx] is not None
493
+ and isinstance(getattr(self, q).flat[idx], (sp.csc_matrix, sp.csc_array))
494
+ )
495
+ for q in self.quantities
496
+ if getattr(self, q) is not None
497
+ )
498
+ if n_total > n_unique:
499
+ ns_name = xp_new if isinstance(xp_new, str) else xp_new.__name__
500
+ logger.debug(
501
+ "to_namespace: %d CSC matrices share %d unique row-index array(s) — "
502
+ "converting index arrays only once to namespace '%s'.",
503
+ n_total,
504
+ n_unique,
505
+ ns_name,
506
+ )
507
+
508
+ # shallow copy and then convert the matrices in-place to avoid unnecessary copying of large arrays.
509
+ dij_copy = self.model_copy(deep=False)
510
+ for _q in self.quantities:
511
+ _src = getattr(self, _q)
512
+ if _src is not None:
513
+ _fresh = np.empty_like(_src) # same shape, dtype=object
514
+ _fresh.flat[:] = None
515
+ object.__setattr__(dij_copy, _q, _fresh)
477
516
 
478
517
  for q in self.quantities:
479
518
  q_container: InfluenceMatrixContainer = getattr(self, q)
480
519
  if q_container is not None:
481
520
  for i in range(q_container.size):
482
- if q_container.flat[i] is not None:
483
- getattr(dij_copy, q).flat[i] = to_namespace(
484
- xp_new, q_container.flat[i], keep_sparse_compat=keep_sparse_compat
485
- )
521
+ mat = q_container.flat[i]
522
+ if mat is None:
523
+ continue
524
+
525
+ # scipy CSC matrices whose index arrays may be shared
526
+ if keep_sparse_compat and isinstance(mat, (sp.csc_matrix, sp.csc_array)):
527
+ addr = mat.indices.ctypes.data
528
+ if addr in _shared_idx_cache:
529
+ if _shared_idx_cache[addr] is None:
530
+ # First encounter for this index array: convert once
531
+ conv_indices = to_namespace(xp_new, mat.indices)
532
+ conv_indptr = to_namespace(xp_new, mat.indptr)
533
+ _shared_idx_cache[addr] = (conv_indices, conv_indptr)
534
+ conv_indices, conv_indptr = _shared_idx_cache[addr]
535
+ conv_data = to_namespace(xp_new, mat.data)
536
+ getattr(dij_copy, q).flat[i] = _rebuild_scipy_csc_in_namespace(
537
+ xp_new, conv_data, conv_indices, conv_indptr, mat.shape
538
+ )
539
+ continue
540
+
541
+ getattr(dij_copy, q).flat[i] = to_namespace(
542
+ xp_new, mat, keep_sparse_compat=keep_sparse_compat
543
+ )
486
544
 
487
- if isinstance(xp_new, str):
488
- name = xp_new
489
- else:
490
- name = xp_new.__name__
545
+ name = xp_new.__name__ if not isinstance(xp_new, str) else xp_new
491
546
 
492
547
  logger.info(f"Converted Dij to namespace '{name}'")
493
548
 
@@ -583,7 +583,7 @@ class DoseEngineBase(ABC):
583
583
  self._machine = self.load_machine(radiation_mode, machine)
584
584
 
585
585
  # Voxel selection for dose calculation
586
- # TODO: set overlap priorites - Skips most of the function
586
+ # TODO: set overlap priorities - Skips most of the function
587
587
  cst = self.set_overlap_priorities(cst, ct_dim=None)
588
588
 
589
589
  # resizing cst to dose cube resolution