ruudcools wrote: >> Is there a method to force pydicom to read a specific tag as a curtain data type. As example I have a tag which is defined in the dicom file as DS (Decimal String) however the value is "MU" a SH data type. The tag is the (x0300a,x000b3) tag.
Well, it's serious black magic, but you could change the VR while the read-in item is still a namedtuple "raw data element" (before conversion according to the VR). This requires a direct call to dict methods to bypass automatic conversions done by the Dataset class. It would look like this (here I've used VR of CS as that is actually the correct VR according to the dictionary):
ds = dicom.read_file("rtplan.dcm")
b0 = ds.BeamSequence[0]
d = dict.__getitem__(b0, 0x300a00b3)
d2 = d._replace(VR='CS')
dict.__setitem__(b0, 0x300a00b3, d2)
print b0.data_element('PrimaryDosimeterUnit') # accessing the item causes conversion, but with new VR in place
Hope that helps. There might be a more elegant way, but that should work at least.
-----------
There was a similar kind of problem someone asked about once, as a comment on one of the wiki pages (https://code.google.com/p/pydicom/wiki/PydicomUserGuide). See my comment Nov 8, 2012 (repeated below in case those comments are lost when pydicom moves to github).The trick is to access the raw data elements right after reading the file, before any conversion has been done. Not elegant, but it should work. In that comment, the solution was to change the VR. In your case it might be better to change the value itself, by replacing comma with slash to turn the value into a multi-valued element and you would get it back as a list.
try: xray_filter_thickness_minimum = get_value_kw('FilterThicknessMinimum', dataset)except ValueError as e: try: xray_filter_thickness_minimum = e.message.split(':')[1].strip().split(',') except: xray_filter_thickness_minimum = None
ds = Dataset()
import dicom
ds = dicom.dataset.Dataset()
ds.FilterThicknessMinimum = 1.23
d = dict.__getitem__(ds, 0x187052)
d2 = d._replace(value='0.34,1.23')
rawelem = RawDataElement(....) # needs tag VR length value value_tell is_implicit_VR is_little_endian
rawdict = {tag:rawelem}
ds = Dataset(rawdict)
from dicom.dataelem import RawDataElement
from dicom.dataset import Dataset
from dicom.tag import Tag
rawelemmin = RawDataElement(Tag(0x187052), 'DS', 9, '0.09,1.18', 0, False, True)
rawelemmax = RawDataElement(Tag(0x187054), 'DS', 9, '0.11,1.22', 0, False, True)
rawdict = {0x187052: rawelemmin, 0x187054: rawelemmax}
ds = Dataset(rawdict)