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 = SafeLayer(hazard_layer)
        function.exposure = SafeLayer(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)
    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)
Exemple #3
0
    def test_run(self):
        function = ClassifiedRasterHazardBuildingFunction.instance()

        hazard_path = standard_data_path(
            'hazard', 'classified_hazard.tif')
        exposure_path = standard_data_path('exposure', 'small_building.shp')
        hazard_layer = read_layer(hazard_path)
        exposure_layer = read_layer(exposure_path)

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

        # Count
        expected_impact = {
            'Not affected': 5,
            'Low hazard zone': 2,
            'Medium hazard zone': 9,
            'High hazard zone': 5
        }

        result_impact = {}
        for impact_feature in impact_data:
            hazard_class = impact_feature[function.target_field]
            if hazard_class in result_impact:
                result_impact[hazard_class] += 1
            else:
                result_impact[hazard_class] = 1
        self.assertDictEqual(expected_impact, result_impact)