Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion tools/ALARAJOYWrapper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ To run this preprocessor, the user must first have acquired TENDL files for each

Running ALARAJOYWrapper can be done with one Python command:
```
python preprocess_fendl3.py -f /path/to/fendl3_data_dir/ -d /path/to/eaf_decay_library/ -a
python preprocess_fendl3.py -f /path/to/fendl3_data_dir/ -d /path/to/eaf_decay_library/ -a -t -r
```
To read in detail about each of these arguments, call this command:
```
Expand Down
6 changes: 4 additions & 2 deletions tools/ALARAJOYWrapper/njoy_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,10 @@ def run_njoy(element, A, matb, file_capture):
}

# Run NJOY
result = subprocess.run(['njoy'], input=open(INPUT).read(),
text=True, capture_output=True)
with open(INPUT, 'r') as f:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logger was capturing a ResourceWarning from the previous way we were opening the input, so this change is simply to done to resolve that because it was unnecessary to have in the first place.

result = subprocess.run(
['njoy'], stdin=f, text=True, capture_output=True
)

fileinfo = file_metadata[file_capture]
fileinfo['save'] = None
Expand Down
56 changes: 55 additions & 1 deletion tools/ALARAJOYWrapper/preprocess_fendl3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import argparse
import warnings
import logging
from pathlib import Path
from collections import defaultdict

Expand Down Expand Up @@ -44,8 +45,55 @@ def args():
# Temperature for NJOY run [Kelvin]
'--temperature', '-t', required=False, nargs=1, default=[293.16]
)
parser.add_argument(
'--redirect_warnings', '-r', action='store_true',
help=('''
Optional argument to redirect any non-fatal warnings that may
arise to a log file.
''')
)
return parser.parse_args()

def configure_logging(redirect_warnings=False):
"""
Configure a logger to redirect output messages away from the terminal.

Arguments:
redirect_warnings (bool, optional): Option to redirect warning
messages to a separate 'warnings.log' file to avoid cluttering
the terminal with non-fatal warnings.

Returns:
None
"""

logger = logging.getLogger()
logger.setLevel(logging.INFO)

formatter = logging.Formatter(
'%(asctime)s - %(levelname)s: \n\t%(message)s',
datefmt='%Y-%m-%d %H:%M:%S'
)

console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)

if redirect_warnings:
console_handler.setLevel(logging.INFO)
console_handler.addFilter(lambda record: record.levelno < logging.WARNING)

warning_log = Path('warnings.log')
warning_log.unlink(missing_ok=True)

file_handler = logging.FileHandler(warning_log)
file_handler.setLevel(logging.WARNING)
file_handler.setFormatter(formatter)

logger.addHandler(file_handler)
warnings.simplefilter('always')
logging.captureWarnings(True)

logger.addHandler(console_handler)

def process_pendf(
njoy_prep_input, material_id, MTs, pKZA, mt_dict, temperature, tendl_path
Expand Down Expand Up @@ -160,7 +208,7 @@ def process_gendf(
diffs = sorted(MTs - gendf_MTs)
warnings.warn(
f'GENDF file missing MTs {diffs} present in the ' \
'original TENDL file.'
f'original TENDL file for {element}-{A}.'
)
if gendf_MTs:
all_rxns = tp.iterate_MTs(
Expand Down Expand Up @@ -322,6 +370,12 @@ def main():
Main method when run as a command line script.
"""

warnings.formatwarning = (
lambda msg, cat, fname, lineno, file=None, line=None:
f"{Path(fname).name}:{lineno}: {cat.__name__}: {msg}\n"
)
configure_logging(args().redirect_warnings)

TAPE20 = Path('tape20')

dir = njt.set_directory()
Expand Down
Loading