pyRadPlan 0.2.2__tar.gz → 0.2.3__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 (164) hide show
  1. {pyradplan-0.2.2/pyRadPlan.egg-info → pyradplan-0.2.3}/PKG-INFO +4 -3
  2. pyradplan-0.2.3/examples/proton_let_optimization.py +61 -0
  3. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/core/_grids.py +8 -8
  4. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/core/np2sitk.py +1 -3
  5. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/core/resample.py +9 -4
  6. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/ct/_ct.py +20 -10
  7. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dij/_compose_beam_dijs.py +1 -1
  8. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dij/_dij.py +49 -10
  9. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +6 -2
  10. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/engines/_svdpb.py +1 -1
  11. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/problems/_optiprob.py +2 -0
  12. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/plan/_plans.py +13 -42
  13. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/quantities/__init__.py +4 -3
  14. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/quantities/_base.py +5 -11
  15. pyradplan-0.2.3/pyRadPlan/quantities/_let_x_dose.py +29 -0
  16. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/raytracer/_perf.py +6 -6
  17. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/raytracer/_siddon.py +14 -6
  18. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/scenarios/__init__.py +29 -38
  19. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/scenarios/_base.py +159 -168
  20. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/scenarios/_nominal.py +22 -21
  21. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/_ray.py +6 -24
  22. pyradplan-0.2.3/pyRadPlan/visualization/_plot_slice.py +184 -0
  23. {pyradplan-0.2.2 → pyradplan-0.2.3/pyRadPlan.egg-info}/PKG-INFO +4 -3
  24. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan.egg-info/SOURCES.txt +10 -2
  25. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan.egg-info/requires.txt +1 -1
  26. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyproject.toml +2 -2
  27. pyradplan-0.2.3/test/conftest.py +43 -0
  28. pyradplan-0.2.3/test/core/test_datamodel.py +49 -0
  29. pyradplan-0.2.3/test/data/test_validate_test_data.py +127 -0
  30. pyradplan-0.2.3/test/dose/conftest.py +78 -0
  31. pyradplan-0.2.3/test/dose/test_dose_engine_base.py +114 -0
  32. pyradplan-0.2.3/test/dose/test_factory.py +31 -0
  33. pyradplan-0.2.3/test/dose/test_hongpb.py +93 -0
  34. pyradplan-0.2.3/test/dose/test_svdpb.py +32 -0
  35. pyradplan-0.2.3/test/quantities/test_let_dose_quantity.py +108 -0
  36. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_plan.py +12 -4
  37. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_scenarios.py +14 -7
  38. pyradplan-0.2.3/test/visualization/test_plot_slice.py +156 -0
  39. pyradplan-0.2.2/pyRadPlan/visualization/_plot_slice.py +0 -105
  40. pyradplan-0.2.2/test/conftest.py +0 -15
  41. pyradplan-0.2.2/test/dose/test_dose_particle.py +0 -231
  42. pyradplan-0.2.2/test/dose/test_dose_photon.py +0 -20
  43. pyradplan-0.2.2/test/visualization/test_plot_slice.py +0 -85
  44. {pyradplan-0.2.2 → pyradplan-0.2.3}/LICENSE +0 -0
  45. {pyradplan-0.2.2 → pyradplan-0.2.3}/README.md +0 -0
  46. {pyradplan-0.2.2 → pyradplan-0.2.3}/docs/conf.py +0 -0
  47. {pyradplan-0.2.2 → pyradplan-0.2.3}/examples/carbon_pencilbeam.py +0 -0
  48. {pyradplan-0.2.2 → pyradplan-0.2.3}/examples/helium_pencilbeam.py +0 -0
  49. {pyradplan-0.2.2 → pyradplan-0.2.3}/examples/import_matrad_patient.py +0 -0
  50. {pyradplan-0.2.2 → pyradplan-0.2.3}/examples/photon_pencilbeam.py +0 -0
  51. {pyradplan-0.2.2 → pyradplan-0.2.3}/examples/proton_pencilbeam.py +0 -0
  52. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/__init__.py +0 -0
  53. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/core/__init__.py +0 -0
  54. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/core/_exceptions.py +0 -0
  55. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/core/datamodel.py +0 -0
  56. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/cst/__init__.py +0 -0
  57. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/cst/_cst.py +0 -0
  58. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/cst/_voi.py +0 -0
  59. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/ct/__init__.py +0 -0
  60. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/ct/_hlut.py +0 -0
  61. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  62. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
  63. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/machines/photons_Generic.mat +0 -0
  64. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
  65. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/phantoms/TG119.mat +0 -0
  66. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/stf/matRad_stf.mat +0 -0
  67. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/stf/matRad_stf_onebeam.mat +0 -0
  68. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
  69. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dij/__init__.py +0 -0
  70. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/__init__.py +0 -0
  71. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/_calc_dose.py +0 -0
  72. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/engines/__init__.py +0 -0
  73. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/engines/_base.py +0 -0
  74. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/engines/_base_pencilbeam.py +0 -0
  75. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/engines/_factory.py +0 -0
  76. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/dose/engines/_hongpb.py +0 -0
  77. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/geometry/__init__.py +0 -0
  78. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/geometry/lps.py +0 -0
  79. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/io/__init__.py +0 -0
  80. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/io/_matlab_file_handler.py +0 -0
  81. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/io/_patient_loader.py +0 -0
  82. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/io/matfile.py +0 -0
  83. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/machines/__init__.py +0 -0
  84. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/machines/_base.py +0 -0
  85. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/machines/_ions.py +0 -0
  86. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/machines/_load.py +0 -0
  87. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/machines/_photons.py +0 -0
  88. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/machines/_validate.py +0 -0
  89. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/matRad/__init__.py +0 -0
  90. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/matRad/_engine.py +0 -0
  91. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/matRad/_matlab.py +0 -0
  92. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/matRad/_octave.py +0 -0
  93. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/__init__.py +0 -0
  94. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/_fluence_optimization.py +0 -0
  95. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/__init__.py +0 -0
  96. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_eud.py +0 -0
  97. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_factory.py +0 -0
  98. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_max_dvh.py +0 -0
  99. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_mean.py +0 -0
  100. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_min_dvh.py +0 -0
  101. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_objective.py +0 -0
  102. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_squared_dev.py +0 -0
  103. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_squared_over.py +0 -0
  104. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_squared_under.py +0 -0
  105. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/objectives/_std.py +0 -0
  106. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/problems/__init__.py +0 -0
  107. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/problems/_factory.py +0 -0
  108. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/problems/_nonlin_fluence.py +0 -0
  109. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/problems/_simple_least_squares.py +0 -0
  110. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/solvers/__init__.py +0 -0
  111. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/solvers/_base_solvers.py +0 -0
  112. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/solvers/_factory.py +0 -0
  113. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/solvers/_ipopt.py +0 -0
  114. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -0
  115. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/plan/__init__.py +0 -0
  116. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/quantities/_dose.py +0 -0
  117. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/raytracer/__init__.py +0 -0
  118. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/raytracer/_base.py +0 -0
  119. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/__init__.py +0 -0
  120. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/_beam.py +0 -0
  121. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/_beamlet.py +0 -0
  122. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/_exceptions.py +0 -0
  123. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/_generate_stf.py +0 -0
  124. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/_rangeshifter.py +0 -0
  125. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/_steeringinformation.py +0 -0
  126. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/generators/__init__.py +0 -0
  127. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/generators/_base.py +0 -0
  128. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/generators/_externalbeam.py +0 -0
  129. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/generators/_factory.py +0 -0
  130. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/generators/_ions.py +0 -0
  131. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/stf/generators/_photons.py +0 -0
  132. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/util/__init__.py +0 -0
  133. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/util/helpers.py +0 -0
  134. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan/visualization/__init__.py +0 -0
  135. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan.egg-info/dependency_links.txt +0 -0
  136. {pyradplan-0.2.2 → pyradplan-0.2.3}/pyRadPlan.egg-info/top_level.txt +0 -0
  137. {pyradplan-0.2.2 → pyradplan-0.2.3}/setup.cfg +0 -0
  138. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/core/test_coordinates.py +0 -0
  139. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/core/test_np2sitk.py +0 -0
  140. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/core/test_resample.py +0 -0
  141. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/cst/conftest.py +0 -0
  142. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/cst/test_VOI.py +0 -0
  143. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/cst/test_cst.py +0 -0
  144. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/ct/test_ct.py +0 -0
  145. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/ct/test_hlut.py +0 -0
  146. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/geometry/test_lps.py +0 -0
  147. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/optimization/test_fluence_optiprob.py +0 -0
  148. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/optimization/test_ipopt_solver.py +0 -0
  149. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/optimization/test_objectives.py +0 -0
  150. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/optimization/test_problem_factory.py +0 -0
  151. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/optimization/test_scipy_solver.py +0 -0
  152. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/optimization/test_solver_factory.py +0 -0
  153. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/quantities/test_dose_quantity.py +0 -0
  154. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/stf/test_beamlet.py +0 -0
  155. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/stf/test_stf.py +0 -0
  156. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/stf/test_stf_gen.py +0 -0
  157. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_dij.py +0 -0
  158. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_fileHandling.py +0 -0
  159. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_grid.py +0 -0
  160. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_helpers.py +0 -0
  161. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_machine_model.py +0 -0
  162. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_matlabEngine.py +0 -0
  163. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_octaveEngine.py +0 -0
  164. {pyradplan-0.2.2 → pyradplan-0.2.3}/test/test_raytracersiddon.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: pyRadPlan
