A library for calculating the gamma index? (Preferably in R or Python, but any language is fine)

In physics - especially in medical physics - the gamma index is a criterion for comparing data from two particle detectors. More abstractly, the gamma index takes two 2D arrays (say, array1 and array2) and compares each element of array1 with spatially close elements of array2.

There are hundreds of scientific articles that use the gamma index in their analysis sections. These documents do not mention which tools / libraries they use to calculate the gamma index. Perhaps the authors implement their own calculations of the gamma index (this is not so difficult). However, I assume that there are libraries / extensions / tools for calculating the gamma index.

Can anyone suggest a gamma index library for use in R or Python? (Other languages ​​would be fine if there was nothing for Python or R.)

+4
source share
3 answers

I found the basic MATLAB implementation of a two-dimensional gamma index in Appendix A this thesis .

I copy / paste the following code from the thesis and I made a couple of simplifications for readability. I spoke with the author and confirmed that my version of the code (below) is correct. Recently, I used this code in the analytic part of a study of medical physics, which I will publish soon.

Inputs A1 and A2 are two-dimensional arrays (which in practice are dose maps or fluence maps). We will use A1 as reference data and A2 as data that is being evaluated. If we use the typical acceptance criterion of 2%, 2 mm, then we set the distance to agreement as DTA=2mm , and we set the dose threshold dosed=0.02 , which is 2%.

In this simple implementation, we assume that the array indices are spaced 1 mm apart. If your data does not use 1 mm increments, then change the dosed value dosed (for example, if your A1 and A2 in 0.5 mm increments, use DTA=4 to get a 2 mm criterion).

The output, G , is a 2D array of gamma values.

 function G = gamma2d (A1, A2, DTA, dosed) size1=size (A1) ; size2=size (A2) ; dosed = dosed * max(A1 ( : ) ) ; %scale dosed as a percent of the maximum dose G=zeros ( size1 ) ; %this will be the output Ga=zeros ( size1 ) ; if size1 == size2 for i = 1 : size1( 1 ) for j = 1 : size1( 2 ) for k = 1 : size1( 1 ) for l = 1 : size1( 2 ) r2 = ( i - k )^2 + (j - l) ^2 ; %distance (radius) squared d2 = ( A1( i , j ) - A2( k , l ) )^2 ; %difference squared Ga( k , l ) = sqrt(r2 / (DTA^2) + d2/ dosed ^ 2); end end G( i , j )=min(min(Ga)) ; end end else fprintf=('matrices A1 and A2 are do not share the same dimensions! \n') end end 

To see the explanation of the gamma index in mathematical notation, I recommend watching this blog post .

0
source

Maybe a little late, but my contribution:

https://gist.github.com/janpipek/334c2533b87cd75c3f59

It is written in Python. Compared to solvePuzzles, methods accept matrices of any dimension (provided that they are the same). There are two methods: one that calculates the gamma index for each point (a bit long) and an optimized version that automatically excludes points that do not meet the dta criterion.

Hope this can help some latecomers.

+4
source

There is an npgamma library. It can be downloaded from pypi using pip install npgamma .

See readme examples.

Main use:

 from npgamma import calc_gamma ... gamma = calc_gamma( coords_reference, dose_reference, coords_evaluation, dose_evaluation, distance_threshold, dose_threshold) 

Where coords_reference and coords_evalution defined as (y, x, z) for 3D, (y, x) for 2D.

It is important to note that this method interpolates between GCPs to a user-defined step size (by default, 1/10 of the distance threshold).

0
source

All Articles