def test_from_total_moment_rate(self):
        mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(
            min_mag=5.0,
            b_val=0.85,
            char_mag=6.75,
            total_moment_rate=6.38119198365e15,
            bin_width=0.1)
        computed_rates = mfd.get_annual_occurrence_rates()
        expected_rates = [(5.05, 0.00017054956240777723),
                          (5.15, 0.00014023312414148282),
                          (5.25, 0.00011530565560445073),
                          (5.35, 9.480922781808791e-05),
                          (5.45, 7.795619072057948e-05),
                          (5.55, 6.409890483786924e-05),
                          (5.65, 5.27048533725948e-05),
                          (5.75, 4.333617830215377e-05),
                          (5.85, 3.5632854085742086e-05),
                          (5.95, 2.9298852368637887e-05),
                          (6.05, 2.4090766011996856e-05),
                          (6.15, 1.9808455284958928e-05),
                          (6.25, 1.6287356764862893e-05),
                          (6.35, 1.3392159386974224e-05),
                          (6.45, 1.1011604622859124e-05),
                          (6.55, 7.057610011964502e-05),
                          (6.65, 7.057610011964502e-05),
                          (6.75, 7.057610011964502e-05),
                          (6.85, 7.057610011964502e-05),
                          (6.95, 7.057610011964502e-05)]
        numpy.testing.assert_allclose(computed_rates, expected_rates)

        self.assertEqual((5.05, 6.95), mfd.get_min_max_mag())
    def test_from_characteristic_rate(self):
        mfd = YoungsCoppersmith1985MFD.from_characteristic_rate(
            min_mag=5.0,
            b_val=0.85,
            char_mag=6.75,
            char_rate=0.000125,
            bin_width=0.1)
        computed_rates = mfd.get_annual_occurrence_rates()
        expected_rates = [(5.05, 6.041335597980433e-05),
                          (5.15, 4.967443791302958e-05),
                          (5.25, 4.084444146424117e-05),
                          (5.35, 3.358404178516568e-05),
                          (5.45, 2.7614231513367556e-05),
                          (5.55, 2.270559889580352e-05),
                          (5.65, 1.8669511804720695e-05),
                          (5.75, 1.535086885953161e-05),
                          (5.85, 1.2622139090051389e-05),
                          (5.95, 1.0378461093404372e-05),
                          (6.05, 8.533613351813384e-06),
                          (6.15, 7.016700856018683e-06),
                          (6.25, 5.7694307057387526e-06),
                          (6.35, 4.74387199217263e-06),
                          (6.45, 3.900613877853681e-06), (6.55, 2.5e-05),
                          (6.65, 2.5e-05), (6.75, 2.5e-05), (6.85, 2.5e-05),
                          (6.95, 2.5e-05)]
        numpy.testing.assert_allclose(computed_rates, expected_rates)

        self.assertEqual((5.05, 6.95), mfd.get_min_max_mag())
    def test_from_characteristic_rate(self):
        mfd = YoungsCoppersmith1985MFD.from_characteristic_rate(
            min_mag=5.0, b_val=0.85, char_mag=6.75,
            char_rate=0.000125, bin_width=0.1
        )
        computed_rates = mfd.get_annual_occurrence_rates()
        expected_rates = [(5.05, 6.041335597980433e-05),
                          (5.15, 4.967443791302958e-05),
                          (5.25, 4.084444146424117e-05),
                          (5.35, 3.358404178516568e-05),
                          (5.45, 2.7614231513367556e-05),
                          (5.55, 2.270559889580352e-05),
                          (5.65, 1.8669511804720695e-05),
                          (5.75, 1.535086885953161e-05),
                          (5.85, 1.2622139090051389e-05),
                          (5.95, 1.0378461093404372e-05),
                          (6.05, 8.533613351813384e-06),
                          (6.15, 7.016700856018683e-06),
                          (6.25, 5.7694307057387526e-06),
                          (6.35, 4.74387199217263e-06),
                          (6.45, 3.900613877853681e-06),
                          (6.55, 2.5e-05),
                          (6.65, 2.5e-05),
                          (6.75, 2.5e-05),
                          (6.85, 2.5e-05),
                          (6.95, 2.5e-05)]
        numpy.testing.assert_allclose(computed_rates, expected_rates)

        self.assertEqual((5.05, 6.95), mfd.get_min_max_mag())
    def test_from_total_moment_rate(self):
        mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(
            min_mag=5.0, b_val=0.85, char_mag=6.75,
            total_moment_rate=6.38119198365e15, bin_width=0.1
        )
        computed_rates = mfd.get_annual_occurrence_rates()
        expected_rates = [(5.05, 0.00017054956240777723),
                          (5.15, 0.00014023312414148282),
                          (5.25, 0.00011530565560445073),
                          (5.35, 9.480922781808791e-05),
                          (5.45, 7.795619072057948e-05),
                          (5.55, 6.409890483786924e-05),
                          (5.65, 5.27048533725948e-05),
                          (5.75, 4.333617830215377e-05),
                          (5.85, 3.5632854085742086e-05),
                          (5.95, 2.9298852368637887e-05),
                          (6.05, 2.4090766011996856e-05),
                          (6.15, 1.9808455284958928e-05),
                          (6.25, 1.6287356764862893e-05),
                          (6.35, 1.3392159386974224e-05),
                          (6.45, 1.1011604622859124e-05),
                          (6.55, 7.057610011964502e-05),
                          (6.65, 7.057610011964502e-05),
                          (6.75, 7.057610011964502e-05),
                          (6.85, 7.057610011964502e-05),
                          (6.95, 7.057610011964502e-05)]
        numpy.testing.assert_allclose(computed_rates, expected_rates)

        self.assertEqual((5.05, 6.95), mfd.get_min_max_mag())
示例#5
0
def YC_moment_rates(characteristic_mag, b_value, min_mag, moment_rate,
                    bin_width):
    """
    Generate Youngs and Coppersmith MFD using OpenQuake, then convert
    to incrementalMFD type. This allows us to balance the seismic moment to 
    be exactly equal to the total moment rate. We do this assuming the GR
    part of the YC distribution starts at magnitude 0.01.
    """

    mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(
        min_mag=0.01,
        b_val=float(b_value),
        char_mag=characteristic_mag,
        total_moment_rate=moment_rate,
        bin_width=float(bin_width))
    mags, rates = zip(*mfd.get_annual_occurrence_rates())
    #print mags, rates
    # calcualate total moment rate and rescale rates if
    # necessary to meet total input rate
    total_moment_rate = 0
    for i in range(len(mags)):
        moment = np.power(10, (1.5 * mags[i] + 16.05))
        moment = moment / 1e7  #Nm
        inc_moment_rate = moment * rates[i]
        total_moment_rate += inc_moment_rate
    moment_error = (total_moment_rate - moment_rate) / moment_rate
    initial_moment_error = moment_error
    print 'Input moment rate ', moment_rate
    print 'MFD moment rate', total_moment_rate
    print 'Relative moment rate error', moment_error

    # Rescale rates
    #    print rates
    rates = rates / (1 + moment_error)
    #    print rates
    # check rates sum as expected
    total_moment_rate = 0
    for i in range(len(mags)):
        moment = np.power(10, (1.5 * mags[i] + 16.05))
        moment = moment / 1e7  #Nm
        inc_moment_rate = moment * rates[i]
        total_moment_rate += inc_moment_rate
    moment_error = (total_moment_rate - moment_rate) / moment_rate
    print 'Final moment rate error after rescaling', moment_error

    # Now trim the distribution to just above min_mag
    #    print mags, rates
    mags = np.array(mags)
    rates = rates[np.where(mags >= float(min_mag))]
    mags = mags[np.where(mags >= float(min_mag))]
    return initial_moment_error
示例#6
0
def momentrate2YC_incremental(characteristic_mag, b_value, min_mag, max_mag,
                              moment_rate, bin_width):
    """Converts a moment rate and b-value into a Youngs &
    Coppersmith 1985 characteristic distribution, 
    then converts this to an OpenQuake incremental MFD
    (to facilitate collapsing of rates with other MFDs)
    """
    mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(
        min_mag=0.01,
        b_val=float(b_value),
        char_mag=characteristic_mag,
        total_moment_rate=moment_rate,
        bin_width=float(bin_width))

    mags, rates = zip(*mfd.get_annual_occurrence_rates())
    # calcualate total moment rate and rescale rates if
    # necessary to meet total input rate
    total_moment_rate = 0
    for i in range(len(mags)):
        moment = np.power(10, (1.5 * mags[i] + 16.05))
        moment = moment / 1e7  #Nm
        inc_moment_rate = moment * rates[i]
        total_moment_rate += inc_moment_rate
    moment_error = (total_moment_rate - moment_rate) / moment_rate
    print 'Relative moment rate error', moment_error
    # Rescale rates
    rates = rates / (1 + moment_error)
    # Check rates sum as expected
    total_moment_rate = 0
    for i in range(len(mags)):
        moment = np.power(10, (1.5 * mags[i] + 16.05))
        moment = moment / 1e7  #Nm
        inc_moment_rate = moment * rates[i]
        total_moment_rate += inc_moment_rate
    moment_error = (total_moment_rate - moment_rate) / moment_rate
    print 'Final moment rate error', moment_error

    # Now trim the distribution to just above min_mag
    mags = np.array(mags)
    rates = rates[np.where(mags >= float(min_mag))]
    mags = mags[np.where(mags >= float(min_mag))]
    return mags, rates
