Medical Physics Python Exercises #1

The radiation oncology medical physics group at the Royal Brisbane and Women’s Hospital have started a series of tutorials on the Python language. For the second tutorial, we will be discussing solutions to a few example medical physics exercises, detailed below. Attendees will be asked to prepare solutions in Python or pseudocode to one or all of the exercises prior to the tutorial.

MLC shaper

The MLC Shaper application, developed by Varian, allows the creation of .MLC files that can be used to deliver multi-leaf collimated fields in service. Unfortunately this software appears to no longer work in recent versions of Microsoft Windows. In this exercise a program to generate MLC leaf position files for rectangular fields needs to be created. The user will input the data required for the file, in the following way:

Field name: test
Field size, x (cm): 2.0
Field size, y (cm): 3.7

The code will then produce a single Shaper MLC file containing the nearest possible (larger) MLC field that matches the user-specified input. An example Shaper MLC file can be found here. The file format will be explored in the solution to this exercise, to be posted at a later date.

Possible expansion of the project includes support for multiple collimator systems (Shaper supports “Standard”, “Millennium” and the BrainLab m3 micro-MLC, for example), supporting more complicated field shapes, and leaf visualisation.

Field size calculator

The physical field size of a radiation beam is typically defined using the 50% isodose line. In this exercise a program to determined field length based on a dose profile needs to be created. The dose profile will be stored in a comma separated value (CSV) file. An example profile can be found here.

Possible expansion of the project includes support for less sanitised data (where no signal doesn’t correspond to 0.0 or resolution varies across the field, for example), and the calculation of other percentile values.

Film calibrator

In this exercise you will create a basic program that generates a dose plane (in any format you wish) from two images, a pre-scan and a post-scan, using an optical density method. The optical density of a point is defined using known pixel values:

$\mathrm{OD} = -\log_{10}(\frac{\mathrm{PV}_\mathrm{pre}}{\mathrm{PV}_\mathrm{post}})$

For this example, the user can be prompted for a calibration relationship, or the code can automatically use the following:

$\mathrm{D} = (26.06 \times \mathrm{OD}^2) + (3.2249 \times \mathrm{OD}) + 0.1213$

Example film images can be found here and here (pre- and post- film scans respectively).

Possible expansion of the project includes the calculation of output factors, by extraction of central axis data (either from the centre of the film, or by identifying the centre of the field) and exporting the dose in multiple formats (including SNC or DICOM formats for analysis software suites).