def test_Multiple_ground_motion_calculatorI(self):
        """
        This checks that for the given test_distance and test_magnitudes,
        the calculated ground motion is the same as the test_ground_motion
        """

        model_name2 = 'Youngs_97_interface'
        (distances, distance_types, magnitudes, test_mean,
         test_sigma, periods, depths, _, _, _, _, _, _) = data2atts(
            model_name2)

        model_names = [model_name2]
        model_weights = array([1.0])
        gm = Multiple_ground_motion_calculator(model_names, periods,
                                               model_weights)

        log_mean, log_sigma = gm._distribution_function(distances,
                                                        magnitudes,
                                                        depth=depths)

        mean_out = []
        for i in range(len(distances.distance(None))):
            mean_out.append([test_mean[i][0]])
        # print "exp(log_mean)", exp(log_mean).shape
        # print "exp(log_mean)", exp(log_mean)
        mean_out = asarray(mean_out).reshape(1, 3, 1, 12)
        # print "mean_out", mean_out.shape
        # print "mean_out", mean_out
        self.assert_(allclose(exp(log_mean), mean_out, rtol=0.05), "Fail")
Esempio n. 2
0
    def test_Multiple_ground_motion_calculatorI(self):
        """
        This checks that for the given test_distance and test_magnitudes,
        the calculated ground motion is the same as the test_ground_motion
        """

        model_name2 = 'Youngs_97_interface'
        (distances, distance_types, magnitudes, test_mean, test_sigma, periods,
         depths, _, _, _, _, _, _) = data2atts(model_name2)

        model_names = [model_name2]
        model_weights = array([1.0])
        gm = Multiple_ground_motion_calculator(model_names, periods,
                                               model_weights)

        log_mean, log_sigma = gm._distribution_function(distances,
                                                        magnitudes,
                                                        depth=depths)

        mean_out = []
        for i in range(len(distances.distance(None))):
            mean_out.append([test_mean[i][0]])
        # print "exp(log_mean)", exp(log_mean).shape
        # print "exp(log_mean)", exp(log_mean)
        mean_out = asarray(mean_out).reshape(1, 3, 1, 12)
        # print "mean_out", mean_out.shape
        # print "mean_out", mean_out
        self.assert_(allclose(exp(log_mean), mean_out, rtol=0.05), "Fail")
Esempio n. 3
0
 def set_ground_motion_calcs(self, periods):
     """
     """
     self.ground_motion_calculator = Multiple_ground_motion_calculator(
         self.atten_models,
         periods,
         self.atten_model_weights)
Esempio n. 4
0
    def test_multiple_GM(self):
        # test that multiple ground motion model results
        # are returned with the right dimensions

        model_1 = 'mean_10_sigma_1'
        model_2 = 'mean_10_sigma_1'

        num_sites = 2
        num_events = 3
        num_periods = 4

        periods = [0.0, 0.3, 1, 1.2]
        model_weights = [0.5, 0.5]
        gm = Multiple_ground_motion_calculator([model_1, model_2], periods,
                                               model_weights)

        # a fake dist_object class
        class ADistObj(object):
            def __init__(self, distance):
                self.the_distance = distance

            def Rupture(self):
                return self.the_distance

            def distance(self, dist_type):
                return self.the_distance

        # The extra dimension will be added by reshaping.
        distance = zeros((num_sites, num_events))
        dist_ob = ADistObj(distance)
        magnitudes = {
            'Mw': array([3.0, 2.0, 1.5]),
            'ML': array([3.0, 2.0, 1.5])
        }
        log_mean_array, log_sigma_array = gm._distribution_function(
            dist_object=dist_ob, mag_dict=magnitudes)

        # When combining multiple GM's on the event axis
        self.assert_(log_mean_array.shape == (2, num_sites, num_events,
                                              num_periods))
        self.assert_(log_sigma_array.shape == (2, num_sites, num_events,
                                               num_periods))
    def test_multiple_GM(self):
        # test that multiple ground motion model results
        # are returned with the right dimensions

        model_1 = 'mean_10_sigma_1'
        model_2 = 'mean_10_sigma_1'

        num_sites = 2
        num_events = 3
        num_periods = 4

        periods = [0.0, 0.3, 1, 1.2]
        model_weights = [0.5, 0.5]
        gm = Multiple_ground_motion_calculator(
            [model_1, model_2], periods, model_weights)

        # a fake dist_object class
        class ADistObj(object):

            def __init__(self, distance):
                self.the_distance = distance

            def Rupture(self):
                return self.the_distance

            def distance(self, dist_type):
                return self.the_distance

        # The extra dimension will be added by reshaping.
        distance = zeros((num_sites, num_events))
        dist_ob = ADistObj(distance)
        magnitudes = {'Mw': array([3.0, 2.0, 1.5]),
                      'ML': array([3.0, 2.0, 1.5])}
        log_mean_array, log_sigma_array = gm._distribution_function(
            dist_object=dist_ob,
            mag_dict=magnitudes)

        # When combining multiple GM's on the event axis
        self.assert_(log_mean_array.shape == (
            2, num_sites, num_events, num_periods))
        self.assert_(log_sigma_array.shape == (
            2, num_sites, num_events, num_periods))
Esempio n. 6
0
    def test_mult_gm(self):
        """
        This checks that for the given test_distance and test_magnitudes,
        the calculated ground motion is the same as the test_ground_motion
        """

        model_name = 'Toro_1997_midcontinent'

        (distances, distance_types, magnitudes, test_mean, test_sigma, periods,
         depths, _, _, _, _, _, _) = data2atts(model_name)
        model_weights = [1]
        gm = Multiple_ground_motion_calculator([model_name], periods,
                                               model_weights)

        # ignoring event_activity
        log_mean, log_sigma = gm._distribution_function(distances,
                                                        magnitudes,
                                                        depth=depths)

        self.assert_(allclose(exp(log_mean), test_mean, rtol=0.05),
                     "%s did not pass assert" % model_name)
    def test_mult_gm(self):
        """
        This checks that for the given test_distance and test_magnitudes,
        the calculated ground motion is the same as the test_ground_motion
        """

        model_name = 'Toro_1997_midcontinent'

        (distances, distance_types, magnitudes, test_mean,
         test_sigma, periods, depths, _, _, _, _, _, _) = data2atts(model_name)
        model_weights = [1]
        gm = Multiple_ground_motion_calculator([model_name], periods,
                                               model_weights)

        # ignoring event_activity
        log_mean, log_sigma = gm._distribution_function(distances,
                                                        magnitudes,
                                                        depth=depths)

        self.assert_(allclose(exp(log_mean), test_mean, rtol=0.05),
                     "%s did not pass assert" % model_name)
    def test_Multiple_ground_motion_calculatorII(self):
        """
        This checks that for the given test_distance and test_magnitudes,
        the calculated ground motion is the same as the test_ground_motion
        """

        model_name = 'Combo_Sadigh_Youngs_M8_trimmed'
        (distances, distance_types, magnitudes, test_mean,
         test_sigma, periods, depths, _, _, _, _, _, _) = data2atts(model_name)

        model_name2 = 'Youngs_97_interface'
        (dist2, distance_types2, mag2, test_mean2,
         test_sigma2, periods2, depths2, _, _, _, _, _, _) = data2atts(
            model_name2)

        self.assert_(allclose(distances.distance(None), dist2.distance(None)))
        self.assert_(magnitudes == mag2)
        self.assert_(periods == periods2)
        self.assert_(depths == depths2)

        model_name = 'Combo_Sadigh_Youngs_M8'

        model_names = [model_name, model_name2]
        model_weights = array([0.1, 0.9])
        gm = Multiple_ground_motion_calculator(model_names, periods,
                                               model_weights)

        log_mean, log_sigma = gm._distribution_function(distances,
                                                        magnitudes,
                                                        depth=depths)

        mean_out = []
        for i in range(len(distances.distance(None))):
            mean_out.append([test_mean[i][0], test_mean2[i][0]])
        # print "exp(log_mean)", exp(log_mean).shape
        # print "exp(log_mean)", exp(log_mean)
        mean_out = asarray(mean_out).reshape(2, 3, 1, 12)
Esempio n. 9
0
    def test_Multiple_ground_motion_calculatorII(self):
        """
        This checks that for the given test_distance and test_magnitudes,
        the calculated ground motion is the same as the test_ground_motion
        """

        model_name = 'Combo_Sadigh_Youngs_M8_trimmed'
        (distances, distance_types, magnitudes, test_mean, test_sigma, periods,
         depths, _, _, _, _, _, _) = data2atts(model_name)

        model_name2 = 'Youngs_97_interface'
        (dist2, distance_types2, mag2, test_mean2, test_sigma2, periods2,
         depths2, _, _, _, _, _, _) = data2atts(model_name2)

        self.assert_(allclose(distances.distance(None), dist2.distance(None)))
        self.assert_(magnitudes == mag2)
        self.assert_(periods == periods2)
        self.assert_(depths == depths2)

        model_name = 'Combo_Sadigh_Youngs_M8'

        model_names = [model_name, model_name2]
        model_weights = array([0.1, 0.9])
        gm = Multiple_ground_motion_calculator(model_names, periods,
                                               model_weights)

        log_mean, log_sigma = gm._distribution_function(distances,
                                                        magnitudes,
                                                        depth=depths)

        mean_out = []
        for i in range(len(distances.distance(None))):
            mean_out.append([test_mean[i][0], test_mean2[i][0]])
        # print "exp(log_mean)", exp(log_mean).shape
        # print "exp(log_mean)", exp(log_mean)
        mean_out = asarray(mean_out).reshape(2, 3, 1, 12)