Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,4 @@ src/
dev_scripts/
.claude/
CLAUDE.md
ruff.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
eq,longitude,latitude,depth,magnitude,strike,dip,rake,occurrence_rate,cell_id,branch,eq_dist,mag_like,attitude_diff,rake_diff,likelihood,rupture
0,122.84613648764069,13.393473300984715,22.0,6.1499999999999995,324.09826048674364,89.99999999999991,0.0,6.217723076923076e-05,836864fffffffff,0,0.008307445332028911,0.9999999999999982,,,0.8700803130360725,88.1_959_0
1,122.82444879123811,13.422612503171793,5.0,6.35,324.0932014578836,89.99999999999862,0.0,4.44449128540305e-05,836864fffffffff,0,0.008751188966425691,1.0,,,0.8700707993251775,88.3_20_0
2,122.82444879123811,13.422612503171793,17.0,6.35,324.09320145750996,89.99999999999943,0.0,4.44449128540305e-05,836864fffffffff,0,0.008751188966425691,1.0,,,0.8700707993251775,88.3_632_0
3,123.13515611661873,13.043089363159988,21.0,6.35,138.2705232295675,89.9999999999986,0.0,4.44449128540305e-05,836864fffffffff,0,0.009577834017931709,1.0,,,0.8700254940656579,88.3_863_0
4,123.24021755955228,12.942734040361454,21.0,6.35,132.64286592590292,89.9999999999999,0.0,4.44449128540305e-05,836864fffffffff,0,0.056623999975138735,1.0,,,0.8674509571948621,88.3_871_0
5,123.15902406860862,13.015642607875844,8.0,6.1499999999999995,316.7786155835812,89.9999999999998,0.0,6.217723076923076e-05,836864fffffffff,0,0.008121511350797988,0.7999999999999989,,,0.795800594960344,88.1_258_0
6,123.39769667412976,12.791267785239032,10.0,6.75,315.7604441751407,89.99999999999835,0.0,2.819954861111111e-05,836864fffffffff,0,0.04854416788542823,1.0,,,0.8680498565564359,88.7_160_0
7,122.8678187969801,13.364332403917711,12.0,6.1499999999999995,324.10330252042854,89.99999999999955,0.0,6.217723076923076e-05,836864fffffffff,0,0.00795326940211525,0.9999999999999982,,,0.8701003562915766,88.1_441_0
8,122.97988381799169,13.221440625581813,14.0,6.85,141.13615381909796,89.99999999999646,0.0,3.43144414893617e-05,836864fffffffff,0,0.026060283180693623,1.0,,,0.8692267944825339,88.8_218_0
9,122.93824935983814,13.26961269720836,12.0,7.05,141.93588061379313,89.99999999999955,0.0,4.573460674157303e-05,836864fffffffff,0,0.007548858951467621,1.0,,,0.8701777827980643,88.10_24_0
10,123.39126255517168,12.797710797835844,12.0,6.45,135.75903803079942,89.99999999999896,0.0,4.011006188118812e-05,836864fffffffff,0,0.05048088112361234,1.0,,,0.8678294815992909,88.4_369_0
11,122.97988381799169,13.221440625581813,13.0,7.25,141.3340478025568,89.9999999999992,0.0,6.585217948717948e-05,836864fffffffff,0,0.026060283180693623,1.0,,,0.8692997775095772,88.12_22_0
12,123.51988382946314,12.668819896039038,6.0,6.05,318.1431789251336,89.99999999999712,0.0,7.753100952380953e-05,836860fffffffff,0,0.013649455201166645,1.0,,,0.8697652951396461,88.0_183_0
13,123.78727949553483,12.304362287437804,8.0,6.05,139.35394269163334,89.99999999999831,0.0,7.753100952380953e-05,836860fffffffff,0,0.0523018481174991,1.0,,,0.8675454214243122,88.0_313_0
0,122.84613648764069,13.393473300984715,22.0,6.1499999999999995,324.09826048674364,89.99999999999991,0.0,6.217723076923076e-05,836864fffffffff,composite,0.008307445332028911,0.9999999999999982,,,0.8700803130360725,88.1_959_composite
1,122.82444879123811,13.422612503171793,5.0,6.35,324.0932014578836,89.99999999999862,0.0,4.44449128540305e-05,836864fffffffff,composite,0.008751188966425691,1.0,,,0.8700707993251775,88.3_20_composite
2,122.82444879123811,13.422612503171793,17.0,6.35,324.09320145750996,89.99999999999943,0.0,4.44449128540305e-05,836864fffffffff,composite,0.008751188966425691,1.0,,,0.8700707993251775,88.3_632_composite
3,123.13515611661873,13.043089363159988,21.0,6.35,138.2705232295675,89.9999999999986,0.0,4.44449128540305e-05,836864fffffffff,composite,0.009577834017931709,1.0,,,0.8700254940656579,88.3_863_composite
4,123.24021755955228,12.942734040361454,21.0,6.35,132.64286592590292,89.9999999999999,0.0,4.44449128540305e-05,836864fffffffff,composite,0.056623999975138735,1.0,,,0.8674509571948621,88.3_871_composite
5,123.15902406860862,13.015642607875844,8.0,6.1499999999999995,316.7786155835812,89.9999999999998,0.0,6.217723076923076e-05,836864fffffffff,composite,0.008121511350797988,0.7999999999999989,,,0.795800594960344,88.1_258_composite
6,123.39769667412976,12.791267785239032,10.0,6.75,315.7604441751407,89.99999999999835,0.0,2.819954861111111e-05,836864fffffffff,composite,0.04854416788542823,1.0,,,0.8680498565564359,88.7_160_composite
7,122.8678187969801,13.364332403917711,12.0,6.1499999999999995,324.10330252042854,89.99999999999955,0.0,6.217723076923076e-05,836864fffffffff,composite,0.00795326940211525,0.9999999999999982,,,0.8701003562915766,88.1_441_composite
8,122.97988381799169,13.221440625581813,14.0,6.85,141.13615381909796,89.99999999999646,0.0,3.43144414893617e-05,836864fffffffff,composite,0.026060283180693623,1.0,,,0.8692267944825339,88.8_218_composite
9,122.93824935983814,13.26961269720836,12.0,7.05,141.93588061379313,89.99999999999955,0.0,4.573460674157303e-05,836864fffffffff,composite,0.007548858951467621,1.0,,,0.8701777827980643,88.10_24_composite
10,123.39126255517168,12.797710797835844,12.0,6.45,135.75903803079942,89.99999999999896,0.0,4.011006188118812e-05,836864fffffffff,composite,0.05048088112361234,1.0,,,0.8678294815992909,88.4_369_composite
11,122.97988381799169,13.221440625581813,13.0,7.25,141.3340478025568,89.9999999999992,0.0,6.585217948717948e-05,836864fffffffff,composite,0.026060283180693623,1.0,,,0.8692997775095772,88.12_22_composite
12,123.51988382946314,12.668819896039038,6.0,6.05,318.1431789251336,89.99999999999712,0.0,7.753100952380953e-05,836860fffffffff,composite,0.013649455201166645,1.0,,,0.8697652951396461,88.0_183_composite
13,123.78727949553483,12.304362287437804,8.0,6.05,139.35394269163334,89.99999999999831,0.0,7.753100952380953e-05,836860fffffffff,composite,0.0523018481174991,1.0,,,0.8675454214243122,88.0_313_composite
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def test_get_matching_rups_sample(self):
)

