Exemple #1
0
    def test_runFloodPopulationImpactFunction_scaling(self):
        """Flood function runs in GUI with 5x5km population data
           Raster on raster based function runs as expected with scaling."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function='Need evacuation',
            function_id='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        # noinspection PyCallByClass,PyTypeChecker
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult

        # Check numbers are OK (within expected errors from resampling)
        # These are expected impact number
        assert format_int(10484) in myResult, myMessage
        assert format_int(977) in myResult, myMessage
Exemple #2
0
    def test_runFloodPopulationImpactFunction_scaling(self):
        """Flood function runs in GUI with 5x5km population data
           Raster on raster based function runs as expected with scaling."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function='Need evacuation',
            function_id='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        # noinspection PyCallByClass,PyTypeChecker
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult

        # Check numbers are OK (within expected errors from resampling)
        # These are expected impact number
        assert format_int(10484) in myResult, myMessage
        assert format_int(977) in myResult, myMessage
Exemple #3
0
    def test_runEarthquakeBuildingImpactFunction(self):
        """Earthquake function runs in GUI with An earthquake in Yogyakarta
        like in 2006 hazard data uses OSM Building Polygons exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='An earthquake in Yogyakarta like in 2006',
            exposure='OSM Building Polygons',
            function='Be affected',
            function_id='Earthquake Building Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([101, -12, 119, -4])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert format_int(786) in myResult, myMessage
        assert format_int(15528) in myResult, myMessage
        assert format_int(177) in myResult, myMessage
Exemple #4
0
    def test_runCategorisedHazardPopulationImpactFunction(self):
        """Flood function runs in GUI with Flood in Jakarta hazard data
            Uses Penduduk Jakarta as exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Flood in Jakarta',
            exposure='Penduduk Jakarta',
            function='Be impacted',
            function_id='Categorised Hazard Population Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of population might be affected
        assert format_int(30938000) in myResult, myMessage
        assert format_int(68280000) in myResult, myMessage
        assert format_int(157551000) in myResult, myMessage
Exemple #5
0
    def test_runEarthquakeBuildingImpactFunction(self):
        """Earthquake function runs in GUI with An earthquake in Yogyakarta
        like in 2006 hazard data uses OSM Building Polygons exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='An earthquake in Yogyakarta like in 2006',
            exposure='OSM Building Polygons',
            function='Be affected',
            function_id='Earthquake Building Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([101, -12, 119, -4])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert format_int(786) in myResult, myMessage
        assert format_int(15528) in myResult, myMessage
        assert format_int(177) in myResult, myMessage
Exemple #6
0
    def test_runEarthquakeFatalityFunction_small(self):
        """Padang 2009 fatalities estimated correctly (small extent)."""

        # Push OK with the left mouse button
        set_canvas_crs(GEOCRS, True)
        set_padang_extent()

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard=PADANG2009_title,
            exposure='People',
            function='Earthquake Fatality Function',
            function_id='Earthquake Fatality Function')
        assert myResult, myMessage

        DOCK.accept()

        myResult = DOCK.wvResults.page_to_text()

        # Check against expected output
        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: fatality count of '
                     '116 , received: \n %s' % myResult)
        assert format_int(116) in myResult, myMessage

        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: total population count of '
                     '847529 , received: \n %s' % myResult)
        assert format_int(847529) in myResult, myMessage
Exemple #7
0
    def test_runFloodPopulationImpactFunction_scaling(self):
        """Flood function runs in GUI with 5x5km population data
           Raster on raster based function runs as expected with scaling."""

        result, message = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='People',
            function='Need evacuation',
            function_id='Flood Evacuation Function')
        self.assertTrue(result, message)

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        button = DOCK.pbnRunStop
        button.click()
        result = DOCK.wvResults.page_to_text()

        message = 'Result not as expected: %s' % result

        # Check numbers are OK (within expected errors from resampling)
        # These are expected impact number
        self.assertTrue(format_int(10473000) in result, message)
        self.assertTrue(format_int(978000) in result, message)
Exemple #8
0
    def test_runCategorizedHazardBuildingImpact(self):
        """Flood function runs in GUI with Flood in Jakarta hazard data
            Uses DKI buildings exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Flood in Jakarta',
            exposure='Essential buildings',
            function='Be affected',
            function_id='Categorised Hazard Building Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert format_int(535) in myResult, myMessage
        assert format_int(453) in myResult, myMessage
        assert format_int(436) in myResult, myMessage
Exemple #9
0
    def test_runEarthquakeFatalityFunction_small(self):
        """Padang 2009 fatalities estimated correctly (small extent)."""

        # Push OK with the left mouse button
        set_canvas_crs(GEOCRS, True)
        set_padang_extent()

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard=PADANG2009_title,
            exposure='People',
            function='Earthquake Fatality Function',
            function_id='Earthquake Fatality Function')
        assert myResult, myMessage

        DOCK.accept()

        myResult = DOCK.wvResults.page_to_text()

        # Check against expected output
        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: fatality count of '
                     '116 , received: \n %s' % myResult)
        assert format_int(116) in myResult, myMessage

        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: total population count of '
                     '847529 , received: \n %s' % myResult)
        assert format_int(847529) in myResult, myMessage
Exemple #10
0
    def test_runCategorisedHazardPopulationImpactFunction(self):
        """Flood function runs in GUI with Flood in Jakarta hazard data
            Uses Penduduk Jakarta as exposure data."""

        result, message = setup_scenario(
            DOCK,
            hazard='Flood in Jakarta',
            exposure='Penduduk Jakarta',
            function='Be impacted',
            function_id='Categorised Hazard Population Impact Function')
        self.assertTrue(result, message)

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        result = DOCK.wvResults.page_to_text()

        message = ('Result not as expected: %s' % result)
        # This is the expected number of population might be affected
        self.assertTrue(format_int(30938000) in result, message)  # high
        #self.assertTrue(format_int(68280000) in result, message)
        #self.assertTrue(format_int(157551000) in result, message)
        # The 2 asserts above are not valid anymore after the fix we made to
        # CategorisedHazardPopulationImpactFunction
        # Look at the fix here:
        # (https://github.com/AIFDR/inasafe/commit/aa5b3d72145c031c91f4d101b830
        # 8228915c248d#diff-378093670f4ebd60b4487af9b7c2e164)
        # New Asserts
        self.assertTrue(format_int(0) in result, message)  # medium
        self.assertTrue(format_int(256769000) in result, message)  # low
Exemple #11
0
    def test_runCategorisedHazardPopulationImpactFunction(self):
        """Flood function runs in GUI with Flood in Jakarta hazard data
            Uses Penduduk Jakarta as exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Flood in Jakarta',
            exposure='Penduduk Jakarta',
            function='Be impacted',
            function_id='Categorised Hazard Population Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of population might be affected
        assert format_int(30938000) in myResult, myMessage
        assert format_int(68280000) in myResult, myMessage
        assert format_int(157551000) in myResult, myMessage
Exemple #12
0
    def test_runCategorizedHazardBuildingImpact(self):
        """Flood function runs in GUI with Flood in Jakarta hazard data
            Uses DKI buildings exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Flood in Jakarta',
            exposure='Essential buildings',
            function='Be affected',
            function_id='Categorised Hazard Building Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert format_int(535) in myResult, myMessage
        assert format_int(453) in myResult, myMessage
        assert format_int(436) in myResult, myMessage
Exemple #13
0
    def test_runEarthquakeFatalityFunction_Padang_full(self):
        """Padang 2009 fatalities estimated correctly (large extent)"""

        # Push OK with the left mouse button

        button = DOCK.pbnRunStop
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([96, -5, 105, 2])  # This covers all of the 2009 shaking
        message = 'Run button was not enabled'
        self.assertTrue(button.isEnabled(), message)

        # Hazard layers
        index = DOCK.cboHazard.findText(PADANG2009_title)
        self.assertTrue(
            index != -1, 'Padang 2009 scenario hazard layer not found')
        DOCK.cboHazard.setCurrentIndex(index)

        # Exposure layers
        index = DOCK.cboExposure.findText('People')
        self.assertTrue(index != -1, 'People')
        DOCK.cboExposure.setCurrentIndex(index)

        # Choose impact function
        index = DOCK.cboFunction.findText('Earthquake Fatality Function')
        message = (
            'Earthquake Fatality Function not '
            'found: ' + combos_to_string(DOCK))
        self.assertTrue(index != -1, message)
        DOCK.cboFunction.setCurrentIndex(index)

        actual_dict = get_ui_state(DOCK)
        expected_dict = {
            'Hazard': PADANG2009_title,
            'Exposure': 'People',
            'Impact Function Id': 'Earthquake Fatality Function',
            'Impact Function Title': 'Earthquake Fatality Function',
            'Run Button Enabled': True}
        message = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            actual_dict, expected_dict, combos_to_string(DOCK))
        self.assertTrue(actual_dict == expected_dict, message)

        DOCK.accept()

        result = DOCK.wvResults.page_to_text()

        # Check against expected output
        message = (
            'Unexpected result returned for Earthquake Fatality '
            'Function Expected: fatality count of '
            '500 , received: \n %s' % result)
        self.assertTrue(format_int(500) in result, message)

        message = (
            'Unexpected result returned for Earthquake Fatality '
            'Function Expected: total population count of '
            '31374747 , received: \n %s' % result)
        self.assertTrue(format_int(31374747) in result, message)
Exemple #14
0
    def test_runEarthquakeFatalityFunction_Padang_full(self):
        """Padang 2009 fatalities estimated correctly (large extent)"""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([96, -5, 105, 2])  # This covers all of the 2009 shaking
        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        # Hazard layers
        myIndex = DOCK.cboHazard.findText(PADANG2009_title)
        assert myIndex != -1, 'Padang 2009 scenario hazard layer not found'
        DOCK.cboHazard.setCurrentIndex(myIndex)

        # Exposure layers
        myIndex = DOCK.cboExposure.findText('People')
        assert myIndex != -1, 'People'
        DOCK.cboExposure.setCurrentIndex(myIndex)

        # Choose impact function
        myIndex = DOCK.cboFunction.findText('Earthquake Fatality Function')
        myMessage = ('Earthquake Fatality Function not '
                     'found: ' + combos_to_string(DOCK))
        assert myIndex != -1, myMessage
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = get_ui_state(DOCK)
        myExpectedDict = {
            'Hazard': PADANG2009_title,
            'Exposure': 'People',
            'Impact Function Id': 'Earthquake Fatality Function',
            'Impact Function Title': 'Earthquake Fatality Function',
            'Run Button Enabled': True
        }
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            myDict, myExpectedDict, combos_to_string(DOCK))
        assert myDict == myExpectedDict, myMessage

        DOCK.accept()

        myResult = DOCK.wvResults.page_to_text()

        # Check against expected output
        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: fatality count of '
                     '500 , received: \n %s' % myResult)
        assert format_int(500) in myResult, myMessage

        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: total population count of '
                     '31372262 , received: \n %s' % myResult)
        assert format_int(31372262) in myResult, myMessage
Exemple #15
0
    def test_runFloodPopulationImpactFunction(self):
        """Flood function runs in GUI with Jakarta data
           Raster on raster based function runs as expected."""

        # Push OK with the left mouse button
        myButton = DOCK.pbnRunStop

        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='Penduduk Jakarta',
            function='HKVtest',
            function_id='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        # Check that the number is as what was calculated by
        # Marco Hartman form HKV
        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected impact number
        assert format_int(2480) in myResult, myMessage
Exemple #16
0
    def test_runEarthQuakeGuidelinesFunction(self):
        """GUI runs with Shakemap 2009 and Padang Buildings"""

        # Push OK with the left mouse button
        set_canvas_crs(GEOCRS, True)
        set_padang_extent()

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard=PADANG2009_title,
            exposure='Padang WGS84',
            function='Earthquake Guidelines Function',
            function_id='Earthquake Guidelines Function')
        assert myResult, myMessage

        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        # Expected output:
        #Buildings    Total
        #All:    3160
        #Low damage (10-25%):    0
        #Medium damage (25-50%):    0
        #Pre merge of clip on steroids branch:
        #High damage (50-100%):    3160
        # Post merge of clip on steoids branch:
        #High damage (50-100%):    2993
        myMessage = ('Unexpected result returned for Earthquake guidelines'
                     'function. Expected:\n "All" count of 2993, '
                     'received: \n %s' % myResult)
        assert format_int(2993) in myResult, myMessage
