Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FENDL-3.2b Retrofitting #42

Draft
wants to merge 59 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
dbef6ca
First commit for FENDL3.2B retrofitting
Jun 14, 2024
cdd7bcd
Replacing NJOY Bash script with subprocess execution in Python
Jun 17, 2024
f3d010f
Simplifying mass number formatting in tendl_download() function
Jun 17, 2024
6c5ac24
Simplifying endf_specs() function
Jun 17, 2024
03e3af3
Remove now-obsolete ENDFtk warning suppression
Jun 17, 2024
fa4f29e
Simplify tendl_download() function using data structures
Jun 17, 2024
0190096
Switching tendl_download() function over to urllib dependence
Jun 17, 2024
413ae46
Moving card deck formatting from Pandas DataFrame to dictionary
Jun 17, 2024
2eb9ffd
Separating out a write function for the GROUPR input from the input c…
Jun 17, 2024
1247db3
Removing now-obsolete Pandas dependence
Jun 17, 2024
1d35b79
Simplifying card writing for groupr_input_file_writer()
eitan-weinstein Jun 18, 2024
de3cbb4
Fixing indexing on groupr_input_file_writer()
Jun 18, 2024
d20eed8
Storing elements in a single dictionary to be referenced across both …
Jun 18, 2024
58a4ede
Removing now-obsolete ENDFtk warning supression from gend_tools.py an…
Jun 18, 2024
b83be55
Updating gendf_download() function -- notably switching away from wge…
Jun 18, 2024
e135311
Switching CSV reading from Pandas DataFrame to dictionary
Jun 18, 2024
29528dd
Moving away from direct input to argparse input/options
Jun 18, 2024
0abb51b
Expanding argparse usage
Jun 18, 2024
582424b
Moving away from print statements towards logging
Jun 18, 2024
77e9a65
Removed unnecessary file from file cleanup list
Jun 19, 2024
493a35c
Expanding logger to capture 'No bottleneck testing available' message
Jun 19, 2024
a29bd66
Improving readability of NJOY run message for logger
Jun 19, 2024
69fe5f0
Updating the logging to redirect ENDFtk messages to the logger and re…
Jun 21, 2024
d0f7d3b
Removing stand-alone groupr script -- unnecessary and not called indi…
Jun 21, 2024
4318ae4
Reorganizing folder structure -- separate GROUPR folder no longer see…
Jun 21, 2024
b1b63f9
Finalizing move out of GROUPR/
Jun 21, 2024
1edd251
Moving the rest of fendl3_gendf.py to the main() function
Jun 21, 2024
fb2d548
Forgot to include mt_table in main()
Jun 21, 2024
4065d00
Streamlining endf_specs usage and placement.
Jun 24, 2024
4250c44
Removing direct GENDF download function -- all downloads need to be p…
Jun 24, 2024
93d469f
Moving GROUPR parameters to global constants.
Jun 24, 2024
98dcc93
Logging error if NJOY run is unsuccessful.
Jun 24, 2024
2460d72
Cleaning up package imports
Jun 24, 2024
6fcf5e5
Removing unnecessary package imports on fendl3_gendf.py
Jun 24, 2024
5ec6bbf
Fixing KZA formatting.
Jun 26, 2024
f490d38
Addressing low-level comments from most recent review.
Jul 1, 2024
45df27f
Improving readability
Jul 1, 2024
b76634f
Beginning high-level overhaul and restructuring
Jul 1, 2024
121e57a
Improving readability for nuclear_decay()
Jul 1, 2024
fb1b796
Increasing readability of argparser
Jul 1, 2024
c8e6cea
Major overhaul of modularity and including functionality for iteratin…
Jul 9, 2024
4d99f41
Removing time package.
Jul 9, 2024
e0529dc
Removing specific example file from GENDF files.
Jul 9, 2024
cc064b6
Making the file saving more versatile.
Jul 9, 2024
14c5730
Responding to a majority of the high-level comments from Tuesday's re…
Jul 11, 2024
95815b2
Fixing docstring for ensure_gendf_markers() function.
Jul 11, 2024
a5997b5
Improving isotope identification methods.
Jul 12, 2024
f83a646
Improving isotope identification methods.
Jul 12, 2024
98f23c3
Simplifying logging method and usage.
Jul 12, 2024
498c824
One more logging fix.
Jul 12, 2024
a807f1e
Completing response to last review and making arg processing more mod…
Jul 16, 2024
76b9aa1
Improving ability to iterate over all elements.
Jul 16, 2024
eebeea3
Fixing minor bug in execution of handle_TENDL_downloads().
Jul 16, 2024
912530f
Small formatting change to fit in max line length.
Jul 16, 2024
c374494
More minor formatting adjustments and simplifying the line length set…
Jul 16, 2024
f50b617
Allowing for fendle_retrofit.py to be executed from DataLib.
Jul 16, 2024
4ba725e
Removing unnecessary print statement.
Jul 17, 2024
6257033
Ensuring that NJOY output is properly handled when program is execute…
Jul 17, 2024
4921dba
Small formatting changes before moving over to project individual PRs.
Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/DataLib/fendl32B_retrofit/activation_analysis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Import packages
import pandas as pd
from tendl_preprocessing import extract_cross_sections

