当前位置: 首页>>代码示例>>Python>>正文


Python Catalogue.get_depth_pmf方法代码示例

本文整理汇总了Python中openquake.hmtk.seismicity.catalogue.Catalogue.get_depth_pmf方法的典型用法代码示例。如果您正苦于以下问题:Python Catalogue.get_depth_pmf方法的具体用法?Python Catalogue.get_depth_pmf怎么用?Python Catalogue.get_depth_pmf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openquake.hmtk.seismicity.catalogue.Catalogue的用法示例。


在下文中一共展示了Catalogue.get_depth_pmf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestMagnitudeDepthDistribution

# 需要导入模块: from openquake.hmtk.seismicity.catalogue import Catalogue [as 别名]
# 或者: from openquake.hmtk.seismicity.catalogue.Catalogue import get_depth_pmf [as 别名]
class TestMagnitudeDepthDistribution(unittest.TestCase):
    """
    Tests the method for generating the magnitude depth distribution
    """
    def setUp(self):
        self.catalogue = Catalogue()
        x, y = np.meshgrid(np.arange(5., 50., 10.), np.arange(5.5, 9.0, 1.))
        nx, ny = np.shape(x)
        self.catalogue.data['depth'] = (x.reshape([nx * ny, 1])).flatten()
        self.catalogue.data['magnitude'] = (y.reshape([nx * ny, 1])).flatten()

    def test_depth_distribution_no_depth_error(self):
        # ensure error is raised when no depths are found in catalogue
        depth_bins = np.arange(0., 60., 10.)
        self.catalogue.data['depth'] = np.array([])
        with self.assertRaises(ValueError) as ae:
            self.catalogue.get_depth_distribution(depth_bins)
        self.assertEqual(str(ae.exception),
                         'Depths missing in catalogue')

    def test_distribution_no_uncertainties(self):
        # Tests the magnitude-depth distribution without uncertainties

        # Without normalisation
        depth_bins = np.arange(0., 60., 10.)
        mag_bins = np.arange(5., 10., 1.)
        expected_array = np.ones([len(mag_bins) - 1, len(depth_bins) - 1],
                                 dtype=float)
        np.testing.assert_array_almost_equal(
            expected_array,
            self.catalogue.get_magnitude_depth_distribution(mag_bins,
                                                            depth_bins))
        # With normalisation
        np.testing.assert_array_almost_equal(
            expected_array / np.sum(expected_array),
            self.catalogue.get_magnitude_depth_distribution(
                mag_bins, depth_bins, normalisation=True))

    def test_depth_to_pmf(self):
        # Tests the function to get depth pmf assuming a simple PMF can be
        # extracted
        self.catalogue.data["depth"] = np.array([2.5, 2.5, 7.5, 12.5, 12.5])
        self.catalogue.data["depthError"] = np.array([0.1, 0.1, 0.1, 0.1, 0.1])
        # Test case with good data
        depth_bins = np.array([0.0, 5.0, 10.0, 15.0])
        output_pmf = self.catalogue.get_depth_pmf(depth_bins)
        self.assertTrue(isinstance(output_pmf, PMF))
        expected_output = [(0.4, 2.5), (0.2, 7.5), (0.4, 12.5)]
        for iloc, (prob, val) in enumerate(output_pmf.data):
            self.assertAlmostEqual(prob, expected_output[iloc][0])
            self.assertAlmostEqual(val, expected_output[iloc][1])

    def test_depth_to_pmf_default(self):
        # Tests the function to get depth pmf assuming no depths are found in
        # catalogue - takes a default value
        self.catalogue.data["depth"] = np.array([])
        self.catalogue.data["depthError"] = np.array([])
        depth_bins = np.array([0.0, 5.0, 10.0, 15.0])
        output_pmf = self.catalogue.get_depth_pmf(depth_bins,
                                                  default_depth=10.0)
        self.assertAlmostEqual(output_pmf.data[0][0], 1.0)
        self.assertAlmostEqual(output_pmf.data[0][1], 10.0)

    def test_mag_depth_distribution_uncertainties(self):
        # Tests the magnitude depth distribution with uncertainties
        self.catalogue.data['depthError'] = 3.0 * np.ones_like(
            self.catalogue.data['depth'])
        self.catalogue.data['sigmaMagnitude'] = 0.1 * np.ones_like(
            self.catalogue.data['sigmaMagnitude'])

        # Extend depth bins to test that no negative depths are being returned
        depth_bins = np.arange(-10., 70., 10.)
        mag_bins = np.arange(5., 10., 1.)
        expected_array = np.array([[0., 1., 1., 1., 1., 1., 0.],
                                   [0., 1., 1., 1., 1., 1., 0.],
                                   [0., 1., 1., 1., 1., 1., 0.],
                                   [0., 1., 1., 1., 1., 1., 0.]])
        test_array = self.catalogue.get_magnitude_depth_distribution(
            mag_bins, depth_bins)
        array_diff = expected_array - np.round(test_array, 1)
        self.assertTrue(np.all(np.fabs(array_diff) < 0.2))
        # Check to make sure first columns is all zeros
        np.testing.assert_array_almost_equal(test_array[:, 0],
                                             np.zeros(4, dtype=float))
开发者ID:gem,项目名称:oq-hazardlib,代码行数:86,代码来源:catalogue_test.py


注:本文中的openquake.hmtk.seismicity.catalogue.Catalogue.get_depth_pmf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。