Skip to content

Instantly share code, notes, and snippets.

View jrkerns's full-sized avatar

James Kerns jrkerns

  • Radformation
  • Houston, TX
View GitHub Profile
from functools import cached_property
from pylinac import CatPhan504
from pylinac.ct import CTP528CP504
from pylinac.core.profile import CollapsedCircleProfile
class MyCTP528CP504(CTP528CP504):
@cached_property
@jrkerns
jrkerns / acr_fix.py
Created August 30, 2023 20:07
acr fix
import math
from pylinac import ACRMRILarge
class MyACRMRI(ACRMRILarge):
def _ensure_physical_scan_extent(self) -> bool:
"""Ensure that all the modules of the phantom have been scanned. If a CBCT isn't
positioned correctly, some modules might not be included."""
@jrkerns
jrkerns / leeds_311.py
Created July 12, 2023 21:48
LeedsTOR 3.11 ROI placement
from pylinac import LeedsTOR
class LeedsTOR311(LeedsTOR):
high_contrast_roi_settings = {
"roi 1": {
"distance from center": 0.3,
"angle": 54.8,
"roi radius": 0.04,
"lp/mm": 0.5,
@jrkerns
jrkerns / mmoverride.py
Created June 27, 2023 16:56
catphan mm override
import pylinac
class CatphanFOV(pylinac.CatPhan504):
@property
def mm_per_pixel(self) -> float:
return super().mm_per_pixel * 0.81
@jrkerns
jrkerns / ct_fixed.py
Created June 27, 2023 15:47
Override catphan localization
# override how pylinac finds the phantom position and angle
import pylinac
class FixedCatPhan604(pylinac.CatPhan604):
def localize(self) -> None:
super().localize()
self._phantom_center_func = (lambda x: 250, lambda y: 250)
def find_origin_slice(self) -> int:
from pylinac.cheese import CheeseModule, CheesePhantomBase
class GammexRMIModule(CheeseModule):
"""The pluggable module with user-accessible holes.
The ROIs of each circle are ~45 degrees apart.
"""
common_name = "Gammex electron density"
outer_radius_mm = 106
@jrkerns
jrkerns / picket_distances.py
Last active April 26, 2023 14:31
Show various ways to get picket/leaf distances
# We assume there is a central picket in the image
# We use the demo image for repeatability even though it's not representative of your specific image
# REMEMBER: leaves are enumerated from the bottom up. I.e. leaf 12 is near the bottom of the image, not the top
# This might not correspond with reality, but that's the convention as it stands currently.
# setup
pf = pylinac.PicketFence.from_demo()
pf.analyze()
# method 1: Get picket distances from the CAX:
@jrkerns
jrkerns / pf_picket_distances.py
Last active April 10, 2023 18:07
PF picket distances by leaf pair
import numpy as np
import pylinac
from pylinac.core.profile import MultiProfile
pf = pylinac.PicketFence.from_demo_image()
pf.analyze()
# the secret sauce. This gives the y-value for each leaf kiss.
import pylinac
logo_path = r"C:/my/logo/path.png"
pf = pylinac.PicketFence(...)
pf.analyze(...)
pf.publish_pdf(..., logo=logo_path)
@jrkerns
jrkerns / center_comparison.py
Created March 14, 2023 21:24
Center Unif ROI
import pylinac
ct = pylinac.CatPhan504.from_demo_images()
ct.analyze()
data = ct.results_data()
center_unif_roi = data.ctp486.rois['Center']
for name, roi in data.ctp486.rois.items():
if name == 'Center':
continue
if abs(roi.value - center_unif_roi.value) > 30: