Some changes in data scripts

This commit is contained in:
Paul Romano 2017-07-19 11:54:56 -05:00
parent cd185bb33d
commit 92d951e080
2 changed files with 42 additions and 55 deletions

View file

@ -1,5 +1,11 @@
#!/usr/bin/env python
"""
Download ENDF/B-VII.1 incident neutron ACE data and incident photon ENDF data
from NNDC and convert it to an HDF5 library for use with OpenMC. This data is
used for OpenMC's regression test suite.
"""
from __future__ import print_function
import os
import shutil
@ -16,29 +22,22 @@ from six.moves.urllib.request import urlopen
import openmc.data
description = """
Download ENDF/B-VII.1 ACE data from NNDC and convert it to an HDF5 library for
use with OpenMC. This data is used for OpenMC's regression test suite.
"""
class CustomFormatter(argparse.ArgumentDefaultsHelpFormatter,
argparse.RawDescriptionHelpFormatter):
pass
parser = argparse.ArgumentParser(
description=description,
description=__doc__,
formatter_class=CustomFormatter
)
parser.add_argument('-b', '--batch', action='store_true',
help='supresses standard in')
parser.add_argument('-p', '--photo', default='generate_true',
help='Whether to include photo-atomic interaction data')
parser.add_argument('-n', '--neutron-only', action='store_false',
help='Whether to exclude photon interaction/atomic data')
args = parser.parse_args()
baseUrl = 'http://www.nndc.bnl.gov/endf/b7.1/aceFiles/'
base_url = 'http://www.nndc.bnl.gov/endf/b7.1/aceFiles/'
files = ['ENDF-B-VII.1-neutron-293.6K.tar.gz',
'ENDF-B-VII.1-tsl.tar.gz']
checksums = ['9729a17eb62b75f285d8a7628ace1449',
@ -48,10 +47,10 @@ block_size = 16384
# ==============================================================================
# DOWNLOAD FILES FROM NNDC SITE
filesComplete = []
files_complete = []
for f in files:
# Establish connection to URL
url = baseUrl + f
url = base_url + f
req = urlopen(url)
# Get file size from header
@ -65,15 +64,15 @@ for f in files:
if os.path.exists(f):
if os.path.getsize(f) == file_size:
print('Skipping ' + f)
filesComplete.append(f)
files_complete.append(f)
continue
else:
overwrite = input('Overwrite {0}? ([y]/n) '.format(f))
overwrite = input('Overwrite {}? ([y]/n) '.format(f))
if overwrite.lower().startswith('n'):
continue
# Copy file to disk
print('Downloading {0}... '.format(f), end='')
print('Downloading {}... '.format(f), end='')
with open(f, 'wb') as fh:
while True:
chunk = req.read(block_size)
@ -84,7 +83,7 @@ for f in files:
downloaded, downloaded * 100. / file_size)
print(status + chr(8)*len(status), end='')
print('')
filesComplete.append(f)
files_complete.append(f)
# ==============================================================================
# VERIFY MD5 CHECKSUMS
@ -102,13 +101,13 @@ for f, checksum in zip(files, checksums):
# EXTRACT FILES FROM TGZ
for f in files:
if f not in filesComplete:
if f not in files_complete:
continue
# Extract files
suffix = f[f.rindex('-') + 1:].rstrip('.tar.gz')
with tarfile.open(f, 'r') as tgz:
print('Extracting {0}...'.format(f))
print('Extracting {}...'.format(f))
tgz.extractall(path='nndc/' + suffix)
# Move ACE files down one level
@ -143,7 +142,7 @@ else:
if not response or response.lower().startswith('y'):
for f in files:
if os.path.exists(f):
print('Removing {0}...'.format(f))
print('Removing {}...'.format(f))
os.remove(f)
# ==============================================================================
@ -162,8 +161,7 @@ subprocess.call([ace2hdf5, '-d', 'nndc_hdf5', '--fission_energy_release',
fer_file] + ace_files)
# Generate photo interaction library files
if args.photo == 'generate_true':
if not args.neutron_only:
pwd = os.path.dirname(os.path.realpath(__file__))
photo_endf = os.path.join(pwd, 'openmc-get-photo-endf71')
subprocess.call([photo_endf, '-c', 'nndc_hdf5/cross_sections.xml'])