3
- Version: 0.2.2
3
+ Version: 0.2.3
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>
@@ -19,7 +19,7 @@ Requires-Dist: regex>=2024.5.15
19
19
  Requires-Dist: pydicom>=2.4.4
20
20
  Requires-Dist: numba>=0.60.0
21
21
  Requires-Dist: matplotlib>=3.9.2
22
- Requires-Dist: pydantic>=2.10
22
+ Requires-Dist: pydantic<2.11,>=2.10
23
23
  Requires-Dist: numpydantic>=1.6.0
24
24
  Requires-Dist: SimpleITK>=2.4.0
25
25
  Requires-Dist: tqdm>=4.0.0
@@ -41,6 +41,7 @@ Requires-Dist: pydata-sphinx-theme; extra == "dev"
41
41
  Requires-Dist: sphinx-design; extra == "dev"
42
42
  Requires-Dist: autodoc_pydantic; extra == "dev"
43
43
  Requires-Dist: sphinx-autodoc-typehints; extra == "dev"
44
+ Dynamic: license-file
44
45
 
45
46
  # pyRadPlan
46
47
  [![Tests](https://github.com/e0404/pyRadPlan/actions/workflows/tests.yml/badge.svg)](https://github.com/e0404/pyRadPlan/actions/workflows/tests.yml)
@@ -0,0 +1,61 @@
1
+ import logging
2
+
3
+ import numpy as np
4
+
5
+ from pyRadPlan import (
6
+ IonPlan,
7
+ generate_stf,
8
+ calc_dose_influence,
9
+ fluence_optimization,
10
+ plot_slice,
11
+ load_tg119,
12
+ )
13
+
14
+ from pyRadPlan.optimization.objectives import SquaredDeviation, SquaredOverdosing, MeanDose
15
+
16
+ logging.basicConfig(level=logging.INFO)
17
+
18
+ # Read patient from provided TG119.mat file and validate data
19
+ ct, cst = load_tg119()
20
+
21
+ # Create a plan object
22
+ pln = IonPlan(radiation_mode="protons", machine="Generic")
23
+ pln.prop_opt = {"solver": "scipy"}
24
+
25
+ # Generate Steering Geometry ("stf")
26
+ stf = generate_stf(ct, cst, pln)
27
+
28
+ # Calculate Dose Influence Matrix ("dij")
29
+ dij = calc_dose_influence(ct, cst, stf, pln)
30
+
31
+ # Optimization
32
+ cst.vois[1].objectives = [SquaredDeviation(priority=100.0, d_ref=3.0)] # Target
33
+ cst.vois[0].objectives = [
34
+ SquaredOverdosing(priority=10.0, d_max=1.0),
35
+ SquaredOverdosing(priority=5.0, d_max=1.0, quantity="let_dose"),
36
+ ] # OAR
37
+ cst.vois[2].objectives = [
38
+ MeanDose(priority=1.0, d_ref=0.0),
39
+ SquaredOverdosing(priority=10.0, d_max=2.0),
40
+ ] # BODY
41
+ fluence = fluence_optimization(ct, cst, stf, dij, pln)
42
+
43
+ # Result
44
+ result = dij.compute_result_ct_grid(fluence)
45
+
46
+ # Choose a slice to visualize
47
+ view_slice = int(np.round(ct.size[2] / 2))
48
+
49
+ # Visualize
50
+ plot_slice(
51
+ ct=ct,
52
+ cst=cst,
53
+ overlay=result["physical_dose"],
54
+ view_slice=view_slice,
55
+ )
56
+ plot_slice(
57
+ ct=ct,
58
+ cst=cst,
59
+ overlay=result["let"],
60
+ view_slice=view_slice,
61
+ )
@@ -76,9 +76,9 @@ class Grid(PyRadPlanBaseModel):
76
76
  raise ValueError("resolution must have keys 'x', 'y', 'z'")
77
77
 
78
78
  # Check if all resolution values are positive floats. If not, try to cast them to float
79
- for key in value:
80
- if value[key] <= 0:
81
- raise ValueError(f"resolution values must be positive floats, got {value[key]}")
79
+ for _, v in value.items():
80
+ if v <= 0:
81
+ raise ValueError(f"resolution values must be positive floats, got {v}")
82
82
 
83
83
  return value
84
84
 
@@ -93,11 +93,12 @@ class Grid(PyRadPlanBaseModel):
93
93
  # Check if all dimensions values are positive integers. If not, try to cast them to int
94
94
  for dim in value:
95
95
  try:
96
- dim = int(dim)
96
+ tmpdim = int(dim)
97
97
  except ValueError:
98
98
  raise ValueError(f"dimension value could not be casted into int, got {dim}")
99
- if dim <= 0:
100
- raise ValueError(f"dimension values must be positive integers, got {dim}")
99
+
100
+ if tmpdim <= 0:
101
+ raise ValueError(f"dimension values must be positive integers, got {tmpdim}")
101
102
 
102
103
  return value
103
104
 
@@ -162,8 +163,7 @@ class Grid(PyRadPlanBaseModel):
162
163
  ],
163
164
  ) -> Self:
164
165
  """
165
- Create a resampled grid covering the original grid in a new
166
- resolution.
166
+ Create a resampled grid covering the original grid in new resolution.
167
167
 
168
168
  Parameters
169
169
  ----------
@@ -1,6 +1,4 @@
1
- """Helper Functions relating to conversion between numpy and SimpleITK data
2
- types.
3
- """
1
+ """Helpers for conversion between numpy and SimpleITK."""
4
2
 
5
3
  from typing import Literal
6
4
  import SimpleITK as sitk
@@ -1,3 +1,5 @@
1
+ """Image / Grid Resampling."""
2
+
1
3
  import numpy as np
2
4
  import SimpleITK as sitk
3
5
  from ._grids import Grid
@@ -11,8 +13,9 @@ def resample_image(
11
13
  target_grid: Grid = None,
12
14
  ) -> sitk.Image: # also accept sitk images and grid points. Can be dealt with with kwargs
13
15
  """
14
- Resamples an sitk Image to a target resolution, reference image
15
- dimensions, or Grid.
16
+ Resample an sitk Image.
17
+
18
+ Use target resolution, reference image, dimensions, or Grid as input.
16
19
 
17
20
  Parameters
18
21
  ----------
@@ -70,8 +73,10 @@ def resample_numpy_array(
70
73
  target_grid: Grid = None,
71
74
  ) -> np.ndarray:
72
75
  """
73
- Resamples a numpy grid to a target resolution, reference image
74
- dimensions, or Grid.
76
+ Resample a numpy grid.
77
+
78
+ Use target resolution, reference image, dimensions, or Grid as input.
79
+
75
80
  We convert the numpy array to an sitk.Image, so the dimensions will be
76
81
  switched. More exactly,
77
82
  the numpy array will be index i,j,k <-> z,y,x, which will converted to
@@ -91,6 +91,9 @@ class CT(PyRadPlanBaseModel, ABC):
91
91
  if cube_hu is None:
92
92
  raise ValueError("HU cube not present in dictionary.")
93
93
 
94
+ if isinstance(cube_hu, sitk.Image) and "origin" not in data:
95
+ data["origin"] = cube_hu.GetOrigin()
96
+
94
97
  if isinstance(cube_hu, np.ndarray):
95
98
  # Now we do check if it is matRad data
96
99
  if data.get("cubeDim", None) is not None:
@@ -133,16 +136,6 @@ class CT(PyRadPlanBaseModel, ABC):
133
136
  is4d = cube_hu.GetDimension() == 4
134
137
  # Now we parse the rest of the data if additional data is available in the dictionary
135
138
 
136
- # TODO: Either set up a Grid or check for x/y/z to do the data management
137
- if "origin" in data:
138
- data["cube_hu"].SetOrigin(data["origin"])
139
-
140
- elif all(key in data for key in ("x", "y", "z")):
141
- origin = np.array([data["x"][0], data["y"][0], data["z"][0]], dtype=float)
142
- if is4d:
143
- origin = np.append(origin, [0.0])
144
- data["cube_hu"].SetOrigin(origin)
145
-
146
139
  if "direction" in data:
147
140
  data["cube_hu"].SetDirection(data["direction"])
148
141
 
@@ -153,6 +146,23 @@ class CT(PyRadPlanBaseModel, ABC):
153
146
  else:
154
147
  cube_hu.SetSpacing([resolution["x"], resolution["y"], resolution["z"]])
155
148
 
149
+ # TODO: Either set up a Grid or check for x/y/z to do the data management
150
+ if "origin" in data:
151
+ data["cube_hu"].SetOrigin(data["origin"])
152
+
153
+ else:
154
+ data["cube_hu"].SetOrigin(
155
+ -np.array(data["cube_hu"].GetSize())
156
+ / 2.0
157
+ * np.array(data["cube_hu"].GetSpacing())
158
+ )
159
+ if is4d:
160
+ data["cube_hu"].SetOrigin(np.append(data["cube_hu"].GetOrigin(), [0.0]))
161
+ # elif all(key in data for key in ("x", "y", "z")):
162
+ # origin = np.array([data["x"][0], data["y"][0], data["z"][0]], dtype=float)
163
+ # if is4d:
164
+ # origin = np.append(origin, [0.0])
165
+ # data["cube_hu"].SetOrigin(origin)
156
166
  return data
157
167
 
158
168
  @computed_field
@@ -51,5 +51,5 @@ def compose_beam_dijs(dijs: list[Dij]) -> Dij:
51
51
  beam_num=beam_num,
52
52
  ray_num=ray_num,
53
53
  bixel_num=bixel_num,
54
- **matrices
54
+ **matrices,
55
55
  )
@@ -1,6 +1,6 @@
1
1
  """Contains the dij class as a (collection of) influence matrices."""
2
2
 
3
- from typing import Any, Union, Annotated, cast
3
+ from typing import Any, Union, Annotated, Optional, cast
4
4
  from pydantic import (
5
5
  Field,
6
6
  field_validator,
@@ -41,15 +41,17 @@ class Dij(PyRadPlanBaseModel):
41
41
  ct_grid: Annotated[Grid, Field(default=None)]
42
42
 
43
43
  physical_dose: Annotated[NDArray, Field(default=None)]
44
- let_dose: Annotated[NDArray, Field(default=None)]
44
+ let_dose: Annotated[NDArray, Field(default=None, alias="mLETDose")]
45
45
  alpha_dose: Annotated[NDArray, Field(default=None)]
46
46
  sqrt_beta_dose: Annotated[NDArray, Field(default=None)]
47
47
 
48
48
  num_of_beams: Annotated[int, Field(default=None)]
49
49
 
50
- bixel_num: Annotated[np.ndarray, Field(default=None)]
51
- ray_num: Annotated[np.ndarray, Field(default=None)]
52
- beam_num: Annotated[np.ndarray, Field(default=None)]
50
+ bixel_num: Annotated[NDArray, Field(default=None)]
51
+ ray_num: Annotated[NDArray, Field(default=None)]
52
+ beam_num: Annotated[NDArray, Field(default=None)]
53
+
54
+ rad_depth_cubes: Optional[list[NDArray]] = Field(default=None)
53
55
 
54
56
  @computed_field
55
57
  @property
@@ -62,7 +64,7 @@ class Dij(PyRadPlanBaseModel):
62
64
  def num_of_voxels(self) -> int:
63
65
  """Number of voxels in the dose influence matrix."""
64
66
  return self.physical_dose.flat[0].shape[0]
65
-
67
+
66
68
  @computed_field
67
69
  @property
68
70
  def quantities(self) -> list[str]:
@@ -109,11 +111,30 @@ class Dij(PyRadPlanBaseModel):
109
111
  if mat.shape[0] != info.data["dose_grid"].num_voxels:
110
112
  raise ValueError(f"{info.field_name} shape inconsistent with ct grid")
111
113
 
114
+ if info.context and "from_matRad" in info.context and info.context["from_matRad"]:
115
+ if v is not None:
116
+ for i in range(v.size):
117
+ shape = (
118
+ int(info.data["dose_grid"].dimensions[2]),
119
+ int(info.data["dose_grid"].dimensions[0]),
120
+ int(info.data["dose_grid"].dimensions[1]),
121
+ )
122
+ v.flat[i] = swap_orientation_sparse_matrix(
123
+ v.flat[i],
124
+ shape,
125
+ (1, 2), # (65, 100, 100) example
126
+ )
127
+ if v.flat[i] is not None and not isinstance(v.flat[i], sp.csc_matrix):
128
+ v.flat[i] = sp.csc_matrix(v.flat[i])
129
+ else:
130
+ v = np.array([0])
131
+ return [[v]] # TODO
132
+
112
133
  return v
113
134
 
114
135
  @field_validator("dose_grid", "ct_grid", mode="before")
115
136
  @classmethod
116
- def validate_grid(cls, grid: Union[Grid, dict]) -> Union[Grid, dict]:
137
+ def validate_grid(cls, grid: Union[Grid, dict], info: ValidationInfo) -> Union[Grid, dict]:
117
138
  """
