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

Python utilities.test_data_path函数代码示例

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

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



在下文中一共展示了test_data_path函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_run

    def test_run(self):
        function = FloodEvacuationRasterHazardFunction.instance()

        hazard_path = test_data_path('hazard', 'continuous_flood_20_20.asc')
        exposure_path = test_data_path(
            'exposure', 'pop_binary_raster_20_20.asc')
        hazard_layer = read_layer(hazard_path)
        exposure_layer = read_layer(exposure_path)

        function.hazard = hazard_layer
        function.exposure = exposure_layer
        function.run()
        impact = function.impact

        # Count of flooded objects is calculated "by the hands"
        # print "keywords", keywords
        keywords = impact.get_keywords()
        evacuated = float(keywords['evacuated'])
        total_needs_full = keywords['total_needs']
        total_needs_weekly = OrderedDict([
            [x['table name'], x['amount']] for x in
            total_needs_full['weekly']
        ])
        total_needs_single = OrderedDict([
            [x['table name'], x['amount']] for x in
            total_needs_full['single']
        ])

        expected_evacuated = 100
        self.assertEqual(evacuated, expected_evacuated)
        self.assertEqual(total_needs_weekly['Rice [kg]'], 280)
        self.assertEqual(total_needs_weekly['Family Kits'], 20)
        self.assertEqual(total_needs_weekly['Drinking Water [l]'], 1750)
        self.assertEqual(total_needs_weekly['Clean Water [l]'], 6700)
        self.assertEqual(total_needs_single['Toilets'], 5)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:35,代码来源:test_flood_raster_population.py


