Skip to content

Update winston_lutz plot_images() - #542

Open
brianmanderson wants to merge 1 commit into
jrkerns:masterfrom
brianmanderson:master
Open

brianmanderson wants to merge 1 commit into
jrkerns:masterfrom
brianmanderson:master

Conversation

@brianmanderson

Copy link
Copy Markdown

I apologize if this is a failing of using the program on my side. I greatly appreciate PyLinac and how it has helped me and the clinic I'm a part of.

The reason I made this change is that when running wl.plot_images() it was unable to correctly split the images based on the presented axis (axis==Axis.GANTRY, COLLIMATOR, etc.)

I'm at an ELEKTA site and am using the axis_mapping feature to establish gantry, collimator, couch angles.

The program runs as expected after applying this change, and I believe it would not detrimentally impact those currently using the program.

Thank you!

Enabling plotting where image.variable_axis.GANTRY, COLLIMATOR, and COUCH seemed to not be identified
@brianmanderson brianmanderson changed the title Update winston_lutz.py Update winston_lutz plot_images() Feb 5, 2025
@jrkerns

jrkerns commented Mar 10, 2025

Copy link
Copy Markdown
Owner

Thanks for the suggestion. I'm not quite clear on the "it was unable to correctly split the images based on the presented axis". Can you show a code snippet of what you were doing when it incorrectly split the images?

@brianmanderson

Copy link
Copy Markdown
Author

Thanks for the response! I've attached the 8 DICOM EPID files that I used to run the analysis.
EPID.zip

When running the code below without my addition I receive the following error below

from pylinac.winston_lutz import WinstonLutz, MachineScale, Axis
import os


def get_last_number(filename):
    # Get the base name in case you have a full path
    base = os.path.basename(filename)
    # Remove the extension (assuming '.dcm' is 4 characters)
    if base.lower().endswith('.dcm'):
        base = base[:-4]
    # Split by '.' and convert the last part to an integer
    return int(base.split('.')[-1])


def main():
    # TODO Change path to files! you can use r'\\radoncphysics\DATA\RIT_QA_Images\UNC\FOLDER'
    path_to_files = os.path.join('.', 'Data')
    files = [i for i in os.listdir(path_to_files) if i.endswith('.dcm')]
    sorted_files = sorted(files, key=get_last_number)
    """
    Mapping values refer to gantry, collimator, couch
    """
    gantry_collimator_couch_angles = [
        (180, 270, 0),
        (180, 90, 0),
        (270, 90, 0),
        (270, 270, 0),
        (0, 270, 0),
        (0, 90, 0),
        (90, 90, 0),
        (90, 270, 0)
    ]
    bb_size_mm = 7
    mapping = {filename: angle for filename, angle in zip(sorted_files, gantry_collimator_couch_angles)}
    print('File name                                     Gantry Collimator Couch')
    for key in mapping.keys():
        print(f"{key} mapped to {mapping[key]}")
    wl = WinstonLutz(directory=path_to_files, axis_mapping=mapping)
    wl.analyze(bb_size_mm=bb_size_mm, machine_scale=MachineScale.ELEKTA_IEC, low_density_bb=False)
    print(wl.bb_shift_instructions())
    wl.plot_images()
    wl.publish_pdf(os.path.join(path_to_files, 'Results.pdf'))


if __name__ == '__main__':
    main()

Traceback (most recent call last):
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\WinstonLutzEval.py", line 47, in
main()
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\WinstonLutzEval.py", line 42, in main
wl.plot_images()
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\venv\Lib\site-packages\pylinac\core\warnings.py", line 43, in wrapper
result = method(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\venv\Lib\site-packages\pylinac\winston_lutz.py", line 2359, in plot_images
fig, axes = plt.subplots(nrows=max_num_images, ncols=4, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\venv\Lib\site-packages\matplotlib\pyplot.py", line 1770, in subplots
axs = fig.subplots(nrows=nrows, ncols=ncols, sharex=sharex, sharey=sharey,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\venv\Lib\site-packages\matplotlib\figure.py", line 918, in subplots
gs = self.add_gridspec(nrows, ncols, figure=self, **gridspec_kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\venv\Lib\site-packages\matplotlib\figure.py", line 1600, in add_gridspec
gs = GridSpec(nrows=nrows, ncols=ncols, figure=self, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\venv\Lib\site-packages\matplotlib\gridspec.py", line 363, in init
super().init(nrows, ncols,
File "C:\Users\u376045\Modular_Projects\UNC_PyLinac\venv\Lib\site-packages\matplotlib\gridspec.py", line 48, in init
raise ValueError(
ValueError: Number of rows must be a positive integer, not 0

@brianmanderson

Copy link
Copy Markdown
Author

Hey, sorry wanted to touch base on this and see if there was any update on merging this into the main branch?

Thank you!
Brian

jrkerns added a commit that referenced this pull request Jul 3, 2025
add the center ROI stdev to kraken's summary area.

* add the center ROI stdev to kraken's summary area.


Approved-by: Joao Silveira
Approved-by: Randy Taylor
alanphys pushed a commit to alanphys/PylinaQA that referenced this pull request Aug 7, 2025
add the center ROI stdev to kraken's summary area.

* add the center ROI stdev to kraken's summary area.


Approved-by: Joao Silveira
Approved-by: Randy Taylor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants