Exemplo n.º 1
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('Padang 2009 scenario')
        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')
        msg = ('Earthquake Guidelines function not '
               'found: ' + combosToString(DOCK))
        assert myIndex != -1, msg
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = getUiState(DOCK)
        myExpectedDict = {'Hazard': 'Padang 2009 scenario',
                          'Exposure': 'Padang_WGS84',
                          'Impact Function': '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
Exemplo n.º 2
0
    def test_runTsunamiBuildingImpactFunction(self):
        """Tsunami function runs in GUI with Batemans Bay model"""
        """Raster and vector 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

        # 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': 'Flood Building Impact Function',
                          '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
Exemplo n.º 3
0
    def test_ResultStyling(self):
        """Test that ouputs from a model are correctly styled (colours and
        opacity. """

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

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

        # Hazard layers -already set to correct entry
        # Exposure layers - set to Penduduk Jakarta
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact function (second item in the list)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)
        myFunction = DOCK.cboFunction.currentText()
        myMessage = ('Incorrect function selected - expected Terdampak,'
                     ' got %s \n%s'
                     % (myFunction, combosToString(DOCK)))
        assert myFunction == 'Need evacuation', 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)
Exemplo n.º 4
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('Padang 2009 scenario')
        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')
        msg = ('Earthquake Fatality Function not '
               'found: ' + combosToString(DOCK))
        assert myIndex != -1, msg
        DOCK.cboFunction.setCurrentIndex(myIndex)

        myDict = getUiState(DOCK)
        myExpectedDict = {'Hazard': 'Padang 2009 scenario',
                          'Exposure': 'People',
                          'Impact Function': '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
Exemplo n.º 5
0
    def test_runTsunamiBuildingImpactFunction(self):
        """Tsunami function runs in GUI with Batemans Bay model"""
        """Raster and vector 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

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

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

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

        myExpectedDict = {'Run Button Enabled': True,
                        'Impact Function': 'Tsunami Building Impact Function',
                        'Hazard': 'tsunami_max_inundation_depth_BB_utm',
                        'Exposure': 'tsunami_exposure_BB'}
        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
        myMessage = 'Result not as expected: %s' % myResult
        assert '1923' in myResult, myMessage
        assert '89' in myResult, myMessage
        assert '0' in myResult, myMessage
Exemplo n.º 6
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"""

        myButton = DOCK.pbnRunStop
        myDict = getUiState(DOCK)
        myMessage = 'Run button was not enabled - UI State: %s\n%s' % (
                        myDict, combosToString(DOCK))
        assert myButton.isEnabled(), myMessage

        # Hazard layers - already on correct entry
        # Hazard layers - default is already Jakarta 2007 flood
        myIndex = DOCK.cboHazard.findText('Jakarta 2007 flood')
        msg = 'Jakarta 2007 flood hazard layer not found.'
        assert myIndex != -1, msg
        DOCK.cboHazard.setCurrentIndex(myIndex)

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

        # Choose impact function - HKVtest
        myIndex = DOCK.cboFunction.findText('HKVtest')
        msg = ('HKVtest impact function not '
               'found: ' + combosToString(DOCK))
        assert myIndex != -1, msg
        DOCK.cboFunction.setCurrentIndex(myIndex)

        # Check that layers and impact function are correct
        myDict = getUiState(DOCK)
        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function': 'HKVtest',
                          'Hazard': 'Jakarta 2007 flood',
                          'Exposure': 'Penduduk Jakarta'}
        myMessage = 'Got: %s\nExpected: %s \n%s' % (
                        myDict, str(myExpectedDict), combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

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

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

        myMessage = 'Result not as expected: %s' % myResult
        assert '2366' in myResult, myMessage
Exemplo n.º 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."""

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

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

        # Hazard layers use default - Banjir Jakarta seperti 2007

        # Exposure layers - Population Density Estimate (5kmx5km)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact function Terdampak
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)

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

        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function': 'Flood Evacuation Function',
                          'Hazard': 'Jakarta 2007 flood',
                          'Exposure': 'People'}
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
                            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

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

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

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

        # Check numbers are OK (within expected errors from resampling)
        assert '10484' in myResult, msg
        assert '977' in myResult, msg  # These are expected impact number
Exemplo n.º 8
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
        # set hazard to Shakemap_Padang_2009
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboHazard, QtCore.Qt.Key_Enter)
        # set exposure to Population Density Estimate (5kmx5km)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        myDict = getUiState(DOCK)
        myExpectedDict = {'Hazard': 'Shakemap_Padang_2009',
                        'Exposure': 'Population Density Estimate (5kmx5km)',
                        'Impact Function': '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
Exemplo n.º 9
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

        # Hazard layers  -Yogya2006
        myIndex = DOCK.cboHazard.findText('Yogya 2006 scenario')
        assert myIndex != -1, 'Yogya 2006 scenario hazard layer not found'
        DOCK.cboHazard.setCurrentIndex(myIndex)
        # Exposure layers - OSM Building Polygons
        myIndex = DOCK.cboExposure.findText('OSM Building Polygons')
        assert myIndex != -1, 'OSM Building Polygons exposure layer not found'
        DOCK.cboExposure.setCurrentIndex(myIndex)
        # Choose impact function
        # QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)

        # Check that layers and impact function are correct
        myDict = getUiState(DOCK)
        myExpectedDict = {'Hazard': 'Yogya 2006 scenario',
                          'Exposure': 'OSM Building Polygons',
                          'Impact Function': 'Earthquake Guidelines Function',
                          'Run Button Enabled': True}
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
                            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, 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
Exemplo n.º 10
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))
Exemplo n.º 11
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"""

        myButton = DOCK.pbnRunStop
        myDict = getUiState(DOCK)
        myMessage = 'Run button was not enabled - UI State: %s\n%s' % (
                        myDict, combosToString(DOCK))
        assert myButton.isEnabled(), myMessage

        # Hazard layers - already on correct entry
        # Exposure layers
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact function (second item in the list)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)

        # Check that layers and impact function are correct
        myDict = getUiState(DOCK)
        myExpectedDict = {'Run Button Enabled': True,
                        'Impact Function': 'Terdampak',
                        'Hazard': 'Banjir Jakarta seperti 2007',
                        'Exposure': 'Penduduk Jakarta'}
        myMessage = 'Got: %s\nExpected: %s \n%s' % (
                        myDict, str(myExpectedDict), combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

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

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

        myMessage = 'Result not as expected: %s' % myResult
        #Terdampak (x 1000):    2366
        assert '2366' in myResult, myMessage
Exemplo n.º 12
0
    def test_issue_160(self):
        """Test that multipart features can be used in a scenario - issue #160
        """
        myTestDataDir = os.path.join(os.path.dirname(__file__), '..',
                                     'unit_test_data')
        myExposure = os.path.join('exposure', 'buildings_osm_4326.shp')
        myHazard = os.path.join('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,
                                                            DIR=myTestDataDir)

        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))
        # Hazard layers  -multipart_polygons_4326
        myIndex = DOCK.cboHazard.findText('multipart_polygons_osm_4326')
        assert myIndex != -1, 'multipart_polygons_4326 hazard layer not found'
        DOCK.cboHazard.setCurrentIndex(myIndex)
        # Exposure layers - buildings_osm_4326
        myIndex = DOCK.cboExposure.findText('buildings_osm_4326')
        assert myIndex != -1, 'buildings_osm_4326 exposure layer not found'
        DOCK.cboExposure.setCurrentIndex(myIndex)
        myDict = getUiState(DOCK)
        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function': 'Flood Building Impact Function',
                          'Hazard': 'multipart_polygons_osm_4326',
                          'Exposure': 'buildings_osm_4326'}
        myMessage = ('Run button was not disabled when exposure set to \n%s'
                     '\nUI State: \n%s\nExpected State:\n%s\n%s') % (
            DOCK.cboExposure.currentText(),
            myDict,
            myExpectedDict,
            combosToString(DOCK))

        assert myExpectedDict == myDict, 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
Exemplo n.º 13
0
    def test_runFloodPopulationImpactFunction(self):
        """Flood function runs in GUI with Jakarta data
           Raster on raster based function runs as expected."""

        # FIXME (Ole):
        # Temporarily disabled as it was depending on old scaling method
        # specific to this dataset. After cleaning up the 'official'
        # impact function, this one doesn't work. Use instead
        # HKV impact function in engine/impact_functions_for_testing

        # Push OK with the left mouse button

        myButton = DOCK.pbnRunStop

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

        # Hazard layers - default is already Banjir Jakarta seperti 2007
        myIndex = DOCK.cboHazard.findText('Jakarta 2007 flood')
        msg = 'Jakarta 2007 flood hazard layer not found'
        assert myIndex != -1, msg
        DOCK.cboHazard.setCurrentIndex(myIndex)

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

        # Choose impact function - HKVtest
        myIndex = DOCK.cboFunction.findText('HKVtest')
        msg = ('HKVtest impact function not '
               'found: ' + combosToString(DOCK))
        assert myIndex != -1, msg
        DOCK.cboFunction.setCurrentIndex(myIndex)

        # Exposure layers - Penduduk Jakarta
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact Terdampak
        #QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        #QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)

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

        myExpectedDict = {'Run Button Enabled': True,
                          'Impact Function': 'HKVtest',
                          'Hazard': 'Jakarta 2007 flood',
                          'Exposure': 'Penduduk Jakarta'}
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
                            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, 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
        msg = 'Result not as expected: %s' % myResult
        assert '2480' in myResult, msg  # This is the expected impact number
Exemplo n.º 14
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

        # Hazard layers - default is already Banjir Jakarta seperti 2007

        # Exposure layers - Penduduk Jakarta
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboExposure, QtCore.Qt.Key_Enter)

        # Choose impact Terdampak
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Down)
        QTest.keyClick(DOCK.cboFunction, QtCore.Qt.Key_Enter)

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

        myExpectedDict = {'Run Button Enabled': True,
                        'Impact Function': 'Terdampak',
                        'Hazard': 'Banjir Jakarta seperti 2007',
                        'Exposure': 'Penduduk Jakarta'}
        myMessage = 'Got unexpected state: %s\nExpected: %s\n%s' % (
                            myDict, myExpectedDict, combosToString(DOCK))
        assert myDict == myExpectedDict, myMessage

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

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

        #Apabila terjadi "Flood Depth (current) Jakarta"
        # perkiraan dampak terhadap "clip_CCaFFQ" kemungkinan yang terjadi:
        #Terdampak (x 1000):    1

        # Pre clipping fix scores:

        #Catatan:
        #- Jumlah penduduk Jakarta 2 <-- should be about 8000
        #- Jumlah dalam ribuan
        #- Penduduk dianggap terdampak ketika banjir
        #lebih dari 0.1 m.  <-- expecting around 2400
        #Terdampak (x 1000): 2479

        # Post clipping fix scores

        #Catatan:
        #- Jumlah penduduk Jakarta 356018
        #- Jumlah dalam ribuan
        #- Penduduk dianggap terdampak ketika banjir lebih dari 0.1 m.
        #print myResult

        msg = 'Result not as expected: %s' % myResult
        assert '2480' in myResult, msg  # This is the expected impact number