Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 26 additions & 2 deletions tests/test_realisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ def test_srf_config_example(tmp_path: Path) -> None:
duration=60.0,
)
srf_config = realisations.SRFConfig(
genslip_version="5.4.2",
resolution=0.1,
point_source_params=schemas.PointSourceParams(
stype=schemas.Stype.cos,
Expand All @@ -123,6 +122,19 @@ def test_srf_config_example(tmp_path: Path) -> None:
risetimedep=0.0,
inittime=0.0,
),
side_taper=0.02,
bot_taper=0.02,
top_taper=0.0,
alpha_rough=0.0,
gwid=[],
rvfac_seg=[],
seg_delay=False,
slip_sigma=1.0,
risetime_coef=1.6,
ymag_exp=None,
xmag_exp=None,
kx_corner=None,
ky_corner=None,
)

realisation_ffp = tmp_path / "realisation.json"
Expand All @@ -141,7 +153,6 @@ def test_srf_config_example(tmp_path: Path) -> None:
"duration": 60.0,
},
"srf": {
"genslip_version": "5.4.2",
"resolution": 0.1,
"point_source_params": {
"stype": "cos",
Expand All @@ -150,6 +161,19 @@ def test_srf_config_example(tmp_path: Path) -> None:
"risetimedep": 0.0,
"inittime": 0.0,
},
"side_taper": 0.02,
"bot_taper": 0.02,
"top_taper": 0.0,
"alpha_rough": 0.0,
"slip_sigma": 1.0,
"risetime_coef": 1.6,
"gwid": [],
"rvfac_seg": [],
"seg_delay": False,
"ymag_exp": None,
"xmag_exp": None,
"kx_corner": None,
"ky_corner": None,
},
}

Expand Down
15 changes: 14 additions & 1 deletion workflow/default_parameters/develop/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
resolution:
resolution: 0.4
emod3d:
Expand Down Expand Up @@ -100,8 +101,20 @@ hf:
stoch_dx: 2.0
stoch_dy: 2.0
srf:
genslip_version: 5.4.2
side_taper: 0.02
bot_taper: 0.02
top_taper: 0.0
alpha_rough: 0.0
gwid: []
rvfac_seg: []
seg_delay: false
ymag_exp: null
xmag_exp: null
kx_corner: null
ky_corner: null
resolution: 0.1
slip_sigma: 0.75
risetime_coef: 1.6
# The following parameters are only used for the point source approximation.
point_source_params:
# Valid options for the slip time function (stype) are:
Expand Down
15 changes: 14 additions & 1 deletion workflow/default_parameters/v24_2_2_1/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
resolution:
resolution: 0.1
emod3d:
Expand Down Expand Up @@ -100,8 +101,20 @@ hf:
stoch_dx: 2.0
stoch_dy: 2.0
srf:
genslip_version: 5.4.2
side_taper: 0.02
bot_taper: 0.02
top_taper: 0.0
alpha_rough: 0.0
gwid: []
rvfac_seg: []
seg_delay: false
ymag_exp: null
xmag_exp: null
kx_corner: null
ky_corner: null
resolution: 0.1
slip_sigma: 0.75
risetime_coef: 1.6
# The following parameters are only used for the point source approximation.
point_source_params:
# Valid options for the slip time function (stype) are:
Expand Down
15 changes: 14 additions & 1 deletion workflow/default_parameters/v24_2_2_2/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
resolution:
resolution: 0.2
emod3d:
Expand Down Expand Up @@ -100,8 +101,20 @@ hf:
stoch_dx: 2.0
stoch_dy: 2.0
srf:
genslip_version: 5.4.2
side_taper: 0.02
bot_taper: 0.02
top_taper: 0.0
alpha_rough: 0.0
gwid: []
rvfac_seg: []
seg_delay: false
ymag_exp: null
xmag_exp: null
kx_corner: null
ky_corner: null
resolution: 0.1
slip_sigma: 0.75
risetime_coef: 1.6
# The following parameters are only used for the point source approximation.
point_source_params:
# Valid options for the slip time function (stype) are:
Expand Down
15 changes: 14 additions & 1 deletion workflow/default_parameters/v24_2_2_4/defaults.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
resolution:
resolution: 0.4
emod3d:
Expand Down Expand Up @@ -100,8 +101,20 @@ hf:
stoch_dx: 2.0
stoch_dy: 2.0
srf:
genslip_version: 5.4.2
side_taper: 0.02
bot_taper: 0.02
top_taper: 0.0
alpha_rough: 0.0
gwid: []
rvfac_seg: []
seg_delay: false
ymag_exp: null
xmag_exp: null
kx_corner: null
ky_corner: null
resolution: 0.1
slip_sigma: 0.75
risetime_coef: 1.6
# The following parameters are only used for the point source approximation.
point_source_params:
# Valid options for the slip time function (stype) are:
Expand Down
35 changes: 32 additions & 3 deletions workflow/realisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,44 @@ class SRFConfig(RealisationConfiguration):
_config_key: ClassVar[str] = "srf"
_schema: ClassVar[Schema] = schemas.SRF_SCHEMA

