def test_run(self):
        """TestEarthquakeBuildingFunction: Test running the IF."""
        eq_path = test_data_path("hazard", "earthquake.tif")
        building_path = test_data_path("exposure", "buildings.shp")

        eq_layer = read_layer(eq_path)
        building_layer = read_layer(building_path)

        impact_function = EarthquakeBuildingFunction.instance()
        impact_function.hazard = SafeLayer(eq_layer)
        impact_function.exposure = SafeLayer(building_layer)
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = "In the event of earthquake 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)
        # Count by hand,
        # 1 = low, 2 = medium, 3 = high
        impact = {1: 0, 2: 181, 3: 0}
        result = {1: 0, 2: 0, 3: 0}
        impact_features = impact_layer.get_data()
        for i in range(len(impact_features)):
            impact_feature = impact_features[i]
            level = impact_feature.get(impact_function.target_field)
            result[level] += 1

        message = "Expecting %s, but it returns %s" % (impact, result)
        self.assertEqual(impact, result, message)
Пример #2
0
    def test_run(self):
        """TestEarthquakeBuildingFunction: Test running the IF."""
        eq_path = test_data_path('hazard', 'earthquake.tif')
        building_path = test_data_path('exposure', 'buildings.shp')

        eq_layer = read_layer(eq_path)
        building_layer = read_layer(building_path)

        impact_function = EarthquakeBuildingFunction.instance()
        impact_function.hazard = eq_layer
        impact_function.exposure = building_layer
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = ('In the event of earthquake 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)
        # Count by hand,
        # 1 = low, 2 = medium, 3 = high
        impact = {1: 0, 2: 181, 3: 0}
        result = {1: 0, 2: 0, 3: 0}
        impact_features = impact_layer.get_data()
        for i in range(len(impact_features)):
            impact_feature = impact_features[i]
            level = impact_feature.get('Shake_cls')
            result[level] += 1

        message = 'Expecting %s, but it returns %s' % (impact, result)
        self.assertEqual(impact, result, message)
Пример #3
0
    def test_calculate_impact(self):
        """Test calculating impact."""
        eq_path = test_data_path('hazard', 'earthquake.tif')
        building_path = test_data_path('exposure', 'buildings.shp')

        eq_layer = read_layer(eq_path)
        building_layer = read_layer(building_path)

        impact_function = EarthquakeBuildingFunction.instance()
        impact_function.hazard = SafeLayer(eq_layer)
        impact_function.exposure = SafeLayer(building_layer)
        impact_layer = calculate_impact(impact_function)

        self.assertIsNotNone(impact_layer)
Пример #4
0
    def test_calculate_impact(self):
        """Test calculating impact."""
        eq_path = test_data_path('hazard', 'earthquake.tif')
        building_path = test_data_path('exposure', 'buildings.shp')

        eq_layer = read_layer(eq_path)
        building_layer = read_layer(building_path)

        impact_function = EarthquakeBuildingFunction.instance()
        impact_function.hazard = SafeLayer(eq_layer)
        impact_function.exposure = SafeLayer(building_layer)
        impact_layer = calculate_impact(impact_function)

        self.assertIsNotNone(impact_layer)
    def test_run(self):
        """TestEarthquakeBuildingFunction: Test running the IF."""
        eq_path = test_data_path('hazard', 'earthquake.tif')
        building_path = test_data_path(
            'exposure', 'buildings.shp')

        eq_layer = read_layer(eq_path)
        building_layer = read_layer(building_path)

        impact_function = EarthquakeBuildingFunction.instance()
        impact_function.hazard = eq_layer
        impact_function.exposure = building_layer
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = ('In the event of earthquake 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)
        # Count by hand,
        # 1 = low, 2 = medium, 3 = high
        impact = {
            1: 0,
            2: 181,
            3: 0
        }
        result = {
            1: 0,
            2: 0,
            3: 0
        }
        impact_features = impact_layer.get_data()
        for i in range(len(impact_features)):
            impact_feature = impact_features[i]
            level = impact_feature.get('Shake_cls')
            result[level] += 1

        message = 'Expecting %s, but it returns %s' % (impact, result)
        self.assertEqual(impact, result, message)
Пример #6
0
    def test_run(self):
        """TestEarthquakeBuildingFunction: Test running the IF."""
        eq_path = standard_data_path('hazard', 'earthquake.tif')
        building_path = standard_data_path('exposure', 'buildings.shp')

        eq_layer = read_layer(eq_path)
        building_layer = read_layer(building_path)

        impact_function = EarthquakeBuildingFunction.instance()
        impact_function.hazard = SafeLayer(eq_layer)
        impact_function.exposure = SafeLayer(building_layer)
        impact_function.run()
        impact_layer = impact_function.impact
        # Check the question
        expected_question = (
            'In the event of earthquake how many buildings might be affected?')
        self.assertEqual(expected_question, impact_function.question)
        # Count by hand,
        # 1 = low, 2 = medium, 3 = high
        impact = {
            1: 0,
            2: 181,
            3: 0
        }
        result = {
            1: 0,
            2: 0,
            3: 0
        }
        impact_features = impact_layer.get_data()
        for i in range(len(impact_features)):
            impact_feature = impact_features[i]
            level = impact_feature.get(impact_function.target_field)
            result[level] += 1

        message = 'Expecting %s, but it returns %s' % (impact, result)
        self.assertEqual(impact, result, message)

        # Check the mixin works too...
        self.maxDiff = None
        action_checklist = impact_function.action_checklist()
        expected = [
            'Which structures have warning capacity (eg. sirens, speakers, '
            'etc.)?',
            'Are the water and electricity services still operating?',
            'Are the health centres still open?',
            'Are the other public services accessible?',
            'Which buildings will be evacuation centres?',
            'Where will we locate the operations centre?',
            'Where will we locate warehouse and/or distribution centres?',
            'Are the schools and hospitals still active?'
        ]
        self.assertListEqual(expected, action_checklist)

        not_expected = [
            'Where will the students from the 0 closed schools go to study?',
            'Where will the patients from the 0 closed hospitals go for '
            'treatment and how will we transport them?',
        ]
        for item in not_expected:
            self.assertNotIn(item, action_checklist)