Skip to content
Draft
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
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ requires-python = ">=3.12"
dynamic = ["version"]
dependencies = [
# UCGMSim Dependencies
"im-calculation>=2025.12.5",
"im-calculation @ git+https://github.com/ucgmsim/IM_calculation@no_parallel",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"im-calculation @ git+https://github.com/ucgmsim/IM_calculation@no_parallel",
"im-calculation @ git+https://github.com/ucgmsim/IM_calculation.git@no_parallel",

"velocity-modelling>=2026.8.1",
"nshmdb>=2026.09.1",
"oq_wrapper>=2025.12.3",
Expand All @@ -37,6 +37,7 @@ dependencies = [
"h5py>=3.15.1",
"parse>=1.21.0",
"rich>=14.3.2",
"dask>=2026.6.0",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -171,3 +172,6 @@ exclude = [ # don't report on objects that match any of these regex
'\.undocumented_method$',
'\.__repr__$',
]

[tool.uv.sources]
im-calculation = { git = "https://github.com/ucgmsim/im_calculation", branch = "no_parallel" }
82 changes: 63 additions & 19 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions workflow/realisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,23 @@ class Rakes(RealisationConfiguration):
rakes: dict[str, float]
"""A map from faults to their rake angles."""

def as_vectors(self) -> dict[str, npt.NDArray[np.float64]]:
"""Represent each rake angle as a unit vector.

Rakes are angles, so they cannot be averaged directly (the mean of
-179 and 179 degrees is 0, not 180). Averaging the unit vectors and
recovering the angle with `arctan2` avoids this.

Returns
-------
dict
A map from faults to the unit vector of their rake angle.
"""
return {
k: np.array([np.cos(np.radians(r)), np.sin(np.radians(r))])
for k, r in self.rakes.items()
}

def __getitem__(self, key: str) -> float:
"""Get the rake for a fault name.

Expand Down Expand Up @@ -713,6 +730,38 @@ def __getitem__(self, key: str) -> BoldM:
"""
return self.magnitudes[key]

@property
def moments(self) -> dict[str, float]: # numpydoc ignore=RT01
"""dict: a map from faults to their moment."""
return {
k: moment.magnitude_to_moment(mag, bold_m=True)
for k, mag in self.magnitudes.items()
}

def moment_averaged(self, values: dict[str, Any]) -> Any:
"""Average per-fault quantities, weighted by fault moment.

Parameters
----------
values : dict
A map from faults to the quantity to average. Every fault in
this realisation must be present. Values may be scalars or
arrays, provided they all share the same shape.

Returns
-------
Any
The moment-weighted average of `values`, with the same shape as
the individual values.
"""
keys = list(self.magnitudes)
moments = self.moments
return np.average(
[values[key] for key in keys],
weights=[moments[key] for key in keys],
axis=0,
)

@property
def total_moment(self) -> float: # numpydoc ignore=RT01
"""float: total moment of realisation"""
Expand Down
Loading
Loading