def get_mean_and_stddevs(self, sx, rx, dx, imt, stddev_types, fd=None):
        """
        See superclass
        `method <http://docs.openquake.org/oq-hazardlib/master/gsim/index.html#openquake.hazardlib.gsim.base.GroundShakingIntensityModel.get_mean_and_stddevs>`__
        for parameter definitions. The only acceptable IMT is MMI.
        Additional subclass argument is "fd", which is the directivity
        amplification factor in natural log units. This is optional,
        and must be a numpy array with the same dimentions as the
        sites and is added to the ground motions before conversion to
        MMI.
        Returns:
            ndarray, list of ndarray:
            mmi (ndarray): Ground motions predicted by the MultiGMPE using
            the supplied parameters are converted to MMI using the GMICE.
            mmi_sd (list of ndarrays): The uncertainty of the combined
            prediction/conversion process. The prediction uncertainty will
            typically be either OpenQuake's TOTAL or INTRA_EVENT.  But can
            be any set that the MultiGMPE supports. See the ShakeMap manual
            for a detailed discussion of the way the uncertainty is computed.
        """  # noqa

        if imt != MMI():
            raise ValueError("imt must be MMI")
        #
        # Get the mean ground motions and stddev for the preferred IMT
        #
        mgm, sdev = self.gmpe.get_mean_and_stddevs(sx, rx, dx, self.imt,
                                                   stddev_types)

        if fd is not None:
            mgm = mgm + fd

        #
        # Get the MMI and the dMMI/dPGM from the GMICE
        #
        if hasattr(dx, 'rrup'):
            dist4gmice = dx.rrup
        else:
            dist4gmice = dx.rhypo

        mmi, dmda = self.gmice.getMIfromGM(mgm, self.imt, dist4gmice, rx.mag)

        #
        # Compute the uncertainty of the combined prediction/conversion
        # Total and intra-event uncertanty are inflated by the uncertainty
        # of the conversion; inter-event uncertainty is not.
        #
        ntypes = len(stddev_types)
        nsd = len(sdev)
        mmi_sd = [None] * nsd
        gm2mi_var = (self.gmice.getGM2MIsd()[self.imt])**2
        dmda *= dmda
        for i in range(nsd):
            gm_var_in_mmi = dmda * sdev[i]**2
            if stddev_types[i % ntypes] == const.StdDev.INTER_EVENT:
                mmi_sd[i] = np.sqrt(gm_var_in_mmi)
            else:
                mmi_sd[i] = np.sqrt(gm2mi_var + gm_var_in_mmi)

        return mmi, mmi_sd
Beispiel #2
0
 def setUp(self):
     # Set parameters
     self.sites = Dummy.get_site_collection(
         4, amplfactor=[-1.0, 1.5, 0.00, -1.99])
     self.rup = Dummy.get_rupture(mag=6.0, hypo_depth=10)
     self.dists = DistancesContext()
     self.dists.rhypo = np.array([1., 10., 30., 70.])
     self.dists.repi = np.array([1., 10., 30., 70.])
     self.imt = MMI()
 def setUp(self):
     self.ctx = ctx = RuptureContext()
     ctx.mag = 6.0
     ctx.hypo_depth = 10.
     sites = Dummy.get_site_collection(4,
                                       amplfactor=[-1.0, 1.5, 0.00, -1.99])
     for name in sites.array.dtype.names:
         setattr(ctx, name, sites[name])
     ctx.rhypo = np.array([1., 10., 30., 70.])
     ctx.repi = np.array([1., 10., 30., 70.])
     self.imt = MMI()
Beispiel #4
0
def test_wald99():
    gmice = Wald99()

    df = {'PGA': amps_in,
          'PGV': amps_in + np.log(100)}

    mi = gmice.getPreferredMI(df)
    mi_target = np.array(
        [3.18167182, 4.23133858, 5.68946656, 6.84666436, 7.47561075,
         7.90914817, 8.24542592, 9.29])

    if do_test is True:
        np.testing.assert_allclose(mi, mi_target)
    else:
        print(repr(mi))

    pga_amps_in_nan = np.log(np.array(
        [0.01, 0.03, 0.1, np.nan, 0.3, 0.4, 0.5, 1.0]))
    pgv_amps_in_nan = np.log(np.array(
        [0.01, 0.03, 0.1, 0.2, np.nan, 0.4, 0.5, 1.0])) + np.log(100)
    pga_amps_in_nan[5] = np.nan
    pgv_amps_in_nan[5] = np.nan
    df = {'PGA': pga_amps_in_nan,
          'PGV': pgv_amps_in_nan}

    mi = gmice.getPreferredMI(df)
    mi_target = np.array(
        [3.18167182, 4.23133858, 5.68946656, 6.86457408, 7.37577236,
         np.nan, 8.24542592, 9.29])

    if do_test is True:
        np.testing.assert_allclose(mi, mi_target)
    else:
        print(repr(mi))

    mi, dmda = gmice.getMIfromGM(amps_in, PGA(), dists=None, mag=None)
    mi_target = np.array(
        [3.18167182,  4.23133858,  5.62950857,  6.73127835,  7.37577236,
         7.83304814,  8.18773878,  9.28950857])

    if do_test is True:
        np.testing.assert_allclose(mi, mi_target)
        assert((set(dmda) - dmda_target[PGA()]) == set())
    else:
        print(repr(mi))

    mi, dmda = gmice.getMIfromGM(
        amps_in + np.log(100), PGV(), dists=None, mag=None)
    mi_target = np.array(
        [3.4,  4.40195463,  5.82,  6.86457408,  7.47561075,
         7.90914817,  8.24542592,  9.29])

    if do_test is True:
        np.testing.assert_allclose(mi, mi_target)
        assert((set(dmda) - dmda_target[PGV()]) == set())
    else:
        print(repr(mi))

    amps, dadm = gmice.getGMfromMI(mmi_in, PGA(), dists=None, mag=None)
    amps_target = np.array(
        [-5.84194287, -4.79531328, -3.7486837, -2.69862254, -1.9436766,
         -1.25164283, -0.74834554, -0.1821361])

    if do_test is True:
        np.testing.assert_allclose(amps, amps_target)
        assert((set(dadm) - dadm_target[PGA()]) == set())
    else:
        print(repr(amps))

    amps, dadm = gmice.getGMfromMI(mmi_in, PGV(), dists=None, mag=None)
    amps_target = np.array(
        [-1.53505673, -0.43858764,  0.65788146,  1.75845836,  2.55474139,
         3.2846675,  3.81552285,  4.41273512])

    if do_test is True:
        np.testing.assert_allclose(amps, amps_target)
        assert((set(dadm) - dadm_target[PGV()]) == set())
    else:
        print(repr(amps))

    if do_test is True:
        sdd = gmice.getGM2MIsd()
        assert sdd[PGA()] == 1.08
        assert sdd[PGV()] == 0.98

        sdd = gmice.getMI2GMsd()
        lnten = np.log(10.0)
        np.testing.assert_allclose(sdd[PGA()], 0.295 * lnten)
        np.testing.assert_allclose(sdd[PGV()], 0.282 * lnten)

        nm = gmice.getName()
        assert nm == 'Wald et al. (1999)'

        sc = gmice.getScale()
        assert sc == 'scale_wald99.ps'

        mm = gmice.getMinMax()
        assert mm == (1.0, 10.0)

        dt = gmice.getDistanceType()
        assert dt == 'rrup'

    #
    # This should fail because MMI() is not a valid argument to
    # getMIfromGM
    #
    with pytest.raises(ValueError) as e:  # noqa
        mi, dmda = gmice.getMIfromGM(amps_in, MMI(), dists=None, mag=None)
