def _area_to_nhlib(src, mesh_spacing, bin_width, area_src_disc): """Convert a NRML area source to the NHLib equivalent. See :mod:`nrml.models` and :mod:`nhlib.source`. :param src: :class:`nrml.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. :param float area_src_disc: Area source discretization, in km. Applies only to area sources. :returns: The NHLib representation of the input source. """ shapely_polygon = wkt.loads(src.geometry.wkt) nhlib_polygon = geo.Polygon( # We ignore the last coordinate in the sequence here, since it is a # duplicate of the first. nhlib will close the loop for us. [geo.Point(*x) for x in list(shapely_polygon.exterior.coords)[:-1]] ) mf_dist = _mfd_to_nhlib(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]) area = mtkAreaSource( source_id=src.id, name=src.name, tectonic_region_type=src.trt, mfd=mf_dist, rupture_mesh_spacing=mesh_spacing, magnitude_scaling_relationship=_SCALE_REL_MAP[src.mag_scale_rel](), rupture_aspect_ratio=src.rupt_aspect_ratio, upper_seismogenic_depth=src.geometry.upper_seismo_depth, lower_seismogenic_depth=src.geometry.lower_seismo_depth, nodal_plane_distribution=npd, hypocenter_distribution=hd, polygon=nhlib_polygon, area_discretization=area_src_disc ) return area
def _area_to_mtk(src): """Convert a NRML area source to the NHLib equivalent. See :mod:`nrml.models` and :mod:`nhlib.source`. :param src: :class:`nrml.models.AreaSource` instance. :returns: The NHLib representation of the input source. """ shapely_poly = wkt.loads(src.geometry.wkt) geometry_input = np.array(list(shapely_poly.exterior.coords)) area = mtkAreaSource( src.id, src.name, src.trt, src.rupt_aspect_ratio, geometry_input, upper_depth=src.geometry.upper_seismo_depth, lower_depth=src.geometry.lower_seismo_depth) return area
def load_area_source(self, source_data, config): '''''' ident, name, region, rupture_depth, hypo_depth = \ self.read_ancilliaries(source_data) return mtkAreaSource(ident, name, region, config['aspect_ratio'], source_data['polygon']), hypo_depth