Output contract¶
Every stage of the cascade returns its numbers under the same three rules. They are what lets a planner tell a low-risk street from a street with no data.
Missing is never zero¶
A value that cannot be computed is NaN, and a status column beside it says why.
| Code | Meaning |
|---|---|
computed |
computed from complete inputs |
partial |
some contributing inputs were missing; the value is a bound |
no_<input> |
a required input was missing, e.g. no_vs30, no_pga |
empty |
the unit holds nothing to compute on; here a zero is a true zero |
outside_envelope |
the input lies outside the model's calibration range; the value is kept as an extrapolation |
import numpy as np
from quakecascade import contract
status = contract.status_from_inputs(vs30=[760, np.nan], pga=[0.2, 0.3])
# array(['computed', 'no_vs30'], dtype=object)
contract.check_status_consistency(values, status) lists rows whose value and status disagree,
and contract.validate_frame(frame, spec) checks a whole table against a column specification,
raising one ContractError that lists every problem.
Counts sum, intensities do not¶
contract.aggregate(frame, by, {"buildings": "extensive", "pga_g": "intensive"}) sums counts with
min_count=1, so a unit whose rows are all missing stays NaN rather than becoming 0, and takes
the median (or maximum) of intensities. With status_column= the result also carries the number
of rows, the number with a complete value (computed, outside_envelope or empty) and a unit
status: empty when every row is empty, outside_envelope when every row is complete and some are
extrapolations, computed when every row is complete otherwise, partial when only some are
(the sums are then lower bounds), and otherwise the most common missing code. An empty row is
complete, so an empty row beside a missing one gives partial, never a true zero.
Fingerprinted runs¶
contract.build_manifest(run_id, parameters, inputs) returns a JSON-ready record whose
run_fingerprint is the SHA-256 of the canonical JSON of the run id, parameters, inputs and
package version. The creation time is stored but excluded from the fingerprint, so the same run
gives the same fingerprint on any machine. contract.validate_manifest detects any later edit.
No silent coefficients¶
A coefficient that has no citable default (a debris spread factor, a closure share, square metres
per sheltered person) is a required argument. contract.require(value, name) raises a clear
TypeError when it is left out.
Metric distances¶
quakecascade.crs.require_metric(crs) rejects geographic and non-metre CRSs before anything is
measured; estimate_utm_crs(lon, lat) proposes the local UTM zone.