Skip to content

Commit 8f988b6

Browse files
committed
Include max_distance in calculation summary
1 parent f2db5c0 commit 8f988b6

21 files changed

+220
-362
lines changed

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/calculation_summary.csv

+149-292
Large diffs are not rendered by default.

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_10.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6590.0 per rupture
1616
Discarded 24/32 stations more distant than 150 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.464, Nominal bias stddev: 0.188
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.464, Nominal bias stddev: 0.188
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.542, Nominal bias stddev: 0.259
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.158, Nominal bias stddev: 0.178
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.482, Nominal bias stddev: 0.271

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_11.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6590.0 per rupture
1616
Discarded 18/32 stations more distant than 250 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.518, Nominal bias stddev: 0.141
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.518, Nominal bias stddev: 0.141
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.417, Nominal bias stddev: 0.182
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.211, Nominal bias stddev: 0.131
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.419, Nominal bias stddev: 0.185

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_12.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6590.0 per rupture
1616
Discarded 26/32 stations more distant than 50 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.279, Nominal bias stddev: 0.225
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.279, Nominal bias stddev: 0.225
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.519, Nominal bias stddev: 0.327
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.042, Nominal bias stddev: 0.212
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.547, Nominal bias stddev: 0.353

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_13.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6590.0 per rupture
1616
Discarded 24/32 stations more distant than 150 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.384, Nominal bias stddev: 0.188
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.384, Nominal bias stddev: 0.188
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.498, Nominal bias stddev: 0.259
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.079, Nominal bias stddev: 0.178
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.475, Nominal bias stddev: 0.271

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_14.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6590.0 per rupture
1616
Discarded 18/32 stations more distant than 250 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.414, Nominal bias stddev: 0.141
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.414, Nominal bias stddev: 0.141
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.355, Nominal bias stddev: 0.182
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.108, Nominal bias stddev: 0.131
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.387, Nominal bias stddev: 0.185

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_15.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6504.0 per rupture
1616
Discarded 26/32 stations more distant than 50 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.282, Nominal bias stddev: 0.228
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.282, Nominal bias stddev: 0.228
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.409, Nominal bias stddev: 0.327
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.065, Nominal bias stddev: 0.212
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.376, Nominal bias stddev: 0.353

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_16.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6504.0 per rupture
1616
Discarded 24/32 stations more distant than 150 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.470, Nominal bias stddev: 0.189
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.470, Nominal bias stddev: 0.189
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.429, Nominal bias stddev: 0.259
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.043, Nominal bias stddev: 0.178
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.374, Nominal bias stddev: 0.271

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_17.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6504.0 per rupture
1616
Discarded 20/32 stations more distant than 250 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.546, Nominal bias stddev: 0.153
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.546, Nominal bias stddev: 0.153
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.313, Nominal bias stddev: 0.200
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.027, Nominal bias stddev: 0.143
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.318, Nominal bias stddev: 0.205

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_18.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6510.0 per rupture
1616
Discarded 26/32 stations more distant than 50 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.344, Nominal bias stddev: 0.219
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.344, Nominal bias stddev: 0.219
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.522, Nominal bias stddev: 0.327
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.027, Nominal bias stddev: 0.212
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.503, Nominal bias stddev: 0.353

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_19.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6510.0 per rupture
1616
Discarded 24/32 stations more distant than 150 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.450, Nominal bias stddev: 0.184
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.450, Nominal bias stddev: 0.184
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.596, Nominal bias stddev: 0.259
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.168, Nominal bias stddev: 0.178
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.530, Nominal bias stddev: 0.271

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_20.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6510.0 per rupture
1616
Discarded 18/32 stations more distant than 250 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.426, Nominal bias stddev: 0.140
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.426, Nominal bias stddev: 0.140
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.458, Nominal bias stddev: 0.182
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.225, Nominal bias stddev: 0.131
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.452, Nominal bias stddev: 0.185

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_21.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Reading 1 ruptures
2323
Affected sites = 8971.0 per rupture
2424
Discarded 90/463 stations more distant than 50 km
2525
totw = 6
26-
GSIM: [AbrahamsonEtAl2014]
27-
region = "CHN", IMT: PGA, Nominal bias mean: -0.437, Nominal bias stddev: 0.090
26+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.437, Nominal bias stddev: 0.090
2827
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.765, Nominal bias stddev: 0.141
2928
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.281, Nominal bias stddev: 0.105
3029
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.442, Nominal bias stddev: 0.142

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_22.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Reading 1 ruptures
2323
Affected sites = 8971.0 per rupture
2424
Discarded 86/463 stations more distant than 150 km
2525
totw = 6
26-
GSIM: [AbrahamsonEtAl2014]
27-
region = "CHN", IMT: PGA, Nominal bias mean: -0.477, Nominal bias stddev: 0.086
26+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.477, Nominal bias stddev: 0.086
2827
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.747, Nominal bias stddev: 0.128
2928
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.154, Nominal bias stddev: 0.096
3029
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.453, Nominal bias stddev: 0.129

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_23.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ Reading 1 ruptures
2323
Affected sites = 8971.0 per rupture
2424
Discarded 76/463 stations more distant than 250 km
2525
totw = 3
26-
GSIM: [AbrahamsonEtAl2014]
27-
region = "CHN", IMT: PGA, Nominal bias mean: -0.512, Nominal bias stddev: 0.078
26+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.512, Nominal bias stddev: 0.078
2827
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.656, Nominal bias stddev: 0.111
2928
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.025, Nominal bias stddev: 0.083
3029
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.454, Nominal bias stddev: 0.111

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_6.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6650.0 per rupture
1616
Discarded 26/32 stations more distant than 50 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.326, Nominal bias stddev: 0.222
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.326, Nominal bias stddev: 0.222
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.445, Nominal bias stddev: 0.327
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.030, Nominal bias stddev: 0.212
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.421, Nominal bias stddev: 0.353

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_7.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6650.0 per rupture
1616
Discarded 24/32 stations more distant than 150 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.531, Nominal bias stddev: 0.185
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.531, Nominal bias stddev: 0.185
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.699, Nominal bias stddev: 0.259
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.249, Nominal bias stddev: 0.178
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.661, Nominal bias stddev: 0.271

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_8.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6650.0 per rupture
1616
Discarded 16/32 stations more distant than 250 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.581, Nominal bias stddev: 0.132
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.581, Nominal bias stddev: 0.132
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.611, Nominal bias stddev: 0.169
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: -0.398, Nominal bias stddev: 0.123
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.617, Nominal bias stddev: 0.171