Beispiel #5
0
def test_ak07():
    gmice = AK07()

    mi, dmda = gmice.getMIfromGM(amps_in, PGA(), dists=None, mag=None)
    mi_target = np.array(
        [4.02841992026,  4.69161846432,  6.23592624018,  7.46713892245,
         8.18735217199, 8.69835160472,  9.09471355792])
    np.testing.assert_allclose(mi, mi_target)

    mi, dmda = gmice.getMIfromGM(
        amps_in + np.log(100), PGV(), dists=dists, mag=None)
    mi_target = np.array(
        [4.37, 4.99980005623, 6.57, 7.48212088686, 8.0156774018,
         8.39424177372, 8.68787911314])
    np.testing.assert_allclose(mi, mi_target)

    mi, dmda = gmice.getMIfromGM(amps_in, SA(0.3), dists=None, mag=3.0)
    mi_target = np.array(
        [3.74866985004, 4.39755475646, 5.26034166627, 6.33200845084,
         6.95889333307, 7.4036752354, 7.74867488171])
    np.testing.assert_allclose(mi, mi_target)

    mi, dmda = gmice.getMIfromGM(amps_in, SA(1.0), dists=dists, mag=7.5)
    mi_target = np.array(
        [3.52702354769, 4.07617250928, 5.55842357177, 6.46666805811,
         7.00909852304, 7.39358539638, 7.67946993475])
    np.testing.assert_allclose(mi, mi_target)

    mi, dmda = gmice.getMIfromGM(amps_in, SA(3.0), dists=None, mag=None)
    mi_target = np.array(
        [4.99925301952, 6.3963707863, 7.96500702214, 8.86809700913,
         9.3963707863, 9.77118699612, 10.])
    np.testing.assert_allclose(mi, mi_target)

    amps, dadm = gmice.getGMfromMI(mmi_in, PGA(), dists=None, mag=7.0)
    amps_target = np.log(np.array(
        [0.000347300247926,   0.00182024377197, 0.00954012388176,
         0.0498674941261, 0.0979977440572, 0.182039122534,
         0.285603651352]))
    np.testing.assert_allclose(amps, amps_target)

    amps, dadm = gmice.getGMfromMI(mmi_in, PGV(), dists=dists, mag=None)
    amps_target = np.log(np.array(
        [0.0160156826445, 0.0916476244071, 0.524441401963,
         3.03283082017, 7.54897155245, 17.4150246057,
         31.9853049046]))
    np.testing.assert_allclose(amps, amps_target)

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(0.3), dists=None, mag=6.0)
    amps_target = np.log(np.array(
        [0.000517861166862, 0.00281518839281, 0.0153038810286,
         0.0845026480232, 0.183632256171, 0.374056955014,
         0.627562284541]))
    np.testing.assert_allclose(amps, amps_target)

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(1.0), dists=dists, mag=8.0)
    amps_target = np.log(np.array(
        [0.000508056775718, 0.00367375892063, 0.0258564132795,
         0.0636582041631, 0.159533013524, 0.371822895172,
         0.694260679175]))
    np.testing.assert_allclose(amps, amps_target)

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(3.0), dists=None, mag=5.0)
    amps_target = np.log(np.array(
        [0.0000473148708829, 0.000281962568289, 0.00168029392098,
         0.0102722203276, 0.0258026508623, 0.0600248374471,
         0.110916883717]))
    np.testing.assert_allclose(amps, amps_target)

    amps, dadm = gmice.getGMfromMI(mmi_in, PGA(), dists=None, mag=7.0)
    amps_target = np.log(np.array(
        [0.000347300247926, 0.00182024377197, 0.00954012388176,
         0.0498674941261, 0.0979977440572, 0.182039122534,
         0.285603651352]))
    # print(repr(100 * np.exp(amps)))
    np.testing.assert_allclose(amps, amps_target)

    sdd = gmice.getGM2MIsd()
    assert sdd[PGA()] == 0.89
    assert sdd[PGV()] == 0.76
    assert sdd[SA(0.3)] == 0.79
    assert sdd[SA(1.0)] == 0.73
    assert sdd[SA(3.0)] == 0.72

    sdd = gmice.getMI2GMsd()
    assert abs(sdd[PGA()] - 1.312473503006606) < 0.0000001
    assert abs(sdd[PGV()] - 1.197344248356904) < 0.0000001
    assert abs(sdd[SA(0.3)] - 1.450628608586249) < 0.0000001
    assert abs(sdd[SA(1.0)] - 1.312473503006606) < 0.0000001
    assert abs(sdd[SA(3.0)] - 1.865093925325177) < 0.0000001

    nm = gmice.getName()
    assert nm == 'Atkinson and Kaka (2007)'

    sc = gmice.getScale()
    assert sc == 'scale_ak07.ps'

    mm = gmice.getMinMax()
    assert mm == (1.0, 10.0)

    dt = gmice.getDistanceType()
    assert dt == 'rrup'

    #
    # This should fail
    #
    with pytest.raises(ValueError) as e:  # noqa
        mi, dmda = gmice.getMIfromGM(amps_in, MMI(), dists=None, mag=None)
Beispiel #6
0
def test_virtualipe():

    #
    # Set up the GMPE, IPE, and GMICE
    #
    gmpe_cy14 = ChiouYoungs2014()
    gmpe = MultiGMPE.from_list([gmpe_cy14], [1.0])
    gmice = WGRW12()
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)

    #
    # Use the Calexico event info
    #
    homedir = os.path.dirname(os.path.abspath(__file__))
    datadir = os.path.abspath(
        os.path.join(homedir, 'virtualipe_data', 'Calexico', 'input'))

    #
    # Read the event, origin, and rupture files and produce Rupture and Origin
    # objects
    #
    # inputfile = os.path.join(datadir, 'stationlist_dat.xml')
    # dyfifile = os.path.join(datadir, 'ciim3_dat.xml')
    eventfile = os.path.join(datadir, 'event.xml')
    rupturefile = os.path.join(datadir, 'wei_fault.txt')

    origin_obj = Origin.fromFile(eventfile)
    rupture_obj = get_rupture(origin_obj, rupturefile)
    rx = rupture_obj.getRuptureContext([gmpe])
    rx.rake = 45.

    smdx = 0.0083333333
    smdy = 0.0083333333
    lonspan = 6.0
    latspan = 4.0
    vs30filename = os.path.join(datadir, '..', 'vs30', 'vs30.grd')

    sites_obj_grid = Sites.fromCenter(rx.hypo_lon,
                                      rx.hypo_lat,
                                      lonspan,
                                      latspan,
                                      smdx,
                                      smdy,
                                      defaultVs30=760.0,
                                      vs30File=vs30filename,
                                      vs30measured_grid=None,
                                      padding=False,
                                      resample=False)

    npts = 200
    lats = np.empty(npts)
    lons = np.empty(npts)
    depths = np.zeros(npts)
    for i in range(npts):
        lats[i] = rx.hypo_lat
        lons[i] = rx.hypo_lon + i * 0.01
    lldict = {'lats': lats, 'lons': lons}

    sx = sites_obj_grid.getSitesContext(lldict=lldict, rock_vs30=760.0)

    dobj = Distance(gmpe, lons, lats, depths, rupture_obj)
    dx = dobj.getDistanceContext()

    sd_types = [oqconst.StdDev.TOTAL]
    mmi_const_vs30, mmi_sd_const_vs30 = \
        ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

    # These prints are just so a human can examine the outputs
    #    print(mmi_const_vs30)
    #    print(mmi_sd_const_vs30)

    sx = sites_obj_grid.getSitesContext(lldict=lldict)
    mmi_variable_vs30, mmi_sd_variable_vs30 = \
        ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

    #    print(mmi_variable_vs30)
    #    print(mmi_sd_variable_vs30)

    sd_types = [
        oqconst.StdDev.TOTAL, oqconst.StdDev.INTRA_EVENT,
        oqconst.StdDev.INTER_EVENT
    ]
    mmi_variable_vs30_intra, mmi_sd_variable_vs30_intra = \
        ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

    #    print(mmi_variable_vs30_intra)
    #    print(mmi_sd_variable_vs30_intra)
    #    assert(0)      # Assert causes test to fail and prints to be displayed

    #
    # Try with PGA
    #
    gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(PGV)
    gmpe.ALL_GMPES_HAVE_PGV = False
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)
    mmi_pga, mmi_sd_pga = \
        ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)
    #
    # Try with SA(1.0)
    #
    gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(PGA)
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)
    mmi_psa, mmi_sd_psa = \
        ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

    #
    # This should raise an exception because the IMT isn't MMI
    #
    with pytest.raises(ValueError) as e:
        mmi_psa, mmi_sd_psa = \
            ipe.get_mean_and_stddevs(sx, rx, dx, PGA(), sd_types)
    #
    # This should raise an exception because no valid IMTs are available
    #
    gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(SA)
    with pytest.raises(ShakeLibException) as e:  # noqa
        ipe = VirtualIPE.fromFuncs(gmpe, gmice)

    #
    # Now do a GMPE that uses Rjb instead of Rrup
    #
    gmpe_ba14 = BooreEtAl2014()
    gmpe = MultiGMPE.from_list([gmpe_ba14], [1.0])
    ipe = VirtualIPE.fromFuncs(gmpe, gmice)
    rx = rupture_obj.getRuptureContext([gmpe])
    rx.rake = 45.
    dobj = Distance(gmpe, lons, lats, depths, rupture_obj)
    dx = dobj.getDistanceContext()

    mmi_rjb, mmi_sd_rjb = \
        ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types)

    #
    # Test the results against a known standard
    #
    savefile = os.path.abspath(
        os.path.join(homedir, 'virtualipe_data', 'Calexico', 'virtualipe_test',
                     'savefile.npz'))

    #
    # If things change, set remake_save to True, and it will rebuild the
    # saved data file against which the comparisons are done
    # Remember to set this back to False once you've remade the test datafile
    #
    remake_save = False
    if remake_save:
        np.savez_compressed(
            savefile,
            mmi_const_vs30=mmi_const_vs30,
            mmi_sd_const_vs30=mmi_sd_const_vs30[0],
            mmi_variable_vs30=mmi_variable_vs30,
            mmi_sd_variable_vs30=mmi_sd_variable_vs30[0],
            mmi_variable_vs30_intra=mmi_variable_vs30_intra,
            mmi_sd_variable_vs30_total=mmi_sd_variable_vs30_intra[0],
            mmi_sd_variable_vs30_intra=mmi_sd_variable_vs30_intra[1],
            mmi_sd_variable_vs30_inter=mmi_sd_variable_vs30_intra[2],
            mmi_pga=mmi_pga,
            mmi_sd_pga=mmi_sd_pga[0],
            mmi_psa=mmi_psa,
            mmi_sd_psa=mmi_sd_psa[0],
            mmi_rjb=mmi_rjb,
            mmi_sd_rjb=mmi_sd_rjb[0])

    td = np.load(savefile)

    assert (np.allclose(td['mmi_const_vs30'], mmi_const_vs30))
    assert (np.allclose(td['mmi_sd_const_vs30'], mmi_sd_const_vs30[0]))
    assert (np.allclose(td['mmi_variable_vs30'], mmi_variable_vs30))
    assert (np.allclose(td['mmi_sd_variable_vs30'], mmi_sd_variable_vs30[0]))
    assert (np.allclose(td['mmi_variable_vs30_intra'],
                        mmi_variable_vs30_intra))
    assert (np.allclose(td['mmi_sd_variable_vs30_total'],
                        mmi_sd_variable_vs30_intra[0]))
    assert (np.allclose(td['mmi_sd_variable_vs30_intra'],
                        mmi_sd_variable_vs30_intra[1]))
    assert (np.allclose(td['mmi_sd_variable_vs30_inter'],
                        mmi_sd_variable_vs30_intra[2]))
    assert (np.allclose(td['mmi_pga'], mmi_pga))
    assert (np.allclose(td['mmi_sd_pga'], mmi_sd_pga[0]))
    assert (np.allclose(td['mmi_psa'], mmi_psa))
    assert (np.allclose(td['mmi_sd_psa'], mmi_sd_psa[0]))
    assert (np.allclose(td['mmi_rjb'], mmi_rjb))
    assert (np.allclose(td['mmi_sd_rjb'], mmi_sd_rjb[0]))

    # The total uncertainties should be greater than the intra-event
    assert (np.all(mmi_sd_variable_vs30[0] > mmi_sd_variable_vs30_intra[1]))

    # The combined intra and inter-event uncertainty should be equal
    # to the total
    tot = np.sqrt(mmi_sd_variable_vs30_intra[1]**2 +
                  mmi_sd_variable_vs30_intra[2]**2)
    assert (np.allclose(tot, mmi_sd_variable_vs30_intra[0], rtol=1e-2))