assert isinstance(matching_rup, pd.Series)
assert matching_rup.name == "88.12_22_0"
assert matching_rup.name == "88.12_22_composite"

def test_match_eqs_to_rups(self):
match_results = match_eqs_to_rups(
Expand Down
5 changes: 4 additions & 1 deletion openquake/hme/utils/io/source_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
from openquake.baselib.general import AccumDict

from openquake.commonlib import datastore
from openquake.commonlib.readinput import get_params
from openquake.commonlib.readinput import (
get_params,
get_composite_source_model,
)
from openquake.engine.engine import create_jobs, run_jobs

from openquake.hazardlib.gsim_lt import GsimLogicTree
Expand Down
3 changes: 2 additions & 1 deletion openquake/hme/utils/io/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,5 @@ def test_2_branches():
c_ssm_lt_weights,
)

breakpoint()
assert (branch_rdf.occurrence_rate.sum() ==
collapse_rdf.occurrence_rate.sum())
108 changes: 72 additions & 36 deletions openquake/hme/utils/io/tests/test_source_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import pathlib
import unittest

from openquake.hazardlib.source import SimpleFaultSource
import numpy as np
from openquake.hazardlib.source import SimpleFaultSource, PointSource

from openquake.hme.core.core import read_yaml_config
from openquake.hme.utils.tests import load_sm1
Expand Down Expand Up @@ -113,28 +114,51 @@ def test_process_source_logic_tree_oq():
tectonic_region_types=source_cfg["tectonic_region_types"],
branch=source_cfg["branch"],
description=load_sm1.cfg["meta"]["description"],
# collapse_lt=True, # test without to make sure default args tested
)

assert list(ssm_lt_sources.keys()) == [0]
assert len(ssm_lt_sources[0]) == 18
assert isinstance(ssm_lt_sources[0][0], SimpleFaultSource)

