def __iter__(self): self.dstore.open('r') # if needed attrs = self.dstore.get_attrs('ruptures') code2cls = {} # code -> rupture_cls, surface_cls for key, val in attrs.items(): if key.startswith('code_'): code2cls[int(key[5:])] = [classes[v] for v in val.split()] grp_trt = self.dstore['csm_info'].grp_by("trt") events = self.dstore['events'] ruptures = self.dstore['ruptures'][self.mask] rupgeoms = self.dstore['rupgeoms'][self.mask] # NB: ruptures.sort(order='serial') causes sometimes a SystemError: # <ufunc 'greater'> returned a result with an error set # this is way I am sorting with Python and not with numpy below data = sorted( (serial, ridx) for ridx, serial in enumerate(ruptures['serial'])) for serial, ridx in data: rec = ruptures[ridx] evs = events[rec['eidx1']:rec['eidx2']] if self.grp_id is not None and self.grp_id != rec['grp_id']: continue mesh = numpy.zeros((3, rec['sy'], rec['sz']), F32) for i, arr in enumerate(rupgeoms[ridx]): # i = 0, 1, 2 mesh[i] = arr.reshape(rec['sy'], rec['sz']) rupture_cls, surface_cls = code2cls[rec['code']] rupture = object.__new__(rupture_cls) rupture.serial = serial rupture.surface = object.__new__(surface_cls) rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.seed = rec['seed'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = grp_trt[rec['grp_id']] pmfx = rec['pmfx'] if pmfx != -1: rupture.pmf = self.dstore['pmfs'][pmfx] 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)) ebr = EBRupture(rupture, (), evs) ebr.eidx1 = rec['eidx1'] ebr.eidx2 = rec['eidx2'] # not implemented: rupture_slip_direction yield ebr
def __iter__(self): self.dstore.open() # if needed oq = self.dstore['oqparam'] grp_trt = self.dstore['csm_info'].grp_by("trt") ruptures = self.dstore['ruptures'][self.mask] # NB: ruptures.sort(order='serial') causes sometimes a SystemError: # <ufunc 'greater'> returned a result with an error set # this is way I am sorting with Python and not with numpy below data = sorted((ser, idx) for idx, ser in enumerate(ruptures['serial'])) for serial, ridx in data: rec = ruptures[ridx] evs = self.dstore['events'][rec['eidx1']:rec['eidx2']] if self.grp_id is not None and self.grp_id != rec['grp_id']: continue mesh = rec['points'].reshape(rec['sx'], rec['sy'], rec['sz']) rupture_cls, surface_cls, source_cls = BaseRupture.types[ rec['code']] rupture = object.__new__(rupture_cls) rupture.surface = object.__new__(surface_cls) # MISSING: case complex_fault_mesh_spacing != rupture_mesh_spacing if 'Complex' in surface_cls.__name__: mesh_spacing = oq.complex_fault_mesh_spacing else: mesh_spacing = oq.rupture_mesh_spacing rupture.source_typology = source_cls rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.seed = rec['seed'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = grp_trt[rec['grp_id']] pmfx = rec['pmfx'] # disable check on PlanarSurface to support UCERF ruptures with mock.patch( 'openquake.hazardlib.geo.surface.PlanarSurface.' 'IMPERFECT_RECTANGLE_TOLERANCE', numpy.inf): if pmfx != -1: rupture.pmf = self.dstore['pmfs'][pmfx] if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array( mesh_spacing, rec['points']) elif surface_cls.__name__.endswith('MultiSurface'): rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh_spacing, m1.flatten()) for m1 in mesh ]) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None m = mesh[0] rupture.surface.mesh = RectangularMesh( m['lon'], m['lat'], m['depth']) ebr = EBRupture(rupture, (), evs, serial) ebr.eidx1 = rec['eidx1'] ebr.eidx2 = rec['eidx2'] # not implemented: rupture_slip_direction yield ebr
def _get_ruptures(dstore, events, grp_ids, rup_id): oq = dstore['oqparam'] grp_trt = dstore['csm_info'].grp_trt() for grp_id in grp_ids: trt = grp_trt[grp_id] grp = 'grp-%02d' % grp_id try: recs = dstore['ruptures/' + grp] except KeyError: # no ruptures in grp continue for rec in recs: if rup_id is not None and rup_id != rec['serial']: continue mesh = rec['points'].reshape(rec['sx'], rec['sy'], rec['sz']) rupture_cls, surface_cls, source_cls = BaseRupture.types[ rec['code']] rupture = object.__new__(rupture_cls) rupture.surface = object.__new__(surface_cls) # MISSING: case complex_fault_mesh_spacing != rupture_mesh_spacing if 'Complex' in surface_cls.__name__: mesh_spacing = oq.complex_fault_mesh_spacing else: mesh_spacing = oq.rupture_mesh_spacing rupture.source_typology = source_cls rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.seed = rec['seed'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = trt pmfx = rec['pmfx'] if pmfx != -1: rupture.pmf = dstore['pmfs/' + grp][pmfx] if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array( mesh_spacing, rec['points']) elif surface_cls.__name__.endswith('MultiSurface'): rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh_spacing, m1.flatten()) for m1 in mesh ]) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None m = mesh[0] rupture.surface.mesh = RectangularMesh(m['lon'], m['lat'], m['depth']) sids = dstore['sids'][rec['sidx']] evs = events[rec['eidx1']:rec['eidx2']] ebr = EBRupture(rupture, sids, evs, grp_id, rec['serial']) ebr.eidx1 = rec['eidx1'] ebr.eidx2 = rec['eidx2'] ebr.sidx = rec['sidx'] # not implemented: rupture_slip_direction yield ebr
def __iter__(self): self.dstore.open() # if needed oq = self.dstore['oqparam'] grp_trt = self.dstore['csm_info'].grp_trt() recs = self.dstore['ruptures'][self.slice] for rec in recs: if self.rup_id is not None and self.rup_id != rec['serial']: continue evs = self.dstore['events'][rec['eidx1']:rec['eidx2']] grp_id = evs['grp_id'][0] if self.grp_id is not None and self.grp_id != grp_id: continue mesh = rec['points'].reshape(rec['sx'], rec['sy'], rec['sz']) rupture_cls, surface_cls, source_cls = BaseRupture.types[ rec['code']] rupture = object.__new__(rupture_cls) rupture.surface = object.__new__(surface_cls) # MISSING: case complex_fault_mesh_spacing != rupture_mesh_spacing if 'Complex' in surface_cls.__name__: mesh_spacing = oq.complex_fault_mesh_spacing else: mesh_spacing = oq.rupture_mesh_spacing rupture.source_typology = source_cls rupture.mag = rec['mag'] rupture.rake = rec['rake'] rupture.seed = rec['seed'] rupture.hypocenter = geo.Point(*rec['hypo']) rupture.occurrence_rate = rec['occurrence_rate'] rupture.tectonic_region_type = grp_trt[grp_id] pmfx = rec['pmfx'] if pmfx != -1: rupture.pmf = self.dstore['pmfs'][pmfx] if surface_cls is geo.PlanarSurface: rupture.surface = geo.PlanarSurface.from_array( mesh_spacing, rec['points']) elif surface_cls.__name__.endswith('MultiSurface'): rupture.surface.__init__([ geo.PlanarSurface.from_array(mesh_spacing, m1.flatten()) for m1 in mesh ]) else: # fault surface, strike and dip will be computed rupture.surface.strike = rupture.surface.dip = None m = mesh[0] rupture.surface.mesh = RectangularMesh(m['lon'], m['lat'], m['depth']) ebr = EBRupture(rupture, (), evs, rec['serial']) ebr.eidx1 = rec['eidx1'] ebr.eidx2 = rec['eidx2'] # not implemented: rupture_slip_direction yield ebr