def execute(self, args):
        try:
            if len(args) != 3:
                pluginHost.showFeedback(
                    "Incorrect number of arguments given to tool.")
                return

            inputfile = args[0]
            outputfile = args[1]
            backgroundVal = 0.0

            # fill the depressions in the DEM, being sure to
            # run on a dedicated thread and supressing
            # the return data (automatically displayed image)
            args2 = [inputfile, outputfile, "0.0"]
            pluginHost.runPlugin("FillDepressions", args2, False, True)

            # measure the depth in sink.
            inputraster = WhiteboxRaster(inputfile, 'r')
            outputraster = WhiteboxRaster(outputfile, 'rw')
            rows = outputraster.getNumberRows()
            cols = outputraster.getNumberColumns()
            nodata = inputraster.getNoDataValue()

            if args[2] == "true":
                backgroundVal = nodata
                outputraster.setPreferredPalette("spectrum.plt")
            else:
                outputraster.setPreferredPalette(
                    "spectrum_black_background.plt")

            oldprogress = -1
            for row in xrange(0, rows):
                for col in xrange(0, cols):
                    z1 = inputraster.getValue(row, col)
                    z2 = outputraster.getValue(row, col)
                    if z1 != nodata:
                        if z1 < z2:
                            outputraster.setValue(row, col, z2 - z1)
                        else:
                            outputraster.setValue(row, col, backgroundVal)
                    else:
                        outputraster.setValue(row, col, nodata)

                progress = (int)(100.0 * row / (rows - 1))
                if progress > oldprogress:
                    oldprogress = progress
                    pluginHost.updateProgress(progress)
                if pluginHost.isRequestForOperationCancelSet():
                    pluginHost.showFeedback("Operation cancelled")
                    return

            inputraster.close()

            outputraster.flush()
            outputraster.findMinAndMaxVals()
            outputraster.setDisplayMinimum(outputraster.getMinimumValue())
            outputraster.setDisplayMaximum(outputraster.getMaximumValue())
            outputraster.close()

            # display the final output
            pluginHost.returnData(outputfile)

            pluginHost.updateProgress(0)

        except Exception, e:
            pluginHost.logException("Error in DepthInSink", e)
            pluginHost.showFeedback("Error during script execution.")
            return
	def execute(self, args):
		try:
			if len(args) != 3:
				pluginHost.showFeedback("Incorrect number of arguments given to tool.")
				return
                
			inputfile = args[0]
			outputfile = args[1]
			backgroundVal = 0.0
				
			# fill the depressions in the DEM, being sure to 
			# run on a dedicated thread and supressing
			# the return data (automatically displayed image)
			args2 = [inputfile, outputfile, "0.0"]
			pluginHost.runPlugin("FillDepressions", args2, False, True)

			# measure the depth in sink.
			inputraster = WhiteboxRaster(inputfile, 'r')
			outputraster = WhiteboxRaster(outputfile, 'rw')
			rows = outputraster.getNumberRows()
			cols = outputraster.getNumberColumns()
			nodata = inputraster.getNoDataValue()
			
			if args[2] == "true":
				backgroundVal = nodata
				outputraster.setPreferredPalette("spectrum.plt")
			else:
				outputraster.setPreferredPalette("spectrum_black_background.plt")
			
			oldprogress = -1
			for row in xrange(0, rows):
				for col in xrange(0, cols):
					z1 = inputraster.getValue(row, col)
					z2 = outputraster.getValue(row, col)
					if z1 != nodata:
						if z1 < z2:
							outputraster.setValue(row, col, z2 - z1)
						else:
							outputraster.setValue(row, col, backgroundVal)
					else:
						outputraster.setValue(row, col, nodata)
				
				progress = (int)(100.0 * row / (rows - 1))
				if progress > oldprogress:
					oldprogress = progress
					pluginHost.updateProgress(progress)
				if pluginHost.isRequestForOperationCancelSet():
					pluginHost.showFeedback("Operation cancelled")
					return
			
			inputraster.close()

			outputraster.flush()
			outputraster.findMinAndMaxVals()
			outputraster.setDisplayMinimum(outputraster.getMinimumValue())
			outputraster.setDisplayMaximum(outputraster.getMaximumValue())
			outputraster.close()
			
			# display the final output
			pluginHost.returnData(outputfile)

			pluginHost.updateProgress(0)
			
		except Exception, e:
			pluginHost.logException("Error in DepthInSink", e)
			pluginHost.showFeedback("Error during script execution.")
			return