Note
Go to the end to download the full example code.
PBS Delivery Timings#
author: OpenTPS team
This example will present the basis of PBS delivery timings with openTPS core.
running time: ~ 5 minutes
Setting up the environment in google collab#
import sys
if "google.colab" in sys.modules:
from IPython import get_ipython
get_ipython().system('git clone https://gitlab.com/openmcsquare/opentps.git')
get_ipython().system('pip install ./opentps')
get_ipython().system('pip install scipy==1.10.1')
import opentps
imports
import numpy as np
np.random.seed(42)
import the needed opentps.core packages
from opentps.core.data.plan._planProtonBeam import PlanProtonBeam
from opentps.core.data.plan._planProtonLayer import PlanProtonLayer
from opentps.core.data.plan._protonPlan import ProtonPlan
from opentps.core.processing.planDeliverySimulation.scanAlgoBeamDeliveryTimings import ScanAlgoBeamDeliveryTimings
from opentps.core.processing.planDeliverySimulation.simpleBeamDeliveryTimings import SimpleBeamDeliveryTimings
from opentps.core.io.dicomIO import readDicomPlan
Create random plan#
plan = ProtonPlan()
plan.appendBeam(PlanProtonBeam())
energies = np.array([130, 140, 150, 160, 170])
for m in energies:
layer = PlanProtonLayer(m)
x = 10*np.random.random(5) - 5
y = 10*np.random.random(5) - 5
mu = 5*np.random.random(5)
layer.appendSpot(x, y, mu)
plan.beams[0].appendLayer(layer)
bdt = SimpleBeamDeliveryTimings(plan)
plan_with_timings = bdt.getPBSTimings(sort_spots="true")
Print plan#
print(plan_with_timings._beams[0]._layers[0].__dict__)
{'_spots': [], '_x': array([-1.43246673, -2.28650968, -1.1132271 , 3.28737509, -2.1906549 ]), '_y': array([-4.25449356, -3.59075775, 0.42696083, 3.02196981, 4.86886937]), '_mu': array([4.07730714, 0.99357841, 3.86122385, 0.02761059, 3.53428672]), '_startTime': array([0. , 0.02459905, 0.03108371, 0.05488965, 0.05586227]), '_irradiationDuration': array([0.02446384, 0.00596147, 0.02316734, 0.00025 , 0.02120572]), 'scalingFactor': 1.0, 'nominalEnergy': 170, 'numberOfPaintings': 1, 'rangeShifterSettings': <opentps.core.data.plan._planProtonLayer.RangeShifterSettings object at 0x7fe76524d550>, 'seriesInstanceUID': '', 'spotsPeakPosInDcmCoords': [], 'spotsPeakPosInTargetSystem': []}
Total running time of the script: (0 minutes 0.006 seconds)