Skip to content

Commit

Permalink
Sensitivity script can also analyse *amounts.txt files now
Browse files Browse the repository at this point in the history
  • Loading branch information
Hemaditya Malla committed Oct 24, 2023
1 parent f47455c commit 6e30da4
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions tools/sensitivity_analyze_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,35 @@
description='''Script to analyze results from a sensitivity study
Authors: Hemaditya Malla, Jannis Teunissen''')
parser.add_argument('logs', type=str, nargs='+',
help='Log/rates files')
help='Log/amounts files')
parser.add_argument('-y', type=str, nargs='+', default=["sum(n_e)"],
help='Variables in the log files to compare')
parser.add_argument('-time_index', type=int, default=-1,
help='Which time index in the log files to consider')
args = parser.parse_args()

logs = sorted(args.logs)
print(logs)
logs_df = [pd.read_csv(f, delim_whitespace=True) for f in args.logs]

# Determine whether we analyse log files(pandas dataframe) or species amounts(txt files)
if not all([x.endswith('amounts.txt') for x in logs]):
logs_df = [pd.read_csv(f, delim_whitespace=True) for f in args.logs]
base_name = logs[0].replace('_log.txt', '')
else:
# Can we use the below variable elsewhere below?
analyse_chemistry = True
# Make sure that the default argument is changed
if args.y[0] == "sum(n_e)":
args.y = ["e"]

# Loading the species list and appending the time column to it
base_name = logs[0].replace('_amounts.txt', '')
with open(base_name + '_species.txt', 'r') as f:
species_list = [x.strip() for x in f.readlines() if x.strip()]
species_list.insert(0, "time")

# Load amounts of species and create a dataframe of them so that the below code wont break
logs_df = [pd.DataFrame(np.loadtxt(f), columns=species_list) for f in args.logs]


log_sizes = np.array([len(df) for df in logs_df])
max_size, min_size = log_sizes.max(), log_sizes.min()
Expand Down Expand Up @@ -92,7 +111,7 @@
print(f'{"rank":<6} R{"#":<6} {"reaction_list":40} {"max(mustar)":15}')

# Load reaction names
base_name = logs[0].replace('_log.txt', '')
# base_name = logs[0].replace('_log.txt', '')
with open(base_name + '_reactions.txt', 'r') as f:
reactions_list = [x.strip() for x in f.readlines() if x.strip()]

Expand Down

0 comments on commit 6e30da4

Please sign in to comment.