dicompyler / dicompyler-core

A library of core radiation therapy modules for DICOM RT used by dicompyler
https://dicompyler-core.readthedocs.io
Other
147 stars 69 forks source link

Issues with float pixel spacing #317

Closed smichi23 closed 2 years ago

smichi23 commented 2 years ago

Hi all!

In my work, I had to create RTDOSE files to store Monte Carlo data. When creating my DICOMs, I had pixel spacings of 0.3710000000000002325/0.37109999999931. When I tried to calculate the DVHs with dicompyler-core, I got this error:

File "/dvh_from_dosegrid/venv/lib/python3.8/site-packages/dicompylercore/dvhcalc.py", line 88, in get_dvh calcdvh = _calculate_dvh(s, rtdose, limit, calculate_full_volume, File "/dvh_from_dosegrid/venv/lib/python3.8/site-packages/dicompylercore/dvhcalc.py", line 218, in _calculate_dvh planedata[z] = calculate_plane_histogram(plane, doseplane, File "/dvh_from_dosegrid/venv/lib/python3.8/site-packages/dicompylercore/dvhcalc.py", line 283, in calculate_plane_histogram hist, vol = calculate_contour_dvh(grid, doseplane, maxdose, dd, id, File "/dvh_from_dosegrid/venv/lib/python3.8/site-packages/dicompylercore/dvhcalc.py", line 316, in calculate_contour_dvh mask = ma.array(doseplane dd['dosegridscaling'] 100, mask=~mask) File "/dvh_from_dosegrid/venv/lib/python3.8/site-packages/numpy/ma/core.py", line 6610, in array return MaskedArray(data, mask=mask, dtype=dtype, copy=copy, File "/dvh_from_dosegrid/venv/lib/python3.8/site-packages/numpy/ma/core.py", line 2906, in new raise MaskError(msg % (nd, nm)) numpy.ma.core.MaskError: Mask and data not compatible: data size is 452188, mask size is 451242.

This error came from an int conversion of 477.9999999 to 477 in the intrapolated shapes. To solve that issue I simply rounded the lut new shapes.

Here is what I changed in file dvhcalc.py line 502 and 503:

col_samples = num_cols * min_pixel_spacing[1] / new_pixel_spacing[1]
row_samples = num_rows * min_pixel_spacing[0] / new_pixel_spacing[0]

to

col_samples = round(num_cols * min_pixel_spacing[1] / new_pixel_spacing[1])
row_samples = round(num_rows * min_pixel_spacing[0] / new_pixel_spacing[0])

Best,

Sam

bastula commented 2 years ago

Thanks Sam! Let me take a look and see if this needs to also be addressed anywhere else in the code and if it would affect normal usage.