A toolkit for performing TG-142 QA-related tasks on a linear accelerator
Pylinac provides TG-142 quality assurance (QA) tools to Python programmers as well as non-programmers in the field of therapy medical physics. The package comes in two flavors: source-level and web app. The source-level allows programming physicists to create custom tests with pylinac. The source also contains a simple GUI for interacting with modules. The web app is a proof-of-concept taking pylinac into the web!
Pylinac contains high-level modules for automatically analyzing images and data generated by linear accelerators. Most scripts can be utilized with <10 lines of code. The built in GUI is also straight-forward although programming experience may help identify errors.
The library also contains lower-level hackable modules & tools for creating your own radiation therapy algorithms.
The major features of the entire package include:
To get started, install the package, run the demos, view the API docs, and learn the module design, visit the Full Documentation on Read The Docs.
Pylinac should be installed via conda if available. First, add the proper channel, then install the package:
$ conda config --add channels jrkerns $ conda install pylinac
You may also install via pip, although you must have C compilers to build the dependencies :
$ pip install pylinac
See the Installation page for further details.
Below are the high-level tools currently available:
A simple but effective GUI is available for those who are less interested in programming. Start the GUI from Python:
import pylinac pylinac.gui() # that simple
Or start from the command line:
$ pylinac gui
True, one-time “set it and forget it” service that analyzes any file that enters the folder. Files with keywords and certain file types are analyzed automatically. You can also specify “source” folders to pull new files from (e.g. a Varian shared drive holding Trajectory logs or QA images).
After installation, run the watcher script via the command line:
$ pylinac watch "dir/to/watch" # start watching!
or via Python
from pylinac import watch, process watch("dir/to/watch") # will run forever process("dir/to/watch") # will run once and then return
And that’s it! No code to write; no fuss, no muss. Analysis settings are customizable and includes optional email service upon analysis.
Input the raw data and pylinac can calculate either individual values (kQ, PDDx, Pion, etc) or use the provided classes to input all measurement data and have it calculate all factors and dose values automatically.
from pylinac import tg51 tg51_6x = tg51.TG51Photon(temp=TEMP, press=PRESS, model=CHAMBER, n_dw=ND_w, p_elec=P_ELEC, measured_pdd=66.4, lead_foil=None, clinical_pdd=66.5, energy=ENERGY, volt_high=-300, volt_low=-150, m_raw=(25.65, 25.66, 25.65), m_opp=(25.64, 25.65, 25.65), m_low=(25.64, 25.63, 25.63), mu=MU, tissue_correction=1.0) # Done! print(tg51_6x.dose_mu_dmax) # examine other parameters tg51_6x.pddx tg51_6x.kq tg51_6x.p_ion # change readings if you adjust output tg51_6x.m_raw = (25.44, 25.44, 25.43) # print new dose value print(tg51_6x.dose_mu_dmax)
The planar imaging module analyzes 2D phantoms. Currently the LeedsTOR kV phantom, Standard Imaging QC-3 MV phantom, and Las Vegas phantom are supported, and more phantoms are in the works!
from pylinac import LeedsTOR, StandardImagingQC3, LasVegas leeds = LeedsTOR("my_leeds.dcm") leeds.analyze() leeds.plot_analyzed_image() leeds.publish_pdf() qc3 = StandardImagingQC3("my_qc3.dcm") qc3.analyze() qc3.plot_analyzed_image() qc3.publish_pdf('qc3.pdf') lv = LasVegas("my_lv.dcm") lv.analyze() lv.plot_analyzed_image() lv.publish_pdf('lv.pdf', open_file=True) # open the PDF after publishing
The Winston-Lutz module analyzes EPID images taken of a small radiation field and BB to determine the 2D distance from BB to field CAX. Additionally, the isocenter size of the gantry, collimator, and couch can all be determined without the BB being at isocenter. Analysis is based on Winkler et al and Du et al.
from pylinac import WinstonLutz wl = WinstonLutz("wl/image/directory") # images are analyzed upon loading wl.plot_summary() print(wl.results()) wl.publish_pdf('my_wl.pdf')
from pylinac import Starshot star = Starshot("mystarshot.tif") star.analyze(radius=0.75, tolerance=1.0, fwhm=True) print(star.return_results()) # prints out wobble information star.plot_analyzed_image() # shows a matplotlib figure star.publish_pdf() # publish a PDF report
The VMAT module consists of the class VMAT, which is capable of loading an EPID DICOM Open field image and MLC field image and analyzing the images according to the Varian RapidArc QA tests and procedures, specifically the Dose-Rate & Gantry-Speed (DRGS) and MLC speed (MLCS) tests.
from pylinac import VMAT vmat = VMAT(images=["DRGSopen.dcm", "DRGSdmlc.dcm"], delivery_types=["open", "dmlc"]) vmat.analyze(test='drgs', tolerance=1.5) print(vmat.return_results()) # prints out ROI information vmat.plot_analyzed_image() # shows a matplotlib figure vmat.publish_pdf('myvmat.pdf') # generate a PDF report
The CBCT module automatically analyzes DICOM images of a CatPhan 504, 503, or 600 acquired when doing CT or CBCT quality assurance. It can load a folder or zip file that the images are in and automatically correct for phantom setup in 6 axes. It can analyze the HU regions and image scaling (CTP404), the high-contrast line pairs (CTP528) to calculate the modulation transfer function (MTF), and the HU uniformity (CTP486) on the corresponding slice.
from pylinac import CatPhan504, CatPhan503, CatPhan600 # for this example, we'll use the CatPhan504 cbct = CatPhan504("my/cbct_image_folder") cbct.analyze(hu_tolerance=40, scaling_tolerance=1, thickness_tolerance=0.2, low_contrast_threshold=1) print(cbct.return_results()) cbct.plot_analyzed_image() cbct.publish_pdf('mycbct.pdf')
The log analyzer module reads and parses Varian linear accelerator machine logs, both Dynalogs and Trajectory logs. The module also calculates actual and expected fluences as well as performing gamma evaluations. Data is structured to be easily accessible and easily plottable.
Unlike most other modules of pylinac, the log analyzer module has no end goal. Data is parsed from the logs, but what is done with that info, and which info is analyzed is up to the user.
from pylinac import load_log tlog = load_log("tlog.bin") # after loading, explore any Axis of the Varian structure tlog.axis_data.gantry.plot_actual() # plot the gantry position throughout treatment tlog.fluence.gamma.calc_map(doseTA=1, distTA=1, threshold=10, resolution=0.1) tlog.fluence.gamma.plot_map() # show the gamma map as a matplotlib figure tlog.publish_pdf() # publish a PDF report dlog = load_log("dynalog.dlg") ...
The picket fence module is meant for analyzing EPID images where a “picket fence” MLC pattern has been made. Physicists regularly check MLC positioning through this test. This test can be done using film and one can “eyeball” it, but this is the 21st century and we have numerous ways of quantifying such data. This module attains to be one of them. It will load in an EPID dicom image and determine the MLC peaks, error of each MLC pair to the picket, and give a few visual indicators for passing/warning/failing.
from pylinac import PicketFence pf = PicketFence("mypf.dcm") pf.analyze(tolerance=0.5, action_tolerance=0.25) print(pf.return_results()) pf.plot_analyzed_image() pf.publish_pdf()
Analysis of Flatness & Symmetry of film or EPID images. Multiple equation definitions, in/cross plane.
Have questions? Ask them on the pylinac discussion forum.
Contributions to pylinac can be many. The most useful things a non-programmer can contribute are images to analyze and bug reports. If you have VMAT images, starshot images, machine log files, CBCT DICOM files, or anything else you want analyzed, upload them privately here.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|File Name & Checksum SHA256 Checksum Help||Version||File Type||Upload Date|
|pylinac-2.0.1-py3-none-any.whl (188.4 kB) Copy SHA256 Checksum SHA256||py3||Wheel||Apr 23, 2017|
|pylinac-2.0.1.tar.gz (138.4 kB) Copy SHA256 Checksum SHA256||–||Source||Apr 23, 2017|