Plotting Plan Fluence

We can plot fluence from an RT Plan using the plan_generator module. This is a simplistic approach.

Warning

This should not be used for evaluating patient treatments or fluences. It is for QA/research purposes only.

Note

This will generate the fluence of the MLCs only. Collimator rotation is not accounted for. Further, jaws are shown as a rectangle outline, but the fluence calculation does not consider them. This is on purpose; accounting for jaw position in the fluence itself will not be supported.

First, we need to load a plan and then call plot_fluences.

import pydicom
from pylinac.plan_generator.fluence import plot_fluences

plan = pydicom.dcmread("path/to/plan.dcm")
plot_fluences(plan, width_mm=200, resolution_mm=0.5)

We can also generate the fluence as a 3D numpy array using the generate_fluences function.

from pylinac.plan_generator.fluence import generate_fluences

fluences = generate_fluences(plan, width_mm=200, resolution_mm=0.5)

The fluence is of shape (num_beams, height, width).

API Documentation

pylinac.plan_generator.fluence.plot_fluences(plan: ~pydicom.dataset.Dataset, width_mm: float, resolution_mm: float, dtype: ~numpy.dtype = <class 'numpy.uint16'>, show: bool = True) list[Figure][source]

Plot the fluences of the dataset. Generates N figures where N is the number of Beams in the plan BeamSequence.

Parameters

planpydicom.Dataset

The RT Plan dataset. Must contain BeamSequence.

width_mmint

The width of the fluence map in mm. Use smaller values for faster calculation.

resolution_mmfloat, optional

The resolution of the fluence map in mm. Smaller values will take longer to calculate.

dtypetype, optional

The data type of the fluence map. Default is uint16.

showbool, optional

Whether to show the plots. Default is True.

Returns

list[Figure]

A list of matplotlib figures, one for each beam in the plan.

pylinac.plan_generator.fluence.generate_fluences(rt_plan: ~pydicom.dataset.Dataset, width_mm: float, resolution_mm: float = 0.1, dtype: ~numpy.dtype = <class 'numpy.uint16'>) ndarray[source]

Generate the fluence map from the RT Plan. This will create an MxN array where M is the width in mm * resolution and N is the height set by the bounds of the MLCs * resolution.

Parameters

rt_planpydicom.Dataset

The RT Plan dataset. Must contain BeamSequence.

width_mmint

The width of the fluence map in mm. Use smaller values for faster calculation.

resolution_mmfloat, optional

The resolution of the fluence map in mm. Smaller values will take longer to calculate.

dtypetype, optional

The data type of the fluence map. Default is uint16.

Returns

np.array

The fluence map. Will be of shape (num_beams, height, width).