コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
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
コード例 #4
0
    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
コード例 #5
0
    def test_run_failed(self):
        """Test run IF with missing keywords."""
        merapi_krb_path = standard_data_path('hazard', 'volcano_krb.shp')
        population_path = standard_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
        layer = SafeLayer(merapi_krb_layer)
        layer.keywords = {}
        impact_function.hazard = layer
        impact_function.exposure = SafeLayer(population_layer)
        self.assertRaises(KeywordNotFoundError, impact_function.run)
コード例 #6
0
    def test_run_failed(self):
        """Test run IF with missing keywords."""
        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
        layer = SafeLayer(merapi_krb_layer)
        layer.keywords = {}
        impact_function.hazard = layer
        impact_function.exposure = SafeLayer(population_layer)
        self.assertRaises(KeywordNotFoundError, impact_function.run)