118
139
  Validate grid dictionaries.
119
140
 
@@ -123,7 +144,14 @@ class Dij(PyRadPlanBaseModel):
123
144
  """
124
145
  # Check if it is a dictionary and then try to create a Grid object
125
146
  if isinstance(grid, dict):
126
- grid = Grid.model_validate(grid)
147
+ if info.context and "from_matRad" in info.context and info.context["from_matRad"]:
148
+ grid["dimensions"] = np.array(
149
+ [grid["dimensions"][1], grid["dimensions"][0], grid["dimensions"][2]]
150
+ )
151
+ # TODO: might swap offset and resolution
152
+ grid = Grid.model_validate(grid)
153
+ else:
154
+ grid = Grid.model_validate(grid)
127
155
  return grid
128
156
 
129
157
  @field_validator("beam_num", mode="before")
@@ -184,7 +212,6 @@ class Dij(PyRadPlanBaseModel):
184
212
  context = info.context
185
213
  if context and context.get("matRad") == "mat-file":
186
214
  return value.to_matrad(context=context["matRad"])
187
-
188
215
  return handler(value, info)
189
216
 
190
217
  @field_serializer("physical_dose", "let_dose", "alpha_dose", "sqrt_beta_dose")
@@ -204,6 +231,18 @@ class Dij(PyRadPlanBaseModel):
204
231
  )
205
232
  if value.flat[i] is not None and not isinstance(value.flat[i], sp.csc_matrix):
206
233
  value.flat[i] = sp.csc_matrix(value.flat[i])
234
+ # return 0 if value is None. savemat() cant handle 'None'
235
+ elif context and context.get("matRad") == "mat-file" and value is None:
236
+ value = np.array([0])
237
+ return value
238
+
239
+ @field_serializer("rad_depth_cubes")
240
+ def rad_depth_cubes_serializer(self, value: np.ndarray, info: SerializationInfo) -> np.ndarray:
241
+ context = info.context
242
+ if context and context.get("matRad") == "mat-file" and value is not None:
243
+ # TODO: it might be necessary to rotate the cube!
244
+ return value
245
+ # return 0 if value is None. savemat() cant handle 'None'
207
246
  elif context and context.get("matRad") == "mat-file" and value is None:
208
247
  value = np.array([0])
209
248
  return value
@@ -253,7 +292,7 @@ class Dij(PyRadPlanBaseModel):
253
292
  if self.physical_dose is None:
254
293
  raise ValueError("Physical dose must be calculated for dose-weighted let")
255
294
 
256
- indices = out["physical_dose"] > 0.0
295
+ indices = out["physical_dose"] > 0.05 * np.max(out["physical_dose"])
257
296
 
258
297
  let_dose = self.let_dose.flat[scenario_index] @ intensity
259
298
  out["let"] = np.zeros_like(let_dose)
@@ -5,6 +5,7 @@ from abc import abstractmethod
5
5
  from typing import cast, Literal, Any
6
6
  import logging
7
7
  import time
8
+ from copy import deepcopy
8
9
 
9
10
  import numpy as np
10
11
  from scipy.interpolate import interp1d
@@ -735,6 +736,8 @@ class ParticlePencilBeamEngineAbstract(PencilBeamEngineAbstract):
735
736
  comp_fac=1.0, depths=depth_values, cut_off=np.inf * np.ones_like(depth_values)
736
737
  )
737
738
 
739
+ base_kernel = deepcopy(kernel) # similar to base_data in matRad
740
+
738
741
  # TODO: this could probably be done for all depths with one calculation without a loop
739
742
  for j, current_depth in enumerate(depth_values):
740
743
  # If there's no cut-off set, we do not need to find it. Set it to infinity
@@ -744,12 +747,13 @@ class ParticlePencilBeamEngineAbstract(PencilBeamEngineAbstract):
744
747
  # depth
745
748
  bixel = {
746
749
  "energy_ix": energy_ix,
747
- "kernel": kernel,
750
+ "kernel": base_kernel,
748
751
  "radial_dist_sq": radial_dist_sq,
749
752
  "sigma_ini_sq": largest_sigma_sq4unique_energies[
750
753
  cnt - 1
751
754
  ], # TODO: check if this result is correct (rounded but may be right)
752
- "rad_depths": (current_depth + kernel.offset) * np.ones_like(radial_dist_sq),
755
+ "rad_depths": (current_depth + base_kernel.offset)
756
+ * np.ones_like(radial_dist_sq),
753
757
  "v_tissue_index": np.ones_like(radial_dist_sq),
754
758
  "v_alpha_x": 0.5 * np.ones_like(radial_dist_sq),
755
759
  "v_beta_x": 0.05 * np.ones_like(radial_dist_sq),
@@ -299,7 +299,7 @@ class PhotonPencilBeamSVDEngine(PencilBeamEngineAbstract):
299
299
  bixel_dose *= ((sad) / geo_depths) ** 2
300
300
 
301
301
  bixel["physical_dose"] = bixel_dose
302
-
302
+ bixel["weight"] = curr_ray["beamlets"][k]["weight"]
303
303
  bixel["ix"] = curr_ray["ix"]
304
304
 
305
305
  return bixel
@@ -191,6 +191,8 @@ class PlanningProblem(ABC):
191
191
  )
192
192
 
193
193
  # TODO: manage scenarios
194
+
195
+ # Manage quantites by getting them from the objective quantities
194
196
  self._quantities = [q(self._dij) for q in quantities]
195
197
 
196
198
  # obtain cache info to match quantities with objectives
@@ -1,7 +1,7 @@
1
1
  """
