I can not seem to open files that are sent from Elekta's IView, and was wondering if anyone can help.
just running:
ds=dicom.read_file('Iview.dcm',force=True)
gives me:
Traceback (most recent call last):
File "C:\Users\jdonaghue\Documents\Python\DICOM Stuff\src\QuickViewer.py", line 12, in <module>
ds=dicom.read_file('Iview.dcm',force=True)
File "C:\Python26\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:\Python26\lib\site-packages\dicom\filereader.py", line 406, in read_partial
file_meta_dataset = _read_file_meta_info(fileobj)
File "C:\Python26\lib\site-packages\dicom\filereader.py", line 350, in _read_file_meta_info
group_length = unpack("<L", fp.read(length))[0] # XXX should prob check (gp, el), VR before read
struct.error: unpack requires a string argument of length 4
I understand what that it's finding information that does not match the length, but have no idea how to get around it. I have attached one the file.
Thank you.
j
Thanks for the example file. It didn't jump out at me at first, but
then I noticed that the file meta information does not have the
mandatory group length data element (0002,0000); it goes straight to
(0002,0001). The "XXX" note about checking them was prophetic, though,
as pydicom could have checked the tag and generated a sensible error
message.
Work-around? I don't know off-hand. Pydicom relies on the group length
to read the file meta info. The only other way I can think of at the
moment would be to create a whole new section of the
_read_file_meta_info method for just this case, using read_dataset
with a "stop_when" callback to finish on the first tag that is not
group 2. Then rewind the file pointer back to the start of the group 8
tag to get ready to read the file dataset. But that rewind amount will
depend on the transfer syntax. It's do-able, but a bit messy.
I've added an issue to the issue list.
Darcy
I've implemented that solution in the latest revision [1]. Pydicom can
now read the example iview file.
-Darcy
[1] http://code.google.com/p/pydicom/source/detail?r=349753235209