Kiyokawa / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 0 forks source link

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

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Reproduction:

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

ERROR:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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

Original issue reported on code.google.com by mkel...@gmail.com on 17 Mar 2011 at 8:43

Attachments:

GoogleCodeExporter commented 8 years ago
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.

Original comment by darcymason@gmail.com on 18 Mar 2011 at 1:35

GoogleCodeExporter commented 8 years ago
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.

Original comment by mkel...@gmail.com on 18 Mar 2011 at 1:51

GoogleCodeExporter commented 8 years ago
Closing as was already solved, just not closed at the time.

Original comment by darcymason@gmail.com on 16 Dec 2011 at 1:50