Skip to content

Use ground motion from another model

cascade.run computes its own ground motion with the Akkar, Sandıkkaya & Bommer (2014) model. To use shaking computed elsewhere, for example by OpenQuake, a regional ShakeMap or a site-response study, chain the modules by hand. They all work on plain arrays and tables. The recipe below is examples/04_external_ground_motion.py, runnable as it stands on the synthetic town.

A median map, or one realisation of a field?

How you compute damage depends on what your PGA is.

Your PGA is Damage dispersion Collapse sampling
a median (or a percentile) per site, such as a GMPE median or a ShakeMap mean the full Hazus β = 0.64 (fragility.HAZUS_PGA_BETA, the default) montecarlo.sample_damage_states_correlated in "between_event" mode, with the τ and φ of the model that produced the median
one realisation of a ground-motion field (residuals included, spatially correlated) only the building-specific part, β = 0.4 (fragility.HAZUS_PGA_BETA_THRESHOLD) "independent": the field already carries the shared shaking

Hazus splits its dispersion into a building-specific threshold part (0.4) and a ground-motion demand part (0.5). A realised field has already drawn the demand part. Keeping β = 0.64 on top of it would count the shaking variability twice.

The recipe

"""Damage, debris, closures and isolation from ground motion computed by another model.

Run from the repository root::

    python examples/04_external_ground_motion.py

`cascade.run` computes its own ground motion (Akkar et al. 2014). When the shaking comes from
elsewhere, for example one realisation of an OpenQuake ground-motion field, the modules can be
chained by hand. Every input here is the synthetic town; the numbers describe no real place.
"""

from __future__ import annotations

import numpy as np
import pandas as pd

from quakecascade import access, datasets, debris, fragility, impact, montecarlo, network

town = datasets.synthetic_town(seed=0)
b, roads = town.buildings, town.roads

# 1. PGA (g) at every building from your own model, e.g. one realisation of an OpenQuake
#    ground-motion field joined to the buildings by id. Here an illustrative lognormal field.
rng = np.random.default_rng(1)
pga = pd.Series(rng.lognormal(np.log(0.3), 0.4, len(b)), index=b["building_id"])

# 2. Damage given that realised field: the field already holds the shaking variability, so
#    only the building-specific part of the Hazus dispersion is left (beta = 0.4).
dmg = fragility.damage(pga, b["building_type"].to_numpy(), floors=b["floors"].to_numpy(),
                       design_levels="low", beta=fragility.HAZUS_PGA_BETA_THRESHOLD)
cas = impact.casualties(dmg, occupants=b["occupants"].to_numpy(),
                        occupancy=b["occupancy"].to_numpy(), time_of_day="2am")
shel = impact.shelter(dmg, occupants=b["occupants"].to_numpy(),
                      units=b["dwelling_units"].to_numpy())
print(cas[["total_s3", "total_s4"]].sum().round(1).to_dict(),
      round(float(shel["public_shelter"].sum()), 0))

# 3. One collapse draw. Given a realised field the buildings fail independently, so the
#    sampler runs in "independent" mode (its sigmas then only normalise the draw).
probs = {s: dmg[f"p_{s}"].to_numpy() for s in fragility.DAMAGE_STATES}
states = montecarlo.sample_damage_states_correlated(
    np.random.default_rng(7), probs, sigma_between=0.0, sigma_within=1.0, mode="independent")
collapsed = states == fragility.DAMAGE_STATES.index("complete")

# 4. Debris on the streets, and the roads it closes.
blockage = debris.corridor_blockage(b, roads, collapsed, heights_m=b["height_m"].to_numpy(),
                                    k=0.5, closed_share=0.5,
                                    road_widths_m=roads["width_m"].to_numpy(),
                                    road_ids=roads["edge_id"].to_numpy())
closed = debris.closed_road_ids(blockage)

# 5. Travel times to the nearest hospital before and after, and the isolation status.
cost = network.speed_by_class({"arterial": 50.0, "local": 30.0}, "road_class")
pre = network.RoadNetwork.from_lines(roads, cost=cost, edge_id="edge_id").largest_component()
post = pre.without(closed, strict=False)
units = town.units.geometry.representative_point()
origins = pre.snap(units, max_dist_m=150.0)
hospitals = pre.snap(town.hospitals.geometry, max_dist_m=150.0)
t_pre = access.nearest_time(pre.travel_time_matrix(origins, hospitals))["nearest_time"]
t_post = access.nearest_time(post.travel_time_matrix(origins, hospitals))["nearest_time"]
iso = access.isolation_status(t_pre, t_post, worse_tol_s=1.0)
print(int(collapsed.sum()), "collapses,", len(closed), "roads closed;",
      iso["isolation_status"].value_counts().to_dict())

Step by step:

  1. PGA at each building: a Series indexed by building id. Replace the illustrative lognormal field with your own model's output joined to the buildings.
  2. Damage, casualties, shelter: fragility.damage, impact.casualties and impact.shelter take the damage table directly.
  3. One collapse draw: inverse-transform sampling on each building's own damage distribution.
  4. Closure: debris.corridor_blockage (blocked share) and, if a clear width matters, debris.navigable_roads. debris.closed_road_ids gives the ids of the closed roads.
  5. Access: one network, snapped once, travel times before and after, and access.isolation_status.

For closure frequencies with an external field, repeat steps 3 to 5 over several seeds and, with a field model that provides them, over several field realisations. This is what cascade.realisations does for the built-in ground motion.