RE: Creating DICOM from Scratch, dicom.write_file - Premable

1,027 views
Skip to first unread message

James Hawkins

unread,
Apr 6, 2010, 6:39:07 PM4/6/10
to pydicom
Sorry for the quick, second posting, but I've changed my code to the
following:
____________________________________
def convertFIDtoDICOM(self, flname=''):
"""Converts FID file to DICOM Tile-Type"""

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

Darcy Mason

unread,
Apr 6, 2010, 7:16:41 PM4/6/10
to pydicom
On Apr 6, 6:39 pm, James Hawkins <dr.katam...@gmail.com> wrote:
> ...

> I now get the following error:
> ____________________________
>...

> 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?
>

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


Message has been deleted

James Hawkins

unread,
Apr 15, 2010, 5:21:18 PM4/15/10
to pydicom
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

Darcy Mason

unread,
Apr 16, 2010, 8:56:57 AM4/16/10
to pydicom

On Apr 15, 5:21 pm, James Hawkins <dr.katam...@gmail.com> wrote:
>
> 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.

Hi James,

I'm going to try to tackle the writing-from-scratch issue in the next
few days, but in the meantime, perhaps we can still solve your
immediate problem with a bit more information. Did you set a transfer
syntax yourself, or just the is_implicit_VR and is_little_endian?
Looking at the code for write_file in filewriter.py, if
TransferSyntaxUID is not present it looks like it should add one
correctly.

It would also be helpful to do a binary dump of the output file to
inspect the file meta information directly. Maybe you could look at
or post here the first bit of the hex dump -- the pydicom wiki
Troubleshooting page shows how to do the hex dump [1].

Regards,
Darcy

[1] http://code.google.com/p/pydicom/wiki/Troubleshooting

--
You received this message because you are subscribed to the Google Groups "pydicom" group.
To post to this group, send email to pyd...@googlegroups.com.
To unsubscribe from this group, send email to pydicom+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pydicom?hl=en.

Reply all
Reply to author
Forward
0 new messages