dicompyler/dicompyler-core

dvhcalc.get_interpolated_dose raises IndexError if no dose for z

cutright opened this issue · 1 comments

When there is no dose plane, GetDoseGrid returns an empty array. So an IndexError is raised in dvhcalc.get_interpolated_dose when there is no dose plane:

d = dose.GetDoseGrid(z)
extent_dose = d[extents[1]:extents[3],
extents[0]:extents[2]] if len(extents) else d

There is a check for an empty dose plane, but it occurs after get_interpolated_dose is called.

for z, plane in iteritems(planes):
# Get the dose plane for the current structure plane
if interpolation_resolution or use_structure_extents:
doseplane = get_interpolated_dose(
dose, z, interpolation_resolution, dgindexextents)
else:
doseplane = dose.GetDoseGrid(z)
if doseplane.size:

I changed lines 490+ to the following:

    d = dose.GetDoseGrid(z)
    if not d.size:
        return d
    extent_dose = d[extents[1]:extents[3],
                        extents[0]:extents[2]] if len(extents) else d

But then calculate_contour_dvh ultimately fails here:

_, vol = calculate_plane_histogram(
plane, dose.GetDoseGrid(origin_z), dosegridpoints, maxdose,
dd, id, structure, hist)

ERROR: Unhandled exception: Traceback (most recent call last):
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\main.py", line 1808, in Run
    run_old(*args, **kwargs)
  File "C:\Users\dcutright\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\models\import_dicom.py", line 2178, in import_target
    StudyImporter(*parameters)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\models\import_dicom.py", line 1758, in __init__
    self.run()
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\models\import_dicom.py", line 1850, in run
    dvh_row = parsed_data.get_dvh_row(roi_key)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\dvha\db\dicom_parser.py", line 701, in get_dvh_row
    dvh_new = dvhcalc.get_dvh(**kwargs)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\venv-production\lib\site-packages\dicompylercore\dvhcalc.py", line 90, in get_dvh
    callback)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\venv-production\lib\site-packages\dicompylercore\dvhcalc.py", line 233, in _calculate_dvh
    dd, id, structure, hist)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\venv-production\lib\site-packages\dicompylercore\dvhcalc.py", line 270, in calculate_plane_histogram
    structure)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\venv-production\lib\site-packages\dicompylercore\dvhcalc.py", line 299, in calculate_contour_dvh
    mask = ma.array(doseplane * dd['dosegridscaling'] * 100, mask=~mask)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\venv-production\lib\site-packages\numpy\ma\core.py", line 6562, in array
    ndmin=ndmin, shrink=shrink, order=order)
  File "C:\Users\dcutright\PycharmProjects\DVH-Analytics\venv-production\lib\site-packages\numpy\ma\core.py", line 2909, in __new__
    raise MaskError(msg % (nd, nm))
numpy.ma.core.MaskError: Mask and data not compatible: data size is 23443, mask size is 1500352.