示例2: test_run

    def test_run(self):
        """TestVolcanoPointPopulationFunction: Test running the IF."""
        merapi_point_path = test_data_path('hazard', 'volcano_point.shp')
        population_path = test_data_path(
            'exposure', 'pop_binary_raster_20_20.asc')

        merapi_point_layer = read_layer(merapi_point_path)
        population_layer = read_layer(population_path)

        impact_function = VolcanoPointPopulationFunction.instance()

        # Run merapi point
        impact_function.hazard = merapi_point_layer
        impact_function.exposure = population_layer
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = (
            'In the event of a volcano point how many '
            'people might be impacted')
        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
        expected_affected_population = 200
        result = numpy.nansum(impact_layer.get_data())
        message = 'Expecting %s, but it returns %s' % (
            expected_affected_population, result)
        self.assertEqual(expected_affected_population, result, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:29,代码来源:test_volcano_point_population.py


示例3: test_run

    def test_run(self):
        impact_function = TsunamiRasterBuildingFunction.instance()

        hazard_path = test_data_path("hazard", "continuous_flood_20_20.asc")
        exposure_path = test_data_path("exposure", "buildings.shp")
        hazard_layer = read_layer(hazard_path)
        exposure_layer = read_layer(exposure_path)

        impact_function.hazard = SafeLayer(hazard_layer)
        impact_function.exposure = SafeLayer(exposure_layer)
        impact_function.run()
        impact_layer = impact_function.impact

        # Extract calculated result
        impact_data = impact_layer.get_data()
        self.assertEqual(len(impact_data), 181)

        # 1 = inundated, 2 = wet, 3 = dry
        expected_result = {0: 1, 1: 116, 2: 64, 3: 0, 4: 0}

        result = {0: 0, 1: 0, 2: 0, 3: 0, 4: 0}
        for feature in impact_data:
            inundated_status = feature[impact_function.target_field]
            result[inundated_status] += 1

        message = "Expecting %s, but it returns %s" % (expected_result, result)
        self.assertEqual(expected_result, result, message)
开发者ID:codeforresilience,项目名称:inasafe,代码行数:27,代码来源:test_tsunami_raster_building.py


示例4: test_is_polygonal_layer

    def test_is_polygonal_layer(self):
        """Test we can get the correct attributes back"""
        # Polygon layer
        layer = clone_shp_layer(
            name='district_osm_jakarta',
            include_keywords=True,
            source_directory=test_data_path('boundaries'))
        message = 'isPolygonLayer, %s layer should be polygonal' % layer
        self.assertTrue(is_polygon_layer(layer), message)

        # Point layer
        layer = clone_shp_layer(
            name='volcano_point',
            include_keywords=True,
            source_directory=test_data_path('hazard'))
        message = '%s layer should be polygonal' % layer
        self.assertFalse(is_polygon_layer(layer), message)

        layer = clone_raster_layer(
            name='padang_tsunami_mw8',
            extension='.tif',
            include_keywords=True,
            source_directory=test_data_path('hazard')
        )
        message = ('%s raster layer should not be polygonal' % layer)
        self.assertFalse(is_polygon_layer(layer), message)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:26,代码来源:test_gis.py


示例5: test_run

    def test_run(self):
        function = ContinuousHazardPopulationFunction.instance()

        hazard_path = test_data_path(
            'hazard', 'continuous_flood_20_20.asc')
        exposure_path = test_data_path(
            'exposure', 'pop_binary_raster_20_20.asc')
        hazard_layer = read_layer(hazard_path)
        exposure_layer = read_layer(exposure_path)

        function.hazard = SafeLayer(hazard_layer)
        function.exposure = SafeLayer(exposure_layer)
        function.run()
        impact = function.impact

        # print "keywords", keywords
        keywords = impact.get_keywords()
        total_needs_full = keywords['total_needs']
        total_needs_weekly = OrderedDict([
            [x['table name'], x['amount']] for x in
            total_needs_full['weekly']
        ])
        total_needs_single = OrderedDict([
            [x['table name'], x['amount']] for x in
            total_needs_full['single']
        ])

        self.assertEqual(total_needs_weekly['Rice [kg]'], 336)
        self.assertEqual(total_needs_weekly['Drinking Water [l]'], 2100)
        self.assertEqual(total_needs_weekly['Clean Water [l]'], 8040)
        self.assertEqual(total_needs_weekly['Family Kits'], 24)
        self.assertEqual(total_needs_single['Toilets'], 6)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:32,代码来源:test_continuous_hazard_population.py


示例6: test_get_keyword_from_file

    def test_get_keyword_from_file(self):
        """Get keyword from a filesystem file's .keyword file."""
        raster_shake_path = test_data_path("hazard", "jakarta_flood_design.tif")
        vector_path = test_data_path("exposure", "buildings_osm_4326.shp")
        raster_tsunami_path = test_data_path("hazard", "tsunami_wgs84.tif")

        keyword = read_file_keywords(raster_shake_path, "layer_purpose")
        expected_keyword = "hazard"
        message = ('The keyword "layer_purpose" for %s is %s. Expected keyword is: ' "%s") % (
            raster_shake_path,
            keyword,
            expected_keyword,
        )
        self.assertEqual(keyword, expected_keyword, message)

        # Test we get an exception if keyword is not found
        self.assertRaises(KeywordNotFoundError, read_file_keywords, raster_shake_path, "boguskeyword")

        # Test if all the keywords are all ready correctly
        keywords = read_file_keywords(raster_shake_path)
        expected_keywords = {
            "hazard_category": "single_event",
            "hazard": "flood",
            "continuous_hazard_unit": "metres",
            "layer_purpose": "hazard",
            "layer_mode": "continuous",
            "title": "Jakarta flood like 2007 with structural improvements",
            "keyword_version": inasafe_keyword_version,
        }
        message = "Expected:\n%s\nGot:\n%s\n" % (expected_keywords, keywords)
        self.assertDictEqual(keywords, expected_keywords, message)

        # Test reading keywords from vector layer
        keywords = read_file_keywords(vector_path)
        expected_keywords = {
            "keyword_version": inasafe_keyword_version,
            "structure_class_field": "FLOODED",
            "title": "buildings_osm_4326",
            "layer_geometry": "polygon",
            "layer_purpose": "exposure",
            "layer_mode": "classified",
            "exposure": "structure",
        }
        message = "Expected:\n%s\nGot:\n%s\n" % (expected_keywords, keywords)
        self.assertDictEqual(keywords, expected_keywords, message)

        # tsunami example
        keywords = read_file_keywords(raster_tsunami_path)
        expected_keywords = {
            "hazard_category": "single_event",
            "title": "Tsunami",
            "hazard": "tsunami",
            "continuous_hazard_unit": "metres",
            "layer_geometry": "raster",
            "layer_purpose": "hazard",
            "layer_mode": "continuous",
            "keyword_version": inasafe_keyword_version,
        }
        message = "Expected:\n%s\nGot:\n%s\n" % (expected_keywords, keywords)
        self.assertEqual(keywords, expected_keywords, message)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:60,代码来源:test_utilities.py


示例7: test_run

    def test_run(self):
        function = FloodPolygonBuildingFunction.instance()

        hazard_path = test_data_path('hazard', 'flood_multipart_polygons.shp')
        exposure_path = test_data_path('exposure', 'buildings.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Flood', 'ogr')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Buildings', 'ogr')

        # Let's set the extent to the hazard extent
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]

        function.hazard = QgisWrapper(hazard_layer)
        function.exposure = QgisWrapper(exposure_layer)
        function.requested_extent = rect_extent
        function.parameters['building_type_field'] = 'TYPE'
        function.parameters['affected_field'] = 'FLOODPRONE'
        function.parameters['affected_value'] = 'YES'
        function.run()
        impact = function.impact

        # Count of flooded objects is calculated "by the hands"
        # total flooded = 27, total buildings = 129
        count = sum(impact.get_data(attribute='INUNDATED'))
        self.assertEquals(count, 33)
        count = len(impact.get_data())
        self.assertEquals(count, 176)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:31,代码来源:test_flood_building_impact_qgis.py


