respect some XDMF defaults
@@ -161,11 +161,27 @@ class XdmfReader(object):
return self.read_xdmf3(root)
- def read_data_item(self, data_item, dt_key='DataType'):
+ def read_data_item(self, data_item):
import h5py
dims = [int(d) for d in data_item.attrib['Dimensions'].split()]
- data_type = data_item.attrib[dt_key]
+
+ # Actually, `NumberType` is XDMF2 and `DataType` XDMF3, but many files
+ # out there use both keys interchangeably.
+ if 'DataType' in data_item.attrib:
+ assert 'NumberType' not in data_item.attrib
+ data_type = data_item.attrib['DataType']
+ elif 'NumberType' in data_item.attrib:
+ assert 'DataType' not in data_item.attrib
+ data_type = data_item.attrib['NumberType']
+ else:
+ # Default, see
+ # <http://www.xdmf.org/index.php/XDMF_Model_and_Format#XML_Element_.28Xdmf_ClassName.29_and_Default_XML_Attributes>
+ data_type = 'Float'
+
+ try:
precision = data_item.attrib['Precision']
+ except KeyError:
+ precision = '4'
if data_item.attrib['Format'] == 'XML':
return numpy.array(
@@ -209,7 +225,12 @@ class XdmfReader(object):
'XDMF reader: Only supports one grid right now.'
grid = grids[0]
assert grid.tag == 'Grid'
+
+ try:
assert grid.attrib['GridType'] == 'Uniform'
+ except KeyError:
+ # The default is 'Uniform'
+ pass
points = None
cells = {}
@@ -222,17 +243,13 @@ class XdmfReader(object):
data_items = list(c)
assert len(data_items) == 1
meshio_type = xdmf_to_meshio_type[c.attrib['TopologyType']]
- cells[meshio_type] = self.read_data_item(
- data_items[0], dt_key='NumberType'
- )
+ cells[meshio_type] = self.read_data_item(data_items[0])
elif c.tag == 'Geometry':
assert c.attrib['GeometryType'] == 'XYZ'
data_items = list(c)
assert len(data_items) == 1
- points = self.read_data_item(
- data_items[0], dt_key='NumberType'
- )
+ points = self.read_data_item(data_items[0])
else:
assert c.tag == 'Attribute', \
@@ -244,7 +261,7 @@ class XdmfReader(object):
data_items = list(c)
assert len(data_items) == 1
- data = self.read_data_item(data_items[0], dt_key='NumberType')
+ data = self.read_data_item(data_items[0])
name = c.attrib['Name']
if c.attrib['Center'] == 'Node':