assert list(ssm_lt_weights.keys()) == [0]
assert ssm_lt_weights == {0: 1.0}
assert len(ssm_lt_sources) == 1
assert "composite" in ssm_lt_sources
assert len(ssm_lt_sources["composite"]) == 18
assert isinstance(ssm_lt_sources["composite"][0], SimpleFaultSource)

assert list(ssm_lt_weights.keys()) == ["composite"]
assert ssm_lt_weights == {
"composite": {
"88.0": 1.0,
"88.1": 1.0,
"88.10": 1.0,
"88.11": 1.0,
"88.12": 1.0,
"88.13": 1.0,
"88.14": 1.0,
"88.15": 1.0,
"88.16": 1.0,
"88.17": 1.0,
"88.2": 1.0,
"88.3": 1.0,
"88.4": 1.0,
"88.5": 1.0,
"88.6": 1.0,
"88.7": 1.0,
"88.8": 1.0,
"88.9": 1.0,
}
}


def test_2_branches_compound():
test_dir = (
BASE_PATH
/ '..'
/ '..'
/ 'tests'
/ 'data'
/ 'source_models'
/ '2_branches'
/ ".."
/ ".."
/ "tests"
/ "data"
/ "source_models"
/ "2_branches"
)
cfg = read_yaml_config(test_dir / 'test_2_ssm_branches.yaml')
source_cfg = cfg['input']['ssm']
cfg = read_yaml_config(test_dir / "test_2_ssm_branches.yaml")
source_cfg = cfg["input"]["ssm"]
(
ssm_lt_sources,
ssm_lt_weights,
Expand All @@ -143,31 +167,31 @@ def test_2_branches_compound():
) = process_source_logic_tree_oq(
source_cfg["job_ini_file"],
test_dir / source_cfg["ssm_dir"],
collapse_lt=False,
)

assert tuple(ssm_lt_sources.keys()) == (0, 1)
assert len(ssm_lt_sources[0]) == 2
assert ssm_lt_sources[0][0].__class__.__name__ == 'PointSource'
assert ssm_lt_sources[0][0].__class__.__name__ == "PointSource"

assert ssm_lt_weights == {0: 0.75, 1: 0.25}
assert ssm_lt_rup_counts == {0: [1, 1], 1: [1, 1]}
# no need to test gsim_lt
# breakpoint()


# @unittest.skip("not implemented correctly")
def test_2_branches_collapse():
test_dir = (
BASE_PATH
/ '..'
/ '..'
/ 'tests'
/ 'data'
/ 'source_models'
/ '2_branches'
/ ".."
/ ".."
/ "tests"
/ "data"
/ "source_models"
/ "2_branches"
)
cfg = read_yaml_config(test_dir / 'test_2_ssm_branches.yaml')
source_cfg = cfg['input']['ssm']
cfg = read_yaml_config(test_dir / "test_2_ssm_branches.yaml")
source_cfg = cfg["input"]["ssm"]
(
ssm_lt_sources,
ssm_lt_weights,
Expand All @@ -179,22 +203,34 @@ def test_2_branches_collapse():
collapse_lt=True,
)

# breakpoint()
assert len(ssm_lt_sources) == 1
assert "composite" in ssm_lt_sources
assert len(ssm_lt_sources["composite"]) == 3
assert isinstance(ssm_lt_sources["composite"][0], PointSource)

assert list(ssm_lt_weights.keys()) == ["composite"]
assert ssm_lt_weights == {
"composite": {
"1": np.float32(1.0),
"2": np.float32(0.75),
"3": np.float32(0.25),
}
}


def test_2_branches_1_branch():
test_dir = (
BASE_PATH
/ '..'
/ '..'
/ 'tests'
/ 'data'
/ 'source_models'
/ '2_branches'
/ ".."
/ ".."
/ "tests"
/ "data"
/ "source_models"
/ "2_branches"
)
cfg = read_yaml_config(test_dir / 'test_2_ssm_branches.yaml')
source_cfg = cfg['input']['ssm']
source_cfg['branch'] = 1
cfg = read_yaml_config(test_dir / "test_2_ssm_branches.yaml")
source_cfg = cfg["input"]["ssm"]
source_cfg["branch"] = 1
(
ssm_lt_sources,
ssm_lt_weights,
Expand All @@ -203,7 +239,7 @@ def test_2_branches_1_branch():
) = process_source_logic_tree_oq(
source_cfg["job_ini_file"],
test_dir / source_cfg["ssm_dir"],
branch=source_cfg['branch'],
branch=source_cfg["branch"],
)

assert tuple(ssm_lt_sources.keys()) == (1,)
Expand Down
Loading