Skip to content

cascade

The whole chain as one run, repeated collapse draws and GIS export.

quakecascade.cascade

One scenario earthquake through the whole chain, as a thin orchestrator.

run calls the module functions in order and keeps every intermediate table:

ground motion (groundmotion) -> damage at bracketing design levels (fragility) -> casualties and shelter (impact) -> liquefaction screening (liquefaction, when a DEM is given) -> Monte Carlo bands (montecarlo, when requested) -> debris reach, pressure and corridor blockage for one sampled collapse realisation (debris) -> closed edges -> pre/post travel times (network) -> isolation status and 2SFCA (access) -> p-median depots and capacity balance (allocate) -> TOPSIS ranking of planning units (mcda) -> pipeline repairs (lifelines).

A stage whose inputs are missing is skipped and recorded in CascadeResult.stages with the reason; its outputs are None, never zero-filled. Every coefficient without a cited default is a field of CascadeParams with no default value.

Per-unit sums over buildings that were not all computed are lower bounds. The ranking and the shelter capacity stages never read them as complete totals: CascadeParams.partial_units decides whether such units are left out (the default), scaled up, or used as lower bounds, and the stage log records the choice and the number of units it touched.

STAGES module-attribute

STAGES = ...

Stage names in execution order.

BUILDING_COLUMNS module-attribute

BUILDING_COLUMNS = ...

Columns run reads from CascadeInputs.buildings.

PARTIAL_UNIT_POLICIES module-attribute

PARTIAL_UNIT_POLICIES = ('exclude', 'scale', 'lower_bound')

How ranking and allocation treat a per-unit sum over incompletely computed buildings.

CascadeInputs dataclass

CascadeInputs(
    crs,
    fault_trace,
    buildings,
    fault=None,
    roads=None,
    hospitals=None,
    fire_stations=None,
    sites=None,
    units=None,
    dem=None,
    dem_transform=None,
    pipes=None,
)

Everything spatial a run needs; optional members switch stages on.

All geometries are in crs, a projected metric CRS. Frames may be GeoDataFrames or DataFrames with a geometry column of Shapely objects.

Attributes:

Name Type Description
crs str or CRS

Projected metric CRS (checked).

fault_trace LineString or (M, 2) array

Surface trace of the scenario fault.

buildings frame

Columns BUILDING_COLUMNS (footprints; NaN where unknown).

fault (FaultGeometry, optional)

Dip geometry with its source; None measures RJB to the trace.

roads (frame, optional)

edge_id, geometry (noded centrelines), road_class, width_m. Needed for debris, closure and network stages.

hospitals (frame, optional)

Points with beds: isolation and 2SFCA target.

fire_stations (frame, optional)

Points: a second isolation target.

sites (frame, optional)

Candidate depot/shelter sites with site_id and area_m2.

units (frame, optional)

Planning units with unit_id, geometry and population. Their representative points are the demand points.

dem, dem_transform optional

Elevation grid (row 0 at the top) and (x_min, y_max, cell_m).

pipes (DataFrame, optional)

unit_id, length_km, material.

CascadeParams dataclass

CascadeParams(
    run_id,
    magnitude,
    mechanism,
    design_levels,
    chain_level,
    time_of_day,
    collapse_mode,
    collapse_seed,
    debris_k,
    closed_share,
    clear_width_m,
    closure_rule,
    road_speeds_kmh,
    max_snap_m,
    worse_tol_s,
    fca_threshold_s,
    fca_decay,
    topsis_weights,
    occupancy_rate=1.0,
    shelter_alpha=1.0,
    fca_param=None,
    access_limit_s=None,
    mc_runs=None,
    mc_seed=None,
    mc_modes=montecarlo.CORRELATION_MODES,
    n_depots=None,
    unreachable_penalty_s=None,
    m2_per_person=None,
    depot_max_cost_s=None,
    pipe_ductile=None,
    pipe_brittle=None,
    unknown_height_reach_m=None,
    default_height=None,
    partial_units="exclude",
)

Scenario choices and coefficients of one run.

Fields without a default have no citable default value and must be stated. Fields defaulting to None belong to optional stages: when the stage runs and the field is still None, run raises TypeError (contract.require) instead of assuming a value. The few numeric defaults are cited where they are defined (Hazus 6.1 neutral shelter modifier, the ASB2014 sigmas taken from the ground-motion table).

Attributes:

Name Type Description
run_id str

Name stored in the manifest.

magnitude float

Moment magnitude.

mechanism {'SS', 'NS', 'RS'}

Style of faulting.

design_levels sequence of str

Hazus design levels bracketing the stock, e.g. ("pre", "low", "moderate").

chain_level str

The bracket member that drives debris, closure and everything after it.

time_of_day {'2am', '2pm', '5pm'}

Hazus casualty scenario time.

collapse_mode str

Correlation mode of the one sampled collapse realisation (quakecascade.montecarlo.CORRELATION_MODES).

collapse_seed int

Seed of that realisation.

debris_k float

Debris spread factor k (see quakecascade.debris; no calibrated value).

closed_share float

Blocked corridor share at or above which a road is closed.

clear_width_m float

Minimum clear width for the navigable-core test (m).

closure_rule {'blockage', 'navigable', 'either'}

Which closure test removes edges from the network.

road_speeds_kmh mapping

Road class -> free-flow speed (km/h); unlisted classes are not routed.

max_snap_m float

Farthest a facility or unit point may lie from a network node (m).

worse_tol_s float

Isolation tolerance (s) below which a change counts as same.

fca_threshold_s float

2SFCA catchment size (s).

fca_decay str

2SFCA decay kind (quakecascade.access.DECAY_KINDS).

topsis_weights mapping or None

Criterion weights; None = equal weights, stated explicitly.

occupancy_rate, shelter_alpha float

Hazus 6.1 Section 13 households per unit and Eq. 13-5 modifier; defaults 1.0 are the neutral upper-bound values of quakecascade.impact.shelter.

fca_param (float, optional)

Decay parameter where the kind needs one.

access_limit_s (float, optional)

Times above it count as unreachable in the isolation status.

mc_runs, mc_seed (int, optional)

Monte Carlo bands run when mc_runs is set; mc_seed is then required.

mc_modes sequence of str

