Skip to content

Commit

Permalink
Merged in bugfix/RAM-3972_starshot_pixel_range (pull request #446)
Browse files Browse the repository at this point in the history
Bugfix/RAM-3972 starshot pixel range

Approved-by: Randy Taylor
  • Loading branch information
jrkerns committed Sep 20, 2024
2 parents 81f326c + 022d3f0 commit b3e9a2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Legend
v 3.28.0
--------

Starshot
^^^^^^^^

* :bdg-warning:`Fixed` Certain types of starshot sets where the pixel values were extremely low would fail to analyze.

Core
^^^^

Expand Down
2 changes: 1 addition & 1 deletion pylinac/starshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def _get_reasonable_wobble(
radius_gen = get_radius()
while wobble_unreasonable:
try:
min_height = max(min_peak_height * local_max, 1.01)
min_height = min_peak_height * local_max
self.circle_profile = StarProfile(
self.image, focus_point, radius, min_height, fwhm
)
Expand Down
26 changes: 26 additions & 0 deletions tests_basic/test_starshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import matplotlib.pyplot as plt
import numpy as np
from parameterized import parameterized

from pylinac import Starshot
from pylinac.core.geometry import Point
Expand Down Expand Up @@ -63,6 +64,20 @@ def test_no_dpi(self):
Starshot.from_url(self.full_url, **self.kwargs)


class TestGeneral(TestCase):
@parameterized.expand([1e5, 1e4, 1e3, 1e1, 1e1, 1, 1e-1, 1e-2, 1e-3])
def test_range_of_pixel_values(self, max_val: float):
"""Test that the range of values in the image is within a certain range."""
star = Starshot.from_demo_image()
# normalize so the max is the max_val
star.image.ground()
star.image.array = star.image.array.astype(float) / star.image.array.max()
star.image.array *= max_val
star.analyze()
self.assertLessEqual(star.wobble.diameter_mm, 0.35)
self.assertTrue(star.passed)


class TestPlottingSaving(TestCase):
@classmethod
def tearDownClass(cls):
Expand Down Expand Up @@ -93,6 +108,7 @@ class StarMixin(CloudFileMixin):
# dir_location = TEST_DIR
dir_path = ["Starshot"]
is_dir = False # whether the starshot is a single file (False) or directory of images to combine (True)
is_zip = False
wobble_diameter_mm = 0
wobble_center = Point()
num_rad_lines = 0
Expand Down Expand Up @@ -123,6 +139,8 @@ def construct_star(cls):
if cls.is_dir:
files = [osp.join(filename, file) for file in os.listdir(filename)]
star = Starshot.from_multiple_images(files, **cls.kwargs)
elif cls.is_zip:
star = Starshot.from_zip(filename, **cls.kwargs)
else:
star = Starshot(filename, **cls.kwargs)
return star
Expand Down Expand Up @@ -533,3 +551,11 @@ class MarkerDots(StarMixin, TestCase):
wobble_tolerance = 0.25
num_rad_lines = 3
passes = False


class SyntheticLowValues(StarMixin, TestCase):
file_name = "synthetic-low-values.zip"
is_zip = True
wobble_center = Point(593, 593)
wobble_diameter_mm = 0.2
num_rad_lines = 6

0 comments on commit b3e9a2b

Please sign in to comment.