searching dcm files

266 views
Skip to first unread message

Jay

unread,
Apr 25, 2011, 8:53:17 PM4/25/11
to Python in Medical Physics
Hi,

I'm starting a project that will involve manipulating large dicom
files. The files are exported fluence maps from the TPS. I'm using
Python 2.7 and pydicom to read the file.

The following commands work for reading the dcm

>>> import dicom
>>> ds=dicom.read_file("test.dcm")

The first step is to search the file's 7943 lines for certain tags
like "Leaf Sequence"

i tried this command with no success

>>> import string
>>> string.find(ds,'Leaf Sequence')

The error message was

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
string.find(ds,'Leaf Sequence')
File "C:\Python27\lib\string.py", line 361, in find
return s.find(*args)
File "C:\Python27\lib\site-packages\dicom\dataset.py", line 234, in
__getattr__
raise AttributeError, "Dataset does not have attribute '%s'." %
name
AttributeError: Dataset does not have attribute 'find'.

Does anyone have an alternative solution?

Thanks,
Jay

Mark Roden

unread,
Apr 25, 2011, 8:56:12 PM4/25/11
to python-...@googlegroups.com
Have you tried gdcm wrapped in python? I don't think it's part of the
standard python distribution, but I believe that it'll have this
functionality.

http://sourceforge.net/apps/mediawiki/gdcm/index.php?title=Main_Page

> --
> Python in Medical Physics resources can be found at:
> https://sites.google.com/site/pythonmedphys/
>

D. M. Tishler

unread,
Oct 12, 2011, 8:40:48 PM10/12/11
to python-...@googlegroups.com
#Search dicom header for key using has_key()

import dicom

ds = dicom.read_file("test.dcm")

key = "Leaf Sequence" 
if ds.has_key(key):
        print key

Jay

unread,
Nov 28, 2012, 5:14:43 PM11/28/12
to python-...@googlegroups.com, lstr...@gmail.com
I used "data_element.tag" to search. For example, the tag for a fluence map in an RT plan is 0x300a00c2, so I used 
 
def test_val(ds, data_element):

        if data_element.tag == 0x300a00c2 and data_element.value == beamNAME:

to search the dataset

Jay
Reply all
Reply to author
Forward
0 new messages