def iterate_MTs(MTs, file_obj, mt_dict, pKZA):
# Initialize lists
cross_sections_by_MT = []
emitted_particles_list = []
dKZAs = []
groups = []

# Extract data for each MT
for MT in MTs:
sigma_list = extract_cross_sections(file_obj, MT)
if not sigma_list:
continue
dKZA = pKZA - mt_dict[str(MT)]['delKZA']
emitted_particles = mt_dict[str(MT)]['Emitted Particles']
if dKZA is None:
continue
cross_sections_by_MT.append(sigma_list)
dKZAs.append(dKZA)
emitted_particles_list.append(emitted_particles)
groups.append(len(sigma_list))


# Store data in a Pandas DataFrame
gendf_data = pd.DataFrame({
'Parent KZA': [pKZA] * len(dKZAs),
'Daughter KZA': dKZAs,
'Emitted Particles': emitted_particles_list,
'Non-Zero Groups' : groups,
'Cross Sections': cross_sections_by_MT
})

return gendf_data
172 changes: 172 additions & 0 deletions src/DataLib/fendl32B_retrofit/fendl3_retrofit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Import packages
import tendl_preprocessing as tpp
import activation_analysis
from logging_config import logger
import groupr_tools
import sys
import argparse
import asyncio
import pandas as pd
import reaction_data as rxd

def fendl_args():
"""
Configure Argument Parser for the FENDL 3.2-b/TENDL 2017 retroffiting,
including options for user input of GENDF files that have already
been processed using the NJOY GROUPR module or downloading and
processing TENDL/PENDF files from the TENDL 2017 database.

Note: If the user opts to select the "Loclal file input" option,
they must ensure that the GENDF file is properly formatted and
contains activation, and not transport data, themselves.

Arguments:
None

Returns:
args (argparse.Namespace): Argparse object that contains the user
specified arguments for executing the program.
"""

parser = argparse.ArgumentParser()

# Subparsers for 'I' and 'D'
subparsers = parser.add_subparsers(dest='method', required=True)
parser_I = subparsers.add_parser('I', help='''Local file input.
Note: This option should only be
selected if the user already has
properly formatted GENDF activation
files that have been processed using
the NJOY GROUPR module for a
Vitmain-J group structure with a
Vitamin-E weight function.''')
parser_I.add_argument('--paths', '-p',
required=True,
nargs= '+',
help='Path to the local GENDF file.')
parser_D = subparsers.add_parser('D', help='''Download TENDL/PENDF files
from the TENDL 2017 neutron activation
database.''')
parser_D.add_argument('--element', '-e',
required=True,
help= 'Chemical symbol for selected element (i.e. Ti).')
parser_D.add_argument('--A', '-a',
required=True,
help= '''Mass number for selected isotope (i.e. 48).
If the target is an isomer, type
"m" after the mass number (i.e. 48m).
To automatically iterate over all of
the isotopes for the target element,
select "all" as the option for --A.
''')

