A question about gamma evaluation - log_analyzer

Hi again, James!

I have a question about the way pylinac calculates pass_prcnt. My problem is that I am getting worse results for the gamma passing rate than I am used to (although this is only a feeling).

I was looking at the pylinac\log_analyzer.py and core\image.py code where functions calc_map() and gamma() are defined. If I understand correctly, pylinac calculates an array of gamma-like distribution with np.nan values where evalution was not performed. Then this array is passed to log_analyzer function calc_map(). There the gamma average and passing percentage are calculated.

What confuses me is line 1140 in log_analyzer, where pylinac converts np.nan back to 0, but it does that before it calculates the pass_prcnt. The average gamma is calculated by averaging over all elements of gamma except nans. But pass_prcnt calculation excludes all zeros, either those that correspond to pixels with dose lower than the treshold and were not considered when calculating gamma (which is ok) or those that did in fact calculate to such a value, but now do not add to the sum of evaluated pixels (perhaps not ok).

I got a bit better results for pass_prcnt by including calculated zeros in the count like this (please excuse my bad python):

pass_prcnt = 100 * np.nansum(gamma_map < 1) / np.nansum (gamma_map >=0 )

Here gamma_map still contains nans.

What do you think?


Sorry, I meant something more like this:

100 * np.sum(gamma_map[~np.isnan(gamma_map)] < 1) / np.sum(gamma_map[~np.isnan(gamma_map)]>=0)

Good catch. Those lines of code didn’t used to be so complicated. I originally rewrote them because of runtime errors dealing with those nans, but your solution is much cleaner. I’ve logged the issue and will be included in the 1.7 release. Thanks for the suggestion.