本文整理汇总了Python中safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function.ITBFatalityFunction.instance方法的典型用法代码示例。如果您正苦于以下问题:Python ITBFatalityFunction.instance方法的具体用法?Python ITBFatalityFunction.instance怎么用?Python ITBFatalityFunction.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function.ITBFatalityFunction
的用法示例。
在下文中一共展示了ITBFatalityFunction.instance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compute_fatality_rate
# 需要导入模块: from safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function import ITBFatalityFunction [as 别名]
# 或者: from safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function.ITBFatalityFunction import instance [as 别名]
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)
示例2: test_run
# 需要导入模块: from safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function import ITBFatalityFunction [as 别名]
# 或者: from safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function.ITBFatalityFunction import instance [as 别名]
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)
示例3: test_run
# 需要导入模块: from safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function import ITBFatalityFunction [as 别名]
# 或者: from safe.impact_functions.earthquake.itb_earthquake_fatality_model.impact_function.ITBFatalityFunction import instance [as 别名]
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)