pyRadPlan 0.3.0__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyradplan-0.3.0/pyRadPlan.egg-info → pyradplan-0.3.2}/PKG-INFO +6 -3
- {pyradplan-0.3.0 → pyradplan-0.3.2}/README.md +2 -0
- pyradplan-0.3.2/examples/pencilbeam_photon_forward.py +187 -0
- pyradplan-0.3.2/examples/proton_mimicking.py +108 -0
- pyradplan-0.3.2/examples/utils_plotting.py +169 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/__init__.py +2 -1
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/_grids.py +3 -3
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/cst/_cst.py +4 -4
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/cst/_voi.py +10 -2
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dij/_dij.py +5 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base.py +2 -2
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base_pencilbeam.py +4 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_factory.py +2 -2
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_fredmc.py +55 -27
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_svdpb.py +84 -30
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/__init__.py +8 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/base/__init__.py +6 -0
- pyradplan-0.3.2/pyRadPlan/machines/base/_beam_modifier.py +393 -0
- pyradplan-0.3.2/pyRadPlan/machines/photons/_calculate_machine_scale.py +86 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/__init__.py +3 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_objective.py +66 -4
- pyradplan-0.3.2/pyRadPlan/optimization/objectives/_squared_mimicking.py +49 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_optiprob.py +30 -11
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/raytracer/_base.py +81 -29
- pyradplan-0.3.2/pyRadPlan/raytracer/_numba_perf.py +33 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/__init__.py +13 -1
- pyradplan-0.3.2/pyRadPlan/stf/_beamlet.py +403 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/_ray.py +7 -2
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/generators/__init__.py +7 -1
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_externalbeam.py +73 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_factory.py +1 -0
- pyradplan-0.3.2/pyRadPlan/stf/generators/_photons.py +258 -0
- pyradplan-0.3.2/pyRadPlan/visualization/__init__.py +9 -0
- pyradplan-0.3.2/pyRadPlan/visualization/_plot_multiple_slices.py +138 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/visualization/_plot_slice.py +84 -59
- {pyradplan-0.3.0 → pyradplan-0.3.2/pyRadPlan.egg-info}/PKG-INFO +6 -3
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan.egg-info/SOURCES.txt +10 -1
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan.egg-info/requires.txt +3 -1
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyproject.toml +8 -6
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/cst/test_VOI.py +51 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/cst/test_cst.py +26 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/dose/test_fred.py +1 -2
- pyradplan-0.3.2/test/machines/test_beam_modifiers.py +302 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/optimization/test_objectives.py +93 -46
- pyradplan-0.3.2/test/stf/test_beamlet.py +274 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_raytracersiddon.py +21 -0
- pyradplan-0.3.2/test/visualization/test_plot_multiple_slices.py +286 -0
- pyradplan-0.3.0/pyRadPlan/raytracer/_perf.py +0 -229
- pyradplan-0.3.0/pyRadPlan/stf/_beamlet.py +0 -112
- pyradplan-0.3.0/pyRadPlan/stf/generators/_photons.py +0 -141
- pyradplan-0.3.0/pyRadPlan/visualization/__init__.py +0 -5
- pyradplan-0.3.0/test/stf/test_beamlet.py +0 -53
- {pyradplan-0.3.0 → pyradplan-0.3.2}/LICENSE +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/docs/conf.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/intro_minimal_photons.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/intro_minimal_protons.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/mc_fred.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/pencilbeam_carbon.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/pencilbeam_helium.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/pencilbeam_photon.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/pencilbeam_proton.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/pencilbeam_proton_let.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/pencilbeam_vhee.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/raytracer_rad_depth.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/examples/utils_matrad.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/analysis/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/analysis/_dvh.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/_exceptions.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/datamodel.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/np2sitk.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/resample.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/compat.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/helpers.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/core/xp_utils/typing.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/cst/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/ct/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/ct/_ct.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/ct/_hlut.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/data/machines/VHEE_Focused.mat +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/data/machines/VHEE_Generic.mat +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/data/machines/carbon_Generic.mat +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/data/machines/helium_Generic.mat +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/data/machines/photons_Generic.mat +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/data/machines/protons_Generic.mat +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/data/phantoms/TG119.mat +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dij/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dij/_compose_beam_dijs.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/_calc_dose.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base_montecarlo.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_base_pencilbeam_particle.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/dose/engines/_hongpb.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/geometry/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/geometry/lps.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/io/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/io/_matlab_file_handler.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/io/_patient_loader.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/io/matfile.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/_load.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/_validate.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/base/_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/base/_external_beam.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/base/_factory.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/base/_internal_beam.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_cutoff.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_emittance.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_energy.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_beam_focus.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_ions.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/_vhee.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/_ions.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/particles/kernel/_vhee.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/photons/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/photons/_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/photons/_linac.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/machines/photons/_svd_kernel.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/matRad/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/matRad/_engine.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/matRad/_matlab.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/matRad/_octave.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/_fluence_optimization.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_eud.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_factory.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_max_dvh.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_mean.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_min_dvh.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_squared_dev.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_squared_over.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_squared_under.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/objectives/_std.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_factory.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_nonlin_fluence.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/problems/_simple_least_squares.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_base_solvers.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_factory.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_ipopt.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/optimization/solvers/_scipy_solver.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/plan/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/plan/_plans.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/quantities/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/quantities/_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/quantities/_dose.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/quantities/_let_x_dose.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/raytracer/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/raytracer/_siddon.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/scenarios/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/scenarios/_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/scenarios/_nominal.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/_beam.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/_exceptions.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/_generate_stf.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/_rangeshifter.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/_steeringinformation.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_ions.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/stf/generators/_vhee.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/util/__init__.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/util/helpers.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan/util/keyboard_listener.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan.egg-info/dependency_links.txt +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/pyRadPlan.egg-info/top_level.txt +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/setup.cfg +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/analysis/test_dvh.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/analysis/test_qi.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/compute/test_math_interp1d.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/compute/test_math_quantile.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/compute/test_namespace_conversion.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/conftest.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/core/test_coordinates.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/core/test_datamodel.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/core/test_np2sitk.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/core/test_resample.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/cst/conftest.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/ct/test_ct.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/ct/test_hlut.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/data/test_validate_test_data.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/dose/conftest.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/dose/test_dose_engine_base.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/dose/test_factory.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/dose/test_hongpb.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/dose/test_pb_geodist.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/dose/test_svdpb.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/geometry/test_lps.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/optimization/test_fluence_optiprob.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/optimization/test_ipopt_solver.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/optimization/test_problem_factory.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/optimization/test_scipy_solver.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/optimization/test_solver_factory.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/quantities/test_dose_quantity.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/quantities/test_let_dose_quantity.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/stf/test_stf.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/stf/test_stf_gen.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_dij.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_fileHandling.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_grid.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_helpers.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_machine_model.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_matlabEngine.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_octaveEngine.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_plan.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/test_scenarios.py +0 -0
- {pyradplan-0.3.0 → pyradplan-0.3.2}/test/visualization/test_plot_slice.py +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyRadPlan
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: A python interface and reimplementation to matRad
|
|
5
|
-
Author-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>,
|
|
5
|
+
Author-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>, Tobias Becher <t.becher@dkfz-heidelberg.de>, Lina Bucher <lina.bucher@dkfz-heidelberg.de>, Antonios Kontopoulos <antonios.kontopoulos@dkfz-heidelberg.de>, Julius Laub <julius.laub@dkfz-heidelberg.de>, Florian Leininger <florian.leininger@dkfz-heidelberg.de>, Tim Ortkamp <tim.ortkamp@kit.edu>, Victoria Santiago Aguilar <victoria.santiagoaguilar@dkfz-heidelberg.de>, Goran Stanic <goran.stanic@dkfz-heidelberg.de>, Samir Schulz <samirshivaji.schulz@dkfz-heidelberg.de>
|
|
6
6
|
Maintainer-email: Niklas Wahl <n.wahl@dkfz-heidelberg.de>, Florian Leininger <florian.leininger@dkfz-heidelberg.de>, Tobias Becher <t.becher@dkfz-heidelberg.de>, Tim Ortkamp <tim.ortkamp@kit.edu>
|
|
7
7
|
Project-URL: Homepage, https://git.dkfz.de
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -21,7 +21,6 @@ Requires-Dist: pymatreader>=1.0.0
|
|
|
21
21
|
Requires-Dist: h5py>=3.11.0
|
|
22
22
|
Requires-Dist: regex>=2024.5.15
|
|
23
23
|
Requires-Dist: pydicom>=2.4.4
|
|
24
|
-
Requires-Dist: numba>=0.61.0
|
|
25
24
|
Requires-Dist: matplotlib>=3.9.2
|
|
26
25
|
Requires-Dist: pydantic<2.13,>=2.10
|
|
27
26
|
Requires-Dist: numpydantic>=1.6.9
|
|
@@ -34,6 +33,8 @@ Provides-Extra: octave
|
|
|
34
33
|
Requires-Dist: oct2py; extra == "octave"
|
|
35
34
|
Provides-Extra: gui
|
|
36
35
|
Requires-Dist: PyQt5; extra == "gui"
|
|
36
|
+
Provides-Extra: numba
|
|
37
|
+
Requires-Dist: numba>=0.61.0; extra == "numba"
|
|
37
38
|
Provides-Extra: dev
|
|
38
39
|
Requires-Dist: pytest; extra == "dev"
|
|
39
40
|
Requires-Dist: coverage; extra == "dev"
|
|
@@ -65,6 +66,8 @@ Development is lead by the [Radiotherapy Optimization group](https://www.dkfz.de
|
|
|
65
66
|
## Concept and Goals
|
|
66
67
|
pyRadPlan is a multi-modality treatment planning toolkit in python born from the established Matlab-based toolkit [matRad](http://www.matRad.org). As such, pyRadPlan aims to provide a framework as well as tools for combining dose calculation with optimization with focus on ion planning.
|
|
67
68
|
|
|
69
|
+
One of pyRadPlan's main goals is for its algorithms to be [Python Array API](https://data-apis.org/array-api/) conform as much as possible, to allow free choice of compute backends and devices (i.e., [`numpy`](https://numpy.org/), [`cupy`](https://cupy.dev/), [`pytorch`](https://pytorch.org/)). Further, its data structures (more precisely, their metadata) should be easily serializable for exchange with novel LLMs. This facilitate performant treatment planning research while enabling the integration of AI - such as deep neural networks implemented in [`pytorch`](https://pytorch.org/) or interaction with an LLM Agent via [`pydantic-ai`](https://ai.pydantic.dev/) - at every step of the treatment planning workflow.
|
|
70
|
+
|
|
68
71
|
### Data Structures
|
|
69
72
|
pyRadPlan uses a similar datastructure and workflow concept as in matRad, while trying to ensure that the corresponding datastructures can be easily imported and exported from/to matRad. This facilitates the application of either algortihms from matRad or native pyRadPlan at any stage of the treatment planning workflow.
|
|
70
73
|
|
|
@@ -16,6 +16,8 @@ Development is lead by the [Radiotherapy Optimization group](https://www.dkfz.de
|
|
|
16
16
|
## Concept and Goals
|
|
17
17
|
pyRadPlan is a multi-modality treatment planning toolkit in python born from the established Matlab-based toolkit [matRad](http://www.matRad.org). As such, pyRadPlan aims to provide a framework as well as tools for combining dose calculation with optimization with focus on ion planning.
|
|
18
18
|
|
|
19
|
+
One of pyRadPlan's main goals is for its algorithms to be [Python Array API](https://data-apis.org/array-api/) conform as much as possible, to allow free choice of compute backends and devices (i.e., [`numpy`](https://numpy.org/), [`cupy`](https://cupy.dev/), [`pytorch`](https://pytorch.org/)). Further, its data structures (more precisely, their metadata) should be easily serializable for exchange with novel LLMs. This facilitate performant treatment planning research while enabling the integration of AI - such as deep neural networks implemented in [`pytorch`](https://pytorch.org/) or interaction with an LLM Agent via [`pydantic-ai`](https://ai.pydantic.dev/) - at every step of the treatment planning workflow.
|
|
20
|
+
|
|
19
21
|
### Data Structures
|
|
20
22
|
pyRadPlan uses a similar datastructure and workflow concept as in matRad, while trying to ensure that the corresponding datastructures can be easily imported and exported from/to matRad. This facilitates the application of either algortihms from matRad or native pyRadPlan at any stage of the treatment planning workflow.
|
|
21
23
|
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
# %% [markdown]
|
|
2
|
+
"""# Example for photon dose calculation using pencilbeam engine."""
|
|
3
|
+
# %% [markdown]
|
|
4
|
+
# This example demonstrates how to use the pyRadPlan library to perform photon dose calculations.
|
|
5
|
+
|
|
6
|
+
# To display this script in a Jupyter Notebook, you need to install jupytext via pip and run the following command.
|
|
7
|
+
# This will create a .ipynb file in the same directory:
|
|
8
|
+
|
|
9
|
+
# ```bash
|
|
10
|
+
# pip install jupytext
|
|
11
|
+
# jupytext --to notebook path/to/this/file/pencilbeam_photon_forward.py
|
|
12
|
+
|
|
13
|
+
# %%
|
|
14
|
+
# Import necessary libraries
|
|
15
|
+
import logging
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
|
|
19
|
+
import matplotlib.pyplot as plt
|
|
20
|
+
|
|
21
|
+
from pyRadPlan import (
|
|
22
|
+
PhotonPlan,
|
|
23
|
+
generate_stf,
|
|
24
|
+
calc_dose_forward,
|
|
25
|
+
plot_slice,
|
|
26
|
+
load_tg119,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
from pyRadPlan.machines import create_bld
|
|
30
|
+
from pyRadPlan.stf import FieldShapeAsBLD, FieldShapeComposite
|
|
31
|
+
|
|
32
|
+
from pyRadPlan.machines.photons._calculate_machine_scale import calculate_machine_scale
|
|
33
|
+
|
|
34
|
+
logging.basicConfig(level=logging.INFO)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
resolution = 1.0
|
|
38
|
+
|
|
39
|
+
leaf_width = 5
|
|
40
|
+
positions = [ # L-form for testing direction
|
|
41
|
+
[0, 0],
|
|
42
|
+
[-20, 20],
|
|
43
|
+
[-20, 10],
|
|
44
|
+
[-20, 0],
|
|
45
|
+
[-20, 0],
|
|
46
|
+
[-20, 0],
|
|
47
|
+
[-20, 0],
|
|
48
|
+
[-20, 0],
|
|
49
|
+
[-20, 0],
|
|
50
|
+
[0, 0],
|
|
51
|
+
]
|
|
52
|
+
number_of_elements = len(positions)
|
|
53
|
+
boundaries = np.arange(
|
|
54
|
+
-int(number_of_elements / 2) * leaf_width, int(number_of_elements / 2) * leaf_width, leaf_width
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
mlc_information = {
|
|
58
|
+
"device_type": "MLC",
|
|
59
|
+
"device_orientation": "X",
|
|
60
|
+
"leaf_position_boundaries": boundaries,
|
|
61
|
+
"leaf_positions": positions,
|
|
62
|
+
"leaf_width": leaf_width,
|
|
63
|
+
"leaf_leakage": 0.1,
|
|
64
|
+
}
|
|
65
|
+
mlc_x = create_bld(mlc_information)
|
|
66
|
+
mask_mlc_x = mlc_x.calculate_transmission_mask(resolution)
|
|
67
|
+
|
|
68
|
+
jaw_info = {
|
|
69
|
+
"device_type": "JAW",
|
|
70
|
+
"device_orientation": "X",
|
|
71
|
+
"positions": [-20, 10],
|
|
72
|
+
"field_width": 70,
|
|
73
|
+
"leakage": 0.1,
|
|
74
|
+
}
|
|
75
|
+
jaw_x = create_bld(jaw_info)
|
|
76
|
+
jaw_info["field_width"] = mask_mlc_x.shape[0] * resolution
|
|
77
|
+
jaw_x_matching_field_width = create_bld(jaw_info)
|
|
78
|
+
mask_jaw_x = jaw_x_matching_field_width.calculate_transmission_mask(resolution)
|
|
79
|
+
|
|
80
|
+
mask = mask_mlc_x * mask_jaw_x
|
|
81
|
+
|
|
82
|
+
half_size = jaw_info["field_width"]
|
|
83
|
+
extent = [-half_size, half_size, -half_size, half_size]
|
|
84
|
+
|
|
85
|
+
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
|
|
86
|
+
|
|
87
|
+
axes[0].imshow(mask_jaw_x, cmap="gray", origin="lower", extent=extent)
|
|
88
|
+
axes[0].set_title("Jaw Mask (IEC DICOM)")
|
|
89
|
+
axes[0].set_xlabel("X (mm)")
|
|
90
|
+
axes[0].set_ylabel("Y (mm)")
|
|
91
|
+
|
|
92
|
+
axes[1].imshow(mask_mlc_x, cmap="gray", origin="lower", extent=extent)
|
|
93
|
+
axes[1].set_title("MLC Mask (IEC DICOM)")
|
|
94
|
+
axes[1].set_xlabel("X (mm)")
|
|
95
|
+
axes[1].set_ylabel("Y (mm)")
|
|
96
|
+
|
|
97
|
+
axes[2].imshow(mask, cmap="gray", origin="lower", extent=extent)
|
|
98
|
+
axes[2].set_title("Combined Mask (IEC DICOM)")
|
|
99
|
+
axes[2].set_xlabel("X (mm)")
|
|
100
|
+
axes[2].set_ylabel("Y (mm)")
|
|
101
|
+
|
|
102
|
+
plt.tight_layout()
|
|
103
|
+
plt.show()
|
|
104
|
+
|
|
105
|
+
# %%
|
|
106
|
+
# pyRadPlan internally defines "field shapes" to represent the shape of the beamlets.
|
|
107
|
+
mlc_shape = FieldShapeAsBLD(energy=6.0, bld=mlc_x, resolution=resolution)
|
|
108
|
+
jaw_shape = FieldShapeAsBLD(energy=6.0, bld=jaw_x_matching_field_width, resolution=resolution)
|
|
109
|
+
combined_shape = FieldShapeComposite(energy=6.0, shapes=[mlc_shape, jaw_shape])
|
|
110
|
+
|
|
111
|
+
# Now plot the field shapes to verify their geometry in LPS BEV coordinates
|
|
112
|
+
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
|
|
113
|
+
axes[0].imshow(jaw_shape.mask, cmap="gray", origin="lower", extent=extent)
|
|
114
|
+
axes[0].set_title("Jaw Field Shape (LPS BEV)")
|
|
115
|
+
axes[0].set_xlabel("X (mm)")
|
|
116
|
+
axes[0].set_ylabel("Y (mm)")
|
|
117
|
+
|
|
118
|
+
axes[1].imshow(mlc_shape.mask, cmap="gray", origin="lower", extent=extent)
|
|
119
|
+
axes[1].set_title("MLC Field Shape (LPS BEV)")
|
|
120
|
+
axes[1].set_xlabel("X (mm)")
|
|
121
|
+
axes[1].set_ylabel("Y (mm)")
|
|
122
|
+
|
|
123
|
+
axes[2].imshow(combined_shape.mask, cmap="gray", origin="lower", extent=extent)
|
|
124
|
+
axes[2].set_title("Combined Field Shape (LPS BEV)")
|
|
125
|
+
axes[2].set_xlabel("X (mm)")
|
|
126
|
+
axes[2].set_ylabel("Y (mm)")
|
|
127
|
+
|
|
128
|
+
plt.tight_layout()
|
|
129
|
+
plt.show()
|
|
130
|
+
|
|
131
|
+
# %%
|
|
132
|
+
# Load TG119 (provided within pyRadPlan)
|
|
133
|
+
ct, cst = load_tg119()
|
|
134
|
+
|
|
135
|
+
# %% [markdown]
|
|
136
|
+
# In this section, we create a photon therapy plan using the ParticleHongPencilBeamEngine.
|
|
137
|
+
# %%
|
|
138
|
+
# Create a plan object
|
|
139
|
+
pln = PhotonPlan(machine="Generic")
|
|
140
|
+
num_of_beams = 1
|
|
141
|
+
pln.prop_stf = {
|
|
142
|
+
"gantry_angles": np.linspace(0, 360, num_of_beams, endpoint=False),
|
|
143
|
+
"couch_angles": np.zeros((num_of_beams,)), # np.array([0, 270]),
|
|
144
|
+
"generator": "photonSingleBixel",
|
|
145
|
+
"field_based": True,
|
|
146
|
+
# "field_shape": np.rot90(mask, k=-1), #TODO: Rotation correct? Should automatically be done in ShapeFromBLD?
|
|
147
|
+
"blds": [mlc_x, jaw_x],
|
|
148
|
+
"resolution": 0.5,
|
|
149
|
+
"energy": 6,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
# Generate Steering Geometry ("stf")
|
|
153
|
+
stf = generate_stf(ct, cst, pln)
|
|
154
|
+
|
|
155
|
+
# Machine Calibration: Calculate the conversion factor between MU and weights
|
|
156
|
+
machine = "Generic"
|
|
157
|
+
ct_dim = [64, 64, 64]
|
|
158
|
+
ct_resolution = [2.0, 2.0, 2.0]
|
|
159
|
+
num_of_ct_scen = 1
|
|
160
|
+
|
|
161
|
+
weights = calculate_machine_scale(machine, ct_dim, ct_resolution, num_of_ct_scen)
|
|
162
|
+
|
|
163
|
+
# Apply weights to the rays in the stf
|
|
164
|
+
for beam in stf.beams:
|
|
165
|
+
for ray in beam.rays:
|
|
166
|
+
for beamlet in ray.beamlets:
|
|
167
|
+
beamlet.weight *= weights
|
|
168
|
+
|
|
169
|
+
# Calculate Dose Influence Matrix ("dij")
|
|
170
|
+
dij = calc_dose_forward(ct, cst, stf, pln)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# %% [markdown]
|
|
174
|
+
# Visualize the results
|
|
175
|
+
# %%
|
|
176
|
+
# Choose a slice to visualize
|
|
177
|
+
view_slice = int(np.round(ct.size[1] / 2))
|
|
178
|
+
|
|
179
|
+
# Visualize
|
|
180
|
+
plot_slice(
|
|
181
|
+
ct=ct,
|
|
182
|
+
cst=cst,
|
|
183
|
+
overlay=dij["physical_dose"],
|
|
184
|
+
view_slice=view_slice,
|
|
185
|
+
plane="coronal",
|
|
186
|
+
overlay_unit="Gy",
|
|
187
|
+
)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# %% [markdown]
|
|
2
|
+
"""# Example for proton dose mimicking of an existing dose distribution."""
|
|
3
|
+
# %% [markdown]
|
|
4
|
+
# This example demonstrates how to use the perform dose mimicking on an existing dose distribution.
|
|
5
|
+
|
|
6
|
+
# To display this script in a Jupyter Notebook, you need to install jupytext via pip and run the following command.
|
|
7
|
+
# This will create a .ipynb file in the same directory:
|
|
8
|
+
|
|
9
|
+
# ```bash
|
|
10
|
+
# pip install jupytext
|
|
11
|
+
# jupytext --to notebook path/to/this/file/pencilbeam_proton.py
|
|
12
|
+
|
|
13
|
+
# %%
|
|
14
|
+
# Import necessary libraries
|
|
15
|
+
import logging
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
import SimpleITK as sitk
|
|
19
|
+
|
|
20
|
+
from pyRadPlan import (
|
|
21
|
+
IonPlan,
|
|
22
|
+
generate_stf,
|
|
23
|
+
calc_dose_influence,
|
|
24
|
+
fluence_optimization,
|
|
25
|
+
plot_slice,
|
|
26
|
+
load_tg119,
|
|
27
|
+
xp_utils,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
from pyRadPlan.optimization.objectives import (
|
|
31
|
+
SquaredDeviation,
|
|
32
|
+
SquaredOverdosing,
|
|
33
|
+
MeanDose,
|
|
34
|
+
SquaredMimicking,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
xp_utils.PREFER_GPU = False
|
|
39
|
+
xp_utils.PREFERRED_CPU_ARRAY_BACKEND = "numpy"
|
|
40
|
+
logging.basicConfig(level=logging.INFO)
|
|
41
|
+
|
|
42
|
+
# %%
|
|
43
|
+
# Load TG119 (provided within pyRadPlan)
|
|
44
|
+
ct, cst = load_tg119()
|
|
45
|
+
|
|
46
|
+
# %% [markdown]
|
|
47
|
+
# In this section, we create a proton therapy plan using the ParticleHongPencilBeamEngine.
|
|
48
|
+
# %%
|
|
49
|
+
# Create a plan object
|
|
50
|
+
pln = IonPlan(radiation_mode="protons", machine="Generic")
|
|
51
|
+
pln.prop_opt = {"solver": "scipy"}
|
|
52
|
+
pln.prop_dose_calc = {"dose_grid": ct.grid}
|
|
53
|
+
|
|
54
|
+
# Generate Steering Geometry ("stf")
|
|
55
|
+
stf = generate_stf(ct, cst, pln)
|
|
56
|
+
|
|
57
|
+
# Calculate Dose Influence Matrix ("dij")
|
|
58
|
+
dij = calc_dose_influence(ct, cst, stf, pln)
|
|
59
|
+
|
|
60
|
+
# %%
|
|
61
|
+
# Optimize a standard plan
|
|
62
|
+
# Optimization
|
|
63
|
+
cst.vois[0].objectives = [SquaredOverdosing(priority=10.0, d_max=1.0)] # OAR
|
|
64
|
+
cst.vois[1].objectives = [SquaredDeviation(priority=100.0, d_ref=3.0)] # Target
|
|
65
|
+
cst.vois[2].objectives = [
|
|
66
|
+
MeanDose(priority=1.0, d_ref=0.0),
|
|
67
|
+
SquaredOverdosing(priority=10.0, d_max=2.0),
|
|
68
|
+
] # BODY
|
|
69
|
+
|
|
70
|
+
# Calculate optimized fluence
|
|
71
|
+
fluence = fluence_optimization(ct, cst, stf, dij, pln)
|
|
72
|
+
|
|
73
|
+
# Compute the result on the CT grid
|
|
74
|
+
result = dij.compute_result_ct_grid(fluence)
|
|
75
|
+
|
|
76
|
+
# %%
|
|
77
|
+
# Now let's mimick a reference dose distribution from the reference plan with noise
|
|
78
|
+
noise_stdev = 0.02
|
|
79
|
+
reference_dose = sitk.SpeckleNoise(result["physical_dose"], noise_stdev)
|
|
80
|
+
|
|
81
|
+
# Let's mimick the noisy dose distribution by using the SquaredMimicking objective.
|
|
82
|
+
cst.vois[1].objectives = [] # Target
|
|
83
|
+
cst.vois[0].objectives = [] # OAR
|
|
84
|
+
cst.vois[2].objectives = [SquaredMimicking(priority=1000.0, d_ref=reference_dose)] # BODY
|
|
85
|
+
|
|
86
|
+
# Calculate optimized fluence
|
|
87
|
+
fluence_mimicked = fluence_optimization(ct, cst, stf, dij, pln)
|
|
88
|
+
|
|
89
|
+
# Compute the result on the CT grid
|
|
90
|
+
result_mimicked = dij.compute_result_ct_grid(fluence_mimicked)
|
|
91
|
+
|
|
92
|
+
# %% [markdown]
|
|
93
|
+
# Visualize the results
|
|
94
|
+
# %%
|
|
95
|
+
# Choose a slice to visualize
|
|
96
|
+
view_slice = int(np.round(ct.size[2] / 2))
|
|
97
|
+
|
|
98
|
+
# Visualize
|
|
99
|
+
plot_slice(
|
|
100
|
+
ct=ct,
|
|
101
|
+
cst=cst,
|
|
102
|
+
overlay=result_mimicked["physical_dose"],
|
|
103
|
+
view_slice=view_slice,
|
|
104
|
+
plane="axial",
|
|
105
|
+
overlay_unit="Gy",
|
|
106
|
+
)
|
|
107
|
+
|
|
108
|
+
# %%
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# %% [markdown]
|
|
2
|
+
"""# Multiple examples on how to use the visualization tools provided by pyRadPlan."""
|
|
3
|
+
# %% [markdown]
|
|
4
|
+
# This example demonstrates the usage of `plot_slice()`, `plot_distributions()` and `plot_3d()`.
|
|
5
|
+
|
|
6
|
+
# To display this script in a Jupyter Notebook, you need to install jupytext via pip and run the following command.
|
|
7
|
+
# This will create a .ipynb file in the same directory:
|
|
8
|
+
|
|
9
|
+
# ```bash
|
|
10
|
+
# pip install jupytext
|
|
11
|
+
# jupytext --to notebook path/to/this/file/utils_plotting.py
|
|
12
|
+
|
|
13
|
+
# %%
|
|
14
|
+
# Import necessary libraries
|
|
15
|
+
import logging
|
|
16
|
+
|
|
17
|
+
import matplotlib.pyplot as plt
|
|
18
|
+
|
|
19
|
+
from pyRadPlan import (
|
|
20
|
+
IonPlan,
|
|
21
|
+
generate_stf,
|
|
22
|
+
calc_dose_influence,
|
|
23
|
+
fluence_optimization,
|
|
24
|
+
plot_slice,
|
|
25
|
+
plot_multiple_slices,
|
|
26
|
+
load_tg119,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
logging.basicConfig(level=logging.INFO)
|
|
30
|
+
|
|
31
|
+
# %% [markdown]
|
|
32
|
+
# ### Just like in other examples, we need to generate some distributions/quantities to visualize.
|
|
33
|
+
# %%
|
|
34
|
+
# load TG119
|
|
35
|
+
ct, cst = load_tg119()
|
|
36
|
+
|
|
37
|
+
# Create a plan object
|
|
38
|
+
pln = IonPlan(radiation_mode="carbon", machine="Generic")
|
|
39
|
+
pln.prop_opt = {"solver": "scipy"}
|
|
40
|
+
# Lets calc the biological dose too
|
|
41
|
+
pln.prop_dose_calc = {"calc_bio_dose": True}
|
|
42
|
+
|
|
43
|
+
# Generate Steering Geometry ("stf")
|
|
44
|
+
stf = generate_stf(ct, cst, pln)
|
|
45
|
+
|
|
46
|
+
# Calculate Dose Influence Matrix ("dij")
|
|
47
|
+
dij = calc_dose_influence(ct, cst, stf, pln)
|
|
48
|
+
|
|
49
|
+
# Run fluence optimization and compute the result
|
|
50
|
+
fluence = fluence_optimization(ct, cst, stf, dij, pln)
|
|
51
|
+
result = dij.compute_result_ct_grid(fluence)
|
|
52
|
+
|
|
53
|
+
# %% [markdown]
|
|
54
|
+
# ### Visualizing a single slice with `plot_slice()`
|
|
55
|
+
# %%
|
|
56
|
+
|
|
57
|
+
# Visualize only ct and choosen quantity
|
|
58
|
+
plot_slice(ct=ct, overlay=result["physical_dose"])
|
|
59
|
+
|
|
60
|
+
# Visualize ct, cst and choosen quantity
|
|
61
|
+
plot_slice(ct=ct, cst=cst, overlay=result["physical_dose"])
|
|
62
|
+
|
|
63
|
+
# %% [markdown]
|
|
64
|
+
# ## Visualze more abstract settings using `plot_slice()` <br>
|
|
65
|
+
|
|
66
|
+
# `plot_slice()` has multiple tweakable parameters:
|
|
67
|
+
# - **ct**: The CT data to visualize
|
|
68
|
+
# - **cst**: The structure set to visualize (optional)
|
|
69
|
+
# - **overlay**: The quantity to visualize
|
|
70
|
+
# - **view_slice**: Which slice to visualize (default: middle slice)
|
|
71
|
+
# - **plane**: Which plane to visualize (default: "axial")
|
|
72
|
+
# - **overlay_alpha**: Transparency of the overlay (default: 0.5)
|
|
73
|
+
# - **overlay_rel_threshold**: Relative threshold for the overlay (default: 0.01)
|
|
74
|
+
# - **overlay_unit**: The unit of the overlay quantity (default: "Gy")
|
|
75
|
+
# - **save_filename**: If provided, saves the plot to a file
|
|
76
|
+
# - **show_plot**: Whether to show the plot (default: True)
|
|
77
|
+
# - **use_global_max**: If True, uses the global maximum of the overlay for scaling (default: False)
|
|
78
|
+
# - **ax**: If provided, plots on the given axes (useful for subplots) - use of 'plot_distributions()' is recommended
|
|
79
|
+
# %%
|
|
80
|
+
# Feel free to change the parameters to see how they affect the plot.
|
|
81
|
+
plot_slice(
|
|
82
|
+
ct=ct,
|
|
83
|
+
cst=cst,
|
|
84
|
+
overlay=result["physical_dose"],
|
|
85
|
+
view_slice=64, # Visualize slice 10
|
|
86
|
+
plane="coronal", # axial, coronal or sagittal
|
|
87
|
+
overlay_alpha=0.5, # Transparency of the overlay
|
|
88
|
+
overlay_unit="Gy", # Gy, dimensionless, etc.
|
|
89
|
+
overlay_rel_threshold=0.01, # Relative threshold for the overlay
|
|
90
|
+
contour_line_width=1.0, # Width of the contour lines
|
|
91
|
+
save_filename=None, # alt: path/to/save/plot.png
|
|
92
|
+
show_plot=True, # Show the plot
|
|
93
|
+
use_global_max=False, # Do not use global max for scaling
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# %% [markdown]
|
|
97
|
+
# ### Visualizing multiple overlays/quantites with `plot_distributions()`
|
|
98
|
+
# This function might be useful in cases you want to compare multiple overlays/quantities/beams side by side.
|
|
99
|
+
|
|
100
|
+
# `plot_distributions()` has similar parameters to `plot_slice()`:
|
|
101
|
+
# - **ct**: The CT data to visualize
|
|
102
|
+
# - **cst**: The structure set to visualize (optional)
|
|
103
|
+
# - **overlays**: List of overlay images to visualize
|
|
104
|
+
# - **view_slice**: Which slices to visualize (default: middle slice)
|
|
105
|
+
# - **plane**: Which plane to visualize (default: "axial")
|
|
106
|
+
# - **overlay_alpha**: Transparency of the overlay (default: 0.5)
|
|
107
|
+
# - **overlay_unit**: List of units for each overlay (default: "Gy")
|
|
108
|
+
# - **overlay_rel_threshold**: Relative threshold for the overlay (default: 0.01)
|
|
109
|
+
# - **contour_line_width**: Line width for the contour lines (default: 1.0)
|
|
110
|
+
# - **save_filename**: If provided, saves the plot to a file
|
|
111
|
+
# - **show_plot**: Whether to show the plot (default: True)
|
|
112
|
+
# - **use_global_max**: If True, uses the global maximum of the overlay for scaling
|
|
113
|
+
# - **overlay_titles**: Custom titles for each overlay type (optional)
|
|
114
|
+
# %%
|
|
115
|
+
# Feel free to change the parameters to see how they affect the plot.
|
|
116
|
+
plot_multiple_slices(
|
|
117
|
+
ct=ct,
|
|
118
|
+
cst=cst,
|
|
119
|
+
overlays=[result["physical_dose"], result["effect"]],
|
|
120
|
+
view_slice=[64, 65], # Visualize slices 64 and 65
|
|
121
|
+
plane="axial", # axial, coronal or sagittal
|
|
122
|
+
overlay_alpha=0.5, # Transparency of the overlay
|
|
123
|
+
overlay_unit=["Gy", "dimensionless"], # Units for each overlay
|
|
124
|
+
overlay_rel_threshold=0.01, # Relative threshold for the overlay
|
|
125
|
+
contour_line_width=1.0, # Width of the contour lines
|
|
126
|
+
save_filename=None, # alt: path/to/save/plot.png
|
|
127
|
+
show_plot=True, # Show the plot
|
|
128
|
+
use_global_max=False, # Do not use global max for scaling
|
|
129
|
+
overlay_titles=["Physical Dose", "Biological Effect"], # Titles for each overlay
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
# %% [markdown]
|
|
133
|
+
# ### Being more flexible with only `plot_slice()` is also possible:
|
|
134
|
+
# %%
|
|
135
|
+
# Create a figure with subplots for side-by-side comparison
|
|
136
|
+
# 2 rows (physical dose, biological effect) x 2 cols (slice1, slice2)
|
|
137
|
+
slices = [64, 65] # Slices to visualize
|
|
138
|
+
fig, axes = plt.subplots(2, 2, figsize=(12, 10))
|
|
139
|
+
|
|
140
|
+
# Plot physical dose for both slices
|
|
141
|
+
for i, slice_idx in enumerate(slices):
|
|
142
|
+
plot_slice(
|
|
143
|
+
ct=ct,
|
|
144
|
+
cst=cst,
|
|
145
|
+
overlay=result["physical_dose"],
|
|
146
|
+
view_slice=slice_idx, # Single slice
|
|
147
|
+
plane="axial",
|
|
148
|
+
overlay_unit="Gy",
|
|
149
|
+
show_plot=False,
|
|
150
|
+
ax=axes[0, i], # Top row
|
|
151
|
+
)
|
|
152
|
+
axes[0, i].set_title(f"Physical Dose - Slice {slice_idx}")
|
|
153
|
+
|
|
154
|
+
# Plot biological effect for both slices
|
|
155
|
+
for i, slice_idx in enumerate(slices):
|
|
156
|
+
plot_slice(
|
|
157
|
+
ct=ct,
|
|
158
|
+
cst=cst,
|
|
159
|
+
overlay=result["effect"],
|
|
160
|
+
view_slice=slice_idx, # Single slice
|
|
161
|
+
plane="axial",
|
|
162
|
+
overlay_unit="dimensionless",
|
|
163
|
+
show_plot=False,
|
|
164
|
+
ax=axes[1, i], # Bottom row
|
|
165
|
+
)
|
|
166
|
+
axes[1, i].set_title(f"Biological Effect - Slice {slice_idx}")
|
|
167
|
+
|
|
168
|
+
plt.tight_layout()
|
|
169
|
+
plt.show()
|
|
@@ -35,7 +35,7 @@ from .stf import SteeringInformation, validate_stf
|
|
|
35
35
|
from .dose._calc_dose import calc_dose_influence, calc_dose_forward
|
|
36
36
|
from .optimization._fluence_optimization import fluence_optimization
|
|
37
37
|
from .analysis._dvh import DVH, DVHCollection
|
|
38
|
-
from .visualization import plot_slice
|
|
38
|
+
from .visualization import plot_slice, plot_multiple_slices
|
|
39
39
|
from .io import load_patient, load_tg119
|
|
40
40
|
from .core import xp_utils
|
|
41
41
|
|
|
@@ -68,6 +68,7 @@ __all__ = [
|
|
|
68
68
|
"SteeringInformation",
|
|
69
69
|
"validate_stf",
|
|
70
70
|
"plot_slice",
|
|
71
|
+
"plot_multiple_slices",
|
|
71
72
|
"load_patient",
|
|
72
73
|
"load_tg119",
|
|
73
74
|
]
|
|
@@ -43,21 +43,21 @@ class Grid(PyRadPlanBaseModel):
|
|
|
43
43
|
|
|
44
44
|
@computed_field
|
|
45
45
|
@property
|
|
46
|
-
def x(self) ->
|
|
46
|
+
def x(self) -> NDArray:
|
|
47
47
|
"""Return the x coordinates in the LPS world system."""
|
|
48
48
|
x = np.arange(self.dimensions[0]) * self.resolution["x"] + self.origin[0]
|
|
49
49
|
return x
|
|
50
50
|
|
|
51
51
|
@computed_field
|
|
52
52
|
@property
|
|
53
|
-
def y(self) ->
|
|
53
|
+
def y(self) -> NDArray:
|
|
54
54
|
"""Return the y coordinates in the LPS world system."""
|
|
55
55
|
y = np.arange(self.dimensions[1]) * self.resolution["y"] + self.origin[1]
|
|
56
56
|
return y
|
|
57
57
|
|
|
58
58
|
@computed_field
|
|
59
59
|
@property
|
|
60
|
-
def z(self) ->
|
|
60
|
+
def z(self) -> NDArray:
|
|
61
61
|
"""Return the z coordinates in the LPS world system."""
|
|
62
62
|
z = np.arange(self.dimensions[2]) * self.resolution["z"] + self.origin[2]
|
|
63
63
|
return z
|
|
@@ -38,15 +38,15 @@ class StructureSet(PyRadPlanBaseModel):
|
|
|
38
38
|
arr = vdata_item[3]
|
|
39
39
|
# return only one scenario (3D) else: Multi-Scenario (4D)
|
|
40
40
|
return (
|
|
41
|
-
[np.asarray(arr
|
|
41
|
+
[np.asarray(arr, dtype=int).ravel()]
|
|
42
42
|
if not isinstance(arr, list)
|
|
43
|
-
else [
|
|
43
|
+
else [np.asarray(a, dtype=int).ravel() for a in arr]
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
def create_mask(idx):
|
|
47
47
|
# Create the ITK mask for a given index list.
|
|
48
48
|
tmp_mask = np.zeros((ct.size[2], ct.size[0], ct.size[1]), dtype=np.uint8)
|
|
49
|
-
tmp_mask.flat[
|
|
49
|
+
tmp_mask.flat[idx - 1] = 1
|
|
50
50
|
tmp_mask = np.swapaxes(tmp_mask, 1, 2)
|
|
51
51
|
mask_image = sitk.GetImageFromArray(tmp_mask)
|
|
52
52
|
mask_image.CopyInformation(ct.cube_hu)
|
|
@@ -349,7 +349,7 @@ class StructureSet(PyRadPlanBaseModel):
|
|
|
349
349
|
stats.Execute(labeled)
|
|
350
350
|
|
|
351
351
|
# Step 3: Identify label with largest number of pixels
|
|
352
|
-
largest_label = max(stats.GetLabels(), key=
|
|
352
|
+
largest_label = max(stats.GetLabels(), key=stats.GetNumberOfPixels)
|
|
353
353
|
|
|
354
354
|
# Step 4: Create binary mask of largest component
|
|
355
355
|
body_segmentation = sitk.Equal(labeled, largest_label)
|
|
@@ -366,11 +366,19 @@ class VOI(PyRadPlanBaseModel, ABC):
|
|
|
366
366
|
raise ValueError("new_ct must be a CT object")
|
|
367
367
|
|
|
368
368
|
if self.mask.GetDimension() == 3:
|
|
369
|
-
new_mask = sitk.Resample(
|
|
369
|
+
new_mask = sitk.Resample(
|
|
370
|
+
self.mask, new_ct.cube_hu, interpolator=sitk.sitkNearestNeighbor
|
|
371
|
+
)
|
|
370
372
|
elif self.mask.GetDimension() == 4:
|
|
371
373
|
new_mask = []
|
|
372
374
|
for i in range(self.mask.GetSize()[-1]):
|
|
373
|
-
new_mask.append(
|
|
375
|
+
new_mask.append(
|
|
376
|
+
sitk.Resample(
|
|
377
|
+
self.mask[:, :, :, i],
|
|
378
|
+
new_ct.cube_hu,
|
|
379
|
+
interpolator=sitk.sitkNearestNeighbor,
|
|
380
|
+
)
|
|
381
|
+
)
|
|
374
382
|
new_mask = sitk.JoinSeries(new_mask)
|
|
375
383
|
else:
|
|
376
384
|
raise ValueError("Sanity check failed -- mask has invalid dimensions")
|
|
@@ -286,6 +286,11 @@ class Dij(PyRadPlanBaseModel):
|
|
|
286
286
|
|
|
287
287
|
dij_dict = super().to_matrad(context=context)
|
|
288
288
|
|
|
289
|
+
# Replace None values with np.array([0]) for savemat compatibility
|
|
290
|
+
for key, value in dij_dict.items():
|
|
291
|
+
if value is None:
|
|
292
|
+
dij_dict[key] = np.array([0])
|
|
293
|
+
|
|
289
294
|
return dij_dict
|
|
290
295
|
|
|
291
296
|
def get_result_arrays_from_intensity(
|
|
@@ -27,7 +27,7 @@ from pyRadPlan.stf import SteeringInformation, validate_stf
|
|
|
27
27
|
from pyRadPlan.plan import Plan, validate_pln
|
|
28
28
|
from pyRadPlan.dij import Dij, validate_dij
|
|
29
29
|
from pyRadPlan.scenarios import create_scenario_model, ScenarioModel
|
|
30
|
-
from pyRadPlan.machines import load_machine_from_mat, validate_machine
|
|
30
|
+
from pyRadPlan.machines import load_machine_from_mat, validate_machine, Machine
|
|
31
31
|
|
|
32
32
|
logger = logging.getLogger(__name__)
|
|
33
33
|
|
|
@@ -91,7 +91,7 @@ class DoseEngineBase(ABC):
|
|
|
91
91
|
self._ct_grid = None
|
|
92
92
|
|
|
93
93
|
# Protected properties with public get access
|
|
94
|
-
self._machine = None # base data defined in machine file
|
|
94
|
+
self._machine: Machine = None # base data defined in machine file
|
|
95
95
|
self._timers = None # timers of dose calc
|
|
96
96
|
self._num_of_columns_dij = None # number of columns in the dij struct
|
|
97
97
|
self._vox_world_coords = None # ct voxel coordinates in world
|
|
@@ -296,6 +296,7 @@ class PencilBeamEngineAbstract(DoseEngineBase):
|
|
|
296
296
|
wed_cube_trace = self.cube_wed
|
|
297
297
|
|
|
298
298
|
self._raytracer = RayTracerSiddon([wed_cube_trace])
|
|
299
|
+
self._raytracer.lateral_cut_off = self.geometric_lateral_cutoff
|
|
299
300
|
|
|
300
301
|
return dij
|
|
301
302
|
|
|
@@ -389,6 +390,9 @@ class PencilBeamEngineAbstract(DoseEngineBase):
|
|
|
389
390
|
start_time = time.time()
|
|
390
391
|
|
|
391
392
|
self._raytracer.debug_core_performance = True
|
|
393
|
+
self._raytracer.lateral_cut_off = beam_info["beam"].get(
|
|
394
|
+
"effective_lateral_cut_off", self._effective_lateral_cutoff
|
|
395
|
+
)
|
|
392
396
|
rad_depth_cubes = self._raytracer.trace_cubes(beam_info["beam"])
|
|
393
397
|
self._raytracer.debug_core_performance = False
|
|
394
398
|
|
|
@@ -48,8 +48,8 @@ def get_available_engines(pln: Union[Plan, dict[str]]) -> dict[str, Type[DoseEng
|
|
|
48
48
|
|
|
49
49
|
Returns
|
|
50
50
|
-------
|
|
51
|
-
|
|
52
|
-
A
|
|
51
|
+
dict[str, Type[DoseEngineBase]]
|
|
52
|
+
A dictionary containing the available engines.
|
|
53
53
|
"""
|
|
54
54
|
pln = validate_pln(pln)
|
|
55
55
|
return {
|