pyRadPlan 0.0.1__py3-none-any.whl

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 (137) hide show
  1. examples/carbon_pencilbeam.py +87 -0
  2. examples/helium_pencilbeam.py +80 -0
  3. examples/import_matrad_patient.py +102 -0
  4. examples/photon_pencilbeam.py +66 -0
  5. examples/proton_pencilbeam.py +80 -0
  6. pyRadPlan/GUI.py +5 -0
  7. pyRadPlan/__init__.py +34 -0
  8. pyRadPlan/core/__init__.py +15 -0
  9. pyRadPlan/core/_exceptions.py +9 -0
  10. pyRadPlan/core/_grids.py +231 -0
  11. pyRadPlan/core/datamodel.py +68 -0
  12. pyRadPlan/core/np2sitk.py +147 -0
  13. pyRadPlan/core/resample.py +130 -0
  14. pyRadPlan/cst/__init__.py +15 -0
  15. pyRadPlan/cst/_cst.py +307 -0
  16. pyRadPlan/cst/_voi.py +603 -0
  17. pyRadPlan/ct/__init__.py +4 -0
  18. pyRadPlan/ct/_ct.py +525 -0
  19. pyRadPlan/ct/_hlut.py +27 -0
  20. pyRadPlan/data/machines/carbon_Generic.mat +0 -0
  21. pyRadPlan/data/machines/helium_Generic.mat +0 -0
  22. pyRadPlan/data/machines/photons_Generic.mat +0 -0
  23. pyRadPlan/data/machines/protons_Generic.mat +0 -0
  24. pyRadPlan/data/phantoms/TG119.mat +0 -0
  25. pyRadPlan/data/stf/matRad_stf.mat +0 -0
  26. pyRadPlan/data/stf/matrad_stf_onebeam.mat +0 -0
  27. pyRadPlan/dij/__init__.py +4 -0
  28. pyRadPlan/dij/_dij.py +410 -0
  29. pyRadPlan/dose/__init__.py +6 -0
  30. pyRadPlan/dose/_calc_dose.py +64 -0
  31. pyRadPlan/dose/engines/__init__.py +17 -0
  32. pyRadPlan/dose/engines/_base.py +591 -0
  33. pyRadPlan/dose/engines/_base_pencilbeam.py +806 -0
  34. pyRadPlan/dose/engines/_base_pencilbeam_particle.py +1015 -0
  35. pyRadPlan/dose/engines/_factory.py +108 -0
  36. pyRadPlan/dose/engines/_hongpb.py +75 -0
  37. pyRadPlan/dose/engines/_svdpb.py +275 -0
  38. pyRadPlan/geometry/__init__.py +7 -0
  39. pyRadPlan/geometry/lps.py +122 -0
  40. pyRadPlan/io/.gitkeep +0 -0
  41. pyRadPlan/io/__init__.py +3 -0
  42. pyRadPlan/io/matLabFileHandler.py +25 -0
  43. pyRadPlan/io/matRad.py +22 -0
  44. pyRadPlan/io/readHLUT.py +17 -0
  45. pyRadPlan/io/temp_files/cst.mat +0 -0
  46. pyRadPlan/io/temp_files/ct.mat +0 -0
  47. pyRadPlan/io/temp_files/pln.mat +0 -0
  48. pyRadPlan/io/temp_files/stf_with_separate_rays.mat +0 -0
  49. pyRadPlan/machines/__init__.py +19 -0
  50. pyRadPlan/machines/_base.py +164 -0
  51. pyRadPlan/machines/_ions.py +528 -0
  52. pyRadPlan/machines/_load.py +48 -0
  53. pyRadPlan/machines/_photons.py +220 -0
  54. pyRadPlan/machines/_validate.py +61 -0
  55. pyRadPlan/matRad/.gitkeep +0 -0
  56. pyRadPlan/matRad/__init__.py +18 -0
  57. pyRadPlan/matRad/_engine.py +36 -0
  58. pyRadPlan/matRad/_matlab.py +26 -0
  59. pyRadPlan/matRad/_octave.py +51 -0
  60. pyRadPlan/optimization/__init__.py +12 -0
  61. pyRadPlan/optimization/_fluenceOptimizer.py +312 -0
  62. pyRadPlan/optimization/_fluence_optimization.py +57 -0
  63. pyRadPlan/optimization/components/__init__.py +3 -0
  64. pyRadPlan/optimization/components/_optimizationProblem.py +162 -0
  65. pyRadPlan/optimization/components/objectives/_EUD.py +93 -0
  66. pyRadPlan/optimization/components/objectives/__init__.py +19 -0
  67. pyRadPlan/optimization/components/objectives/_doseUniformity.py +81 -0
  68. pyRadPlan/optimization/components/objectives/_maxDVH.py +92 -0
  69. pyRadPlan/optimization/components/objectives/_meanDose.py +80 -0
  70. pyRadPlan/optimization/components/objectives/_minDVH.py +92 -0
  71. pyRadPlan/optimization/components/objectives/_objectiveClass.py +98 -0
  72. pyRadPlan/optimization/components/objectives/_squaredDeviation.py +82 -0
  73. pyRadPlan/optimization/components/objectives/_squaredOverdosing.py +84 -0
  74. pyRadPlan/optimization/components/objectives/_squaredUnderdosing.py +84 -0
  75. pyRadPlan/optimization/projections/__init__.py +5 -0
  76. pyRadPlan/optimization/projections/_backProjection.py +59 -0
  77. pyRadPlan/optimization/projections/_constantRBEProjection.py +26 -0
  78. pyRadPlan/optimization/projections/_doseProjection.py +25 -0
  79. pyRadPlan/optimization/solvers/__init__.py +18 -0
  80. pyRadPlan/optimization/solvers/_ipopt.py +89 -0
  81. pyRadPlan/optimization/solvers/_scipy_solver.py +120 -0
  82. pyRadPlan/plan/__init__.py +3 -0
  83. pyRadPlan/plan/_plans.py +360 -0
  84. pyRadPlan/raytracer/__init__.py +4 -0
  85. pyRadPlan/raytracer/_base.py +289 -0
  86. pyRadPlan/raytracer/_perf.py +227 -0
  87. pyRadPlan/raytracer/_siddon.py +428 -0
  88. pyRadPlan/scenarios/__init__.py +102 -0
  89. pyRadPlan/scenarios/_base.py +374 -0
  90. pyRadPlan/scenarios/_nominal.py +126 -0
  91. pyRadPlan/stf/__init__.py +29 -0
  92. pyRadPlan/stf/_base.py +226 -0
  93. pyRadPlan/stf/_beam.py +195 -0
  94. pyRadPlan/stf/_beamlet.py +106 -0
  95. pyRadPlan/stf/_exceptions.py +14 -0
  96. pyRadPlan/stf/_externalbeam.py +162 -0
  97. pyRadPlan/stf/_generate_stf.py +23 -0
  98. pyRadPlan/stf/_ions.py +255 -0
  99. pyRadPlan/stf/_photons.py +125 -0
  100. pyRadPlan/stf/_rangeshifter.py +40 -0
  101. pyRadPlan/stf/_ray.py +201 -0
  102. pyRadPlan/stf/_steeringinformation.py +181 -0
  103. pyRadPlan/stf/base_matrad.py +6 -0
  104. pyRadPlan/stf/hlutLibrary/matRad_default.hlut +10 -0
  105. pyRadPlan/stf/loadHLUT.py +63 -0
  106. pyRadPlan/util/__init__.py +0 -0
  107. pyRadPlan/util/helpers.py +209 -0
  108. pyRadPlan-0.0.1.dist-info/LICENSE +28 -0
  109. pyRadPlan-0.0.1.dist-info/METADATA +70 -0
  110. pyRadPlan-0.0.1.dist-info/RECORD +137 -0
  111. pyRadPlan-0.0.1.dist-info/WHEEL +5 -0
  112. pyRadPlan-0.0.1.dist-info/top_level.txt +3 -0
  113. test/core/test_coordinates.py +46 -0
  114. test/core/test_np2sitk.py +178 -0
  115. test/core/test_resample.py +45 -0
  116. test/cst/conftest.py +57 -0
  117. test/cst/test_VOI.py +422 -0
  118. test/cst/test_cst.py +144 -0
  119. test/ct/test_ct.py +218 -0
  120. test/ct/test_hlut.py +10 -0
  121. test/dose/test_dose_particle.py +234 -0
  122. test/dose/test_dose_photon.py +22 -0
  123. test/geometry/test_lps.py +96 -0
  124. test/stf/test_beamlet.py +53 -0
  125. test/stf/test_stf.py +205 -0
  126. test/stf/test_stf_gen.py +295 -0
  127. test/test_dij.py +238 -0
  128. test/test_fileHandling.py +37 -0
  129. test/test_grid.py +148 -0
  130. test/test_helpers.py +65 -0
  131. test/test_machine_model.py +155 -0
  132. test/test_matlabEngine.py +30 -0
  133. test/test_objectives.py +371 -0
  134. test/test_octaveEngine.py +30 -0
  135. test/test_plan.py +158 -0
  136. test/test_raytracersiddon.py +104 -0
  137. test/test_scenarios.py +198 -0
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024, DKFZ
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,70 @@
1
+ Metadata-Version: 2.2
2
+ Name: pyRadPlan
3
+ Version: 0.0.1
4
+ Summary: A python interface and reimplementation to matRad
5
+ Author-email: 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>, Niklas Wahl <n.wahl@dkfz-heidelberg.de>
6
+ Maintainer-email: Goran Stanic <goran.stanic@dkfz-heidelberg.de>, Tim Ortkamp <tim.ortkamp@kit.edu>, Tobias Becher <t.becher@dkfz-heidelberg.de>, Niklas Wahl <n.wahl@dkfz-heidelberg.de>
7
+ Project-URL: Homepage, https://git.dkfz.de
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: BSD License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: scipy==1.14.0
15
+ Requires-Dist: numpy==2.0.0
16
+ Requires-Dist: pymatreader==1.0.0
17
+ Requires-Dist: h5py==3.11.0
18
+ Requires-Dist: regex==2024.5.15
19
+ Requires-Dist: pydicom==2.4.4
20
+ Requires-Dist: numba==0.60.0
21
+ Requires-Dist: matplotlib==3.9.2
22
+ Requires-Dist: pydantic==2.8.2
23
+ Requires-Dist: numpydantic==1.6.6
24
+ Requires-Dist: SimpleITK==2.4.0
25
+ Requires-Dist: tqdm>=4.0.0
26
+ Provides-Extra: matlab
27
+ Requires-Dist: matlabengine; extra == "matlab"
28
+ Provides-Extra: octave
29
+ Requires-Dist: oct2py; extra == "octave"
30
+ Provides-Extra: gui
31
+ Requires-Dist: PyQt5; extra == "gui"
32
+ Provides-Extra: dev
33
+ Requires-Dist: pytest; extra == "dev"
34
+ Requires-Dist: coverage; extra == "dev"
35
+ Requires-Dist: pytest-cov; extra == "dev"
36
+ Requires-Dist: pre-commit; extra == "dev"
37
+
38
+ ![tests](https://git.dkfz.de/e040/e0404/pyRadPlan/badges/main/pipeline.svg)
39
+ ![coverage](https://git.dkfz.de/e040/e0404/pyRadPlan/badges/main/coverage.svg?min_medium=50&min_acceptable=65&min_good=80)
40
+
41
+ # pyRadPlan
42
+ pyRadPlan is an open-source radiotherapy treatment planning toolkit designed for interoperability with [matRad](http://www.matRad.org).
43
+
44
+ Development is lead by the [Radiotherapy Optimization group](https://www.dkfz.de/radopt) at the [German Cancer Research Center (DKFZ)](https://www.dkfz.de)
45
+
46
+ ## Concept and Goals
47
+ 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 staget of the treatment planning workflow.
48
+
49
+ To enforce valid datastructures, we perform validation and serialization with pydantic.
50
+ Datastructures and algorithms rely mostly on SimpleITK, numpy, and scipy for internal data representation and processing.
51
+
52
+ If you are interested in helping with development, get in touch.
53
+
54
+ ## Note for Developers
55
+ pyRadPlan development uses unit-testing and code formatting via pre-commit hooks to ensure clean code.
56
+ If you are a developer or want to contribute, make sure to clone the latest state via git. Then, we strongly suggest to create a virtual python environment with a suitable version and do an editable installation of pyRadPlan in dev mode: `pip install -e .[dev]`
57
+
58
+ > **Note**
59
+ > If you are using venv to create a virtual environment in the project's root folder, we suggest to name it `.venv` as this folder will be automatically excluded by all formatters and linters
60
+
61
+ This will install an editable pyRadPlan module including `pytest` and `pre-commit` in addition to the standard modules.
62
+ - **pytest** is used to run unit tests before publishing the code. Run on the test folder via `pytest test`, or choose any test file following the pytest syntax. We encourage writing at least fundamental unit tests for new code. Will also install `coverage` and the pytest extension to monitor coverage.
63
+ - **pre-commit** allows for automatic code formatting to ensure following of PEPs (mainly PEP8 and PEP257).
64
+
65
+ After successfully running `pip install -e .[dev]` check in the console that `pre-commit --version` provides a correct response.
66
+ Afterwards run `pre-commit install`. This reads the `.pre-commit_config.yaml` and adds a hook to your git repository, which whenever a commit is made the changed files are reformatted to ensure the PEP standards.
67
+
68
+ ### Matlab / Octave Engine
69
+ If you want to interface via matRad, you can use install the matlab engine by appending `[matlab]` to the pip install command. However, as there is some compatibility matrix for what matlabengine version is suitable for your Matlab installation, it might be better to not install the latest version but instead install the correct matlabengine manually before.
70
+ To use Octave via oct2py, analogously append `[octave]`.
@@ -0,0 +1,137 @@
1
+ examples/carbon_pencilbeam.py,sha256=a60Re6x9sceoN4ZGQ63GRuZvhiLSRxkA6sPsSt1fLtk,2521
2
+ examples/helium_pencilbeam.py,sha256=DI5tpr8lTeczHzqpLZ8HTiy0Im627lYWOD0RaABIN5k,2106
3
+ examples/import_matrad_patient.py,sha256=8yFYzpO0LN6XOfvmOv-RIrv2EkRRt8w5Z5GsiwfEX-0,3634
4
+ examples/photon_pencilbeam.py,sha256=ztknn0Ttx4arf7Tdoz9e1o_RPHCEX3oKftwlTB9l-1Q,2330
5
+ examples/proton_pencilbeam.py,sha256=DwNXfFJS85WoMboh0VnEMrKP4U34HgHPL2yusrmd-bQ,2099
6
+ pyRadPlan/GUI.py,sha256=mwlsegH8zOpJUA90fkrDubzTgcxeP0tngb5-SsKdf-M,186
7
+ pyRadPlan/__init__.py,sha256=1cvj4Ahd2nMLoBAAIDyVfgKk9EKgCSqIl-qkEX1SBDE,960
8
+ pyRadPlan/core/__init__.py,sha256=CbDwwzAkdQk6zHGRiPoxdOLttVM6e5OEI5i9xE-kGBk,402
9
+ pyRadPlan/core/_exceptions.py,sha256=WtsjmcMjYPsCC9tlxAtq23x-ghc5RXzSBtFCdRsMl8U,255
10
+ pyRadPlan/core/_grids.py,sha256=A7OTwYzEdc26Gig6Sk7k97-Qk_PSCNJ7eFra3dpjdYA,8435
11
+ pyRadPlan/core/datamodel.py,sha256=F8FFVuJPIeCtXCL9w4GW0cxeeVw5AvOChImK7abxDc0,2356
12
+ pyRadPlan/core/np2sitk.py,sha256=_4z6d9tRh11F26dXG8cMtdT0D4RYWVkLSi7DSxgGv8k,4392
13
+ pyRadPlan/core/resample.py,sha256=ABjfBKICFrJCEqymY3HDs7ntpSx-GTNm3rwfSV8TrS0,4788
14
+ pyRadPlan/cst/__init__.py,sha256=QaekJdXEAPs5bX3VWEIdiRaBZTQ89QxcKjLKIosnmas,340
15
+ pyRadPlan/cst/_cst.py,sha256=c9vKppXKGvN_jsAm7QbjPvV36cCuYY8dhExFUxgSdJ4,10788
16
+ pyRadPlan/cst/_voi.py,sha256=eXYZ2yr5xaLJ24dl46ayTDBgTU25iElkUZuqQmkdowM,16537
17
+ pyRadPlan/ct/__init__.py,sha256=X3yFJIzqzMDc97atxL3-F0juTBkzqusX054fkW2o0W4,200
18
+ pyRadPlan/ct/_ct.py,sha256=uEGzOIJOmuph4L4e1Wq0-Os3CiW5HeUZqCsdj5qIDSE,15950
19
+ pyRadPlan/ct/_hlut.py,sha256=L4xrd-OCVElvZyHaTUu8kp_70Yp3faIPWKRhjup3Qps,570
20
+ pyRadPlan/data/machines/carbon_Generic.mat,sha256=ReO-U5cXsLq4YwYyon4ysIAK6YP8OX_9myA_s9LQdU0,840401
21
+ pyRadPlan/data/machines/helium_Generic.mat,sha256=6SUObCosHC1E0VyOHRR7Ip4pG8J6qoYOu0Hvyu4GhOg,974402
22
+ pyRadPlan/data/machines/photons_Generic.mat,sha256=ru-SxCGBYO4i4PY5HKC-lCuCVZlX8jsjSyM-gGzV6Xk,2259101
23
+ pyRadPlan/data/machines/protons_Generic.mat,sha256=JNGl8k4K3LObKKpoh4fIyVWdQZo5JzorkJPpCI2WOT0,1239807
24
+ pyRadPlan/data/phantoms/TG119.mat,sha256=9ONP-s46ncLOIRBsZZIdWQ-r1y6v-deIRcktAP-0LHQ,23728931
25
+ pyRadPlan/data/stf/matRad_stf.mat,sha256=AdqY9nKn4c4fzRMV0d4dXzySQ5zD3BmoiXxMG_IqRME,252774
26
+ pyRadPlan/data/stf/matrad_stf_onebeam.mat,sha256=LAVw9S0NirKHEfp_HOdsBrZnovKgxtVWBkjFkwpWRLM,40699
27
+ pyRadPlan/dij/__init__.py,sha256=gy4ySBJYhunpi62Zk0yXJCSpkjHDcCGa9OLO4GRfHm0,168
28
+ pyRadPlan/dij/_dij.py,sha256=r9yjoLaOnbi7GB4QK7CtXLYgu2fHNUYSF48nb9AzLxk,13886
29
+ pyRadPlan/dose/__init__.py,sha256=tMstTwQMhIKn6Aa54coqYFWwm5w3C7gpT6NBRA24sC0,136
30
+ pyRadPlan/dose/_calc_dose.py,sha256=TZ4DKHZmu6-OiGfRP-2Ju7JOe0Psukv4BwO1EERQ4Jo,1353
31
+ pyRadPlan/dose/engines/__init__.py,sha256=CZ10F375TbN8AykvOAzMQjkGdl_JY4rtyQ54jOeqXmA,488
32
+ pyRadPlan/dose/engines/_base.py,sha256=pC1fj7pnhjwHR1Q9uRVXN9_oo3AbNJ3lmI95EGxJ-Ks,23584
33
+ pyRadPlan/dose/engines/_base_pencilbeam.py,sha256=_6HJ4-G34lXJ1__curoQy1k3dGV493VKx4P4s93bGmI,30749
34
+ pyRadPlan/dose/engines/_base_pencilbeam_particle.py,sha256=ARxWsa1JHGg4Uu9zYKkfeEreEHwTDTHgfQPJtydqSpc,39117
35
+ pyRadPlan/dose/engines/_factory.py,sha256=MNk4szqpExqhmoewbFOROoXpmqWl4OmCmg-thgKPT3E,3498
36
+ pyRadPlan/dose/engines/_hongpb.py,sha256=psqsEZzsh_4RRZt1aR1VAH17W5SizYLG_W154ulGZ4E,3042
37
+ pyRadPlan/dose/engines/_svdpb.py,sha256=dsOruabu0IWRXevOutOKQEFZ-ODEaZXyu2x5-fSdFhM,10044
38
+ pyRadPlan/geometry/__init__.py,sha256=kSg26jDTabb5xVOig0s5YZMwnGHhiF3guohhj2rO9nM,218
39
+ pyRadPlan/geometry/lps.py,sha256=xmVoVRjJrEgTl9GrXvX2mPfbd9jKtaWgYMjOXIVQ0ck,3460
40
+ pyRadPlan/io/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
+ pyRadPlan/io/__init__.py,sha256=diM0wfvGRyvyjTkxiFsKiw2TQjCj5F8epvKwDObpVqU,85
42
+ pyRadPlan/io/matLabFileHandler.py,sha256=mWxziFdl2tYK-fZij-XiVrw5PueNWL5la5Q_zxaF568,798
43
+ pyRadPlan/io/matRad.py,sha256=fM9SE1pJjqAPzRSeemZJEAp2lbShdqUVpc42284IdVg,655
44
+ pyRadPlan/io/readHLUT.py,sha256=FEX-SwrMb8G_ncKjEogWfLSgahAArsT5Y1bQ5dd-qnw,420
45
+ pyRadPlan/io/temp_files/cst.mat,sha256=99q1t_WwM99w92Juk5YsIz7CTYLwvaCNtr6DCDXokZg,4887840
46
+ pyRadPlan/io/temp_files/ct.mat,sha256=o9LZoepTDFPSf0y6s-oMhDeEEsIyCwxQI9N1RQvc6Rc,57581216
47
+ pyRadPlan/io/temp_files/pln.mat,sha256=SQk99vo2cukiLTLc-IeNxEZL6GIv5ne-Ld_2UoPqIds,2008
48
+ pyRadPlan/io/temp_files/stf_with_separate_rays.mat,sha256=bTUHbZuSsOECe6AXs1AwL78pyV3TFya-G1CV3UOXNU4,1211488
49
+ pyRadPlan/machines/__init__.py,sha256=daksFs1kcd6RJI0iHWC_MnxOf3zspNcsPG9sGE3kZTA,563
50
+ pyRadPlan/machines/_base.py,sha256=EjBh0XiEdDbLQMEV3NT4Nt10dxeMp4HXG0iD9fwFDl8,5466
51
+ pyRadPlan/machines/_ions.py,sha256=eyIKYBnFpQYvRKEXXytYN5GdXT-c8Z8k4Ei5okd1VCg,17673
52
+ pyRadPlan/machines/_load.py,sha256=ws-bfHw0MQ4tIZjQzHjQeqYWCyqNYn1yldApbvgIG3s,1632
53
+ pyRadPlan/machines/_photons.py,sha256=vdjAiy7Y3DjRYR14DiyI86arNCPsCap4LNq3KnctDV0,7966
54
+ pyRadPlan/machines/_validate.py,sha256=OsixBcbclXm9rlQA_8t3-Cfuau01y-CGLOU8KvBhIJU,1955
55
+ pyRadPlan/matRad/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
56
+ pyRadPlan/matRad/__init__.py,sha256=jGVLUjLrXQ4YneNw4nWgQixC6DZPV9uGHtKR2Rdth9g,513
57
+ pyRadPlan/matRad/_engine.py,sha256=BjZ_MBV7xisP7z3-DO6URQNJ2_aGML8n1pBsifkA5dw,735
58
+ pyRadPlan/matRad/_matlab.py,sha256=DEGYX6G73g2emUeBKYTnBrMtB7vK83TpusJprnPxMQ8,776
59
+ pyRadPlan/matRad/_octave.py,sha256=Em9pwp6R2l08nfRR_r7jG8GVz35cTJKgUEUMnAYlcDE,1359
60
+ pyRadPlan/optimization/__init__.py,sha256=VW7ZxXCWxmWg5izozL0RRisFQX1VWBh5uArqE7tpivw,409
61
+ pyRadPlan/optimization/_fluenceOptimizer.py,sha256=DDOG0L6ltNs5BihsWP32XNLgnYurTSDP1bc-G3Bhsnw,10965
62
+ pyRadPlan/optimization/_fluence_optimization.py,sha256=XRY7aQK4-6Cy9PDyJazh0IYnI9WTNmio0uV0r4o0CYM,2082
63
+ pyRadPlan/optimization/components/__init__.py,sha256=SLXhDV8Mu0oH7Aat7YbIwZler_fmyCSWpxpCxKmnnrU,92
64
+ pyRadPlan/optimization/components/_optimizationProblem.py,sha256=Ncwz21QCaW75fJVkoFvP2K0IEWrIhxQDPITE6JwArJE,5366
65
+ pyRadPlan/optimization/components/objectives/_EUD.py,sha256=x4s4PXDD_AWDXkTZ3yEHxJ8rh8BnMUzMlaEMyFzI6PM,2478
66
+ pyRadPlan/optimization/components/objectives/__init__.py,sha256=Qocx3AheLAPpsueLnQy37ziMZdqMgHbdFPIgteZoPpk,490
67
+ pyRadPlan/optimization/components/objectives/_doseUniformity.py,sha256=av4bJ-2g2c31Iq0-LgJLCrjUngf9JveQO9jvTL-uMKU,2029
68
+ pyRadPlan/optimization/components/objectives/_maxDVH.py,sha256=moTFYaJwYgCzzpri-oRrOc5ljdn8pwf-Cn6Pjtn8YMc,2519
69
+ pyRadPlan/optimization/components/objectives/_meanDose.py,sha256=TIFBaS9WD3Z6Qx0EbWKx9Ns_SkzQAU-69W0IxF7XlQY,2047
70
+ pyRadPlan/optimization/components/objectives/_minDVH.py,sha256=8w1pRClxUnYD7OyatFBmPD4zI_mI_91TymdP1DOtfTU,2512
71
+ pyRadPlan/optimization/components/objectives/_objectiveClass.py,sha256=1Ofxete6eSvMKsX1hvVaY_svN3lbm2-wqOMnM-lDUEk,2941
72
+ pyRadPlan/optimization/components/objectives/_squaredDeviation.py,sha256=_IqrqjBrvnzsYHhEUwewJiwMX4LHli1B_0lB0kjhbKM,2103
73
+ pyRadPlan/optimization/components/objectives/_squaredOverdosing.py,sha256=l48AOOUZ9u1NbDEHj0AaNzPm0w0dDUoWb11Sx-FZa98,2235
74
+ pyRadPlan/optimization/components/objectives/_squaredUnderdosing.py,sha256=ZBKw8tlbBkwW1cANXghD0_Tplm1ISGGlE2LJbhSy69k,2244
75
+ pyRadPlan/optimization/projections/__init__.py,sha256=qQrLq9uWzWqaGK3DKWU6JbLHIBxsPWxZSMyt-h4tido,224
76
+ pyRadPlan/optimization/projections/_backProjection.py,sha256=g_m6sr9Wc4jLMm7xJWwLa8Qapc-iPlYqzmYLGo3YqBE,1349
77
+ pyRadPlan/optimization/projections/_constantRBEProjection.py,sha256=kLLCkorMgss2b_zAQoc5erqsgUaI8faLJ4tR_bE07UA,551
78
+ pyRadPlan/optimization/projections/_doseProjection.py,sha256=YMNrAx80E07MLpGzH685R20AfjGw8UE3CqtvV48a348,480
79
+ pyRadPlan/optimization/solvers/__init__.py,sha256=_J-NAygE9784CcSygpwQ97IHPJxwY885GiZ2RK8aVyM,428
80
+ pyRadPlan/optimization/solvers/_ipopt.py,sha256=nDJ8unCflBfSk7m9_L7botmNN_uGcrz3OtBB2R3uxeU,2742
81
+ pyRadPlan/optimization/solvers/_scipy_solver.py,sha256=shjqzL4iMW0ZKtk43tBksxk9U8Mb7F6GqdfjVsopy3k,3410
82
+ pyRadPlan/plan/__init__.py,sha256=-uaeelTBELnp1Y_5xXzhn77L7g75JJre0BDFnLkh9zk,150
83
+ pyRadPlan/plan/_plans.py,sha256=RIph7AD6lyYAZkWOvX7e1w0lhIS5oaH3A4y9PtXEcCs,10410
84
+ pyRadPlan/raytracer/__init__.py,sha256=2D5ifYbD2rx_BY-sBhVf7cfyWxAqp_pXFKZEzMDr9nk,122
85
+ pyRadPlan/raytracer/_base.py,sha256=sJpjXHHy9RFAU1vx7WbQG0yWHo7cLZFsaieM4Ju_wRo,11319
86
+ pyRadPlan/raytracer/_perf.py,sha256=y0IDuN1O4bkxN8G2TbUaDp9ENz8qRWMOHlf_AS4OTaQ,7791
87
+ pyRadPlan/raytracer/_siddon.py,sha256=X2udtIE2Th4B_SRSKOgLZhMtd26u86d9dafvhetil_c,17171
88
+ pyRadPlan/scenarios/__init__.py,sha256=iiX68wKU4zvFcNEn8r1oaLltQaTsm8wobN9HOJiW2C8,3040
89
+ pyRadPlan/scenarios/_base.py,sha256=m2xfc-DI9BCbvv6P4EvcGTA6pVB5fYzcoSebZfGW8mI,11732
90
+ pyRadPlan/scenarios/_nominal.py,sha256=5-FupnCxs6unMcGsypmBfjn3YsuX585T3SGmZ-q7qGw,4112
91
+ pyRadPlan/stf/__init__.py,sha256=ZxWv6pwTwt92GmAVggDP_1J1r1pDNGZjoC3PuMaAMf8,955
92
+ pyRadPlan/stf/_base.py,sha256=7zC65Rxuis_GoVf21s_aPsnDYNjQGy2KxY9qD89cRnk,8289
93
+ pyRadPlan/stf/_beam.py,sha256=2VgU0T8g9Gnn9N6dtQvQIG3W-qoH0gAl_lFiOTAoVTE,6752
94
+ pyRadPlan/stf/_beamlet.py,sha256=ak5Yu41g8WvdDexNrncCkkliiBFg-LeCpLePrZYRjXQ,3526
95
+ pyRadPlan/stf/_exceptions.py,sha256=PmHMFifhI0nVNI0obJ50XPDbP9BzR46LM3rEkRDlkW4,381
96
+ pyRadPlan/stf/_externalbeam.py,sha256=u7x9TNMm8DuhV3UtPUOWtdDvUHspq7-hszp8JwERcho,6234
97
+ pyRadPlan/stf/_generate_stf.py,sha256=UEjYXw_EJ6wek8vXnMkkB-rvhokMljqFS_T9SIc-oDU,761
98
+ pyRadPlan/stf/_ions.py,sha256=NT0HYPgMbnYbUwzrpKRVBIXs57zcDI3RmRo4Wb3IfwE,9534
99
+ pyRadPlan/stf/_photons.py,sha256=uJH41nR5nbLC23F5mAou_izWmvP0mxaT65Z6TC95tMw,3773
100
+ pyRadPlan/stf/_rangeshifter.py,sha256=LRmcHph3GMX4yBRXsXTVxHB4DoWnBkbv7v94HsHXgjA,1419
101
+ pyRadPlan/stf/_ray.py,sha256=624KYZdtIcXDrT28cc_9xtgfExptRQvgfbKF_Sh7afo,7751
102
+ pyRadPlan/stf/_steeringinformation.py,sha256=Xm3LXFFhQyDlgennoEVq0ViGPSZtfUmuy940nmCD71c,6090
103
+ pyRadPlan/stf/base_matrad.py,sha256=P4_aN-T6EpAFbVZR__MHw_K2X5C47bR5kMoBqQtqc-s,168
104
+ pyRadPlan/stf/loadHLUT.py,sha256=1wd_RDOtN1vFZg8lqRuE1qYlIleFaDDC1cS_ZMIkhwI,1817
105
+ pyRadPlan/stf/hlutLibrary/matRad_default.hlut,sha256=-zJ9dweKrqjMKBDfQ9XyZr4wUHOyIKzV9eTVJLRXEBU,290
106
+ pyRadPlan/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
107
+ pyRadPlan/util/helpers.py,sha256=KUv9uj-ryOQ5ueLHwmGuY8mWMC7DCZ_wCq5PXbRvQbM,7626
108
+ test/test_dij.py,sha256=rotqoPVFXPH_iHtKCnV1ylfknH7J3AOTZODLEuxuBhc,8496
109
+ test/test_fileHandling.py,sha256=jvwsubGXR_ME9Fk6TH8i4FGj6cDZ7QJ3_NrboP6h-IY,1051
110
+ test/test_grid.py,sha256=I8_ozdHyA9K3AYXr8BTAd_Ka9hoR4HrCu5Zj3L5-xBg,5587
111
+ test/test_helpers.py,sha256=coVX7aiOZQdwfIgL37Ug9utVNS9Cr2pmdLJOimtlqOo,1970
112
+ test/test_machine_model.py,sha256=CIDecnidgbYu0tfZh6RK2BAqRL6zyKhXCYNllh1y6hY,5685
113
+ test/test_matlabEngine.py,sha256=OwG1O_45BrK_gFteaEsyGMpObvjmcuSMCYRsDF0z6Y0,701
114
+ test/test_objectives.py,sha256=H5Zu15YlEmbPvRdUcjsM01oUEy302l7a-_VbFildGv4,12271
115
+ test/test_octaveEngine.py,sha256=-Tcli9tVg8ao2yzLyVyp0hwzYJMn9M5COWe4Q41mP4U,677
116
+ test/test_plan.py,sha256=rPc37hGVwyenL1HG36ZJxKgFeCnnwhv8x9bfisEw6Qc,4533
117
+ test/test_raytracersiddon.py,sha256=ubaTNh4c0Ip6KYil7P_wHMH1lXLxI043KGrVWaN7ik0,3707
118
+ test/test_scenarios.py,sha256=L-dsaLuoacKq7nyATWq7sq-vs6-XEr82agkoSuYHWhU,6743
119
+ test/core/test_coordinates.py,sha256=coCPNKHCet17iy7aX-u78EmUq10Uc-9gz2h_uMnoKag,1394
120
+ test/core/test_np2sitk.py,sha256=2c4GHx9aGJe4SQPDDsAHbJOuxtQqaegSMrMxYuVzuH4,5945
121
+ test/core/test_resample.py,sha256=pmHxUclp2ioLyn4BBcjVTZlZblvezfIJQb0LrrCJsSY,1696
122
+ test/cst/conftest.py,sha256=bCmYcxtJR38bpaMfZcNhUoJeL2Hxzr-VXBkGDsy8XNg,1766
123
+ test/cst/test_VOI.py,sha256=cHkcXwhphFNuia6bSEKb2tYOb0ySGO2UDUtw0vS8wK4,16308
124
+ test/cst/test_cst.py,sha256=VmYekLyLC1UCWuueXDperq4dRrYhSQw-DKHwa649bHE,5155
125
+ test/ct/test_ct.py,sha256=2GSGgYIqzAk_ZrFqBLo2Y8DJlTHcZ7KbEHK_9NbpQrg,7464
126
+ test/ct/test_hlut.py,sha256=4PlzhxgSbT0PUKk8J9CUtitAJZN4Nq5t7cFjSXp-SEg,249
127
+ test/dose/test_dose_particle.py,sha256=2JtSRUDgiBo2kZdshUHZ7hkgQI2hDkioAZrLNTgIjN4,7183
128
+ test/dose/test_dose_photon.py,sha256=pV1zkDB2kC3sjpOItBDgkMAgFfR8vD2L2BOLV6OBtGg,681
129
+ test/geometry/test_lps.py,sha256=_7GyFsYFLWP8wNpL_Hl4YmGB9U6FqfWyWfnUTgOqn3E,3355
130
+ test/stf/test_beamlet.py,sha256=DH_ZdROeKI-2tGisni2285UTyytxYhHoQW_qjvFlmiM,1768
131
+ test/stf/test_stf.py,sha256=o01t4329N8JXApGogpGGGhkygnAMfYIK5hIxHhy0z08,7580
132
+ test/stf/test_stf_gen.py,sha256=9dpGvG_iyg-7VCMk9sIF9GutL0Ohd9rAgEoGlhlhZkQ,9838
133
+ pyRadPlan-0.0.1.dist-info/LICENSE,sha256=EUuOrWuDRiW110EErAYQgbKngLHCyXuuRK8XuDTHfOs,1519
134
+ pyRadPlan-0.0.1.dist-info/METADATA,sha256=AcJ6IBKo_938cPceX9FrRxH4uYYq9V8ejEc8qlMSzDM,4776
135
+ pyRadPlan-0.0.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
136
+ pyRadPlan-0.0.1.dist-info/top_level.txt,sha256=wTRaAWWgNh8CCGY3BOHCdn6oAn_vFlC1fuoGD-aLWf4,24
137
+ pyRadPlan-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (75.8.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ examples
2
+ pyRadPlan
3
+ test
@@ -0,0 +1,46 @@
1
+ from importlib import resources
2
+ from typing import cast
3
+ import pytest
4
+
5
+ import SimpleITK as sitk
6
+ import numpy as np
7
+
8
+ import pyRadPlan.io.matRad as matRadIO
9
+ from pyRadPlan.core import np2sitk
10
+ from pyRadPlan.ct import validate_ct, CT
11
+ from pyRadPlan.cst import validate_cst, StructureSet
12
+
13
+
14
+ @pytest.fixture
15
+ def tg119():
16
+ path = resources.files("pyRadPlan.data.phantoms")
17
+ tg119_file = path.joinpath("TG119.mat")
18
+ tg119 = matRadIO.load(tg119_file)
19
+
20
+ ct = validate_ct(tg119["ct"])
21
+ cst = validate_cst(tg119["cst"], ct=ct)
22
+ return {"ct": ct, "cst": cst}
23
+
24
+
25
+ def test_linear_index_to_world(tg119):
26
+ ct = cast(CT, tg119["ct"])
27
+ cst = cast(StructureSet, tg119["cst"])
28
+
29
+ ct_array = sitk.GetArrayViewFromImage(ct.cube_hu)
30
+
31
+ np_index = cst.vois[0].indices_numpy
32
+ sitk_index = cst.vois[0].indices
33
+ np_index_raveled = np.unravel_index(np_index, ct_array.shape)
34
+ np_index_raveled = np.array(
35
+ [np_index_raveled[0][0], np_index_raveled[1][0], np_index_raveled[2][0]]
36
+ ).astype(np.int_)
37
+
38
+ sitk_index = tuple([v.item() for v in np_index_raveled[::-1]])
39
+
40
+ sitk_point = np.array(ct.cube_hu.TransformIndexToPhysicalPoint(sitk_index))
41
+
42
+ np_coord = np2sitk.linear_indices_to_image_coordinates(
43
+ indices=np_index[0], image=ct.cube_hu, index_type="numpy"
44
+ )
45
+
46
+ assert np.isclose(sitk_point, np_coord).all()
@@ -0,0 +1,178 @@
1
+ import pytest
2
+ import numpy as np
3
+ import SimpleITK as sitk
4
+ from pyRadPlan.core.np2sitk import (
5
+ linear_indices_to_sitk_mask,
6
+ linear_indices_to_grid_coordinates,
7
+ linear_indices_to_image_coordinates,
8
+ sitk_mask_to_linear_indices,
9
+ )
10
+ from pyRadPlan.core._grids import Grid
11
+
12
+
13
+ @pytest.fixture
14
+ def ref_image() -> sitk.Image:
15
+ # Create a reference SimpleITK image
16
+ ref_image = sitk.Image(3, 4, 5, sitk.sitkUInt8)
17
+ ref_image.SetSpacing((1.0, 2.0, 3.0))
18
+ ref_image.SetOrigin((0.0, -20.0, 5.0))
19
+ ref_image.SetDirection(np.eye(3).flatten())
20
+ return ref_image
21
+
22
+
23
+ @pytest.fixture
24
+ def grid(ref_image: sitk.Image) -> Grid:
25
+ # Create a reference Grid object
26
+ return Grid.from_sitk_image(ref_image)
27
+
28
+
29
+ def test_linear_indices_to_sitk_mask_sitk_order(ref_image: sitk.Image):
30
+ # Create a reference SimpleITK image
31
+
32
+ indices = np.array([0, 4, 25])
33
+ indices_unraveled = np.unravel_index(indices, ref_image.GetSize())
34
+
35
+ # Convert linear indices to SimpleITK mask
36
+ mask = linear_indices_to_sitk_mask(indices, ref_image, order="sitk")
37
+
38
+ # Check the mask properties
39
+ mask_array = sitk.GetArrayViewFromImage(mask)
40
+ assert mask_array.shape == ref_image.GetSize()[::-1]
41
+
42
+ for i in range(len(indices)):
43
+ assert (
44
+ mask.GetPixel(
45
+ int(indices_unraveled[0][i]),
46
+ int(indices_unraveled[1][i]),
47
+ int(indices_unraveled[2][i]),
48
+ )
49
+ == 1
50
+ )
51
+
52
+ assert mask.GetPixel(1, 0, 0) == 0
53
+
54
+
55
+ def test_linear_indices_to_sitk_mask_numpy_order(ref_image: sitk.Image):
56
+ # Create a reference SimpleITK image
57
+
58
+ indices = np.array([0, 4, 25])
59
+ indices_unraveled = np.unravel_index(indices, ref_image.GetSize(), order="F")
60
+
61
+ # Convert linear indices to SimpleITK mask
62
+ mask = linear_indices_to_sitk_mask(indices, ref_image, order="numpy")
63
+
64
+ # Check the mask properties
65
+ mask_array = sitk.GetArrayViewFromImage(mask)
66
+ assert mask_array.shape == ref_image.GetSize()[::-1]
67
+
68
+ for i in range(len(indices)):
69
+ assert (
70
+ mask.GetPixel(
71
+ int(indices_unraveled[0][i]),
72
+ int(indices_unraveled[1][i]),
73
+ int(indices_unraveled[2][i]),
74
+ )
75
+ == 1
76
+ )
77
+
78
+ assert np.all(mask_array.flat[indices] == 1)
79
+
80
+
81
+ def test_linear_indices_to_sitk_mask_invalid_order(ref_image: sitk.Image):
82
+ # dummy indices
83
+ indices = np.array([0, 1])
84
+
85
+ # Check for invalid order
86
+ with pytest.raises(ValueError):
87
+ mask = linear_indices_to_sitk_mask(indices, ref_image, order="invalid")
88
+
89
+
90
+ def test_sitk_mask_to_linear_indices_sitk_order(ref_image: sitk.Image):
91
+
92
+ indices = np.array([0, 4, 25])
93
+
94
+ # Convert linear indices to SimpleITK mask
95
+ mask = linear_indices_to_sitk_mask(indices, ref_image, order="sitk")
96
+ new_indices = sitk_mask_to_linear_indices(mask, order="sitk")
97
+ assert np.all(new_indices == indices)
98
+
99
+
100
+ def test_sitk_mask_to_linear_indices_numpy_order(ref_image: sitk.Image):
101
+
102
+ indices = np.array([0, 4, 25])
103
+
104
+ # Convert linear indices to SimpleITK mask
105
+ mask = linear_indices_to_sitk_mask(indices, ref_image, order="numpy")
106
+ new_indices = sitk_mask_to_linear_indices(mask, order="numpy")
107
+ assert np.all(new_indices == indices)
108
+
109
+
110
+ def test_sitk_mask_to_linear_indices_invalid_order(ref_image: sitk.Image):
111
+ # dummy indices
112
+ indices = np.array([0, 1])
113
+
114
+ # Convert linear indices to SimpleITK mask
115
+ mask = linear_indices_to_sitk_mask(indices, ref_image, order="numpy")
116
+
117
+ # Check for invalid order
118
+ with pytest.raises(ValueError):
119
+ new_indices = sitk_mask_to_linear_indices(mask, order="invalid")
120
+
121
+
122
+ def test_linear_indices_to_grid_coordinates_numpy_order(grid: Grid, ref_image: sitk.Image):
123
+ indices = np.array([0, 4, 25])
124
+ indices_unraveled = np.unravel_index(indices, grid.dimensions, order="F")
125
+ coordinates = linear_indices_to_grid_coordinates(indices, grid, index_type="numpy")
126
+
127
+ for i in range(len(indices)):
128
+ ix_tuple = (
129
+ int(indices_unraveled[0][i]),
130
+ int(indices_unraveled[1][i]),
131
+ int(indices_unraveled[2][i]),
132
+ )
133
+ assert np.all(
134
+ np.isclose(ref_image.TransformIndexToPhysicalPoint(ix_tuple), coordinates[i, :])
135
+ )
136
+
137
+
138
+ def test_linear_indices_to_grid_coordinates_sitk_order(grid: Grid, ref_image: sitk.Image):
139
+ indices = np.array([0, 4, 25])
140
+ indices_unraveled = np.unravel_index(indices, grid.dimensions)
141
+ coordinates = linear_indices_to_grid_coordinates(indices, grid, index_type="sitk")
142
+
143
+ for i in range(len(indices)):
144
+ ix_tuple = (
145
+ int(indices_unraveled[0][i]),
146
+ int(indices_unraveled[1][i]),
147
+ int(indices_unraveled[2][i]),
148
+ )
149
+ assert np.all(
150
+ np.isclose(ref_image.TransformIndexToPhysicalPoint(ix_tuple), coordinates[i, :])
151
+ )
152
+
153
+
154
+ def test_linear_indices_to_grid_coordinates_invalid_order(grid: Grid):
155
+ indices = np.array([0, 1])
156
+
157
+ with pytest.raises(ValueError):
158
+ coordinates = linear_indices_to_grid_coordinates(indices, grid, index_type="invalid")
159
+
160
+
161
+ def test_linear_indices_to_image_coordinates(grid: Grid, ref_image: sitk.Image):
162
+ indices = np.array([0, 4, 25])
163
+ assert np.all(
164
+ np.isclose(
165
+ linear_indices_to_grid_coordinates(indices, grid),
166
+ linear_indices_to_image_coordinates(indices, ref_image),
167
+ )
168
+ )
169
+
170
+ assert np.all(
171
+ np.isclose(
172
+ linear_indices_to_grid_coordinates(indices, grid, index_type="numpy"),
173
+ linear_indices_to_image_coordinates(indices, ref_image, index_type="numpy"),
174
+ )
175
+ )
176
+
177
+ with pytest.raises(ValueError):
178
+ coordinates = linear_indices_to_image_coordinates(indices, ref_image, index_type="invalid")
@@ -0,0 +1,45 @@
1
+ import pytest
2
+ import numpy as np
3
+ import SimpleITK as sitk
4
+
5
+ # from pyRadPlan.core import Grid
6
+ from pyRadPlan.core.resample import resample_image, resample_numpy_array
7
+
8
+
9
+ @pytest.fixture
10
+ def sample_image():
11
+ """Create a sample SimpleITK image for testing."""
12
+ sample_array = np.random.rand(50, 100, 100) * 1000 # Random HU values
13
+ image = sitk.GetImageFromArray(sample_array)
14
+ image.SetOrigin((0, 0, 0))
15
+ image.SetSpacing((1, 1, 2))
16
+ image.SetDirection((1, 0, 0, 0, 1, 0, 0, 0, 1))
17
+ return image
18
+
19
+
20
+ def test_resample_image2grid_with_spacing(sample_image):
21
+ target_spacing = (3, 2, 2)
22
+ resampled_image = resample_image(sample_image, target_grid_spacing=target_spacing)
23
+ assert resampled_image.GetSpacing() == target_spacing
24
+ assert resampled_image.GetSize() == (34, 50, 50)
25
+
26
+
27
+ def test_resample_image2grid_with_target_image(sample_image):
28
+ target_image = sample_image
29
+ resampled_image = resample_image(sample_image, target_image=target_image)
30
+ assert resampled_image.GetSpacing() == target_image.GetSpacing()
31
+ assert resampled_image.GetSize() == target_image.GetSize()
32
+
33
+
34
+ def test_resample_numpy_array(sample_image):
35
+ sample_array = sitk.GetArrayFromImage(sample_image)
36
+ resampled_array = resample_numpy_array(
37
+ sample_array, sample_image, target_grid_spacing=(2, 2, 2)
38
+ )
39
+ assert resampled_array.shape == (50, 50, 50)
40
+
41
+
42
+ def test_resample_numpy_array_with_target_image(sample_image):
43
+ sample_array = sitk.GetArrayFromImage(sample_image)
44
+ resampled_array = resample_numpy_array(sample_array, sample_image, target_image=sample_image)
45
+ assert resampled_array.shape == sample_array.shape
test/cst/conftest.py ADDED
@@ -0,0 +1,57 @@
1
+ import pytest
2
+ from importlib import resources
3
+ import pymatreader
4
+ import numpy as np
5
+ import SimpleITK as sitk
6
+ from pyRadPlan.ct import create_ct
7
+
8
+
9
+ @pytest.fixture
10
+ def sample_image_3d():
11
+ """Create a sample SimpleITK image for testing."""
12
+ dims = [50, 100, 100]
13
+ sample_array = np.ones(dims) * 1000 # Random HU values
14
+ image = sitk.GetImageFromArray(sample_array)
15
+ image.SetOrigin((0, 0, 0))
16
+ image.SetSpacing((1, 1, 2))
17
+ image.SetDirection((1, 0, 0, 0, 1, 0, 0, 0, 1))
18
+ return image, dims
19
+
20
+
21
+ @pytest.fixture
22
+ def sample_image_4d(sample_image_3d):
23
+ image, dims_3d = sample_image_3d
24
+ image_4d = sitk.JoinSeries([image, image])
25
+ image_4d.SetOrigin((0, 0, 0, 0))
26
+ image_4d.SetSpacing((1, 1, 2, 1))
27
+ image_4d.SetDirection((1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1))
28
+ return image_4d, dims_3d
29
+
30
+
31
+ @pytest.fixture
32
+ def generic_input_3d(sample_image_3d):
33
+ cube_hu, dims = sample_image_3d
34
+ mask = np.zeros(dims).astype("uint8")
35
+ mask[0, 0, 1] = 1
36
+ return "VOI", create_ct(cube_hu=cube_hu), mask, 0.2, 0.3
37
+
38
+
39
+ @pytest.fixture
40
+ def generic_input_4d(sample_image_4d):
41
+ cube_hu, dims_3d = sample_image_4d
42
+ mask_1 = np.zeros(dims_3d, dtype=np.uint8)
43
+ mask_1[0, 0, 1] = 1
44
+ mask_2 = np.zeros(dims_3d, dtype=np.uint8)
45
+ mask_2[1, 1, 0] = 1
46
+ mask_np = [sitk.GetImageFromArray(mask_1, False), sitk.GetImageFromArray(mask_2, False)]
47
+ mask = sitk.JoinSeries(mask_np)
48
+ return "VOI", create_ct(cube_hu=cube_hu), mask, 0.2, 0.3
49
+
50
+
51
+ @pytest.fixture
52
+ def matrad_import():
53
+ """Load a matRad phantom for testing."""
54
+ files = resources.files("pyRadPlan.data.phantoms")
55
+ path = files.joinpath("TG119.mat")
56
+ tmp = pymatreader.read_mat(path)
57
+ return tmp