• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python impact_function.EarthquakeBuildingFunction类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中safe.impact_functions.earthquake.earthquake_building.impact_function.EarthquakeBuildingFunction的典型用法代码示例。如果您正苦于以下问题:Python EarthquakeBuildingFunction类的具体用法?Python EarthquakeBuildingFunction怎么用?Python EarthquakeBuildingFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了EarthquakeBuildingFunction类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:27,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:8,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:10,代码来源:test_impact_function_metadata.py


示例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'
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:11,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:12,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:13,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:13,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:13,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:15,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:15,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:16,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:29,代码来源:test_earthquake_building.py


示例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)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:19,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:20,代码来源:test_impact_function_metadata.py


示例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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:45,代码来源:test_impact_function_metadata.py


示例16: test_allowed_subcategories

    def test_allowed_subcategories(self):
        """Test for allowed_subcategories API."""
        impact_function = EarthquakeBuildingFunction()
        result = impact_function.metadata().allowed_subcategories(
            category='hazard')
        expected_result = [hazard_earthquake]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        result = impact_function.metadata().allowed_subcategories(
            category='exposure')
        expected_result = [exposure_structure]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        result = impact_function.metadata().allowed_subcategories()
        expected_result = [exposure_structure, hazard_earthquake]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        impact_function = ContinuousHazardPopulationFunction()
        result = impact_function.metadata().allowed_subcategories(
            category='hazard')
        expected_result = hazard_all
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:26,代码来源:test_impact_function_metadata.py


示例17: test_calculate_impact

    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)
开发者ID:codeforresilience,项目名称:inasafe,代码行数:14,代码来源:test_core.py


示例18: 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 = 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)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:40,代码来源:test_earthquake_building.py


示例19: test_units_for_layer

    def test_units_for_layer(self):
        """Test for units_for_layer API."""
        impact_function = EarthquakeBuildingFunction()
        result = impact_function.metadata().units_for_layer(
            subcategory='earthquake',
            layer_type='raster',
            data_type='continuous')
        expected_result = [unit_mmi]
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        result = impact_function.metadata().units_for_layer(
            subcategory='flood', layer_type='raster', data_type='continuous')
        expected_result = []
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        result = impact_function.metadata().units_for_layer(
            subcategory='earthquake',
            layer_type='vector',
            data_type='continuous')
        expected_result = []
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        result = impact_function.metadata().units_for_layer(
            subcategory='earthquake', layer_type='raster', data_type='polygon')
        expected_result = []
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)

        impact_function = ContinuousHazardPopulationFunction()
        result = impact_function.metadata().units_for_layer(
            subcategory='flood', layer_type='raster', data_type='continuous')
        expected_result = []
        message = ('I expect %s but I got %s.' % (expected_result, result))
        self.assertEqual(result, expected_result, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:37,代码来源:test_impact_function_metadata.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python impact_function.ITBFatalityFunction类代码示例发布时间:2022-05-27
下一篇:
Python core.population_rounding函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap