Hello,
Ā
You can replicate what you would like to do easily using a Whitebox Workflows for Python script such as the following:
Ā
import time
from whitebox_workflows import WbEnvironment
Ā
wbe = WbEnvironment()
start = time.time()
try:
Ā Ā Ā wbe.verbose = True
Ā Ā Ā wbe.working_directory = 'path/to/your/data'
Ā
Ā Ā Ā decrement_value = 20.0 # Set this to whatever value you wish to lower streams by
Ā
Ā Ā Ā # Read in the DEM and streams vector
Ā Ā Ā dem = wbe.read_raster('your_DEM.tif')
Ā Ā Ā streams = wbe.read_vector('your_streams.shp')
Ā
Ā Ā Ā # Convert the streams vector to a raster
Ā Ā Ā streams_raster = wbe.rasterize_streams(
Ā Ā Ā Ā Ā Ā Ā streams=streams,
Ā Ā Ā Ā Ā Ā Ā Ā base_raster=dem,
Ā Ā Ā Ā Ā Ā Ā Ā zero_background=True,
Ā Ā Ā Ā Ā Ā Ā Ā use_feature_id=False
Ā Ā Ā )
Ā Ā Ā burned_dem = dem - (streams_raster * decrement_value)
Ā Ā Ā
Ā Ā Ā Ā # Save the streams burned DEM
Ā Ā Ā print('Burning streams...')
Ā Ā Ā wbe.write_raster(burned_dem, 'stream_burned_DEM.tif', compress=True)
Ā
Ā Ā Ā print('Done!')
except Exception as e:
Ā Ā Ā print("The error raised is: ", e)
finally:
Ā Ā Ā end = time.time()
Ā Ā Ā print(f'Elapsed time: {end-start}s')
Ā
Iāll add a āBurnStreamsā function to Whitebox Workflows that basically just replicatest his script with user specified input parameters of the decrement value, DEM and stream objects. It wonāt be available until I release the next version though.
Ā
Regards,
Ā
John
Ā
--
You received this message because you are subscribed to the Google Groups "WhiteboxTools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
whiteboxtool...@googlegroups.com.
To view this discussion visit
https://groups.google.com/d/msgid/whiteboxtools/62bda21b-a84a-4f91-8ef2-238ea48b31e0n%40googlegroups.com.
Hi Sima,
Ā
Yes, the script can be easily modified to add an optional gradient away from rivers. Hereās a sample script. You need to update the working directory, the names of the DEM, streams, and output file, and adjust the decrement_value (the elevation decrement at stream cells) and the gradient_distance (the distance away from streams, measured in grid cells, for which there is some gradient applied).
Ā
import time
from whitebox_workflows import WbEnvironment
Ā
wbe = WbEnvironment()
start = time.time()
try:
Ā Ā Ā wbe.verbose = True
Ā Ā Ā wbe.working_directory = '/path/to/data' # update this
Ā
Ā Ā Ā decrement_value = 20.0 # Set this to whatever value you wish to lower streams by
Ā Ā Ā gradient_distance = 5 # In grid cells
Ā
Ā Ā Ā # Read in the DEM and streams vector
Ā Ā Ā dem = wbe.read_raster('DEM.tif') # update this
Ā Ā Ā grid_res = (dem.configs.resolution_x + dem.configs.resolution_x) / 2.0
Ā Ā Ā streams = wbe.read_vector('rivers.shp') # update this
Ā
Ā Ā Ā # Convert the streams vector to a raster
Ā Ā Ā streams_raster = wbe.rasterize_streams(
Ā Ā Ā Ā Ā Ā Ā streams=streams,
Ā Ā Ā Ā Ā Ā Ā Ā base_raster=dem,
Ā Ā Ā Ā Ā Ā Ā Ā zero_background=True,
Ā Ā Ā Ā Ā Ā Ā Ā use_feature_id=False
Ā Ā Ā )
Ā Ā Ā
Ā Ā Ā Ā print('Burning streams...')
Ā Ā Ā if gradient_distance <= 0.0:
Ā Ā Ā Ā Ā Ā Ā Ā # Perform a straightforward elevation decrement on stream cells only
Ā Ā Ā Ā Ā Ā Ā burned_dem = dem - (streams_raster * decrement_value)
Ā Ā Ā else:
Ā Ā Ā Ā Ā Ā Ā # Decrement stream cells byt he decrement_value and then apply a gradient away from the streams
Ā
Ā Ā Ā Ā Ā Ā Ā # First calculate the distance away from streams
Ā Ā Ā Ā Ā Ā Ā dist = wbe.euclidean_distance(streams_raster)
Ā
Ā Ā Ā Ā Ā Ā Ā # Now covert that value into a decrement value
Ā Ā Ā Ā Ā Ā Ā dist_threshold = gradient_distance * grid_res # Put the gradient distance in map units rather than grid cells
Ā
Ā Ā Ā Ā Ā Ā Ā # This is where the elevation decrement and gradient are added
Ā Ā Ā Ā Ā Ā Ā burned_dem = dem + (((dist - dist_threshold) / dist_threshold).min(0.0)) * decrement_value
Ā Ā Ā
Ā Ā Ā Ā # Save the streams burned DEM; you might want to change the output name.
Ā Ā Ā wbe.write_raster(burned_dem, 'stream_burned_DEM.tif', compress=True)
Ā
Ā Ā Ā print('Done!')
except Exception as e:
Ā Ā Ā print("The error raised is: ", e)
finally:
Ā Ā Ā end = time.time()
Ā Ā Ā print(f'Elapsed time: {end-start}s')
Ā
Ā
Here is what the output looks like:
Ā
Original DEM
Ā
Stream-burned DEM
Ā
Cheers,
Ā
John
Ā
Ā
To view this discussion visit https://groups.google.com/d/msgid/whiteboxtools/2312af22-5a98-4e3d-b20c-d19e6bd35f9fn%40googlegroups.com.