Commit 009945f9 authored by Jakob Maljaars's avatar Jakob Maljaars

Write to S string in h5parm

parent 9d0c3a4b
Pipeline #8083 passed with stages
in 24 minutes and 29 seconds
......@@ -163,11 +163,15 @@ class H5ParmWriter:
hdf_location = self.solution_set + "/" + name
self.h5file[self.solution_set].create_group(name)
self.h5file[hdf_location].attrs["TITLE"] = str.encode(type_name)
self.h5file[hdf_location].attrs["TITLE"] = np.asarray(
type_name, dtype=f"<S{len(type_name)}"
)
self.__write_version_stamp(self.solution_set + "/" + name)
# Convert axes labels to S-type
axes_labels = list(axes.keys())
axes_labels = ",".join(axes_labels).encode()
axes_labels = np.asarray(axes_labels, dtype=f"<S{len(axes_labels)}")
axes_shape = tuple(axes.values())
dtype = values.dtype if values is not None else dtype
......@@ -205,7 +209,9 @@ class H5ParmWriter:
self.h5file[hdf_location + "/weight"][:] = weights
if history is not None:
self.h5file[hdf_location + "/val"].attrs["HISTORY000"] = str.encode(history)
self.h5file[hdf_location + "/val"].attrs["HISTORY000"] = np.asarray(
history, dtype=f"<S{len(history)}"
)
def fill_solution_table(self, name, values, offset=None):
"""
......@@ -359,7 +365,9 @@ class H5ParmWriter:
hdf_location : str
Location where the version stamp will be added.
"""
self.h5file[hdf_location].attrs["h5parm_version"] = str.encode(H5PARM_VERSION)
self.h5file[hdf_location].attrs["h5parm_version"] = np.asarray(
H5PARM_VERSION, dtype=f"<S{len(H5PARM_VERSION)}"
)
def __write_attributes(self, hdf_location, attributes, overwrite):
"""
......@@ -384,7 +392,9 @@ class H5ParmWriter:
else:
if isinstance(value, str):
# Byte encoded string
self.h5file[hdf_location].attrs[key] = str.encode(value)
self.h5file[hdf_location].attrs[key] = np.asarray(
value, dtype=f"<S{len(value)}"
)
elif isinstance(value, np.ndarray) and value.dtype.type == np.str_:
# Convert to S string
data_type_h5 = re.sub(r"[a-zA-Z]", "S", value.dtype.str)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment