ct_philips.py extractor fails for Philips Brilliance 16P CT scanner

Issue #500 resolved
David Platten created an issue

For the only example I have from this type of scanner the extractor fails because the Acquisition DateTime is blank for each acquisition in the dose summary object.

Comments (10)

  1. David Platten reporter

    I have fixed this on my local system by altering get_date_time in the dcmdatetime.py file. This routine currently fails if the contents of the tag are blank. A tweak is also required in _ctradiationdose within the ct_philips.py file.

    Altering get_date_time to the following fixes the first problem:

    def get_date_time(tag,dataset):
        """Get DICOM date time string and return Python date time.
        :param tag:         DICOM keyword, no spaces or plural as per dictionary.
        :type tag:          str.
        :param dataset:     The DICOM dataset containing the tag.
        :type dataset:      dataset
        :returns:           Python date time value
        import datetime
        if (tag in dataset):
            dicomdatetime = getattr(dataset,tag)
            if '+' in dicomdatetime or '-' in dicomdatetime:
                import re
                dicomdatetime = re.split('\+|-',dicomdatetime)[0]
            if '.' in dicomdatetime:
                return datetime.datetime.strptime(dicomdatetime, "%Y%m%d%H%M%S.%f")
                return datetime.datetime.strptime(dicomdatetime, "%Y%m%d%H%M%S")
            except ValueError:

    _ctradiationdose needs to have a try put around the microsecond calculation code:

            # Come back and set start and end of irradiation after creating the x-ray events
            proj.start_of_xray_irradiation = events.aggregate(Min('date_time_started'))['date_time_started__min']
                latestlength = int(events.latest('date_time_started').exposure_time * 1000) # in microseconds
                lastevent = events.aggregate(Max('date_time_started'))['date_time_started__max']
                if lastevent and latestlength:
                    last = lastevent + timedelta(microseconds=latestlength)
                    proj.end_of_xray_irradiation = last
            except TypeError:
  2. David Platten reporter

    Is it a good idea to configure get_date_time to return nothing if it encounters a ValueError? Would it be better to try and catch the error in the calling routine? Any thoughts @edmcdonagh?

  3. Ed McDonagh

    I think returning nothing probably is the best way to do it. It is consistent with the other get functions.

    We'd need to make the same change for the other date_time functions.

  4. David Platten reporter

    The two commits solve this problem - the Philips Brilliance 16P study with empty Acquisition DateTime imports without a problem. I can also confirm that studies from the Philips Brilliance 64 continue to import correctly.

  5. Log in to comment