How to lookup a parent sequence of a tag?

138 views
Skip to first unread message

Dan Cutright

unread,
Mar 28, 2020, 10:54:30 AM3/28/20
to pydicom
Hi everyone,

Is there an easy/pythonic way to find if a tag is part of a sequence, and also the tag of that sequence?

I'm using pydicom.datadict to get keywords and tags to build a search tool. I could do a brute force search for parent sequences, but I wonder if there's a more eloquent, faster solution? Does pydicom already store this information? Or maybe it's inherent in the tag number design?

Thanks!

Dan


Screen Shot 2020-03-28 at 9.45.46 AM.png

Darcy Mason

unread,
Mar 28, 2020, 11:47:17 AM3/28/20
to pydicom
There isn't usually direct information about parents, because a given data element can be assigned to different datasets,  just like in python, a string "Hello" could be assigned to two different variables, or two different lists.

Having said that, because we had to track character encodings because the overall dataset encoding applies to the nested elements if they don't have their own, there is some information:

Sequence's have a `parent` attribute that point to the dataset the sequence is part of.  Sequence items (datasets) also have a `parent` property pointing to the same parent dataset.  But the individual data elements within the dataset do not.

You can also check if a sequence item is in a sequence per the usual python check of an item in a list:

if seq_item in seq:
   ...

Not quite the direct checks you were looking for, but you could certainly build the information you want by using dataset.walk() to walk the tree once and keep track of the relationships.

Hope that helps,
Darcy

Dan Cutright

unread,
Mar 28, 2020, 12:09:44 PM3/28/20
to pydicom
Thanks Darcy, that does help... and thank you for the quick reply!
Reply all
Reply to author
Forward
0 new messages