pyRadPlan 0.2.4__tar.gz → 0.2.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 (163) hide show
  1. {pyradplan-0.2.4/pyRadPlan.egg-info → pyradplan-0.2.5}/PKG-INFO +1 -1
  2. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/__init__.py +3 -0
  3. pyradplan-0.2.5/pyRadPlan/analysis/__init__.py +8 -0
  4. pyradplan-0.2.5/pyRadPlan/analysis/_dvh.py +414 -0
  5. {pyradplan-0.2.4 → pyradplan-0.2.5/pyRadPlan.egg-info}/PKG-INFO +1 -1
  6. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan.egg-info/SOURCES.txt +4 -0
  7. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyproject.toml +1 -1
  8. pyradplan-0.2.5/test/analysis/test_dvh.py +70 -0
  9. pyradplan-0.2.5/test/analysis/test_qi.py +1 -0
  10. {pyradplan-0.2.4 → pyradplan-0.2.5}/LICENSE +0 -0
  11. {pyradplan-0.2.4 → pyradplan-0.2.5}/README.md +0 -0
  12. {pyradplan-0.2.4 → pyradplan-0.2.5}/docs/conf.py +0 -0
  13. {pyradplan-0.2.4 → pyradplan-0.2.5}/examples/carbon_pencilbeam.py +0 -0
  14. {pyradplan-0.2.4 → pyradplan-0.2.5}/examples/helium_pencilbeam.py +0 -0
  15. {pyradplan-0.2.4 → pyradplan-0.2.5}/examples/import_matrad_patient.py +0 -0
  16. {pyradplan-0.2.4 → pyradplan-0.2.5}/examples/photon_pencilbeam.py +0 -0
  17. {pyradplan-0.2.4 → pyradplan-0.2.5}/examples/proton_let_optimization.py +0 -0
  18. {pyradplan-0.2.4 → pyradplan-0.2.5}/examples/proton_pencilbeam.py +0 -0
  19. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/core/__init__.py +0 -0
  20. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/core/_exceptions.py +0 -0
  21. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/core/_grids.py +0 -0
  22. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/core/datamodel.py +0 -0
  23. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/core/np2sitk.py +0 -0
  24. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/core/resample.py +0 -0
  25. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/cst/__init__.py +0 -0
  26. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/cst/_cst.py +0 -0
  27. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/cst/_voi.py +0 -0
  28. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/ct/__init__.py +0 -0
  29. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/ct/_ct.py +0 -0
  30. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/ct/_hlut.py +0 -0
  31. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  32. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
  33. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/machines/photons_Generic.mat +0 -0
  34. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
  35. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/phantoms/TG119.mat +0 -0
  36. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/stf/matRad_stf.mat +0 -0
  37. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/stf/matRad_stf_onebeam.mat +0 -0
  38. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
  39. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dij/__init__.py +0 -0
  40. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dij/_compose_beam_dijs.py +0 -0
  41. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dij/_dij.py +0 -0
  42. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/__init__.py +0 -0
  43. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/_calc_dose.py +0 -0
  44. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/engines/__init__.py +0 -0
  45. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/engines/_base.py +0 -0
  46. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/engines/_base_pencilbeam.py +0 -0
  47. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +0 -0
  48. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/engines/_factory.py +0 -0
  49. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/engines/_hongpb.py +0 -0
  50. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/dose/engines/_svdpb.py +0 -0
  51. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/geometry/__init__.py +0 -0
  52. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/geometry/lps.py +0 -0
  53. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/io/__init__.py +0 -0
  54. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/io/_matlab_file_handler.py +0 -0
  55. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/io/_patient_loader.py +0 -0
  56. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/io/matfile.py +0 -0
  57. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/machines/__init__.py +0 -0
  58. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/machines/_base.py +0 -0
  59. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/machines/_ions.py +0 -0
  60. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/machines/_load.py +0 -0
  61. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/machines/_photons.py +0 -0
  62. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/machines/_validate.py +0 -0
  63. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/matRad/__init__.py +0 -0
  64. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/matRad/_engine.py +0 -0
  65. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/matRad/_matlab.py +0 -0
  66. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/matRad/_octave.py +0 -0
  67. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/__init__.py +0 -0
  68. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/_fluence_optimization.py +0 -0
  69. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/__init__.py +0 -0
  70. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_eud.py +0 -0
  71. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_factory.py +0 -0
  72. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_max_dvh.py +0 -0
  73. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_mean.py +0 -0
  74. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_min_dvh.py +0 -0
  75. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_objective.py +0 -0
  76. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_squared_dev.py +0 -0
  77. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_squared_over.py +0 -0
  78. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_squared_under.py +0 -0
  79. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/objectives/_std.py +0 -0
  80. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/problems/__init__.py +0 -0
  81. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/problems/_factory.py +0 -0
  82. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/problems/_nonlin_fluence.py +0 -0
  83. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/problems/_optiprob.py +0 -0
  84. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/problems/_simple_least_squares.py +0 -0
  85. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/solvers/__init__.py +0 -0
  86. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/solvers/_base_solvers.py +0 -0
  87. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/solvers/_factory.py +0 -0
  88. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/solvers/_ipopt.py +0 -0
  89. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -0
  90. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/plan/__init__.py +0 -0
  91. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/plan/_plans.py +0 -0
  92. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/quantities/__init__.py +0 -0
  93. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/quantities/_base.py +0 -0
  94. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/quantities/_dose.py +0 -0
  95. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/quantities/_let_x_dose.py +0 -0
  96. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/raytracer/__init__.py +0 -0
  97. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/raytracer/_base.py +0 -0
  98. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/raytracer/_perf.py +0 -0
  99. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/raytracer/_siddon.py +0 -0
  100. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/scenarios/__init__.py +0 -0
  101. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/scenarios/_base.py +0 -0
  102. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/scenarios/_nominal.py +0 -0
  103. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/__init__.py +0 -0
  104. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/_beam.py +0 -0
  105. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/_beamlet.py +0 -0
  106. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/_exceptions.py +0 -0
  107. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/_generate_stf.py +0 -0
  108. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/_rangeshifter.py +0 -0
  109. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/_ray.py +0 -0
  110. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/_steeringinformation.py +0 -0
  111. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/generators/__init__.py +0 -0
  112. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/generators/_base.py +0 -0
  113. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/generators/_externalbeam.py +0 -0
  114. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/generators/_factory.py +0 -0
  115. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/generators/_ions.py +0 -0
  116. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/stf/generators/_photons.py +0 -0
  117. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/util/__init__.py +0 -0
  118. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/util/helpers.py +0 -0
  119. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/visualization/__init__.py +0 -0
  120. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan/visualization/_plot_slice.py +0 -0
  121. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan.egg-info/dependency_links.txt +0 -0
  122. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan.egg-info/requires.txt +0 -0
  123. {pyradplan-0.2.4 → pyradplan-0.2.5}/pyRadPlan.egg-info/top_level.txt +0 -0
  124. {pyradplan-0.2.4 → pyradplan-0.2.5}/setup.cfg +0 -0
  125. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/conftest.py +0 -0
  126. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/core/test_coordinates.py +0 -0
  127. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/core/test_datamodel.py +0 -0
  128. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/core/test_np2sitk.py +0 -0
  129. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/core/test_resample.py +0 -0
  130. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/cst/conftest.py +0 -0
  131. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/cst/test_VOI.py +0 -0
  132. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/cst/test_cst.py +0 -0
  133. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/ct/test_ct.py +0 -0
  134. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/ct/test_hlut.py +0 -0
  135. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/data/test_validate_test_data.py +0 -0
  136. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/dose/conftest.py +0 -0
  137. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/dose/test_dose_engine_base.py +0 -0
  138. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/dose/test_factory.py +0 -0
  139. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/dose/test_hongpb.py +0 -0
  140. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/dose/test_svdpb.py +0 -0
  141. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/geometry/test_lps.py +0 -0
  142. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/optimization/test_fluence_optiprob.py +0 -0
  143. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/optimization/test_ipopt_solver.py +0 -0
  144. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/optimization/test_objectives.py +0 -0
  145. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/optimization/test_problem_factory.py +0 -0
  146. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/optimization/test_scipy_solver.py +0 -0
  147. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/optimization/test_solver_factory.py +0 -0
  148. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/quantities/test_dose_quantity.py +0 -0
  149. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/quantities/test_let_dose_quantity.py +0 -0
  150. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/stf/test_beamlet.py +0 -0
  151. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/stf/test_stf.py +0 -0
  152. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/stf/test_stf_gen.py +0 -0
  153. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_dij.py +0 -0
  154. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_fileHandling.py +0 -0
  155. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_grid.py +0 -0
  156. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_helpers.py +0 -0
  157. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_machine_model.py +0 -0
  158. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_matlabEngine.py +0 -0
  159. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_octaveEngine.py +0 -0
  160. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_plan.py +0 -0
  161. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_raytracersiddon.py +0 -0
  162. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/test_scenarios.py +0 -0
  163. {pyradplan-0.2.4 → pyradplan-0.2.5}/test/visualization/test_plot_slice.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyRadPlan
3
- Version: 0.2.4
3
+ Version: 0.2.5
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>
@@ -10,6 +10,7 @@ from .stf._generate_stf import generate_stf
10
10
  from .stf import SteeringInformation, validate_stf
11
11
  from .dose._calc_dose import calc_dose_influence, calc_dose_forward
12
12
  from .optimization._fluence_optimization import fluence_optimization
13
+ from .analysis._dvh import DVH, DVHCollection
13
14
  from .visualization import plot_slice
14
15
  from .io import load_patient, load_tg119
15
16
 
@@ -36,6 +37,8 @@ __all__ = [
36
37
  "calc_dose_influence",
37
38
  "calc_dose_forward",
38
39
  "fluence_optimization",
40
+ "DVH",
41
+ "DVHCollection",
39
42
  "SteeringInformation",
40
43
  "validate_stf",
41
44
  "plot_slice",
@@ -0,0 +1,8 @@
1
+ """Analysis module for pyRadPlan."""
2
+
3
+ from ._dvh import DVH, DVHCollection
4
+
5
+ __all__ = [
6
+ "DVH",
7
+ "DVHCollection",
8
+ ]
@@ -0,0 +1,414 @@
1
+ import logging
2
+ from typing import Union, Optional, Any
3
+ from typing_extensions import Self
4
+ from pydantic import (
5
+ Field,
6
+ computed_field,
7
+ field_validator,
8
+ model_validator,
9
+ )
10
+ from numpydantic import NDArray, Shape
11
+
12
+ import pint
13
+ import numpy as np
14
+ import SimpleITK as sitk
15
+ import matplotlib.pyplot as plt
16
+
17
+ from pyRadPlan.core import PyRadPlanBaseModel
18
+ from pyRadPlan.cst import StructureSet
19
+
20
+ logger = logging.getLogger(__name__)
21
+
22
+ ureg = pint.UnitRegistry()
23
+
24
+
25
+ class DVH(PyRadPlanBaseModel):
26
+ """
27
+ Dose Volume Histogram (DVH) class.
28
+
29
+ Note
30
+ ----
31
+ The DVH class can be used for other quantities as well.
32
+ The bins correspond to the left edge of the bin, thus we have as many bin points as dose points.
33
+
34
+ """
35
+
36
+ diff_volume: NDArray[Shape["*"], np.float64] = Field(
37
+ alias="volumePoints", description="Volume percentages for each point"
38
+ )
39
+
40
+ unit: pint.Unit = Field(default=ureg.gray, description="Unit of the DVH bins")
41
+ name: str = Field(default="DVH", description="Name of the DVH")
42
+
43
+ bin_edges: NDArray[Shape["*"], np.float64] = Field(
44
+ alias="doseGrid", description="Left bin edges for the DVH"
45
+ )
46
+
47
+ @field_validator("unit", mode="before")
48
+ @classmethod
49
+ def validate_unit(cls, v: Any) -> pint.Unit:
50
+ """
51
+ Validate the unit of the DVH bins.
52
+
53
+ Parameters
54
+ ----------
55
+ v : Any
56
+ The unit to validate.
57
+
58
+ Returns
59
+ -------
60
+ pint.Unit: Validated unit of the DVH bins.
61
+ """
62
+
63
+ if isinstance(v, pint.Unit):
64
+ return v
65
+
66
+ try:
67
+ return ureg(v)
68
+ except pint.UndefinedUnitError:
69
+ raise ValueError(f"Invalid unit: {v}")
70
+
71
+ @model_validator(mode="after")
72
+ def check_shapes(self) -> Self:
73
+ """
74
+ Validate the shapes of the DVH data.
75
+
76
+ Returns
77
+ -------
78
+ DVH: The DVH object itself if validation passes.
79
+ """
80
+ if (
81
+ self.diff_volume.ndim != self.bin_edges.ndim
82
+ or self.diff_volume.ndim != 1
83
+ or self.bin_edges.size != self.diff_volume.size + 1
84
+ ):
85
+ raise ValueError("The shape of diff_volume must be consistent with shape of bins.")
86
+ return self
87
+
88
+ @computed_field
89
+ @property
90
+ def cum_volume(self) -> NDArray[Shape["*"], np.float64]:
91
+ """
92
+ Get the cumulative DVH Volume.
93
+
94
+ Returns
95
+ -------
96
+ NDArray: Cumulative DVH volume as a numpy array
97
+ """
98
+ return np.cumsum(self.diff_volume[::-1])[::-1]
99
+
100
+ @computed_field
101
+ @property
102
+ def cumulative(self) -> NDArray[Shape["2,*"], np.float64]:
103
+ """
104
+ Get the cumulative DVH.
105
+
106
+ Gives a 2xnum_points array with the first row being the dose / quantity
107
+ and the second row being the cumulative volume percentages.
108
+
109
+ Returns
110
+ -------
111
+ NDArray: Cumulative DVH
112
+
113
+ Notes
114
+ -----
115
+ The x coordinate (dose/quantity) corresponds to the histograms left
116
+ bin edge, as this corresponds to the meaning: Volume covered by
117
+ "at least" the respective dose/quantity value.
118
+ """
119
+ return np.vstack((self.bins, self.cum_volume))
120
+
121
+ @computed_field
122
+ @property
123
+ def differential(self) -> NDArray[Shape["2,*"], np.float64]:
124
+ """
125
+ Get the differential DVH.
126
+
127
+ Gives a 2xnum_points array with the first row being the dose
128
+ and the second row being the differential volume percentages.
129
+
130
+ Returns
131
+ -------
132
+ NDArray: Differential DVH
133
+
134
+ Notes
135
+ -----
136
+ The x ccoordinate (dose/quantity) corresponds to the histograms
137
+ bin center for the differntial DVH. This is because the differential
138
+ DVH captures the relative volume within a bin, thus the center
139
+ represents the dose/quantity value for that bin best.
140
+ Be aware of this difference to the cumulative DVH.
141
+
142
+ """
143
+ return np.vstack((self.bin_centers, self.diff_volume))
144
+
145
+ @computed_field
146
+ @property
147
+ def num_points(self) -> int:
148
+ """
149
+ Get the number of points in the DVH.
150
+
151
+ Returns
152
+ -------
153
+ int: Number of points in the DVH
154
+ """
155
+ return len(self.diff_volume)
156
+
157
+ @computed_field
158
+ @property
159
+ def bins(self) -> NDArray[Shape["*"], np.float64]:
160
+ """
161
+ Get the DVH bin left edges.
162
+
163
+ This corresponds to the dose / quantity thresholds for the cumulative volume percentages.
164
+
165
+ Returns
166
+ -------
167
+ NDArray: DVH bins as a numpy array
168
+ """
169
+ return self.bin_edges[:-1]
170
+
171
+ @computed_field
172
+ @property
173
+ def has_regular_bins(self) -> bool:
174
+ """
175
+ Check if the DVH has regular bins.
176
+
177
+ Returns
178
+ -------
179
+ bool: True if the DVH has regular bins, False otherwise
180
+ """
181
+ return np.all(np.diff(self.bin_edges) == self.bin_edges[1] - self.bin_edges[0])
182
+
183
+ @computed_field
184
+ @property
185
+ def bin_centers(self) -> NDArray[Shape["*"], np.float64]:
186
+ """
187
+ Get the centers of the DVH bins.
188
+
189
+ Returns
190
+ -------
191
+ NDArray: Centers of the DVH bins as a numpy array
192
+ """
193
+ return (self.bin_edges[:-1] + self.bin_edges[1:]) / 2.0
194
+
195
+ def get_vx(self, x: Union[float, NDArray]) -> float:
196
+ """
197
+ Get the volume percentage for a given dose (or other quantity) value.
198
+
199
+ Parameters
200
+ ----------
201
+ x : float
202
+ The dose/quantity value to get the volume percentage for.
203
+
204
+ Returns
205
+ -------
206
+ float: Volume percentage corresponding to the given dose/quantity value.
207
+ """
208
+ if x < self.bins[0] or x > self.bins[-1]:
209
+ raise ValueError("Dose value is out of bounds of the DVH bins.")
210
+
211
+ # Interpolate to find the volume percentage
212
+ return np.interp(x, self.bins, self.cum_volume)
213
+
214
+ def get_dy(self, y: Union[float, NDArray]) -> float:
215
+ """
216
+ Get the dose (or other quantity) value for a given volume percentage.
217
+
218
+ Parameters
219
+ ----------
220
+ y : float
221
+ The volume percentage to get the dose/quantity value for.
222
+
223
+ Returns
224
+ -------
225
+ float: Dose/quantity value corresponding to the given volume percentage.
226
+ """
227
+ if y < 0 or y > 100:
228
+ raise ValueError("Volume percentage must be between 0 and 100.")
229
+
230
+ # Interpolate to find the dose value
231
+ return np.interp(y / 100, self.cum_volume, self.bins)
232
+
233
+ @classmethod
234
+ def compute(
235
+ cls,
236
+ quantity: Union[sitk.Image, NDArray],
237
+ mask: Optional[Union[sitk.Image, NDArray]] = None,
238
+ num_points: int = 1000,
239
+ max_value: Optional[float] = None,
240
+ min_value: float = 0.0,
241
+ **kwargs,
242
+ ) -> Self:
243
+ """
244
+ Create a DVH from a dose_like quantity and mask.
245
+
246
+ Parameters
247
+ ----------
248
+ quantity : Union[sitk.Image, NDArray]
249
+ The dose-like quantity to update the DVH with. Can be a SimpleITK image or a numpy array.
250
+ mask : Optional[Union[sitk.Image, NDArray]], optional
251
+ The mask to apply to the dose quantity. If None, the whole image / array will be used.
252
+ If provided, it must either have the same shape as the quantity.
253
+ Defaults to None.
254
+ num_points : int, optional
255
+ The number of points in the DVH. Defaults to 100.
256
+ max_value : Optional[float], optional
257
+ The maximum value for the DVH bins. If None, it will be set to 105% of the maximum value in the quantity.
258
+ min_value : float, optional
259
+ The minimum value for the DVH bins. Defaults to 0.0.
260
+ **kwargs: Additional arguments passed to the DVH Model.
261
+
262
+ Returns
263
+ -------
264
+ DVH: DVH Object
265
+ """
266
+
267
+ # manage quantity
268
+ if isinstance(quantity, sitk.Image):
269
+ # Convert SimpleITK image to numpy array
270
+ quantity = sitk.GetArrayFromImage(quantity)
271
+
272
+ # First check if mask is provided and is valid
273
+ if mask is not None:
274
+ if isinstance(mask, sitk.Image):
275
+ # Convert SimpleITK mask to numpy array
276
+ mask = sitk.GetArrayViewFromImage(mask)
277
+
278
+ # Mask has either same dimensionality as quantity, or is a linear mask
279
+ if mask.shape != quantity.shape:
280
+ raise ValueError("Mask must have the same shape as the quantity.")
281
+
282
+ q_array = quantity[mask.astype(np.bool)].flat
283
+ else:
284
+ q_array = quantity.flat
285
+
286
+ if max_value is None:
287
+ max_value = np.max(q_array) * 1.05
288
+
289
+ # Use bin edges that include the last point
290
+ hist, edges = np.histogram(
291
+ q_array, bins=num_points, range=(min_value, max_value), density=False
292
+ )
293
+ # Remove the last bin
294
+ hist = hist / len(q_array) * 100
295
+
296
+ return DVH(diff_volume=hist, bin_edges=edges, **kwargs)
297
+
298
+ def plot(self, ax=None, line_width=2, plot_legend=True, **kwargs):
299
+ """Plot the DVH curve.
300
+
301
+ Parameters
302
+ ----------
303
+ ax : matplotlib.axes.Axes, optional
304
+ Axes to plot on. If None, creates new figure and axes. Defaults to None.
305
+ line_width : float, optional
306
+ Width of the plotted lines. Defaults to 2.
307
+ plot_legend : bool, optional
308
+ Whether to show the legend. Defaults to True.
309
+ **kwargs:
310
+ Additional arguments passed to matplotlib's plot function.
311
+
312
+ Returns
313
+ -------
314
+ matplotlib.axes.Axes: The axes containing the plot
315
+ """
316
+ if ax is None:
317
+ _, ax = plt.subplots()
318
+
319
+ # Plot with or without legend
320
+ if plot_legend:
321
+ ax.plot(
322
+ self.bins,
323
+ self.cum_volume,
324
+ linewidth=line_width,
325
+ label=self.name,
326
+ **kwargs,
327
+ )
328
+ else:
329
+ ax.plot(self.bins, self.cum_volume, linewidth=line_width, **kwargs)
330
+
331
+ # Set labels and legend
332
+ ax.set_xlabel("Dose [Gy]")
333
+ ax.set_ylabel("Volume [%]")
334
+ if plot_legend:
335
+ ax.legend()
336
+
337
+ # Set axis limits with 5% padding
338
+ ax.set_xlim(0, np.max(self.bins) * 1.05)
339
+ ax.set_ylim(0, np.max(self.cumulative) * 1.05)
340
+
341
+ return ax
342
+
343
+
344
+ class DVHCollection(PyRadPlanBaseModel):
345
+ """Collection of DVH curves for multiple structures."""
346
+
347
+ dvhs: list[DVH] = Field(description="List of DVH curves")
348
+
349
+ @classmethod
350
+ def from_structure_set(
351
+ cls,
352
+ cst: StructureSet,
353
+ dose: Union[NDArray, sitk.Image],
354
+ ) -> Self:
355
+ """
356
+ Create DVH collection from a structure set.
357
+
358
+ Parameters
359
+ ----------
360
+ cst : StructureSet
361
+ The structure set containing the VOIs (Volumes of Interest).
362
+ dose : Union[NDArray, sitk.Image]
363
+ The dose-like quantity to compute the DVH from. Can be a SimpleITK image or a numpy array.
364
+
365
+ Returns
366
+ -------
367
+ DVHCollection: Collection of DVH curves for all structures
368
+ """
369
+ dvhs = [DVH.compute(quantity=dose, mask=voi.mask, name=voi.name) for voi in cst.vois]
370
+ return cls(dvhs=dvhs)
371
+
372
+ def plot(
373
+ self,
374
+ structures: Union[list[str], None] = None,
375
+ ax=None,
376
+ line_width=2,
377
+ plot_legend=True,
378
+ **kwargs,
379
+ ):
380
+ """Plot DVH curves for selected or all structures.
381
+
382
+ Parameters
383
+ ----------
384
+ structures : Union[list[str], None], optional
385
+ List of structure names to plot. If None, all structures are plotted. Defaults to None.
386
+ ax : matplotlib.axes.Axes, optional
387
+ Axes to plot on. If None, creates new figure and axes. Defaults to None
388
+ line_width : float, optional
389
+ Width of the plotted lines. Defaults to 2.
390
+ plot_legend : bool, optional
391
+ Whether to show the legend. Defaults to True.
392
+ **kwargs:
393
+ Additional arguments passed to matplotlib's plot function.
394
+
395
+
396
+ Returns
397
+ -------
398
+ matplotlib.axes.Axes: The axes containing the plot
399
+ """
400
+ if ax is None:
401
+ _, ax = plt.subplots()
402
+
403
+ # Filter DVHs based on structure names if provided
404
+ dvhs_to_plot = self.dvhs
405
+ if structures is not None:
406
+ dvhs_to_plot = [dvh for dvh in self.dvhs if dvh.name in structures]
407
+ if not dvhs_to_plot:
408
+ raise ValueError("None of the specified structures found in DVH collection")
409
+
410
+ # Plot each DVH
411
+ for dvh in dvhs_to_plot:
412
+ dvh.plot(ax=ax, line_width=line_width, plot_legend=plot_legend, **kwargs)
413
+
414
+ return ax
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyRadPlan
3
- Version: 0.2.4
3
+ Version: 0.2.5
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>
@@ -14,6 +14,8 @@ pyRadPlan.egg-info/SOURCES.txt
14
14
  pyRadPlan.egg-info/dependency_links.txt
15
15
  pyRadPlan.egg-info/requires.txt
16
16
  pyRadPlan.egg-info/top_level.txt
17
+ pyRadPlan/analysis/__init__.py
18
+ pyRadPlan/analysis/_dvh.py
17
19
  pyRadPlan/core/__init__.py
18
20
  pyRadPlan/core/_exceptions.py
19
21
  pyRadPlan/core/_grids.py
@@ -127,6 +129,8 @@ test/test_octaveEngine.py
127
129
  test/test_plan.py
128
130
  test/test_raytracersiddon.py
129
131
  test/test_scenarios.py
132
+ test/analysis/test_dvh.py
133
+ test/analysis/test_qi.py
130
134
  test/core/test_coordinates.py
131
135
  test/core/test_datamodel.py
132
136
  test/core/test_np2sitk.py
@@ -10,7 +10,7 @@ pyRadPlan = ["data/**/*"]
10
10
 
11
11
  [project]
12
12
  name = "pyRadPlan"
13
- version = "0.2.4"
13
+ version = "0.2.5"
14
14
  # dynamic = ["version"] # Will be used in the future
15
15
  authors = [
16
16
  { name="Niklas Wahl", email = "n.wahl@dkfz-heidelberg.de"},
@@ -0,0 +1,70 @@
1
+ import pytest
2
+ from pyRadPlan import load_tg119
3
+ import SimpleITK as sitk
4
+ from pyRadPlan.analysis import DVHCollection, DVH
5
+ import numpy as np
6
+ from matplotlib import pyplot as plt
7
+
8
+
9
+ @pytest.fixture
10
+ def cst():
11
+ # Get StructureSet from TG119
12
+ return load_tg119()[1]
13
+
14
+
15
+ @pytest.fixture
16
+ def dose():
17
+ # Create dose image using information from TG119
18
+ ct, _ = load_tg119()
19
+ dose_array = np.zeros(ct.size[::-1])
20
+ dose_array[60:80, 80:120, 80:120] = 1
21
+
22
+ # Create dose image
23
+ dose_image = sitk.GetImageFromArray(dose_array)
24
+ # Copy information from CT image
25
+ dose_image.SetSpacing((ct.resolution["x"], ct.resolution["y"], ct.resolution["z"]))
26
+ dose_image.SetOrigin((ct.origin[0], ct.origin[1], ct.origin[2]))
27
+ dose_image.SetDirection(
28
+ (
29
+ ct.direction[0],
30
+ ct.direction[1],
31
+ ct.direction[2],
32
+ ct.direction[3],
33
+ ct.direction[4],
34
+ ct.direction[5],
35
+ ct.direction[6],
36
+ ct.direction[7],
37
+ ct.direction[8],
38
+ )
39
+ )
40
+ return dose_image
41
+
42
+
43
+ def test_dvhcollection(cst, dose):
44
+ dvh = DVHCollection.from_structure_set(cst=cst, dose=dose)
45
+ assert len(dvh.dvhs) == len(cst.vois)
46
+
47
+
48
+ def test_dvh(cst, dose):
49
+ n_points = 500
50
+ dvh = DVH.compute(
51
+ mask=cst.vois[0].mask, quantity=dose, name=cst.vois[0].name, num_points=n_points
52
+ )
53
+ assert dvh.name == cst.vois[0].name
54
+ assert dvh.bin_edges.shape == (n_points + 1,)
55
+ assert dvh.bins.shape == (n_points,)
56
+ assert np.all(dvh.bins == dvh.bin_edges[:-1])
57
+ assert dvh.bin_centers.shape == (n_points,)
58
+ assert np.all(dvh.bin_centers > dvh.bins)
59
+ assert dvh.diff_volume.shape == (n_points,)
60
+ assert dvh.cum_volume.shape == (n_points,)
61
+ assert dvh.cumulative.shape == (2, n_points)
62
+ assert dvh.differential.shape == (2, n_points)
63
+ assert np.array_equal(dvh.cumulative[0], dvh.bins)
64
+ assert np.array_equal(dvh.cumulative[1], dvh.cum_volume)
65
+ assert np.array_equal(dvh.differential[0], dvh.bin_centers)
66
+ assert np.array_equal(dvh.differential[1], dvh.diff_volume)
67
+
68
+ assert isinstance(dvh.has_regular_bins, np.bool)
69
+ assert dvh.get_vx(1.0) == np.interp(1.0, dvh.cumulative[0], dvh.cumulative[1])
70
+ assert dvh.get_dy(50) > 0.0
@@ -0,0 +1 @@
1
+ import pytest
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes