ds = dicom.dataset.Dataset()
ds.PixelData = self.Image
ds.SliceThickness = self.Parms['thk']
if self.Parms['ns']:
ds.NumberofFrames = self.Parms['ns']
if self.Parms['nv2']:
ds.NumberofFrames = self.Parms['nv2']
ds.Rows = self.Parms['np']/2
ds.Columns = self.Parms['nv']
ds.PixelSpacing = self.Spc
ds.isExplicitVR = True
ds.isLittleEndian = True
if flname == '':
flname = self.Parms['seqfil'] + '.nii'
dicom.write_file(flname,ds)
_____________________________
I now get the following error:
____________________________
Traceback (most recent call last):
File "ConvertFIDtoDICOM.py", line 36, in <module>
temp.convertFIDtoDICOM(flname)
File "/Users/jhawkins/Documents/UCSF Radiology 7T/Python/
VNMRJ_Python/ProcparSer.py", line 55, in convertFIDtoDICOM
dicom.write_file(flname,ds)
File "/Library/Frameworks/Python.framework/Versions/6.1/lib/
python2.6/site-packages/pydicom-0.9.4_1-py2.6.egg/dicom/
filewriter.py", line 256, in write_file
if not dataset.preamble and not WriteLikeOriginal:
File "/Library/Frameworks/Python.framework/Versions/6.1/lib/
python2.6/site-packages/pydicom-0.9.4_1-py2.6.egg/dicom/dataset.py",
line 235, in __getattr__
raise AttributeError, "Dataset does not have attribute '%s'." %
name
AttributeError: Dataset does not have attribute 'preamble'.
_______________________________________________
I was under the impression that dicom.write_file will set a default
preamble if none is defined. Is that true, and how do I get the
default set?
Thanks,
James
Hi James,
Writing files from scratch like this is a weak spot in the pydicom
documentation (and the code itself), and something I'd like to pay
more attention to. And the latest version reorganized some of this so
you are uncovering some bugs.
You are right, the default preamble will be used if you don't supply
one. However, there is a bug there. Try setting ds.preamble = None,
then you should get the default. I'll add an issue on the issue list
to make sure this gets fixed in future versions.
Your other post asked about file_meta. It is a set of data elements
that is not really part of the main dataset, but is added only for
file storage (per DICOM standard). It was separated from the other
data elements in pydicom 0.9.4, so that is also leading to a few bugs.
Try setting that to None also and you should get the minimal required
elements (although I'm not sure whether the transfer syntax will be
properly used -- I'll try to check into that).
One other thing. You should use:
ds.is_little_endian = True
ds.is_implicit_VR = False # note implicit=False not explicit=True
rather then the ds.isLittleEndian and ds.isExplicitVR in your code
above -- that also changed in the latest version.
You could also look at dicom.dataset.FileDataset, and set all these
through creating an instance of that class, and passing it to
write_file.
Hopefully this will get you going, or at least close; feel free to
post any other problems you encounter.
Regards,
Darcy
Thanks for the advice.
When I set ds.file_meta = none (in addition to the other changes), the
dicom file is created just fine. When I try to load it up in a
viewer, however, the meta-data is unsupported. dcmdump (from dcmtk)
dumps out: # Used TransferSyntax: Unknown Transfer Syntax. I need to
read up more on dicom file storage to understand what's going on, but
I'd appreciate your thoughts, too.
Thanks again,
James