Skip to content

Commit

Permalink
Merged in feature/RAM-4172-gamma-x-domain-restrictions (pull request #…
Browse files Browse the repository at this point in the history
…478)

RAM-4172 don't enforce gamma x-domain restrictions.

Approved-by: Randy Taylor
  • Loading branch information
jrkerns committed Nov 14, 2024
2 parents fbdbce5 + 71fb8b2 commit 2bbd84b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
4 changes: 4 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Gamma
were not in ascending order. Coordinates can now be in any order.
* :bdg-warning:`Fixed` The geometric gamma function now validates that the x-coordinates are monotonically increasing or decreasing and
will error out if not.
* :bdg-warning:`Fixed` The geometric gamma previously enforced that the reference x-domain contained the entire
evaluation x-domain. I.e. your reference scan had to be larger than your evaluation scan. This is no longer the case.
An evaluation profile will be calculated at all points above the threshold. If the reference scan is too small, the gamma
value will be large.

Core
^^^^
Expand Down
2 changes: 1 addition & 1 deletion pylinac/core/array_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def fill_middle_zeros(array: np.ndarray, cutoff_px: int = 0) -> np.ndarray:
return filled_arr


def _rt_image_position(array: np.ndarray, dpmm: float) -> list[float, float]:
def _rt_image_position(array: np.ndarray, dpmm: float) -> list[float]:
"""Calculate the RT Image Position of the array."""
rows, cols = array.shape
pixel_size_mm = 1.0 / dpmm
Expand Down
9 changes: 0 additions & 9 deletions pylinac/core/gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,6 @@ def gamma_geometric(
raise ValueError(
f"Evaluation and evaluation_x_values must be the same length. Got evaluation: {len(evaluation)} and evaluation_x_values: {len(evaluation_coordinates)}"
)
# we add some padding on the check because resampling SingleProfiles
# can add ~1/2 pixel on each side to retain the same physical size
# when upsampling.
if min(reference_coordinates) - 1 > min(evaluation_coordinates) or max(
reference_coordinates
) + 1 < max(evaluation_coordinates):
raise ValueError(
"The evaluation x-values must be within the range of the reference x-values"
)
# normalize the dose threshold by the DTA
threshold = float(dose_threshold) / float(dose_to_agreement)
# convert dose to normalized distance of dose to agreement. I.e. D/delta(D) in Figure 1.
Expand Down
39 changes: 19 additions & 20 deletions tests_basic/core/test_gamma.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,26 +292,6 @@ def test_eval_x_values_not_same_length_as_eval(self):
reference=ref, evaluation=eval, evaluation_coordinates=np.arange(6)
)

def test_min_eval_x_lower_than_min_ref_x(self):
ref = eval = np.ones(5)
with self.assertRaises(ValueError):
gamma_geometric(
reference=ref,
evaluation=eval,
evaluation_coordinates=(np.arange(5) - 2),
reference_coordinates=np.arange(5),
)

def test_max_eval_x_higher_than_max_ref_x(self):
ref = eval = np.ones(5)
with self.assertRaises(ValueError):
gamma_geometric(
reference=ref,
evaluation=eval,
evaluation_coordinates=(np.arange(5) + 2),
reference_coordinates=np.arange(5),
)

def test_same_profile_is_0_gamma(self):
ref = eval = np.ones(5)
gamma = gamma_geometric(reference=ref, evaluation=eval)
Expand Down Expand Up @@ -504,6 +484,25 @@ def test_very_far_spacings(self):
)
self.assertEqual(np.nanmax(g), 0)

def test_reference_x_domain_smaller_than_eval(self):
"""Even if the reference x-domain is too small we can still
evaluate the gamma."""
vals = [0, 0, 0, 0, 1, 2, 5, 8, 10, 10, 10, 10, 10, 8, 5, 2, 1, 0, 0, 0, 0]
x_vals = np.arange(len(vals))
ref_vals = vals[3:-3] # we short-change the reference in low-dose areas
x_ref_vals = x_vals[3:-3]
gamma = gamma_geometric(
reference=np.array(ref_vals),
reference_coordinates=np.array(x_ref_vals),
evaluation=np.array(vals),
evaluation_coordinates=np.array(x_vals),
distance_to_agreement=1,
gamma_cap_value=2,
dose_threshold=0, # 0 threshold is important to ensure we calculate the gamma at the edges
)
self.assertEqual(np.nanmax(gamma), 2)
self.assertAlmostEqual(np.nanmean(gamma), 0.476, places=2)

@parameterized.expand(
[
(np.arange(5), np.arange(5), [np.nan, 0, 0, 0, 0]),
Expand Down

0 comments on commit 2bbd84b

Please sign in to comment.