Correlation modes of the bands (all three by default: the module's own set).

n_depots (int, optional)

p for the p-median depot stage.

unreachable_penalty_s (float, optional)

Cost of an unreachable unit-site pair in the p-median.

m2_per_person (float, optional)

Usable area per sheltered person, for site capacity.

depot_max_cost_s (float, optional)

Catchment limit of the capacity balance.

pipe_ductile, pipe_brittle sequence of str, optional

Inventory material codes of ductile and brittle pipe.

unknown_height_reach_m (float, optional)

Reach (m) assumed for buildings without a usable height in the debris stages (see quakecascade.debris.reach_pairs); required as soon as one such building exists. Roads such buildings may reach read partial or no_height, never debris-free.

default_height ({'L', 'M', 'H'}, optional)

Hazus height class assumed for a building of a height-split type without a storey count; required as soon as one exists (the screening convention of mid-rise is a choice, not a Hazus value). The buildings it was applied to are flagged height_assumed and counted in the stage log.

partial_units {'exclude', 'scale', 'lower_bound'}

What the ranking and the shelter capacity stages do with a unit whose sum (expected complete damage, casualties, shelter need) misses some of its buildings. "exclude" (default) sets that value to NaN, so the unit is not ranked and its demand reads no_demand: nothing is assumed about the missing buildings. "scale" multiplies the sum by n_rows / n_known, i.e. assumes the missing buildings resemble the computed ones of the same unit. "lower_bound" uses the sum as it is. With either of the last two the unit's criteria_status (ranking) and demand_status (capacity) read partial; with "exclude" its criteria_status reads no_complete_sum. "exclude" is the default because it is the only choice that assumes nothing: a lower bound would rank a unit lower because data are missing, and scaling assumes something the data cannot check. The excluded units stay visible in every table.

as_dict

as_dict()

JSON-ready parameters (for the manifest).

CascadeResult dataclass

CascadeResult(
    params,
    manifest,
    stages,
    ground_motion,
    damage,
    buildings,
    casualties=None,
    shelter=None,
    liquefaction=None,
    bands=None,
    collapsed=None,
    debris_pressure=None,
    blockage=None,
    navigable=None,
    closed_edges=None,
    travel=None,
    isolation=dict(),
    population_by_status=dict(),
    access=None,
    depots=None,
    capacity=None,
    ranking=None,
    pipes=None,
    units=None,
)

Every table of one run.

buildings (one row per building at chain_level) and units (one row per planning unit) are the summary tables; the per-stage tables are kept as returned by the modules. Skipped stages leave None. stages maps each stage to {"status": "run" | "skipped", ...}.

summary

summary()

A few headline numbers, each with the number of buildings it leaves out.

The sums run over the buildings that have a value; <name>_n_missing counts the others, so a sum with a non-zero count is a lower bound.

Realisations dataclass

Realisations(seeds, runs, roads, units, target)

Closure and isolation over repeated collapse draws (see realisations).

Attributes:

Name Type Description
seeds list of int

The collapse_seed of each run.

runs DataFrame

One row per run: seed, collapsed, closed_edges, open_roads_uncertain, newly_cut_off_units, newly_cut_off_population (NaN when the isolation stage did not run) and run_fingerprint.

roads DataFrame

One row per road: road_id, closed_runs, closed_frequency (share of runs in which the road closed), uncertain_runs and uncertain_frequency (open, but touched by debris of unknown extent).

units DataFrame or None

One row per planning unit: unit_id and, for every isolation category of quakecascade.access.ISOLATION_CATEGORIES, the share of runs in that category (<category>_frequency), plus unknown_frequency for runs without a pre- or post-event time. None when the isolation stage cannot run (no units or targets).

target str

The facility kind the isolation shares refer to.

run

run(inputs, params)

Run the cascade.

Parameters:

Name Type Description Default
inputs CascadeInputs
required
params CascadeParams
required

Returns:

Type Description
CascadeResult

All stage tables, the per-building and per-unit summaries, the stage log and a fingerprinted manifest (quakecascade.contract.build_manifest). buildings["root_status"] is the first non-computed status along ground motion -> damage -> casualties -> shelter, so a building without Vs30 reads no_vs30 in every downstream table, with NaN values.

Raises:

Type Description
CRSError

When a frame carries a CRS other than inputs.crs.

ValueError

When a road has no usable width (fill it first, e.g. with quakecascade.debris.highway_width_m), before any stage runs.

inputs_from_town

inputs_from_town(town)

realisations

realisations(inputs, params, seeds, *, target='hospital')

Repeat the collapse draw and count how often each road closes and each unit is cut off.

run draws one correlated collapse realisation, so its closed roads and isolation categories hold for that draw only. This function reruns the chain for every seed in seeds (collapse_seed replaced, everything else unchanged) and reports frequencies: the share of draws in which a road closes, and the share in which a unit falls in each isolation category. The ground motion and the damage probabilities are the same in every run; only the realised collapses change.

Stages that do not depend on the collapse draw (liquefaction, Monte Carlo bands, allocation, lifelines) are left out of the repeated runs.

Parameters:

Name Type Description Default
inputs CascadeInputs

As for run; roads are required.

required
params CascadeParams

As for run; collapse_seed and mc_runs are ignored.

required
seeds sequence of int

One run per seed. The frequencies have a sampling error of about sqrt(f (1 - f) / n) for n seeds.

required
target str

Facility kind for the isolation shares ("hospital" or "fire_station").

'hospital'

Returns:

Type Description
Realisations

result_layers

result_layers(result, inputs)

The result tables joined to their geometries, as GeoDataFrames (needs geopandas).

Returns:

Type Description
dict of GeoDataFrame

buildings (footprints with the per-building table), roads (centrelines with debris pressure, blockage, navigability and a closed flag), units (with the per-unit table, access and ranking), sites (with the capacity balance), hospitals and fire_stations, as far as the run produced them. Every layer is in inputs.crs.

export_geopackage

export_geopackage(result, inputs, path)

Write result_layers to a GeoPackage, one layer each, and the manifest beside it.

The manifest goes to <path without suffix>.manifest.json, so the numbers in the GeoPackage can be traced to the run that produced them. Returns {"geopackage": path, "manifest": manifest_path, "layers": [...]}.