Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nhm df reader #255

Merged
merged 1 commit into from
Oct 13, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions qcore/nhm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from dataclasses import dataclass

import numpy as np
from scipy.stats import truncnorm
import pandas as pd

from srf_generation.source_parameter_generation.uncertainties import mag_scaling
from srf_generation.source_parameter_generation.uncertainties.distributions import (
truncated_normal as sample_trunc_norm_dist,
)


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

return faults


def load_nhm_df(nhm_ffp, erf_name=None):
"""Creates a standardised pandas dataframe for the
ruptures in the given erf file.

Parameters
----------
nhm_ffp : str
Path to the ERF file
erf_name : ERFFileType
name to identify faults from an ERF

Returns
-------
DataFrame
"""
nhm_infos = load_nhm(nhm_ffp)

erf_suffix = ""
if erf_name:
erf_suffix = f"_{erf_name}"

rupture_dict = {
f"{info.name}{erf_suffix}":
{"name": info.name,
"tectonic_type": info.tectonic_type,
"length": info.length,
"length_sigma": info.length_sigma,
"dip": info.dip,
"dip_sigma": info.dip_sigma,
"dip_dir": info.dip_dir,
"rake": info.rake,
"dbottom": info.dbottom,
"dbottom_sigma": info.dbottom_sigma,
"dtop": info.dtop,
"dtop_min": info.dtop_min,
"dtop_max": info.dtop_max,
"slip_rate": info.slip_rate,
"slip_rate_sigma": info.slip_rate_sigma,
"coupling_coeff": info.coupling_coeff,
"coupling_coeff_sigma": info.coupling_coeff_sigma,
"mw": info.mw,
"recur_int_median": info.recur_int_median if info.recur_int_median > 0 else float("nan"),
"exceedance": 1 / info.recur_int_median if info.recur_int_median > 0 else float("nan"),
}
for key, info in nhm_infos.items()
}

return pd.DataFrame.from_dict(
rupture_dict, orient="index"
).sort_index()