suever / pydicom-experimental

pydicom test
0 stars 1 forks source link

exception thrown accessing dicom object after modifying PatientSetups[0].FixationDevices[2] #51

Closed suever closed 10 years ago

suever commented 10 years ago

From howard.b...@gmail.com on June 23, 2009 15:24:29

What steps will reproduce the problem? 1. f=dicom.ReadFile( 'Rt_Ion_Plan.dcm' )

  1. f.PatientSetups[0].FixationDevices[2] = '1234567-890' either of the following throw an exception at this point 3a. print str(f) 3b. dicom.WriteFile( 'CorruptedFileBecauseOfException.dcm', f )

Details: (1) Unzip attached tar file ModifyFixationDevicesBug.tar.bz2 into temp directory. (2) python ModifyingFixationDevicesCorruptsDataStructures.py What version of the product are you using? On what operating system? 0.9.2 (bug also occurs with 0.9.3) Please provide any additional information below. python import dicom f=dicom.ReadFile( 'RT_Ion_Plan_pt00000030.dcm' ) print str(f) <<>> (300a, 0180) Patient Setup Sequence 1 item(s) ---- (0018, 5100) Patient Position CS: 'HFS' (300a, 0182) Patient Setup Number IS: '1' (300a, 0190) Fixation Device Sequence 5 item(s) ---- (300a, 00f9) Accessory Code LO: '1008756-001' (300a, 0192) Fixation Device Type CS: 'WHOLE_BODY_POD' (300a, 0194) Fixation Device Label SH: 'MPSS_SHORT_EXT' (300a, 0196) Fixation Device Description ST: 'Table Extension, Short Head Pod'

  (300a, 00f9) Accessory Code                      LO: 'N00000030SP'
  (300a, 0192) Fixation Device Type                CS: 'MOLD'
  (300a, 0194) Fixation Device Label               SH: 'MPSS_SP_LINER'
  (300a, 0196) Fixation Device Description         ST: 'Table Liner,

Short Head Pod'

  (300a, 00f9) Accessory Code                      LO: '???'
  (300a, 0192) Fixation Device Type                CS: 'MOLD'
  (300a, 0194) Fixation Device Label               SH: 'MPSS_TRI_SUPP_M'
  (300a, 0196) Fixation Device Description         ST: 'Triangle

Pillow, Medium'

  (300a, 00f9) Accessory Code                      LO: '???'
  (300a, 0192) Fixation Device Type                CS: 'BITEBLOCK'
  (300a, 0194) Fixation Device Label               SH: 'MOUTHPIECE'
  (300a, 0196) Fixation Device Description         ST: 'Biteblock

mouthpiece'

  (300a, 00f9) Accessory Code                      LO: '1003010-002'
  (300a, 0192) Fixation Device Type                CS: 'HEADFRAME'
  (300a, 0194) Fixation Device Label               SH: 'MPSS_Z_BOX'
  (300a, 0196) Fixation Device Description         ST: 'Z-Box'
  ---------

<<>>

f.PatientSetups[0].FixationDevices[2] = '1234567-890' ###### CORRUPTS FILE

dicom.WriteFile( 'Corrupted_TR_Ion_Plan_pt00000030.dcm', f )

Traceback (most recent call last): File "ModifyingFixationDevicesCorruptsDataStructures.py", line 48, in

dicom.WriteFile( strFilename, f ) # exception thrown here File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 289, in WriteFile WriteDataset(fp, no_group2_dataset) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 144, in WriteDataset WriteDataElement(fp, dataset[tag]) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 116, in WriteDataElement writers[VR](fp, data_element) # call the function to write that kind of item File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 154, in WriteSequence WriteSequenceItem(fp, dataset) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 163, in WriteSequenceItem WriteDataset(fp, dataset) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 144, in WriteDataset WriteDataElement(fp, dataset[tag]) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 116, in WriteDataElement writers[VR](fp, data_element) # call the function to write that kind of item File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 154, in WriteSequence WriteSequenceItem(fp, dataset) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 163, in WriteSequenceItem WriteDataset(fp, dataset) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/filewriter.py", line 141, in WriteDataset tags = dataset.keys() AttributeError: 'str' object has no attribute 'keys' # print str(f) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/dataset.py", line 393, in **str** return self._PrettyStr() File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/dataset.py", line 334, in _PrettyStr strings.append(dataset._PrettyStr(indent+1)) File "/usr/local/lib/python2.5/site-packages/pydicom-0.9.2-py2.5.egg/dicom/dataset.py", line 334, in _PrettyStr strings.append(dataset._PrettyStr(indent+1)) AttributeError: 'str' object has no attribute '_PrettyStr' _Original issue: http://code.google.com/p/pydicom/issues/detail?id=51_
suever commented 10 years ago

From darcymason@gmail.com on June 23, 2009 15:29:33

This looks like a question of setting the wrong object type -- an item in a Sequence needs to be a Dataset instance. Probably what is needed here is: f.PatientSetups[0].FixationDevices[2].AccessoryCode = '1234567-890'

However, the code should test that an item assignment is in fact a Dataset. I'll create that as an issue for the issue list.

Status: Fixed

suever commented 10 years ago

From howard.b...@gmail.com on June 23, 2009 20:53:49

Thank you! --Bryan