This page was generated from docs/user/examples/trf_mudensity.ipynb. Interactive online version: Binder badge

MU Density from trf logfile

PyMedPhys exposes tools to read in trf logfiles into objects which can be easily passed around. In this example we will be reading a logfile directly from disk into a Delivery object, then using the values within this object to calculate an MU Density.

from glob import glob

import numpy as np
import matplotlib.pyplot as plt

from pymedphys import Delivery
from pymedphys.mudensity import (
    calc_mu_density, get_grid, display_mu_density)

For the purpose of this exercise one of the log files used for constancy testing within PyMedPhys will be used. Any trf log file path can be provided in the string below.

logfile_path_search_string = '../../../packages/pymedphys_fileformats/tests/trf/data/*/*VMAT*.trf'

example_logfile_from_tests = glob(logfile_path_search_string)[0]
'../../../packages/pymedphys_fileformats/tests/trf/data/elekta_reference/17_04_24 02_23_05 Z 1-1_1ARCVMAT.trf'

Delivery Data from a Log File

Delivery is an object within PyMedPhys which holds monitor units, gantry angles, collimator angles, as well as MLC and Jaw positions. It can be parameterised by control points, or by time interval. This particular object is a likely candiated for being adjusted in the future.

Helper functions are provided within PyMedPhys to extract Delivery from Mosaiq SQL queries as well as log files. In the future DICOM RT plan files are also expected to be supported.

The API for creating and interacting with Delivery is likely to change in the future.

delivery_data = Delivery.from_logfile(example_logfile_from_tests)
mu = delivery_data.monitor_units
mlc = delivery_data.mlc
jaw = delivery_data.jaw

Calculating and displaying the MU Density

Once MU, MLC, and Jaw parameters are known these can be used to calculate an MU Density.

first_10_seconds = slice(0, 10 * 25, 1)
mu_density = calc_mu_density(
    mu[first_10_seconds], mlc[first_10_seconds],
grid = get_grid()

display_mu_density(grid, mu_density)
plt.xlim([-60, 60])
plt.ylim([50, -60])
(50, -60)