Tag (0029, 1140) not found in DICOM dictionary; also question about pixeldata

1,011 views
Skip to first unread message

cooper1234

unread,
Jan 26, 2011, 6:09:24 PM1/26/11
to pydicom
Hello,

I have a dicom file that is giving me trouble. When I try to read it,
I get the following exception:
KeyError: 'Tag (0029, 1140) not found in DICOM dictionary'

I've looked around, and I can't determine what this metadata tag field
is. Any idea? How can I get around this?

Also, what is the best way to determine whether a dicom file has an
image? Is it via checking whether the PixelData dataelement exists?
For this same file, the DICOM file has a viewable image, but it does
not have a pixeldata field.

Thanks!!!

Coop

Julien Lamy

unread,
Jan 27, 2011, 3:28:29 AM1/27/11
to pyd...@googlegroups.com
Le 27/01/2011 00:09, cooper1234 a �crit :

> Hello,
>
> I have a dicom file that is giving me trouble. When I try to read it,
> I get the following exception:
> KeyError: 'Tag (0029, 1140) not found in DICOM dictionary'
>
> I've looked around, and I can't determine what this metadata tag field
> is. Any idea? How can I get around this?

Since the group number (0029) of the tag is odd, the element is private
and thus can mean different things to different vendors. Have a look at
_private_dict.py, and search for 0029xx40 since (as far as I can tell)
the first byte of the element number is irrelevant to the semantic of a
private tag.

To get around this, post a bit of code so that we can know what's going
wrong :) In my experience, private tags have been processed correctly by
pydicom.

> Also, what is the best way to determine whether a dicom file has an
> image? Is it via checking whether the PixelData dataelement exists?
> For this same file, the DICOM file has a viewable image, but it does
> not have a pixeldata field.

I'd use the SOP Class UID (0008,0016) (cf. PS 3.4, section B.5 for the
standard classes) : basically, anything ending with "Image Storage"
should contain an image.

--
Julien

cooper1234

unread,
Jan 27, 2011, 12:48:21 PM1/27/11
to pydicom
Thanks Julien. I agree, that it's probably a private tag. Looking at
_private_dict.py, I see: {'1.2.840.113663.1': {'0029xx00': ('US', '1',
'Unknown', ''),
'0029xx01': ('US', '1', 'Unknown', '')},

How do I go about adding 0029,1140 to __private_dict.py? The
following didn't work:
{'1.2.840.113663.1': {'0029xx00': ('US', '1', 'Unknown', ''),
'0029xx01': ('US', '1', 'Unknown', ''),
'0029xx40': ('US', '1', 'Unknown', '')},

The code is very simple:
if __name__ == "__main__":
arg1 = sys.argv[1]
print arg1
dicomObj = None
try:
dicomObj = dicom.read_file(arg1)
except:
print traceback.format_exc()
pass
print dicomObj


The trackeback is:
Traceback (most recent call last):
File "dump.py", line 13, in <module>
dicomObj = dicom.read_file(arg1)
File "C:\dev\Python25\lib\site-packages\dicom\filereader.py", line
472, in read_file
dataset = read_partial(fp, stop_when, defer_size=defer_size,
force=force)
File "C:\dev\Python25\lib\site-packages\dicom\filereader.py", line
433, in read_partial
stop_when=stop_when, defer_size=defer_size)
File "C:\dev\Python25\lib\site-packages\dicom\filereader.py", line
272, in read_dataset
raw_data_element = de_gen.next()
File "C:\dev\Python25\lib\site-packages\dicom\filereader.py", line
243, in data_element_generator
VR = dictionaryVR(tag)
File "C:\dev\Python25\lib\site-packages\dicom\datadict.py", line 67,
in dictionaryVR
return get_entry(tag)[0]
File "C:\dev\Python25\lib\site-packages\dicom\datadict.py", line 55,
in get_entry
raise KeyError, "Tag %s not found in DICOM dictionary" % Tag(tag)
KeyError: 'Tag (0029, 1140) not found in DICOM dictionary'


Thanks!!!

Darcy Mason

unread,
Jan 27, 2011, 10:43:10 PM1/27/11
to pydicom
On Jan 27, 12:48 pm, cooper1234 <anish...@gmail.com> wrote:
...
>
> The trackeback is:
> Traceback (most recent call last):
>...
> KeyError: 'Tag (0029, 1140) not found in DICOM dictionary'

This sounds very similar to issue 91 [1]. In that case, it was an
implicit VR file and it appeared that the private data element was a
sequence. Could it be something like that here? Do you have a test
file that can be posted publicly?

[1] http://code.google.com/p/pydicom/issues/detail?id=91
Message has been deleted

Edoardo Pasca

unread,
Jan 28, 2011, 3:42:25 AM1/28/11
to pyd...@googlegroups.com
On Thu, Jan 27, 2011 at 6:48 PM, cooper1234 <anis...@gmail.com> wrote:
>
> How do I go about adding 0029,1140 to __private_dict.py?

First you need to know what type your parameter is (sequence, floating
point and so forth and then:

I use the following (correct to add the proper line with your parameter) :

from dicom.datadict import DicomDictionary, NameDict, CleanName
import dicom

new_dict_items = {
0x2005140f: ('SQ', '1', "Test FourthyTwo 0 Sequence" ),
0x20051330: ('CS', '1', "Why would you save this?" ),
0x20051402: ('SQ', '1', "Test FourthyTwo 12 Sequence" ),
0x20051418: ('CS', '1', "Some MR parameter" ),
0x20051419: ('CS', '1', "Some other MR parameter" ),
0x2005143a: ('CS', '1', "Yet some other MR parameter" ),
0x2001105f: ('SQ', '1', "Stack Sequence"),
0x2005100d: ('FL', '1', "Scale Intercept"),
0x2005100e: ('FL', '1', "Scale Slope"),
0x00281052: ('FL', '1', "Rescale Intercept"),
0x00281053: ('FL', '1', "Rescale Slope"),
0x20051008: ('FL', '1', "Image OffCenter AP mm"),
0x20051009: ('FL', '1', "Image OffCenter FH mm"),
0x2005100a: ('FL', '1', "Image OffCenter RL mm"),
0x2005101d: ('US', '1', "Who knows"),
}
DicomDictionary.update(new_dict_items)

new_names_dict = dict([(CleanName(tag), tag) for tag in new_dict_items])
NameDict.update(new_names_dict)

--
Edo
weblog  http://edo.imanetti.net/wordpress
podcast http://sieegiueeaccaso.blogspot.com
cooking http://edo.imanetti.net/cucina
:wq

cooper1234

unread,
Jan 31, 2011, 7:35:49 PM1/31/11
to pydicom
Unfortunately, I can't share a sample DICOM file with the problem.
But, this partially sounds like issue 91, so I followed the suggestion
in issue #91 and made the following change to datadict.py.
return ('NONE', '1', "Unknown Item : "+str(tag), '')

This works fine, and I'm able to read the file!

Next, I need to modify dicom tags to remove patient info. The problem
is that the following does not work:
dataset.save_as(dicomFile)

I get the following exception:
File "C:\dev\Python25\lib\site-packages\dicom\dataset.py", line 455,
in save_as
dicom.write_file(filename, self, WriteLikeOriginal)
File "C:\dev\Python25\lib\site-packages\dicom\filewriter.py", line
282, in write_file
write_dataset(fp, dataset)
File "C:\dev\Python25\lib\site-packages\dicom\filewriter.py", line
138, in write_dataset
write_data_element(fp, dataset[tag])
File "C:\dev\Python25\lib\site-packages\dicom\dataset.py", line 254,
in __getitem__
self[tag] = DataElement_from_raw(data_elem)
File "C:\dev\Python25\lib\site-packages\dicom\dataelem.py", line
324, in DataElement_from_raw
raise NotImplementedError, "%s in tag %r" % (str(e), raw.tag)
NotImplementedError: Unknown Value Representation 'NONE' in tag (0009,
0010)

Any ideas? Obviously, there are some issues with how pydicom handles
this dicom file. (note: I am able to view this DICOM file in multiple
viewers)

Thanks!

Coop

On Jan 28, 12:42 am, Edoardo Pasca <edo.pask...@gmail.com> wrote:

Edoardo Pasca

unread,
Feb 1, 2011, 2:20:35 AM2/1/11
to pyd...@googlegroups.com
Why do you set the type to NONE? Can you not simply empty or anonimize
the content keeping their type?

Edo

> --
> You received this message because you are subscribed to the Google Groups "pydicom" group.
> To post to this group, send email to pyd...@googlegroups.com.
> To unsubscribe from this group, send email to pydicom+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pydicom?hl=en.
>
>

Darcy Mason

unread,
Feb 2, 2011, 7:45:17 PM2/2/11
to pydicom
On Jan 31, 7:35 pm, cooper1234 <anish...@gmail.com> wrote:
> ...I followed the suggestion
> in issue #91 and made the following change to datadict.py.
> return ('NONE', '1', "Unknown Item : "+str(tag), '')
>
> This works fine, and I'm able to read the file!
>
> Next, I need to modify dicom tags to remove patient info.  The problem
> is that the following does not work:
> dataset.save_as(dicomFile)
> ...
> raise NotImplementedError, "%s in tag %r" % (str(e), raw.tag)
> NotImplementedError: Unknown Value Representation 'NONE' in tag (0009,
> 0010)
>
> Any ideas?  Obviously, there are some issues with how pydicom handles
> this dicom file.  (note: I am able to view this DICOM file in multiple
> viewers)
>

Later in the responses in issue 91, I tried 'SQ' for the type and that
worked on the file that prompted the issue to be entered. Could you
try 'SQ' instead of 'NONE'? If that doesn't work, I expect that 'OB'
would probably be the safest type to try -- with OB, pydicom should
simply just write the bytes without any kind of manipulation.

These are just workarounds for now until the root logic can be sorted
out for pydicom to properly handle these unusual private data
elements.

-Darcy

Reply all
Reply to author
Forward
0 new messages