Example #1
0
    def test_runCategorizedHazardBuildingImpact(self):
        """Flood function runs in GUI with Flood in Jakarta hazard data
            Uses DKI buildings exposure data."""

        myResult, myMessage = setupScenario(
            theHazard='Flood in Jakarta',
            theExposure='DKI buildings',
            theFunction='Be affected',
            theFunctionId='Categorised Hazard Building Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert '535' in myResult, myMessage
        assert '453' in myResult, myMessage
        assert '436' in myResult, myMessage
Example #2
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 = setupScenario(
            theHazard='A flood in Jakarta like in 2007',
            theExposure='Penduduk Jakarta',
            theFunction='HKVtest',
            theFunctionId='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        # 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 '2480' in myResult, myMessage
Example #3
0
    def test_issue45(self):
        """Points near the edge of a raster hazard layer are interpolated OK"""

        myButton = DOCK.pbnRunStop
        setCanvasCrs(GEOCRS, True)
        setYogyaGeoExtent()

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

        myResult, myMessage = setupScenario(
            theHazard='An earthquake in Yogyakarta like in 2006',
            theExposure='OSM Building Polygons',
            theFunction='Earthquake Guidelines Function',
            theFunctionId='Earthquake Guidelines Function')
        assert myResult, myMessage

        # This is the where nosetest sometims hangs when running the
        # guitest suite (Issue #103)
        # The QTest.mouseClick call some times never returns when run
        # with nosetest, but OK when run normally.
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        # Check that none of these  get a NaN value:
        assert 'Unknown' in myResult

        myMessage = ('Some buildings returned by Earthquake guidelines '
                     'function '
                     'had NaN values. Result: \n %s' % myResult)
        assert 'Unknown (NaN):	196' not in myResult, myMessage
Example #4
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 = setupScenario(
            theHazard='A flood in Jakarta like in 2007',
            theExposure='People',
            theFunction='Need evacuation',
            theFunctionId='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

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

        # Check numbers are OK (within expected errors from resampling)
        assert '10484' in myResult, myMessage
        assert '977' in myResult, myMessage  # These are expected impact number
Example #5
0
    def test_issue45(self):
        """Points near the edge of a raster hazard layer are interpolated OK"""

        myButton = DOCK.pbnRunStop
        setCanvasCrs(GEOCRS, True)
        setYogyaGeoExtent()

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

        myResult, myMessage = setupScenario(
            theHazard='An earthquake in Yogyakarta like in 2006',
            theExposure='OSM Building Polygons',
            theFunction='Earthquake Guidelines Function',
            theFunctionId='Earthquake Guidelines Function')
        assert myResult, myMessage

        # This is the where nosetest sometims hangs when running the
        # guitest suite (Issue #103)
        # The QTest.mouseClick call some times never returns when run
        # with nosetest, but OK when run normally.
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        # Check that none of these  get a NaN value:
        assert 'Unknown' in myResult

        myMessage = ('Some buildings returned by Earthquake guidelines '
                     'function '
                     'had NaN values. Result: \n %s' % myResult)
        assert 'Unknown (NaN):	196' not in myResult, myMessage
Example #6
0
    def test_runCategorizedHazardBuildingImpact(self):
        """Flood function runs in GUI with Flood in Jakarta hazard data
            Uses DKI buildings exposure data."""

        myResult, myMessage = setupScenario(
            theHazard='Flood in Jakarta',
            theExposure='DKI buildings',
            theFunction='Be affected',
            theFunctionId='Categorised Hazard Building Impact Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of building might be affected
        assert '535' in myResult, myMessage
        assert '453' in myResult, myMessage
        assert '436' in myResult, myMessage
Example #7
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 = setupScenario(
            theHazard='A flood in Jakarta like in 2007',
            theExposure='Penduduk Jakarta',
            theFunction='HKVtest',
            theFunctionId='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        # 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 '2480' in myResult, myMessage
Example #8
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 = setupScenario(
            theHazard='A flood in Jakarta like in 2007',
            theExposure='People',
            theFunction='Need evacuation',
            theFunctionId='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

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

        # Check numbers are OK (within expected errors from resampling)
        assert '10484' in myResult, myMessage
        assert '977' in myResult, myMessage  # These are expected impact number
Example #9
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

        # Hazard layers
        myIndex = DOCK.cboHazard.findText('Tsunami Max Inundation')
        assert myIndex != -1, 'Tsunami Max Inundation hazard layer not found'
        DOCK.cboHazard.setCurrentIndex(myIndex)

        # Exposure layers
        myIndex = DOCK.cboExposure.findText('Tsunami Building Exposure')
        assert myIndex != -1, 'Tsunami Building Exposure layer not found'
        DOCK.cboExposure.setCurrentIndex(myIndex)

        # Check that layers and impact function are correct
        myDict = getUiState(DOCK)

        myExpectedDict = {
            'Run Button Enabled': True,
            'Impact Function Id': 'Flood Building Impact Function',
            'Impact Function Title': 'Be temporarily closed',
            'Hazard': 'Tsunami Max Inundation',
            'Exposure': 'Tsunami Building Exposure'
        }
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        setCanvasCrs(GEOCRS, True)
        setBatemansBayGeoExtent()

        # Press RUN
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        #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	Temporarily closed	Total
        #All	        7	                17

        myMessage = 'Result not as expected: %s' % myResult
        assert '17' in myResult, myMessage
        assert '7' in myResult, myMessage
Example #10
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

        # Hazard layers
        myIndex = DOCK.cboHazard.findText('Tsunami Max Inundation')
        assert myIndex != -1, 'Tsunami Max Inundation hazard layer not found'
        DOCK.cboHazard.setCurrentIndex(myIndex)

        # Exposure layers
        myIndex = DOCK.cboExposure.findText('Tsunami Building Exposure')
        assert myIndex != -1, 'Tsunami Building Exposure layer not found'
        DOCK.cboExposure.setCurrentIndex(myIndex)

        # Check that layers and impact function are correct
        myDict = getUiState(DOCK)

        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function Id':
                              'Flood Building Impact Function',
                          'Impact Function Title':
                              'Be temporarily closed',
                          'Hazard': 'Tsunami Max Inundation',
                          'Exposure': 'Tsunami Building Exposure'}
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        setCanvasCrs(GEOCRS, True)
        setBatemansBayGeoExtent()

        # Press RUN
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        #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	Temporarily closed	Total
        #All	        7	                17

        myMessage = 'Result not as expected: %s' % myResult
        assert '17' in myResult, myMessage
        assert '7' in myResult, myMessage
Example #11
0
    def test_runEarthquakeFatalityFunction_small(self):
        """Padang 2009 fatalities estimated correctly (small extent)"""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop
        setCanvasCrs(GEOCRS, True)
        setPadangGeoExtent()

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

        # Simulate choosing another combo item and running
        # the model again
        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: ' + combosToString(DOCK))
        assert myIndex != -1, myMessage
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = getUiState(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, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)

        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

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

        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: total population count of '
                     '847529 , received: \n %s' % myResult)
        assert '847529' in myResult, myMessage
Example #12
0
    def test_runEarthquakeFatalityFunction_small(self):
        """Padang 2009 fatalities estimated correctly (small extent)"""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop
        setCanvasCrs(GEOCRS, True)
        setPadangGeoExtent()

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

        # Simulate choosing another combo item and running
        # the model again
        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: ' + combosToString(DOCK))
        assert myIndex != -1, myMessage
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = getUiState(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, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)

        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

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

        myMessage = ('Unexpected result returned for Earthquake Fatality '
                     'Function Expected: total population count of '
                     '847529 , received: \n %s' % myResult)
        assert '847529' in myResult, myMessage
Example #13
0
    def test_issue_160(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' % qgisVersion()
        self.tearDown()
        myButton = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        myFileList = [myHazard, myExposure]
        myHazardLayerCount, myExposureLayerCount = loadLayers(
            myFileList, theDataDirectory=TESTDATA)

        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
        myHazardLayerCount, myExposureLayerCount = (loadLayers(
            myFileList, myClearFlag))

        myResult, myMessage = setupScenario(
            theHazard='multipart_polygons_osm_4326',
            theExposure='buildings_osm_4326',
            theFunction='Be temporarily closed',
            theFunctionId='Flood Building Impact Function')
        assert myResult, myMessage

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

        # Press RUN
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        assert '68' in myResult, myMessage
Example #14
0
    def test_issue_160(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' % qgisVersion()
        self.tearDown()
        myButton = DOCK.pbnRunStop
        # First part of scenario should have enabled run
        myFileList = [myHazard, myExposure]
        myHazardLayerCount, myExposureLayerCount = loadLayers(myFileList,
                                            theDataDirectory=TESTDATA)

        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
        myHazardLayerCount, myExposureLayerCount = (
            loadLayers(myFileList, myClearFlag))

        myResult, myMessage = setupScenario(
            theHazard='multipart_polygons_osm_4326',
            theExposure='buildings_osm_4326',
            theFunction='Be temporarily closed',
            theFunctionId='Flood Building Impact Function')
        assert myResult, myMessage

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

        # Press RUN
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        assert '68' in myResult, myMessage
Example #15
0
 def test_vectorProjections(self):
     """Test that vector input data is reprojected properly during clip"""
     # Input data is OSM in GOOGLE CRS
     # We are reprojecting to GEO and expecting the output shp to be in GEO
     # see https://github.com/AIFDR/inasafe/issues/119
     # and https://github.com/AIFDR/inasafe/issues/95
     myVectorLayer = QgsVectorLayer(VECTOR_PATH2, 'OSM Buildings', 'ogr')
     myMessage = 'Failed to load osm buildings'
     assert myVectorLayer is not None, myMessage
     assert myVectorLayer.isValid()
     setCanvasCrs(GEOCRS, True)
     setJakartaGeoExtent()
     myClipRect = [106.52, -6.38, 107.14, -6.07]
     # Clip the vector to the bbox
     myResult = clipLayer(myVectorLayer, myClipRect)
     assert (os.path.exists(myResult))
Example #16
0
    def test_clipVectorHard(self):
        """Vector layers can be hard clipped.

        Hard clipping will remove any dangling, non intersecting elements.
        """
        myVectorLayer = QgsVectorLayer(VECTOR_PATH3, 'OSM Buildings', 'ogr')
        myMessage = 'Failed to load osm buildings'
        assert myVectorLayer is not None, myMessage
        assert myVectorLayer.isValid()
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()
        myClipRect = [106.8218, -6.1842, 106.8232, -6.1830]

        # Clip the vector to the bbox
        myResult = clipLayer(myVectorLayer, myClipRect, theHardClipFlag=True)

        # Check the output is valid
        assert (os.path.exists(myResult))
Example #17
0
 def test_vectorProjections(self):
     """Test that vector input data is reprojected properly during clip"""
     # Input data is OSM in GOOGLE CRS
     # We are reprojecting to GEO and expecting the output shp to be in GEO
     # see https://github.com/AIFDR/inasafe/issues/119
     # and https://github.com/AIFDR/inasafe/issues/95
     myVectorLayer = QgsVectorLayer(VECTOR_PATH2,
                                    'OSM Buildings',
                                    'ogr')
     myMessage = 'Failed to load osm buildings'
     assert myVectorLayer is not None, myMessage
     assert myVectorLayer.isValid()
     setCanvasCrs(GEOCRS, True)
     setJakartaGeoExtent()
     myClipRect = [106.52, -6.38, 107.14, -6.07]
     # Clip the vector to the bbox
     myResult = clipLayer(myVectorLayer, myClipRect)
     assert(os.path.exists(myResult))
Example #18
0
    def test_ResultStyling(self):
        """Test that ouputs from a model are correctly styled (colours and
        opacity. """

        # Push OK with the left mouse button

        print '--------------------'
        print combosToString(DOCK)

        myResult, myMessage = setupScenario(
            theHazard=('A flood in Jakarta like in 2007'),
            theExposure='People',
            theFunction='Need evacuation',
            theFunctionId='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Run manually so we can get the output layer
        DOCK.setupCalculator()
        myRunner = DOCK.calculator.getRunner()
        myRunner.run()  # Run in same thread
        myEngineImpactLayer = myRunner.impactLayer()
        myQgisImpactLayer = DOCK.readImpactLayer(myEngineImpactLayer)
        myStyle = myEngineImpactLayer.get_style_info()
        #print myStyle
        setRasterStyle(myQgisImpactLayer, myStyle)
        # simple test for now - we could test explicity for style state
        # later if needed.
        myMessage = ('Raster layer was not assigned a ColorRampShader'
                     ' as expected.')
        assert myQgisImpactLayer.colorShadingAlgorithm() == \
                QgsRasterLayer.ColorRampShader, myMessage

        myMessage = ('Raster layer was not assigned transparency'
                     'classes as expected.')
        myTransparencyList = (myQgisImpactLayer.rasterTransparency().
                              transparentSingleValuePixelList())
        #print "Transparency list:" + str(myTransparencyList)
        assert (len(myTransparencyList) > 0)
Example #19
0
    def test_ResultStyling(self):
        """Test that ouputs from a model are correctly styled (colours and
        opacity. """

        # Push OK with the left mouse button

        print '--------------------'
        print combosToString(DOCK)

        myResult, myMessage = setupScenario(
            theHazard=('A flood in Jakarta like in 2007'),
            theExposure='People',
            theFunction='Need evacuation',
            theFunctionId='Flood Evacuation Function')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Run manually so we can get the output layer
        DOCK.setupCalculator()
        myRunner = DOCK.calculator.getRunner()
        myRunner.run()  # Run in same thread
        myEngineImpactLayer = myRunner.impactLayer()
        myQgisImpactLayer = DOCK.readImpactLayer(myEngineImpactLayer)
        myStyle = myEngineImpactLayer.get_style_info()
        #print myStyle
        setRasterStyle(myQgisImpactLayer, myStyle)
        # simple test for now - we could test explicity for style state
        # later if needed.
        myMessage = ('Raster layer was not assigned a ColorRampShader'
                     ' as expected.')
        assert myQgisImpactLayer.colorShadingAlgorithm() == \
                QgsRasterLayer.ColorRampShader, myMessage

        myMessage = ('Raster layer was not assigned transparency'
                     'classes as expected.')
        myTransparencyList = (myQgisImpactLayer.rasterTransparency().
                transparentSingleValuePixelList())
        #print "Transparency list:" + str(myTransparencyList)
        assert (len(myTransparencyList) > 0)
Example #20
0
    def test_clipVectorHard(self):
        """Vector layers can be hard clipped.

        Hard clipping will remove any dangling, non intersecting elements.
        """
        myVectorLayer = QgsVectorLayer(VECTOR_PATH3,
                                       'OSM Buildings',
                                       'ogr')
        myMessage = 'Failed to load osm buildings'
        assert myVectorLayer is not None, myMessage
        assert myVectorLayer.isValid()
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()
        myClipRect = [106.8218, -6.1842, 106.8232, -6.1830]

        # Clip the vector to the bbox
        myResult = clipLayer(myVectorLayer, myClipRect, theHardClipFlag=True)

        # Check the output is valid
        assert(os.path.exists(myResult))
Example #21
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 = setupScenario(
            theHazard='A flood in Jakarta like in 2007',
            theExposure='Penduduk Jakarta',
            theFunction='HKVtest',
            theFunctionId='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GOOGLECRS, True)
        setJakartaGoogleExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        assert '2366' in myResult, myMessage
Example #22
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 = setupScenario(
            theHazard='A flood in Jakarta like in 2007',
            theExposure='Penduduk Jakarta',
            theFunction='HKVtest',
            theFunctionId='HKVtest')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GOOGLECRS, True)
        setJakartaGoogleExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

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

        myResult, myMessage = setupScenario(
            theHazard=('A flood in Jakarta in RW areas identified'
                       ' as flood prone'),
            theExposure='Penduduk Jakarta',
            theFunction='Need evacuation',
            theFunctionId='Flood Evacuation Function Vector Hazard')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of people needing evacuation
        assert '134953000' in myResult, myMessage
Example #24
0
    def test_runFloodPopulationPolygonHazardImpactFunction(self):
        """Flood function runs in GUI with Jakarta polygon flood hazard data.
           Uses population raster exposure layer"""

        myResult, myMessage = setupScenario(
            theHazard=('A flood in Jakarta in RW areas identified'
                      ' as flood prone'),
            theExposure='Penduduk Jakarta',
            theFunction='Need evacuation',
            theFunctionId='Flood Evacuation Function Vector Hazard')
        assert myResult, myMessage

        # Enable on-the-fly reprojection
        setCanvasCrs(GEOCRS, True)
        setJakartaGeoExtent()

        # Press RUN
        myButton = DOCK.pbnRunStop
        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()

        myMessage = 'Result not as expected: %s' % myResult
        # This is the expected number of people needing evacuation
        assert '134953000' in myResult, myMessage
Example #25
0
    def test_runEarthQuakeGuidelinesFunction(self):
        """GUI runs with Shakemap 2009 and Padang Buildings"""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop
        setCanvasCrs(GEOCRS, True)
        setPadangGeoExtent()
        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        #QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Enter)
        #
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

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

        # Exposure layer
        myIndex = DOCK.cboExposure.findText('Padang_WGS84')
        myMessage = ('Could not find layer Padang_WGS84:\n'
                     '%s' % (combosToString(DOCK)))
        assert myIndex != -1, myMessage
        DOCK.cboExposure.setCurrentIndex(myIndex)

        # Impact function
        myIndex = DOCK.cboFunction.findText('Earthquake Guidelines Function')
        myMessage = ('Earthquake Guidelines function not '
                     'found: ' + combosToString(DOCK))
        assert myIndex != -1, myMessage
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = getUiState(DOCK)
        myExpectedDict = {
            'Hazard': PADANG2009_title,
            'Exposure': 'Padang_WGS84',
            'Impact Function Id': 'Earthquake Guidelines Function',
            'Impact Function Title': 'Earthquake Guidelines Function',
            'Run Button Enabled': True
        }
        myMessage = 'Got:\n %s\nExpected:\n%s\n%s' % (myDict, myExpectedDict,
                                                      combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()
        # 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 '2993' in myResult, myMessage
Example #26
0
    def test_runEarthQuakeGuidelinesFunction(self):
        """GUI runs with Shakemap 2009 and Padang Buildings"""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop
        setCanvasCrs(GEOCRS, True)
        setPadangGeoExtent()
        myMessage = 'Run button was not enabled'
        assert myButton.isEnabled(), myMessage

        #QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Enter)
        #
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

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

        # Exposure layer
        myIndex = DOCK.cboExposure.findText('Padang_WGS84')
        myMessage = ('Could not find layer Padang_WGS84:\n'
                     '%s' % (combosToString(DOCK)))
        assert myIndex != -1, myMessage
        DOCK.cboExposure.setCurrentIndex(myIndex)

        # Impact function
        myIndex = DOCK.cboFunction.findText('Earthquake Guidelines Function')
        myMessage = ('Earthquake Guidelines function not '
               'found: ' + combosToString(DOCK))
        assert myIndex != -1, myMessage
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = getUiState(DOCK)
        myExpectedDict = {'Hazard': PADANG2009_title,
                          'Exposure': 'Padang_WGS84',
                          'Impact Function Id':
                              'Earthquake Guidelines Function',
                          'Impact Function Title':
                              'Earthquake Guidelines Function',
                          'Run Button Enabled': True}
        myMessage = 'Got:\n %s\nExpected:\n%s\n%s' % (
                        myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

        QTest.mouseClick(myButton, QtCore.Qt.LeftButton)
        myResult = DOCK.wvResults.page().currentFrame().toPlainText()
        # 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 '2993' in myResult, myMessage