Skip to content

Commit f7492c4

Browse files
committed
Merge branch 'refactor/machines' into 'develop'
refactor/machines See merge request e040/e0404/pyRadPlan!89
2 parents e736c52 + aeab32d commit f7492c4

27 files changed

+1106
-819
lines changed

pyRadPlan/dose/engines/_base_pencilbeam_particle.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
from pyRadPlan.ct import CT
1515
from pyRadPlan.stf import SteeringInformation
16-
from pyRadPlan.machines import IonAccelerator, IonPencilBeamKernel, LateralCutOff
16+
from pyRadPlan.machines.particles import (
17+
ParticleAccelerator,
18+
ParticlePencilBeamKernel,
19+
LateralCutOff,
20+
)
1721
from pyRadPlan.cst import StructureSet
1822
from ._base_pencilbeam import PencilBeamEngineAbstract
1923

@@ -183,7 +187,7 @@ def _init_bixel(self, curr_ray, k):
183187
bixel["energy_ix"] = energy_ix
184188

185189
# Get the kernel for the current energy
186-
tmp_machine = cast(IonAccelerator, self._machine)
190+
tmp_machine = cast(ParticleAccelerator, self._machine)
187191
bixel["kernel"] = tmp_machine.get_kernel_by_index(energy_ix)
188192

189193
bixel["range_shifter"] = curr_ray["beamlets"][k]["range_shifter"]
@@ -218,7 +222,7 @@ def _init_bixel(self, curr_ray, k):
218222
return bixel
219223

220224
def _interpolate_kernels_in_depth(self, bixel):
221-
kernel = cast(IonPencilBeamKernel, bixel["kernel"])
225+
kernel = cast(ParticlePencilBeamKernel, bixel["kernel"])
222226
depths = kernel.depths
223227

224228
# Add potential offset
@@ -299,7 +303,7 @@ def _get_ray_geometry_from_beam(self, ray: dict[str], beam_info: dict[str]):
299303
]
300304

301305
def _get_bixel_indices_on_ray(self, curr_bixel, curr_ray):
302-
kernel = cast(IonPencilBeamKernel, curr_bixel["kernel"])
306+
kernel = cast(ParticlePencilBeamKernel, curr_bixel["kernel"])
303307

304308
# Create offset vector to account for additional offsets modeled in the base data
305309
# and a potential range shifter
@@ -437,7 +441,7 @@ def _init_beam(
437441
beam_info = super()._init_beam(dij, ct, cst, stf, i)
438442

439443
# Sanity Check
440-
assert isinstance(self._machine, IonAccelerator)
444+
assert isinstance(self._machine, ParticleAccelerator)
441445

442446
# Assuming currBeam is part of beam_info
443447
curr_beam = beam_info["beam"]
@@ -557,7 +561,7 @@ def _allocate_let_container(self, dij):
557561

558562
def _calc_lateral_particle_cut_off(self, cut_off_level, stf_element):
559563
# Sanity Checks
560-
assert isinstance(self._machine, IonAccelerator)
564+
assert isinstance(self._machine, ParticleAccelerator)
561565

562566
if len(stf_element) > 1 and not isinstance(stf_element, dict):
563567
raise ValueError(
@@ -798,7 +802,7 @@ def _calc_lateral_particle_cut_off(self, cut_off_level, stf_element):
798802
def _init_ray(self, beam_info: dict[str], j: int) -> dict[str]:
799803
ray = super()._init_ray(beam_info, j)
800804

801-
self._machine = cast(IonAccelerator, self._machine)
805+
self._machine = cast(ParticleAccelerator, self._machine)
802806

803807
# Calculate initial sigma for all bixels on the current ray
804808
# TODO: here [ray] since calc_sigma_ini takes multiple rays (why?)
@@ -853,7 +857,7 @@ def _fill_dij(
853857

854858
def _get_lateral_distance_from_dose_cutoff_on_ray(self, ray: dict):
855859
# Find index of maximum used energy (round to keV for numerical reasons)
856-
self._machine = cast(IonAccelerator, self._machine)
860+
self._machine = cast(ParticleAccelerator, self._machine)
857861

858862
max_energy = max([beamlet["energy"] for beamlet in ray["beamlets"]])
859863
kernel = self._machine.get_kernel_by_energy(max_energy)

pyRadPlan/dose/engines/_hongpb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import cast
22
import numpy as np
33
from ._base_pencilbeam_particle import ParticlePencilBeamEngineAbstract
4-
from pyRadPlan.machines import IonPencilBeamKernel
4+
from pyRadPlan.machines import ParticlePencilBeamKernel
55

66

77
class ParticleHongPencilBeamEngine(ParticlePencilBeamEngineAbstract):
@@ -14,7 +14,7 @@ class ParticleHongPencilBeamEngine(ParticlePencilBeamEngineAbstract):
1414
def _calc_particle_bixel(self, bixel):
1515
kernels = self._interpolate_kernels_in_depth(bixel)
1616

17-
pb_kernel = cast(IonPencilBeamKernel, bixel["kernel"])
17+
pb_kernel = cast(ParticlePencilBeamKernel, bixel["kernel"])
1818

1919
# Lateral Component
2020
if self.lateral_model == "single":

pyRadPlan/machines/__init__.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,36 @@
1-
"""Treatment machines and beam models."""
1+
"""Machine definitions for external beam radiotherapy."""
22

3-
from ._base import Machine, ExternalBeamMachine
4-
from ._photons import PhotonLINAC, PhotonSVDKernel
5-
from ._ions import IonAccelerator, IonPencilBeamKernel, LateralCutOff
3+
from .base import (
4+
Machine,
5+
ExternalBeamMachine,
6+
InternalBeamMachine,
7+
register_machine,
8+
)
9+
from .photons import PhotonLINAC, PhotonSVDKernel
10+
from .particles import (
11+
ParticlePencilBeamKernel,
12+
LateralCutOff,
13+
IonAccelerator,
14+
)
615
from ._validate import validate_machine
716
from ._load import load_from_name, load_machine_from_mat, load_machine
817

18+
register_machine(PhotonLINAC)
19+
register_machine(IonAccelerator)
20+
# register_machine(VHEEAccelerator)
21+
922
__all__ = [
1023
"Machine",
1124
"ExternalBeamMachine",
25+
"InternalBeamMachine",
1226
"PhotonLINAC",
1327
"PhotonSVDKernel",
14-
"load_from_name",
15-
"validate_machine",
16-
"IonAccelerator",
17-
"IonPencilBeamKernel",
28+
"ParticlePencilBeamKernel",
1829
"LateralCutOff",
30+
"IonAccelerator",
31+
"validate_machine",
32+
"load_from_name",
1933
"load_machine_from_mat",
2034
"load_machine",
35+
"register_machine",
2136
]

0 commit comments

Comments
 (0)