args = parser.parse_args()
return args

def handle_local_file_input(mt_dict, cumulative_data, gendf_paths = None, args = None):
"""
Method for extracting and analyzing data from preprocessed GENDF files
that the user already has saved locally. Called when the argument
for the main function -- fendl3_2b_retrofit() -- is specified as 'I'.

Arguments:
args (argparse.Namespace): Argparse object that contains the user
specified arguments for executing the program.
mt_dict (dict): Dictionary formatted data structure for mt_table.csv
"""

# Format gendf_paths parameter
if gendf_paths is None:
gendf_paths = args.paths
elif type(gendf_paths) is not list:
gendf_paths = [gendf_paths]

for gendf_path in gendf_paths:
# Extract fundamental data from the GENDF file
pKZA = tpp.extract_gendf_pkza(gendf_path)
matb, MTs, file_obj = tpp.extract_endf_specs(gendf_path, 'gendf')

logger.info(f"GENDF file path: {gendf_path}")
logger.info(f"Parent KZA (pKZA): {pKZA}")
logger.info(f'MTs: {MTs}')

# Extract and save specific data for each MT
gendf_data = activation_analysis.iterate_MTs(MTs, file_obj, mt_dict, pKZA)
cumulative_data = pd.concat([cumulative_data, gendf_data], ignore_index= True)
return cumulative_data

def handle_download_file(args, mt_dict, cumulative_df):
"""
Method for downloading ENDF/PENDF files from the TENDL 2017 database,
using the NJOY GROUPR module to convert these to a group-wise file,
and then extracting and analyzing the resultant data. Called when
the argument for the main function -- fendl3_2b_retrofit() --
is specified as 'D'.

Arguments:
args (argparse.Namespace): Argparse object that contains the user
specified arguments for executing the program.
mt_dict (dict): Dictionary formatted data structure for mt_table.csv
"""

# Establish parameters from the user arguments
element = args.element
A = args.A
if A == 'all':
A_vals = asyncio.run(tpp.identify_tendl_isotopes(element))
logger.info(
f'All isotopes of {element} in the TENDL database: {A_vals}'
)
else:
A_vals = [A]

# Iterate over all isotopes/isomers, as specified by arguments
gendf_paths = []
for A in A_vals:
endf_path = tpp.download_tendl(element, A, 'endf')
pendf_path = tpp.download_tendl(element, A, 'pendf')

material_id, MTs = tpp.extract_endf_specs(endf_path, 'endf')

card_deck = groupr_tools.groupr_input_file_format(material_id, MTs,
element, A, mt_dict)
groupr_tools.groupr_input_file_writer(card_deck, MTs)

gendf_path = groupr_tools.run_njoy(card_deck, element, A, material_id)
gendf_paths.append(gendf_path)

groupr_tools.njoy_file_cleanup()
logger.info(f'Finished iterating for {element}-{A} \n \n')

return gendf_paths

##############################################################################

def fendl3_2b_retrofit():
"""
Main method when run as a command line script.
"""

# Initialize arguments, DataFrame to store data, and load in MT reference
args = fendl_args()
gendf_paths = []
cumulative_data = rxd.initialize_dataframe()
mt_dict = rxd.process_mt_table('mt_table.csv')

# Execute file handling
if args.method == 'D':
gendf_paths = handle_download_file(args, mt_dict, cumulative_data)
args = None
cumulative_data = handle_local_file_input(mt_dict,
cumulative_data,
gendf_paths = gendf_paths,
args = args)

# Save to CSV
cumulative_data.to_csv('gendf_data.csv', index=False)
logger.info("Saved gendf_data.csv")

##############################################################################

if __name__ == '__main__':
fendl3_2b_retrofit()
Loading