Ejemplo n.º 1
0
    def setUp(self):
        super(PointSourceSourceFilterTestCase, self).setUp()
        self.sitecol = SiteCollection(self.SITES)

        self.source1 = make_point_source(
            mfd=EvenlyDiscretizedMFD(min_mag=5,
                                     bin_width=1,
                                     occurrence_rates=[1]),
            rupture_aspect_ratio=1.9,
            upper_seismogenic_depth=0,
            lower_seismogenic_depth=18.5,
            magnitude_scaling_relationship=PeerMSR(),
            nodal_plane_distribution=PMF([
                (0.5, NodalPlane(strike=1, dip=2, rake=3)),
                (0.5, NodalPlane(strike=1, dip=20, rake=3)),
            ]),
            location=Point(2.0, 0.0),
        )
        self.source2 = make_point_source(
            mfd=EvenlyDiscretizedMFD(min_mag=6.5,
                                     bin_width=1,
                                     occurrence_rates=[1]),
            rupture_aspect_ratio=0.5,
            upper_seismogenic_depth=0,
            lower_seismogenic_depth=18.5,
            magnitude_scaling_relationship=PeerMSR(),
            nodal_plane_distribution=PMF([
                (0.5, NodalPlane(strike=1, dip=10, rake=3)),
                (0.5, NodalPlane(strike=1, dip=20, rake=3)),
            ]),
            location=Point(2.0, 0.0),
        )
Ejemplo n.º 2
0
 def _get_rupture(self, min_mag, max_mag, hypocenter_depth,
                  aspect_ratio, dip, rupture_mesh_spacing,
                  upper_seismogenic_depth=2,
                  lower_seismogenic_depth=16):
     source_id = name = 'test-source'
     trt = TRT.ACTIVE_SHALLOW_CRUST
     mfd = TruncatedGRMFD(a_val=2, b_val=1, min_mag=min_mag,
                          max_mag=max_mag, bin_width=1)
     location = Point(0, 0)
     nodal_plane = NodalPlane(strike=45, dip=dip, rake=-123.23)
     nodal_plane_distribution = PMF([(1, nodal_plane)])
     hypocenter_distribution = PMF([(1, hypocenter_depth)])
     magnitude_scaling_relationship = PeerMSR()
     rupture_aspect_ratio = aspect_ratio
     tom = PoissonTOM(time_span=50)
     point_source = PointSource(
         source_id, name, trt, mfd, rupture_mesh_spacing,
         magnitude_scaling_relationship, rupture_aspect_ratio, tom,
         upper_seismogenic_depth, lower_seismogenic_depth,
         location, nodal_plane_distribution, hypocenter_distribution
     )
     ruptures = list(point_source.iter_ruptures())
     self.assertEqual(len(ruptures), 1)
     [rupture] = ruptures
     self.assertIs(rupture.temporal_occurrence_model, tom)
     self.assertIs(rupture.tectonic_region_type, trt)
     self.assertEqual(rupture.rake, nodal_plane.rake)
     self.assertIsInstance(rupture.surface, PlanarSurface)
     return rupture
Ejemplo n.º 3
0
def reference_psha_calculation_openquake():
    """
    Sets up the reference PSHA calculation calling OpenQuake directly. All
    subsequent implementations should match this example
    """
    # Site model - 3 Sites
    site_model = SiteCollection([
        Site(Point(30.0, 30.0), 760., True, 1.0, 1.0, 1),
        Site(Point(30.25, 30.25), 760., True, 1.0, 1.0, 2),
        Site(Point(30.4, 30.4), 760., True, 1.0, 1.0, 2)
    ])
    # Source Model Two Point Sources
    mfd_1 = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0)
    mfd_2 = TruncatedGRMFD(4.5, 7.5, 0.1, 3.5, 1.1)
    source_model = [
        PointSource('001', 'Point1', 'Active Shallow Crust', mfd_1, 1.0,
                    WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                    Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                    PMF([(1.0, 10.0)])),
        PointSource('002', 'Point2', 'Active Shallow Crust', mfd_2, 1.0,
                    WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                    Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                    PMF([(1.0, 10.0)]))
    ]
    imts = {
        'PGA': [0.01, 0.1, 0.2, 0.5, 0.8],
        'SA(0.5)': [0.01, 0.1, 0.2, 0.5, 0.8]
    }
    # Akkar & Bommer (2010) GMPE
    gsims = {'Active Shallow Crust': gsim.akkar_bommer_2010.AkkarBommer2010()}
    truncation_level = None
    return calc_hazard_curves(source_model, site_model, imts, gsims,
                              truncation_level)
Ejemplo n.º 4
0
    def setUp(self):

        mfd = TruncatedGRMFD(min_mag=4.0, max_mag=6.0, bin_width=0.1,
                             a_val=2.0, b_val=1.0)
        msr = WC1994()
        tom = PoissonTOM(1.0)
        pol = Polygon([Point(longitude=0.0, latitude=0.0),
                       Point(longitude=1.0, latitude=0.0),
                       Point(longitude=1.0, latitude=1.0),
                       Point(longitude=0.0, latitude=1.0)])
        npd = PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))])
        hpd = PMF([(0.7, 10.), (0.3, 20.0)])

        self.src1 = AreaSource(source_id='1',
                               name='1',
                               tectonic_region_type='Test',
                               mfd=mfd,
                               rupture_mesh_spacing=1,
                               magnitude_scaling_relationship=msr,
                               rupture_aspect_ratio=1.,
                               temporal_occurrence_model=tom,
                               upper_seismogenic_depth=0,
                               lower_seismogenic_depth=100.,
                               nodal_plane_distribution=npd,
                               hypocenter_distribution=hpd,
                               polygon=pol,
                               area_discretization=10.)
Ejemplo n.º 5
0
 def test_mutually_exclusive_ruptures(self):
     # Test the calculation of hazard curves using mutually exclusive
     # ruptures for a single source
     gsim_by_trt = [SadighEtAl1997()]
     rupture = _create_rupture(10., 6.)
     data = [(rupture, PMF([(0.7, 0), (0.3, 1)])),
             (rupture, PMF([(0.6, 0), (0.4, 1)]))]
     data[0][0].weight = 0.5
     data[1][0].weight = 0.5
     src = NonParametricSeismicSource('0', 'test', "Active Shallow Crust",
                                      data)
     src.id = 0
     src.grp_id = 0
     src.trt_smr = 0
     src.mutex_weight = 1
     group = SourceGroup(src.tectonic_region_type, [src], 'test', 'mutex',
                         'mutex')
     param = dict(imtls=self.imtls,
                  src_interdep=group.src_interdep,
                  rup_interdep=group.rup_interdep,
                  grp_probability=group.grp_probability)
     cmaker = ContextMaker(src.tectonic_region_type, gsim_by_trt, param)
     crv = classical(group, self.sites, cmaker)['pmap'][0]
     npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]),
                             crv.array[:, 0],
                             decimal=4)
Ejemplo n.º 6
0
 def test_mutually_exclusive_ruptures(self):
     # Test the calculation of hazard curves using mutually exclusive
     # ruptures for a single source
     gsim_by_trt = [SadighEtAl1997()]
     rupture = _create_rupture(10., 6.)
     data = [(rupture, PMF([(0.7, 0), (0.3, 1)])),
             (rupture, PMF([(0.6, 0), (0.4, 1)]))]
     print(data[0][0])
     data[0][0].weight = 0.5
     data[1][0].weight = 0.5
     print(data[0][0].weight)
     src = NonParametricSeismicSource('0', 'test', TRT.ACTIVE_SHALLOW_CRUST,
                                      data)
     src.src_group_id = 0
     src.mutex_weight = 1
     group = SourceGroup(src.tectonic_region_type, [src], 'test', 'mutex',
                         'mutex')
     param = dict(imtls=self.imtls,
                  filter_distance='rjb',
                  src_interdep=group.src_interdep,
                  rup_interdep=group.rup_interdep,
                  grp_probability=group.grp_probability)
     crv = classical(group, self.sites, gsim_by_trt, param)['pmap'][0]
     npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]),
                             crv[0].array[:, 0],
                             decimal=4)
Ejemplo n.º 7
0
def make_area_source(polygon, discretization, **kwargs):
    default_arguments = {
        'source_id': 'source_id',
        'name': 'area source name',
        'tectonic_region_type': TRT.VOLCANIC,
        'mfd': TruncatedGRMFD(a_val=3,
                              b_val=1,
                              min_mag=5,
                              max_mag=7,
                              bin_width=1),
        'nodal_plane_distribution': PMF([(1, NodalPlane(1, 2, 3))]),
        'hypocenter_distribution': PMF([(0.5, 4.0), (0.5, 8.0)]),
        'upper_seismogenic_depth': 1.3,
        'lower_seismogenic_depth': 10.0,
        'magnitude_scaling_relationship': PeerMSR(),
        'rupture_aspect_ratio': 1.333,
        'polygon': polygon,
        'area_discretization': discretization,
        'rupture_mesh_spacing': 12.33,
        'temporal_occurrence_model': PoissonTOM(50.)
    }
    default_arguments.update(kwargs)
    kwargs = default_arguments
    source = AreaSource(**kwargs)
    return source
