API Reference
Python wrapper for WhiteboxTools command-line utility.
prepare_wbt #
Download the WhiteboxTools executable for the current platform.
Parameters:
-
wbt_root(str or Path) –Root directory to extract WhiteboxTools to.
-
zip_path(str or Path, default:None) –Path to the zip file containing the WhiteboxTools executables, defaults to
None. IfNone, the zip file will be downloaded to a temporary directory that gets deleted after the function finishes. Otherwise, the zip file will be saved to the specified path. -
refresh_download(bool, default:False) –Whether to refresh the download even if WhiteboxTools is found. Defaults to
False. -
max_attempts(int, default:3) –Maximum number of attempts to prepare WhiteboxTools, defaults to 3.
-
verbose(bool, default:False) –Whether to enable verbose logging, defaults to
False.
Returns:
-
str–Version of WhiteboxTools.
whitebox_tools #
whitebox_tools(
src_dir,
arg_dict,
files_to_save=None,
save_dir=".",
wbt_root="WBT",
compress_rasters=False,
zip_path=None,
refresh_download=False,
max_procs=-1,
verbose=False,
)
Run a WhiteboxTools (not Whitebox Runner) tool with specified arguments.
Parameters:
-
src_dir(str or Path) –Path to the source directory containing input files. This will be the working directory for the WhiteboxTools session. The input files should be in this directory. Thus, when using the files in this directory in
arg_dict, you must just use the filenames without the directory path. Refer to the example inarg_dict. -
arg_dict(dict) –A dictionary containing the tool names as keys and list of each tool's arguments as values. For example:
Note that the input and output file names should not contain the directory path, only the filenames. -
files_to_save(list, default:None) –List of output files to save to
save_dir. Note that these should be the filenames without the directory path, just as they are used in thearg_dict, i.e. the values that are passed by-oor--output. Defaults toNone, which means all intermediate files will be saved tosave_dir. -
save_dir(str or Path, default:'.') –Path to the directory where the output files given in
files_to_savewill be saved (default is".", i.e., current working directory). -
wbt_root(str or Path, default:'WBT') –Path to the directory the Whitebox executables will be extracted to (default is
"WBT"). -
zip_path(str or Path, default:None) –Path to the zip file containing the WhiteboxTools executables (default is
None). IfNone, the zip file will be downloaded to a temporary directory that gets deleted after the function finishes. Otherwise, the zip file will be saved to the specified path. -
refresh_download(bool, default:False) –Whether to refresh the download if WhiteboxTools is found (default is
False). -
compress_rasters(bool, default:False) –Whether to compress output rasters (default is
False). -
max_procs(int, default:-1) –The maximum number of processes to use (default is
-1). -
verbose(bool, default:False) –Whether to print verbose output (default is
False).
Raises:
-
CalledProcessError–If the tool execution fails.
-
Exception–For any other unexpected errors.
list_tools #
List the available WhiteboxTools commands.
Parameters:
-
wbt_root(str or Path, default:'WBT') –Path to the directory containing the WhiteboxTools executables (default is
WBT). -
zip_path(str or Path, default:None) –Path to the zip file containing the WhiteboxTools executables (default is
None).
Returns:
-
dict–A dictionary of WhiteboxTools commands and their descriptions. Can be converted to a
pandas.Seriesfor easier viewing usingpd.Series(pywbt.list_tools()).
tool_parameters #
List the parameters for a WhiteboxTools command.
Parameters:
-
tool_name(str) –Name of the WhiteboxTools command.
-
wbt_root(str or Path, default:'WBT') –Path to the directory containing the WhiteboxTools executables (default is
"WBT"). -
zip_path(str or Path, default:None) –Path to the zip file containing the WhiteboxTools executables (default is
None).
Returns:
-
list–A list of WhiteboxTools command parameters and their descriptions. Can be converted to a
pandas.DataFramefor easier viewing. For example, to get parameters ofAspecttool, usepd.DataFrame(pywbt.tool_parameters("Aspect")).
Utility functions for getting and processing Digital Elevation Models (DEMs).
DependencyError #
get_nasadem #
Get DEM for a given bounding box from NASADEM.
Parameters:
get_3dep #
Get DEM from USGS's 3D Hydrography Elevation Data Program (3DEP).
Parameters:
-
bbox(tuple) –Bounding box coordinates in the order (west, south, east, north) in decimal degrees.
-
tif_path(str or Path) –Path to save the obtained data as a GeoTIFF file.
-
resolution(int, default:10) –Resolution of the DEM in meters, by default 10.
-
to_5070(bool, default:False) –Reproject the DEM to EPGS:5070, by default False.
tif_to_da #
Read a GeoTIFF file with a single band into an xarray DataArray.
Parameters:
-
tif_path(str or Path) –Path to the GeoTIFF file with a single band.
-
dtype(str, default:None) –Data type to cast the data to, e.g.
int32, by defaultNone, i.e. use the data type from the GeoTIFF. -
name(str, default:None) –Name to assign to the
xarray.DataArray, by defaultNone. -
long_name(str, default:None) –Long name to assign to the
xarray.DataArray, by defaultNone. -
nodata(int or float, default:None) –Value to use as
da.rio.nodata, by defaultNone, i.e. use theda.rio.nodatavalue from the GeoTIFF.
Returns:
-
DataArray–DataArray containing the GeoTIFF data.
tif_to_gdf #
Convert a GeoTIFF to a GeoDataFrame.
Parameters:
-
tif_path(str or Path) –Path to the GeoTIFF file. The file must contain a single band.
-
dtype(str) –String representation of the data type to use for the feature values, e.g.
int32. -
feat_name(str) –Name to assign to the feature values column.
-
connectivity(int, default:8) –Use 4 or 8 pixel connectivity for grouping pixels into features, by default 8.
Returns:
-
GeoDataFrame–GeoDataFrame containing the features.