Skip to content

datasets

The synthetic town, the open-data fetchers and the DEM regridding.

quakecascade.datasets

Demonstration inputs: a deterministic synthetic town and open-data fetchers.

synthetic_town builds a small, fully synthetic city in a projected metric CRS (UTM zone 35N coordinates, about 3 km across) with every input the cascade needs: a fault trace with a dip geometry, building footprints with storeys, heights, Hazus types, occupants, dwelling units and Vs30, a noded road grid with classes and widths, hospitals and fire stations, candidate open-space sites, a unit grid with residents, a coarse DEM and pipe lengths by material. Nothing in it describes a real place; the numbers exist to exercise the chain, including a few deliberately missing values that show how status codes travel.

The fetch_* functions download open data (OpenStreetMap via osmnx, the Copernicus GLO-30 DEM from its public AWS bucket, the GEM Global Active Faults database from GitHub). They need network access and optional packages, import those lazily, and are never called by the test-suite.

SYNTHETIC_CRS module-attribute

SYNTHETIC_CRS = 'EPSG:32635'

CRS of the synthetic town (WGS 84 / UTM zone 35N, metres).

SYNTHETIC_FAULT_SOURCE module-attribute

SYNTHETIC_FAULT_SOURCE = ...

Source string of the synthetic fault. It is not a real structure.

COPERNICUS_DEM_URL module-attribute

COPERNICUS_DEM_URL = ...

Copernicus DEM GLO-30 tile URL template on the public AWS Open Data bucket.

GEM_FAULTS_URL module-attribute

GEM_FAULTS_URL = ...

GEM Global Active Faults harmonised GeoJSON (CC BY-SA 4.0).

GEM_COMPASS module-attribute

GEM_COMPASS = ...

Compass directions used in the GEM dip_dir field, as azimuths (degrees from north).

Town dataclass

Town(
    crs,
    fault_trace,
    fault,
    buildings,
    roads,
    hospitals,
    fire_stations,
    sites,
    units,
    dem,
    dem_transform,
    pipes,
    attribution=dict(),
)

Inputs of one cascade run.

Frames are GeoDataFrames when geopandas is installed, otherwise pandas DataFrames with a geometry column of Shapely objects.

Attributes:

Name Type Description
crs str

Projected metric CRS of every geometry.

fault_trace LineString

Surface trace of the scenario fault.

fault FaultGeometry

Dip, dip azimuth and seismogenic depths with their source.

buildings frame

building_id, geometry (footprint polygon), floors, height_m, building_type (Hazus base type), design_level (per building, synthetic), occupancy, occupants, dwelling_units, vs30_m_s (NaN for a few buildings) and unit_id.

roads frame

edge_id, geometry (noded LineStrings), road_class, width_m.

hospitals, fire_stations frame

Points with facility_id (and beds for hospitals).

sites frame

Candidate open-space depot/assembly sites: site_id, polygon, area_m2. Candidates only, not designated areas.

units frame

Planning units (500 m cells): unit_id, polygon, population.

dem ndarray

Elevation grid (m), row 0 at the top.

dem_transform tuple

(x_min, y_max, cell_size_m) of dem.

pipes DataFrame

unit_id, length_km, material (some None).

attribution dict

Licence and provenance notes.

synthetic_town

synthetic_town(seed=0)

A deterministic synthetic town for demonstrations and tests.

Parameters:

Name Type Description Default
seed int

Seed of the generator. The same seed gives identical inputs on every machine.

0

Returns:

Type Description
Town

About 500-700 buildings on a 20 x 20 block grid of 150 m blocks, 840 road edges, 3 hospitals, 3 fire stations, 8 candidate sites, 36 planning units, an 8 x 8 DEM at 500 m and pipe lengths per unit. A few buildings have no Vs30, one has no occupant count and a few lanes carry a class ("lane") that a speed table may not list, so status codes can be seen downstream.

Notes

Everything is synthetic, including the fault (see SYNTHETIC_FAULT_SOURCE). The design levels and building types are drawn at random to give a mixed stock; they do not represent any real code history.

fetch_osm

fetch_osm(place=None, bbox=None, *, network_type='drive')

Download buildings, roads, hospitals, fire stations and parks from OpenStreetMap.

Network only. Uses osmnx (pip install 'quakecascade[demo]'); data © OpenStreetMap contributors, ODbL 1.0. When the default Overpass server is busy or unreachable, point osmnx at a mirror before calling, e.g. osmnx.settings.overpass_url = "https://maps.mail.ru/osm/tools/overpass/api".

Parameters:

Name Type Description Default
place str

Place name geocoded by Nominatim.

None
bbox (west, south, east, north)

