Skip to content

Commit cf2ea99

Browse files
lispandfoundclaude
andcommitted
Rewrite bb-sim on dask and switch to the site-calculation models
Two changes to the same function body, which is why they are one commit. **Larger than memory.** `bb-sim` read both waveform files entirely into memory and looped over the three components in Python. Now LF and HF are opened lazily, the common stations are selected on the *backend* arrays before chunking -- selecting after chunking makes station reordering an all-to-all dask shuffle, which materialises the whole array -- and the recombination runs per chunk under `map_blocks`. Chunking is over stations only, so each chunk holds complete traces for resampling, alignment and filtering. `resample_signal` and `align_datasets` replace the old pad-and-align: the two legs no longer have to share a timestep, so an SW4 LF run at one dt can be combined with HF at another. `relabel_hf_components` maps HF's 090/000/ver onto LF's x/y/z once, up front. **Site amplification.** Replaces `qcore.siteamp_models.cb_amp_multi` with the `site-calculation` models, selected by `bb.site_amp_version`: CB2014 as before, or BA2018. The amplification is now constrained to an explicit [fmin, fmax] band with logarithmic tapers at both ends, which is what the two new `fhightop` and `fmax` parameters are for -- the old code had a lowpass taper only. `site_amp_version` becomes an enum rather than a free string. It was previously declared, defaulted to "2014", and read by nothing at all. The shared broadband parameters move from each defaults version into root; the versions now carry only `flo`, which is the one value that genuinely differs between them. Station-dimension coordinates -- `supergrid_depth` among them -- ride through `map_blocks` untouched, which is why the supergrid penetration is carried as a coordinate rather than a data variable. This changes broadband results: different site amplification model, and a highpass taper where there was none. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent a092176 commit cf2ea99

11 files changed

Lines changed: 408 additions & 122 deletions

File tree

‎pyproject.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ dependencies = [
1616
"nshmdb>=2026.09.1",
1717
"oq_wrapper>=2025.12.3",
1818
"qcore-utils>=2025.12.2",
19+
"site-calculation>=2026.7.1",
1920
"source_modelling>=2026.08.1",
2021
# Data Formats
2122
"geopandas",
@@ -141,6 +142,7 @@ known-first-party = [
141142
"IM",
142143
"mera",
143144
"velocity_modelling",
145+
"site_calculation",
144146
]
145147

146148
[tool.ruff.lint.per-file-ignores]

‎tests/test_realisation.py‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,23 @@ def test_emod3d(tmp_path: Path) -> None:
604604
def test_broadband_parameters(tmp_path: Path) -> None:
605605
test_realisation = tmp_path / "realisation.json"
606606
broadband_parameters = realisations.BroadbandParameters(
607-
flo=0.5, fmidbot=0.5, fmin=0.25, site_amp_version="2014"
607+
flo=0.5,
608+
fmidbot=0.5,
609+
fmin=0.2,
610+
fhightop=100.0,
611+
fmax=101.0,
612+
site_amp_version=schemas.SiteAmpModel.BA2018,
608613
)
609614
broadband_parameters.write_to_realisation(test_realisation)
610615
with open(test_realisation, "r") as realisation_handle:
611616
assert json.load(realisation_handle) == {
612617
"bb": {
613618
"flo": 0.5,
614619
"fmidbot": 0.5,
615-
"fmin": 0.25,
616-
"site_amp_version": "2014",
620+
"fmin": 0.2,
621+
"fhightop": 100.0,
622+
"fmax": 101.0,
623+
"site_amp_version": "ba2018",
617624
}
618625
}
619626
assert (

‎uv.lock‎

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎workflow/default_parameters/root/defaults.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,3 +1526,9 @@ hf_velocity_model_1d:
15261526
rho: 3.33
15271527
Qp: 394.80
15281528
Qs: 197.40
1529+
bb:
1530+
fmin: 0.2
1531+
fmidbot: 0.5
1532+
fhightop: 100.0
1533+
fmax: 101.0
1534+
site_amp_version: "ba2018"

‎workflow/default_parameters/v24_2_2_1/defaults.yaml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ resolution:
33
resolution: 0.1
44
bb:
55
flo: 1.0
6-
fmidbot: 0.5
7-
fmin: 0.25
8-
site_amp_version: "2014"

‎workflow/default_parameters/v24_2_2_2/defaults.yaml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ resolution:
33
resolution: 0.2
44
bb:
55
flo: 0.5
6-
fmidbot: 0.5
7-
fmin: 0.25
8-
site_amp_version: "2014"

‎workflow/default_parameters/v24_2_2_4/defaults.yaml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ resolution:
33
resolution: 0.4
44
bb:
55
flo: 0.25
6-
fmidbot: 0.5
7-
fmin: 0.25
8-
site_amp_version: "2014"

‎workflow/default_parameters/v26_7_1Hz/defaults.yaml‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
---
22
bb:
33
flo: 1.0
4-
fmidbot: 0.5
5-
fmin: 0.2
6-
site_amp_version: "ba2018"
74
velocity_model:
85
# Overrides the root default of 2.0 km, which is an EMOD3D value and has no
96
# absorbing layer to clear. Two criteria bear on this number, and only the

‎workflow/realisations.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,15 @@ class BroadbandParameters(RealisationConfiguration):
13661366
flo: float
13671367
"""low/high frequency cutoff."""
13681368
fmidbot: float
1369-
"""fmidbot for site amplification"""
1369+
"""fmidbot for the site amplification lowpass taper."""
13701370
fmin: float
1371-
"""fmin for site amplification."""
1372-
site_amp_version: str
1371+
"""fmin for the site amplification lowpass taper."""
1372+
fhightop: float
1373+
"""fhightop for the site amplification highpass taper."""
1374+
fmax: float
1375+
"""fmax for the site amplification highpass taper."""
1376+
site_amp_version: schemas.SiteAmpModel
1377+
"""The site amplification model to apply."""
13731378

13741379

13751380
@dataclasses.dataclass

‎workflow/schemas.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ class Stype(StrEnum):
3535
seki = "seki"
3636

3737

38+
class SiteAmpModel(StrEnum):
39+
"""Site amplification models for broadband simulation."""
40+
41+
CB2014 = "cb2014"
42+
BA2018 = "ba2018"
43+
44+
3845
class KModel(IntEnum):
3946
"""Correlation length models for genslip."""
4047

@@ -1168,7 +1175,13 @@ def _corners_to_array(corners_spec: list[dict[str, float]]) -> np.ndarray:
11681175
Literal("fmin", description="fmin for site amplification"): And(
11691176
NUMBER, _is_non_negative
11701177
),
1171-
"site_amp_version": str,
1178+
Literal("fhightop", description="fhightop for site amplification"): And(
1179+
NUMBER, _is_non_negative
1180+
),
1181+
Literal("fmax", description="fmax for site amplification"): And(
1182+
NUMBER, _is_non_negative
1183+
),
1184+
"site_amp_version": Use(SiteAmpModel),
11721185
}
11731186
)
11741187

0 commit comments

Comments
 (0)