當前位置: 首頁>>代碼示例>>Python>>正文


Python impact_function.ITBFatalityFunction類代碼示例

本文整理匯總了Python中safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function.ITBFatalityFunction的典型用法代碼示例。如果您正苦於以下問題:Python ITBFatalityFunction類的具體用法?Python ITBFatalityFunction怎麽用?Python ITBFatalityFunction使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ITBFatalityFunction類的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_available_exposure_layer_mode

 def test_available_exposure_layer_mode(self):
     """Test for available_exposure_layer_mode."""
     impact_function = ITBFatalityFunction()
     result = impact_function.metadata().available_exposure_layer_mode(
         'population',
         'raster'
     )
     expected = layer_mode_continuous
     self.assertEqual(result, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:9,代碼來源:test_impact_function_metadata.py

示例2: test_available_exposure_constraints

 def test_available_exposure_constraints(self):
     """Test for available_exposure_constraints."""
     impact_function = ITBFatalityFunction()
     result = impact_function.metadata().available_exposure_constraints(
         'population'
     )
     expected = [
         (layer_mode_continuous, layer_geometry_raster)
     ]
     self.assertItemsEqual(result, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:10,代碼來源:test_impact_function_metadata.py

示例3: test_available_hazard_layer_mode

    def test_available_hazard_layer_mode(self):
        """Test for available_hazard_layer_mode."""
        impact_function = ITBFatalityFunction()
        result = impact_function.metadata().available_hazard_layer_mode(
            'earthquake',
            'raster',
            'single_event'
        )

        expected = layer_mode_continuous
        self.assertEqual(result, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:11,代碼來源:test_impact_function_metadata.py

示例4: test_available_hazard_constraints

 def test_available_hazard_constraints(self):
     """Test for available_hazard_constraints."""
     impact_function = ITBFatalityFunction()
     result = impact_function.metadata().available_hazard_constraints(
         'earthquake',
         'single_event'
     )
     expected = [
         (layer_mode_continuous, layer_geometry_raster)
     ]
     self.assertItemsEqual(result, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:11,代碼來源:test_impact_function_metadata.py

示例5: test_exposure_units_for_layer

    def test_exposure_units_for_layer(self):
        """Test exposure_units_for_layer."""
        impact_function = ITBFatalityFunction()
        exposure_units = impact_function.metadata().exposure_units_for_layer(
            'population', 'raster', 'continuous')
        expected = [count_exposure_unit]
        self.assertItemsEqual(exposure_units, expected)

        exposure_units = impact_function.metadata().exposure_units_for_layer(
            'population', 'raster', 'classified')
        expected = []
        self.assertItemsEqual(exposure_units, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:12,代碼來源:test_impact_function_metadata.py

示例6: test_available_hazards

    def test_available_hazards(self):
        """Test available_hazards."""
        impact_function = ITBFatalityFunction()
        hazards = impact_function.metadata().available_hazards(
            'single_event')
        expected = [hazard_earthquake]
        self.assertItemsEqual(hazards, expected)

        hazards = impact_function.metadata().available_hazards(
            'multiple_event')
        expected = [hazard_earthquake]
        self.assertItemsEqual(hazards, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:12,代碼來源:test_impact_function_metadata.py

示例7: test_continuous_hazards_units_for_layer

    def test_continuous_hazards_units_for_layer(self):
        """Test continuous_hazards_units_for_layer."""
        impact_function = ITBFatalityFunction()
        continuous_hazards_units = impact_function.metadata().\
            continuous_hazards_units_for_layer(
                'earthquake', 'raster', 'continuous', 'single_event')
        expected = [unit_mmi]
        self.assertItemsEqual(continuous_hazards_units, expected)

        continuous_hazards_units = impact_function.metadata().\
            continuous_hazards_units_for_layer(
                'flood', 'raster', 'continuous', 'single_event')
        expected = []
        self.assertItemsEqual(continuous_hazards_units, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:14,代碼來源:test_impact_function_metadata.py

示例8: test_functions_for_constraint

    def test_functions_for_constraint(self):
        """Test functions_for_constraint."""
        ifm = ImpactFunctionManager()
        impact_functions = ifm.functions_for_constraint(
            'earthquake',
            'population',
            'raster',
            'raster',
            'continuous',
            'continuous',
        )
        expected = [
            ITBFatalityFunction.metadata().as_dict(),
            ITBBayesianFatalityFunction.metadata().as_dict(),
            PAGFatalityFunction.metadata().as_dict(),
            ContinuousHazardPopulationFunction.metadata().as_dict()]

        for key in impact_functions[0].keys():
            if key == 'parameters':
                # We do not check the parameters since they are mutable.
                continue
            result = [x[key] for x in impact_functions]
            hope = [x[key] for x in expected]
            message = key
            self.assertItemsEqual(result, hope, message)
開發者ID:easmetz,項目名稱:inasafe,代碼行數:25,代碼來源:test_impact_function_manager.py

示例9: test_is_function_for_constraint

    def test_is_function_for_constraint(self):
        """Test for is_function_for_constraint"""
        impact_function = ITBFatalityFunction()
        result = impact_function.metadata().is_function_for_constraint(
            'earthquake',
            'population',
            'raster',
            'raster',
            'continuous',
            'continuous',
        )
        self.assertTrue(result)

        result = impact_function.metadata().is_function_for_constraint(
            'earthquake',
            'population',
            'raster',
            'raster',
            'classified',
            'continuous',
        )
        self.assertFalse(result)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:22,代碼來源:test_impact_function_metadata.py

示例10: test_compute_fatality_rate

 def test_compute_fatality_rate(self):
     impact_function = ITBFatalityFunction.instance()
     expected_result = {2: 0,
                        3: 0,
                        4: 2.869e-6,
                        5: 1.203e-5,
                        6: 5.048e-5,
                        7: 2.117e-4,
                        8: 8.883e-4,
                        9: 3.726e-3,
                        10: 1.563e-2}
     result = impact_function.compute_fatality_rate()
     for item in expected_result.keys():
         self.assertAlmostEqual(
             expected_result[item], result[item], places=4)
開發者ID:jobel-openscience,項目名稱:inasafe,代碼行數:15,代碼來源:test_itb_earthquake_fatality_model.py

示例11: test_run

    def test_run(self):
        """TestITEarthquakeFatalityFunction: Test running the IF."""
        eq_path = test_data_path('hazard', 'earthquake.tif')
        population_path = test_data_path(
            'exposure', 'pop_binary_raster_20_20.asc')

        # For EQ on Pops we need to clip the hazard and exposure first to the
        # same dimension
        clipped_hazard, clipped_exposure = clip_layers(
            eq_path, population_path)

        # noinspection PyUnresolvedReferences
        eq_layer = read_layer(
            str(clipped_hazard.source()))
        # noinspection PyUnresolvedReferences
        population_layer = read_layer(
            str(clipped_exposure.source()))

        impact_function = ITBFatalityFunction.instance()
        impact_function.hazard = eq_layer
        impact_function.exposure = population_layer
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = ('In the event of earthquake how many '
                             'population might die or be displaced')
        message = 'The question should be %s, but it returns %s' % (
            expected_question, impact_function.question)
        self.assertEqual(expected_question, impact_function.question, message)
        # Count by hand,
        # 1 = low, 2 = medium, 3 = high
        expected_exposed_per_mmi = {
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 0,
            7: 0,
            8: 200,
            9: 0
        }
        result = impact_layer.get_keywords('exposed_per_mmi')

        message = 'Expecting %s, but it returns %s' % (
            expected_exposed_per_mmi, result)
        self.assertEqual(expected_exposed_per_mmi, result, message)
開發者ID:Charlotte-Morgan,項目名稱:inasafe,代碼行數:46,代碼來源:test_itb_earthquake_fatality_model.py

示例12: test_available_exposures

 def test_available_exposures(self):
     """Test available_exposure."""
     impact_function = ITBFatalityFunction()
     hazards = impact_function.metadata().available_exposures()
     expected = [exposure_population]
     self.assertItemsEqual(hazards, expected)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:6,代碼來源:test_impact_function_metadata.py

示例13: test_run

    def test_run(self):
        """TestITEarthquakeFatalityFunction: Test running the IF."""
        # FIXME(Hyeuk): test requires more realistic hazard and population data
        eq_path = test_data_path('hazard', 'earthquake.tif')
        population_path = test_data_path(
            'exposure', 'pop_binary_raster_20_20.asc')

        # For EQ on Pops we need to clip the hazard and exposure first to the
        # same dimension
        clipped_hazard, clipped_exposure = clip_layers(
            eq_path, population_path)

        # noinspection PyUnresolvedReferences
        eq_layer = read_layer(
            str(clipped_hazard.source()))
        # noinspection PyUnresolvedReferences
        population_layer = read_layer(
            str(clipped_exposure.source()))

        impact_function = ITBFatalityFunction.instance()
        impact_function.hazard = SafeLayer(eq_layer)
        impact_function.exposure = SafeLayer(population_layer)
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = ('In the event of earthquake how many '
                             'population might die or be displaced')
        message = 'The question should be %s, but it returns %s' % (
            expected_question, impact_function.question)
        self.assertEqual(expected_question, impact_function.question, message)

        expected_result = {
            'total_population': 200,
            'total_fatalities': 0,  # should be zero FIXME
            'total_displaced': 200
        }
        for key_ in expected_result.keys():
            result = impact_layer.get_keywords(key_)
            message = 'Expecting %s, but it returns %s' % (
                expected_result[key_], result)
            self.assertEqual(expected_result[key_], result, message)

        expected_result = {}
        expected_result['fatalities_per_mmi'] = {
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 0,
            7: 0,
            8: 0.17778,
            9: 0,
            10: 0
        }
        expected_result['exposed_per_mmi'] = {
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 0,
            7: 0,
            8: 200,
            9: 0,
            10: 0
        }
        expected_result['displaced_per_mmi'] = {
            2: 0,
            3: 0,
            4: 0,
            5: 0,
            6: 0,
            7: 0,
            8: 199.82221,
            9: 0,
            10: 0
        }

        for key_ in expected_result.keys():
            result = impact_layer.get_keywords(key_)
            for item in expected_result[key_].keys():
                message = 'Expecting %s, but it returns %s' % (
                    expected_result[key_][item], result[item])
                self.assertAlmostEqual(
                    expected_result[key_][item],
                    result[item], places=4, msg=message)
開發者ID:Mloweedgar,項目名稱:inasafe,代碼行數:85,代碼來源:test_itb_earthquake_fatality_model.py


注:本文中的safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function.ITBFatalityFunction類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。