ivoflipse / pydicom

Automatically exported from code.google.com/p/pydicom
0 stars 1 forks source link

Error for defer_size read of gzip file object #103

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Make a gzipped DICOM file
2.  fobj = gzip.open(fname)
3.  data = dicom.read_file(fobj, defer_size=1)
4.  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.

Original issue reported on code.google.com by matthew....@gmail.com on 27 Jul 2011 at 6:55

Attachments:

GoogleCodeExporter commented 9 years ago
This issue was closed by revision f79c25fd0c65.

Original comment by darcymason@gmail.com on 4 Jan 2012 at 4:18