Ejemplo n.º 8
0
def example_calc(apply):
    sitecol = SiteCollection([
        Site(Point(30.0, 30.0), 760., 1.0, 1.0),
        Site(Point(30.25, 30.25), 760., 1.0, 1.0),
        Site(Point(30.4, 30.4), 760., 1.0, 1.0)
    ])
    mfd_1 = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0)
    mfd_2 = TruncatedGRMFD(4.5, 7.5, 0.1, 3.5, 1.1)
    sources = [
        PointSource('001', 'Point1', 'Active Shallow Crust', mfd_1, 1.0,
                    WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                    Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                    PMF([(1.0, 10.0)])),
        PointSource('002', 'Point2', 'Active Shallow Crust', mfd_2, 1.0,
                    WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                    Point(30.0, 30.5), PMF([(1.0, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                    PMF([(1.0, 10.0)]))
    ]
    imtls = {
        'PGA': [0.01, 0.1, 0.2, 0.5, 0.8],
        'SA(0.5)': [0.01, 0.1, 0.2, 0.5, 0.8]
    }
    gsims = {'Active Shallow Crust': AkkarBommer2010()}
    return calc_hazard_curves(sources,
                              sitecol,
                              imtls,
                              gsims,
                              apply=apply,
                              filter_distance='rrup')
Ejemplo n.º 9
0
 def setUp(self):
     """
     """
     mfd_1 = TruncatedGRMFD(4.5, 8.0, 0.1, 4.0, 1.0)
     mfd_2 = TruncatedGRMFD(4.5, 7.5, 0.1, 3.5, 1.1)
     self.source_model = [
         PointSource('001', 'Point1', 'Active Shallow Crust', mfd_1, 1.0,
                     WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                     Point(30.0, 30.5),
                     PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]),
                     PMF([(1.0, 10.0)])),
         PointSource('002', 'Point2', 'Active Shallow Crust', mfd_2, 1.0,
                     WC1994(), 1.0, PoissonTOM(50.0), 0.0, 30.0,
                     Point(30.0, 30.5),
                     PMF([(1.0, NodalPlane(0.0, 90.0, 0.0))]),
                     PMF([(1.0, 10.0)]))
     ]
     self.sites = SiteCollection([
         Site(Point(30.0, 30.0), 760., True, 1.0, 1.0, 1),
         Site(Point(30.25, 30.25), 760., True, 1.0, 1.0, 2),
         Site(Point(30.4, 30.4), 760., True, 1.0, 1.0, 2)
     ])
     self.gsims = {'Active Shallow Crust': 'AkkarBommer2010'}
     self.imts = ['PGA', 'SA(0.5)']
     self.imls = [[0.01, 0.1, 0.2, 0.5, 0.8]]
Ejemplo n.º 10
0
def make_non_parametric_source():
    surf1 = PlanarSurface(
        mesh_spacing=2., strike=0, dip=90,
        top_left=Point(0., -1., 0.), top_right=Point(0., 1., 0.),
        bottom_right=Point(0., 1., 10.), bottom_left=Point(0., -1., 10.)
    )
    surf2 = PlanarSurface(
        mesh_spacing=2., strike=90., dip=90.,
        top_left=Point(-1., 0., 0.), top_right=Point(1., 0., 0.),
        bottom_right=Point(1., 0., 10.), bottom_left=Point(-1., 0., 10.)
    )
    rup1 = Rupture(
        mag=5., rake=90., tectonic_region_type='ASC',
        hypocenter=Point(0., 0., 5.), surface=surf1, source_typology=None
    )
    rup2 = Rupture(
        mag=6, rake=0, tectonic_region_type='ASC',
        hypocenter=Point(0., 0., 5.), surface=surf2, source_typology=None
    )
    pmf1 = PMF([(Decimal('0.7'), 0), (Decimal('0.3'), 1)])
    pmf2 = PMF([(Decimal('0.7'), 0), (Decimal('0.2'), 1), (Decimal('0.1'), 2)])
    kwargs = {
        'source_id': 'source_id', 'name': 'source name',
        'tectonic_region_type': 'tectonic region',
        'data': [(rup1, pmf1), (rup2, pmf2)]
    }
    npss = NonParametricSeismicSource(**kwargs)
    assert_pickleable(npss)
    return npss, kwargs
Ejemplo n.º 11
0
def make_point_source(lon=1.2, lat=3.4, **kwargs):
    default_arguments = {
        'source_id': 'source_id',
        'name': 'source name',
        'tectonic_region_type': TRT.SUBDUCTION_INTRASLAB,
        'mfd': TruncatedGRMFD(a_val=1,
                              b_val=2,
                              min_mag=3,
                              max_mag=5,
                              bin_width=1),
        'location': Point(lon, lat, 5.6),
        'nodal_plane_distribution': PMF([(1, NodalPlane(1, 2, 3))]),
        'hypocenter_distribution': PMF([(1, 4)]),
        'upper_seismogenic_depth': 1.3,
        'lower_seismogenic_depth': 4.9,
        'magnitude_scaling_relationship': PeerMSR(),
        'rupture_aspect_ratio': 1.333,
        'rupture_mesh_spacing': 1.234,
        'temporal_occurrence_model': PoissonTOM(50.)
    }
    default_arguments.update(kwargs)
    kwargs = default_arguments
    ps = PointSource(**kwargs)
    assert_pickleable(ps)
    return ps
Ejemplo n.º 12
0
 def test_sample_pmf_numerical(self):
     """
     Tests the sampling function for numerical data - using a random
     seed approach
     """
     pmf = PMF([(0.3, 1), (0.5, 2), (0.2, 4)])
     np.random.seed(22)
     self.assertListEqual(pmf.sample(10), [1, 2, 2, 4, 1, 2, 1, 2, 1, 4])
Ejemplo n.º 13
0
    def test_case_11(self):
        hypocenter_probability = (Decimal(1) /
                                  len(test_data.SET1_CASE11_HYPOCENTERS))
        hypocenter_pmf = PMF([
            (hypocenter_probability, hypocenter)
            for hypocenter in test_data.SET1_CASE11_HYPOCENTERS
        ])
        # apart from hypocenter pmf repeats case 10
        sources = [
            AreaSource(
                source_id='area',
                name='area',
                tectonic_region_type=const.TRT.ACTIVE_SHALLOW_CRUST,
                mfd=test_data.SET1_CASE11_MFD,
                nodal_plane_distribution=PMF([(1, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                hypocenter_distribution=hypocenter_pmf,
                upper_seismogenic_depth=0.0,
                lower_seismogenic_depth=10.0,
                magnitude_scaling_relationship=PointMSR(),
                rupture_aspect_ratio=test_data.SET1_RUPTURE_ASPECT_RATIO,
                temporal_occurrence_model=PoissonTOM(1.),
                polygon=test_data.SET1_CASE11_SOURCE_POLYGON,
                area_discretization=10.0,
                rupture_mesh_spacing=10.0)
        ]
        sites = SiteCollection([
            test_data.SET1_CASE11_SITE1, test_data.SET1_CASE11_SITE2,
            test_data.SET1_CASE11_SITE3, test_data.SET1_CASE11_SITE4
        ])
        gsims = {const.TRT.ACTIVE_SHALLOW_CRUST: SadighEtAl1997()}
        truncation_level = 0
        imts = {str(test_data.IMT): test_data.SET1_CASE11_IMLS}

        curves = calc_hazard_curves(sources, sites, imts, gsims,
                                    truncation_level)
        s1hc, s2hc, s3hc, s4hc = curves[str(test_data.IMT)]

        assert_hazard_curve_is(self,
                               s1hc,
                               test_data.SET1_CASE11_SITE1_POES,
                               atol=1e-4,
                               rtol=1e-1)
        assert_hazard_curve_is(self,
                               s2hc,
                               test_data.SET1_CASE11_SITE2_POES,
                               atol=1e-4,
                               rtol=1e-1)
        assert_hazard_curve_is(self,
                               s3hc,
                               test_data.SET1_CASE11_SITE3_POES,
                               atol=1e-4,
                               rtol=1e-1)
        assert_hazard_curve_is(self,
                               s4hc,
                               test_data.SET1_CASE11_SITE4_POES,
                               atol=1e-4,
                               rtol=1e-1)
Ejemplo n.º 14
0
 def test_sample_pmf_numerical(self):
     """
     Tests the sampling function for numerical data - using a random
     seed approach
     """
     pmf = PMF([(0.3, 1), (0.5, 2), (0.2, 4)])
     np.random.seed(22)
     self.assertListEqual(pmf.sample(10),
                          [1, 2, 2, 4, 1, 2, 1, 2, 1, 4])
    def setUp(self):
        """
        """
        #~ self.npd_as_list = [models.NodalPlane(0.5, 0., 90., 0.),
                            #~ models.NodalPlane(0.5, 90., 90., 180.)]
        self.npd_as_pmf = PMF([(0.5, NodalPlane(0., 90., 0.)),
                               (0.5, NodalPlane(90., 90., 180.))])

        self.npd_as_pmf_bad = PMF([(0.5, None),
                                    (0.5, NodalPlane(90., 90., 180.))])
Ejemplo n.º 16
0
    def test(self):
        npd = PMF([(0.5, NodalPlane(1, 20, 3)),
                   (0.5, NodalPlane(2, 2, 4))])
        hd = PMF([(1, 14)])
        mesh = Mesh(numpy.array([0, 1]), numpy.array([0.5, 1]))
        mmfd = MultiMFD('incrementalMFD',
                        size=2,
                        min_mag=[4.5],
                        bin_width=[2.0],
                        occurRates=[[.3, .1], [.4, .2, .1]])
        mps = MultiPointSource('mp1', 'multi point source',
                               'Active Shallow Crust',
                               mmfd, PeerMSR(), 1.0,
                               10, 20, npd, hd, mesh)
        # test the splitting
        splits = list(mps)
        self.assertEqual(len(splits), 2)
        for split in splits:
            self.assertEqual(split.grp_id, mps.grp_id)

        got = obj_to_node(mps).to_str()
        print(got)
        exp = '''\
multiPointSource{id='mp1', name='multi point source'}
  multiPointGeometry
    gml:posList [0.0, 0.5, 1.0, 1.0]
    upperSeismoDepth 10
    lowerSeismoDepth 20
  magScaleRel 'PeerMSR'
  ruptAspectRatio 1.0
  multiMFD{kind='incrementalMFD', size=2}
    bin_width [2.0]
    min_mag [4.5]
    occurRates [0.3, 0.1, 0.4, 0.2, 0.1]
    lengths [2, 3]
  nodalPlaneDist
    nodalPlane{dip=20, probability=0.5, rake=3, strike=1}
    nodalPlane{dip=2, probability=0.5, rake=4, strike=2}
  hypoDepthDist
    hypoDepth{depth=14, probability=1.0}
'''
        self.assertEqual(got, exp)

        # test serialization to and from hdf5
        tmp = general.gettemp(suffix='.hdf5')
        with hdf5.File(tmp, 'w') as f:
            f[mps.source_id] = mps
        with hdf5.File(tmp, 'r') as f:
            f[mps.source_id]

        # test the bounding box
        bbox = mps.get_bounding_box(maxdist=100)
        numpy.testing.assert_almost_equal(
            (-0.8994569916564479, -0.39932, 1.8994569916564479, 1.89932),
            bbox)
Ejemplo n.º 17
0
 def test_sample_pmf_convergence(self):
     """
     Tests the PMF sampling function for numerical convergence
     """
     pmf = PMF([(0.3, 1.), (0.5, 2.), (0.2, 4.)])
     # Take 100000 samples of the PMF and find the density of the results
     output = np.histogram(pmf.sample(100000),
                           np.array([0.5, 1.5, 2.5, 3.5, 4.5]),
                           density=True)[0]
     np.testing.assert_array_almost_equal(output,
                                          np.array([0.3, 0.5, 0.0, 0.2]),
                                          2)  # Tests to 2 decimal places
Ejemplo n.º 18
0
 def test_sample_pmf_convergence(self):
     """
     Tests the PMF sampling function for numerical convergence
     """
     pmf = PMF([(0.3, 1.), (0.5, 2.), (0.2, 4.)])
     # Take 100000 samples of the PMF and find the density of the results
     output = np.histogram(pmf.sample(100000),
                           np.array([0.5, 1.5, 2.5, 3.5, 4.5]),
                           density=True)[0]
     np.testing.assert_array_almost_equal(output,
                                          np.array([0.3, 0.5, 0.0, 0.2]),
                                          2)  # Tests to 2 decimal places
Ejemplo n.º 19
0
 def test_sample_pmf_non_numerical(self):
     """
     Tests the sampling function for non-numerical data - using a random
     seed approach
     """
     pmf = PMF([(0.3, "apples"),
                (0.1, "oranges"),
                (0.4, "bananas"),
                (0.2, "lemons")])
     np.random.seed(22)
     expected = ['apples', 'bananas', 'bananas', 'lemons', 'apples',
                 'oranges', 'apples', 'bananas', 'apples', 'lemons']
     self.assertListEqual(pmf.sample(10), expected)
Ejemplo n.º 20
0
 def test_sample_pmf_non_numerical(self):
     """
     Tests the sampling function for non-numerical data - using a random
     seed approach
     """
     pmf = PMF([(0.3, "apples"),
                (0.1, "oranges"),
                (0.4, "bananas"),
                (0.2, "lemons")])
     np.random.seed(22)
     expected = ['apples', 'bananas', 'bananas', 'lemons', 'apples',
                 'oranges', 'apples', 'bananas', 'apples', 'lemons']
     self.assertListEqual(pmf.sample(10), expected)
Ejemplo n.º 21
0
 def setUp(self):
     self.src1 = _create_non_param_sourceA(15., 6.3,
                                           PMF([(0.6, 0), (0.4, 1)]))
     self.src2 = _create_non_param_sourceA(10., 6.0,
                                           PMF([(0.7, 0), (0.3, 1)]))
     self.src3 = _create_non_param_sourceA(10., 6.0,
                                           PMF([(0.7, 0), (0.3, 1)]),
                                           "Geothermal")
     site = Site(Point(0.0, 0.0), 800, z1pt0=100., z2pt5=1.)
     self.sites = SiteCollection([site])
     self.imtls = DictArray({'PGA': [0.01, 0.1, 0.3]})
     gsim = SadighEtAl1997()
     self.gsim_by_trt = {"Active Shallow Crust": gsim}
Ejemplo n.º 22
0
 def setUp(self):
     self.src1 = _create_non_param_sourceA(15., 6.3,
                                           PMF([(0.6, 0), (0.4, 1)]))
     self.src2 = _create_non_param_sourceA(10., 6.0,
                                           PMF([(0.7, 0), (0.3, 1)]))
     self.src3 = _create_non_param_sourceA(10., 6.0,
                                           PMF([(0.7, 0), (0.3, 1)]),
                                           TRT.GEOTHERMAL)
     site = Site(Point(0.0, 0.0), 800, True, z1pt0=100., z2pt5=1.)
     s_filter = SourceFilter(SiteCollection([site]), {})
     self.sites = s_filter
     self.imtls = DictArray({'PGA': [0.01, 0.1, 0.3]})
     self.gsim_by_trt = {TRT.ACTIVE_SHALLOW_CRUST: SadighEtAl1997()}
Ejemplo n.º 23
0
    def setUp(self):
        # time span of 10 million years
        self.time_span = 10e6

        nodalplane = NodalPlane(strike=0.0, dip=90.0, rake=0.0)
        self.mfd = TruncatedGRMFD(a_val=3.5,
                                  b_val=1.0,
                                  min_mag=5.0,
                                  max_mag=6.5,
                                  bin_width=0.1)

        # area source of circular shape with radius of 100 km
        # centered at 0., 0.
        self.area1 = AreaSource(
            source_id='src_1',
            name='area source',
            tectonic_region_type='Active Shallow Crust',
            mfd=self.mfd,
            nodal_plane_distribution=PMF([(1.0, nodalplane)]),
            hypocenter_distribution=PMF([(1.0, 5.0)]),
            upper_seismogenic_depth=0.0,
            lower_seismogenic_depth=10.0,
            magnitude_scaling_relationship=WC1994(),
            rupture_aspect_ratio=1.0,
            polygon=Point(0., 0.).to_polygon(100.),
            area_discretization=9.0,
            rupture_mesh_spacing=1.0,
            temporal_occurrence_model=PoissonTOM(self.time_span))

        # area source of circular shape with radius of 100 km
        # centered at 1., 1.
        self.area2 = AreaSource(
            source_id='src_1',
            name='area source',
            tectonic_region_type='Active Shallow Crust',
            mfd=self.mfd,
            nodal_plane_distribution=PMF([(1.0, nodalplane)]),
            hypocenter_distribution=PMF([(1.0, 5.0)]),
            upper_seismogenic_depth=0.0,
            lower_seismogenic_depth=10.0,
            magnitude_scaling_relationship=WC1994(),
            rupture_aspect_ratio=1.0,
            polygon=Point(5., 5.).to_polygon(100.),
            area_discretization=9.0,
            rupture_mesh_spacing=1.0,
            temporal_occurrence_model=PoissonTOM(self.time_span))

        # non-parametric source
        self.np_src, _ = make_non_parametric_source()
Ejemplo n.º 24
0
 def test_mutually_exclusive_ruptures(self):
     # Test the calculation of hazard curves using mutually exclusive
     # ruptures for a single source
     gsim_by_trt = [SadighEtAl1997()]
     rupture = _create_rupture(10., 6.)
     data = [(rupture, PMF([(0.7, 0), (0.3, 1)])),
             (rupture, PMF([(0.6, 0), (0.4, 1)]))]
     src = NonParametricSeismicSource('0', 'test', TRT.ACTIVE_SHALLOW_CRUST,
                                      data)
     group = SourceGroup(
         src.tectonic_region_type, [src], 'test', 'indep', 'mutex')
     param = dict(imtls=self.imtls)
     crv = pmap_from_grp(group, self.sites, gsim_by_trt, param)[0]
     npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]),
                             crv.array[:, 0], decimal=4)
Ejemplo n.º 25
0
    def test_case_10(self):
        hypocenter_pmf = PMF([(1, test_data.SET1_CASE10_HYPOCENTER_DEPTH)])
        sources = [
            AreaSource(
                source_id='area',
                name='area',
                tectonic_region_type=const.TRT.ACTIVE_SHALLOW_CRUST,
                mfd=test_data.SET1_CASE10_MFD,
                nodal_plane_distribution=PMF([(1, NodalPlane(0.0, 90.0,
                                                             0.0))]),
                hypocenter_distribution=hypocenter_pmf,
                upper_seismogenic_depth=0.0,
                lower_seismogenic_depth=10.0,
                magnitude_scaling_relationship=PeerMSR(),
                rupture_aspect_ratio=test_data.SET1_RUPTURE_ASPECT_RATIO,
                polygon=test_data.SET1_CASE10_SOURCE_POLYGON,
                area_discretization=30.0,
                rupture_mesh_spacing=10.0)
        ]
        sites = SiteCollection([
            test_data.SET1_CASE10_SITE1, test_data.SET1_CASE10_SITE2,
            test_data.SET1_CASE10_SITE3, test_data.SET1_CASE10_SITE4
        ])
        gsims = {const.TRT.ACTIVE_SHALLOW_CRUST: SadighEtAl1997()}
        truncation_level = 0
        time_span = 1.0
        imts = {test_data.IMT: test_data.SET1_CASE10_IMLS}

        curves = hazard_curves(sources, sites, imts, time_span, gsims,
                               truncation_level)
        s1hc, s2hc, s3hc, s4hc = curves[test_data.IMT]

        assert_hazard_curve_is(self,
                               s1hc,
                               test_data.SET1_CASE10_SITE1_POES,
                               tolerance=2e-3)
        assert_hazard_curve_is(self,
                               s2hc,
                               test_data.SET1_CASE10_SITE2_POES,
                               tolerance=2e-3)
        assert_hazard_curve_is(self,
                               s3hc,
                               test_data.SET1_CASE10_SITE3_POES,
                               tolerance=2e-3)
        assert_hazard_curve_is(self,
                               s4hc,
                               test_data.SET1_CASE10_SITE4_POES,
                               tolerance=2e-3)
Ejemplo n.º 26
0
 def test_numbers_of_ruptures_not_defined_with_unit_step(self):
     pmf = PMF([(0.8, 0), (0.2, 2)])
     self.assert_failed_creation(
         NonParametricProbabilisticRupture,
         ValueError,
         'numbers of ruptures must be defined with unit step', pmf=pmf
     )
Ejemplo n.º 27
0
 def test_get_probability_no_exceedance(self):
     pmf = PMF([(0.7, 0), (0.2, 1), (0.1, 2)])
     poes = numpy.array([[0.9, 0.8, 0.7], [0.6, 0.5, 0.4]])
     rup = make_rupture(NonParametricProbabilisticRupture, pmf=pmf)
     pne = rup.get_probability_no_exceedance(poes)
     numpy.testing.assert_allclose(
         pne, numpy.array([[0.721, 0.744, 0.769], [0.796, 0.825, 0.856]]))
Ejemplo n.º 28
0
 def test_numbers_of_ruptures_not_in_increasing_order(self):
     pmf = PMF([(0.8, 0), (0.1, 2), (0.1, 1)])
     self.assert_failed_creation(
         NonParametricProbabilisticRupture,
         ValueError,
         'numbers of ruptures must be defined in increasing order', pmf=pmf
     )
Ejemplo n.º 29
0
 def test_dilated(self):
     mfd = TruncatedGRMFD(a_val=1, b_val=2, min_mag=3,
                          max_mag=5, bin_width=1)
     np_dist = PMF([(1, NodalPlane(0, 2, 4))])
     source = make_point_source(nodal_plane_distribution=np_dist, mfd=mfd)
     polygon = source.get_rupture_enclosing_polygon(dilation=20)
     self.assertIsInstance(polygon, Polygon)
     elons = [
         1.3917408, 1.3908138, 1.3880493, 1.3834740, 1.3771320, 1.3690846,
         1.3594093, 1.3481992, 1.3355624, 1.3216207, 1.3065082, 1.2903704,
         1.2733628, 1.2556490, 1.2373996, 1.2187902, 1.2000000, 1.1812098,
         1.1626004, 1.1443510, 1.1266372, 1.1096296, 1.0934918, 1.0783793,
         1.0644376, 1.0518008, 1.0405907, 1.0309154, 1.0228680, 1.0165260,
         1.0119507, 1.0091862, 1.0082592, 1.0091788, 1.0119361, 1.0165049,
         1.0228411, 1.0308838, 1.0405556, 1.0517635, 1.0643995, 1.0783420,
         1.0934567, 1.1095979, 1.1266103, 1.1443298, 1.1625858, 1.1812023,
         1.2000000, 1.2187977, 1.2374142, 1.2556702, 1.2733897, 1.2904021,
         1.3065433, 1.3216580, 1.3356005, 1.3482365, 1.3594444, 1.3691162,
         1.3771589, 1.3834951, 1.3880639, 1.3908212, 1.3917408
     ]
     elats = [
         3.3999810, 3.3812204, 3.3626409, 3.3444213, 3.3267370, 3.3097585,
         3.2936490, 3.2785638, 3.2646481, 3.2520357, 3.2408482, 3.2311932,
         3.2231637, 3.2168369, 3.2122738, 3.2095182, 3.2085967, 3.2095182,
         3.2122738, 3.2168369, 3.2231637, 3.2311932, 3.2408482, 3.2520357,
         3.2646481, 3.2785638, 3.2936490, 3.3097585, 3.3267370, 3.3444213,
         3.3626409, 3.3812204, 3.3999810, 3.4187420, 3.4373226, 3.4555440,
         3.4732305, 3.4902120, 3.5063247, 3.5214135, 3.5353329, 3.5479490,
         3.5591401, 3.5687983, 3.5768308, 3.5831599, 3.5877248, 3.5904815,
         3.5914033, 3.5904815, 3.5877248, 3.5831599, 3.5768308, 3.5687983,
         3.5591401, 3.5479490, 3.5353329, 3.5214135, 3.5063247, 3.4902120,
         3.4732305, 3.4555440, 3.4373226, 3.4187420, 3.3999810
     ]
     numpy.testing.assert_allclose(polygon.lons, elons)
     numpy.testing.assert_allclose(polygon.lats, elats)
Ejemplo n.º 30
0
    def test(self):
        mfd = TruncatedGRMFD(a_val=1, b_val=2, min_mag=3,
                             max_mag=5, bin_width=1)
        np_dist = PMF([(0.5, NodalPlane(1, 20, 3)),
                       (0.5, NodalPlane(2, 2, 4))])
        source = make_point_source(nodal_plane_distribution=np_dist, mfd=mfd)
        radius = source._get_max_rupture_projection_radius()
        self.assertAlmostEqual(radius, 1.2830362)

        mfd = TruncatedGRMFD(a_val=1, b_val=2, min_mag=5,
                             max_mag=6, bin_width=1)
        np_dist = PMF([(0.5, NodalPlane(1, 40, 3)),
                       (0.5, NodalPlane(2, 30, 4))])
        source = make_point_source(nodal_plane_distribution=np_dist, mfd=mfd)
        radius = source._get_max_rupture_projection_radius()
        self.assertAlmostEqual(radius, 3.8712214)
Ejemplo n.º 31
0
    def test_simple_fault_surface_vertical(self):

        # Create the rupture
        mag = 10.0
        rake = 90.0
        trt = TRT.ACTIVE_SHALLOW_CRUST
        hypoc = Point(0.25, 0.0, 5)
        pmf = PMF([(0.8, 0), (0.2, 1)])
        rup = NPPR(mag, rake, trt, hypoc, self.srfc1, pmf)

        # Compute distances
        param = 'closest_point'
        sites = SiteCollection(
            [Site(Point(0.25, -0.1, 0.0)),
             Site(Point(-0.1, 0.0, 0.0))])
        dsts = get_distances(rup, sites, param)

        # Check first point
        msg = 'The longitude of the first point is wrong'
        self.assertTrue(abs(dsts[0, 0] - 0.25) < 1e-2, msg)
        msg = 'The latitude of the first point is wrong'
        self.assertTrue(abs(dsts[0][1] - 0.0) < 1e-2, msg)

        # Check second point
        msg = 'The longitude of the second point is wrong'
        self.assertTrue(abs(dsts[1, 0] - 0.0) < 1e-2, msg)
        msg = 'The latitude of the second point is wrong'
        self.assertTrue(abs(dsts[1][1] - 0.0) < 1e-2, msg)
Ejemplo n.º 32
0
 def test_hypocenter_depth_out_of_seismogenic_layer(self):
     self.assert_failed_creation(
         ValueError, 'depths of all hypocenters must be in between '
         'lower and upper seismogenic depths',
         upper_seismogenic_depth=3,
         lower_seismogenic_depth=8,
         hypocenter_distribution=PMF([(0.3, 4), (0.7, 8.001)]))
Ejemplo n.º 33
0
 def fromdict(self, dic, weights=None):
     """
     Populate a GriddedSource with ruptures
     """
     assert not self.data, '%s is not empty' % self
     i = 0
     for mag, rake, hp, probs, (start, stop) in zip(dic['magnitude'],
                                                    dic['rake'],
                                                    dic['hypocenter'],
                                                    dic['probs_occur'],
                                                    dic['slice']):
         mesh = Mesh(dic['mesh3d'][start:stop, 0],
                     dic['mesh3d'][start:stop, 1], dic['mesh3d'][start:stop,
                                                                 2])
         surface = GriddedSurface(mesh)
         pmf = PMF([(prob, i) for i, prob in enumerate(probs)])
         hypocenter = Point(hp[0], hp[1], hp[2])
         rup = NonParametricProbabilisticRupture(
             mag,
             rake,
             self.tectonic_region_type,
             hypocenter,
             surface,
             pmf,
             weight=None if weights is None else weights[i])
         self.data.append((rup, pmf))
         i += 1