Tutorial: one scenario through the whole chain¶
This page runs quakecascade.cascade.run on the built-in synthetic town and reads its output
stage by stage. The script is examples/01_synthetic_town.py, and you can run it as is:
python examples/01_synthetic_town.py # tables only
pip install -e ".[demo]" # add matplotlib to also write the figures
Synthetic data
The town, its fault and every number below exist only to exercise the code. They describe no real place, and no planning conclusion should be drawn from them.
1. The inputs¶
datasets.synthetic_town(seed=0) builds a deterministic town about 3 km across in WGS 84 /
UTM zone 35N (metres):
| Member | Content |
|---|---|
fault_trace, fault |
a 27 km fault trace and its dip geometry (60°, 1–14 km), labelled as synthetic |
buildings |
597 footprints with storeys, height, Hazus base type, occupancy, occupants, dwelling units, Vs30 and planning unit; a few Vs30 and occupant values are deliberately missing |
roads |
840 noded edges with a road class (arterial, local, lane) and a width |
hospitals, fire_stations |
three of each, hospitals with beds |
sites |
eight candidate open spaces with their area |
units |
36 planning cells of 500 m with residents |
dem, dem_transform |
a coarse elevation grid for the liquefaction screen |
pipes |
pipe length by unit and material, some materials unknown |
cascade.inputs_from_town(town) packs these into a CascadeInputs. Your own data go in
the same way: any frame with the documented columns, in one projected metric CRS.
2. The parameters¶
from quakecascade import cascade, datasets
town = datasets.synthetic_town(seed=0)
params = cascade.CascadeParams(
run_id="synthetic_town_demo",
magnitude=6.5, mechanism="NS", # scenario choice
design_levels=("pre", "low", "moderate"), # bracket of Hazus design levels
chain_level="low", # level that drives debris onwards
time_of_day="2am",
collapse_mode="between_event", collapse_seed=7, # one sampled collapse realisation
debris_k=0.5, # spread factor: uncalibrated, bracket it
closed_share=0.5, clear_width_m=3.0, closure_rule="either",
road_speeds_kmh={"arterial": 50.0, "local": 30.0}, # "lane" deliberately unlisted
max_snap_m=150.0, worse_tol_s=1.0,
fca_threshold_s=600.0, fca_decay="gaussian",
topsis_weights=None, # equal weights, stated explicitly
mc_runs=300, mc_seed=1,
n_depots=3, unreachable_penalty_s=3600.0, m2_per_person=3.5,
pipe_ductile=["DI", "PE"], pipe_brittle=["CI", "AC"],
)
res = cascade.run(cascade.inputs_from_town(town), params)
CascadeParams has no defaults for anything that lacks a published value. The debris spread
factor, the closure threshold, the clear width, the road speeds and the catchment size are
planning choices. You must state them, and the manifest records them. Even "equal TOPSIS
weights" has to be written as topsis_weights=None. A parameter that an optional stage needs
(for example n_depots) may stay None only while that stage is switched off. Once the stage
runs, run raises instead of guessing a value.
3. Stages and their log¶
All fourteen stages run here. Drop an input and the stages that need it are skipped, with the
reason given. With roads=None, dem=None, pipes=None the log reads, for example:
liquefaction {'status': 'skipped', 'reason': 'no DEM given'}
debris {'status': 'skipped', 'reason': 'no roads given'}
...
ranking {'status': 'run', 'criteria': {'expected_complete': True, 'casualties_s3_s4': True,
'public_shelter': True}, 'n_unranked': 7, ...}
lifelines {'status': 'skipped', 'reason': 'no pipes given'}
A skipped stage leaves its result fields as None. It never fills them with zeros, and the
ranking says which criteria it actually used.
4. Headline numbers¶
buildings 597
buildings_computed 588
expected_complete 151.49694769169943
expected_complete_n_missing 8
killed_s4 27.742354278507396
killed_s4_n_missing 9
public_shelter 5672.288027318444
public_shelter_n_missing 9
collapsed_in_realisation 109
collapsed_in_realisation_n_missing 8
closed_edges 23
stages_skipped []
Each sum runs over the buildings that have a value, and the _n_missing count beside it says
how many it leaves out. A sum with a non-zero count is a lower bound.
expected_complete is the sum of complete-damage probabilities at the chain level (low). It is
an expected count, not a collapse list. The debris stage needs concrete collapses, so it draws
one correlated realisation (collapse_mode, collapse_seed), and 109 buildings collapse in
that draw. To see how much the street closures depend on that draw, rerun with other seeds.
5. Damage across design levels¶
p_slight p_moderate p_extensive p_complete
design_level
low 53.2 176.2 172.0 151.5
moderate 97.0 220.4 123.4 38.9
pre 30.1 138.2 179.3 223.2
The design level of a real stock is rarely known building by building. Each level is a Hazus
calibration of US code eras, so the range from pre to moderate is the honest answer when
the code era is uncertain.
6. Missing values stay visible¶
building_id vs30_m_s pga_g_p50 p_complete total_s4 root_status
b0055 NaN NaN NaN NaN no_vs30
b0133 281.0 0.341322 0.236753 NaN no_occupants
...
Building b0055 has no Vs30, so it has no motion, no damage and no casualties. Building b0133
has motion and damage but no occupant count, so its casualty columns are NaN with
no_occupants. Any total over a set that contains such rows is reported as partial. See the
output contract.
7. Uncertainty bands¶
mode analytic_expected mean p05 p95 band_status
independent 151.5 151.1 134.0 169.0 partial
between_event 151.5 155.9 50.9 291.1 partial
fully_correlated 151.5 163.9 1.0 479.6 partial
All three modes keep each building's marginal damage distribution, so their means agree with
the analytic expectation within sampling error. What they change is the spread. Independent
sampling understates it badly. Sharing the between-event ground-motion residual across the city
(between_event) is the realistic middle case, and fully_correlated is the upper bound
(Monte Carlo method).

8. Debris, closures and access¶
From the sampled collapses, the debris stage computes reach envelopes, the debris pressure on
each road corridor, the blocked share of each corridor and whether a clear core of
clear_width_m survives. With closure_rule="either", a road is closed when either test fails,
and 23 edges close in this run. Travel times are then recomputed on the damaged network.
The eight buildings without Vs30 have no damage state, so the draw cannot say whether they
collapse. They are not read as standing. Where their debris could land, three roads read
no_damage in the blockage table and partial in the navigable table, and the stage log counts
them (open_roads_uncertain). Roads that a vehicle of clear_width_m could not use even before
the event are left out of both networks, so they never count as closures.

Isolation compares each unit's time to its nearest hospital before and after the event:
isolation_status n_units population n_population_missing
newly_cut_off 0 0.0 0
worse 2 495.0 0
same 34 10857.0 0
9. Allocation and ranking¶
The p-median stage picks n_depots candidate sites on the post-event network, and a capacity
balance checks the sites' areas (m2_per_person) against the shelter demand. TOPSIS then ranks
the planning units on expected complete damage, severe casualties, public shelter need and
post-event access.
Seven units hold a building that was not fully computed: no Vs30, or no occupant count. Their
sums over buildings are only lower bounds. Ranking a unit on a lower bound would push it down
the list because of a data gap, which is the street-with-no-data error at the scale of a
neighbourhood. CascadeParams.partial_units decides how these units are treated:
partial_units |
Ranking | Shelter demand |
|---|---|---|
"exclude" (default) |
not ranked (criteria_status = no_complete_sum, NaN score) |
no_demand, left out of the totals |
"scale" |
ranked on the sum × n_rows / n_known |
scaled demand, demand_status = partial |
"lower_bound" |
ranked on the sum as it is | partial sum, demand_status = partial |
"exclude" is the default because it is the only choice that assumes nothing about the
missing buildings. A lower bound ranks a unit lower simply because data are missing, which
is the error the package exists to avoid. "scale" assumes the missing buildings resemble the
computed ones of the same unit, and nothing in the data can check that. Leaving the unit out
does not hide it: it stays in every table with criteria_status = no_complete_sum, so the gap
can be filled or the unit judged by hand. Use "scale" only when its assumption is defensible,
and report it. The stage log records the policy and
how many units it touched:
Units with an unknown population, or that lie off the road network, are left out of the
p-median and counted in stages["allocation"] (n_units_no_population,
n_units_unsnapped). They are never weighted as zero people.

10. Reproducibility¶
res.manifest holds the package version, every parameter, a digest of every input and a
run_fingerprint. With the same inputs and parameters you get the same fingerprint, so a
reported number can be traced to the exact run that produced it.
Using real data¶
quakecascade.datasets has fetchers for open data: fetch_osm (buildings, roads, hospitals, fire
stations and parks from OpenStreetMap via osmnx), fetch_copernicus_dem (Copernicus GLO-30 tiles) and
fetch_gem_faults (GEM Global Active Faults, CC BY-SA 4.0). They need the demo extra and a
network connection. gem_fault_geometry(record) turns one GEM record into a FaultGeometry whose
source names the record. Most records lack a dip, a dip direction or a depth bound (only about one
in eight of the 13,696 records has all four), and the helper asks for the missing values rather
than filling them in. You still have to supply Vs30, building types and occupants.
examples/02_open_data.py puts these pieces together for a strip of central Napa, California. It
uses OSM buildings, roads, hospital, fire stations and parks, Vs30 from the slope of the
Copernicus DEM, and a scenario on a GEM fault whose record is complete. Every value open data
cannot give (structural type, storey height, floor area per occupant, road widths) sits in one
ASSUMPTIONS block, marked as a choice of the example. Set the OVERPASS_URL environment
variable to use an Overpass mirror when the main server is busy.