thegooglecodearchive / pydicom

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

Python 3: The VR 'OB' should not be prefixed with b'OB'. #141

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In the method `_write_file_meta_info`, there is a "b" prefix for 'OB' in line 
259, which is perhaps wrong and should just be a str:

if Tag((2, 1)) not in meta_dataset: meta_dataset.add_new((2, 1), b'OB', b"\0\1") # file meta information version


This will later fail in `write_data_element` when

if in_py3: fp.write(bytes(VR, default_encoding))


... tries to convert `VR` to bytes but it has to be a string. Therefore my 
assumption is that `b'OB'` should not be prefixed. I am pretty sure you can 
decide if I am right or not without me making a minimal program that shows this 
error. But if you want me to, just give me a shout.

Version info:
Python 3.4 on OS X on latest hg tip (changeset:   326:98b641dc8823)

Here is the code that I use to create the `file_meta` for the dicom file from 
scratch.
file_meta = dicom.dataset.Dataset()
file_meta.SourceApplicationEntityTitle = __file__
file_meta.ImplementationVersionName = "0.1.2"
# Secondary image storge
file_meta.MediaStorageSOPClassUID = "1.2.840.10008.5.1.4.1.1.7"
# Todo: Fixme: The next two would require to get an official ID that
# can be used to derive an own UID for this software.
file_meta.MediaStorageSOPInstanceUID = \
    "1.2.826.0.1.3680043.8.498.13215509892738242775390658"
# # UID for this specific version of the software
file_meta.ImplementationClassUID = \
    "1.2.826.0.1.3680043.8.498.132155098927382427736600651"

and here is where I create the DS and set some values...
 ds = dicom.dataset.Dataset()
 ds.preamble = b"\0"*128
 ds.file_meta = file_meta
 ds.is_little_endian = True
 ds.is_implicit_VR = True

and finally write the file
dicom.dataset.FileDataset(outfile, ds, file_meta=file_meta,
                              preamble=b"\0"*128).save_as(outfile)

I am sure, I could remove some stuff that is duplicate (for example the 
preamble), but I think this is somewhat unrelated.

Thanks for pydicom.

Original issue reported on code.google.com by samueljo...@gmail.com on 12 Apr 2014 at 5:52

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

Original comment by Suever@gmail.com on 12 Apr 2014 at 8:59

GoogleCodeExporter commented 9 years ago
Thanks for the report. Should be functional now.

Original comment by Suever@gmail.com on 12 Apr 2014 at 8:59