예제 #1
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
예제 #2
0
    def test_run(self):
        """TestVolcanoPointPopulationFunction: Test running the IF."""
        merapi_point_path = standard_data_path('hazard', 'volcano_point.shp')
        population_path = standard_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 = SafeLayer(merapi_point_layer)
        impact_function.exposure = SafeLayer(population_layer)
        impact_function._prepare()
        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?')
        self.assertEqual(expected_question, impact_function.question)
        # Count by hand
        expected_affected_population = 200
        result = numpy.nansum(impact_layer.get_data())
        self.assertEqual(expected_affected_population, result)
    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)
예제 #4
0
    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 = SafeLayer(merapi_point_layer)
        impact_function.exposure = SafeLayer(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)
    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
 def test_valid_layer_keywords(self):
     """Test for valid_layer_keywords."""
     impact_function = VolcanoPointPopulationFunction()
     layer_keywords = impact_function.metadata().valid_layer_keywords()
     from pprint import pprint
     pprint(layer_keywords)
 def test_valid_layer_keywords(self):
     """Test for valid_layer_keywords. For development."""
     impact_function = VolcanoPointPopulationFunction()
     layer_keywords = impact_function.metadata().valid_layer_keywords()
     from pprint import pprint
     pprint(layer_keywords)