genslip_version: str
"""The version of genslip to use (currently supports "5.4.2")."""

resolution: float
"""The resolution of the SRF discretisation (different, in general, from the simulation resolution)."""

point_source_params: schemas.PointSourceParams | None
"""Parameters for point source approximation, if applicable."""

side_taper: float
"""Side slip tapering, proportion of along-strike 0-1."""
bot_taper: float
"""Bottom slip tapering proportion of down-dip 0-1."""
top_taper: float
"""Top slip tapering proportion of down-dip 0-1."""

alpha_rough: float
"""Roughness (0.0 = smooth)"""

gwid: list[float]
"""Width of delay zone around segment boundaries"""
rvfac_seg: list[float]
"""Rupture speed reduction (proportion) at segment boundaries."""
seg_delay: bool
"""If true, delay rupture across slip boundaries according to specifications of rvfac_seg and gwid."""

slip_sigma: float
"""The stddev of slip distribution."""

risetime_coef: float
"""Risetime scaling coefficient."""

ymag_exp: float | None = None
"""Corner magnitude exponent for along-strike slip correlation length. See genslip_v5.6.2c:1385"""
xmag_exp: float | None = None
"""Corner magnitude exponent for down-dip slip correlation length. See genslip_v5.6.2c:1385"""
kx_corner: float | None = None
"""Corner wavenumber for along-strike slip correlation length. See genslip_v5.6.2c:1385"""
ky_corner: float | None = None
"""Corner wavenumber for down-dip slip correlation length. See genslip_v5.6.2c:1385"""

