From 06ccbcbd2b4a9ae75b84fb6d631293dcc6140c42 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 19 Jan 2024 14:09:55 -0600 Subject: [PATCH 1/2] Updating file extension for excel files when exporting MGXS data --- openmc/mgxs/mdgxs.py | 4 ++-- openmc/mgxs/mgxs.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openmc/mgxs/mdgxs.py b/openmc/mgxs/mdgxs.py index c9d76bc1080..58f6a2d2f75 100644 --- a/openmc/mgxs/mdgxs.py +++ b/openmc/mgxs/mdgxs.py @@ -743,9 +743,9 @@ def export_xs_data(self, filename='mgxs', directory='mgxs', df.to_csv(filename + '.csv', index=False) elif format == 'excel': if self.domain_type == 'mesh': - df.to_excel(filename + '.xls') + df.to_excel(filename + '.xlsx') else: - df.to_excel(filename + '.xls', index=False) + df.to_excel(filename + '.xlsx', index=False) elif format == 'pickle': df.to_pickle(filename + '.pkl') elif format == 'latex': diff --git a/openmc/mgxs/mgxs.py b/openmc/mgxs/mgxs.py index b6840d079ce..2eb7f275649 100644 --- a/openmc/mgxs/mgxs.py +++ b/openmc/mgxs/mgxs.py @@ -2001,9 +2001,9 @@ def export_xs_data(self, filename='mgxs', directory='mgxs', df.to_csv(filename + '.csv', index=False) elif format == 'excel': if self.domain_type == 'mesh': - df.to_excel(filename + '.xls') + df.to_excel(filename + '.xlsx') else: - df.to_excel(filename + '.xls', index=False) + df.to_excel(filename + '.xlsx', index=False) elif format == 'pickle': df.to_pickle(filename + '.pkl') elif format == 'latex': From a788cb3b20b12861b1dd5ea2cb67bdb2570e67e3 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 19 Jan 2024 14:15:02 -0600 Subject: [PATCH 2/2] Add test for excel writing of MGXS data --- setup.py | 2 +- tests/regression_tests/mgxs_library_hdf5/test.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 29c129d7b28..eeb0b3f293c 100755 --- a/setup.py +++ b/setup.py @@ -71,7 +71,7 @@ 'depletion-mpi': ['mpi4py'], 'docs': ['sphinx', 'sphinxcontrib-katex', 'sphinx-numfig', 'jupyter', 'sphinxcontrib-svg2pdfconverter', 'sphinx-rtd-theme'], - 'test': ['pytest', 'pytest-cov', 'colorama'], + 'test': ['pytest', 'pytest-cov', 'colorama', 'openpyxl'], 'vtk': ['vtk'], }, # Cython is used to add resonance reconstruction and fast float_endf diff --git a/tests/regression_tests/mgxs_library_hdf5/test.py b/tests/regression_tests/mgxs_library_hdf5/test.py index 2f3c9d149de..06625c25f9e 100644 --- a/tests/regression_tests/mgxs_library_hdf5/test.py +++ b/tests/regression_tests/mgxs_library_hdf5/test.py @@ -54,6 +54,11 @@ def _get_results(self, hash_output=False): # Export the MGXS Library to an HDF5 file self.mgxs_lib.build_hdf5_store(directory='.') + # Test export of the MGXS Library to an Excel spreadsheet + for mgxs in self.mgxs_lib.all_mgxs.values(): + for xs in mgxs.values(): + xs.export_xs_data('mgxs', xs_type='macro', format='excel') + # Open the MGXS HDF5 file with h5py.File('mgxs.h5', 'r') as f: @@ -76,9 +81,8 @@ def _get_results(self, hash_output=False): def _cleanup(self): super()._cleanup() - f = 'mgxs.h5' - if os.path.exists(f): - os.remove(f) + files = ['mgxs.h5', 'mgxs.xlsx'] + (os.remove(f) for f in files if os.path.exists(f)) def test_mgxs_library_hdf5():