qurit / rt-utils

A minimal Python library to facilitate the creation and manipulation of DICOM RTStructs.
MIT License
191 stars 56 forks source link

'FileDataset' object has no attribute 'SeriesDate' #20

Closed pchlap closed 3 years ago

pchlap commented 3 years ago

Hi,

We have come across this error on a few datasets we are using. Including the LCTSC dataset from TCIA: http://doi.org/10.7937/K9/TCIA.2017.3r3fvz08

/usr/local/lib/python3.6/dist-packages/rt_utils/rtstruct_builder.py:22: in create_new
    ds = ds_helper.create_rtstruct_dataset(series_data)
/usr/local/lib/python3.6/dist-packages/rt_utils/ds_helper.py:15: in create_rtstruct_dataset
    add_study_and_series_information(ds, series_data)
/usr/local/lib/python3.6/dist-packages/rt_utils/ds_helper.py:68: in add_study_and_series_information
    ds.SeriesDate = reference_ds.SeriesDate

AttributeError: 'FileDataset' object has no attribute 'SeriesDate'

The problem is our DICOMs don't have the SeriesDate attribute. Is this something any one else has come across? Could we consider adjusting the code only copy over that attribute if it is available? I'd be happy to look at submitting a pull request if this is something you are interested in.

Thanks! Phil

awtkns commented 3 years ago

That would be awesome if you could PR this, we are always looking for new contributors to help make rt-utils a better community tool!

The implementation for it should be fairly simple and would essentially just entail changing the dates to provide a default value as we do for the StudyDescription, etc... (shown below)

def add_study_and_series_information(ds: FileDataset, series_data):
    reference_ds = series_data[0] # All elements in series should have the same data
    ds.StudyDate = reference_ds.StudyDate
    ds.SeriesDate = reference_ds.SeriesDate
    ds.StudyTime = reference_ds.StudyTime
    ds.SeriesTime = reference_ds.SeriesTime
    ds.StudyDescription = getattr(reference_ds, 'StudyDescription', '')
    ds.SeriesDescription = getattr(reference_ds, 'SeriesDescription', '')
    ds.StudyInstanceUID = reference_ds.StudyInstanceUID
    ds.SeriesInstanceUID = generate_uid()
    ds.StudyID = reference_ds.StudyID
    ds.SeriesNumber = "1"

This issue is similar to #19 @carluri