Skip to content

Commit

Permalink
Merge pull request #10 from VForWaTer/development_commits
Browse files Browse the repository at this point in the history
CATFLOW Geospatial Tool
  • Loading branch information
Ash-Manoj authored Jul 25, 2023
2 parents 835d501 + d55cffb commit 27b36f3
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 178 deletions.
23 changes: 13 additions & 10 deletions src/lib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from wbt import wbt


def print_info(to_file: bool):
info = wbt.version()

Expand All @@ -11,29 +12,31 @@ def print_info(to_file: bool):
# output
print(info)

def fill(inp,out,flats):
def clip(inp,out,shp):

wbt.fill_depressions(
inp,
out,
flats
wbt.clip(
i=inp,
clip=shp,
output=out,
)

def aspect(inp,out,zfactor):
def fill(inp, out):
wbt.fill_depressions(inp, out)


def aspect(inp,out):

wbt.aspect(
inp,
out,
zfactor
)

def accu_d8(inp,out,type,log):
def accu_d8(inp,out):

wbt.d8_flow_accumulation(
inp,
out,
out_type=type,
log=log,
out_type='cells',
)

def dir_d8(inp,out):
Expand Down
130 changes: 39 additions & 91 deletions src/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,119 +16,67 @@
if toolname == 'whitebox_info':
wblib.print_info(to_file=kwargs.get('toFile', True))

# Fill Depression tool
elif toolname == 'fill_depressions':
# Tool for generating required Raster files for CATFLOW Hillslope Wizard
elif toolname == 'hillslope_generator':
# get the parameters
try:
inp = kwargs['dem']
out = '/out/filled_dem.tif'
flats = kwargs.get('fix_flats', True)
clip = kwargs.get('clip_extent', False)
shp = kwargs.get('basins', '/in/basin.shp')
thres = kwargs.get('stream_threshold', 100.0)
except Exception as e:
print(str(e))
sys.exit(1)

if(clip):
wblib.clip(inp,inp,shp)

# Define the output file locations
filled = '/out/fill_DEM.tif'
aspect = '/out/aspect.tif'
accu = '/out/flow_accumulation.tif'
flowdir = '/out/flow_direction.tif'
streams = '/out/streams.tif'
hillslope = '/out/hillslopes.tif'
elevation = '/out/elevation.tif'
distance = '/out/distance.tif'

# run the whitebox fill_depression algorithm
print(f"Filling depressions in DEM '{inp}'...",end='',flush=True)
wblib.fill(inp,out,flats)
wblib.fill(inp,filled)
print('done.')

# Aspect tool
elif toolname == 'aspect':
# get the parameters
try:
inp = kwargs['dem']
out = '/out/aspect.tif'
zfactor = kwargs.get('z_factor', None)
except Exception as e:
print(str(e))
sys.exit(1)

# run the whitebox fill_depression algorithm
print(f"Calculating Slope Aspect in DEM '{inp}'...",end='',flush=True)
wblib.aspect(inp,out,zfactor)
#Aspect algorithm
print(f"Calculating Slope Aspect in DEM '{filled}'...",end='',flush=True)
wblib.aspect(filled,aspect)
print('done.')

# Flow Accumulation tool
elif toolname == 'flow_accumulation_d8':
# get the parameters
try:
inp = kwargs['dem']
out = '/out/flow_accumulation.tif'
type = kwargs.get('out_type', 'cells')
log = kwargs.get('log', False)
except Exception as e:
print(str(e))
sys.exit(1)

# run the whitebox algorithm
print(f"Calculating Flow Accumulation DEM '{inp}'...",end='',flush=True)
wblib.accu_d8(inp,out,type,log)
#Flow Accumulation Algorithm
print(f"Calculating Flow Accumulation DEM '{filled}'...",end='',flush=True)
wblib.accu_d8(filled,accu)
print('done.')

# Flow Direction tool
elif toolname == 'flow_direction_d8':
# get the parameters
try:
inp = kwargs['dem']
out = '/out/flow_direction.tif'
except Exception as e:
print(str(e))
sys.exit(1)

# run the whitebox algorithm
print(f"Calculating Flow Direction '{inp}'...",end='',flush=True)
wblib.dir_d8(inp,out)
#Flow Direction Algorithm
print(f"Calculating Flow Direction '{filled}'...",end='',flush=True)
wblib.dir_d8(filled,flowdir)
print('done.')

# Stream Extraction tool
elif toolname == 'stream_extraction':
# get the parameters
try:
inp = kwargs['flow_accumulation']
out = '/out/streams.tif'
thres = kwargs['threshold']
except Exception as e:
print(str(e))
sys.exit(1)

# run the whitebox algorithm
print(f"Stream Extraction from '{inp}'...",end='',flush=True)
wblib.stream(inp,out,thres)
#Stream Extraction tool
print(f"Stream Extraction from '{accu}'...",end='',flush=True)
wblib.stream(accu,streams,thres)
print('done.')

# Hillslope Extraction tool
elif toolname == 'hillslope_extraction':
# get the parameters
try:
inp = kwargs['flow_direction']
out = '/out/hillslopes.tif'
stream = kwargs['stream']
except Exception as e:
print(str(e))
sys.exit(1)

# run the whitebox algorithm
print(f"Hillslope Extraction from '{inp}'...",end='',flush=True)
wblib.hillslope(inp,out,stream)
#Hillslope Extraction tool
print(f"Hillslope Extraction from '{flowdir}'...",end='',flush=True)
wblib.hillslope(flowdir,hillslope,streams)
print('done.')

# Elevation to River tool
elif toolname == 'stream_elev_dist':
# get the parameters
try:
inp = kwargs['dem']
out1 = '/out/elevation.tif'
out2 = '/out/distance.tif'
stream = kwargs['stream']
except Exception as e:
print(str(e))
sys.exit(1)
#Elevation to River tool
print(f" Distance and Elevation from River '{streams}'...", end='', flush=True)
wblib.distance(filled, elevation, streams)
wblib.elevation(filled, distance, streams)
print('done.')

# run the whitebox algorithm
print(f" Distance and Elevation from River '{stream}'...",end='',flush=True)
wblib.distance(inp,out2,stream)
wblib.elevation(inp,out1,stream)
print('done.')
# In any other case, it was not clear which tool to run
else:
raise AttributeError(f"[{dt.now().isocalendar()}] Either no TOOL_RUN environment variable available, or '{toolname}' is not valid.\n")
87 changes: 10 additions & 77 deletions src/tool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,88 +8,21 @@ tools:
type: bool
description: If True, an INFO.txt will be written
default: true
fill_depressions:
title: Fill Depressions
description: Fill Depressions in a DEM using WhiteboxGIS [fill_depression](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#FillDepressions) tool
hillslope_generator:
title: CATFLOW Hillslope Generator
description: Produces the required Raster (.TIFF) files for running the CATFLOW Hillslope Wizard Tool using [Whitebox GIS](https://www.whiteboxgeo.com/) Platform
version: 0.1
parameters:
dem:
type: file
description: Input Raster DEM file
fix_flats:
clip_extent:
type: bool
description: flag indicating whether flat areas should have a small gradient applied
default: true
aspect:
title: Calculate Slope Aspect
description: Calculates slope aspect (i.e. slope orientation in degrees clockwise from north) for each grid cell in an input digital elevation model using WhiteboxGIS [Aspect](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/geomorphometric_analysis.html?highlight=aspect#aspect) tool
version: 0.1
parameters:
dem:
description: flag indicating whether the processing area should be clipped based on a provided shapefile
default: false
basins:
type: file
description: Input Raster filled DEM file
z_factor:
description: Input shapefile for clipping the processing extent
stream_threshold:
type: float
description: Optional multiplier for when the vertical and horizontal units are not the same
default: None
flow_accumulation_d8:
title: Generate a flow accumulation grid - D8
description: This tool is used to generate a flow accumulation grid (i.e. catchment area) using the D8 Algorithm by WhiteboxGIS [D8FlowAccumulation](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#d8flowaccumulation) tool
version: 0.1
parameters:
dem:
type: file
description: Input Raster filled DEM file
out_type:
type: string
description: Output type; one of 'cells' (default), 'catchment area', and 'specific contributing area' (i.e. the catchment area divided by the flow width.
default: 'cells'
log:
type: bool
description: Optional flag to request the output be log-transformed
default: false
flow_direction_d8:
title: Generate a flow pointer grid - D8
description: This tool is used to generate a flow pointer grid using the D8 Algorithm by WhiteboxGIS [D8Pointer](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#d8pointer) tool
version: 0.1
parameters:
dem:
type: file
description: Input Raster filled DEM file
stream_extraction:
title: Extract, or map, the likely stream cells
description: This tool can be used to extract, or map, the likely stream cells from an input flow-accumulation image by WhiteboxGIS [ExtractStreams](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/stream_network_analysis.html#ExtractStreams) tool
version: 0.1
parameters:
flow_accumulation:
type: file
description: Flow Accumulation file
threshold:
type: float
description: Threshold in flow accumulation values for channelization
hillslope_extraction:
title: Identify the hillslopes associated with a user-specified stream network
description: This tool identify the hillslopes associated with a user-specified stream network by WhiteboxGIS [Hillslopes](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#hillslopes) tool
version: 0.1
parameters:
flow_direction:
type: file
description: Flow Direction file
stream:
type: file
description: Extracted Streams file
stream_elev_dist:
title: To calculate the distance and elevation of each grid cell in a raster above the nearest stream cell
description: This tool can be used to calculate the elevation and distance of each grid cell in a raster using
Whitebox GIS tools [ElevationAboveStream](https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#ElevationAboveStream)
[DownslopeDistanceToStream] (https://www.whiteboxgeo.com/manual/wbt_book/available_tools/hydrological_analysis.html#downslopedistancetostream)
version: 0.1
parameters:
dem:
type: file
description: Input DEM file
stream:
type: file
description: Extracted Streams file


description: Threshold in flow accumulation values for channelization (extracting streams)

0 comments on commit 27b36f3

Please sign in to comment.