h5m: simplification for point data
@@ -10,6 +10,7 @@ import logging
import numpy
from . import __about__
+from .mesh import Mesh
# def _int_to_bool_list(num):
@@ -103,7 +104,9 @@ def read(filename):
# end = row[0] + 1
- return points, cells, point_data, cell_data, field_data
+ return Mesh(
+ points, cells, point_data=point_data, cell_data=cell_data, field_data=field_data
+ )
def write(
@@ -143,13 +146,15 @@ def write(
# The GLOBAL_ID associated with a point is used to identify points if
# distributed across several processes. mbpart automatically adds them,
# too.
- if "GLOBAL_ID" not in point_data and add_global_ids:
- point_data["GLOBAL_ID"] = numpy.arange(1, len(points) + 1)
+ # Copy to pd to avoid changing point_data. The items are not deep-copied.
+ pd = point_data.copy()
+ if "GLOBAL_ID" not in pd and add_global_ids:
+ pd["GLOBAL_ID"] = numpy.arange(1, len(points) + 1)
# add point data
- if point_data is not None:
+ if pd:
tags = nodes.create_group("tags")
- for key, data in point_data.items():
+ for key, data in pd.items():
if len(data.shape) == 1:
dtype = data.dtype
tags.create_dataset(key, data=data)
