really simple question on pymedphys.gamma

113 views
Skip to first unread message

Charlie White

unread,
Nov 7, 2020, 4:46:43 PM11/7/20
to PyMedPhys
hi, i searched in the PyMedPhys documentation but i wasn't able ( mostly because i'm new to this field ) to understand how to set ' axes_reference ' and ' axes_evaluation'  inside 'pymedphys.gamma' to calculate the gamma index.
 my goal was to calculate the gamma index between 2 numpy array containing 2 beams,
both numpy arrays have a shape of (80,128,80)  and every element in the arrays rapresent a cube of side 4mm of the original image.
is ' (range(80), range(128), range(80)) ' a proper input for the two axes arguments?

right now im calling it like this:
 pymedphys.gamma(axes_reference=axe, dose_reference=x, axes_evaluation=axe, dose_evaluation=y, dose_percent_threshold=3,  distance_mm_threshold=10, lower_percent_dose_cutoff=20)

where x and y are the 2 beams and axe is equal to  ' (range(80), range(128), range(80)) '

Simon Biggs

unread,
Nov 7, 2020, 9:59:21 PM11/7/20
to Charlie White, PyMedPhys
Hi Charlie,

The following how-to guide in the docs provides an example comparing two numpy arrays with gamma:


An important point is that the axes coordinates should be an array of mm values representing each axis of the image. Given your images have a step size of 2 mm I'd expect that to be represented within your axes values.

In the provided example a the pixel size was 0.5 mm, the axes_reference and axes_evaluation was defined in the following way for that case:

grid = 0.5

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

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

coords = (y, x)

See the document linked above for more of the context of that code.

Hope that helps, let me know if you need any more guidance, and once you work out your issue, if you have an idea for how to improve the documentation for newcomers like yourself that'd be awesome.

Cheers,
Simon





Charlie White

unread,
Nov 8, 2020, 6:18:52 AM11/8/20
to PyMedPhys
Thanks a lot!
I actually had already seen that example but i was not able to figure out the pixel size of that image.
now this is what i am doing:

def calculate_gamma_index(beam1,beam2):
  grid = 4
  x_z_min = -160 # same for x and z
  x_z_max = 160 # same for x and z
  ymin = -256
  ymax = 256

  x_z = np.arange(x_z_min, x_z_max, grid) # same for x and z
  y = np.arange(ymin, ymax, grid)
  coords = (x_z, y, x_z)

  gamma_volume = pymedphys.gamma(axes_reference=coords, dose_reference=beam1, axes_evaluation=coords, 
                                 dose_evaluation=beam2, dose_percent_threshold=3, distance_mm_threshold=3,
                                 lower_percent_dose_cutoff=20, max_gamma=None)

  return gamma_volume



Where beam1 and beam2 are numpy arrays of shape (80, 128, 80) and voxel size of 4 mm.

Simon Biggs

unread,
Nov 8, 2020, 6:23:48 AM11/8/20
to Charlie White, PyMedPhys
Just a heads up that having your distance threshold smaller than your pixel width "works", but it isn't ideal.

The software will go and linearly interpolated between your grid down to 1/10th of the distance threshold. But that is a lot of linear interpolation. Possibly worth getting higher res data if that's plausible.

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymedphys+...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/pymedphys/d17784de-25da-4004-8d7b-06e50ca98259n%40googlegroups.com.

Charlie White

unread,
Nov 8, 2020, 7:12:54 AM11/8/20
to PyMedPhys
Thanks again for the advices, i changed it to 30

Simon Biggs

unread,
Nov 8, 2020, 2:48:22 PM11/8/20
to Charlie White, PyMedPhys
Out of interest, what's the use case? 

illuminami

unread,
Nov 9, 2020, 2:49:49 PM11/9/20
to Simon Biggs, PyMedPhys
for my thesis, i'm trying to use the gamma evaluation as a loss function in a neural network for the simulations of beams 

Simon Biggs

unread,
Nov 9, 2020, 3:03:46 PM11/9/20
to illuminami, PyMedPhys
Interesting, what's the reasoning for using gamma over something like a sum of squares difference?

--
You received this message because you are subscribed to the Google Groups "PyMedPhys" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymedphys+...@googlegroups.com.

illuminami

unread,
Nov 10, 2020, 7:59:56 AM11/10/20
to Simon Biggs, PyMedPhys
we want to see if the network is able to make better predictions with a different loss, square difference doesn't take account of the DTA 

Simon Biggs

unread,
Nov 10, 2020, 8:59:51 AM11/10/20
to illuminami, PyMedPhys
Kk, is there a GitHub repo where maybe I could take a look at what you're working on?
Reply all
Reply to author
Forward
0 new messages