def to_dict(self) -> dict[str, Any]:
"""
Convert the object to a dictionary representation.
Expand Down
111 changes: 82 additions & 29 deletions workflow/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,6 @@
from velocity_modelling.bounding_box import BoundingBox
from workflow.defaults import DefaultsVersion

# NOTE: These functions seem silly and short, however there is a good
# reason for the choice to create functions like this. The reason is
# because when the schema library reports an error (such as the input
# file having a negative depth value) it prints the name of the
# function. So
#
# And(float, lambda x: x > 0).validate(-12)
#
# Would report the error
#
# schema.SchemaError: <lambda>(-12) should evaluate to True
#
# But using the function `is_positive` we instead have
#
# And(float, is_positive).validate(-12)
# schema.SchemaError: is_positive(-12) should evaluate to True
#
# So using short functions with names improves the error reporting
# from the library.
#
# Accordingly, the most trivial of these functions lack docstrings.


class Stype(StrEnum):
"""Options for slip time function (stype) in generic_slip2srf."""
Expand Down Expand Up @@ -94,6 +72,29 @@ def from_dict(cls, params_dict: dict) -> "PointSourceParams":
return cls(**params_dict)


# NOTE: These functions seem silly and short, however there is a good
# reason for the choice to create functions like this. The reason is
# because when the schema library reports an error (such as the input
# file having a negative depth value) it prints the name of the
# function. So
#
# And(float, lambda x: x > 0).validate(-12)
#
# Would report the error
#
# schema.SchemaError: <lambda>(-12) should evaluate to True
#
# But using the function `is_positive` we instead have
#
# And(float, is_positive).validate(-12)
# schema.SchemaError: is_positive(-12) should evaluate to True
#
# So using short functions with names improves the error reporting
# from the library.
#
# Accordingly, the most trivial of these functions lack docstrings.


def _is_positive(x: float) -> bool: # noqa: D103 # numpydoc ignore=GL08
return x > 0

Expand Down Expand Up @@ -130,6 +131,10 @@ def _is_valid_bearing(bearing: float) -> bool: # noqa: D103 # numpydoc ignore=G
return 0 <= bearing <= 360


def _is_proportion(x: float | int) -> bool: # noqa: D103 # numpydoc ignore=GL08
return 0 <= x <= 1


def _is_correct_corner_shape(corners: np.ndarray) -> bool:
"""Check if the corner shape matches the corner shape for plane sources.

Expand Down Expand Up @@ -373,21 +378,69 @@ def _corners_to_array(corners_spec: list[dict[str, float]]) -> np.ndarray:
)
)


SRF_SCHEMA = Schema(
{
Literal("genslip_version", description="The version of genslip to use"): Or(
"5.4.2"
),
Literal("resolution", description="The resolution of the SRF discretisation."): And(
NUMBER, _is_positive
),
Literal(
"resolution", description="The resolution of the SRF discretisation."
): And(NUMBER, _is_positive),
Optional(
Literal(
"point_source_params",
description="Parameters for point source approximation, if applicable",
)
): Or(None, POINT_SOURCE_PARAMS_SCHEMA),
Literal(
"side_taper",
description="Side slip tapering, proportion of along-strike 0-1.",
): And(NUMBER, _is_proportion),
Literal(
"bot_taper",
description="Bottom slip tapering proportion of down-dip 0-1.",
): And(NUMBER, _is_proportion),
Literal(
"top_taper",
description="Top slip tapering proportion of down-dip 0-1.",
): And(NUMBER, _is_proportion),
Literal(
"alpha_rough",
description="Roughness (0.0 = smooth)",
): And(NUMBER, _is_proportion),
Literal(
"gwid",
description="Width of delay zone around segment boundaries",
): [And(NUMBER, _is_positive)],
Literal(
"rvfac_seg",
description="Rupture speed reduction (proportion) at segment boundaries.",
): [And(NUMBER, _is_proportion)],
Literal(
"seg_delay",
description="If true, delay rupture across slip boundaries according to specifications of rvfac_seg and gwid.",
): bool,
Literal(
"ymag_exp",
description="Corner magnitude exponent for along-strike slip correlation length. See genslip_v5.6.2c:1385",
): Or(NUMBER, None),
Literal(
"xmag_exp",
description="Corner magnitude exponent for down-dip slip correlation length. See genslip_v5.6.2c:1385",
): Or(NUMBER, None),
Literal(
"kx_corner",
description="Corner wavenumber for along-strike slip correlation length. See genslip_v5.6.2c:1385",
): Or(NUMBER, None),
Literal(
"ky_corner",
description="Corner wavenumber for down-dip slip correlation length. See genslip_v5.6.2c:1385",
): Or(NUMBER, None),
Literal(
"slip_sigma",
description="The stddev of slip distribution.",
): And(NUMBER, _is_non_negative),
Literal(
"risetime_coef",
description="Risetime scaling coefficient.",
): And(NUMBER, _is_positive),
}
)

Expand Down
Loading
Loading