-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Fiorito Luca
committed
Aug 19, 2022
1 parent
ffb8795
commit 4bd7ef3
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .mctal import * | ||
from .meshtal import * | ||
from .output_file import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import re | ||
from io import StringIO | ||
|
||
import pandas as pd | ||
|
||
|
||
__author__ = "Luca Fiorito" | ||
|
||
__all__ = [ | ||
"get_keff", | ||
"get_table140", | ||
] | ||
|
||
|
||
def get_keff(file): | ||
with open(file, 'r') as f: | ||
text = f.read() | ||
PATTERN = "final estimate.*= (?P<keff>[\.0-9]+).*?(?P<stdev>[\.0-9]+)" | ||
match = re.search(PATTERN, text) | ||
keff = float(match.group("keff")) | ||
std = float(match.group("stdev")) | ||
return {"KEFF": keff, "ERR": std} | ||
|
||
|
||
def get_table140(file): | ||
print(f"reading file '{file}'...") | ||
with open(file, 'r') as f: | ||
text = f.read() | ||
PATTERN = "(?:^1neutron.*table 140\n)(?P<table>(?:.*\n)+?)(?P<end>^\s+total\s{20})" | ||
match = re.search(PATTERN, text, re.MULTILINE).group("table") | ||
widths=[10, 9, 11, 9,] + [12] * 6 | ||
dtypes = [int, int, str, float, int, float, float, float, float, int] | ||
names = pd.read_fwf( | ||
StringIO(match), | ||
widths=widths, | ||
skip_blank_lines=True, | ||
nrows=2, | ||
header=None, | ||
).fillna("").apply(lambda col: " ".join(col).strip()) | ||
df = pd.read_fwf( | ||
StringIO(match), | ||
widths=widths, | ||
skip_blank_lines=True, | ||
skiprows=3, | ||
names=names, | ||
).ffill() | ||
return df.astype(dict(zip(names, dtypes))) |