本文整理汇总了Python中safe.impact_functions.earthquake.earthquake_building.impact_function.EarthquakeBuildingFunction类的典型用法代码示例。如果您正苦于以下问题:Python EarthquakeBuildingFunction类的具体用法?Python EarthquakeBuildingFunction怎么用?Python EarthquakeBuildingFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EarthquakeBuildingFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_allowed_units
def test_allowed_units(self):
"""Test for allowed_units API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata() .allowed_units(
'structure', 'polygon')
expected_result = [unit_building_type_type, unit_building_generic]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertItemsEqual(result, expected_result, message)
result = impact_function.metadata() .allowed_units(
'structure', 'continuous')
expected_result = []
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
impact_function = FloodRasterBuildingFunction
result = impact_function.metadata().allowed_units(
'structure', 'polygon')
expected_result = [unit_building_type_type, unit_building_generic]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertItemsEqual(result, expected_result, message)
result = impact_function.metadata()\
.allowed_units('flood', 'continuous')
expected_result = [unit_metres_depth, unit_feet_depth]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
示例2: test_purposes_for_layer
def test_purposes_for_layer(self):
"""Test for purposes_for_layer."""
impact_function = EarthquakeBuildingFunction()
layer_purpose = impact_function.metadata().purposes_for_layer(
'polygon')
self.assertIsNotNone(layer_purpose)
expected_result = [layer_purpose_exposure]
self.assertItemsEqual(layer_purpose, expected_result)
示例3: test_exposures_for_layer
def test_exposures_for_layer(self):
"""Test exposures_for_layer."""
impact_function = EarthquakeBuildingFunction()
exposures = impact_function.metadata().exposures_for_layer('polygon')
expected = [exposure_structure]
self.assertItemsEqual(exposures, expected)
exposures = impact_function.metadata().exposures_for_layer('raster')
expected = []
self.assertItemsEqual(exposures, expected)
示例4: test_inner_class
def test_inner_class(self):
"""Test call inner class."""
impact_function = EarthquakeBuildingFunction()
# call from an object
metadata = impact_function.metadata()
metadata_dictionary = metadata.as_dict()
assert isinstance(metadata_dictionary, dict), 'I did not got a dict'
# call from the class
metadata = impact_function.metadata()
metadata_dictionary = metadata.as_dict()
assert isinstance(metadata_dictionary, dict), 'I did not got a dict'
示例5: test_allowed_data_types
def test_allowed_data_types(self):
"""Test for allowed_data_types API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().allowed_data_types('structure')
expected_result = ['polygon', 'point']
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertItemsEqual(result, expected_result, message)
result = impact_function.metadata().allowed_data_types('earthquake')
expected_result = ['continuous']
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertItemsEqual(result, expected_result, message)
示例6: test_get_hazards
def test_get_hazards(self):
"""Test for get_hazards API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().get_hazards()
expected_result = [hazard_earthquake]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
impact_function = FloodRasterBuildingFunction()
result = impact_function.metadata().get_hazards()
expected_result = [hazard_flood, hazard_tsunami]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
示例7: test_get_exposures
def test_get_exposures(self):
"""Test for get_exposures API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().get_exposures()
expected_result = [exposure_structure]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
impact_function = FloodRasterBuildingFunction()
result = impact_function.metadata().get_exposures()
expected_result = []
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertNotEqual(result, expected_result, message)
示例8: test_has_exposure
def test_has_exposure(self):
"""Test for has_exposure API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().has_exposure(exposure_structure)
expected_result = True
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
impact_function = FloodRasterBuildingFunction()
result = impact_function.metadata().has_exposure(exposure_structure)
expected_result = True
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
示例9: test_subcategories_for_layer
def test_subcategories_for_layer(self):
"""Test for subcategories_for_layer API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().subcategories_for_layer(
category='hazard', layer_type='raster', data_type='continuous')
expected_result = [hazard_earthquake]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().subcategories_for_layer(
category='exposure', layer_type='vector', data_type='polygon')
expected_result = [exposure_structure]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
示例10: test_has_hazard_id
def test_has_hazard_id(self):
"""Test for has_hazard_id API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().has_hazard_id(
hazard_earthquake['id'])
expected_result = True
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
impact_function = FloodRasterBuildingFunction()
result = impact_function.metadata().has_hazard_id(
hazard_earthquake['id'])
expected_result = False
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
示例11: test_hazards_for_layer
def test_hazards_for_layer(self):
"""Test hazards_for_layer"""
impact_function = EarthquakeBuildingFunction()
hazards = impact_function.metadata().hazards_for_layer(
'raster', 'single_event')
expected = [hazard_earthquake]
self.assertItemsEqual(hazards, expected)
hazards = impact_function.metadata().hazards_for_layer('raster',)
expected = [hazard_earthquake]
self.assertItemsEqual(hazards, expected)
hazards = impact_function.metadata().hazards_for_layer(
'polygon', 'single_event')
expected = []
self.assertItemsEqual(hazards, expected)
示例12: test_run
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)
示例13: test_hazard_categories_for_layer
def test_hazard_categories_for_layer(self):
"""Test for hazard_categories_for_layer"""
impact_function = EarthquakeBuildingFunction()
hazard_categories = impact_function.metadata()\
.hazard_categories_for_layer('raster')
expected = [
hazard_category_single_event, hazard_category_multiple_event]
self.assertItemsEqual(hazard_categories, expected)
hazard_categories = impact_function.metadata() \
.hazard_categories_for_layer('raster', 'earthquake')
expected = [
hazard_category_single_event, hazard_category_multiple_event]
self.assertItemsEqual(hazard_categories, expected)
hazard_categories = impact_function.metadata() \
.hazard_categories_for_layer('polygon')
expected = []
self.assertItemsEqual(hazard_categories, expected)
示例14: test_allowed_layer_constraints
def test_allowed_layer_constraints(self):
"""Test for allowed_layer_constraints API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().allowed_layer_constraints()
expected_result = [layer_raster_continuous, layer_vector_polygon,
layer_vector_point]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
result = impact_function.metadata().allowed_layer_constraints(
'hazard')
expected_result = [layer_raster_continuous]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
result = impact_function.metadata().allowed_layer_constraints(
'exposure')
expected_result = [layer_vector_polygon, layer_vector_point]
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
示例15: test_categories_for_layer
def test_categories_for_layer(self):
"""Test for categories_for_layer API."""
impact_function = EarthquakeBuildingFunction()
result = impact_function.metadata().categories_for_layer(
layer_type='raster', data_type='continuous')
expected_result = ['hazard']
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
result = impact_function.metadata().categories_for_layer(
layer_type='vector', data_type='line')
expected_result = []
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
result = impact_function.metadata().categories_for_layer(
layer_type='vector', data_type='polygon')
expected_result = ['exposure']
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertItemsEqual(result, expected_result, message)
impact_function = ContinuousHazardPopulationFunction()
result = impact_function.metadata().categories_for_layer(
layer_type='raster', data_type='continuous')
expected_result = ['exposure', 'hazard']
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertListEqual(result, expected_result, message)
result = impact_function.metadata().categories_for_layer(
layer_type='vector', data_type='line')
expected_result = []
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertEqual(result, expected_result, message)
result = impact_function.metadata().categories_for_layer(
layer_type='vector', data_type='polygon')
expected_result = []
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertItemsEqual(result, expected_result, message)
result = impact_function.metadata().categories_for_layer(
layer_type='vector', data_type='point')
expected_result = []
message = ('I expect %s but I got %s.' % (expected_result, result))
self.assertItemsEqual(result, expected_result, message)