suever / pydicom-experimental

pydicom test
0 stars 1 forks source link

Key Error rasied when accessing unset MediaStorageSOPInstanceUID element (0x0002, 0x0003) #101

Closed suever closed 9 years ago

suever commented 9 years ago

From mkel...@gmail.com on March 17, 2011 16:43:30

Reproduction:

import dicom ds = dicom.read_file('00137DCM') ds.data_element('MediaStorageSOPInstanceUID')

ERROR: Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/dist-packages/pydicom-0.9.5-py2.6.egg/dicom/dataset.py", line 100, in data_element return self[tag] File "/usr/local/lib/python2.6/dist-packages/pydicom-0.9.5-py2.6.egg/dicom/dataset.py", line 244, in getitem data_elem = dict.getitem(self, tag) KeyError: (0002, 0003)

The file clearly contains this tag, so I'm not sure what to think. Also, if I set the element value:

import dicom ds = dicom.read_file('00137DCM') ds.MediaStorageSOPInstanceUID = '1234' ds.data_element('MediaStorageSOPInstanceUID')

Everything looks good:

(0002, 0003) Media Storage SOP Instance UID UI: 1234

except that the changes do not save back to a file when calling ds.save_as('filename.dcm')

Changes to ds.PatientID = 'SOMEID'

save just fine.

Any thoughts? Thanks.

Python 2.6.5 pydicom-0.9.5-py2.6.egg

Attachment: 00137DCM

Original issue: http://code.google.com/p/pydicom/issues/detail?id=101

suever commented 9 years ago

From darcymason@gmail.com on March 17, 2011 18:35:01

Back in 0.9.4 the file meta information was separated into its own dataset. You should be able to work with this data element using the file_meta object, in this case ds.file_meta.MediaStorageSOPInstanceUID.

suever commented 9 years ago

From mkel...@gmail.com on March 18, 2011 06:51:41

Thanks so much. That did the trick. I wonder though if I'm using an outdated version - 0.9.5? You eluded to a newer technique.

In any case, thanks for your help. It's all working wonderfully now.

Regards.

suever commented 9 years ago

From darcymason@gmail.com on December 15, 2011 17:50:30

Closing as was already solved, just not closed at the time.

Status: Invalid