diff --git a/openmc/data/neutron.py b/openmc/data/neutron.py index 95a3424ea4d..7adc8387f1e 100644 --- a/openmc/data/neutron.py +++ b/openmc/data/neutron.py @@ -351,7 +351,13 @@ def get_reaction_components(self, mt): else: return [mt] if mt in self else [] - def export_to_hdf5(self, path, mode='a', libver='earliest'): + def export_to_hdf5( + self, + path: cv.PathLike, + mode: str = 'a', + libver: str = 'earliest', + metadata: str | None = None + ): """Export incident neutron data to an HDF5 file. Parameters @@ -364,6 +370,8 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'): libver : {'earliest', 'latest'} Compatibility mode for the HDF5 file. 'latest' will produce files that are less backwards compatible but have performance benefits. + metadata : Optional str + A string of metadata to include in the HDF5 file as an attribute. """ # If data come from ENDF, don't allow exporting to HDF5 @@ -375,6 +383,8 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'): with h5py.File(str(path), mode, libver=libver) as f: f.attrs['filetype'] = np.bytes_('data_neutron') f.attrs['version'] = np.array(HDF5_VERSION) + if metadata is not None: + f.attrs['metadata'] = np.bytes_(metadata) # Write basic data g = f.create_group(self.name) diff --git a/openmc/data/photon.py b/openmc/data/photon.py index 25ded24cbe3..c3339d39c55 100644 --- a/openmc/data/photon.py +++ b/openmc/data/photon.py @@ -749,7 +749,13 @@ def from_hdf5(cls, group_or_filename): return data - def export_to_hdf5(self, path, mode='a', libver='earliest'): + def export_to_hdf5( + self, + path: cv.PathLike, + mode: str = 'a', + libver: str = 'earliest', + metadata: str | None = None + ): """Export incident photon data to an HDF5 file. Parameters @@ -762,6 +768,8 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'): libver : {'earliest', 'latest'} Compatibility mode for the HDF5 file. 'latest' will produce files that are less backwards compatible but have performance benefits. + metadata : Optional str + A string of metadata to include in the HDF5 file as an attribute. """ with h5py.File(str(path), mode, libver=libver) as f: @@ -769,6 +777,8 @@ def export_to_hdf5(self, path, mode='a', libver='earliest'): f.attrs['filetype'] = np.bytes_('data_photon') if 'version' not in f.attrs: f.attrs['version'] = np.array(HDF5_VERSION) + if metadata is not None: + f.attrs['metadata'] = np.bytes_(metadata) group = f.create_group(self.name) group.attrs['Z'] = Z = self.atomic_number