Getting started¶
Install¶
quakecascade needs Python 3.10 or newer. The core depends only on NumPy, SciPy, pandas, Shapely
and pyproj.
The latest release on PyPI.
The head of the main branch: the latest release plus what the changelog lists under Unreleased.
git clone https://gitlab.com/yusufeminoglu/quakecascade.git
cd quakecascade
pip install -e ".[test,geo]"
python -m pytest
For changing the code or running the examples and tests; see Contributing.
Optional extras add what some tasks need:
| Extra | Adds | For |
|---|---|---|
geo |
geopandas, pyogrio, pyarrow | GeoDataFrame input and output, the GeoPackage export |
raster |
rasterio | reading and regridding DEMs (datasets.dem_grid, regrid_dem) |
demo |
geopandas, pyogrio, osmnx, matplotlib | the open-data fetchers and the example figures |
test |
pytest, pytest-cov, geopandas | running the test suite |
docs |
mkdocs-material, mkdocstrings | building this site |
pip install "quakecascade[demo,raster]" # everything the examples use
pip install "quakecascade[demo,raster] @ git+https://gitlab.com/yusufeminoglu/quakecascade.git"
Every kernel also has a pure-NumPy path: with QUAKECASCADE_FORCE_NUMPY=1 the package ignores
SciPy. CI tests both paths.
How the package is organised¶
- Modules do one step each and work on plain arrays and tables:
groundmotion,fragility,impact,montecarlo,liquefaction,debris,network,access,allocate,mcdaandlifelines. Use them on their own when you need one step, for example damage from ground motion you computed elsewhere. cascaderuns the whole chain for one scenario, keeps every intermediate table, logs each stage and writes a fingerprinted manifest.cascade.realisationsrepeats the collapse draw, andcascade.export_geopackagewrites the results for QGIS.datasetsholds a synthetic demonstration town and the open-data fetchers (OpenStreetMap, Copernicus DEM, GEM active faults).contractandcrshold the shared rules: status codes, column specifications, aggregation, manifests and metric-CRS checks.
Coordinates¶
All distances are in metres in a projected CRS. Functions that take a CRS refuse geographic
ones, and also Web Mercator (EPSG:3857) and the other Mercator projections, whose distances grow
as 1/cos(latitude), about +28 % at 38°. If your data are in longitude/latitude, reproject first,
for example to the local UTM zone from crs.estimate_utm_crs.
Ground motion and damage in a dozen lines¶
import numpy as np
from quakecascade import fragility, groundmotion as gm
trace = np.array([[0.0, 0.0], [30_000.0, 0.0]]) # metres, projected CRS
rupture = gm.FaultGeometry.from_wells_coppersmith(
dip_deg=60.0, dip_azimuth_deg=0.0, magnitude=6.8, mechanism="NS",
source="hypothetical example fault, dip 60 deg to the north")
sites = np.array([[15_000.0, 5_000.0], [15_000.0, 12_000.0], [15_000.0, 40_000.0]])
vs30 = np.array([300.0, np.nan, 760.0])
motion = gm.scenario(sites, vs30, trace, magnitude=6.8, mechanism="NS", geometry=rupture)
print(motion[["rjb_km", "pga_g_p50", "gm_status"]])
dmg = fragility.damage(motion["pga_g_p50"].to_numpy(), ["C1M", "C1M", "URML"],
floors=[5, 5, 2], design_levels=["pre", "moderate"])
print(dmg[["building_id", "design_level", "p_complete", "dmg_status"]].round(3))
rjb_km pga_g_p50 gm_status
0 0.000000 0.443460 computed
1 3.310996 NaN no_vs30
2 31.310996 0.073523 computed
building_id design_level p_complete dmg_status
0 0 pre 0.519 computed
1 1 pre NaN no_pga
2 2 pre 0.006 computed
3 0 moderate 0.138 computed
4 1 moderate NaN no_pga
5 2 moderate NaN no_fragility_curve
Three things to notice:
- The second site has no Vs30. Its motion is
NaNwith statusno_vs30, and the damage row downstream inherits it asno_pga. It never turns into a zero. - Hazus has no unreinforced-masonry curve at the moderate design level, so that row reports
no_fragility_curveinstead of borrowing another level's curve. - Damage is computed at several design levels at once. A stock whose code era is not known is bracketed, not assigned one level.
Next steps¶
- The whole chain on a synthetic town: every stage of
cascade.run, read table by table. - A real area from open data: assembling the inputs from OpenStreetMap, the Copernicus DEM and the GEM fault database.
- Run on your own inventory: the input checklist.
- Cascade parameters: every choice the cascade asks for.
Running the tests¶
The tests ship with the source distribution, not the wheel. From a source tree:
pip install -e ".[test]"
python -m pytest -q
QUAKECASCADE_FORCE_NUMPY=1 python -m pytest -q # pure-NumPy paths
No test touches the network. The fetch_* helpers in quakecascade.datasets are the only code
that downloads anything, and only when you call them.