Skip to content

Commit

Permalink
split code create get_gsim_required_attrs in resduals
Browse files Browse the repository at this point in the history
  • Loading branch information
rizac committed Sep 9, 2023
1 parent cb67550 commit fbbe653
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions egsim/smtk/flatfile-metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# type: The column type. Supported values are: i (intensity measure), d
# (distance measure), r (rupture parameter), s (site parameter).
# When missing, defaults to 'u' (unknown)
# alias: A column alias, usually the column name used by OpenQuake (any name listed
# in Gsims REQUIRED_* attributes). If missing, it defaults to <column_name>.
# alias: A column alias, usually the OpenQuake corresponding name, if it differs
# from <column name>. If missing, it defaults to <column_name>.
# Columns of type i (intensity measure) cannot have aliases
# required: Tells if the column should be always present in flatfile (default when
# missing: false)
Expand Down
12 changes: 8 additions & 4 deletions egsim/smtk/flatfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,20 @@ def prepare_for_residuals(flatfile: pd.DataFrame,
columns.
Raise `MissingColumn` if the flatfile cannot be made compliant to the given arguments
"""
for attr in get_gsim_required_attributes(gsims):
_prepare_for_gsim_required_attribute(flatfile, attr)
_prepare_for_sa(flatfile, imts)


def get_gsim_required_attributes(gsims: Iterable[GMPE]):
required = set()
# code copied from openquake,hazardlib.contexts.ContextMaker.__init__:
for gsim in gsims:
# NB: REQUIRES_DISTANCES is empty when gsims = [FromFile]
required.update(gsim.REQUIRES_DISTANCES | {'rrup'})
required.update(gsim.REQUIRES_RUPTURE_PARAMETERS or [])
required.update(gsim.REQUIRES_SITES_PARAMETERS or [])
for attr in required:
_prepare_for_gsim_required_attribute(flatfile, attr)
_prepare_for_sa(flatfile, imts)
return required


DEFAULT_MSR = PeerMSR()
Expand Down Expand Up @@ -569,7 +573,7 @@ def _prepare_for_sa(flatfile: pd.DataFrame, imts: Iterable[str]):
if not source_sa or not target_sa:
return

# source_sa_periods = sorted(p for p in source_sa if p is not None)
# Take the log10 of all SA:
source_spectrum = np.log10(flatfile[list(source_sa.values())])
# we need to interpolate row wise
# build the interpolation function:
Expand Down

0 comments on commit fbbe653

Please sign in to comment.