def get_ruptures(self, srcfilter=calc.filters.nofilter, min_mag=0): """ :returns: a list of EBRuptures filtered by bounding box """ ebrs = [] with datastore.read(self.filename) as dstore: rupgeoms = dstore['rupgeoms'] for e0, rec in zip(self.e0, self.rup_array): if rec['mag'] < min_mag: continue if srcfilter.integration_distance: sids = srcfilter.close_sids(rec, self.trt) if len(sids) == 0: # the rupture is far away continue else: sids = None geom = rupgeoms[rec['gidx1']:rec['gidx2']].reshape( rec['sx'], rec['sy']) rupture = get_rupture(rec, geom, self.trt) grp_id = rec['grp_id'] ebr = EBRupture(rupture, rec['srcidx'], grp_id, rec['n_occ'], self.samples) # not implemented: rupture_slip_direction ebr.sids = sids ebr.e0 = 0 if self.e0 is None else e0 ebr.id = rec['id'] # rup_id in the datastore ebrs.append(ebr) return ebrs
def get_ruptures(self, srcfilter): """ :returns: a list of EBRuptures filtered by bounding box """ ebrs = [] with datastore.read(self.filename) as dstore: rupgeoms = dstore['rupgeoms'] for e0, rec in zip(self.e0, self.rup_array): if srcfilter.integration_distance: sids = srcfilter.close_sids(rec, self.trt) if len(sids) == 0: # the rupture is far away continue else: sids = None mesh = numpy.zeros((3, rec['sy'], rec['sz']), F32) geom = rupgeoms[rec['gidx1']:rec['gidx2']].reshape( rec['sy'], rec['sz']) mesh[0] = geom['lon'] mesh[1] = geom['lat'] mesh[2] = geom['depth'] rupture_cls, surface_cls = code2cls[rec['code']] rupture = object.__new__(rupture_cls) rupture.rup_id = rec['serial'] rupture.surface = object.__new__(surface_cls) rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = self.trt if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array(mesh[:, 0, :]) elif surface_cls is geo.MultiSurface: # mesh has shape (3, n, 4) rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh[:, i, :]) for i in range(mesh.shape[1]) ]) elif surface_cls is geo.GriddedSurface: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.mesh = Mesh(*mesh) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None rupture.surface.__init__(RectangularMesh(*mesh)) grp_id = rec['grp_id'] ebr = EBRupture(rupture, rec['srcidx'], grp_id, rec['n_occ'], self.samples) # not implemented: rupture_slip_direction ebr.sids = sids ebr.ridx = rec['id'] ebr.e0 = 0 if self.e0 is None else e0 ebrs.append(ebr) return ebrs
def pre_execute(self): """ Read the site collection and initialize GmfComputer and seeds """ oq = self.oqparam cinfo = logictree.FullLogicTree.fake(readinput.get_gsim_lt(oq)) self.realizations = cinfo.get_realizations() self.datastore['full_lt'] = cinfo if 'rupture_model' not in oq.inputs: logging.warning( 'There is no rupture_model, the calculator will just ' 'import data without performing any calculation') super().pre_execute() return self.rup = readinput.get_rupture(oq) self.gsims = readinput.get_gsims(oq) R = len(self.gsims) self.cmaker = ContextMaker( '*', self.gsims, { 'maximum_distance': oq.maximum_distance, 'filter_distance': oq.filter_distance }) super().pre_execute() self.datastore['oqparam'] = oq self.store_rlz_info({}) rlzs_by_gsim = cinfo.get_rlzs_by_gsim(0) E = oq.number_of_ground_motion_fields n_occ = numpy.array([E]) ebr = EBRupture(self.rup, 0, 0, n_occ) ebr.e0 = 0 events = numpy.zeros(E * R, events_dt) for rlz, eids in ebr.get_eids_by_rlz(rlzs_by_gsim).items(): events[rlz * E:rlz * E + E]['id'] = eids events[rlz * E:rlz * E + E]['rlz_id'] = rlz self.datastore['events'] = self.events = events rupser = calc.RuptureSerializer(self.datastore) rup_array = get_rup_array([ebr], self.src_filter()) if len(rup_array) == 0: maxdist = oq.maximum_distance(self.rup.tectonic_region_type, self.rup.mag) raise RuntimeError('There are no sites within the maximum_distance' ' of %s km from the rupture' % maxdist) rupser.save(rup_array) rupser.close() self.computer = GmfComputer(ebr, self.sitecol, oq.imtls, self.cmaker, oq.truncation_level, oq.correl_model, self.amplifier) M32 = (numpy.float32, len(self.oqparam.imtls)) self.sig_eps_dt = [('eid', numpy.uint64), ('sig', M32), ('eps', M32)]
def _read_scenario_ruptures(self): oq = self.oqparam if oq.inputs['rupture_model'].endswith(('.xml', '.toml', '.txt')): self.gsims = readinput.get_gsims(oq) self.cmaker = ContextMaker( '*', self.gsims, {'maximum_distance': oq.maximum_distance, 'filter_distance': oq.filter_distance}) n_occ = numpy.array([oq.number_of_ground_motion_fields]) rup = readinput.get_rupture(oq) ebr = EBRupture(rup, 0, 0, n_occ) ebr.e0 = 0 rup_array = get_rup_array([ebr], self.srcfilter).array mesh = surface_to_array(rup.surface).transpose(1, 2, 0).flatten() hdf5.extend(self.datastore['rupgeoms'], numpy.array([mesh], object)) elif oq.inputs['rupture_model'].endswith('.csv'): aw = readinput.get_ruptures(oq.inputs['rupture_model']) rup_array = aw.array hdf5.extend(self.datastore['rupgeoms'], aw.geom) if len(rup_array) == 0: raise RuntimeError( 'There are no sites within the maximum_distance' ' of %s km from the rupture' % oq.maximum_distance( rup.tectonic_region_type, rup.mag)) gsim_lt = readinput.get_gsim_lt(self.oqparam) # check the number of branchsets branchsets = len(gsim_lt._ltnode) if len(rup_array) == 1 and branchsets > 1: raise InvalidFile( '%s for a scenario calculation must contain a single ' 'branchset, found %d!' % (oq.inputs['job_ini'], branchsets)) fake = logictree.FullLogicTree.fake(gsim_lt) self.realizations = fake.get_realizations() self.datastore['full_lt'] = fake self.store_rlz_info({}) # store weights self.save_params() calc.RuptureImporter(self.datastore).import_rups(rup_array)