Exemple #17
0
    def test_runEarthQuakeGuidelinesFunction(self):
        """GUI runs with Shakemap 2009 and Padang Buildings"""

        # Push OK with the left mouse button
        set_canvas_crs(GEOCRS, True)
        set_padang_extent()

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard=PADANG2009_title,
            exposure='Padang WGS84',
            function='Earthquake Guidelines Function',
            function_id='Earthquake Guidelines Function')
        assert myResult, myMessage

        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        # Expected output:
        #Buildings    Total
        #All:    3160
        #Low damage (10-25%):    0
        #Medium damage (25-50%):    0
        #Pre merge of clip on steroids branch:
        #High damage (50-100%):    3160
        # Post merge of clip on steoids branch:
        #High damage (50-100%):    2993
        myMessage = ('Unexpected result returned for Earthquake guidelines'
                     'function. Expected:\n "All" count of 2993, '
                     'received: \n %s' % myResult)
        assert format_int(2993) in myResult, myMessage
Exemple #18
0
    def test_runFloodPopulationImpactFunction(self):
        """Flood function runs in GUI with Jakarta data
           Raster on raster based function runs as expected."""

        # Push OK with the left mouse button
        myButton = DOCK.pbnRunStop

        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='Penduduk Jakarta',
            function='HKVtest',
            function_id='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        # Check that the number is as what was calculated by
        # Marco Hartman form HKV
        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected impact number
        assert format_int(2480) in myResult, myMessage
Exemple #19
0
    def test_issue160(self):
        """Test that multipart features can be used in a scenario - issue #160
        """

        exposure = os.path.join(
            UNITDATA, 'exposure', 'buildings_osm_4326.shp')
        hazard = os.path.join(
            UNITDATA, 'hazard', 'multipart_polygons_osm_4326.shp')
        # See https://github.com/AIFDR/inasafe/issues/71
        # Push OK with the left mouse button
        #print 'Using QGIS: %s' % qgis_version()
        self.tearDown()
        button = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        file_list = [hazard, exposure]
        hazard_layer_count, exposure_layer_count = load_layers(file_list)

        message = (
            'Incorrect number of Hazard layers: expected 1 got %s'
            % hazard_layer_count)
        self.assertTrue(hazard_layer_count == 1, message)

        message = (
            'Incorrect number of Exposure layers: expected 1 got %s'
            % exposure_layer_count)
        self.assertTrue(exposure_layer_count == 1, message)

        message = 'Run button was not enabled'
        self.assertTrue(button.isEnabled(), message)

        # Second part of scenario - run disabled when adding invalid layer
        # and select it - run should be disabled
        file_list = ['issue71.tif']  # This layer has incorrect keywords
        clear_flag = False
        _, _ = load_layers(file_list, clear_flag)

        result, message = setup_scenario(
            DOCK,
            hazard='multipart_polygons_osm_4326',
            exposure='buildings_osm_4326',
            function='Be flooded',
            function_id='Flood Building Impact Function')
        self.assertTrue(result, message)

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        IFACE.mapCanvas().setExtent(
            QgsRectangle(106.788, -6.193, 106.853, -6.167))

        # Press RUN
        # noinspection PyCallByClass,PyCallByClass,PyTypeChecker
        DOCK.accept()
        result = DOCK.wvResults.page_to_text()

        message = 'Result not as expected: %s' % result
        self.assertTrue(format_int(68) in result, message)
Exemple #20
0
    def test_issue160(self):
        """Test that multipart features can be used in a scenario - issue #160
        """

        myExposure = os.path.join(UNITDATA, 'exposure',
                                  'buildings_osm_4326.shp')
        myHazard = os.path.join(UNITDATA, 'hazard',
                                'multipart_polygons_osm_4326.shp')
        # See https://github.com/AIFDR/inasafe/issues/71
        # Push OK with the left mouse button
        print 'Using QGIS: %s' % qgis_version()
        self.tearDown()
        myButton = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        myFileList = [myHazard, myExposure]
        myHazardLayerCount, myExposureLayerCount = load_layers(myFileList)

        myMessage = ('Incorrect number of Hazard layers: expected 1 got %s' %
                     myHazardLayerCount)
        assert myHazardLayerCount == 1, myMessage

        myMessage = ('Incorrect number of Exposure layers: expected 1 got %s' %
                     myExposureLayerCount)
        assert myExposureLayerCount == 1, myMessage

        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        # Second part of scenario - run disabled when adding invalid layer
        # and select it - run should be disabled
        myFileList = ['issue71.tif']  # This layer has incorrect keywords
        myClearFlag = False
        _, _ = load_layers(myFileList, myClearFlag)

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='multipart_polygons_osm_4326',
            exposure='buildings_osm_4326',
            function='Be flooded',
            function_id='Flood Building Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        IFACE.mapCanvas().setExtent(
            QgsRectangle(106.788, -6.193, 106.853, -6.167))

        # Press RUN
        # noinspection PyCallByClass,PyCallByClass,PyTypeChecker
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        assert format_int(68) in myResult, myMessage
Exemple #21
0
    def test_runTsunamiBuildingImpactFunction(self):
        """Tsunami function runs in GUI as expected."""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Tsunami Max Inundation',
            exposure='Tsunami Building Exposure',
            function='Be flooded',
            function_id='Flood Building Impact Function')
        assert myResult, myMessage

        set_canvas_crs(GEOCRS, True)
        set_batemans_bay_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        #print myResult
        # Post clip on steroids refactor
        # < 1 m:    1923
        # 1 - 3 m:    89
        # > 3 m:    0
        # Post replacement of Batemans Bay dataset
        #< 1 m:  10
        #1 - 3 m:    7
        #> 3 m:  0
        # Post rewrite of impact function
        #Building type	 closed	Total
        #All	        7	                17

        myMessage = 'Result not as expected: %s' % myResult
        assert format_int(17) in myResult, myMessage
        assert format_int(7) in myResult, myMessage