Geographic bounding box in degrees (EPSG:4326). Exactly one of place and bbox is required.

None
network_type str

osmnx network type for the road graph.

'drive'

Returns:

Type Description
dict

buildings, roads (graph edges, noded at junctions, with edge_id), hospitals, fire_stations, parks: GeoDataFrames in EPSG:4326. Project them with quakecascade.crs.estimate_utm_crs before measuring anything.

fetch_copernicus_dem

fetch_copernicus_dem(bbox)

Read the Copernicus DEM GLO-30 over a bounding box from the public AWS bucket.

Network only; needs rasterio (pip install 'quakecascade[raster]'). Copernicus DEM © DLR e.V. 2010-2014 and © Airbus Defence and Space GmbH 2014-2018, provided under COPERNICUS by the European Union and ESA; free licence with attribution.

Parameters:

Name Type Description Default
bbox (west, south, east, north)

Degrees (EPSG:4326). Must lie within one 1-degree tile.

required

Returns:

Type Description
(ndarray, dict)

Elevation in metres (float, NaN for no-data) and a profile dict with transform (rasterio Affine), crs ("EPSG:4326") and url.

regrid_dem

regrid_dem(
    data,
    src_transform,
    src_crs,
    dst_crs,
    cell_size_m,
    *,
    bounds=None,
)

Average a DEM onto a square grid in a projected metric CRS.

The grid the cascade's liquefaction stage needs (CascadeInputs.dem and dem_transform): row 0 at the top, cells of cell_size_m, NaN for no-data. Each target cell is the mean of the source cells it covers (rasterio.warp.reproject with average resampling), so a 30 m DEM regridded to ~1 km gives the scale Zhu et al. (2015) were fitted on.

Parameters:

Name Type Description Default
data (rows, cols) array

Elevations; NaN is no-data.

required
src_transform Affine

Geotransform of data (e.g. fetch_copernicus_dem(...)[1]["transform"]).

required
src_crs

CRS of data and of the target grid; dst_crs must be metric.

required
dst_crs

CRS of data and of the target grid; dst_crs must be metric.

required
cell_size_m float

Target cell size (m).

required
bounds (x_min, y_min, x_max, y_max)

Target extent in dst_crs; default the source footprint.

None

Returns:

Type Description
(ndarray, tuple)

The regridded elevations and (x_min, y_max, cell_size_m).

dem_grid

dem_grid(bbox, crs, cell_size_m=1000.0)

Copernicus GLO-30 DEM over bbox averaged onto a metric grid, ready for the cascade.

Network only; needs rasterio. Combines fetch_copernicus_dem and regrid_dem. bbox is (west, south, east, north) in degrees within one 1-degree tile; crs is the run's metric CRS. The default 1 km cell is the input scale of Zhu et al. (2015).

Returns:

Type Description
(ndarray, tuple)

dem and dem_transform for quakecascade.cascade.CascadeInputs.

fetch_gem_faults

fetch_gem_faults(bbox, *, cache=None, timeout=120.0)

GEM Global Active Faults traces intersecting a bounding box.

Network only. Downloads GEM_FAULTS_URL (about 10 MB; CC BY-SA 4.0, Styron & Pagani 2020, doi:10.1177/8755293020944182). cache keeps the file for later calls.

Parameters:

Name Type Description Default
bbox (west, south, east, north)

Degrees (EPSG:4326).

required

Returns:

Type Description
GeoDataFrame (or list of GeoJSON features without geopandas)

Fault traces with their attributes (catalog_id, name, slip_type, average_dip, upper_seis_depth, lower_seis_depth ... as published: most numbers are "(preferred, min, max)" text; gem_fault_geometry turns a record into a FaultGeometry).

gem_fault_geometry

gem_fault_geometry(
    record,
    *,
    dip_deg=None,
    dip_azimuth_deg=None,
    upper_depth_km=None,
    lower_depth_km=None,
)

FaultGeometry from one GEM Global Active Faults record.

Reads the preferred values of average_dip, dip_dir, upper_seis_depth and lower_seis_depth (GEM stores them as (preferred, min, max) text). A keyword argument replaces the record's value; a value that is missing from the record and not given raises TypeError instead of being assumed. A vertical fault (dip 90) needs no dip direction. The source string names the record and says, for each number, whether it came from the record or from the caller.

Parameters:

Name Type Description Default
record mapping or Series

One row of fetch_gem_faults (GeoDataFrame row or GeoJSON properties).

required
dip_deg float

Values that replace or complete the record.

None
dip_azimuth_deg float

Values that replace or complete the record.

None
upper_depth_km float

Values that replace or complete the record.

None
lower_depth_km float

Values that replace or complete the record.

None

Returns:

Type Description
FaultGeometry