Ejemplo n.º 1
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.º 2
0
def _create_non_param_sourceA(rjb, magnitude, pmf,
                              tectonic_region_type=TRT.ACTIVE_SHALLOW_CRUST):
    # Create a non-parametric source
    rupture = _create_rupture(rjb, magnitude)
    pmf = pmf
    data = [(rupture, pmf)]
    return NonParametricSeismicSource('0', 'test', tectonic_region_type, data)
Ejemplo n.º 3
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)
     src.src_group_id = [0]
     group = SourceGroup(
         src.tectonic_region_type, [src], 'test', 'mutex', 'mutex')
     param = dict(imtls=self.imtls)
     crv = classical(group, self.sites, gsim_by_trt, param)[0]
     npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]),
                             crv[0].array[:, 0], decimal=4)
Ejemplo n.º 4
0
def _create_non_param_sourceA(rjb,
                              magnitude,
                              pmf,
                              tectonic_region_type="Active Shallow Crust"):
    # Create a non-parametric source
    rupture = _create_rupture(rjb, magnitude)
    pmf = pmf
    data = [(rupture, pmf)]
    return NonParametricSeismicSource('0', 'test', tectonic_region_type, data)
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_non_parametric_source(self):
        # non-parametric source equivalent to case 2 simple fault source
        data = test_data.SET1_CASE2_SOURCE_DATA
        ruptures = []
        for i in range(data['num_rups_dip']):
            for j in range(data['num_rups_strike']):
                lons = data['lons']
                lats = data['lats'][j]
                depths = data['depths'][i]
                mesh = RectangularMesh(lons, lats, depths)
                surf = SimpleFaultSurface(mesh)
                hypo = Point(
                    data['hypo_lons'][i, j],
                    data['hypo_lats'][i, j],
                    data['hypo_depths'][i, j]
                )
                rup = BaseRupture(data['mag'], data['rake'],
                                  data['tectonic_region_type'], hypo, surf,
                                  data['source_typology'])
                ruptures.append((rup, data['pmf']))
        npss = NonParametricSeismicSource(
            'id', 'name', data['tectonic_region_type'], ruptures
        )
        sites = SiteCollection([
            test_data.SET1_CASE1TO9_SITE1, test_data.SET1_CASE1TO9_SITE2,
            test_data.SET1_CASE1TO9_SITE3, test_data.SET1_CASE1TO9_SITE4,
            test_data.SET1_CASE1TO9_SITE5, test_data.SET1_CASE1TO9_SITE6,
            test_data.SET1_CASE1TO9_SITE7
        ])
        gsims = {const.TRT.ACTIVE_SHALLOW_CRUST: SadighEtAl1997()}
        truncation_level = 0
        imts = {str(test_data.IMT): test_data.SET1_CASE2_IMLS}

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

        assert_hazard_curve_is(self, s1hc, test_data.SET1_CASE2_SITE1_POES,
                               atol=3e-3, rtol=1e-5)
        assert_hazard_curve_is(self, s2hc, test_data.SET1_CASE2_SITE2_POES,
                               atol=2e-5, rtol=1e-5)
        assert_hazard_curve_is(self, s3hc, test_data.SET1_CASE2_SITE3_POES,
                               atol=2e-5, rtol=1e-5)
        assert_hazard_curve_is(self, s4hc, test_data.SET1_CASE2_SITE4_POES,
                               atol=1e-3, rtol=1e-5)
        assert_hazard_curve_is(self, s5hc, test_data.SET1_CASE2_SITE5_POES,
                               atol=1e-3, rtol=1e-5)
        assert_hazard_curve_is(self, s6hc, test_data.SET1_CASE2_SITE6_POES,
                               atol=1e-3, rtol=1e-5)
        assert_hazard_curve_is(self, s7hc, test_data.SET1_CASE2_SITE7_POES,
                               atol=2e-5, rtol=1e-5)
Ejemplo n.º 7
0
def create_nrml_source(rup, mag, sid, name, tectonic_region_type):
    """
    :param rup:
    :param mag:
    :param sid:
    :param name:
    :param tectonic_region_type:
    """
    data = []
    for key in rup.keys():
        d = rup[key][:]
        #
        # creating the surface
        llo = np.squeeze(d['lons'])
        lla = np.squeeze(d['lats'])
        lde = np.squeeze(d['deps'])
        #
        # find a node in the middle of the rupture
        if len(llo.shape):
            ihyp = (int(np.round(llo.shape[0] / 2)))
            if len(llo.shape) > 1:
                ihyp = (ihyp, int(np.round(llo.shape[1] / 2)))
            hlo = llo[ihyp]
            hla = lla[ihyp]
            hde = lde[ihyp]
            #
            #
            ppp = np.squeeze(d['prbs'])
            i = np.isfinite(llo)
            points = [
                Point(x, y, z) for x, y, z in zip(llo[i], lla[i], lde[i])
            ]
            srf = GriddedSurface.from_points_list(points)
            """
            br = BaseRupture(mag=mag,
                             rake=-90.,
                             tectonic_region_type=tectonic_region_type,
                             hypocenter=Point(hlo, hla, hde),
                             surface=srf,
                             source_typology=NonParametricSeismicSource)
            """
            br = BaseRupture(mag=mag,
                             rake=-90.,
                             tectonic_region_type=tectonic_region_type,
                             hypocenter=Point(hlo, hla, hde),
                             surface=srf)
            xxx = Decimal('{:.8f}'.format(ppp[1]))
            pmf = PMF(data=[((Decimal('1') - xxx), 0), (xxx, 1)])
            data.append((br, pmf))
    src = NonParametricSeismicSource(sid, name, tectonic_region_type, data)
    return src
 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.º 9
0
def create_source(rup, mag, sid, name, tectonic_region_type):
    """
    :param rup:
        A h5py dataset with the rupture information
    :param mag:
        The magnitude of the ruptures
    :param sid:
        Source ID
    :param name:
        Name of the source
    :param tectonic_region_type:
        Tectonic region type
    """
    data = []
    for key in rup.keys():
        d = rup[key][:]

        # Creating the surface
        llo = np.squeeze(d['lons'])
        lla = np.squeeze(d['lats'])
        lde = np.squeeze(d['deps'])

        # Create the gridded surface
        if len(llo.shape) > 0:

            # Hypocenter computed in the 'rupture.py' module
            hypo = np.squeeze(d['hypo'][:])
            hlo = hypo[0]
            hla = hypo[1]
            hde = hypo[2]

            # Probabilities of occurrence
            ppp = np.squeeze(d['prbs'])
            i = np.isfinite(llo)
            points = [Point(x, y, z) for x, y, z in
                      zip(llo[i], lla[i], lde[i])]

            # Create the surface and the rupture
            srf = GriddedSurface.from_points_list(points)
            brup = BaseRupture(mag=mag, rake=-90.,
                               tectonic_region_type=tectonic_region_type,
                               hypocenter=Point(hlo, hla, hde),
                               surface=srf)
            xxx = Decimal('{:.8f}'.format(ppp[1]))
            pmf = PMF(data=[((Decimal('1')-xxx), 0), (xxx, 1)])
            data.append((brup, pmf))
    src = NonParametricSeismicSource(sid, name, tectonic_region_type, data)
    return src