Beispiel #7
0
def _parse_csv_line(headers, values):
    """
    Parse a single line from data file.

    :param headers:
        A list of header names, the strings from the first line of csv file.
    :param values:
        A list of values of a single row to parse.
    :returns:
        A tuple of the following values (in specified order):

        sctx
            An instance of :class:`openquake.hazardlib.gsim.base.SitesContext`
            with attributes populated by the information from in row in a form
            of single-element numpy arrays.
        rctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.RuptureContext`.
        dctx
            An instance of
            :class:`openquake.hazardlib.gsim.base.DistancesContext`.
        stddev_types
            An empty list, if the ``result_type`` column says "MEAN"
            for that row, otherwise it is a list with one item --
            a requested standard deviation type.
        expected_results
            A dictionary mapping IMT-objects to one-element arrays of expected
            result values. Those results represent either standard deviation
            or mean value of corresponding IMT depending on ``result_type``.
        result_type
            A string literal, one of ``'STDDEV'`` or ``'MEAN'``. Value
            is taken from column ``result_type``.
    """
    rctx = RuptureContext()
    sctx = SitesContext()
    dctx = DistancesContext()
    expected_results = {}
    stddev_types = result_type = damping = None

    for param, value in zip(headers, values):
        if param == 'result_type':
            value = value.upper()
            if value.endswith('_STDDEV'):
                # the row defines expected stddev results
                result_type = 'STDDEV'
                stddev_types = [getattr(const.StdDev, value[:-len('_STDDEV')])]
            else:
                # the row defines expected exponents of mean values
                assert value == 'MEAN'
                stddev_types = []
                result_type = 'MEAN'
        elif param == 'damping':
            damping = float(value)
        elif param.startswith('site_'):
            # value is sites context object attribute
            if (param == 'site_vs30measured') or (param == 'site_backarc'):
                value = float(value) != 0
            else:
                value = float(value)
            setattr(sctx, param[len('site_'):], numpy.array([value]))
        elif param.startswith('dist_'):
            # value is a distance measure
            value = float(value)
            setattr(dctx, param[len('dist_'):], numpy.array([value]))
        elif param.startswith('rup_'):
            # value is a rupture context attribute
            value = float(value)
            setattr(rctx, param[len('rup_'):], value)
        elif param == 'component_type':
            pass
        else:
            # value is the expected result (of result_type type)
            value = float(value)
            if param == 'pga':
                imt = PGA()
            elif param == 'pgv':
                imt = PGV()
            elif param == 'pgd':
                imt = PGD()
            elif param == 'cav':
                imt = CAV()
            elif param == 'mmi':
                imt = MMI()
            elif param == "arias":
                imt = IA()
            elif param == "rsd595":
                imt = RSD595()
            elif param == "rsd575":
                imt = RSD575()
            elif param == "rsd2080":
                imt = RSD2080()
            else:
                period = float(param)
                assert damping is not None
                imt = SA(period, damping)

            expected_results[imt] = numpy.array([value])

    assert result_type is not None
    return sctx, rctx, dctx, stddev_types, expected_results, result_type