示例8: test_run

    def test_run(self):
        function = ClassifiedRasterHazardBuildingFunction.instance()

        hazard_path = test_data_path('hazard', 'classified_flood_20_20.asc')
        exposure_path = test_data_path('exposure', 'buildings.shp')
        hazard_layer = read_layer(hazard_path)
        exposure_layer = read_layer(exposure_path)

        function.hazard = hazard_layer
        function.exposure = exposure_layer
        function.run()
        impact_layer = function.impact
        impact_data = impact_layer.get_data()

        # Count
        expected_impact = {
            1.0: 67,
            2.0: 49,
            3.0: 64
        }

        result_impact = {
            1.0: 0,
            2.0: 0,
            3.0: 0
        }
        for impact_feature in impact_data:
            level = impact_feature['level']
            if not math.isnan(level):
                result_impact[level] += 1
        message = 'Expecting %s, but it returns %s' % (
            expected_impact, result_impact)
        self.assertEqual(expected_impact, result_impact, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:33,代码来源:test_classified_raster_hazard_building.py


示例9: test_polygon_roads_impact

    def test_polygon_roads_impact(self):
        """Test FloodVectorRoadsExperimentalFunction work."""
        hazard_name = test_data_path(
            'hazard', 'multipart_polygons_osm_4326.shp')
        qgis_hazard = QgsVectorLayer(hazard_name, 'HAZARD', 'ogr')

        exposure_name = test_data_path('exposure', 'roads_osm_4326.shp')
        qgis_exposure = QgsVectorLayer(exposure_name, 'EXPOSURE', 'ogr')

        plugin_name = "FloodVectorRoadsExperimentalFunction"

        params = OrderedDict([
            ('target_field', 'flooded'),
            ('road_type_field', 'TYPE'),
            ('affected_field', 'FLOODPRONE'),
            ('affected_value', 'YES')
        ])

        impact = self._get_impact_function(
            qgis_hazard, qgis_exposure, plugin_name, params)

        keywords = impact.get_keywords()
        self.assertEquals(params['target_field'], keywords['target_field'])

        # Count of flooded objects is calculated "by hand"
        # the count = 63
        count = sum(impact.get_data(attribute=keywords['target_field']))
        self.assertEquals(count, 63)
开发者ID:severinmenard,项目名称:inasafe,代码行数:28,代码来源:test_qgis_native_impact_functions.py


示例10: test_run

    def test_run(self):
        """TestClassifiedPolygonPopulationFunction: Test running the IF."""
        generic_polygon_path = test_data_path(
            'hazard', 'classified_generic_polygon.shp')
        population_path = test_data_path(
            'exposure', 'pop_binary_raster_20_20.asc')

        generic_polygon_layer = read_layer(generic_polygon_path)
        population_layer = read_layer(population_path)

        impact_function = ClassifiedPolygonHazardPopulationFunction.instance()
        impact_function.hazard = SafeLayer(generic_polygon_layer)
        impact_function.exposure = SafeLayer(population_layer)
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = ('In each of the hazard zones how many people '
                             'might be impacted.')
        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
        expected_affected_population = 181
        result = numpy.nansum(impact_layer.get_data())
        self.assertEqual(expected_affected_population, result, message)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:25,代码来源:test_classified_polygon_population.py


示例11: test_run

    def test_run(self):
        """TestVolcanoPointBuildingFunction: Test running the IF."""
        volcano_path = test_data_path('hazard', 'volcano_point.shp')
        building_path = test_data_path('exposure', 'buildings.shp')

        hazard_layer = read_layer(volcano_path)
        exposure_layer = read_layer(building_path)

        impact_function = VolcanoPointBuildingFunction.instance()
        impact_function.hazard = SafeLayer(hazard_layer)
        impact_function.exposure = SafeLayer(exposure_layer)
        impact_function.run()
        impact_layer = impact_function.impact

        # Check the question
        expected_question = (
            'In the event of volcano point 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)

        # The buildings should all be categorised into 3000 zone
        zone_sum = sum(impact_layer.get_data(
            attribute=impact_function.target_field))
        expected_sum = 3000 * 181
        message = 'Expecting %s, but it returns %s' % (expected_sum, zone_sum)
        self.assertEqual(zone_sum, expected_sum, message)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:28,代码来源:test_volcano_point_building.py


示例12: test_state

    def test_state(self):
        """Check if the save/restore state methods work. See also
        https://github.com/AIFDR/inasafe/issues/58
        """
        # default selected layer is the third layer exposure
        # so, decrease the index by one to change it
        DOCK.cboExposure.setCurrentIndex(DOCK.cboExposure.currentIndex() - 1)
        DOCK.save_state()
        expected_dict = get_ui_state(DOCK)
        # myState = DOCK.state
        # Now reset and restore and check that it gets the old state
        # Html is not considered in restore test since the ready
        # message overwrites it in dock implementation
        DOCK.cboExposure.setCurrentIndex(DOCK.cboExposure.currentIndex() - 1)
        DOCK.restore_state()
        result_dict = get_ui_state(DOCK)
        message = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            result_dict, expected_dict, combos_to_string(DOCK))
        self.assertTrue(expected_dict == result_dict, message)

        # Corner case test when two layers can have the
        # same functions - when switching layers the selected function should
        # remain unchanged
        self.tearDown()
        file_list = [
            test_data_path('hazard', 'jakarta_flood_design.tif'),
            test_data_path('hazard', 'continuous_flood_20_20.asc'),
            test_data_path('exposure', 'pop_binary_raster_20_20.asc')
        ]
        hazard_layer_count, exposure_layer_count = load_layers(file_list)
        self.assertTrue(hazard_layer_count == 2)
        self.assertTrue(exposure_layer_count == 1)
        # we will have 2 impact function available right now:
        # - ContinuousHazardPopulationFunction, titled: 'Be impacted'
        # - FloodEvacuationRasterHazardFunction, titled: 'Need evacuation'
        # set it to the second for testing purposes
        DOCK.cboFunction.setCurrentIndex(1)
        DOCK.cboHazard.setCurrentIndex(0)
        DOCK.cboExposure.setCurrentIndex(0)
        expected_function = str(DOCK.cboFunction.currentText())
        # Now move down one hazard in the combo then verify
        # the function remains unchanged
        DOCK.cboHazard.setCurrentIndex(1)
        current_function = str(DOCK.cboFunction.currentText())
        message = (
            'Expected selected impact function to remain unchanged when '
            'choosing a different hazard of the same category:'
            ' %s\nExpected: %s\n%s' % (
                expected_function, current_function, combos_to_string(DOCK)))

        self.assertTrue(expected_function == current_function, message)
        DOCK.cboHazard.setCurrentIndex(0)
        # Selected function should remain the same
        # RM: modified it, because there is generic one right now as the first.
        # the selected one should be FloodEvacuationRasterHazardFunction
        DOCK.cboFunction.setCurrentIndex(1)
        expected = 'Need evacuation'
        function = DOCK.cboFunction.currentText()
        message = 'Expected: %s, Got: %s' % (expected, function)
        self.assertTrue(function == expected, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:60,代码来源:test_dock.py


示例13: test_run

    def test_run(self):
        """TestVolcanoPolygonPopulationFunction: Test running the IF."""
        merapi_krb_path = test_data_path('hazard', 'volcano_krb.shp')
        population_path = test_data_path(
            'exposure', 'pop_binary_raster_20_20.asc')

        merapi_krb_layer = read_layer(merapi_krb_path)
        population_layer = read_layer(population_path)

        impact_function = VolcanoPolygonPopulationFunction.instance()

        # 2. Run merapi krb
        impact_function.hazard = SafeLayer(merapi_krb_layer)
        impact_function.exposure = SafeLayer(population_layer)
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = ('In the event of volcano krb how many population '
                             'might need evacuation')
        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
        expected_affected_population = 181
        result = numpy.nansum(impact_layer.get_data())
        self.assertEqual(expected_affected_population, result, message)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:26,代码来源:test_volcano_polygon_population.py


示例14: test_run

    def test_run(self):
        function = FloodRasterRoadsFunction.instance()

        hazard_path = test_data_path('hazard', 'continuous_flood_20_20.asc')
        exposure_path = test_data_path('exposure', 'roads.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsRasterLayer(hazard_path, 'Flood')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr')

        # Let's set the extent to the hazard extent
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]
        function.hazard = SafeLayer(hazard_layer)
        function.exposure = SafeLayer(exposure_layer)
        function.requested_extent = rect_extent
        function.run()
        impact = function.impact

        keywords = impact.get_keywords()
        self.assertEquals(function.target_field, keywords['target_field'])
        expected_inundated_feature = 182
        count = sum(impact.get_data(attribute=function.target_field))
        self.assertEquals(count, expected_inundated_feature)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:26,代码来源:test_flood_raster_roads_function.py


示例15: test_get_keyword_from_file

    def test_get_keyword_from_file(self):
        """Get keyword from a filesystem file's .keyword file."""
        raster_layer = clone_raster_layer(
            'jakarta_flood_design', '.tif', False, test_data_path('hazard'))

        raster_layer_path = raster_layer.source()

        keyword_file = test_data_path('other', 'jakarta_flood_design.keywords')

        raster_keyword_path = (
            os.path.splitext(raster_layer_path)[0] + '.keywords')

        shutil.copy2(keyword_file, raster_keyword_path)

        keyword = read_file_keywords(raster_layer_path, 'layer_purpose')
        expected_keyword = 'hazard'
        self.assertEqual(keyword, expected_keyword)

        # Test we get an exception if keyword is not found
        self.assertRaises(
            KeywordNotFoundError,
            read_file_keywords, raster_layer_path, 'boguskeyword')

        # Test if all the keywords are all ready correctly
        keywords = read_file_keywords(raster_layer_path)
        expected_keywords = {
            'hazard_category': 'single_event',
            'hazard': 'flood',
            'continuous_hazard_unit': 'metres',
            'layer_purpose': 'hazard',
            'layer_mode': 'continuous',
            'title': 'Jakarta flood like 2007 with structural improvements',
            'keyword_version': '3.2'
        }
        self.assertDictEqual(keywords, expected_keywords)
开发者ID:codeforresilience,项目名称:inasafe,代码行数:35,代码来源:test_utilities.py


示例16: test_run

    def test_run(self):
        """TestVolcanoPolygonBuildingFunction: Test running the IF."""
        volcano_path = test_data_path('hazard', 'volcano_krb.shp')
        building_path = test_data_path('exposure', 'buildings.shp')

        hazard_layer = read_layer(volcano_path)
        exposure_layer = read_layer(building_path)

        impact_function = VolcanoPolygonBuildingFunction.instance()
        impact_function.hazard = SafeLayer(hazard_layer)
        impact_function.exposure = SafeLayer(exposure_layer)
        impact_function.run()
        impact_layer = impact_function.impact

        # Check the question
        expected_question = ('In the event of volcano krb 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)

        # The buildings should all be categorised into 5000 zone
        zone_sum = impact_layer.get_data(
            attribute=impact_function.target_field)
        krb3_zone_count = zone_sum.count('High Hazard Zone')
        krb2_zone_count = zone_sum.count('Medium Hazard Zone')
        # The result (counted by hand)
        expected_krb3_count = 11
        expected_krb2_count = 161
        message = 'Expecting %s for KRB III zone, but it returns %s' % (
            krb3_zone_count, expected_krb3_count)
        self.assertEqual(krb3_zone_count, expected_krb3_count, message)
        message = 'Expecting %s for KRB II zone, but it returns %s' % (
            krb2_zone_count, expected_krb2_count)
        self.assertEqual(krb2_zone_count, expected_krb2_count, message)
开发者ID:codeforresilience,项目名称:inasafe,代码行数:35,代码来源:test_volcano_polygon_building.py


示例17: test_run

    def test_run(self):
        function = FloodPolygonRoadsFunction.instance()

        hazard_path = test_data_path('hazard', 'flood_multipart_polygons.shp')
        exposure_path = test_data_path('exposure', 'roads.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Flood', 'ogr')
        # noinspection PyCallingNonCallable
        exposure_layer = QgsVectorLayer(exposure_path, 'Roads', 'ogr')

        # Let's set the extent to the hazard extent
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]
        function.hazard = SafeLayer(hazard_layer)
        function.exposure = SafeLayer(exposure_layer)
        function.requested_extent = rect_extent
        function.run()
        impact = function.impact

        # Count of flooded objects is calculated "by the hands"
        # the count = 69
        expected_feature_total = 69
        count = sum(impact.get_data(attribute=function.target_field))
        message = 'Expecting %s, but it returns %s' % (
            expected_feature_total, count)
        self.assertEquals(count, expected_feature_total, message)
开发者ID:Mloweedgar,项目名称:inasafe,代码行数:28,代码来源:test_flood_polygon_roads.py


示例18: test_run

    def test_run(self):
        impact_function = FloodRasterBuildingFunction.instance()

        hazard_path = test_data_path('hazard', 'continuous_flood_20_20.asc')
        exposure_path = test_data_path('exposure', 'buildings.shp')
        hazard_layer = read_layer(hazard_path)
        exposure_layer = read_layer(exposure_path)

        impact_function.hazard = hazard_layer
        impact_function.exposure = exposure_layer
        impact_function.run()
        impact_layer = impact_function.impact

        # Extract calculated result
        impact_data = impact_layer.get_data()
        self.assertEqual(len(impact_data), 181)

        # 1 = inundated, 2 = wet, 3 = dry
        expected_result = {
            1: 64,
            2: 117,
            3: 0
        }

        result = {
            1: 0,
            2: 0,
            3: 0
        }
        for feature in impact_data:
            inundated_status = feature['INUNDATED']
            result[inundated_status] += 1

        message = 'Expecting %s, but it returns %s' % (expected_result, result)
        self.assertEqual(expected_result, result, message)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:35,代码来源:test_flood_raster_osm_building.py


示例19: test_zonal_with_exact_cell_boundaries

 def test_zonal_with_exact_cell_boundaries(self):
     """Test that zonal stats returns the expected output."""
     raster_layer, _ = load_layer(
         test_data_path('other', 'tenbytenraster.asc'))
     # Note this is a matrix of 11x11 polygons - one per cell
     # and one poly extending beyond to the right of each row
     # and one poly extending beyond the bottom of each col
     vector_layer, _ = load_layer(
         test_data_path('other', 'ten_by_ten_raster_as_polys.shp'))
     result = calculate_zonal_stats(
         raster_layer=raster_layer,
         polygon_layer=vector_layer)
     expected_result = {
         0L: {'count': 1.0, 'sum': 0.0, 'mean': 0.0},  # TL polygon
         9L: {'count': 1.0, 'sum': 9.0, 'mean': 9.0},  # TR polygon
         25L: {'count': 1.0, 'sum': 3.0, 'mean': 3.0},  # Central polygon
         88L: {'count': 1.0, 'sum': 0.0, 'mean': 0.0},  # BL polygon
         108L: {'count': 1.0, 'sum': 9.0, 'mean': 9.0}}  # BR polygon
     # We will just check TL, TR, Middle, BL and BR cells
     result = {
         0L: result[0L],
         9L: result[9L],
         25L: result[25L],
         88L: result[88L],
         108L: result[108L]}
     # noinspection PyPep8Naming
     self.maxDiff = None
     self.assertDictEqual(expected_result, result)
开发者ID:Charlotte-Morgan,项目名称:inasafe,代码行数:28,代码来源:test_zonal_stats.py


示例20: test_run

    def test_run(self):
        function = FloodPolygonBuildingFunction.instance()

        hazard_path = test_data_path('hazard', 'flood_multipart_polygons.shp')
        # exposure_path = test_data_path('exposure', 'buildings.shp')
        # noinspection PyCallingNonCallable
        hazard_layer = QgsVectorLayer(hazard_path, 'Flood', 'ogr')
        # noinspection PyCallingNonCallable
        # exposure_layer = QgsVectorLayer(exposure_path, 'Buildings', 'ogr')

        exposure_layer = clone_shp_layer(
            name='buildings',
            include_keywords=True,
            source_directory=test_data_path('exposure'))
        # Let's set the extent to the hazard extent
        extent = hazard_layer.extent()
        rect_extent = [
            extent.xMinimum(), extent.yMaximum(),
            extent.xMaximum(), extent.yMinimum()]

        function.hazard = SafeLayer(hazard_layer)
        function.exposure = SafeLayer(exposure_layer)
        function.requested_extent = rect_extent
        function.run()
        impact = function.impact

        # Count of flooded objects is calculated "by the hands"
        # total flooded = 27, total buildings = 129
        count = sum(impact.get_data(attribute=function.target_field))
        self.assertEquals(count, 33)
        count = len(impact.get_data())
        self.assertEquals(count, 176)
开发者ID:jobel-openscience,项目名称:inasafe,代码行数:32,代码来源:test_flood_building_impact_qgis.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python gis.is_raster_layer函数代码示例发布时间:2022-05-27
下一篇:
Python utilities.standard_data_path函数代码示例发布时间: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