Exemplo n.º 1
0
 def test_area_with_tgr_mfd(self):
     trunc_mfd = mfd.TruncatedGRMFD(a_val=2.1,
                                    b_val=4.2,
                                    bin_width=0.1,
                                    min_mag=6.55,
                                    max_mag=8.91)
     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)])
     polygon = geo.Polygon([
         geo.Point(-122.5, 37.5),
         geo.Point(-121.5, 37.5),
         geo.Point(-121.5, 38.5),
         geo.Point(-122.5, 38.5)
     ])
     area = source.AreaSource(
         source_id="1",
         name="source A",
         tectonic_region_type="Active Shallow Crust",
         mfd=trunc_mfd,
         rupture_mesh_spacing=self.rupture_mesh_spacing,
         magnitude_scaling_relationship=scalerel.PeerMSR(),
         rupture_aspect_ratio=1.0,
         upper_seismogenic_depth=0.0,
         lower_seismogenic_depth=10.0,
         nodal_plane_distribution=npd,
         hypocenter_distribution=hd,
         polygon=polygon,
         area_discretization=10,
         temporal_occurrence_model=PoissonTOM(50.))
     actual = list(source.area_to_point_sources(area))
     self.assertEqual(len(actual), 96)  # expected 96 points
     self.assertAlmostEqual(actual[0].mfd.a_val, 0.1177287669604317)
Exemplo n.º 2
0
    def convert_areaSource(self, node):
        """
        Convert the given node into an area source object.

        :param node: a node with tag areaGeometry
        :returns: a :class:`openquake.hazardlib.source.AreaSource` instance
        """
        geom = node.areaGeometry
        coords = split_coords_2d(~geom.Polygon.exterior.LinearRing.posList)
        polygon = geo.Polygon([geo.Point(*xy) for xy in coords])
        msr = valid.SCALEREL[~node.magScaleRel]()
        area_discretization = geom.attrib.get('discretization',
                                              self.area_source_discretization)
        if area_discretization is None:
            raise ValueError(
                'The source %r has no `discretization` parameter and the job.'
                'ini file has no `area_source_discretization` parameter either'
                % node['id'])
        return source.AreaSource(
            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,
            nodal_plane_distribution=self.convert_npdist(node),
            hypocenter_distribution=self.convert_hddist(node),
            polygon=polygon,
            area_discretization=area_discretization,
            temporal_occurrence_model=self.get_tom(node))
Exemplo n.º 3
0
    def _expected_area(self):
        incr_mfd = mfd.EvenlyDiscretizedMFD(
            min_mag=6.55, bin_width=0.1,
            occurrence_rates=[
                0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4,
                5.080653E-4])

        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)])

        polygon = geo.Polygon(
            [geo.Point(-122.5, 37.5), geo.Point(-121.5, 37.5),
             geo.Point(-121.5, 38.5), geo.Point(-122.5, 38.5)])

        area = source.AreaSource(
            source_id="1",
            name="Quito",
            tectonic_region_type="Active Shallow Crust",
            mfd=incr_mfd,
            rupture_mesh_spacing=self.rupture_mesh_spacing,
            magnitude_scaling_relationship=scalerel.PeerMSR(),
            rupture_aspect_ratio=1.5,
            upper_seismogenic_depth=0.0,
            lower_seismogenic_depth=10.0,
            nodal_plane_distribution=npd,
            hypocenter_distribution=hd,
            polygon=polygon,
            area_discretization=2,
            temporal_occurrence_model=PoissonTOM(50.))
        area.num_ruptures = area.count_ruptures()
        return area
Exemplo n.º 4
0
 def test_area_with_incr_mfd(self):
     incr_mfd = mfd.EvenlyDiscretizedMFD(
         min_mag=6.55, bin_width=0.1,
         occurrence_rates=[
             0.0010614989, 8.8291627E-4, 7.3437777E-4, 6.108288E-4,
             5.080653E-4])
     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)])
     polygon = geo.Polygon(
         [geo.Point(-122.5, 37.5), geo.Point(-121.5, 37.5),
          geo.Point(-121.5, 38.5), geo.Point(-122.5, 38.5)])
     area = source.AreaSource(
         source_id="1",
         name="source A",
         tectonic_region_type="Active Shallow Crust",
         mfd=incr_mfd,
         rupture_mesh_spacing=self.rupture_mesh_spacing,
         magnitude_scaling_relationship=scalerel.PeerMSR(),
         rupture_aspect_ratio=1.0,
         upper_seismogenic_depth=0.0,
         lower_seismogenic_depth=10.0,
         nodal_plane_distribution=npd,
         hypocenter_distribution=hd,
         polygon=polygon,
         area_discretization=10,
         temporal_occurrence_model=PoissonTOM(50.0),
     )
     actual = list(area)
     self.assertEqual(len(actual), 96)  # expected 96 points
     assert_allclose(
         actual[0].mfd.occurrence_rates,
         [1.10572802083e-05, 9.197044479166666e-06, 7.6497684375e-06,
          6.3627999999999995e-06, 5.292346875e-06])
Exemplo n.º 5
0
def _area_to_hazardlib(src, mesh_spacing, bin_width, area_src_disc):
    """Convert a NRML area 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.
    :param float area_src_disc:
        Area source discretization, in km. Applies only to area sources.
    :returns:
        The HazardLib representation of the input source.
    """
    shapely_polygon = wkt.loads(src.geometry.wkt)
    hazardlib_polygon = geo.Polygon(
        # We ignore the last coordinate in the sequence here, since it is a
        # duplicate of the first. hazardlib will close the loop for us.
        [geo.Point(*x) for x in list(shapely_polygon.exterior.coords)[:-1]])

    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]()
    area = source.AreaSource(
        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,
        nodal_plane_distribution=npd,
        hypocenter_distribution=hd,
        polygon=hazardlib_polygon,
        area_discretization=area_src_disc)

    return area