-
Notifications
You must be signed in to change notification settings - Fork 3
/
parse_srun.py
78 lines (66 loc) · 2.71 KB
/
parse_srun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import numpy as np
def parse_srun(fn,debug_flag=0):
"""
% (C) Nick Holschuh - Amherst College -- 2022 (Nick.Holschuh@gmail.com)
%
% This function will parse the results of the inverse model statistics
% from icepack
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are:
%
% fn -- .out filename to parse
%
%%%%%%%%%%%%%%%
% The outputs are:
%
% stats: the statistics of the optimization problem
% meta: metadata about the performance of the inverse solver
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
"""
with open(fn) as f:
lines = f.readlines() # list containing lines of file
i = 1
columns1 = [];
columns2 = [];
temp_data2 = [];
debug_list = []
for ind0,line in enumerate(lines):
line = line.strip() # remove leading/trailing white spaces
if debug_flag == 2:
print(ind0,'-',line)
############################ Here, we pull out the values from X
if ind0 == 30:
columns1 = [item.strip() for item in line.split()]
elif ind0>46:
temp_data = [item.strip() for item in line.split()]
if len(temp_data) == len(columns1):
if 'data1' not in locals():
data1 = np.expand_dims(np.array(temp_data).astype(float),1).T
else:
data1 = np.concatenate([data1,np.expand_dims(np.array(temp_data).astype(float),0)],axis=0)
if ind0 > 32:
temp_columns = [item.strip() for item in line.split(':')]
if len(temp_columns) == 2:
if temp_columns[0][0:5] != 'Inter':
if ind0 < 46:
columns2.append(temp_columns[0])
temp_data2.append(temp_columns[1])
if len(temp_data2) == 12:
if 'data2' not in locals():
data2 = np.expand_dims(np.array(temp_data2).astype(float),1).T
else:
data2 = np.concatenate([data2,np.expand_dims(np.array(temp_data2).astype(float),0)],axis=0)
debug_list.append([ind0,temp_columns[0]])
temp_data2 = [];
if debug_flag == 1:
if ind0> 141:
if ind0 < 157:
print(line)
print(temp_columns)
print(temp_data2)
pass
stats = {'values': data1,'headers':columns1}
meta = {'values': data2,'headers':columns2}
return stats,meta