Skip to content

Preserve photon-data source metadata through HDF5 conversion - #4117

Open
JROChub wants to merge 1 commit into
openmc-dev:developfrom
JROChub:photon-source-metadata
Open

Preserve photon-data source metadata through HDF5 conversion#4117
JROChub wants to merge 1 commit into
openmc-dev:developfrom
JROChub:photon-source-metadata

Conversation

@JROChub

@JROChub JROChub commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Description

This adds component-specific source metadata to photon-data conversion and HDF5 persistence.

Photoatomic and atomic-relaxation data retain separate library, version, and release information. The change includes metadata extraction, round-trip, older-file compatibility, and data-integrity tests, plus an inspection example.

Related to #4075.

Feedback on the proposed storage layout is welcome during review. The implementation stores optional source_library, source_version, and source_release attributes on the existing element group for photoatomic data and on its existing subshells group for relaxation data. The HDF5 root and numerical datasets are unchanged.

The fields come directly from each evaluation's info["library"]. Missing information remains absent; files without source attributes load with empty dictionaries. Metadata is validated before opening an output file, including malformed strings and integers outside HDF5's representable range.

Validation

  • Real OpenMC native library, strict floating point enabled; no documentation import mock.
  • Python 3.13.12, NumPy 2.5.3, h5py 3.16.0, endf 0.1.12; official NNDC ENDF/B-VII.1 photon and atomic-relaxation files.
  • 43 tests passed. Coverage includes filename/Path/group loading, independent component evaluations, UTF-8 and partial records, zero-valued NumPy integers, older files, element registration, and invalid-input preservation.
  • Independent exports using the unmodified 438b05d photon module and this implementation: 295 numerical datasets byte-identical, with 419 existing attributes unchanged, across H, O, Al, Cu, Ag, U, and Pu.
  • Focused lint, compilation, and git diff --check passed.

From the configured OpenMC development environment:

export OPENMC_ENDF_DATA=/path/to/endf-b-vii.1
OMP_NUM_THREADS=2 OPENBLAS_NUM_THREADS=1 python -m pytest tests/unit_tests/test_data_photon.py -q
Actual test output
========================= OpenMC Environment Warnings ==========================
WARNING: OPENMC_CROSS_SECTIONS environment variable is not set. Regression tests require the NNDC HDF5 cross section data.

...........................................                              [100%]
=============================== warnings summary ===============================
tests/unit_tests/test_data_photon.py: 114 warnings
  /usr/lib/python3.13/contextlib.py:141: Pandas4Warning: 'future.no_silent_downcasting' is deprecated, please refrain from using it.
    return next(self.gen)

tests/unit_tests/test_data_photon.py: 57 warnings
  /usr/lib/python3.13/contextlib.py:148: Pandas4Warning: 'future.no_silent_downcasting' is deprecated, please refrain from using it.
    next(self.gen)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================= OpenMC Environment Warnings ==========================
WARNING: OPENMC_CROSS_SECTIONS environment variable is not set. Regression tests require the NNDC HDF5 cross section data.

43 passed, 171 warnings in 3.22s

The transport cross-section warning and existing pandas deprecation warnings are retained above. These tests use the ENDF photon fixtures and HDF5 conversion, not particle transport.

Save, reload, and inspect

Executed using the official ENDF/B-VII.1 uranium evaluations:

u = openmc.data.IncidentPhoton.from_endf(
    'photoat-092_U_000.endf', 'atom-092_U_000.endf')
u.export_to_hdf5('U.h5')
restored = openmc.data.IncidentPhoton.from_hdf5('U.h5')
print(restored.source_metadata)
print(restored.atomic_relaxation.source_metadata)
{'library': 'ENDF/B', 'version': 7, 'release': 1}
{'library': 'ENDF/B', 'version': 7, 'release': 1}

These inputs happen to share the same library. Separate tests deliberately assign different source tuples to the two evaluations and verify that each survives independently.

Checklist

  • I have performed a self-review of my own code
  • I have followed the Python style guidelines
  • I have made corresponding changes to the documentation
  • I have added tests that prove the feature works

Capture each ENDF evaluation's library, version, and release separately
for photoatomic and atomic-relaxation components. Persist optional
attributes on the existing element and subshells groups, preserving the
root layout and compatibility with files that omit source metadata.

Validate metadata before opening output files. Add extraction, round-trip,
legacy compatibility, data-integrity, and invalid-input coverage, with
an inspection example and the optional attributes in the format guide.
@JROChub
JROChub marked this pull request as ready for review September 9, 2026 14:51
@JROChub
JROChub requested a review from amandalund as a code owner September 9, 2026 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant