diff --git a/openmc/data/function.py b/openmc/data/function.py index 582d4ee6f5..f167a3c236 100644 --- a/openmc/data/function.py +++ b/openmc/data/function.py @@ -349,8 +349,8 @@ class Tabulated1D(Function1D): raise ValueError("Expected an HDF5 attribute 'type' equal to '" + cls.__name__ + "'") - x = dataset.value[0, :] - y = dataset.value[1, :] + x = dataset[0, :] + y = dataset[1, :] breakpoints = dataset.attrs['breakpoints'] interpolation = dataset.attrs['interpolation'] return cls(x, y, breakpoints, interpolation) diff --git a/openmc/data/photon.py b/openmc/data/photon.py index db984c7693..e038ca05d2 100644 --- a/openmc/data/photon.py +++ b/openmc/data/photon.py @@ -376,8 +376,8 @@ class AtomicRelaxation(EqualityMixin): # Write transition data with replacements if shell in self.transitions: df = self.transitions[shell].replace( - _SUBSHELLS, np.arange(float(len(_SUBSHELLS)))) - group.create_dataset('transitions') + _SUBSHELLS, range(len(_SUBSHELLS))) + group.create_dataset('transitions', data=df.values.astype(float)) class IncidentPhoton(EqualityMixin): diff --git a/openmc/data/thermal.py b/openmc/data/thermal.py index ef1fa3b02d..27ed7aa291 100644 --- a/openmc/data/thermal.py +++ b/openmc/data/thermal.py @@ -200,8 +200,8 @@ class CoherentElastic(EqualityMixin): Coherent elastic scattering cross section """ - bragg_edges = dataset.value[0, :] - factors = dataset.value[1, :] + bragg_edges = dataset[0, :] + factors = dataset[1, :] return cls(bragg_edges, factors) diff --git a/tests/unit_tests/test_data_photon.py b/tests/unit_tests/test_data_photon.py index f0a107a05d..9bbbcc8ecb 100644 --- a/tests/unit_tests/test_data_photon.py +++ b/tests/unit_tests/test_data_photon.py @@ -129,6 +129,20 @@ def test_export_to_hdf5(tmpdir, element): filename = str(tmpdir.join('tmp.h5')) element.export_to_hdf5(filename) assert os.path.exists(filename) - # Read in data from hdf5 and export again + # Read in data from hdf5 element2 = openmc.data.IncidentPhoton.from_hdf5(filename) + # Check for some cross section and datasets of element and element2 + energy = np.logspace(np.log10(1.0), np.log10(1.0e10), num=100) + for mt in (502, 504, 515, 517, 522, 541, 570): + xs = element[mt].xs(energy) + xs2 = element2[mt].xs(energy) + assert np.allclose(xs, xs2) + assert element[502].scattering_factor == element2[502].scattering_factor + assert element.atomic_relaxation.transitions['O3'].equals( + element2.atomic_relaxation.transitions['O3']) + assert (element.compton_profiles['binding_energy'] == + element2.compton_profiles['binding_energy']).all() + assert (element.bremsstrahlung['electron_energy'] == + element2.bremsstrahlung['electron_energy']).all() + # Export to hdf5 again element2.export_to_hdf5(filename, 'w')