Beispiel #8
0
def test_wgrw12():
    gmice = WGRW12()

    mi, dmda = gmice.getMIfromGM(amps_in, PGA(), dists=None, mag=None)
    mi_target = np.array(
        [3.31708696,  4.05662491,  5.76917533,  6.88298631,  7.53452397,
         7.9967973,  8.35536434])
    np.testing.assert_allclose(mi, mi_target)
    assert((set(dmda) - dmda_target[PGA()]) == set())

    mi, dmda = gmice.getMIfromGM(
        amps_in + np.log(100), PGV(), dists=dists, mag=None)
    mi_target = np.array(
        [3.78,  4.48136824,  6.05,  7.00125479,  7.55770316,
         7.95250957,  8.25874521])
    np.testing.assert_allclose(mi, mi_target)
    assert((set(dmda) - dmda_target[PGV()]) == set())

    mi, dmda = gmice.getMIfromGM(amps_in, SA(0.3), dists=None, mag=3.0)
    mi_target = np.array(
        [2.93592062,  3.74225554,  4.62592062,  5.34177387,  6.07079169,
         6.58803805,  6.98924551])
    np.testing.assert_allclose(mi, mi_target)
    assert((set(dmda) - dmda_target[SA(0.3)]) == set())

    mi, dmda = gmice.getMIfromGM(amps_in, SA(1.0), dists=dists, mag=7.5)
    mi_target = np.array(
        [3.49070724,  4.3808733,  5.63884012,  6.26430362,  6.49369295,
         6.66102468,  6.94206372])
    np.testing.assert_allclose(mi, mi_target)
    assert((set(dmda) - dmda_target[SA(1.0)]) == set())

    mi, dmda = gmice.getMIfromGM(amps_in, SA(3.0), dists=None, mag=None)
    mi_target = np.array(
        [4.97492371,   6.41105869,   7.98492371,   8.891024,
         9.42105869,   9.79712429,  10.])
    np.testing.assert_allclose(mi, mi_target)
    assert((set(dmda) - dmda_target[SA(3.0)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, PGA(), dists=None, mag=7.0)
    amps_target = np.log(np.array(
        [0.14134045,   0.6243495,   2.75796695,   6.19604804,
         13.07492182,  25.92605261,  42.65329774]) / 100.0)
    np.testing.assert_allclose(amps, amps_target)
    assert((set(dadm) - dadm_target[PGA()]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, PGV(), dists=dists, mag=None)
    amps_target = np.log(np.array(
        [0.06153407,   0.29470517,   1.41143169,   4.65287643,
         11.15496866,  24.86392117,  44.53835548]))
    np.testing.assert_allclose(amps, amps_target)
    assert((set(dadm) - dadm_target[PGV()]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(0.3), dists=None, mag=6.0)
    amps_target = np.log(np.array(
        [0.27938354,   1.09123124,   4.26218963,  16.53773087,
         32.23524628,  59.43352318,  92.74023471]) / 100.0)
    np.testing.assert_allclose(amps, amps_target)
    assert((set(dadm) - dadm_target[SA(0.3)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(1.0), dists=dists, mag=8.0)
    amps_target = np.log(np.array(
        [1.02985637e-01,   3.65288187e-01,   1.67836836e+00,
         7.32931235e+00,   2.37600759e+01,   6.64349034e+01,
         1.25388693e+02]) / 100.0)
    np.testing.assert_allclose(amps, amps_target)
    assert((set(dadm) - dadm_target[SA(1.0)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(3.0), dists=None, mag=5.0)
    amps_target = np.log(np.array(
        [2.89282689e-03,   2.07025242e-02,   1.48157675e-01,
         1.01936799e+00,   2.55271358e+00,   5.92175716e+00,
         1.09202184e+01]) / 100.0)
    np.testing.assert_allclose(amps, amps_target)
    assert((set(dadm) - dadm_target[SA(3.0)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, PGA(), dists=None, mag=7.0)
    amps_target = np.log(np.array(
        [0.14134045,   0.6243495,   2.75796695,   6.19604804,
         13.07492182,  25.92605261,  42.65329774]) / 100.0)
    np.testing.assert_allclose(amps, amps_target)
    assert((set(dadm) - dadm_target[PGA()]) == set())

    sdd = gmice.getGM2MIsd()
    assert sdd[PGA()] == 0.66
    assert sdd[PGV()] == 0.63
    assert sdd[SA(0.3)] == 0.82
    assert sdd[SA(1.0)] == 0.75
    assert sdd[SA(3.0)] == 0.89

    sdd = gmice.getMI2GMsd()
    lnten = np.log(10.0)
    np.testing.assert_allclose(sdd[PGA()], np.log10(2.238721) * lnten)
    np.testing.assert_allclose(sdd[PGV()], np.log10(2.39883291) * lnten)
    np.testing.assert_allclose(sdd[SA(0.3)], np.log10(2.7542287) * lnten)
    np.testing.assert_allclose(sdd[SA(1.0)], np.log10(2.951209) * lnten)
    np.testing.assert_allclose(sdd[SA(3.0)], np.log10(4.365158) * lnten)

    nm = gmice.getName()
    assert nm == 'Worden et al. (2012)'

    sc = gmice.getScale()
    assert sc == 'scale_wgrw12.ps'

    mm = gmice.getMinMax()
    assert mm == (1.0, 10.0)

    dt = gmice.getDistanceType()
    assert dt == 'rrup'

    assert gmice.supports('PGA')
    assert gmice.supports('PGV')
    assert gmice.supports('SA(0.3)')
    assert gmice.supports('SA(1.0)')
    assert gmice.supports('SA(3.0)')
    try:
        assert gmice.supports('SA(10.0)')
        assert 1 == 2
    except AssertionError:
        assert 1 == 1

    #
    # This should fail
    #
    with pytest.raises(ValueError) as e:  # noqa
        mi, dmda = gmice.getMIfromGM(amps_in, MMI(), dists=None, mag=None)
Beispiel #9
0
def test_fm11():
    gmice = FM11()

    mi, dmda = gmice.getMIfromGM(amps_in, PGA(), dists=None, mag=None)
    mi_target = np.array(
        [4.238506, 5.469479, 6.818506, 7.595163, 8.049479, 8.371821, 8.621849])
    np.testing.assert_allclose(mi, mi_target)
    assert ((set(dmda) - dmda_target[PGA()]) == set())

    mi, dmda = gmice.getMIfromGM(amps_in + np.log(100),
                                 PGV(),
                                 dists=dists,
                                 mag=None)
    mi_target = np.array(
        [5.11, 6.231235, 7.46, 8.16742, 8.581235, 8.874841, 9.10258])
    np.testing.assert_allclose(mi, mi_target)
    assert ((set(dmda) - dmda_target[PGV()]) == set())

    mi, dmda = gmice.getMIfromGM(amps_in, SA(0.3), dists=None, mag=3.0)
    mi_target = np.array([
        3.68942245, 4.86791195, 6.15942245, 6.90296654, 7.33791195, 7.64651063,
        7.88587836
    ])
    np.testing.assert_allclose(mi, mi_target)
    assert ((set(dmda) - dmda_target[SA(0.3)]) == set())

    mi, dmda = gmice.getMIfromGM(amps_in, SA(1.0), dists=dists, mag=7.5)
    mi_target = np.array(
        [5.152921, 6.13102, 7.202921, 7.820033, 8.18102, 8.437144, 8.63581])
    np.testing.assert_allclose(mi, mi_target)
    assert ((set(dmda) - dmda_target[SA(1.0)]) == set())

    mi, dmda = gmice.getMIfromGM(amps_in, SA(3.0), dists=None, mag=None)
    mi_target = np.array(
        [6.293338, 7.247581, 8.293338, 8.895398, 9.247581, 9.497458, 9.691278])
    np.testing.assert_allclose(mi, mi_target)
    assert ((set(dmda) - dmda_target[SA(3.0)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, PGA(), dists=None, mag=7.0)
    amps_target = np.array([
        -6.60298051, -5.71050567, -4.81803083, -3.92555598, -2.85458617,
        -1.87286385, -1.15888397
    ])
    np.testing.assert_allclose(amps, amps_target)
    assert ((set(dadm) - dadm_target[PGA()]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, PGV(), dists=dists, mag=None)
    amps_target = np.array([
        -3.04725091, -2.06742747, -1.08760402, -0.10778058, 1.06800755,
        2.14581334, 2.9296721
    ])
    np.testing.assert_allclose(amps, amps_target)
    assert ((set(dadm) - dadm_target[PGV()]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(0.3), dists=None, mag=6.0)
    amps_target = np.array([
        -6.18008474, -5.24786405, -4.31564337, -3.38342268, -2.26475786,
        -1.23931511, -0.49353856
    ])
    np.testing.assert_allclose(amps, amps_target)
    assert ((set(dadm) - dadm_target[SA(0.3)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(1.0), dists=dists, mag=8.0)
    amps_target = np.array([
        -8.14657017, -7.02335793, -5.90014569, -4.77693345, -3.42907876,
        -2.19354529, -1.2949755
    ])
    assert ((set(dadm) - dadm_target[SA(1.0)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, SA(3.0), dists=None, mag=5.0)
    amps_target = np.array([
        -9.54805824, -8.3967657, -7.24547315, -6.0941806, -4.71262955,
        -3.44620775, -2.52517371
    ])
    np.testing.assert_allclose(amps, amps_target)
    np.testing.assert_allclose(amps, amps_target)
    assert ((set(dadm) - dadm_target[SA(3.0)]) == set())

    amps, dadm = gmice.getGMfromMI(mmi_in, PGA(), dists=None, mag=7.0)
    amps_target = np.array([
        -6.60298051, -5.71050567, -4.81803083, -3.92555598, -2.85458617,
        -1.87286385, -1.15888397
    ])
    np.testing.assert_allclose(amps, amps_target)
    assert ((set(dadm) - dadm_target[PGA()]) == set())

    sdd1 = gmice.getGM2MIsd()
    assert sdd1[PGA()] == 0.18
    assert sdd1[PGV()] == 0.14
    assert sdd1[SA(0.3)] == 0.3
    assert sdd1[SA(1.0)] == 0.21
    assert sdd1[SA(3.0)] == 0.14

    sdd2 = gmice.getMI2GMsd()
    np.testing.assert_allclose(sdd2[PGA()], 0.7138013788281542)
    np.testing.assert_allclose(sdd2[PGV()], 0.5065687204586901)
    np.testing.assert_allclose(sdd2[SA(0.3)], 0.9670857390574993)
    np.testing.assert_allclose(sdd2[SA(1.0)], 0.7138013788281542)
    np.testing.assert_allclose(sdd2[SA(3.0)], 0.598672124178452)

    nm = gmice.getName()
    assert nm == 'Faenza and Michelini (2010, 2011)'

    sc = gmice.getScale()
    assert sc == 'scale_fm11.ps'

    mm = gmice.getMinMax()
    assert mm == (1.0, 10.0)

    dt = gmice.getDistanceType()
    assert dt == 'rrup'

    #
    # This should fail
    #
    with pytest.raises(ValueError):  # noqa
        mi, dmda = gmice.getMIfromGM(amps_in, MMI(), dists=None, mag=None)