Ejemplo n.º 1
0
    def test_multiple_GGmax_curve_get_curve_matrix(self):
        damping = 1.23  # choose a dummy value

        mgc = Multiple_GGmax_Curves('./files/curve_FKSH14.txt')
        curve = mgc.get_curve_matrix(damping_filler_value=damping)

        curve_benchmark = np.genfromtxt('./files/curve_FKSH14.txt')
        for j in range(curve_benchmark.shape[1]):
            if j % 4 == 3:  # original damping info is lost; use same dummy value
                curve_benchmark[:, j] = damping

        self.assertTrue(np.allclose(curve, curve_benchmark, rtol=1e-5, atol=0.0))
Ejemplo n.º 2
0
    def test_init(self):
        # This should pass
        vs_profile = Vs_Profile('./files/profile_FKSH14.txt')
        hh_c = HH_Calibration(vs_profile)

        # Type of vs_profile not correct
        with self.assertRaises(TypeError, msg='must be of type Vs_Profile'):
            HH_Calibration(np.array([1, 2, 3, 4, 5]))

        # This should pass
        curves = Multiple_GGmax_Curves('./files/curve_FKSH14.txt')
        hh_c = HH_Calibration(vs_profile, GGmax_curves=curves)

        # Type of curves not correct
        with self.assertRaises(TypeError,
                               msg='If `GGmax_curves` is not `None`,'
                               ' it must be of type Multiple_GGmax_Curves'):
            HH_Calibration(vs_profile, GGmax_curves=np.array([1, 2, 3]))

        # Length of curves not correct
        del curves[-1]  # remove the last layer
        with self.assertRaises(ValueError,
                               msg='The number of layers implied '
                               'in `GGmax_curves` and `vs_profile` must be'
                               ' the same.'):
            HH_Calibration(vs_profile, GGmax_curves=curves)

        # Type of Tmax not correct
        curves = Multiple_GGmax_Curves('./files/curve_FKSH14.txt')
        Tmax = [1, 2, 3, 4, 5]
        with self.assertRaises(TypeError,
                               msg='`Tmax_profile` must be a 1D '
                               'numpy array.'):
            HH_Calibration(vs_profile, GGmax_curves=curves, Tmax_profile=Tmax)

        # Length of Tmax not correct
        Tmax = np.array([1, 2, 3])
        with self.assertRaises(ValueError,
                               msg='The length of `Tmax_profile` '
                               'needs to equal'):
            HH_Calibration(vs_profile, GGmax_curves=curves, Tmax_profile=Tmax)

        # This should pass
        Tmax = np.array([1, 2, 3, 4, 5])
        hh_c = HH_Calibration(vs_profile,
                              GGmax_curves=curves,
                              Tmax_profile=Tmax)
        self.assertTrue(isinstance(hh_c.vs_profile, Vs_Profile))
        self.assertTrue(isinstance(hh_c.GGmax_curves, Multiple_GGmax_Curves))
        self.assertTrue(isinstance(hh_c.Tmax_profile, np.ndarray))
Ejemplo n.º 3
0
    def test_fit(self):
        # Case 1: users only have Vs profile
        vs_profile = Vs_Profile('./files/profile_FKSH14.txt')
        hh_c = HH_Calibration(vs_profile)
        HH_G_param = hh_c.fit(verbose=False)
        HH_G_param_benchmark = HH_Param_Multi_Layer('./files/HH_G_FKSH14.txt')
        self.assertTrue(
            np.allclose(HH_G_param.serialize_to_2D_array(),
                        HH_G_param_benchmark.serialize_to_2D_array(),
                        rtol=1e-5,
                        atol=0.0))

        # Case 2: users have both Vs profile and G/Gmax curves
        curves = Multiple_GGmax_Curves('./files/curve_FKSH14.txt')
        hh_c = HH_Calibration(vs_profile, GGmax_curves=curves)
        HH_G_param = hh_c.fit(verbose=False)
        HH_G_benchmark_data \
            = np.array([[0.0003, 0.0001, 0.0001, 0.0001, 0.0001],
                        [100, 100, 100, 100, 100],
                        [0.000285072, 0.000516205, 0.000944545, 0.00129825, 0.00144835],
                        [1.75224, 1.71444, 1.64057, 1.58664, 1.56314],
                        [0.918975, 0.919001, 0.918973, 0.919007, 0.918999],
                        [2.11104e+07, 6.859e+07, 1.4896e+08, 2.25441e+09, 3.28398e+09],
                        [0.233357, 0.199149, 0.253784, 1, 1],
                        [26501, 64856.6, 148805, 804855, 1.10785e+06],
                        [0.937739, 0.850905, 0.861759, 0.984774, 0.981156]])
        HH_G_param_benchmark = HH_Param_Multi_Layer(HH_G_benchmark_data)
        self.assertTrue(
            np.allclose(HH_G_param.serialize_to_2D_array(),
                        HH_G_param_benchmark.serialize_to_2D_array(),
                        rtol=1e-2,
                        atol=0.0))
 def test_init__incorrect_Tmax_length(self):
     vs_profile = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt'))
     curves = Multiple_GGmax_Curves(_join(f_dir, 'curve_FKSH14.txt'))
     Tmax = np.array([1, 2, 3])
     with self.assertRaisesRegex(
             ValueError, 'The length of `Tmax_profile` '
             'needs to equal'):
         HH_Calibration(vs_profile, GGmax_curves=curves, Tmax_profile=Tmax)
 def test_init__incorrect_Tmax_type(self):
     vs_profile = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt'))
     curves = Multiple_GGmax_Curves(_join(f_dir, 'curve_FKSH14.txt'))
     Tmax = [1, 2, 3, 4, 5]
     with self.assertRaisesRegex(
             TypeError, '`Tmax_profile` must be a 1D '
             'numpy array.'):
         HH_Calibration(vs_profile, GGmax_curves=curves, Tmax_profile=Tmax)
 def test_init__incorrect_length_of_curves(self):
     vs_profile = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt'))
     curves = Multiple_GGmax_Curves(_join(f_dir, 'curve_FKSH14.txt'))
     del curves[-1]  # remove the last layer
     with self.assertRaisesRegex(
             ValueError, 'The number of layers implied '
             'in `GGmax_curves` and `vs_profile` must be'
             ' the same.'):
         HH_Calibration(vs_profile, GGmax_curves=curves)
 def test_init__success_with_curves_and_Tmax(self):
     vs_profile = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt'))
     curves = Multiple_GGmax_Curves(_join(f_dir, 'curve_FKSH14.txt'))
     Tmax = np.array([1, 2, 3, 4, 5])
     hh_c = HH_Calibration(vs_profile,
                           GGmax_curves=curves,
                           Tmax_profile=Tmax)
     self.assertTrue(isinstance(hh_c.vs_profile, Vs_Profile))
     self.assertTrue(isinstance(hh_c.GGmax_curves, Multiple_GGmax_Curves))
     self.assertTrue(isinstance(hh_c.Tmax_profile, np.ndarray))
Ejemplo n.º 8
0
    def test_init_multiple_GGmax_damping_curves(self):
        # Case 1: with MGC and MDC
        mgc = Multiple_GGmax_Curves(_join(f_dir, 'curve_FKSH14.txt'))
        mdc = Multiple_Damping_Curves(_join(f_dir, 'curve_FKSH14.txt'))
        with self.assertRaisesRegex(ValueError, 'Both parameters are `None`'):
            Multiple_GGmax_Damping_Curves()
        with self.assertRaisesRegex(ValueError,
                                    'one and only one input parameter'):
            Multiple_GGmax_Damping_Curves(mgc_and_mdc=(mgc, mdc), data=2.6)
        with self.assertRaisesRegex(TypeError, 'needs to be of type'):
            Multiple_GGmax_Damping_Curves(mgc_and_mdc=(mdc, mgc))
        mgc_ = Multiple_GGmax_Curves(_join(f_dir, 'curve_FKSH14.txt'))
        del mgc_[-1]
        with self.assertRaisesRegex(ValueError, 'same number of soil layers'):
            Multiple_GGmax_Damping_Curves(mgc_and_mdc=(mgc_, mdc))

        mgdc = Multiple_GGmax_Damping_Curves(mgc_and_mdc=(mgc, mdc))
        matrix = mgdc.get_curve_matrix()
        benchmark = np.genfromtxt(_join(f_dir, 'curve_FKSH14.txt'))
        self.assertTrue(np.allclose(matrix, benchmark))

        # Case 2: with a numpy array
        array = np.genfromtxt(_join(f_dir, 'curve_FKSH14.txt'))
        array_ = np.column_stack((array, array[:, -1]))
        with self.assertRaisesRegex(ValueError, 'needs to be a multiple of 4'):
            Multiple_GGmax_Damping_Curves(data=array_)

        mgdc = Multiple_GGmax_Damping_Curves(data=array)
        mgc_, mdc_ = mgdc.get_MGC_MDC_objects()
        self.assertTrue(
            np.allclose(mgc_.get_curve_matrix(), mgc.get_curve_matrix()))
        self.assertTrue(
            np.allclose(mdc_.get_curve_matrix(), mdc.get_curve_matrix()))

        # Case 3: with a file name
        with self.assertRaisesRegex(TypeError,
                                    'must be a 2D numpy array or a file name'):
            Multiple_GGmax_Damping_Curves(data=3.5)
        mgdc = Multiple_GGmax_Damping_Curves(
            data=_join(f_dir, 'curve_FKSH14.txt'))
        mgc_, mdc_ = mgdc.get_MGC_MDC_objects()
        self.assertTrue(
            np.allclose(mgc_.get_curve_matrix(), mgc.get_curve_matrix()))
        self.assertTrue(
            np.allclose(mdc_.get_curve_matrix(), mdc.get_curve_matrix()))
 def test_init__success_with_vs_profile_and_curve(self):
     vs_profile = Vs_Profile(_join(f_dir, 'profile_FKSH14.txt'))
     curves = Multiple_GGmax_Curves(_join(f_dir, 'curve_FKSH14.txt'))
     hh_c = HH_Calibration(vs_profile, GGmax_curves=curves)