How to calculate the passing rate from the matrix

Hi @TableFan :slightly_smiling_face:

Welcome to the PyMedPhys community! :balloon: :rocket:

Check out the following how-to guide:

In particular, extracting some key parts out of that link above gives the following code below:

import numpy as np
import matplotlib.pyplot as plt

import pymedphys

xmin = -28
xmax = 28
ymin = -25
ymax = 25
grid = 0.5

x = np.arange(xmin, xmax + grid, grid)
y = np.arange(ymin, ymax + grid, grid)

coords = (y, x)

xx, yy = np.meshgrid(x, y)
dose_ref = np.exp(-((xx/15)**20 + (yy/15)**20))

scale_factor = 1.035
dose_eval = dose_ref * scale_factor

gamma_options = {
    'dose_percent_threshold': 3,
    'distance_mm_threshold': 3,
    'lower_percent_dose_cutoff': 20,
    'interp_fraction': 10,  # Should be 10 or more for more accurate results
    'max_gamma': 2,
    'random_subset': None,
    'local_gamma': True,
    'ram_available': 2**29,  # 1/2 GB
    'quiet': True
}

gamma = pymedphys.gamma(
    coords, dose_ref,
    coords, dose_eval,
    **gamma_options)
valid_gamma = gamma[~np.isnan(gamma)]

# ---------------------------------------------------------------------
# Passing rate determined here
# ---------------------------------------------------------------------

passing = 100 * np.sum(valid_gamma <= 1) / len(valid_gamma)

# ---------------------------------------------------------------------

plt.figure()
plt.title(f'Gamma Histogram | Passing rate = {passing:.2f}%')
plt.xlabel('Gamma')
plt.ylabel('Number of pixels')

plt.hist(valid_gamma, 20)
plt.show()

Which produces:

image

Hope that helps :slight_smile: