Skip to content

Commit d072606

Browse files
authored
Merge pull request #255 from ucgmsim/nhmdf
nhm df reader
2 parents c74d6f4 + d1c6e5c commit d072606

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

qcore/nhm.py

+54-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
from dataclasses import dataclass
44

55
import numpy as np
6-
from scipy.stats import truncnorm
6+
import pandas as pd
77

88
from srf_generation.source_parameter_generation.uncertainties import mag_scaling
99
from srf_generation.source_parameter_generation.uncertainties.distributions import (
1010
truncated_normal as sample_trunc_norm_dist,
1111
)
1212

13-
14-
NHM_HEADER = f"""FAULT SOURCES - New Zealand National Seismic Hazard Model 2010 (created {datetime.datetime.now().strftime("%d-%b-%Y")})
13+
NHM_HEADER = f"""FAULT SOURCES - (created {datetime.datetime.now().strftime("%d-%b-%Y")})
1514
Row 1: FaultName
1615
Row 2: TectonicType , FaultType
1716
Row 3: LengthMean , LengthSigma (km)
@@ -238,3 +237,55 @@ def str2floats(line):
238237
faults[nhm_fault.name] = nhm_fault
239238

240239
return faults
240+
241+
242+
def load_nhm_df(nhm_ffp, erf_name=None):
243+
"""Creates a standardised pandas dataframe for the
244+
ruptures in the given erf file.
245+
246+
Parameters
247+
----------
248+
nhm_ffp : str
249+
Path to the ERF file
250+
erf_name : ERFFileType
251+
name to identify faults from an ERF
252+
253+
Returns
254+
-------
255+
DataFrame
256+
"""
257+
nhm_infos = load_nhm(nhm_ffp)
258+
259+
erf_suffix = ""
260+
if erf_name:
261+
erf_suffix = f"_{erf_name}"
262+
263+
rupture_dict = {
264+
f"{info.name}{erf_suffix}":
265+
{"name": info.name,
266+
"tectonic_type": info.tectonic_type,
267+
"length": info.length,
268+
"length_sigma": info.length_sigma,
269+
"dip": info.dip,
270+
"dip_sigma": info.dip_sigma,
271+
"dip_dir": info.dip_dir,
272+
"rake": info.rake,
273+
"dbottom": info.dbottom,
274+
"dbottom_sigma": info.dbottom_sigma,
275+
"dtop": info.dtop,
276+
"dtop_min": info.dtop_min,
277+
"dtop_max": info.dtop_max,
278+
"slip_rate": info.slip_rate,
279+
"slip_rate_sigma": info.slip_rate_sigma,
280+
"coupling_coeff": info.coupling_coeff,
281+
"coupling_coeff_sigma": info.coupling_coeff_sigma,
282+
"mw": info.mw,
283+
"recur_int_median": info.recur_int_median if info.recur_int_median > 0 else float("nan"),
284+
"exceedance": 1 / info.recur_int_median if info.recur_int_median > 0 else float("nan"),
285+
}
286+
for key, info in nhm_infos.items()
287+
}
288+
289+
return pd.DataFrame.from_dict(
290+
rupture_dict, orient="index"
291+
).sort_index()

0 commit comments

Comments
 (0)