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 DeliveryData object, then using the values within this object to calculate an MU Density.

[1]:
from glob import glob

import numpy as np
import matplotlib.pyplot as plt

from pymedphys.trf import delivery_data_from_logfile
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.

[2]:
logfile_path_search_string = '../../../packages/pymedphys_fileformats/tests/trf/data/*/*VMAT*.trf'

example_logfile_from_tests = glob(logfile_path_search_string)[0]
example_logfile_from_tests
[2]:
'../../../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

DeliveryData 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 DeliveryData 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 DeliveryData is likely to change in the future.

[3]:
delivery_data = delivery_data_from_logfile(example_logfile_from_tests)
[4]:
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.

[5]:
first_10_seconds = slice(0, 10 * 25, 1)
[6]:
mu_density = calc_mu_density(
    mu[first_10_seconds], mlc[first_10_seconds],
    jaw[first_10_seconds])
[7]:
grid = get_grid()

plt.figure(figsize=(6,4))
display_mu_density(grid, mu_density)
plt.xlim([-60, 60])
plt.ylim([50, -60])
[7]:
(50, -60)
../../_images/user_examples_trf_mudensity_10_1.png