From 5b90d9bbaa8474b65cfd92b60c755b2829c564bc Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 25 Nov 2026 12:52:47 +0100 Subject: [PATCH 1/2] Make the JEFF 3.3 TENDL-2019 substitution explicit generate_jeff -r 3.3 processes TENDL-2019 evaluations in place of the defective JEFF 3.3 C13 and O17 files. This was only noted in the docstring and a print line. The README now has a footnote, each substitution raises a warning, and the final summary lists the substituted files as not JEFF data. --- README.md | 7 ++++++- src/openmc_data/generate/generate_jeff.py | 15 ++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index ea6e18d..852a68b 100644 --- a/README.md +++ b/README.md @@ -127,9 +127,14 @@ See `convert_jeff --help` for all options. | generate_endf | ENDF/B | VII.1
VIII.0
VIII.1 | NNDC | | generate_fendl | FENDL | 3.2c
3.2b
3.2a
3.2
3.1d
3.1a
3.0 | | | generate_jendl | JENDL | 4.0
5.0 (neutron, thermal scattering and photon) | NJOY | -| generate_jeff | JEFF | 3.3
4.0 (neutron and thermal scattering) | NJOY | +| generate_jeff | JEFF | 3.3\*
4.0 (neutron and thermal scattering) | NJOY | | generate_tendl | TENDL | 2023
2025 | | +\* `generate_jeff -r 3.3` substitutes TENDL-2019 evaluations for C13 and O17, because +the JEFF 3.3 evaluations of these nuclides have defective MF=6 data. The C13 and O17 +files in the output are therefore TENDL-2019 data, not JEFF. JEFF 4.0 has no +substitutions. + ### Download cross sections diff --git a/src/openmc_data/generate/generate_jeff.py b/src/openmc_data/generate/generate_jeff.py index 5822e64..d5b9e2b 100644 --- a/src/openmc_data/generate/generate_jeff.py +++ b/src/openmc_data/generate/generate_jeff.py @@ -15,9 +15,13 @@ Additional temperature-split PuO2/UO2/Zy4 evaluations are excluded. Full-library NJOY qualification has not been performed. -JEFF 3.3 C13/O17 use individual IAEA TENDL-2019 replacements without editing -originals. ZIP CRCs and ENDF targets are checked (no published MD5). If IAEA +JEFF 3.3 only: the C13 and O17 neutron files in the output are TENDL-2019 +data, not JEFF. The JEFF 3.3 evaluations of these two nuclides have defective +MF=6 data, so individual IAEA TENDL-2019 evaluations are processed in their +place (the downloaded JEFF files are not edited). A warning is issued for each +substitution. ZIP CRCs and ENDF targets are checked (no published MD5). If IAEA blocks automated access, manually cache the archives; blocked downloads fail. +JEFF 4.0 has no substitutions. Output uses particle subdirectories and relative XML paths. Isolated workers stage and validate outputs before publication; only current outputs are @@ -254,6 +258,7 @@ def main(argv=None): prepared.append(particle) tasks = [] + substituted = [] if 'neutron' in required: neutrons = _index(inputs / 'neutron', details['neutron']['pattern']) if 'neutron' in particles: @@ -265,7 +270,9 @@ def main(argv=None): _prepare(replacement, archives / group, inputs / group, args) prepared.append(group) selected[name] = _replacement(replacement, inputs / group) - print(f'Using TENDL-2019 replacement for {name}') + substituted.append(name) + warnings.warn(f'{name} is substituted with TENDL-2019 data; its HDF5 ' + 'output is not JEFF data', stacklevel=2) tasks.extend(('neutron', (path,)) for path in selected.values()) if 'thermal' in particles: thermal = _index(inputs / 'thermal', details['neutron']['pattern'], @@ -281,6 +288,8 @@ def main(argv=None): if enabled and (root / group).exists(): shutil.rmtree(root / group) print(f'Wrote {destination / "cross_sections.xml"}') + if substituted: + print(f'Not JEFF data: {", ".join(substituted)} were substituted with TENDL-2019') if __name__ == '__main__': From 4d1f8d8c40d5bff03bf6235c27e4dfb8deef9190 Mon Sep 17 00:00:00 2001 From: shimwell Date: Wed, 25 Nov 2026 13:01:01 +0100 Subject: [PATCH 2/2] Record data provenance in cross_sections.xml and never mix libraries Every generate and convert script now writes an XML comment at the top of cross_sections.xml with the data source, entry counts by type, the openmc_data version and script, the date, and any evaluations taken from another library (JEFF 3.3 C13/O17). OpenMC's C++ and Python readers ignore comments. convert_mcnp70 and convert_mcnp71 no longer accept --photon, which added eprdata photoatomic data to an ENDF/B library. combine_libraries now records how many entries of each type came from each input. The README explains that it fills any gap from later libraries, and shows how to combine JEFF-4.0 or TENDL-2025 with a photon-only ENDF/B-VIII.1 library. --- README.md | 46 ++++++++++++++++++++++ src/openmc_data/__init__.py | 1 + src/openmc_data/convert/convert_endf.py | 3 +- src/openmc_data/convert/convert_fendl.py | 3 +- src/openmc_data/convert/convert_jeff.py | 3 +- src/openmc_data/convert/convert_lib80x.py | 3 +- src/openmc_data/convert/convert_mcnp70.py | 36 ++++------------- src/openmc_data/convert/convert_mcnp71.py | 34 ++++------------ src/openmc_data/convert/convert_tendl.py | 3 +- src/openmc_data/generate/generate_cendl.py | 3 +- src/openmc_data/generate/generate_endf.py | 3 +- src/openmc_data/generate/generate_fendl.py | 3 +- src/openmc_data/generate/generate_jeff.py | 8 ++-- src/openmc_data/generate/generate_jendl.py | 3 +- src/openmc_data/generate/generate_tendl.py | 3 +- src/openmc_data/other/combine_libraries.py | 45 +++++++++++++++++++++ src/openmc_data/utils.py | 45 +++++++++++++++++++++ tests/test_utils.py | 34 ++++++++++++++++ 18 files changed, 211 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 852a68b..6f9392f 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,17 @@ A few categories of scripts are available: ## Produce Cross Section Files +Each generate and convert script produces data from one evaluated library only. +Photon or other data missing from that library are not filled in from another +library. To combine libraries, for example JEFF neutron data with ENDF/B photon +data, run the scripts separately and combine the `cross_sections.xml` files. + +Each `cross_sections.xml` written by these scripts starts with an XML comment +that records the data source, the number of entries of each type, the +openmc_data version and script, and any evaluations taken from another library. +OpenMC ignores XML comments, so the comment does not change how the library +loads. `openmc.data.DataLibrary` drops comments when it rewrites a file. + ### Convert cross sections | Script name | Library | Release | Processed by | @@ -157,6 +168,41 @@ substitutions. |generate_jendl| JENDL | 4.0 | | | | :heavy_check_mark: | | |convert_tendl| TENDL | 2015
2017
2019
2021| | | :heavy_check_mark: | | | --> +### Combine libraries + +The generate and convert scripts never mix libraries, so photon data for a +neutron-only library (JEFF, TENDL) come from a separate run. `combine_libraries` +then merges the `cross_sections.xml` files. Libraries are listed in order of +preference: everything from the first is used, and a later library only adds +entries the earlier ones lack. Give the photon library as a photon-only library, +otherwise its neutron and thermal entries would also fill gaps in the first. + +JEFF-4.0 neutron and thermal scattering data with ENDF/B-VIII.1 photon data: + +```bash +generate_jeff -r 4.0 # writes jeff-4.0-hdf5/ +generate_endf -r viii.1 -p photon # writes endfb-viii.1-hdf5/ (photon only) +combine_libraries \ + -l jeff-4.0-hdf5/cross_sections.xml endfb-viii.1-hdf5/cross_sections.xml \ + -o jeff-4.0-endfb-viii.1-photon.xml +``` + +TENDL-2025 neutron data with ENDF/B-VIII.1 photon data: + +```bash +generate_tendl -r 2025 # writes tendl-2025-hdf5/ +generate_endf -r viii.1 -p photon # writes endfb-viii.1-hdf5/ (photon only) +combine_libraries \ + -l tendl-2025-hdf5/cross_sections.xml endfb-viii.1-hdf5/cross_sections.xml \ + -o tendl-2025-endfb-viii.1-photon.xml +``` + +Without `-d` the combined XML is written to the current directory and points at +the original files. With `-d ` the HDF5 files are copied there too. +The combined XML records, as a comment, how many entries of each type came from +which library. Point OpenMC at it with `openmc.config['cross_sections']` or +`OPENMC_CROSS_SECTIONS`. + ## Produce Depletion Chain files ### Generate chain files diff --git a/src/openmc_data/__init__.py b/src/openmc_data/__init__.py index 0d9ae2a..2f1396a 100644 --- a/src/openmc_data/__init__.py +++ b/src/openmc_data/__init__.py @@ -18,6 +18,7 @@ from .utils import ( ProgressTracker, + add_provenance, apply_updates, calculate_download_size, download, diff --git a/src/openmc_data/convert/convert_endf.py b/src/openmc_data/convert/convert_endf.py index 685c109..1bb413b 100755 --- a/src/openmc_data/convert/convert_endf.py +++ b/src/openmc_data/convert/convert_endf.py @@ -11,7 +11,7 @@ from pathlib import Path import openmc.data -from openmc_data import download, extract, all_release_details, get_file_types, calculate_download_size, ProgressTracker +from openmc_data import add_provenance, download, extract, all_release_details, get_file_types, calculate_download_size, ProgressTracker # Make sure Python version is sufficient assert sys.version_info >= (3, 6), "Python 3.6+ is required" @@ -187,6 +187,7 @@ def main(): # Write cross_sections.xml print("Writing ", args.destination / "cross_sections.xml") library.export_to_xml(args.destination / "cross_sections.xml") + add_provenance(args.destination / "cross_sections.xml", "ENDF/B-VII.1") if __name__ == "__main__": diff --git a/src/openmc_data/convert/convert_fendl.py b/src/openmc_data/convert/convert_fendl.py index 682cd83..64bf5b2 100755 --- a/src/openmc_data/convert/convert_fendl.py +++ b/src/openmc_data/convert/convert_fendl.py @@ -14,7 +14,7 @@ from urllib.parse import urljoin import openmc.data -from openmc_data import download, all_release_details, calculate_download_size, get_file_types, ProgressTracker +from openmc_data import add_provenance, download, all_release_details, calculate_download_size, get_file_types, ProgressTracker class CustomFormatter( @@ -291,6 +291,7 @@ def main(): # Write cross_sections.xml print("Writing ", args.destination / "cross_sections.xml") library.export_to_xml(args.destination / "cross_sections.xml") + add_provenance(args.destination / "cross_sections.xml", f"FENDL-{args.release}") # Print any warnings for warning in output_warnings: diff --git a/src/openmc_data/convert/convert_jeff.py b/src/openmc_data/convert/convert_jeff.py index 5d86c46..2f0a5ce 100644 --- a/src/openmc_data/convert/convert_jeff.py +++ b/src/openmc_data/convert/convert_jeff.py @@ -16,7 +16,7 @@ from tempfile import TemporaryDirectory import warnings -from openmc_data import ProgressTracker, all_release_details, download, extract +from openmc_data import ProgressTracker, add_provenance, all_release_details, download, extract RELEASES = ("3.2", "3.3", "4.0") @@ -293,6 +293,7 @@ def main(argv=None): del data library.register_file(output) library.export_to_xml(stage / "cross_sections.xml") + add_provenance(stage / "cross_sections.xml", f"JEFF-{args.release}") for name in groups: (stage / f"{name}.h5").replace(destination / f"{name}.h5") (stage / "cross_sections.xml").replace(destination / "cross_sections.xml") diff --git a/src/openmc_data/convert/convert_lib80x.py b/src/openmc_data/convert/convert_lib80x.py index 37a23e3..e943dbd 100755 --- a/src/openmc_data/convert/convert_lib80x.py +++ b/src/openmc_data/convert/convert_lib80x.py @@ -13,7 +13,7 @@ import openmc.data -from openmc_data import ProgressTracker +from openmc_data import ProgressTracker, add_provenance # Make sure Python version is sufficient @@ -107,6 +107,7 @@ def main(): # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', 'ENDF/B-VIII.0 (LANL lib80x)') if __name__ == '__main__': diff --git a/src/openmc_data/convert/convert_mcnp70.py b/src/openmc_data/convert/convert_mcnp70.py index bd84ce3..1869013 100755 --- a/src/openmc_data/convert/convert_mcnp70.py +++ b/src/openmc_data/convert/convert_mcnp70.py @@ -3,9 +3,10 @@ """ Convert ENDF/B-VII.0 ACE data from the MCNP5/6 distribution into an HDF5 library that can be used by OpenMC. This assumes that you have a directory containing -files named endf70[a-k] and endf70sab. Optionally, if a recent photoatomic -library (e.g., eprdata14) is available, it can also be converted using the ---photon argument. +files named endf70[a-k] and endf70sab. Only the ENDF/B neutron and thermal +scattering data are converted; photoatomic data from other libraries +(e.g. eprdata) are not added. To use them, convert them separately and combine +the cross_sections.xml files. """ import argparse @@ -15,7 +16,7 @@ import openmc.data -from openmc_data import ProgressTracker +from openmc_data import ProgressTracker, add_provenance # Make sure Python version is sufficient @@ -38,10 +39,8 @@ class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, default='earliest', help="Output HDF5 versioning. Use " "'earliest' for backwards compatibility or 'latest' for " "performance") -parser.add_argument('-p', '--photon', type=Path, - help='Path to photoatomic data library (eprdata12 or later)') parser.add_argument('mcnpdata', type=Path, - help="Directory containing endf70[a-k], endf70sab, and mcplib") + help="Directory containing endf70[a-k] and endf70sab") args = parser.parse_args() @@ -49,14 +48,12 @@ def main(): # Check arguments to make sure they're valid assert args.mcnpdata.is_dir(), 'mcnpdata argument must be a directory' - if args.photon is not None: - assert args.photon.is_file(), 'photon argument must be an existing file' # Get a list of all neutron ACE files endf70 = args.mcnpdata.glob('endf70[a-k]') # Create output directory if it doesn't exist - (args.destination / 'photon').mkdir(parents=True, exist_ok=True) + args.destination.mkdir(parents=True, exist_ok=True) library = openmc.data.DataLibrary() @@ -121,26 +118,9 @@ def main(): # Register with library library.register_file(h5_file) - # Handle photoatomic data - if args.photon is not None: - lib = openmc.data.ace.Library(args.photon) - - tracker = ProgressTracker(len(lib.tables)) - for table in lib.tables: - # Convert first temperature for the table - tracker.starting(table.name) - data = openmc.data.IncidentPhoton.from_ace(table) - - # Export HDF5 file - h5_file = args.destination / 'photon' / f'{data.name}.h5' - print(f'Writing {h5_file}...') - data.export_to_hdf5(h5_file, 'w', libver=args.libver) - - # Register with library - library.register_file(h5_file) - # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', 'ENDF/B-VII.0 (MCNP endf70)') if __name__ == '__main__': diff --git a/src/openmc_data/convert/convert_mcnp71.py b/src/openmc_data/convert/convert_mcnp71.py index 2f393c1..cbb6f08 100755 --- a/src/openmc_data/convert/convert_mcnp71.py +++ b/src/openmc_data/convert/convert_mcnp71.py @@ -3,9 +3,10 @@ """ Convert ENDF/B-VII.1 ACE data from the MCNP6 distribution into an HDF5 library that can be used by OpenMC. This assumes that you have a directory containing -subdirectories 'endf71x' and 'ENDF71SaB'. Optionally, if a recent photoatomic -library (e.g., eprdata14) is available, it can also be converted using the ---photon argument. +subdirectories 'endf71x' and 'ENDF71SaB'. Only the ENDF/B neutron and thermal +scattering data are converted; photoatomic data from other libraries +(e.g. eprdata) are not added. To use them, convert them separately and combine +the cross_sections.xml files. """ import argparse @@ -15,7 +16,7 @@ import openmc.data -from openmc_data import ProgressTracker +from openmc_data import ProgressTracker, add_provenance # Make sure Python version is sufficient @@ -38,8 +39,6 @@ class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, default='earliest', help="Output HDF5 versioning. Use " "'earliest' for backwards compatibility or 'latest' for " "performance") -parser.add_argument('-p', '--photon', type=Path, - help='Path to photoatomic data library (eprdata12 or later)') parser.add_argument('mcnpdata', type=Path, help='Directory containing endf71x and ENDF71SaB') args = parser.parse_args() @@ -49,8 +48,6 @@ def main(): # Check arguments to make sure they're valid assert args.mcnpdata.is_dir(), 'mcnpdata argument must be a directory' - if args.photon is not None: - assert args.photon.is_file(), 'photon argument must be an existing file' # Get a list of all ACE files endf71x = list(args.mcnpdata.glob('endf71x/*/*.7??nc')) @@ -85,7 +82,7 @@ def main(): tables[p.stem].append(p) # Create output directory if it doesn't exist - (args.destination / 'photon').mkdir(parents=True, exist_ok=True) + args.destination.mkdir(parents=True, exist_ok=True) library = openmc.data.DataLibrary() @@ -116,26 +113,9 @@ def main(): # Register with library library.register_file(h5_file) - # Handle photoatomic data - if args.photon is not None: - lib = openmc.data.ace.Library(args.photon) - - tracker = ProgressTracker(len(lib.tables)) - for table in lib.tables: - # Convert first temperature for the table - tracker.starting(table.name) - data = openmc.data.IncidentPhoton.from_ace(table) - - # Export HDF5 file - h5_file = args.destination / 'photon' / f'{data.name}.h5' - print(f'Writing {h5_file}...') - data.export_to_hdf5(h5_file, 'w', libver=args.libver) - - # Register with library - library.register_file(h5_file) - # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', 'ENDF/B-VII.1 (MCNP endf71x)') if __name__ == '__main__': diff --git a/src/openmc_data/convert/convert_tendl.py b/src/openmc_data/convert/convert_tendl.py index c0e3f56..40d0328 100755 --- a/src/openmc_data/convert/convert_tendl.py +++ b/src/openmc_data/convert/convert_tendl.py @@ -11,7 +11,7 @@ from urllib.parse import urljoin import openmc.data -from openmc_data import download, extract, calculate_download_size, all_release_details, get_file_types, ProgressTracker +from openmc_data import add_provenance, download, extract, calculate_download_size, all_release_details, get_file_types, ProgressTracker # Make sure Python version is sufficient @@ -165,6 +165,7 @@ def main(): # Write cross_sections.xml library.export_to_xml(args.destination / "cross_sections.xml") + add_provenance(args.destination / "cross_sections.xml", f"TENDL-{args.release}") if __name__ == "__main__": diff --git a/src/openmc_data/generate/generate_cendl.py b/src/openmc_data/generate/generate_cendl.py index a0ff41f..78e107a 100755 --- a/src/openmc_data/generate/generate_cendl.py +++ b/src/openmc_data/generate/generate_cendl.py @@ -11,7 +11,7 @@ from urllib.parse import urljoin import openmc.data -from openmc_data import download, extract, process_neutron, state_download_size, ProgressTracker +from openmc_data import add_provenance, download, extract, process_neutron, state_download_size, ProgressTracker class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, @@ -155,6 +155,7 @@ def main(): # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', f'CENDL-{args.release}') if __name__ == '__main__': diff --git a/src/openmc_data/generate/generate_endf.py b/src/openmc_data/generate/generate_endf.py index 5864b34..76f059e 100755 --- a/src/openmc_data/generate/generate_endf.py +++ b/src/openmc_data/generate/generate_endf.py @@ -16,7 +16,7 @@ from shutil import rmtree, copy, copyfileobj import openmc.data -from openmc_data import download, process_neutron, process_thermal, state_download_size, ProgressTracker +from openmc_data import add_provenance, download, process_neutron, process_thermal, state_download_size, ProgressTracker # Make sure Python version is sufficient assert sys.version_info >= (3, 6), "Python 3.6+ is required" @@ -504,6 +504,7 @@ def main(): # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', f'ENDF/B-{args.release.upper()}') if __name__ == '__main__': diff --git a/src/openmc_data/generate/generate_fendl.py b/src/openmc_data/generate/generate_fendl.py index 4945d33..58782a4 100644 --- a/src/openmc_data/generate/generate_fendl.py +++ b/src/openmc_data/generate/generate_fendl.py @@ -12,7 +12,7 @@ from urllib.parse import urljoin import openmc.data -from openmc_data import download, extract, process_neutron, state_download_size, all_release_details, ProgressTracker +from openmc_data import add_provenance, download, extract, process_neutron, state_download_size, all_release_details, ProgressTracker class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, @@ -124,6 +124,7 @@ def main(): # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', f'FENDL-{args.release}') if __name__ == '__main__': diff --git a/src/openmc_data/generate/generate_jeff.py b/src/openmc_data/generate/generate_jeff.py index d5b9e2b..a7c5412 100644 --- a/src/openmc_data/generate/generate_jeff.py +++ b/src/openmc_data/generate/generate_jeff.py @@ -47,7 +47,7 @@ from tempfile import TemporaryDirectory import warnings -from openmc_data import download, extract, process_neutron, process_thermal, ProgressTracker +from openmc_data import add_provenance, download, extract, process_neutron, process_thermal, ProgressTracker from openmc_data.urls_jeff import jeff_endf_details, jeff33_replacements from openmc_data.utils import _file_md5 @@ -170,7 +170,7 @@ def _process_task(particle, paths, output, libver, temperatures): raise RuntimeError(f'Failed processing {particle}: {paths}') from exc -def _generate(tasks, destination, args): +def _generate(tasks, destination, args, notes=()): import openmc.data destination.parent.mkdir(parents=True, exist_ok=True) @@ -213,6 +213,7 @@ def _generate(tasks, destination, args): for entry, relative in zip(root.findall('library'), outputs): entry.set('path', relative.as_posix()) tree.write(manifest, encoding='utf-8', xml_declaration=True) + add_provenance(manifest, f'JEFF-{args.release}', notes) destination.mkdir(parents=True, exist_ok=True) # Old data remain untouched on processing/validation failure. Once publishing @@ -281,7 +282,8 @@ def main(argv=None): for n, t in details['thermal']['pairs']) if not tasks: raise ValueError('No evaluations selected for generation') - _generate(tasks, destination, args) + _generate(tasks, destination, args, + [f'Not JEFF data: {name} replaced with TENDL-2019' for name in substituted]) if args.cleanup: for group in prepared: for root, enabled in ((archives, args.download), (inputs, args.extract)): diff --git a/src/openmc_data/generate/generate_jendl.py b/src/openmc_data/generate/generate_jendl.py index d130b10..fac0157 100755 --- a/src/openmc_data/generate/generate_jendl.py +++ b/src/openmc_data/generate/generate_jendl.py @@ -12,7 +12,7 @@ from urllib.parse import urljoin import openmc.data -from openmc_data import apply_updates, download, extract, process_neutron, process_thermal, state_download_size, all_release_details, ProgressTracker +from openmc_data import add_provenance, apply_updates, download, extract, process_neutron, process_thermal, state_download_size, all_release_details, ProgressTracker class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, @@ -250,6 +250,7 @@ def main(argv=None): # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', f'JENDL-{args.release}') if __name__ == '__main__': diff --git a/src/openmc_data/generate/generate_tendl.py b/src/openmc_data/generate/generate_tendl.py index c7edf74..5745ecb 100644 --- a/src/openmc_data/generate/generate_tendl.py +++ b/src/openmc_data/generate/generate_tendl.py @@ -12,7 +12,7 @@ from urllib.parse import urljoin import openmc.data -from openmc_data import download, extract, process_neutron, state_download_size, all_release_details, ProgressTracker +from openmc_data import add_provenance, download, extract, process_neutron, state_download_size, all_release_details, ProgressTracker class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter, @@ -160,6 +160,7 @@ def endf_to_h5_name(endf_filename): # Write cross_sections.xml library.export_to_xml(args.destination / 'cross_sections.xml') + add_provenance(args.destination / 'cross_sections.xml', f'TENDL-{args.release}') if __name__ == '__main__': diff --git a/src/openmc_data/other/combine_libraries.py b/src/openmc_data/other/combine_libraries.py index 952ec35..85418de 100755 --- a/src/openmc_data/other/combine_libraries.py +++ b/src/openmc_data/other/combine_libraries.py @@ -1,12 +1,16 @@ #!/usr/bin/env python3 import argparse +from collections import Counter from pathlib import Path +import re import shutil import numpy as np import openmc.data +from openmc_data import add_provenance + def library_in_list(lib, lib_list): """Returns whether the given nuclide library is present in the given list of libraries. @@ -21,8 +25,35 @@ def library_in_list(lib, lib_list): return False +def recorded_provenance(path): + """Return the data source and extra notes from a cross_sections.xml comment""" + text = Path(path).read_text(encoding='utf-8') + match = re.search(r'\s*`` and ```` elements of + cross_sections.xml, in both the C++ (pugixml) and Python (ElementTree) + readers, and both skip XML comments, so the comment does not change how the + library loads. ``openmc.data.DataLibrary`` does not keep comments when it + rewrites a file, so a combined cross_sections.xml must be annotated again. + + Parameters + ---------- + path : str or pathlib.Path + cross_sections.xml to annotate in place + source : str + Evaluated library the data come from, e.g. "JEFF-4.0" + notes : iterable of str + Further lines, e.g. evaluations taken from another library + """ + from . import __version__ + + path = Path(path) + counts = Counter(e.get('type') for e in ET.parse(path).getroot().iter('library')) + contents = ', '.join(f'{n} {kind}' for kind, n in sorted(counts.items())) or 'none' + lines = [ + f'Data source: {source}', + f'Contents: {contents}', + f'Generated by: openmc_data {__version__} ({Path(sys.argv[0]).name})', + f'Date: {datetime.now(timezone.utc):%Y-%m-%d} (UTC)', + *notes, + ] + for line in lines: + # "--" is not allowed inside an XML comment + if '--' in line or line.endswith('-'): + raise ValueError(f'Provenance line cannot be an XML comment: {line!r}') + comment = '\n' + + text = path.read_text(encoding='utf-8') + root = text.index('\n\n") + with pytest.raises(ValueError, match="XML comment"): + openmc_data.add_provenance(xml, "JEFF-4.0", ["run with --release 4.0"]) + assert "