def test_multiple_threshold_inputs(): coords, reference, evaluation, _ = get_dummy_gamma_set() gamma_shell( coords, reference, coords, evaluation, [3], [0.3, 0.5], lower_percent_dose_cutoff=0)
def run_gamma(filepath_ref, filepath_eval, random_subset=None, max_gamma=1.1, dose_threshold=1, distance_threshold=1): if random_subset is not None: np.random.seed(42) dcm_ref = pydicom.read_file(filepath_ref) dcm_eval = pydicom.read_file(filepath_eval) coords_reference = load_yx_from_dicom(dcm_ref) dose_reference = load_dose_from_dicom(dcm_ref) coords_evaluation = load_yx_from_dicom(dcm_eval) dose_evaluation = load_dose_from_dicom(dcm_eval) gamma = gamma_shell( coords_reference, dose_reference, coords_evaluation, dose_evaluation, dose_threshold, distance_threshold, lower_percent_dose_cutoff=20, interp_fraction=10, max_gamma=max_gamma, local_gamma=True, skip_once_passed=True, random_subset=random_subset) return gamma
def does_gamma_scale_as_expected(init_distance_threshold, threshold_ratio, scales_to_test): coords, reference, evaluation, _ = get_dummy_gamma_set() all_scales = np.concatenate([[1], scales_to_test]) distance_thresholds_to_test = init_distance_threshold * all_scales dose_thresholds_to_test = distance_thresholds_to_test * threshold_ratio gamma_results = [] for dose, distance in zip(dose_thresholds_to_test, distance_thresholds_to_test): gamma_results.append( gamma_shell(coords, reference, coords, evaluation, dose, distance, lower_percent_dose_cutoff=0)) for i, scale in enumerate(scales_to_test): print(scale) abs_diff = np.abs(gamma_results[i + 1] - gamma_results[0] / scale) ref = np.where(abs_diff == np.max(abs_diff)) print(np.max(abs_diff)) # print(gamma_results[0][ref]) # print(gamma_results[i+1][ref]) assert np.all(abs_diff <= 0.1)
def test_regression_of_gamma_2d(): """Test for changes in expected 2D gamma.""" coords, reference, evaluation, expected_gamma = get_dummy_gamma_set() gamma2d = np.round(gamma_shell( coords[1::], reference[5, :, :], coords[1::], evaluation[5, :, :], 3, 0.3, lower_percent_dose_cutoff=0), decimals=1) assert np.all(expected_gamma[5, :, :] == gamma2d)
def test_regression_of_gamma_3d(): """Test for changes in expected 3D gamma.""" coords, reference, evaluation, expected_gamma = get_dummy_gamma_set() gamma3d = np.round(gamma_shell( coords, reference, coords, evaluation, 3, 0.3, lower_percent_dose_cutoff=0), decimals=1) assert np.all(expected_gamma == gamma3d)
def test_lower_dose_threshold(): """Verify that the lower dose threshold works as expected""" ref = [0, 1, 1.9, 2, 2.1, 3, 4, 5, 10, 10] coords_ref = (np.arange(len(ref)),) evl = [10] * (len(ref) + 2) coords_evl = (np.arange(len(evl)) - 4,) result = gamma_shell(coords_ref, ref, coords_evl, evl, 10, 1) assert np.array_equal(ref < 0.2 * np.max(ref), np.isnan(result))