2
- Module: _plans.py
3
- This module contains the definition of the Plan class and its derived classes,
4
- PhotonPlan and IonPlan.
2
+ Contains the definition of the Plan class and its derived classes.
3
+
4
+ Available spezialized Plan classes are PhotonPlan and IonPlan.
5
5
  """
6
6
 
7
7
  from abc import ABC
@@ -11,8 +11,6 @@ from copy import deepcopy
11
11
  from pydantic import (
12
12
  Field,
13
13
  field_validator,
14
- field_serializer,
15
- SerializationInfo,
16
14
  ValidationError,
17
15
  )
18
16
  from pydantic.alias_generators import to_snake
@@ -60,7 +58,7 @@ class Plan(PyRadPlanBaseModel, ABC):
60
58
  @classmethod
61
59
  def validate_radiation_mode(cls, v: str) -> str:
62
60
  """
63
- Validates the radiation mode.
61
+ Validate the radiation mode.
64
62
 
65
63
  Parameters
66
64
  ----------
@@ -76,11 +74,11 @@ class Plan(PyRadPlanBaseModel, ABC):
76
74
 
77
75
  @field_validator("mult_scen", mode="before")
78
76
  @classmethod
79
- def validate_mult_scen(
77
+ def _validate_mult_scen(
80
78
  cls, v: Union[Union[Dict[str, Any], ScenarioModel], str]
81
79
  ) -> ScenarioModel:
82
80
  """
83
- Validates the mult_scen attribute.
81
+ Validate the mult_scen attribute.
84
82
 
85
83
  Parameters
86
84
  ----------
@@ -109,7 +107,8 @@ class Plan(PyRadPlanBaseModel, ABC):
109
107
  @classmethod
110
108
  def validate_prop(cls, v: Dict[str, Any]) -> Dict[str, Any]:
111
109
  """
112
- Validates the workflow property dictionaries.
110
+ Validate the workflow property dictionaries.
111
+
113
112
  Will try to convert to snake_case if camelCase is used.
114
113
 
115
114
  Parameters
@@ -129,38 +128,9 @@ class Plan(PyRadPlanBaseModel, ABC):
129
128
  # Convert camelCase to snake_case
130
129
  return {to_snake(k): v for k, v in v.items()}
131
130
 
132
- @field_serializer("mult_scen")
133
- def serialize_mult_scen(self, v: ScenarioModel, info: SerializationInfo) -> Dict:
134
- """
135
- Serializes the mult_scen attribute.
136
-
137
- Parameters
138
- ----------
139
- v : ScenarioModel
140
- The ScenarioModel object to be serialized.
141
-
142
- Returns
143
- -------
144
- Dict
145
- The serialized ScenarioModel object.
146
- """
147
-
148
- use_alias = info.by_alias
149
- context = info.context
150
-
151
- if context and context.get("matfile_compatible"):
152
- out_dict = v.to_matrad(context=context)
153
- elif use_alias:
154
- out_dict = v.to_matrad()
155
- else:
156
- out_dict = v.to_dict()
157
-
158
- return out_dict
159
-
160
131
  def to_matrad(self, context: str = "mat-file") -> Any:
161
132
  """
162
- Creates a dictionary ready to save the Plan model to a mat-file that
163
- can be ready.
133
+ Create a dictionary ready to save the Plan model to a mat-file.
164
134
 
165
135
  Returns
166
136
  -------
@@ -193,7 +163,7 @@ class PhotonPlan(Plan):
193
163
  @classmethod
194
164
  def validate_radiation_mode(cls, v: str) -> str:
195
165
  """
196
- Validates the radiation mode for a PhotonPlan.
166
+ Validate the radiation mode for a PhotonPlan.
197
167
 
198
168
  Parameters
199
169
  ----------
@@ -269,7 +239,7 @@ class IonPlan(Plan):
269
239
 
270
240
  def create_pln(data: Union[Dict[str, Any], Plan, None] = None, **kwargs) -> Plan:
271
241
  """
272
- Factory function to create a Plan object.
242
+ Create a Plan object (factory function).
273
243
 
274
244
  Parameters
275
245
  ----------
@@ -316,7 +286,8 @@ def create_pln(data: Union[Dict[str, Any], Plan, None] = None, **kwargs) -> Plan
316
286
 
317
287
  def validate_pln(plan: Union[Dict[str, Any], Plan, None] = None, **kwargs) -> Plan:
318
288
  """
319
- Validates and creates a Plan object.
289
+ Validate and create a Plan object.
290
+
320
291
  Synonym to create_pln but should be used in validation context.
321
292
 
322
293
  Parameters
@@ -1,12 +1,13 @@
1
1
  from ._base import FluenceDependentQuantity, RTQuantity
2
2
  from ._dose import Dose
3
+ from ._let_x_dose import LETxDose
3
4
 
4
- QUANTITIES = {Dose.identifier: Dose}
5
+ QUANTITIES = {Dose.identifier: Dose, LETxDose.identifier: LETxDose}
5
6
 
6
7
 
7
8
  def get_available_quantities() -> dict[str, RTQuantity]:
8
9
  """
9
- Obtains the available quantities in planning.
10
+ Obtain the available quantities in planning.
10
11
 
11
12
  Returns
12
13
  -------
@@ -18,7 +19,7 @@ def get_available_quantities() -> dict[str, RTQuantity]:
18
19
 
19
20
  def get_quantity(identifier: str) -> RTQuantity:
20
21
  """
21
- Obtains the quantity from name.
22
+ Obtain the quantity from name.
22
23
 
23
24
  Parameters
24
25
  ----------
@@ -42,7 +42,7 @@ class FluenceDependentQuantity(RTQuantity, ABC):
42
42
 
43
43
  def __call__(self, fluence: ArrayLike) -> NDArray:
44
44
  """
45
- Makes the quantity callable by calling the compute method.
45
+ Make the quantity callable by calling the compute method.
46
46
 
47
47
  Parameters
48
48
  ----------
@@ -82,9 +82,7 @@ class FluenceDependentQuantity(RTQuantity, ABC):
82
82
 
83
83
  def compute_chain_derivative(self, d_quantity: ArrayLike, fluence: ArrayLike) -> NDArray:
84
84
  """
85
- Derivative of the quantity with respect to the fluence from the
86
- derivative
87
- w.r.t. the quantity.
85
+ Fluence Derivative of the quantity w.r.t. to the quantity derivative.
88
86
 
89
87
  Parameters
90
88
  ----------
@@ -110,8 +108,7 @@ class FluenceDependentQuantity(RTQuantity, ABC):
110
108
 
111
109
  def _compute_quantity_cache(self):
112
110
  """
113
- Protected function to compute the quantity from the fluence and
114
- write it into the cache.
111
+ Protected function to compute the quantity from the fluence and write it into the cache.
115
112
 
116
113
  Parameters
117
114
  ----------
@@ -126,9 +123,7 @@ class FluenceDependentQuantity(RTQuantity, ABC):
126
123
 
127
124
  def _compute_chain_derivative_cache(self, d_quantity: NDArray) -> NDArray:
128
125
  """
129
- Protected interface for calculating the derivative of the quantity
130
- with respect to the
131
- fluence from the derivative w.r.t. the quantity.
126
+ Protected interface for calculating the fluence derivative from quantity derivative.
132
127
 
133
128
  Parameters
134
129
  ----------
@@ -169,8 +164,7 @@ class FluenceDependentQuantity(RTQuantity, ABC):
169
164
  self, d_quantity: NDArray, scenario_index: int
170
165
  ) -> NDArray:
