Skip to content

Commit

Permalink
Merge pull request #10425 from gem/relevant
Browse files Browse the repository at this point in the history
Extended view `relevant_sources`
  • Loading branch information
micheles authored Mar 7, 2025
2 parents 8a209c8 + 64b7de2 commit ddd0ca8
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion debian/changelog
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Michele Simionato]
* Added an extractor `losses_by_site`
* Improved `oq info sources`
* Improved `oq info sources` and `oq show relevant_sources:<IMT>`
* Internal: accepted `source_model_file` in place of
`source_model_logic_tree_file`
* Extended `source_model.serialise_to_nrml` to accept a `mesh_spacing`
Expand Down
5 changes: 5 additions & 0 deletions openquake/calculators/tests/classical_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ def test_case_27(self): # Nankai mutex model
coordinate_bin_width="1.0",
num_epsilon_bins="6")

# check relevant sources
rel = view('relevant_sources:PGV', self.calc.datastore)
fname = general.gettemp(text_table(rel, ext='org'))
self.assertEqualFiles('expected/rel_source.org', fname)

def test_case_29(self): # non parametric source with 2 KiteSurfaces
check = False

Expand Down
21 changes: 15 additions & 6 deletions openquake/calculators/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1591,14 +1591,23 @@ def view_event_based_mfd(token, dstore):
def view_relevant_sources(token, dstore):
"""
Returns a table with the sources contributing more than 10%
of the highest source.
of the highest source. Requires disagg_by_src and a single site.
"""
oq = dstore['oqparam']
assert oq.disagg_by_src
imt = token.split(':')[1]
kw = dstore['oqparam'].postproc_args
[iml] = kw['imls_by_sid']['0']
aw = extract(dstore, f'mean_rates_by_src?imt={imt}&iml={iml}')
rates = aw.array['rate'] # for each source in decreasing order
return aw.array[rates > .1 * rates[0]]
if 'imls_by_sid' in oq.postproc_args:
[iml] = oq.postproc_args['imls_by_sid']['0']
aw = extract(dstore, f'mean_rates_by_src?imt={imt}&iml={iml}')
rates = aw.array['rate'] # for each source in decreasing order
return aw.array[rates > .1 * rates[0]]
else:
m = list(oq.imtls).index(imt)
assert list(oq.hazard_stats())[0] == 'mean', oq.hazard_stats()
iml = dstore['hmaps-stats'][0, 0, m, 0] # the first site and poe
aw = extract(dstore, f'mean_rates_by_src?imt={imt}&iml={iml}')
rates = aw.array['rate'] # for each source in decreasing order
return aw.array[rates > .1 * rates[0]]


def asce_fix(asce, siteid):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
| src_id | rate |
|--------+--------|
| case | 0.0052 |
1 change: 1 addition & 0 deletions openquake/qa_tests_data/classical/case_27/job.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ intensity_measure_types_and_levels = {"PGV": [20]}
maximum_distance = 200.
truncation_level = 99.
disagg_by_src = true
poes = .02

0 comments on commit ddd0ca8

Please sign in to comment.