本文整理汇总了Python中safe.impact_functions.earthquake.earthquake_building.impact_function.EarthquakeBuildingFunction.instance方法的典型用法代码示例。如果您正苦于以下问题:Python EarthquakeBuildingFunction.instance方法的具体用法?Python EarthquakeBuildingFunction.instance怎么用?Python EarthquakeBuildingFunction.instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.impact_functions.earthquake.earthquake_building.impact_function.EarthquakeBuildingFunction
的用法示例。
在下文中一共展示了EarthquakeBuildingFunction.instance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_run
# 需要导入模块: from safe.impact_functions.earthquake.earthquake_building.impact_function import EarthquakeBuildingFunction [as 别名]
# 或者: from safe.impact_functions.earthquake.earthquake_building.impact_function.EarthquakeBuildingFunction import instance [as 别名]
def test_run(self):
"""TestEarthquakeBuildingFunction: Test running the IF."""
eq_path = test_data_path("hazard", "earthquake.tif")
building_path = test_data_path("exposure", "buildings.shp")
eq_layer = read_layer(eq_path)
building_layer = read_layer(building_path)
impact_function = EarthquakeBuildingFunction.instance()
impact_function.hazard = SafeLayer(eq_layer)
impact_function.exposure = SafeLayer(building_layer)
impact_function.run()
impact_layer = impact_function.impact
# Check the question
expected_question = "In the event of earthquake how many buildings might be affected"
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
impact = {1: 0, 2: 181, 3: 0}
result = {1: 0, 2: 0, 3: 0}
impact_features = impact_layer.get_data()
for i in range(len(impact_features)):
impact_feature = impact_features[i]
level = impact_feature.get(impact_function.target_field)
result[level] += 1
message = "Expecting %s, but it returns %s" % (impact, result)
self.assertEqual(impact, result, message)
示例2: test_calculate_impact
# 需要导入模块: from safe.impact_functions.earthquake.earthquake_building.impact_function import EarthquakeBuildingFunction [as 别名]
# 或者: from safe.impact_functions.earthquake.earthquake_building.impact_function.EarthquakeBuildingFunction import instance [as 别名]
def test_calculate_impact(self):
"""Test calculating impact."""
eq_path = test_data_path('hazard', 'earthquake.tif')
building_path = test_data_path('exposure', 'buildings.shp')
eq_layer = read_layer(eq_path)
building_layer = read_layer(building_path)
impact_function = EarthquakeBuildingFunction.instance()
impact_function.hazard = SafeLayer(eq_layer)
impact_function.exposure = SafeLayer(building_layer)
impact_layer = calculate_impact(impact_function)
self.assertIsNotNone(impact_layer)
示例3: test_run
# 需要导入模块: from safe.impact_functions.earthquake.earthquake_building.impact_function import EarthquakeBuildingFunction [as 别名]
# 或者: from safe.impact_functions.earthquake.earthquake_building.impact_function.EarthquakeBuildingFunction import instance [as 别名]
def test_run(self):
"""TestEarthquakeBuildingFunction: Test running the IF."""
eq_path = test_data_path('hazard', 'earthquake.tif')
building_path = test_data_path(
'exposure', 'buildings.shp')
eq_layer = read_layer(eq_path)
building_layer = read_layer(building_path)
impact_function = EarthquakeBuildingFunction.instance()
impact_function.hazard = eq_layer
impact_function.exposure = building_layer
impact_function.run()
impact_layer = impact_function.impact
# Check the question
expected_question = ('In the event of earthquake how many '
'buildings might be affected')
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
impact = {
1: 0,
2: 181,
3: 0
}
result = {
1: 0,
2: 0,
3: 0
}
impact_features = impact_layer.get_data()
for i in range(len(impact_features)):
impact_feature = impact_features[i]
level = impact_feature.get('Shake_cls')
result[level] += 1
message = 'Expecting %s, but it returns %s' % (impact, result)
self.assertEqual(impact, result, message)