Exemplo n.º 1
0
 def test_get_amplification_factors(self):
     """
     Tests the amplification tables
     """
     ctx = RuptureContext()
     ctx.mag = 6.0
     # Takes distances at the values found in the table (not checking
     # distance interpolation)
     ctx.rjb = np.copy(self.amp_table.distances[:, 0, 0])
     # Test Vs30 is 700.0 m/s midpoint between the 400 m/s and 1000 m/s
     # specified in the table
     ctx.vs30 = 700.0 * np.ones_like(ctx.rjb)
     stddevs = [const.StdDev.TOTAL]
     expected_mean = np.ones_like(ctx.rjb)
     expected_sigma = np.ones_like(ctx.rjb)
     # Check PGA and PGV
     mean_amp, sigma_amp = self.amp_table.get_amplification_factors(
         imt_module.PGA(), ctx, ctx.rjb, stddevs)
     np.testing.assert_array_almost_equal(
         mean_amp,
         midpoint(1.0, 1.5) * expected_mean)
     np.testing.assert_array_almost_equal(sigma_amp[0], 0.9 * expected_mean)
     mean_amp, sigma_amp = self.amp_table.get_amplification_factors(
         imt_module.PGV(), ctx, ctx.rjb, stddevs)
     np.testing.assert_array_almost_equal(
         mean_amp,
         midpoint(1.0, 0.5) * expected_mean)
     np.testing.assert_array_almost_equal(sigma_amp[0], 0.9 * expected_mean)
     # Sa (0.5)
     mean_amp, sigma_amp = self.amp_table.get_amplification_factors(
         imt_module.SA(0.5), ctx, ctx.rjb, stddevs)
     np.testing.assert_array_almost_equal(
         mean_amp,
         midpoint(1.0, 2.0) * expected_mean)
     np.testing.assert_array_almost_equal(sigma_amp[0], 0.9 * expected_mean)
Exemplo n.º 2
0
 def test_get_mean_and_stddevs_good_amplified(self):
     """
     Tests the full execution of the GMPE tables for valid data with
     amplification
     """
     gsim = GMPETable(gmpe_table=self.TABLE_FILE)
     ctx = RuptureContext()
     ctx.mag = 6.0
     # Test values at the given distances and those outside range
     ctx.rjb = np.array([0.5, 1.0, 10.0, 100.0, 500.0])
     ctx.sids = np.arange(5)
     ctx.vs30 = 100. * np.ones(5)
     stddevs = [const.StdDev.TOTAL]
     expected_mean = np.array([20., 20., 10., 5., 1.0E-19])
     expected_sigma = 0.25 * np.ones(5)
     # PGA
     mean, sigma = gsim.get_mean_and_stddevs(ctx, ctx, ctx,
                                             imt_module.PGA(), stddevs)
     np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5)
     np.testing.assert_array_almost_equal(sigma[0], expected_sigma, 5)
     # SA
     mean, sigma = gsim.get_mean_and_stddevs(ctx, ctx, ctx,
                                             imt_module.SA(1.0), stddevs)
     np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5)
     np.testing.assert_array_almost_equal(sigma[0], 0.4 * np.ones(5), 5)
Exemplo n.º 3
0
 def test_recarray_conversion(self):
     # automatic recarray conversion for backward compatibility
     imt = PGA()
     gsim = AbrahamsonGulerce2020SInter()
     ctx = RuptureContext()
     ctx.mag = 5.
     ctx.sids = [0, 1]
     ctx.vs30 = [760., 760.]
     ctx.rrup = [100., 110.]
     mean, _stddevs = gsim.get_mean_and_stddevs(ctx, ctx, ctx, imt, [])
     numpy.testing.assert_allclose(mean, [-5.81116004, -6.00192455])
Exemplo n.º 4
0
 def test_zero_distance(self):
     # test the calculation in case of zero rrup distance (for rrup=0
     # the equations have a singularity). In this case the
     # method should return values equal to the ones obtained by
     # replacing 0 values with 1
     ctx = RuptureContext()
     ctx.sids = [0, 1]
     ctx.vs30 = numpy.array([500.0, 2500.0])
     ctx.mag = 5.0
     ctx.rrup = numpy.array([0.0, 0.2])
     mean_0, stds_0 = self.GSIM_CLASS().get_mean_and_stddevs(
         ctx, ctx, ctx, PGA(), [StdDev.TOTAL])
     ctx.rrup = numpy.array([1.0, 0.2])
     mean_01, stds_01 = self.GSIM_CLASS().get_mean_and_stddevs(
         ctx, ctx, ctx, PGA(), [StdDev.TOTAL])
     numpy.testing.assert_array_equal(mean_0, mean_01)
     numpy.testing.assert_array_equal(stds_0, stds_01)
Exemplo n.º 5
0
 def test_rhypo_smaller_than_15(self):
     # test the calculation in case of rhypo distances less than 15 km
     # (for rhypo=0 the distance term has a singularity). In this case the
     # method should return values equal to the ones obtained by clipping
     # distances at 15 km.
     ctx = RuptureContext()
     ctx.sids = [0, 1, 2]
     ctx.vs30 = numpy.array([800.0, 800.0, 800.0])
     ctx.mag = 5.0
     ctx.rake = 0
     ctx.rhypo = numpy.array([0.0, 10.0, 16.0])
     ctx.rhypo.flags.writeable = False
     mean_0, stds_0 = self.GSIM_CLASS().get_mean_and_stddevs(
         ctx, ctx, ctx, PGA(), [StdDev.TOTAL])
     mean_15, stds_15 = self.GSIM_CLASS().get_mean_and_stddevs(
         ctx, ctx, ctx, PGA(), [StdDev.TOTAL])
     numpy.testing.assert_array_equal(mean_0, mean_15)
     numpy.testing.assert_array_equal(stds_0, stds_15)
Exemplo n.º 6
0
 def test_zero_distance(self):
     # test the calculation in case of zero rrup distance (for rrup=0
     # the slab correction term has a singularity). In this case the
     # method should return values equal to the ones obtained by
     # replacing 0 values with 0.1
     ctx = RuptureContext()
     ctx.sids = [0, 1]
     ctx.vs30 = numpy.array([800.0, 800.0])
     ctx.mag = 5.0
     ctx.rake = 0.0
     ctx.hypo_depth = 0.0
     ctx.rrup = numpy.array([0.0, 0.2])
     ctx.occurrence_rate = .0001
     mean_0, stds_0 = self.GSIM_CLASS().get_mean_and_stddevs(
         ctx, ctx, ctx, PGA(), [StdDev.TOTAL])
     ctx.rrup = numpy.array([0.1, 0.2])
     mean_01, stds_01 = self.GSIM_CLASS().get_mean_and_stddevs(
         ctx, ctx, ctx, PGA(), [StdDev.TOTAL])
     numpy.testing.assert_array_equal(mean_0, mean_01)
     numpy.testing.assert_array_equal(stds_0, stds_01)
Exemplo n.º 7
0
def signal_end(
    st,
    event_time,
    event_lon,
    event_lat,
    event_mag,
    method=None,
    vmin=None,
    floor=None,
    model=None,
    epsilon=2.0,
):
    """
    Estimate end of signal by using a model of the 5-95% significant
    duration, and adding this value to the "signal_split" time. This probably
    only works well when the split is estimated with a p-wave picker since
    the velocity method often ends up with split times that are well before
    signal actually starts.

    Args:
        st (StationStream):
            Stream of data.
        event_time (UTCDateTime):
            Event origin time.
        event_mag (float):
            Event magnitude.
        event_lon (float):
            Event longitude.
        event_lat (float):
            Event latitude.
        method (str):
            Method for estimating signal end time. Either 'velocity'
            or 'model'.
        vmin (float):
            Velocity (km/s) for estimating end of signal. Only used if
            method="velocity".
        floor (float):
            Minimum duration (sec) applied along with vmin.
        model (str):
            Short name of duration model to use. Must be defined in the
            gmprocess/data/modules.yml file.
        epsilon (float):
            Number of standard deviations; if epsilon is 1.0, then the signal
            window duration is the mean Ds + 1 standard deviation. Only used
            for method="model".

    Returns:
        trace with stats dict updated to include a
        stats['processing_parameters']['signal_end'] dictionary.

    """
    # Load openquake stuff if method="model"
    if method == "model":
        dmodel = load_model(model)

        # Set some "conservative" inputs (in that they will tend to give
        # larger durations).
        rctx = RuptureContext()
        rctx.mag = event_mag
        rctx.rake = -90.0
        rctx.vs30 = np.array([180.0])
        rctx.z1pt0 = np.array([0.51])
        dur_imt = imt.from_string("RSD595")
        stddev_types = [const.StdDev.TOTAL]

    for tr in st:
        if not tr.hasParameter("signal_split"):
            continue
        if method == "velocity":
            if vmin is None:
                raise ValueError('Must specify vmin if method is "velocity".')
            if floor is None:
                raise ValueError('Must specify floor if method is "velocity".')
            epi_dist = (gps2dist_azimuth(
                lat1=event_lat,
                lon1=event_lon,
                lat2=tr.stats["coordinates"]["latitude"],
                lon2=tr.stats["coordinates"]["longitude"],
            )[0] / 1000.0)
            end_time = event_time + max(floor, epi_dist / vmin)
        elif method == "model":
            if model is None:
                raise ValueError('Must specify model if method is "model".')
            epi_dist = (gps2dist_azimuth(
                lat1=event_lat,
                lon1=event_lon,
                lat2=tr.stats["coordinates"]["latitude"],
                lon2=tr.stats["coordinates"]["longitude"],
            )[0] / 1000.0)
            # Repi >= Rrup, so substitution here should be conservative
            # (leading to larger durations).
            rctx.rrup = np.array([epi_dist])
            rctx.sids = np.array(range(np.size(rctx.rrup)))
            lnmu, lnstd = dmodel.get_mean_and_stddevs(rctx, rctx, rctx,
                                                      dur_imt, stddev_types)
            duration = np.exp(lnmu + epsilon * lnstd[0])
            # Get split time
            split_time = tr.getParameter("signal_split")["split_time"]
            end_time = split_time + float(duration)
        else:
            raise ValueError('method must be either "velocity" or "model".')
        # Update trace params
        end_params = {
            "end_time": end_time,
            "method": method,
            "vsplit": vmin,
            "floor": floor,
            "model": model,
            "epsilon": epsilon,
        }
        tr.setParameter("signal_end", end_params)

    return st