Beispiel #1
0
    def test_get_mean_std(self):
        """ Check calculation of mean and stds """

        stds_types = [
            const.StdDev.TOTAL, const.StdDev.INTER_EVENT,
            const.StdDev.INTRA_EVENT
        ]

        gmpe_name = 'AkkarEtAlRjb2014'
        gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                             set_between_epsilon={'epsilon_tau': 0.5})
        mean, stds = gmm.get_mean_and_stddevs(self.sites, self.rup, self.dists,
                                              self.imt, stds_types)

        gmpe = registry[gmpe_name]()
        emean, estds = gmpe.get_mean_and_stddevs(self.sites, self.rup,
                                                 self.dists, self.imt,
                                                 stds_types)
        idx = stds_types.index(const.StdDev.INTER_EVENT)
        exp_mean = emean + estds[idx] * 0.5

        # Check the computed mean + between event variability
        np.testing.assert_almost_equal(mean, exp_mean)

        # Check that the total std now corresponds to the within event
        # standard deviation
        np.testing.assert_almost_equal(stds[0], estds[2])
Beispiel #2
0
    def test_set_between_epsilon_raises_error(self):
        """ Check that error is raised for GMPEs with only total std """

        stds_types = [const.StdDev.TOTAL]
        gmm = ModifiableGMPE(gmpe={'Campbell2003': {}},
                             set_between_epsilon={'epsilon_tau': 0.5})
        with self.assertRaises(ValueError):
            _, _ = gmm.get_mean_and_stddevs(self.sites, self.rup, self.dists,
                                            self.imt, stds_types)
Beispiel #3
0
    def test_set_total_std_as_tau_plus_phi(self):
        """Check set total std as between plus phi SS"""
        gmpe_name = 'AkkarEtAlRjb2014'
        stddevs = [const.StdDev.TOTAL]

        gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                             set_total_std_as_tau_plus_delta={"delta": 0.45})
        imt = PGA()
        [stddev] = gmm.get_mean_and_stddevs(self.sites, self.rup, self.dists,
                                            imt, stddevs)[1]

        # Original tau for PGA is 0.6201
        np.testing.assert_almost_equal(stddev[0], 0.5701491121, decimal=6)
Beispiel #4
0
    def test_add_delta(self):
        """Check adding/removing a delta std to the total std"""
        gmpe_name = 'AkkarEtAlRjb2014'
        stddevs = [const.StdDev.TOTAL]

        gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                             add_delta_std_to_total_std={"delta": -0.20})
        imt = PGA()
        [stddev] = gmm.get_mean_and_stddevs(self.sites, self.rup, self.dists,
                                            imt, stddevs)[1]

        # Original total std for PGA is 0.7121
        np.testing.assert_almost_equal(stddev[0], 0.68344277, decimal=6)
 def test_add_between_within_sigma(self):
     """ Checks that the modified GMM has between and within std """
     stds_types = [
         const.StdDev.TOTAL, const.StdDev.INTRA_EVENT,
         const.StdDev.INTER_EVENT
     ]
     gmm = ModifiableGMPE(gmpe={'Campbell2003': {}},
                          add_between_within_stds={'with_betw_ratio': 0.6})
     out = gmm.get_mean_and_stddevs(self.ctx, self.ctx, self.ctx, self.imt,
                                    stds_types)
     expected_with = np.ones(4) * 0.24381161
     expected_betw = np.ones(4) * 0.40635268
     aae = np.testing.assert_array_almost_equal
     aae(expected_betw, out[1][2])
     aae(expected_with, out[1][1])
Beispiel #6
0
    def test_fixed_total_sigma(self):
        """Check the assignment of total sigma to a fixed value"""
        gmpe_name = 'AkkarEtAlRjb2014'
        stddevs = [const.StdDev.TOTAL]
        gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                             set_fixed_total_sigma={
                                 "total_sigma": {
                                     "PGA": 0.6,
                                     "SA(0.2)": 0.75
                                 }
                             })

        for imt, sfact in zip([PGA(), SA(0.2)], [0.6, 0.75]):
            [stddev] = gmm.get_mean_and_stddevs(self.sites, self.rup,
                                                self.dists, imt, stddevs)[1]
            np.testing.assert_almost_equal(stddev,
                                           sfact * np.ones(stddev.shape))
Beispiel #7
0
 def test_coefficients_as_dictionary(self):
     """Check the parsing of the coefficients to a dictionary"""
     input_coeffs = {"PGA": 1.0, "SA(0.2)": 2.0, "SA(3.0)": 3.0}
     output_coeffs = ModifiableGMPE._dict_to_coeffs_table(
         input_coeffs, "XYZ")
     self.assertListEqual(list(output_coeffs), ["XYZ"])
     self.assertIsInstance(output_coeffs["XYZ"], CoeffsTable)
     self.assertAlmostEqual(output_coeffs["XYZ"][PGA()]["XYZ"], 1.0)
     self.assertAlmostEqual(output_coeffs["XYZ"][SA(0.2)]["XYZ"], 2.0)
     self.assertAlmostEqual(output_coeffs["XYZ"][SA(3.0)]["XYZ"], 3.0)
    def test_get_mean_std(self):
        """ Check calculation of amplified mean"""

        for gmpe_name in [
                'ECOS2009', 'BindiEtAl2011RepiFixedH',
                'BaumontEtAl2018High2210IAVGDC30n7', 'FaccioliCauzzi2006'
        ]:

            stds_types = [const.StdDev.TOTAL]
            gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                                 apply_swiss_amplification={})
            mean, stds = gmm.get_mean_and_stddevs(self.ctx, self.ctx, self.ctx,
                                                  self.imt, stds_types)

            gmpe = registry[gmpe_name]()
            emean, estds = gmpe.get_mean_and_stddevs(self.ctx, self.ctx,
                                                     self.ctx, self.imt,
                                                     stds_types)

            exp_mean = emean + np.array([-1.00, 1.50, 0, -1.99])

            # Check the computed mean + amplification
            np.testing.assert_almost_equal(mean, exp_mean)
Beispiel #9
0
 def test_scale_median_scalar(self):
     """Check the scaling of the median ground motion - scalar"""
     gmpe_name = 'AkkarEtAlRjb2014'
     stddevs = [const.StdDev.TOTAL]
     gmm_unscaled = ModifiableGMPE(gmpe={gmpe_name: {}})
     gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                          set_scale_median_scalar={'scaling_factor': 1.2})
     mean_unscaled = gmm_unscaled.get_mean_and_stddevs(
         self.sites, self.rup, self.dists, self.imt, stddevs)[0]
     mean = gmm.get_mean_and_stddevs(self.sites, self.rup, self.dists,
                                     self.imt, stddevs)[0]
     np.testing.assert_almost_equal(
         np.exp(mean) / np.exp(mean_unscaled), 1.2 * np.ones(mean.shape))
 def test_scale_total_sigma_scalar(self):
     """Check the scaling of the total stddev - scalar"""
     gmpe_name = 'AkkarEtAlRjb2014'
     stddevs = [const.StdDev.TOTAL]
     gmm_unscaled = ModifiableGMPE(gmpe={gmpe_name: {}})
     gmm = ModifiableGMPE(
         gmpe={gmpe_name: {}},
         set_scale_total_sigma_scalar={"scaling_factor": 1.2})
     [stddev_unscaled
      ] = gmm_unscaled.get_mean_and_stddevs(self.ctx, self.ctx, self.ctx,
                                            self.imt, stddevs)[1]
     [stddev] = gmm.get_mean_and_stddevs(self.ctx, self.ctx, self.ctx,
                                         self.imt, stddevs)[1]
     np.testing.assert_array_almost_equal(stddev / stddev_unscaled,
                                          1.2 * np.ones(stddev.shape))
Beispiel #11
0
 def test_scale_median_vector(self):
     """Check the scaling of the median ground motion - IMT-dependent"""
     gmpe_name = 'AkkarEtAlRjb2014'
     stddevs = [const.StdDev.TOTAL]
     gmm_unscaled = ModifiableGMPE(gmpe={gmpe_name: {}})
     gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                          set_scale_median_vector={
                              'scaling_factor': {
                                  "PGA": 0.9,
                                  "SA(0.2)": 1.1
                              }
                          })
     for imt, sfact in zip([PGA(), SA(0.2)], [0.9, 1.1]):
         mean_unscaled = gmm_unscaled.get_mean_and_stddevs(
             self.sites, self.rup, self.dists, imt, stddevs)[0]
         mean = gmm.get_mean_and_stddevs(self.sites, self.rup, self.dists,
                                         imt, stddevs)[0]
         np.testing.assert_almost_equal(
             np.exp(mean) / np.exp(mean_unscaled),
             sfact * np.ones(mean.shape))
Beispiel #12
0
    def test_scale_total_sigma_vector(self):
        """Check the scaling of the total stddev - vector"""
        gmpe_name = 'AkkarEtAlRjb2014'
        stddevs = [const.StdDev.TOTAL]
        gmm_unscaled = ModifiableGMPE(gmpe={gmpe_name: {}})
        gmm = ModifiableGMPE(gmpe={gmpe_name: {}},
                             set_scale_total_sigma_vector={
                                 "scaling_factor": {
                                     "PGA": 0.9,
                                     "SA(0.2)": 1.1
                                 }
                             })

        for imt, sfact in zip([PGA(), SA(0.2)], [0.9, 1.1]):
            [stddev_unscaled
             ] = gmm_unscaled.get_mean_and_stddevs(self.sites, self.rup,
                                                   self.dists, imt, stddevs)[1]
            [stddev] = gmm.get_mean_and_stddevs(self.sites, self.rup,
                                                self.dists, imt, stddevs)[1]
            np.testing.assert_almost_equal(stddev / stddev_unscaled,
                                           sfact * np.ones(stddev.shape))