def test_run(self):
        """TestVolcanoPolygonBuildingFunction: Test running the IF."""
        volcano_path = standard_data_path('hazard', 'volcano_krb.shp')
        building_path = standard_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?')
        self.assertEqual(expected_question, impact_function.question)

        # 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)
Example #2
0
    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 = hazard_layer
        impact_function.exposure = 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='zone')
        krb3_zone_count = zone_sum.count('Kawasan Rawan Bencana III')
        krb2_zone_count = zone_sum.count('Kawasan Rawan Bencana II')
        # 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)
    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 = hazard_layer
        impact_function.exposure = 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='zone')
        krb3_zone_count = zone_sum.count('Kawasan Rawan Bencana III')
        krb2_zone_count = zone_sum.count('Kawasan Rawan Bencana II')
        # 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)
Example #4
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
    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_get_layer_requirements(self):
     """Test for get_layer_requirements."""
     impact_function = VolcanoPolygonBuildingFunction()
     layer_req = impact_function.metadata().get_layer_requirements()
     self.assertIsNotNone(layer_req)
     self.assertIsInstance(layer_req, dict)
 def test_get_layer_requirements(self):
     """Test for get_layer_requirements."""
     impact_function = VolcanoPolygonBuildingFunction()
     layer_req = impact_function.metadata().get_layer_requirements()
     self.assertIsNotNone(layer_req)
     self.assertIsInstance(layer_req, dict)