From 672c71811704b92cf6a00e967fa272ac25031207 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 27 Jan 2020 13:59:04 -0600 Subject: [PATCH] More changes based on view comments in #1455 --- scripts/openmc-make-stopping-powers | 7 ++- scripts/openmc-make-test-data | 2 +- scripts/openmc-plot-mesh-tally | 21 ++++--- scripts/openmc-update-mgxs | 88 +++++++++++++---------------- scripts/openmc-voxel-to-vtk | 2 +- 5 files changed, 55 insertions(+), 65 deletions(-) diff --git a/scripts/openmc-make-stopping-powers b/scripts/openmc-make-stopping-powers index 76ac6686c8..3357f2fe52 100755 --- a/scripts/openmc-make-stopping-powers +++ b/scripts/openmc-make-stopping-powers @@ -24,6 +24,7 @@ with h5py.File('stopping_powers.h5', 'w') as f: # Write energies f.create_dataset('energy', data=energies) + # Look over atomic number; ESTAR only goes up to Z=98 (Californium) for Z in range(1, 99): print('Processing {} data...'.format(ATOMIC_SYMBOL[Z])) @@ -32,9 +33,11 @@ with h5py.File('stopping_powers.h5', 'w') as f: payload = urlencode(data).encode("utf-8") # Retrieve data from ESTAR site - r = urlopen(url=base_url, data=payload).read() + with urlopen(url=base_url, data=payload) as response: + r = response.read() - # Remove text and reformat data + # Remove text and reformat data -- omit first 12 and last 5 lines to get + # only data in table r = html.fromstring(r).xpath('//pre//text()') values = np.fromstring(' '.join(r[12:-5]), sep=' ').reshape((-1, 5)).T diff --git a/scripts/openmc-make-test-data b/scripts/openmc-make-test-data index 571d8ea746..4d26db7fb0 100755 --- a/scripts/openmc-make-test-data +++ b/scripts/openmc-make-test-data @@ -84,7 +84,7 @@ with tempfile.TemporaryDirectory() as tmpdir: print('Converting {}...'.format(os.path.basename(f))) data = openmc.data.IncidentNeutron.from_ace(f) - # Check for fission energy release data + # Check for fission energy release data on MF=1, MT=458 endf_filename = 'neutrons/n-{:03}_{}_{:03}{}.endf'.format( data.atomic_number, data.atomic_symbol, diff --git a/scripts/openmc-plot-mesh-tally b/scripts/openmc-plot-mesh-tally index 6fa3c84f7f..6716b66095 100755 --- a/scripts/openmc-plot-mesh-tally +++ b/scripts/openmc-plot-mesh-tally @@ -21,10 +21,12 @@ import numpy as np from openmc import StatePoint, MeshFilter +_COMBOBOX_SELECTED = '<>' + class MeshPlotter(tk.Frame): def __init__(self, parent, filename): - tk.Frame.__init__(self, parent) + super().__init__(self, parent) self.labels = { 'Cell': 'Cell:', @@ -79,7 +81,7 @@ class MeshPlotter(tk.Frame): for i in self.meshTallies] self.tallyBox.current(0) self.tallyBox.grid(row=0, column=1, sticky=tk.W+tk.E) - self.tallyBox.bind('<>', self.update) + self.tallyBox.bind(_COMBOBOX_SELECTED, self.update) # Planar basis selection labelBasis = tk.Label(self.selectFrame, text='Basis:') @@ -88,14 +90,14 @@ class MeshPlotter(tk.Frame): self.basisBox['values'] = ('xy', 'yz', 'xz') self.basisBox.current(0) self.basisBox.grid(row=1, column=1, sticky=tk.W+tk.E) - self.basisBox.bind('<>', self.update) + self.basisBox.bind(_COMBOBOX_SELECTED, self.update) # Axial level labelAxial = tk.Label(self.selectFrame, text='Axial level:') labelAxial.grid(row=2, column=0, sticky=tk.W) self.axialBox = ttk.Combobox(self.selectFrame, state='readonly') self.axialBox.grid(row=2, column=1, sticky=tk.W+tk.E) - self.axialBox.bind('<>', self.redraw) + self.axialBox.bind(_COMBOBOX_SELECTED, self.redraw) # Option for mean/uncertainty labelMean = tk.Label(self.selectFrame, text='Mean/Uncertainty:') @@ -105,14 +107,14 @@ class MeshPlotter(tk.Frame): 'Relative uncertainty') self.meanBox.current(0) self.meanBox.grid(row=3, column=1, sticky=tk.W+tk.E) - self.meanBox.bind('<>', self.update) + self.meanBox.bind(_COMBOBOX_SELECTED, self.update) # Scores labelScore = tk.Label(self.selectFrame, text='Score:') labelScore.grid(row=4, column=0, sticky=tk.W) self.scoreBox = ttk.Combobox(self.selectFrame, state='readonly') self.scoreBox.grid(row=4, column=1, sticky=tk.W+tk.E) - self.scoreBox.bind('<>', self.redraw) + self.scoreBox.bind(_COMBOBOX_SELECTED, self.redraw) # Filter label boldfont = font.Font(weight='bold') @@ -121,10 +123,7 @@ class MeshPlotter(tk.Frame): labelFilters.grid(row=5, column=0, sticky=tk.W) def update(self, event=None): - if not event: - widget = None - else: - widget = event.widget + widget = event.widget if event else None tally_id = self.meshTallies[self.tallyBox.current()] selectedTally = self.datafile.tallies[tally_id] @@ -188,7 +187,7 @@ class MeshPlotter(tk.Frame): combobox.current(0) combobox.grid(row=count+6, column=1, sticky=tk.W+tk.E) - combobox.bind('<>', self.redraw) + combobox.bind(_COMBOBOX_SELECTED, self.redraw) # If There are no filters, leave a 'None available' message if count == 0: diff --git a/scripts/openmc-update-mgxs b/scripts/openmc-update-mgxs index f78a5dc694..aac6959b7e 100755 --- a/scripts/openmc-update-mgxs +++ b/scripts/openmc-update-mgxs @@ -13,15 +13,11 @@ import numpy as np import openmc.mgxs_library -description = """\ -Update OpenMC's deprecated multi-group cross section XML files to the latest -HDF5-based format.""" - def parse_args(): """Read the input files from the commandline.""" # Create argument parser - parser = argparse.ArgumentParser(description=description, + parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawTextHelpFormatter) parser.add_argument('-i', '--input', type=argparse.FileType('r'), help='input XML file') @@ -52,7 +48,7 @@ def get_data(element, entry): return value -if __name__ == '__main__': +def main(): args = parse_args() # Parse the XML data. @@ -60,17 +56,16 @@ if __name__ == '__main__': root = tree.getroot() # Get old metadata - temp = tree.find('group_structure').text.strip() - temp = np.array(temp.split()) - group_structure = temp.astype(np.float) + group_structure = tree.find('group_structure').text.strip() + group_structure = np.array(group_structure.split(), dtype=float) # Convert from MeV to eV group_structure *= 1.e6 energy_groups = openmc.mgxs.EnergyGroups(group_structure) - temp = tree.find('inverse-velocity') - if temp is not None: - temp = temp.text.strip() - temp = np.array(temp.split()) - inverse_velocity = temp.astype(np.float) + + inverse_velocity = tree.find('inverse-velocity') + if inverse_velocity is not None: + inverse_velocity = inverse_velocity.text.split() + inverse_velocity = np.array(inverse_velocity, dtype=float) else: inverse_velocity = None @@ -83,8 +78,7 @@ if __name__ == '__main__': temperature = get_data(xsdata_elem, 'kT') if temperature is not None: - temperature = \ - float(temperature) / openmc.data.K_BOLTZMANN * 1.E6 + temperature = float(temperature) / openmc.data.K_BOLTZMANN * 1.E6 else: temperature = 294. temperatures = [temperature] @@ -108,8 +102,8 @@ if __name__ == '__main__': tab_leg = get_data(xsdata_elem, 'tabular_legendre') if tab_leg is not None: - warnings.Warning('The tabular_legendre option has moved to the ' - 'settings.xml file and must be added manually') + warnings.warn('The tabular_legendre option has moved to the ' + 'settings.xml file and must be added manually') # Either add the data to a previously existing xsdata (if it is # for the same 'name' but a different temperature), or create a @@ -140,25 +134,22 @@ if __name__ == '__main__': if i != -1: xsd[i].add_temperature(temperature) - temp = get_data(xsdata_elem, 'total') - if temp is not None: - temp = np.array(temp.split(), dtype=float) - total = temp.astype(np.float) + total = get_data(xsdata_elem, 'total') + if total is not None: + total = np.array(total.split(), dtype=float) total.shape = xsd[i].xs_shapes['[G]'] xsd[i].set_total(total, temperature) if inverse_velocity is not None: xsd[i].set_inverse_velocity(inverse_velocity, temperature) - temp = get_data(xsdata_elem, 'absorption') - temp = np.array(temp.split()) - absorption = temp.astype(np.float) + absorption = get_data(xsdata_elem, 'absorption') + absorption = np.array(absorption.split(), dtype=float) absorption.shape = xsd[i].xs_shapes['[G]'] xsd[i].set_absorption(absorption, temperature) - temp = get_data(xsdata_elem, 'scatter') - temp = np.array(temp.split()) - scatter = temp.astype(np.float) + scatter = get_data(xsdata_elem, 'scatter') + scatter = np.array(scatter.split(), dtype=float) # This is now a flattened-array of something that started with a # shape of [Order][G][G']; we need to unflatten and then switch the # ordering @@ -176,40 +167,35 @@ if __name__ == '__main__': xsd[i].set_scatter_matrix(scatter, temperature) - temp = get_data(xsdata_elem, 'multiplicity') - if temp is not None: - temp = np.array(temp.split()) - multiplicity = temp.astype(np.float) + multiplicity = get_data(xsdata_elem, 'multiplicity') + if multiplicity is not None: + multiplicity = np.array(multiplicity.split(), dtype=float) multiplicity.shape = xsd[i].xs_shapes["[G][G']"] xsd[i].set_multiplicity_matrix(multiplicity, temperature) - temp = get_data(xsdata_elem, 'fission') - if temp is not None: - temp = np.array(temp.split()) - fission = temp.astype(np.float) + fission = get_data(xsdata_elem, 'fission') + if fission is not None: + fission = np.array(fission.split(), dtype=float) fission.shape = xsd[i].xs_shapes['[G]'] xsd[i].set_fission(fission, temperature) - temp = get_data(xsdata_elem, 'kappa_fission') - if temp is not None: - temp = np.array(temp.split()) - kappa_fission = temp.astype(np.float) + kappa_fission = get_data(xsdata_elem, 'kappa_fission') + if kappa_fission is not None: + kappa_fission = np.array(kappa_fission.split(), dtype=float) kappa_fission.shape = xsd[i].xs_shapes['[G]'] xsd[i].set_kappa_fission(kappa_fission, temperature) - temp = get_data(xsdata_elem, 'chi') - if temp is not None: - temp = np.array(temp.split()) - chi = temp.astype(np.float) + chi = get_data(xsdata_elem, 'chi') + if chi is not None: + chi = np.array(chi.split(), dtype=float) chi.shape = xsd[i].xs_shapes['[G]'] xsd[i].set_chi(chi, temperature) else: chi = None - temp = get_data(xsdata_elem, 'nu_fission') - if temp is not None: - temp = np.array(temp.split()) - nu_fission = temp.astype(np.float) + nu_fission = get_data(xsdata_elem, 'nu_fission') + if nu_fission is not None: + nu_fission = np.array(nu_fission.split(), dtype=float) if chi is not None: nu_fission.shape = xsd[i].xs_shapes['[G]'] else: @@ -218,7 +204,9 @@ if __name__ == '__main__': # Build library as we go, but first we have enough to initialize it lib = openmc.MGXSLibrary(energy_groups) - lib.add_xsdatas(xsd) - lib.export_to_hdf5(args['output']) + + +if __name__ == '__main__': + main() diff --git a/scripts/openmc-voxel-to-vtk b/scripts/openmc-voxel-to-vtk index c7f5ffa1a1..33251144fb 100755 --- a/scripts/openmc-voxel-to-vtk +++ b/scripts/openmc-voxel-to-vtk @@ -8,7 +8,7 @@ import numpy as np import h5py import vtk -_min_version = (2,0) +_min_version = (2, 0) def main():