Exemplo n.º 1
0
 def test_get_hazard_layer_constraint(self):
     """Test for get_hazard_layer_constraint."""
     impact_function = FloodRasterBuildingFunction()
     expected_layer_constraint = [layer_raster_continuous]
     layer_constraints \
         = impact_function.metadata().get_hazard_layer_constraint()
     message = 'Expected %s but got %s' % (expected_layer_constraint,
                                           layer_constraints)
     self.assertItemsEqual(expected_layer_constraint, layer_constraints,
                           message)
 def test_get_hazard_layer_constraint(self):
     """Test for get_hazard_layer_constraint."""
     impact_function = FloodRasterBuildingFunction()
     expected_layer_constraint = [layer_raster_continuous]
     layer_constraints \
         = impact_function.metadata().get_hazard_layer_constraint()
     message = 'Expected %s but got %s' % (
         expected_layer_constraint, layer_constraints)
     self.assertItemsEqual(
         expected_layer_constraint, layer_constraints, message)
Exemplo n.º 3
0
 def test_get_exposure_layer_constraint(self):
     """Test for get_exposure_layer_constraint."""
     impact_function = FloodRasterBuildingFunction()
     expected_layer_constraint = [layer_vector_polygon, layer_vector_point]
     layer_constraints \
         = impact_function.metadata().get_exposure_layer_constraint()
     message = 'Expected %s but got %s' % (expected_layer_constraint,
                                           layer_constraints)
     self.assertItemsEqual(expected_layer_constraint, layer_constraints,
                           message)
 def test_get_exposure_layer_constraint(self):
     """Test for get_exposure_layer_constraint."""
     impact_function = FloodRasterBuildingFunction()
     expected_layer_constraint = [
         layer_vector_polygon,
         layer_vector_point
     ]
     layer_constraints \
         = impact_function.metadata().get_exposure_layer_constraint()
     message = 'Expected %s but got %s' % (
         expected_layer_constraint, layer_constraints)
     self.assertItemsEqual(
         expected_layer_constraint, layer_constraints, message)
    def test_run(self):
        impact_function = FloodRasterBuildingFunction.instance()

        hazard_path = standard_data_path('hazard',
                                         'continuous_flood_20_20.asc')
        exposure_path = standard_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 = {1: 64, 2: 117, 3: 0}

        result = {1: 0, 2: 0, 3: 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)
    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)
Exemplo n.º 7
0
 def test_is_valid(self):
     """Test is_valid."""
     impact_functions = [
         # Earthquake
         EarthquakeBuildingFunction(),
         ITBFatalityFunction(),
         PAGFatalityFunction(),
         # Generic
         ClassifiedPolygonHazardBuildingFunction(),
         ClassifiedPolygonHazardPopulationFunction(),
         ClassifiedRasterHazardBuildingFunction(),
         ClassifiedRasterHazardPopulationFunction(),
         ContinuousHazardPopulationFunction(),
         # Inundation
         FloodEvacuationVectorHazardFunction(),
         FloodPolygonRoadsFunction(),
         FloodRasterBuildingFunction(),
         FloodEvacuationRasterHazardFunction(),
         FloodRasterRoadsFunction(),
         FloodPolygonBuildingFunction(),
         TsunamiEvacuationFunction(),
         # Volcanic
         VolcanoPointBuildingFunction(),
         VolcanoPointPopulationFunction(),
         VolcanoPolygonBuildingFunction(),
         VolcanoPolygonPopulationFunction()
     ]
     for impact_function in impact_functions:
         valid = impact_function.metadata().is_valid()
         impact_function_name = impact_function.__class__.__name__
         message = '%s is invalid because %s' % (impact_function_name,
                                                 valid[1])
         self.assertTrue(valid[0], message)
         if valid[0]:
             print '%s has a valid metadata.' % impact_function_name
Exemplo n.º 8
0
    def test_run(self):
        impact_function = FloodRasterBuildingFunction.instance()

        hazard_path = standard_data_path("hazard", "continuous_flood_20_20.asc")
        exposure_path = standard_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 = {1: 64, 2: 117, 3: 0}

        result = {1: 0, 2: 0, 3: 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)
    def test_is_valid(self):
        """Test is_valid."""
        impact_functions = [
            # Earthquake
            EarthquakeBuildingFunction(),
            ITBFatalityFunction(),
            PAGFatalityFunction(),
            ITBBayesianFatalityFunction(),

            # Generic
            ClassifiedPolygonHazardBuildingFunction(),
            ClassifiedPolygonHazardLandCoverFunction(),
            ClassifiedPolygonHazardPopulationFunction(),
            ClassifiedPolygonHazardPolygonPeopleFunction(),
            ClassifiedRasterHazardBuildingFunction(),
            ClassifiedRasterHazardPopulationFunction(),
            ContinuousHazardPopulationFunction(),

            # Inundation
            FloodEvacuationVectorHazardFunction(),
            FloodPolygonRoadsFunction(),
            FloodRasterBuildingFunction(),
            FloodEvacuationRasterHazardFunction(),
            FloodRasterRoadsFunction(),
            FloodPolygonBuildingFunction(),

            # Tsunami
            TsunamiEvacuationFunction(),
            TsunamiRasterRoadsFunction(),
            TsunamiRasterLandcoverFunction(),
            TsunamiRasterBuildingFunction(),

            # Volcanic
            VolcanoPointBuildingFunction(),
            VolcanoPointPopulationFunction(),
            VolcanoPolygonBuildingFunction(),
            VolcanoPolygonPopulationFunction(),

            # Volcanic Ash
            AshRasterLandCoverFunction(),
            AshRasterPlacesFunction(),
            AshRasterPopulationFunction()
        ]
        self.assertEqual(len(impact_functions), len(EXPECTED_IF))

        for impact_function in impact_functions:
            valid = impact_function.metadata().is_valid()
            impact_function_name = impact_function.__class__.__name__
            message = '%s is invalid because %s' % (impact_function_name,
                                                    valid[1])
            self.assertTrue(valid[0], message)
            if valid[0]:
                # print '%s has a valid metadata.' % impact_function_name
                continue
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
    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)
Exemplo n.º 12
0
    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)
Exemplo n.º 13
0
    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)