171
166
  """
172
- Calculate the derivative of the quantity w.r.t. the fluence in a
173
- specific scenario.
167
+ Calculate the derivative of the quantity w.r.t. the fluence in a specific scenario.
174
168
 
175
169
  Parameters
176
170
  ----------
@@ -0,0 +1,29 @@
1
+ from numpy.typing import NDArray
2
+ import pint
3
+
4
+ from pyRadPlan.quantities._base import FluenceDependentQuantity
5
+
6
+ ureg = pint.UnitRegistry()
7
+
8
+
9
+ class LETxDose(FluenceDependentQuantity):
10
+ """LETxDose quantity depending on fluence."""
11
+
12
+ unit = ureg.gray * ureg.micrometer / ureg.keV
13
+ dim = 1
14
+ identifier = "let_dose"
15
+ name = "LETxDose"
16
+
17
+ def __init__(self, *args, **kwargs):
18
+ super().__init__(*args, **kwargs)
19
+
20
+ if self.identifier not in self._dij.model_fields or self._dij.let_dose is None:
21
+ raise ValueError(f"Quantity {self.identifier} not available in Dij object.")
22
+
23
+ def _compute_quantity_single_scenario_from_cache(self, scenario_index: int) -> NDArray:
24
+ return self._dij.let_dose.flat[scenario_index] @ self._w_cache
25
+
26
+ def _compute_chained_fluence_gradient_single_scenario_from_cache(
27
+ self, d_quantity, scenario_index: int
28
+ ) -> NDArray:
29
+ return d_quantity @ self._dij.let_dose.flat[scenario_index]
@@ -215,12 +215,12 @@ def _fast_compute_all_alphas(
215
215
 
216
216
  alphas = np.concatenate((alpha_limits, alpha_x, alpha_y, alpha_z), axis=1)
217
217
 
218
- # Row wise Unique (could be externalized and potentially jitted if performance critical)
219
- np_unique = np.unique # Lookup function once to improve performance
220
- for i in range(alphas.shape[0]):
221
- v = np_unique(alphas[i, :])
222
- alphas[i, : v.size] = v
223
- alphas[i, v.size + 1 :] = np.nan
218
+ # Vectorized unique operation across rows
219
+ # Sort alphas row-wise and remove duplicates
220
+ alphas = np.sort(alphas, axis=1) # Sort each row ascendingly
221
+ mask = np.diff(alphas, axis=1) == 0 # Identify duplicates
222
+ alphas[:, 1:][mask] = np.nan # Replace duplicates with NaN
223
+ alphas = np.sort(alphas, axis=1)
224
224
 
225
225
  # Size Reduction
226
226
  max_num_columns = np.max(np.sum(~np.isnan(alphas), axis=1))