Skip to content

Commit

Permalink
Adding with_betw_ratio in Aristotle mode
Browse files Browse the repository at this point in the history
  • Loading branch information
micheles committed Nov 7, 2024
1 parent 1c9e4bd commit c5fc0c6
Showing 1 changed file with 43 additions and 31 deletions.
74 changes: 43 additions & 31 deletions openquake/calculators/event_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
nofilter, getdefault, get_distances, SourceFilter)
from openquake.hazardlib.calc.gmf import GmfComputer
from openquake.hazardlib.calc.conditioned_gmfs import ConditionedGmfComputer
from openquake.hazardlib import logictree, InvalidFile
from openquake.hazardlib import valid, logictree, InvalidFile
from openquake.hazardlib.calc.stochastic import get_rup_array, rupture_dt
from openquake.hazardlib.source.rupture import (
RuptureProxy, EBRupture, get_ruptures)
Expand Down Expand Up @@ -428,6 +428,46 @@ def compute_avg_gmf(gmf_df, weights, min_iml):
return dic


def read_gsim_lt(oq):
# in aristotle mode the gsim_lt is read from the exposure.hdf5 file
gsim_lt = readinput.get_gsim_lt(oq)
if oq.aristotle:
if not oq.mosaic_model:
if oq.rupture_dict:
lon, lat = [oq.rupture_dict['lon'], oq.rupture_dict['lat']]
elif oq.rupture_xml:
hypo = readinput.get_rupture(oq).hypocenter
lon, lat = [hypo.x, hypo.y]
mosaic_models = get_close_mosaic_models(lon, lat, 5)
# NOTE: using the first mosaic model
oq.mosaic_model = mosaic_models[0]
if len(mosaic_models) > 1:
logging.info('Using the "%s" model' % oq.mosaic_model)
[expo_hdf5] = oq.inputs['exposure']
if oq.mosaic_model == '???':
raise ValueError(
'(%(lon)s, %(lat)s) is not covered by the mosaic!' %
oq.rupture_dict)
if oq.gsim != '[FromFile]':
raise ValueError(
'In Aristotle mode the gsim can not be specified in'
' the job.ini: %s' % oq.gsim)
if oq.tectonic_region_type == '*':
raise ValueError(
'The tectonic_region_type parameter must be specified')
gsim_lt = logictree.GsimLogicTree.from_hdf5(
expo_hdf5, oq.mosaic_model,
oq.tectonic_region_type.encode('utf8'))
# add with_betw_ratio when only the total stddev is defined
betw = {'with_betw_ratio': 1.7}
for gsims in gsim_lt.values.values():
for g, gsim in enumerate(gsims):
if len(gsim.DEFINED_FOR_STANDARD_DEVIATION_TYPES) == 1:
gsims[g] = valid.modified_gsim(
gsim, add_between_within_stds=betw)
return gsim_lt


@base.calculators.add('event_based', 'scenario', 'ucerf_hazard')
class EventBasedCalculator(base.HazardCalculator):
"""
Expand Down Expand Up @@ -590,36 +630,8 @@ def agg_dicts(self, acc, result):

def _read_scenario_ruptures(self):
oq = self.oqparam
gsim_lt = readinput.get_gsim_lt(oq)
if oq.aristotle:
# the gsim_lt is read from the exposure.hdf5 file
if not oq.mosaic_model:
if oq.rupture_dict:
lon, lat = [oq.rupture_dict['lon'], oq.rupture_dict['lat']]
elif oq.rupture_xml:
hypo = readinput.get_rupture(oq).hypocenter
lon, lat = [hypo.x, hypo.y]
mosaic_models = get_close_mosaic_models(lon, lat, 5)
# NOTE: using the first mosaic model
oq.mosaic_model = mosaic_models[0]
if len(mosaic_models) > 1:
logging.info('Using the "%s" model' % oq.mosaic_model)
[expo_hdf5] = oq.inputs['exposure']
if oq.mosaic_model == '???':
raise ValueError(
'(%(lon)s, %(lat)s) is not covered by the mosaic!' %
oq.rupture_dict)
if oq.gsim != '[FromFile]':
raise ValueError(
'In Aristotle mode the gsim can not be specified in'
' the job.ini: %s' % oq.gsim)
if oq.tectonic_region_type == '*':
raise ValueError(
'The tectonic_region_type parameter must be specified')
gsim_lt = logictree.GsimLogicTree.from_hdf5(
expo_hdf5, oq.mosaic_model,
oq.tectonic_region_type.encode('utf8'))
elif (str(gsim_lt.branches[0].gsim) == '[FromFile]'
gsim_lt = read_gsim_lt(oq)
if (str(gsim_lt.branches[0].gsim) == '[FromFile]'
and 'gmfs' not in oq.inputs):
raise InvalidFile('%s: missing gsim or gsim_logic_tree_file' %
oq.inputs['job_ini'])
Expand Down

0 comments on commit c5fc0c6

Please sign in to comment.