Nepal/20150425_M7.8_Gorkha/OpenQuake_gmfs/Sensitivity/log_calc_9.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ Reading 1 ruptures
1515
Affected sites = 6590.0 per rupture
1616
Discarded 26/32 stations more distant than 50 km
1717
totw = 4
18-
GSIM: [AbrahamsonEtAl2014]
19-
region = "CHN", IMT: PGA, Nominal bias mean: -0.293, Nominal bias stddev: 0.226
18+
GSIM: [AbrahamsonEtAl2014] region = "CHN", IMT: PGA, Nominal bias mean: -0.293, Nominal bias stddev: 0.226
2019
GSIM: [AbrahamsonEtAl2015SInter], IMT: PGA, Nominal bias mean: -0.458, Nominal bias stddev: 0.327
2120
GSIM: [AtkinsonBoore2003SInter], IMT: PGA, Nominal bias mean: 0.029, Nominal bias stddev: 0.212
2221
GSIM: [CauzziEtAl2014], IMT: PGA, Nominal bias mean: -0.431, Nominal bias stddev: 0.353

src/3_4_calculations_summary.ipynb

+5-13
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,13 @@
8585
"outputs": [],
8686
"source": [
8787
"oq_summary = []\n",
88-
"cols = ['calc_id', 'description', 'cal_time', \n",
89-
" 'recording_stations', 'gmlt', 'rupture', 'gmpe', 'imt',\n",
90-
" 'max_gmv', 'nominal_bias_mean', 'nominal_bias_stdev']\n",
88+
"cols=['calc_id', 'description', 'cal_time', \n",
89+
" 'recording_stations', 'gmlt', 'rupture', 'gmpe', 'max_distance', 'imt', \n",
90+
" 'max_gmv', 'nominal_bias_mean', 'nominal_bias_stdev']\n",
9191
"for log in logs:\n",
9292
" # Get information from log\n",
9393
" df_log, calc_id = read_log(log)\n",
94-
"\n",
94+
" \n",
9595
" try:\n",
9696
" # Read gmfs from csv file\n",
9797
" gmfs_path = log.replace('log_calc', 'gmf_median_PGA').replace('txt', 'csv')\n",
@@ -108,7 +108,7 @@
108108
"\n",
109109
" # Add max_gmv to summary data\n",
110110
" if len(df_log) == 1 and any(df_log.gmpe == ''):\n",
111-
" # Calculation woth NO gmf conditioning:\n",
111+
" # Calculation with NO gmf conditioning:\n",
112112
" df = df_log.merge(max_gmv, on=['calc_id'], suffixes=('_x', ''))\n",
113113
" else:\n",
114114
" df = df_log.merge(max_gmv, on=['calc_id', 'gmpe', 'imt'])\n",
@@ -155,14 +155,6 @@
155155
"oq_summary.to_csv(save_as, index=False)\n",
156156
"print(' File save in', save_as) "
157157
]
158-
},
159-
{
160-
"cell_type": "code",
161-
"execution_count": null,
162-
"id": "036220f7",
163-
"metadata": {},
164-
"outputs": [],
165-
"source": []
166158
}
167159
],
168160
"metadata": {

src/oq_parse_gmfs.py

+48-21
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,26 @@ def read_log(log):
114114
The log file follows the ECD format
115115
'''
116116

117-
lines = open(log, 'r').readlines()
117+
# Fix log file for GSIMs tailored for specific regions
118+
fix_gsims(log)
118119

119-
# Get calculation details
120+
# Read lines of log file
121+
with open(log, 'r', encoding="utf-8") as f:
122+
lines = f.readlines()
123+
124+
# Get calculation details from the description line
125+
# (recording stations, gmlt, rupture, and optionally the max_distance)
120126
calc_id = int(lines[0][8:-1])
121-
description = lines[1][17:]
122-
rs, gmlt, rup = description.split(',')[1:]
123-
rs = rs.replace('Stations:', '')
124-
gmlt = gmlt.replace('gmlt:', '')
125-
rup = rup.replace('Rupture:', '').replace('\n', '')
127+
description = lines[1][17:].replace('\n', '').strip()
128+
_, rs, gmlt, rup, *max_dist = map(str.strip, description.split(',')[0:5])
129+
130+
rs = rs.replace('Stations:', '').strip()
131+
gmlt = gmlt.replace('gmlt:', '').strip()
132+
rup = rup.replace('Rupture:', '').strip()
133+
if max_dist:
134+
max_dist = max_dist[0].replace('Max_dist:', '').strip()
135+
else:
136+
max_dist = ''
126137

127138
# Get time
128139
try:
@@ -132,44 +143,60 @@ def read_log(log):
132143
# If no time is found, then the calculation has an error
133144
raise Exception(f"Calculation with error. Check log file: {log}")
134145

135-
# Create DataFrame
146+
# Create DataFrame columns
136147
cols=['calc_id', 'description', 'cal_time',
137-
'recording_stations', 'gmlt', 'rupture', 'gmpe', 'imt',
138-
'nominal_bias_mean', 'nominal_bias_stdev']
139-
calc = []
148+
'recording_stations', 'gmlt', 'rupture', 'gmpe', 'max_distance',
149+
'imt', 'nominal_bias_mean', 'nominal_bias_stdev']
140150

141-
# Get bias
142-
bias = [line for line in lines if 'Nominal bias' in line]
143-
if bias:
151+
# Initialize data list for DataFrame
152+
calc = []
153+
154+
# Get bias information
155+
bias_lines = [line for line in lines if 'Nominal bias' in line]
156+
if bias_lines:
144157
# Calculation with station data
145-
for line in bias:
158+
for line in bias_lines:
146159
ini = line.find('INFO]')
147160
if ini != -1:
148161
line = line[ini + 6 :] # Remove info from initial paragraph
149-
gmpe = line.split(':')[1].split(',')[0].strip(' [] ')
162+
gmpe = line.split(':')[1].split(',')[0].strip(' [] ')
150163
imt = line.split(':')[2].split(',')[0].strip()
151164
bias_mean = float(line.split(':')[3].split(",")[0].replace('\n', '').strip())
152165
bias_stdv = float(line.split(':')[4].replace('\n', '').strip())
153-
vals = [calc_id, description, time, rs, gmlt, rup, gmpe, imt, bias_mean, bias_stdv]
166+
vals = [calc_id, description, time, rs, gmlt, rup, gmpe, max_dist, imt, bias_mean, bias_stdv]
154167
data = pd.DataFrame(dict(zip(cols, vals)), index=[0])
155168
calc.append(data)
156169
else:
157-
# Calculation without station data
170+
# Calculation without station data (i.e., no bias information found)
158171
gmpe = ''
159172
imt = ''
173+
max_dist = ''
160174
bias_mean = np.nan
161175
bias_stdv = np.nan
162-
vals = [calc_id, description, time, rs, gmlt, rup, gmpe, imt, bias_mean, bias_stdv]
176+
vals = [calc_id, description, time, rs, gmlt, rup, gmpe, max_dist, imt, bias_mean, bias_stdv]
163177
data = pd.DataFrame(dict(zip(cols, vals)), index=[0])
164178
calc.append(data)
165-
179+
180+
# Concatenate DataFrames
166181
df = pd.concat(calc, ignore_index=True)
167182

168183
assert df.shape[0]>0, f'No data extracted from log file {log}'
169184

170185
return df, calc_id
171186

172187

188+
def fix_gsims(log):
189+
"""Fix log files that have GSIMS tailored for specific regions
190+
"""
191+
with open(log, 'r', encoding="utf-8") as f:
192+
content = f.read()
193+
# Replace the desired string
194+
content = content.replace(']\nregion = ', '] region = ')
195+
with open(log, 'w', encoding="utf-8") as f:
196+
f.write(content)
197+
return
198+
199+
173200
def plot_df(df, pad=None, **kwargs):
174201
'''
175202
Plot ground motion fields starting from a given DataFrame.
@@ -310,4 +337,4 @@ def get_imfd(df_log, gmfs):
310337
for col in cols:
311338
df.insert(0, col, df_log.loc[0, col])
312339

313-
return df
340+
return df

0 commit comments

Comments
 (0)