示例#7
0
    def test_from_total_moment_rate(self):
        total_moment_rate = 6.38119198365e15
        mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(
            min_mag=5.0,
            b_val=0.85,
            char_mag=6.75,
            total_moment_rate=total_moment_rate,
            bin_width=0.1)
        computed_rates = mfd.get_annual_occurrence_rates()

        expected_rates = [(5.05, 0.00017254493595137864),
                          (5.15, 0.000141873805371608),
                          (5.25, 0.00011665469368682727),
                          (5.35, 9.591846446582074e-05),
                          (5.45, 7.88682524012297e-05),
                          (5.55, 6.484884085108228e-05),
                          (5.65, 5.3321482747389806e-05),
                          (5.75, 4.384319727332041e-05),
                          (5.85, 3.6049746708167595e-05),
                          (5.95, 2.9641639263244427e-05),
                          (6.05, 2.4372620016585263e-05),
                          (6.15, 2.004020766858989e-05),
                          (6.25, 1.647791345891117e-05),
                          (6.35, 1.3548843228053625e-05),
                          (6.45, 1.1140436759552141e-05),
                          (6.55, 7.140181717808345e-05),
                          (6.65, 7.140181717808345e-05),
                          (6.75, 7.140181717808345e-05),
                          (6.85, 7.140181717808345e-05),
                          (6.95, 7.140181717808345e-05)]

        computed_total_moment_rate = sum(
            [rate * 10.**(1.5 * mag + 9.05) for (mag, rate) in computed_rates])

        numpy.testing.assert_allclose(computed_rates, expected_rates)
        numpy.testing.assert_almost_equal(computed_total_moment_rate,
                                          total_moment_rate)

        self.assertEqual((5.05, 6.95), mfd.get_min_max_mag())
def append_earthquake_information_inc(output_xml, magnitude_scaling_relation,
                                  rupture_aspect_ratio, characteristic_mag, b_value,
                                  min_mag, max_mag, rake, moment_rate, bin_width):
    """
    Generate Youngs and Coppersmith MFD using OpenQuake, then convert
    to incrementalMFD type. This allows us to balance the seismic moment to 
    be exactly equal to the total moment rate. We do this assuming the GR
    part of the YC distribution starts at magnitude 0.05.
    """

    mfd = YoungsCoppersmith1985MFD.from_total_moment_rate(min_mag=0.01,
                                                          b_val=float(b_value),
                                                          char_mag=characteristic_mag, 
                                                          total_moment_rate=moment_rate,
                                                          bin_width=float(bin_width))
    mags,rates=zip(*mfd.get_annual_occurrence_rates())
    #print mags, rates
    # calcualate total moment rate and rescale rates if
    # necessary to meet total input rate
    total_moment_rate = 0
    for i in range(len(mags)):
        moment = np.power(10, (1.5*mags[i]+16.05))
        moment = moment/1e7 #Nm
        inc_moment_rate = moment*rates[i]
        total_moment_rate += inc_moment_rate
    moment_error = (total_moment_rate - moment_rate)/moment_rate
    print 'Relative moment rate error', moment_error

    # Rescale rates
#    print rates
    rates = rates/(1+moment_error)
#    print rates
    # check rates sum as expected
    total_moment_rate = 0
    for i in range(len(mags)):
        moment = np.power(10, (1.5*mags[i]+16.05))
        moment = moment/1e7 #Nm
        inc_moment_rate = moment*rates[i]
        total_moment_rate += inc_moment_rate
    moment_error = (total_moment_rate - moment_rate)/moment_rate
    print 'Final moment rate error',  moment_error

    # Now trim the distribution to just above min_mag
    #print mags, rates
    mags = np.array(mags)
    rates = rates[np.where(mags >= float(min_mag))]
    mags = mags[np.where(mags >= float(min_mag))]
    print mags, rates
#    if float(min_mag) != mags[0]:
#        print 'Modelled min magnitude %.2f not equal to '\
#            'input minimum magnitude %s' % (mags[0], min_mag)
   # print mags, rates

    output_xml.append('      <magScaleRel>' +
                      str(magnitude_scaling_relation) + '</magScaleRel>')
  #  output_xml.append('')

    output_xml.append(
        '      <ruptAspectRatio>' + str(rupture_aspect_ratio) + '</ruptAspectRatio>')
 #   output_xml.append('')

    output_xml.append('      <incrementalMFD minMag="' +
                      str(min_mag) + '" binWidth="' + str(bin_width) + '">')
    output_xml.append('          <occurRates>' + ' '.join(str(rt) for rt in rates ) +
                      '</occurRates>')
    output_xml.append('      </incrementalMFD>')
                     
                      
#    output_xml.append('')

    output_xml.append('      <rake>' + str(rake) + '</rake>')
    output_xml.append('    </simpleFaultSource>')

    return