def _expected_point(self): tgr_mfd = mfd.TruncatedGRMFD(a_val=-3.5, b_val=1.0, min_mag=5.0, max_mag=6.5, bin_width=1.0) np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0) np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0) npd = pmf.PMF([(decimal.Decimal("0.3"), np1), (decimal.Decimal("0.7"), np2)]) hd = pmf.PMF([(decimal.Decimal("0.5"), 4.0), (decimal.Decimal("0.5"), 8.0)]) point = source.PointSource( source_id="2", name="point", tectonic_region_type="Stable Continental Crust", mfd=tgr_mfd, rupture_mesh_spacing=MESH_SPACING, magnitude_scaling_relationship=scalerel.WC1994(), rupture_aspect_ratio=0.5, upper_seismogenic_depth=0.0, lower_seismogenic_depth=10.0, location=geo.Point(-122.0, 38.0), nodal_plane_distribution=npd, hypocenter_distribution=hd) return point
def _expected_point(self): tgr_mfd = mfd.TruncatedGRMFD( a_val=-3.5, b_val=1.0, min_mag=5.0, max_mag=6.5, bin_width=1.0) np1 = geo.NodalPlane(strike=0.0, dip=90.0, rake=0.0) np2 = geo.NodalPlane(strike=90.0, dip=45.0, rake=90.0) npd = pmf.PMF([(0.3, np1), (0.7, np2)]) hd = pmf.PMF([(0.5, 4.0), (0.5, 8.0)]) point = source.PointSource( source_id="2", name="point", tectonic_region_type="Stable Continental Crust", mfd=tgr_mfd, rupture_mesh_spacing=self.rupture_mesh_spacing, magnitude_scaling_relationship=scalerel.WC1994(), rupture_aspect_ratio=0.5, upper_seismogenic_depth=0.0, lower_seismogenic_depth=10.0, location=geo.Point(-122.0, 38.0), nodal_plane_distribution=npd, hypocenter_distribution=hd, temporal_occurrence_model=PoissonTOM(50.)) point.num_ruptures = point.count_ruptures() return point
def area_to_point_sources(area_src): """ Split an area source into a generator of point sources. MFDs will be rescaled appropriately for the number of points in the area mesh. :param area_src: :class:`openquake.hazardlib.source.AreaSource` """ mesh = area_src.polygon.discretize(area_src.area_discretization) num_points = len(mesh) area_mfd = area_src.mfd if isinstance(area_mfd, mfd.TruncatedGRMFD): new_mfd = mfd.TruncatedGRMFD(a_val=area_mfd.a_val - math.log10(num_points), b_val=area_mfd.b_val, bin_width=area_mfd.bin_width, min_mag=area_mfd.min_mag, max_mag=area_mfd.max_mag) elif isinstance(area_mfd, mfd.EvenlyDiscretizedMFD): new_occur_rates = [x / num_points for x in area_mfd.occurrence_rates] new_mfd = mfd.EvenlyDiscretizedMFD(min_mag=area_mfd.min_mag, bin_width=area_mfd.bin_width, occurrence_rates=new_occur_rates) elif isinstance(area_mfd, mfd.ArbitraryMFD): new_occur_rates = [x / num_points for x in area_mfd.occurrence_rates] new_mfd = mfd.ArbitraryMFD(magnitudes=area_mfd.magnitudes, occurrence_rates=new_occur_rates) elif isinstance(area_mfd, mfd.YoungsCoppersmith1985MFD): new_mfd = mfd.YoungsCoppersmith1985MFD.from_characteristic_rate( area_mfd.min_mag, area_mfd.b_val, area_mfd.char_mag, area_mfd.char_rate / num_points, area_mfd.bin_width) else: raise TypeError('Unknown MFD: %s' % area_mfd) for i, (lon, lat) in enumerate(zip(mesh.lons, mesh.lats)): pt = source.PointSource( # Generate a new ID and name source_id='%s:%s' % (area_src.source_id, i), name='%s:%s' % (area_src.name, i), tectonic_region_type=area_src.tectonic_region_type, mfd=new_mfd, rupture_mesh_spacing=area_src.rupture_mesh_spacing, magnitude_scaling_relationship=area_src. magnitude_scaling_relationship, rupture_aspect_ratio=area_src.rupture_aspect_ratio, upper_seismogenic_depth=area_src.upper_seismogenic_depth, lower_seismogenic_depth=area_src.lower_seismogenic_depth, location=geo.Point(lon, lat), nodal_plane_distribution=area_src.nodal_plane_distribution, hypocenter_distribution=area_src.hypocenter_distribution, temporal_occurrence_model=area_src.temporal_occurrence_model) pt.src_group_id = area_src.src_group_id pt.num_ruptures = pt.count_ruptures() yield pt
def area_to_point_sources(area_src, area_src_disc): """ Split an area source into a generator of point sources. MFDs will be rescaled appropriately for the number of points in the area mesh. :param area_src: :class:`openquake.hazardlib.source.AreaSource` :param float area_src_disc: Area source discretization step, in kilometers. """ mesh = area_src.polygon.discretize(area_src_disc) num_points = len(mesh) area_mfd = area_src.mfd if isinstance(area_mfd, mfd.TruncatedGRMFD): new_a_val = math.log10(10 ** area_mfd.a_val / float(num_points)) new_mfd = mfd.TruncatedGRMFD( a_val=new_a_val, b_val=area_mfd.b_val, bin_width=area_mfd.bin_width, min_mag=area_mfd.min_mag, max_mag=area_mfd.max_mag) elif isinstance(area_mfd, mfd.EvenlyDiscretizedMFD): new_occur_rates = [float(x) / num_points for x in area_mfd.occurrence_rates] new_mfd = mfd.EvenlyDiscretizedMFD( min_mag=area_mfd.min_mag, bin_width=area_mfd.bin_width, occurrence_rates=new_occur_rates) for i, (lon, lat) in enumerate(zip(mesh.lons, mesh.lats)): pt = source.PointSource( # Generate a new ID and name source_id='%s-%s' % (area_src.source_id, i), name='%s-%s' % (area_src.name, i), tectonic_region_type=area_src.tectonic_region_type, mfd=new_mfd, rupture_mesh_spacing=area_src.rupture_mesh_spacing, magnitude_scaling_relationship= area_src.magnitude_scaling_relationship, rupture_aspect_ratio=area_src.rupture_aspect_ratio, upper_seismogenic_depth=area_src.upper_seismogenic_depth, lower_seismogenic_depth=area_src.lower_seismogenic_depth, location=geo.Point(lon, lat), nodal_plane_distribution=area_src.nodal_plane_distribution, hypocenter_distribution=area_src.hypocenter_distribution, temporal_occurrence_model=area_src.temporal_occurrence_model) pt.trt_model_id = area_src.trt_model_id yield pt
def _point_to_hazardlib(src, mesh_spacing, bin_width): """Convert a NRML point source to the HazardLib equivalent. See :mod:`openquake.nrmllib.models` and :mod:`openquake.hazardlib.source`. :param src: :class:`openquake.nrmllib.models.PointSource` instance. :param float mesh_spacing: Rupture mesh spacing, in km. :param float bin_width: Truncated Gutenberg-Richter MFD (Magnitude Frequency Distribution) bin width. :returns: The HazardLib representation of the input source. """ shapely_pt = wkt.loads(src.geometry.wkt) mf_dist = _mfd_to_hazardlib(src.mfd, bin_width) # nodal plane distribution: npd = pmf.PMF([(x.probability, geo.NodalPlane(strike=x.strike, dip=x.dip, rake=x.rake)) for x in src.nodal_plane_dist]) # hypocentral depth distribution: hd = pmf.PMF([(x.probability, x.depth) for x in src.hypo_depth_dist]) msr = scalerel.get_available_magnitude_scalerel()[src.mag_scale_rel]() point = source.PointSource( source_id=src.id, name=src.name, tectonic_region_type=src.trt, mfd=mf_dist, rupture_mesh_spacing=mesh_spacing, magnitude_scaling_relationship=msr, rupture_aspect_ratio=src.rupt_aspect_ratio, upper_seismogenic_depth=src.geometry.upper_seismo_depth, lower_seismogenic_depth=src.geometry.lower_seismo_depth, location=geo.Point(shapely_pt.x, shapely_pt.y), nodal_plane_distribution=npd, hypocenter_distribution=hd) return point
def convert_pointSource(self, node): """ Convert the given node into a point source object. :param node: a node with tag pointGeometry :returns: a :class:`openquake.hazardlib.source.PointSource` instance """ geom = node.pointGeometry lon_lat = ~geom.Point.pos msr = valid.SCALEREL[~node.magScaleRel]() return source.PointSource( source_id=node['id'], name=node['name'], tectonic_region_type=node.attrib.get('tectonicRegion'), mfd=self.convert_mfdist(node), rupture_mesh_spacing=self.rupture_mesh_spacing, magnitude_scaling_relationship=msr, rupture_aspect_ratio=~node.ruptAspectRatio, upper_seismogenic_depth=~geom.upperSeismoDepth, lower_seismogenic_depth=~geom.lowerSeismoDepth, location=geo.Point(*lon_lat), nodal_plane_distribution=self.convert_npdist(node), hypocenter_distribution=self.convert_hpdist(node), temporal_occurrence_model=self.tom)