 # How to calculate the passing rate from the matrix

Hi, i am currently using “pymedphys.gamma” to calculate the gamma index between 2 beams and i needed to obtain the gamma passing rate ( to see if it was over 95% ) from the returned matrix, how should i do it?
Right now i’m doing it like this:
`passing_rate = (GAMMAVOLUME<=1).sum() / (~np.isnan(GAMMAVOLUME)).sum()`

Hi @TableFan Welcome to the PyMedPhys community!  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: Hope that helps Yes, Thanks, i’m getting the same results both ways

Glad to hear it. Down the line, it would be handy if there was a standalone function for just that.