What steps will reproduce the problem? 1. Make a gzipped DICOM file
fobj = gzip.open(fname)
data = dicom.read_file(fobj, defer_size=1)
no = data.InstanceNumber # Nasty obscure error
The error (on a test file, see script below) ends with:
522 if data_elem.tag != raw_data_elem.tag:
523 raise ValueError, "Deferred read tag %r does not match
original %r" % (data_elem.tag, raw_data_elem.tag)
ValueError: Deferred read VR '??' does not match original 'IS' What version of the product are you using? Current tip : parent: 138:31325f49ed70 release-0.9.5 Please provide any additional information below. Here's what you were saying on the mailing list:
... a quick look at the code shows the
read_deferred_data_element function in filereader.py simply opens the
file based on a filename passed to it.
I won't have time to try to code this for at least a few weeks, but
here is the approach that comes to mind after a survey of the key
events in the code:
The decision to call that read_deferred_data_element function is in
dataset.py, around line 270. It is called passing "self.filename",
i.e. info stored in the FileDataset object (defined at bottom of
dataset.py).
I think the best approach would be to add another item stored in the
FileDataset, i.e. to add the type of the fileobj that was used to
create the FileDataset. That can later be referenced to open it again.
i.e. in FileDatset
...(in the branch where it is not a string, but a file obj)
self.typefileobj = type(filename_or_obj)
then in read_deferred_data_element:
(instead of open() using the filename, check if self.typefileobj
exists, then do:)
fp = self.typefileobj(self.filename, "rb")
I think something like that should work for gzipped objects as you are
using, and for the standard non-zipped DICOM files. I'm not sure it
will work just like that for StringIO-based ones though (which are
used for compression within the DICOM files). Might need some
modification.
From matthew....@gmail.com on July 27, 2011 14:55:41
What steps will reproduce the problem? 1. Make a gzipped DICOM file
The error (on a test file, see script below) ends with:
522 if data_elem.tag != raw_data_elem.tag: 523 raise ValueError, "Deferred read tag %r does not match original %r" % (data_elem.tag, raw_data_elem.tag)
ValueError: Deferred read VR '??' does not match original 'IS' What version of the product are you using? Current tip : parent: 138:31325f49ed70 release-0.9.5 Please provide any additional information below. Here's what you were saying on the mailing list:
... a quick look at the code shows the read_deferred_data_element function in filereader.py simply opens the file based on a filename passed to it.
I won't have time to try to code this for at least a few weeks, but here is the approach that comes to mind after a survey of the key events in the code:
The decision to call that read_deferred_data_element function is in dataset.py, around line 270. It is called passing "self.filename", i.e. info stored in the FileDataset object (defined at bottom of dataset.py).
I think the best approach would be to add another item stored in the FileDataset, i.e. to add the type of the fileobj that was used to create the FileDataset. That can later be referenced to open it again.
i.e. in FileDatset ...(in the branch where it is not a string, but a file obj) self.typefileobj = type(filename_or_obj)
then in read_deferred_data_element: (instead of open() using the filename, check if self.typefileobj exists, then do:) fp = self.typefileobj(self.filename, "rb")
I think something like that should work for gzipped objects as you are using, and for the standard non-zipped DICOM files. I'm not sure it will work just like that for StringIO-based ones though (which are used for compression within the DICOM files). Might need some modification.
Attachment: dcm_gz_deferred.py
Original issue: http://code.google.com/p/pydicom/issues/detail?id=103