Exemple #22
0
    def test_runTsunamiBuildingImpactFunction(self):
        """Tsunami function runs in GUI as expected."""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Tsunami Max Inundation',
            exposure='Tsunami Building Exposure',
            function='Be flooded',
            function_id='Flood Building Impact Function')
        assert myResult, myMessage

        set_canvas_crs(GEOCRS, True)
        set_batemans_bay_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        #print myResult
        # Post clip on steroids refactor
        # < 1 m:    1923
        # 1 - 3 m:    89
        # > 3 m:    0
        # Post replacement of Batemans Bay dataset
        #< 1 m:  10
        #1 - 3 m:    7
        #> 3 m:  0
        # Post rewrite of impact function
        #Building type	 closed	Total
        #All	        7	                17

        myMessage = 'Result not as expected: %s' % myResult
        assert format_int(17) in myResult, myMessage
        assert format_int(7) in myResult, myMessage
Exemple #23
0
    def test_runVolcanoPopulationImpact(self):
        """Volcano function runs in GUI with a donut (merapi hazard map)
         hazard data uses population density grid."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='donut',
            exposure='People',
            function='Need evacuation',
            function_id='Volcano Polygon Hazard Population')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([110.01, -7.81, 110.78, -7.50])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of people affected
        # Kategori	Jumlah	Kumulatif
        # Kawasan Rawan Bencana III	45.000	45.000
        # Kawasan Rawan Bencana II	84.000	129.000
        # Kawasan Rawan Bencana I	28.000	157.000

        # We could also get a memory error here so there are
        # two plausible outcomes:

        # Outcome 1: we ran out of memory
        if 'system does not have sufficient memory' in myResult:
            return
            # Outcome 2: It ran so check the results
        assert format_int(45) in myResult, myMessage
        assert format_int(84) in myResult, myMessage
        assert format_int(28) in myResult, myMessage
Exemple #24
0
    def test_runVolcanoCirclePopulation(self):
        """Volcano function runs in GUI with a circular evacuation zone.

        Uses population density grid as exposure."""

        # NOTE: We assume radii in impact function to be 3, 5 and 10 km

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Merapi Alert',
            exposure='People',
            function='Need evacuation',
            function_id='Volcano Polygon Hazard Population')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([110.01, -7.81, 110.78, -7.50])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        myMemoryString = 'not have sufficient memory'
        if myMemoryString in myResult:
            # Test host did not have enough memory to run the test
            # and user was given a nice message stating this
            return
            # This is the expected number of people affected
        # Jarak [km]	Jumlah	Kumulatif
        # 3	     15.000	15.000
        # 5	     17.000	32.000
        # 10	124.000	156.000
        assert format_int(15000) in myResult, myMessage
        assert format_int(17000) in myResult, myMessage
        assert format_int(124000) in myResult, myMessage
Exemple #25
0
    def test_runVolcanoPopulationImpact(self):
        """Volcano function runs in GUI with a donut (merapi hazard map)
         hazard data uses population density grid."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='donut',
            exposure='People',
            function='Need evacuation',
            function_id='Volcano Polygon Hazard Population')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([110.01, -7.81, 110.78, -7.50])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of people affected
        # Kategori	Jumlah	Kumulatif
        # Kawasan Rawan Bencana III	45.000	45.000
        # Kawasan Rawan Bencana II	84.000	129.000
        # Kawasan Rawan Bencana I	28.000	157.000

        # We could also get a memory error here so there are
        # two plausible outcomes:

        # Outcome 1: we ran out of memory
        if 'system does not have sufficient memory' in myResult:
            return
            # Outcome 2: It ran so check the results
        assert format_int(45) in myResult, myMessage
        assert format_int(84) in myResult, myMessage
        assert format_int(28) in myResult, myMessage
Exemple #26
0
    def test_runVolcanoCirclePopulation(self):
        """Volcano function runs in GUI with a circular evacuation zone.

        Uses population density grid as exposure."""

        # NOTE: We assume radii in impact function to be 3, 5 and 10 km

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='Merapi Alert',
            exposure='People',
            function='Need evacuation',
            function_id='Volcano Polygon Hazard Population')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([110.01, -7.81, 110.78, -7.50])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        myMemoryString = 'not have sufficient memory'
        if myMemoryString in myResult:
            # Test host did not have enough memory to run the test
            # and user was given a nice message stating this
            return
            # This is the expected number of people affected
        # Jarak [km]	Jumlah	Kumulatif
        # 3	     15.000	15.000
        # 5	     17.000	32.000
        # 10	124.000	156.000
        assert format_int(15000) in myResult, myMessage
        assert format_int(17000) in myResult, myMessage
        assert format_int(124000) in myResult, myMessage
Exemple #27
0
    def test_issue47(self):
        """Issue47: Problem when hazard & exposure data are in different
        proj to viewport.
        See https://github.com/AIFDR/inasafe/issues/47"""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='Penduduk Jakarta',
            function='HKVtest',
            function_id='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GOOGLECRS, True)
        set_jakarta_google_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        assert format_int(2366) in myResult, myMessage
Exemple #28
0
    def test_runFloodPopulationPolygonHazardImpactFunction(self):
        """Flood function runs in GUI with Jakarta polygon flood hazard data.
           Uses population raster exposure layer"""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta',
            exposure='Penduduk Jakarta',
            function='Need evacuation',
            function_id='Flood Evacuation Function Vector Hazard')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of people needing evacuation
        assert format_int(1349000) in myResult, myMessage
Exemple #29
0
    def test_issue47(self):
        """Issue47: Problem when hazard & exposure data are in different
        proj to viewport.
        See https://github.com/AIFDR/inasafe/issues/47"""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta like in 2007',
            exposure='Penduduk Jakarta',
            function='HKVtest',
            function_id='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GOOGLECRS, True)
        set_jakarta_google_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        assert format_int(2366) in myResult, myMessage
Exemple #30
0
    def test_runFloodPopulationPolygonHazardImpactFunction(self):
        """Flood function runs in GUI with Jakarta polygon flood hazard data.
           Uses population raster exposure layer"""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='A flood in Jakarta',
            exposure='Penduduk Jakarta',
            function='Need evacuation',
            function_id='Flood Evacuation Function Vector Hazard')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_jakarta_extent()

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of people needing evacuation
        assert format_int(1349000) in myResult, myMessage
Exemple #31
0
    def test_runVolcanoBuildingImpact(self):
        """Volcano function runs in GUI with An donut (merapi hazard map)
         hazard data uses OSM Building Polygons exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='donut',
            exposure='OSM Building Polygons',
            function='Be affected',
            function_id='Volcano Building Impact')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([110.01, -7.81, 110.78, -7.50])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert format_int(288) in myResult, myMessage
Exemple #32
0
    def test_runVolcanoBuildingImpact(self):
        """Volcano function runs in GUI with An donut (merapi hazard map)
         hazard data uses OSM Building Polygons exposure data."""

        myResult, myMessage = setup_scenario(
            DOCK,
            hazard='donut',
            exposure='OSM Building Polygons',
            function='Be affected',
            function_id='Volcano Building Impact')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        set_canvas_crs(GEOCRS, True)
        set_geo_extent([110.01, -7.81, 110.78, -7.50])

        # Press RUN
        DOCK.accept()
        myResult = DOCK.wvResults.page_to_text()
        LOGGER.debug(myResult)

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert format_int(288) in myResult, myMessage