Getting A Fluence Map from RT Plan

Hello everyone,

First off, I haven’t used PyMedPhys before. I have some experience with Python and PyLinac, but not PyMedPhys.

I’ve started using PyLinac for Varian log file analysis and would have interest in comparing fluences generated from log files to fluences generated in a similar fashion from MLC/jaw/etc. positions in the RT Plan file.

My googling has indicated that this should be possible with PyMedPhys. Is there any sort of guide that would help me in getting started with this?

Thanks in advance,

Thanks

1 Like

Hi David :slight_smile:,

PyMedPhys’ MLC + Jaw fluence approach assumes that there is only one set of jaws (no backup jaws). It was designed with the Elekta Agility in mind. Are you wanting to be able to utilise the backup jaws on the Varian or is that not an issue?

The first example within the docs gives an idea of how one might provide some raw MLC and jaw positions:

https://docs.pymedphys.com/lib/ref/metersetmap.html#api

I’ll copy the example in below for ease:

>>> import numpy as np
>>> import pymedphys
>>>
>>> leaf_pair_widths = (5, 5, 5)  # The widths of the leaves on the bank
>>> max_leaf_gap = 10  # The max distance between opposing leaves
>>> mu = np.array([0, 2, 5, 10])  # MU for each control point
>>> mlc = np.array([  # MLC positions for each control point
...     [
...         [1, 1],
...         [2, 2],
...         [3, 3]
...     ],
...     [
...         [2, 2],
...         [3, 3],
...         [4, 4]
...     ],
...     [
...         [-2, 3],
...         [-2, 4],
...         [-2, 5]
...     ],
...     [
...         [0, 0],
...         [0, 0],
...         [0, 0]
...     ]
... ])
>>> jaw = np.array([  # Jaw positions for each control point
...     [7.5, 7.5],
...     [7.5, 7.5],
...     [-2, 7.5],
...     [0, 0]
... ])
>>>
>>> grid = pymedphys.metersetmap.grid(  # The grid to calculate over
...    max_leaf_gap=max_leaf_gap, leaf_pair_widths=leaf_pair_widths)
>>> grid['mlc']
array([-5., -4., -3., -2., -1.,  0.,  1.,  2.,  3.,  4.,  5.])
>>>
>>> grid['jaw']
array([-8., -7., -6., -5., -4., -3., -2., -1.,  0.,  1.,  2.,  3.,  4.,
        5.,  6.,  7.,  8.])
>>>
>>> metersetmap = pymedphys.metersetmap.calculate(
...    mu, mlc, jaw, max_leaf_gap=max_leaf_gap,
...    leaf_pair_widths=leaf_pair_widths)
>>> pymedphys.metersetmap.display(grid, metersetmap)
>>>
>>> np.round(metersetmap, 1)
array([[0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0.3, 1.9, 2.2, 1.9, 0.4, 0. , 0. , 0. ],
       [0. , 0. , 0. , 0.4, 2.2, 2.5, 2.2, 0.6, 0. , 0. , 0. ],
       [0. , 0. , 0. , 0.4, 2.4, 2.8, 2.5, 0.8, 0. , 0. , 0. ],
       [0. , 0. , 0. , 0.4, 2.5, 3.1, 2.8, 1. , 0. , 0. , 0. ],
       [0. , 0. , 0. , 0.4, 2.5, 3.4, 3.1, 1.3, 0. , 0. , 0. ],
       [0. , 0. , 0.4, 2.3, 3.2, 3.7, 3.7, 3.5, 1.6, 0. , 0. ],
       [0. , 0. , 0.4, 2.3, 3.2, 3.8, 4. , 3.8, 1.9, 0.1, 0. ],
       [0. , 0. , 0.4, 2.3, 3.2, 3.8, 4.3, 4.1, 2.3, 0.1, 0. ],
       [0. , 0. , 0.4, 2.3, 3.2, 3.9, 5.2, 4.7, 2.6, 0.2, 0. ],
       [0. , 0. , 0.4, 2.3, 3.2, 3.8, 5.4, 6.6, 3.8, 0.5, 0. ],
       [0. , 0.3, 2.2, 3. , 3.5, 4. , 5.1, 7.5, 6.7, 3.9, 0.5],
       [0. , 0.3, 2.2, 3. , 3.5, 4. , 4.7, 6.9, 6.7, 3.9, 0.5],
       [0. , 0.3, 2.2, 3. , 3.5, 4. , 4.5, 6.3, 6.4, 3.9, 0.5],
       [0. , 0.3, 2.2, 3. , 3.5, 4. , 4.5, 5.6, 5.7, 3.8, 0.5],
       [0. , 0.3, 2.2, 3. , 3.5, 4. , 4.5, 5.1, 5.1, 3.3, 0.5],
       [0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. , 0. ]])

Alternatively, if you are keen on also supporting the backup jaws, and you have some python chops, adding in backup jaws would involve extending the following:

I’d be more than happy to help you achieve that if that’s the path you’d like to go down.

Thanks Simon,

Yeah, I’m more interested in Varian as we don’t have any Elekta machines. I highly doubt that I’d be skilled enough with Python to be able to extend your code to working with Varians, unfortunately.

Kk :slight_smile:,

If you ever do decide to give it a crack, let me know. I’d be happy to jump on a video call and help you out.

Cheers,
Simon