def test_nankai(self): # source model for the Nankai region provided by M. Pagani source_model = os.path.join(os.path.dirname(__file__), 'nankai.xml') # it has a single group containing 15 mutex sources [group] = nrml.to_python(source_model) aae([src.mutex_weight for src in group], [0.0125, 0.0125, 0.0125, 0.0125, 0.1625, 0.1625, 0.0125, 0.0125, 0.025, 0.025, 0.05, 0.05, 0.325, 0.025, 0.1]) seed = 42 start = 0 for i, src in enumerate(group): src.id = i nr = src.num_ruptures src.serial = start + seed start += nr param = dict(ses_per_logic_tree_path=10, filter_distance='rjb', gsims=[SiMidorikawa1999SInter()]) sf = calc.filters.SourceFilter(None, {}) dic = sum(sample_ruptures(group, sf, param), {}) self.assertEqual(len(dic['rup_array']), 6) self.assertEqual(len(dic['calc_times']), 15) # mutex sources # test no filtering 1 ruptures = list(stochastic_event_set(group)) self.assertEqual(len(ruptures), 19) # test no filtering 2 ruptures = sum(sample_ruptures(group, sf, param), {})['rup_array'] self.assertEqual(len(ruptures), 6)
def test_nankai(self): # source model for the Nankai region provided by M. Pagani source_model = os.path.join(os.path.dirname(__file__), 'nankai.xml') # it has a single group containing 15 mutex sources [group] = nrml.to_python(source_model) aae([src.mutex_weight for src in group], [0.0125, 0.0125, 0.0125, 0.0125, 0.1625, 0.1625, 0.0125, 0.0125, 0.025, 0.025, 0.05, 0.05, 0.325, 0.025, 0.1]) seed = 42 rup_serial = numpy.arange(seed, seed + group.tot_ruptures, dtype=numpy.uint32) start = 0 for i, src in enumerate(group): src.id = i nr = src.num_ruptures src.serial = rup_serial[start:start + nr] start += nr lonlat = 135.68, 35.68 site = Site(geo.Point(*lonlat), 800, z1pt0=100., z2pt5=1.) s_filter = SourceFilter(SiteCollection([site]), {}) param = dict(ses_per_logic_tree_path=10, filter_distance='rjb', gsims=[SiMidorikawa1999SInter()]) dic = sum(sample_ruptures(group, param, s_filter), {}) self.assertEqual(len(dic['rup_array']), 5) self.assertEqual(len(dic['calc_times']), 15) # mutex sources # test no filtering 1 ruptures = list(stochastic_event_set(group)) self.assertEqual(len(ruptures), 19) # test no filtering 2 ruptures = sum(sample_ruptures(group, param), {})['rup_array'] self.assertEqual(len(ruptures), 5)
def test_nankai(self): # source model for the Nankai region provided by M. Pagani source_model = os.path.join(os.path.dirname(__file__), 'nankai.xml') # it has a single group containing 15 mutex sources [group] = nrml.to_python(source_model) for i, src in enumerate(group): src.id = i src.grp_id = 0 aae([src.mutex_weight for src in group], [ 0.0125, 0.0125, 0.0125, 0.0125, 0.1625, 0.1625, 0.0125, 0.0125, 0.025, 0.025, 0.05, 0.05, 0.325, 0.025, 0.1 ]) param = dict(ses_per_logic_tree_path=10, ses_seed=42, imtls={}) cmaker = contexts.ContextMaker('*', [SiMidorikawa1999SInter()], param) dic = sum(sample_ruptures(group, cmaker), {}) self.assertEqual(len(dic['rup_array']), 8) self.assertEqual(len(dic['calc_times']), 15) # mutex sources # test no filtering 1 ruptures = list(stochastic_event_set(group)) self.assertEqual(len(ruptures), 19) # test no filtering 2 ruptures = sum(sample_ruptures(group, cmaker), {})['rup_array'] self.assertEqual(len(ruptures), 8)
def test_nankai(self): # source model for the Nankai region provided by M. Pagani source_model = os.path.join(os.path.dirname(__file__), 'nankai.xml') # it has a single group containing 15 mutex sources [group] = nrml.to_python(source_model) aae([src.mutex_weight for src in group], [0.0125, 0.0125, 0.0125, 0.0125, 0.1625, 0.1625, 0.0125, 0.0125, 0.025, 0.025, 0.05, 0.05, 0.325, 0.025, 0.1]) seed = 42 start = 0 for i, src in enumerate(group): src.id = i nr = src.num_ruptures src.serial = start + seed start += nr param = dict(ses_per_logic_tree_path=10, filter_distance='rjb', gsims=[SiMidorikawa1999SInter()]) sf = calc.filters.SourceFilter(None, {}) dic = sum(sample_ruptures(group, sf, param), {}) self.assertEqual(len(dic['rup_array']), 5) self.assertEqual(len(dic['calc_times']), 15) # mutex sources # test no filtering 1 ruptures = list(stochastic_event_set(group)) self.assertEqual(len(ruptures), 19) # test no filtering 2 ruptures = sum(sample_ruptures(group, sf, param), {})['rup_array'] self.assertEqual(len(ruptures), 5)
def compute_hazard(sources_or_ruptures, src_filter, rlzs_by_gsim, param, monitor): """ Compute events, ruptures, gmfs and hazard curves """ res = AccumDict() with monitor('building ruptures', measuremem=True): if isinstance(sources_or_ruptures, RuptureGetter): grp_id = sources_or_ruptures.grp_id res['ruptures'] = {} ruptures = list(sources_or_ruptures) sitecol = src_filter else: grp_id = sources_or_ruptures[0].src_group_id dic = sample_ruptures(sources_or_ruptures, src_filter, rlzs_by_gsim, param, monitor) ruptures = dic['eb_ruptures'] res.num_events = dic['num_events'] res.calc_times = dic['calc_times'] res.eff_ruptures = {grp_id: dic['num_ruptures']} res['ruptures'] = {grp_id: ruptures} res.num_ruptures = len(ruptures) sitecol = src_filter.sitecol res['num_ruptures'] = len(ruptures) getter = GmfGetter(rlzs_by_gsim, ruptures, sitecol, param['oqparam'], param['min_iml'], param['samples']) res.update(getter.compute_gmfs_curves(monitor)) if param['oqparam'].save_ruptures is False: res.events = get_events(ruptures) res['ruptures'] = {} return res
def test_nankai(self): # source model for the Nankai region provided by M. Pagani source_model = os.path.join(os.path.dirname(__file__), 'nankai.xml') # it has a single group containing 15 mutex sources [group] = nrml.to_python(source_model) aae(group.srcs_weights, [ 0.0125, 0.0125, 0.0125, 0.0125, 0.1625, 0.1625, 0.0125, 0.0125, 0.025, 0.025, 0.05, 0.05, 0.325, 0.025, 0.1 ]) rup_serial = numpy.arange(group.tot_ruptures, dtype=numpy.uint32) start = 0 for i, src in enumerate(group): src.id = i nr = src.num_ruptures src.serial = rup_serial[start:start + nr] start += nr group.samples = 1 lonlat = 135.68, 35.68 site = Site(geo.Point(*lonlat), 800, True, z1pt0=100., z2pt5=1.) s_filter = SourceFilter(SiteCollection([site]), {}) param = dict(ses_per_logic_tree_path=10, seed=42) gsims = [SiMidorikawa1999SInter()] dic = sample_ruptures(group, s_filter, gsims, param) self.assertEqual(dic['num_ruptures'], 19) # total ruptures self.assertEqual(dic['num_events'], 16) self.assertEqual(len(dic['eb_ruptures']), 8) self.assertEqual(len(dic['calc_times']), 15) # mutex sources # test export mesh = numpy.array([lonlat], [('lon', float), ('lat', float)]) ebr = dic['eb_ruptures'][0] ebr.export(mesh)
def preprocess(srcs, srcfilter, param, monitor): """ :returns: a dict src_group_id -> sources """ src = srcs[0] if 'ses_per_logic_tree_path' in param: # from event based # keep only the sources producing ruptures from openquake.hazardlib.calc.stochastic import sample_ruptures ok = [] for src in srcfilter.filter(srcs): gsims = param['gsims_by_trt'][src.tectonic_region_type] dic = sample_ruptures([src], srcfilter, gsims, param, monitor) vars(src).update(dic) ok.append(src) else: # from classical ok = list(srcfilter.filter(srcs)) return {src.src_group_id: ok}
def build_ruptures(srcs, srcfilter, param, monitor): """ A small wrapper around :func: `openquake.hazardlib.calc.stochastic.sample_ruptures` """ acc = [] n = 0 mon = monitor('making contexts', measuremem=False) for src in srcs: dic = sample_ruptures([src], param, srcfilter, mon) vars(src).update(dic) acc.append(src) n += len(dic['eb_ruptures']) if n > param['ruptures_per_block']: yield acc n = 0 acc.clear() if acc: yield acc
def compute_ruptures(sources, src_filter, gsims, param, monitor): """ :param sources: a sequence of sources of the same group :param src_filter: a source site filter :param gsims: a list of GSIMs for the current tectonic region model :param param: a dictionary of additional parameters :param monitor: monitor instance :returns: a dictionary src_group_id -> [Rupture instances] """ # NB: by construction each block is a non-empty list with # sources of the same src_group_id grp_id = sources[0].src_group_id dic = sample_ruptures(sources, src_filter, gsims, param, monitor) res = AccumDict({grp_id: dic['eb_ruptures']}) res.num_events = dic['num_events'] res.calc_times = dic['calc_times'] res.eff_ruptures = {grp_id: dic['num_ruptures']} return res