Coder Social home page Coder Social logo

opengeos / whitebox-python Goto Github PK

View Code? Open in Web Editor NEW
364.0 25.0 67.0 8.18 MB

WhiteboxTools Python Frontend

Home Page: https://pypi.org/project/whitebox/

License: MIT License

Makefile 0.43% Python 99.50% Shell 0.08%
geospatial gis remote-sensing geoprocessing hydrology geomorphometry geomorphology python lidar

whitebox-python's Introduction

whitebox-python

image

image

image

image

image

Documentation Status

image

image

Important Note

image

This repository is related to the WhiteboxTools Python Frontend only. You can report issues to this repo if you have problems installing this Python package. If you encounter any tool functioning specific errors, please open an issue on Dr. John Lindsay's WhiteboxTools repo.

Links

Contents

Description

The whitebox Python package is built on WhiteboxTools, an advanced geospatial data analysis platform developed by Prof. John Lindsay (webpage; jblindsay) at the University of Guelph's Geomorphometry and Hydrogeomatics Research Group. WhiteboxTools can be used to perform common geographical information systems (GIS) analysis operations, such as cost-distance analysis, distance buffering, and raster reclassification. Remote sensing and image processing tasks include image enhancement (e.g. panchromatic sharpening, contrast adjustments), image mosaicing, numerous filtering operations, simple classification (k-means), and common image transformations. WhiteboxTools also contains advanced tooling for spatial hydrological analysis (e.g. flow-accumulation, watershed delineation, stream network analysis, sink removal), terrain analysis (e.g. common terrain indices such as slope, curvatures, wetness index, hillshading; hypsometric analysis; multi-scale topographic position analysis), and LiDAR data processing. LiDAR point clouds can be interrogated (LidarInfo, LidarHistogram), segmented, tiled and joined, analyized for outliers, interpolated to rasters (DEMs, intensity images), and ground-points can be classified or filtered. WhiteboxTools is not a cartographic or spatial data visualization package; instead it is meant to serve as an analytical backend for other data visualization software, mainly GIS.

Installation

whitebox supports a variety of platforms, including Microsoft Windows, macOS, and Linux operating systems. Note that you will need to have Python 3.x installed. Python 2.x is not supported. The whitebox Python package can be installed using the following command:

pip install whitebox

If you have installed whitebox Python package before and want to upgrade to the latest version, you can use the following command:

pip install whitebox -U

It is recommended that you use a Python virtual environment (e.g., conda) to test the whitebox package. Please follow the conda user guide to install conda if necessary. Once you have conda installed, you can use Terminal or an Anaconda Prompt to create a Python virtual environment. Check managing Python environment for more information.

conda create -n wbt python
source activate wbt
conda install whitebox -c conda-forge

If you encounter an GLIBC errors when installing the whitebox package, you can try the following command:

import whitebox
whitebox.download_wbt(linux_musl=True, reset=True)

Alternatively, you can set the environment variable WBT_LINUX to MUSL before installing the whitebox package. It will automatically download the MUSL version of WhiteboxTools.

import os
os.environ["WBT_LINUX"] = "MUSL"

whitebox Tutorials

Launch the whitebox tutorial notebook directly with mybinder.org now:

image

Quick Example

Tool names in the whitebox Python package can be called either using the snake_case or CamelCase convention (e.g. lidar_info or LidarInfo). See below for an example Python script (example.py). If you are interested in using the WhiteboxTools command-line program, check WhiteboxTools Usage.

import os
import pkg_resources
import whitebox

wbt = whitebox.WhiteboxTools()
print(wbt.version())
print(wbt.help())

# identify the sample data directory of the package
data_dir = os.path.dirname(pkg_resources.resource_filename("whitebox", 'testdata/'))

wbt.set_working_dir(data_dir)
wbt.verbose = False
wbt.feature_preserving_smoothing("DEM.tif", "smoothed.tif", filter=9)
wbt.breach_depressions("smoothed.tif", "breached.tif")
wbt.d_inf_flow_accumulation("breached.tif", "flow_accum.tif")

A Jupyter Notebook Tutorial for whitebox

This tutorial can be accessed in three ways:

Launch this tutorial as an interactive Jupyter Notebook on the cloud - https://gishub.org/whitebox-cloud.

image

whitebox GUI

WhiteboxTools also provides a Graphical User Interface (GUI) - WhiteboxTools Runner, which can be invoked using the following Python script:

import whitebox
whitebox.Runner()

image

Troubleshooting

Linux

When using import whitebox, if you get an error that says No module named '_tkinter', please install the python3-tk package, you can try the following solution:

  • For Ubuntu, Linux Mint, etc: sudo apt-get install python3-tk
  • For Manjaro, Arch Linux: sudo pacman -S tk

Available Tools

The library currently contains 518 tools, which are each grouped based on their main function into one of the following categories: Data Tools, GIS Analysis, Hydrological Analysis, Image Analysis, LiDAR Analysis, Mathematical and Statistical Analysis, Stream Network Analysis, and Terrain Analysis. For a listing of available tools, complete with documentation and usage details, please see the WhiteboxTools User Manual.

Supported Data Formats

The WhiteboxTools library currently supports read/writing raster data in Whitebox GAT, GeoTIFF, ESRI (ArcGIS) ASCII and binary (.flt & .hdr), GRASS GIS, Idrisi, SAGA GIS (binary and ASCII), and Surfer 7 data formats. At present, there is limited ability in WhiteboxTools to read vector geospatial data. Support for Shapefile (and other common vector formats) will be enhanced within the library soon.

Contributing

If you would like to contribute to the project as a developer, follow these instructions to get started:

  1. Fork the whitebox project (https://github.com/opengeos/whitebox-python)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

The whitebox package is distributed under the MIT license, a permissive open-source (free software) license.

Reporting Bugs

Report bugs at https://github.com/opengeos/whitebox-python/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.
  • Any details about your local setup that might be helpful in troubleshooting.
  • Detailed steps to reproduce the bug.

Credits

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

whitebox-python's People

Contributors

ewouth avatar giswqs avatar trellixvulnteam avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

whitebox-python's Issues

Negative flow path length

  • whitebox version: 2.2.0
  • Python version: 3.10.8
  • Operating System: Docker Image, python:3.10-slim-bullseye

Description

Hi, Iโ€™m trying to compute the flow length using downslope_flowpath_length function. The tool seems to work, but I have negative lengths as results. Am I doing something wrong? Could you explain what the output represents?
Thank you!

What I Did

wbt.downslope_flowpath_length(flow_dir_catch, flowlength_catch, esri_pntr=True)

(I opened the raster in QGIS for convenience)
Python result:
image

Expected result:
image

Running ConditionalEvaluation requires manual Whitebox library folder permissions change

  • whitebox version: 2.1.1
  • Python version: 3.9.10
  • Operating System: Ubuntu 20.04 under Windows WSL2

Description

Running the ConditionalEvaluation tool (also applies to RasterCalculator as per jblindsay/whitebox-tools#202) requires a manual permission change on the whitebox library folders and files. Without this, the tool crashes and throws a denied permissions exception.

When WBT executables are downloaded upon the first import whitebox, some permissions are rw-r--r-- (644), other are rwxr-xr-x (755). Changing all the whitebox/ folder, subfolders and files to rwxr-xr-x allowed the tool to run properly.

What I Did

import whitebox
wbt = whitebox.WhiteboxTools()

wbt.conditional_evaluation(
    i = "/path/to/raster/input.tif",
    output = "/path/to/raster/output.tif",
    statement = "'value >= 3'",
    true = 1,
    false = "nodata"
)

>>> ./whitebox_tools --run="ConditionalEvaluation" --input='/path/to/raster/input.tif' --statement='value >= 3' --true='1' --false='nodata' --output='/path/to/raster/output.tif'

>>> thread 'main' panicked at 'failed to execute process: Os { code: 13, kind: PermissionDenied, message: "Permission denied" }', whitebox-tools-app/src/tools/mod.rs:1264:26
>>> note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
>>> 0

Permissions change on the whitebox library folder and files, in your Python environment folder:

chmod -R 755 /path_to_conda_env/lib/python3.9/site-packages/whitebox/

wbt.conditional_evaluation(
    i = "/path/to/raster/input.tif",
    output = "/path/to/raster/output.tif",
    statement = "'value >= 3'",
    true = 1,
    false = "nodata"
)

>>> ./whitebox_tools --run="ConditionalEvaluation" --input='/path/to/raster/input.tif' --statement='value >= 3' --true='1' --false='nodata' --output='/path/to/raster/output.tif'
>>> (Tool runs normally).

Error during whitebox.Runner()

  • whitebox version: 1.2.0
  • Python version: 3.5
  • Operating System: ubuntu 16.04

Description

Describe what you were trying to get done.
.Traceback (most recent call last):
File "", line 1, in
File "/home/Documents/venvs/base_all/lib/python3.5/site-packages/whitebox/wb_runner.py", line 1316, in Runner
wbr = WbRunner(tool_name)
File "/home/Documents/venvs/base_all/lib/python3.5/site-packages/whitebox/wb_runner.py", line 767, in init
self.create_widgets()
File "/home/Documents/venvs/base_all/lib/python3.5/site-packages/whitebox/wb_runner.py", line 789, in create_widgets
self.get_tools_list()
File "/home/Documents/venvs/base_all/lib/python3.5/site-packages/whitebox/wb_runner.py", line 1022, in get_tools_list
self.tool_name = self.tools_list[0]
IndexError: list index out of range

What I Did

whitebox.Runner()

Paste the command(s) you ran and the output.
If there was a crash, please include the traceback here.

AttributeError: module 'whitebox' has no attribute...

  • whitebox version: 2.3.1
  • Python version: 3.11.0
  • Operating System: Windows 10 Enterprise

Description

Hi,
I installed whitebox from conda.

When I run any command (e.g., wbt.d8_pointer, wbt.d8_flow_accumulation, or any other) from a python script I get the following error:
AttributeError: module 'whitebox' has no attribute 'flow_accumulation_full_workflow'

This happen with any command I use.

When I run instead the GUI wbt.Runner() everything works fine and I can correctly do all the operations I need from the GUI.

I tried to uninstall and reinstall the package, to install it in a separate environment, but still no changes.

What is it happening? How could I solve the issue? (I would like to write a sequence of operations that I can run every time I need, without having to repeat it "by hand" every time using the GUI.

Thanks a lot for your help!
Stefano

<class 'urllib.error.URLError'>

  • whitebox version: 2.0.1
  • Python version: 3.7.10
  • Operating System: Windows 10 Education 64-bit

Description

Unexpected error when I ran whitebox.WhiteboxTools()

What I Did

import whitebox
print(whitebox.__version__)
wbt = whitebox.WhiteboxTools()

2.0.1
Unexpected error: <class 'urllib.error.URLError'>
URLError: <urlopen error unknown url type: hhttps>

Conda info

     active environment : tiruan
    active env location : F:\Anaconda3\envs\tiruan
            shell level : 1
       user config file : C:\Users\Muhammad Ichsan\.condarc
 populated config files : C:\Users\Muhammad Ichsan\.condarc
          conda version : 4.10.3
    conda-build version : 3.21.4
         python version : 3.7.10.final.0
       virtual packages : __cuda=10.2=0
                          __win=0=0
                          __archspec=1=x86_64
       base environment : F:\Anaconda3  (writable)
      conda av data dir : F:\Anaconda3\etc\conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/win-64
                          https://conda.anaconda.org/conda-forge/noarch
                          https://repo.anaconda.com/pkgs/main/win-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/free/win-64
                          https://repo.anaconda.com/pkgs/free/noarch
                          https://repo.anaconda.com/pkgs/r/win-64
                          https://repo.anaconda.com/pkgs/r/noarch
                          https://repo.anaconda.com/pkgs/msys2/win-64
                          https://repo.anaconda.com/pkgs/msys2/noarch
          package cache : F:\Anaconda3\pkgs
                          C:\Users\Muhammad Ichsan\.conda\pkgs
                          C:\Users\Muhammad Ichsan\AppData\Local\conda\conda\pkgs
       envs directories : F:\Anaconda3\envs
                          C:\Users\Muhammad Ichsan\.conda\envs
                          C:\Users\Muhammad Ichsan\AppData\Local\conda\conda\envs
               platform : win-64
             user-agent : conda/4.10.3 requests/2.26.0 CPython/3.7.10 Windows/10 Windows/10.0.16299
          administrator : False
             netrc file : None
           offline mode : False

Additional note : I installed whitebox (with pip) to another conda environment. It gave same error.

Documentation for raster_calculator tool

  • whitebox version: 2.0.0
  • Python version: 3.6
  • Operating System: Windows 10

Description

The documentation for the raster_calculator function on the Python frontend does not seem to be correct. It currently reads: "This tool performs a conditional evaluaton (if-then-else) operation on a raster", which is the documentation for the conditional_evaluation tool. This is a very small issue but I thought I would raise it because it has an easy fix.

Thanks,
Marc

Raster shift in LidarPointStats?

  • whitebox version: 2.1.4
  • Python version: 3.8
  • Operating System: Win11/WSL2

Description

Hi. I used LidarPointStats tool through whitebox-python to create a grid with each raster cell representing the number of points. The tool worked fine. However, it looks like the output is either incorrect or shifted (see a screenshot below). Is this the expected behaviour or am I doing something wrong?

What I Did

wbt.lidar_point_stats(
    i=lidar.las, 
    resolution=1.0,
    num_points=True,
    num_pulses=False,
    avg_points_per_pulse=False,
    z_range=False,
    intensity_range=False,
    predom_class=False
)

Layout 1

whitebox clip function corrupting output file

  • whitebox version: 2.0.3
  • Python version: 3.9
  • Operating System: RedHat Enterprise

Description

After using the whitebox tools clip function, the output lidar file seems to be corrupted. Attached is a zip folder with the lidar.laz tile. Also, here is an example error message I get when viewing the output file in lastools.
'chunk table and XXXXXXXXXX bytes are missing' is the common error message from the output file.

image

What I Did

wbt.clip_lidar_to_polygon(
    i="NEON_D01_HARV_DP1_732000_4713000_classified_point_cloud_colorized.laz", 
    polygons="towerPoly.shp", 
    output="lidarAOI.laz"
)

Thanks!

LidarIdwInterpolation does not save CRS to output

  • whitebox version:
  • Python version:
  • Operating System:

Description

When running the LidarIdwInterpolation function using the Python front end for whitebox, the coordinate reference system (CRS) is not saved to the output .tif file.

What I Did

Basic command of function was used.

    wbt.lidar_idw_interpolation(
        i=f, 
        output=outdir+fname_dem, 
        parameter="elevation", 
        returns="all", 
        resolution=1.0, 
        weight=1.0, 
        radius=5, 
        exclude_cls='3,4,5,6,7,18', 
        minz=None, 
        maxz=None
    )

Thanks in advance.

(QGIS) ModuleNotFoundError: No module named '_tkinter'

  • whitebox version:1.5.1
  • Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
  • Operating System: Windows 10 64bit

Description

I'm running the OSGeo pyqgis distribution

pip install whitebox

works fine. However, my distribution seems to be missing Tkinter. I believe there is something with QGIS that doesn't let Tkinter run/install.

Is there way to change the backend of whitebox? Or another workaround that will let me run the pyqgis AND whitebox API?

import whitebox
ModuleNotFoundError: No module named '_tkinter'

Download_wbt.py Error

  • whitebox version: 2.2.0
  • Python version: 3.8.10
  • Operating System: Ubuntu 20.04

Description

I'm trying to download the WBT binaries for use in a docker container. I would like to be able to have them set up in the docker image so that each container will not have to download them individually.

What I Did

Here's what I'm running inside my terminal to try to download the binaries and the error it produces:

# python /usr/local/lib/python3.8/dist-packages/whitebox/download_wbt.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py", line 388, in get_provider
    module = sys.modules[moduleOrReq]
KeyError: 'whitebox'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/whitebox/download_wbt.py", line 182, in <module>
    download_wbt()
  File "/usr/local/lib/python3.8/dist-packages/whitebox/download_wbt.py", line 20, in download_wbt
    pkg_resources.resource_filename(package_name, "whitebox_tools.py")
  File "/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py", line 1201, in resource_filename
    return get_provider(package_or_requirement).get_resource_filename(
  File "/usr/local/lib/python3.8/dist-packages/pkg_resources/__init__.py", line 390, in get_provider
    __import__(moduleOrReq)
  File "/usr/local/lib/python3.8/dist-packages/whitebox/whitebox.py", line 5, in <module>
    from .whitebox_tools import WhiteboxTools
ImportError: attempted relative import with no known parent package

However, opening a python interpreter and running from whitebox import WhiteboxTools; WhiteboxTools() will successfully download the binaries.

a bug in func (raster_to_vector_lines)

Description

Hello! Mr.WU. When I turn a single pixel wide raster into a line vector, the previously continuous closed shape becomes a broken line segment. How to avoid this problem?

code

from WBT.whitebox_tools import WhiteboxTools

if __name__ == "__main__":
    rasterPath = "/home/BE/results/cq_test_edge.tif"
    outputPath = "/home/BE/results/cq_test_edge4.shp"
    wbt = WhiteboxTools()

    wbt.raster_to_vector_lines(rasterPath, outputPath)

image

LidarIdwInterpolation does not save CRS to output

  • whitebox version: 2.1.2
  • Python version: 3.10
  • Operating System: Windows 64-bit

Description

When running the LidarIdwInterpolation function using the Python front end for whitebox, the coordinate reference system (CRS) is not saved to the output .tif file.

What I Did

Basic command of function was used.

    wbt.lidar_idw_interpolation(
        i=f, 
        output=outdir+fname_dem, 
        parameter="elevation", 
        returns="all", 
        resolution=1.0, 
        weight=1.0, 
        radius=5, 
        exclude_cls='3,4,5,6,7,18', 
        minz=None, 
        maxz=None
    )

Thanks in advance.

glibc requirements

  • whitebox version: 1.5.1
  • Python version: 3.6
  • Operating System: CentOS 8

Description

It seems to install, but it won't run any functionality.
error:
./whitebox_tools: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by ./whitebox_tools)

What I Did

print(wbt.license())
./whitebox_tools: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by ./whitebox_tools)

urllib.error.HTTPError: HTTP Error 404: Not Found

  • whitebox version: 1.4.0
  • Python version: 3.6
  • Operating System: Linux 18.04 LTS

Description

Hey, I'm getting error in the Docker geemap container when import whitebox for the first time.
error

It is not a problem if I type again an import. I couldn't understand why this throws an error. Here is a related issue:
https://stackoverflow.com/questions/42441211/python-urllib-error-httperror-http-error-404-not-found

I guess this is not an important error and related to network issues. I wanted to add in case someone sees the error message.

What I Did

docker run -it --name geemap_latest -p 8888:8888 -p 6006:6006 -v C:/Users/batuh/Desktop:/geemap/data bkavlak/geemap:latest bash
import whitebox

Installing whitebox tools gets the dev version - FlightlineOverlap fails

  • whitebox version: 0.8.0.dev0
  • Python version: 3.9.16
  • Operating System: Windows

Description

I am trying to run the flightline overlap tool within a function in a larger python script. I have run it fine on my computer that I installed whitebox tools on more than a year ago (it is using whitebox version 2.1.2), but I had to get it setup for someone else and had to have them install whitebox tools. We used the conda install line from the anaconda website (https://anaconda.org/conda-forge/whitebox_tools): "conda install -c conda-forge whitebox_tools". After successfully installing, I checked the version and was surprised that it was 0.8.0.dev0. The first thing that was different when using it was just importing the module. In my scripts I could use "import whitebox" and on the computer with the new install of whitebox it has to be imported with "import whitebox_tools". When I run FlightlineOverlap on my computer I get the expected/correct outputs. On the new install I get this error:

[WinError 2] The system cannot find the file specified

What I Did

import os
try:
    import whitebox
except:
    import whitebox_tools as whitebox
wbt = whitebox.WhiteboxTools()

lidar_dir = r"path\to\lidar"
raster_dir = r"path\to\raster"
pre_name="Test"

# Create overlap raster for lidar swaths.
def create_overlap(lidar_dir, pre_name, raster_dir):
    print("Creating overlap raster...")
    overlap_raster = os.path.join(raster_dir, pre_name+"_Overlap.tif")

    wbt.set_working_dir(lidar_dir)
    wbt.flightline_overlap(i=None, output=overlap_raster, resolution=1)

    print("Overlap raster created.")
    return overlap_raster

create_overlap(lidar_dir, pre_name, raster_dir)

Again, I get this error when running:
[WinError 2] The system cannot find the file specified

Thanks in advance!

ResourceWarnings for unclosed

  • whitebox version: 2.0.3
  • Python version: 3.8
  • Operating System: "Rocky Linux 8.5

Description

I am creating drainage lines from an input DEM. I am running the following tools in succession so that the output of a tool becomes the input of the next:

  • breach_depressions_least_cost
  • d8_pointer
  • d8_flow_accumulation
  • extract_streams

It all works and I'm happy with the output, but I get a lot of warning messages about resource warnings like the following:

/usr/lib64/python3.8/subprocess.py:946: ResourceWarning: subprocess 2454694 is still running
_warn("subprocess %s is still running" % self.pid,
ResourceWarning: Enable tracemalloc to get the object allocation traceback
/mydata/drainage_lines.py:558: ResourceWarning: unclosed file <_io.TextIOWrapper name=7 encoding='UTF-8'>
wbt.set_verbose_mode(False)

This fills the error log with messages, despite the fact that tool appears to function fine. I've searched for the process ids but they seem to have been closed, despite the message.

Is there a step I need to take after running one tool and before running the next?

Using previous versions of WhiteboxTools

  • whitebox version: 1.5.0
  • Python version: 3.6.10
  • Operating System: Ubuntu 20.04

Description

I would like to use WhiteboxTools v1.5.0 in order to use

https://github.com/NCAR/wrf_hydro_gis_preprocessor

but unforuntately, I can't pin WhiteboxTools to v1.5.0, despite
being aware of issues like this:

https://stackoverflow.com/questions/67495221/conda-environment-has-access-to-system-modules-how-to-prevent

What I Did

My steps to reproduce on Ubuntu 20.04 are:

rm -rf ~/miniconda3 ~/.condarc ~/.conda ~/.continuum
bash Miniconda3-py38_4.12.0-Linux-x86_64.sh
conda init
conda config --add channels conda-forge
conda create -n wrfh_gis_env -c conda-forge python=3.6 gdal netCDF4 numpy pyproj whitebox=1.5.0
conda activate wrfh_gis_env
(wrfh_gis_env) > python

from whitebox.whitebox_tools import WhiteboxTools
print(' Using {0}'.format(WhiteboxTools().version().split('\n')[0]))
Using WhiteboxTools v2.1.0 by Dr. John B. Lindsay (c) 2017-2021

Please note that outside of wrfh_gis_env, I do not have access
to WhiteboxTools v2.1.0:

python3.8

from whitebox.whitebox_tools import WhiteboxTools
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'whitebox'

Does anyone know how I might pin WhiteboxTools to v1.5.0?

PS - Even from inside wrfh_gis_env, it's still not clear where v2.1.0 comes from:

conda activate wrfh_gis_env
(wrfh_gis_env) > python

import whitebox as ; print(.path)
['/home/soft/miniconda3/envs/wrfh_gis_env/lib/python3.6/site-packages/whitebox']

conda deactivate
cd /home/soft/miniconda3/envs/wrfh_gis_env/lib/python3.6/site-packages/whitebox
ls -al

drwxrwxr-x 4 4096 Jun 28 15:54 WBT
-rw-rw-r-- 1 25866248 Jun 28 15:54 WhiteboxTools_linux_amd64.zip
-rw-rw-r-- 2 221 Jun 6 2021 init.py
drwxrwxr-x 2 4096 Jun 28 15:58 pycache
-rw-rw-r-- 2 3904 Jun 6 2021 automation.py
-rw-rw-r-- 2 416 Jun 6 2021 cli.py
-rw-rw-r-- 2 3831 Jun 6 2021 download_wbt.py
-rw-rw-r-- 2 2469 Jun 6 2021 example.py
drwxrwxr-x 2 4096 Jun 28 15:54 img
drwxrwxr-x 2 4096 Jun 28 15:54 plugins
drwxrwxr-x 2 4096 Jun 28 15:54 testdata
-rw-rw-r-- 2 58608 Jun 6 2021 wb_runner.py
-rw-rw-r-- 2 44 Jun 6 2021 whitebox.py
-rw-rw-r-- 2 6146 Jun 6 2021 whitebox_example.py
-rwxr-xr-x 1 29133144 Jun 28 15:54 whitebox_tools
-rw-rw-r-- 2 401432 Jun 6 2021 whitebox_tools.py

grep 2.1.0 *
Binary file WhiteboxTools_linux_amd64.zip matches
Binary file whitebox_tools matches

cat init.py

-- coding: utf-8 --

"""Top-level package for whitebox."""

author = """Qiusheng Wu"""
email = '[email protected]'
version = '1.5.0'

from .whitebox_tools import WhiteboxTools
from .wb_runner import Runner

failed to use the mosaic function

  • whitebox version: v 2.2.0
  • Python version:3.9
  • Operating System: windows 11

Hello Prof. Wu,

I tried to use the mosaic function according to the tutorial https://jblindsay.github.io/wbt_book/tutorials/mosaic.html, and it does not work.

here is the error report:

--output='M:\test\output\NAME_OF_FILE.tif' --method=nn -v --compress_rasters=False



Number of tiles: 2
Reading data...
thread 'main' panicked at 'index out of bounds: the len is 2 but the index is 2', whitebox-raster\src\geotiff\mod.rs:797:44
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

I do not know how to solve this problem, can you help me?

Best regards

glibc requirements

  • whitebox version: (latest, as of sept 2020)
  • Python version: 3.7
  • Operating System: Ubuntu 18.04

Description

I tried installing the latest version of Whitebox using:
pip install whitebox

It seems to install, but it won't run because I don't have glibc 2.29 ... (I can't even check the version)
error:
./whitebox_tools: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by ./whitebox_tools)

I'm running GLIBC 2.27... is upgrading to 2.29 really the only way to get whitebox working?

Whitebox resetting working directory to whitebox directory in Anaconda environment

  • whitebox version: 2.0.3
  • Python version: 3.9
  • Operating System: RedHat Enterprise

Description

When using any whitebox functions for python, the current working directory is reset to the whitebox directory in my anaconda environment (e.g. /home/user_name/minconda3/envs/osgeo-env-v1/lib/python3.8/site-packages/whitebox). This causes many problems, since I am using whitebox functions across multiple scripts for my automated workflow.

To clarify, after importing whitebox, the current working directory is set to my project directory where my python file is calling whitebox, which is what I want. But after using a function it is reset to the whitebox directory, so the functions do not end up running.

I am attempting this in jupyter notebook.

What I Did

from whitebox import whitebox_tools
wbt = whitebox_tools.WhiteboxTools()
CWD = "/home/user_name/project/data"
wbt.set_working_dir(CWD)
wbt.clip_lidar_to_polygon("./filename.las", polygons="./poly_shapefile.shp", output="./lidarClip.las")

Below is the error messages I receive.

image

Thank you for your time in reading this.

Error while call Runner()

  • whitebox version: latest
  • Python version: 3.4
  • Operating System: windows 10

Description

D:\Python34\python3.exe F:/demospace/whitebox/run.py
Traceback (most recent call last):
File "F:/demospace/whitebox/run.py", line 7, in
whitebox.Runner()
File "D:\Python34\lib\site-packages\whitebox\wb_runner.py", line 1129, in Runner
wbr = WbRunner(tool_name)
File "D:\Python34\lib\site-packages\whitebox\wb_runner.py", line 729, in init
for filename in glob.iglob('**/*', recursive=True):
TypeError: iglob() got an unexpected keyword argument 'recursive'

What I Did

import whitebox
whitebox.Runner()

Missing GLIBC library error with Python module

  • whitebox version:2.0.0
  • Python version:3.8
  • Operating System: Scientific Linux 7.9, 'Nitrogen'

Description

I have developed a program that uses the python whitebox module on my own computer that uses Centos 8, but when I try to install on our scientific linux machines I get the following error:
./whitebox_tools: /lib64/libm.so.6: version GLIBC_2.27' not found (required by ./whitebox_tools) ./whitebox_tools: /lib64/libc.so.6: version GLIBC_2.18' not found (required by ./whitebox_tools)

What I Did

I've seen this thread, which seems to address the same issue:
(https://github.com/jblindsay/whitebox-tools/issues/112)
but the solution is for the whitebox tool and not the python module and I haven't been able to adapt it to my own situation. Is it possible, or am I barking up the wrong tree?

Thanks in advance

How to stop the binary being downloaded?

Any use of the python library attempts to download a tarball into a read only directly on my system. I already have whitebox_tools on my path, so I do not want to download it again.

  1. The file should be downloaded into one of the XDG_* directories rather than into this read-only directory.
  2. The file wouldn't work even if it was downloaded on my OS so I would prefer to have the option to skip this step.
[nix-shell:~/whitebox-python]$ ./lidar.py 
Downloading WhiteboxTools pre-compiled binary for first time use ...
Unexpected error: <class 'OSError'>
Traceback (most recent call last):
  File "./lidar.py", line 5, in <module>
    from whitebox.whitebox_tools import WhiteboxTools
  File "/nix/store/cnzdmpl269k27j4j28l0xmi39yr278qw-python3-3.7.7-env/lib/python3.7/site-packages/whitebox/__init__.py", line 10, in <module>
    from .wb_runner import Runner
  File "/nix/store/cnzdmpl269k27j4j28l0xmi39yr278qw-python3-3.7.7-env/lib/python3.7/site-packages/whitebox/wb_runner.py", line 33, in <module>
    wbt = WhiteboxTools()
  File "/nix/store/cnzdmpl269k27j4j28l0xmi39yr278qw-python3-3.7.7-env/lib/python3.7/site-packages/whitebox/whitebox_tools.py", line 144, in __init__
    download_wbt()
  File "/nix/store/cnzdmpl269k27j4j28l0xmi39yr278qw-python3-3.7.7-env/lib/python3.7/site-packages/whitebox/whitebox_tools.py", line 55, in download_wbt
    urllib.request.urlretrieve(url, zip_name)   # Download WhiteboxTools
  File "/nix/store/syqcp8zb9c0vxj2sx6jbv5f9q7yki4jz-python3-3.7.7/lib/python3.7/urllib/request.py", line 257, in urlretrieve
    tfp = open(filename, 'wb')
OSError: [Errno 30] Read-only file system: '/nix/store/cnzdmpl269k27j4j28l0xmi39yr278qw-python3-3.7.7-env/lib/python3.7/site-packages/whitebox/WhiteboxTools_linux_amd64.tar.xz'

Can we make the distinction between this repo and Whitebox-tools clearer

There seems to be some confusion about the nature of this repo. As you are aware, this repo only contains the Python front-end for WhiteboxTools and is not the WhiteboxTools project itself. Is it possible to make this distinction clearer on the homepage so that people don't continue to report issues here rather than at jblindsay/whitebox-tools? I would suggest 1) renaming of this repo to something like whitebox-python, 2) making the fact that this is a frontend only clearer (although I know that it is already there in the description), 3) adding a statement about issuing tool functioning specific errors to the appropriate repository.

VectorPolygonsToRaster issue

  • whitebox version: 0.9.0
  • Python version: 3.7.3
  • Operating System: Windows 10

Description

The whitebox tool "VectorPolygonsToRaster" return a different result compare to the Whitebox GAT -win tool "Vector polygons to raster" . The output .tif has gaps!!!

What I Did

from whitebox import WhiteboxTools

# Set up the environment
wbt = WhiteboxTools()
data_dir = "/../whitebox_issue"
wbt.work_dir = (data_dir) 

i_vector = "poly.shp"
fieldZ = "Value"
out_raster = "poly2raster_PYTHON.tif"

wbt.vector_polygons_to_raster(
    i=i_vector,
    output=out_raster,
    field=fieldZ,
    nodata=True,
    cell_size=1,
   # base=None,
   # callback=default_callback
)

Vector Polygons To Raster - GAT-win

poly2raster_GAT-win
poly2raster_PYTHON

Discontinuous streams

  • whitebox version: 2.1.4
  • Python version: 3.8
  • Operating System: Scientific Linux (Rocky 8)

Description

This is probably not an issue with the tools, but am struggling to extract a continuous stream network from a DEM. I've been experimenting with it for some time but have been unable to improve on what I have now, which is 95% of a drainage network, but with intermittent gaps. The gaps occur where the downhill slope flattens off, even though there is still an obvious channel. I'm guessing that issue originates at the breach_depressions_least_cost stage, but I've experimented with the parameters and can't improve on what I have now, which is no good.

Discontinuous_streams

What I Did

dem.zip

My method is:

breach_depressions_least_cost: dist=10, max_cost=100, min_dist=True, fill=True,
d8_flow_accumulation: out_type="catchment area"
extract_streams: threshold=3000

Regarding the parameters. I've experimented with a wide range of values for breach depressions dist and max_cost. The values I've shown here work for most of the DEM, but still leave gaps in the stream network.

Any help would be appreciated.

Thanks,
Rick

Whiteboxtools in AWS Sagemaker

I was able to install whiteboxtools in AWS Sagemaker notebook instance.
When I tried to execute commands:

import whitebox
wbt = whitebox.WhiteboxTools()
print(wbt.tool_help("ElevPercentile")) and
print(wbt.help())

There is no output printed.
Can anyone help me with how to use whiteboxtools and get results in AWS cloud. Thank you in advance.

Whitebox python lib method lidar_digital_surface_model getting stuck at filtering

  • whitebox version: v2.2.0
  • Python version: Python 3.9.13
  • Operating System: macOsX 13.2, Ubuntu 20.04, Ubuntu 22.04

Description

I am trying to convert lidar files to DSM raster, using method lidar_digital_surface_model.
For certain lidars, the method is getting stuck at filtering.
Example input lidar files can be obtained from USGS links:

  1. https://rockyweb.usgs.gov/vdelivery/Datasets/Staged/Elevation/LPC/Projects/FEMA_R6_AR_Dardanelle_Reservoir_QL2_Lidar/AR_DardanelleReservoir_2015/LAZ/USGS_LPC_FEMA_R6_AR_Dardanelle_Reservoir_QL2_Lidar_15svv560345.laz

  2. https://rockyweb.usgs.gov/vdelivery/Datasets/Staged/Elevation/LPC/Projects/FEMA_R6_AR_Dardanelle_Reservoir_QL2_Lidar/AR_DardanelleReservoir_2015/LAZ/USGS_LPC_FEMA_R6_AR_Dardanelle_Reservoir_QL2_Lidar_15svv560270.laz

Logs:


./whitebox_tools --run="LidarDigitalSurfaceModel" --wd="/tmp" --input='647910b9d34eac007b50fc55_USGS_LPC_FEMA_R6_AR_Dardanelle_Reservoir_QL2_Lidar_15svv560345.laz' --output='dsm_from_laz_1.tif' --resolution=0.5 --radius=0.5

***************************************
* Welcome to LidarDigitalSurfaceModel *
* Powered by WhiteboxTools            *
* www.whiteboxgeo.com                 *
***************************************
Performing interpolation...
Reading input LiDAR file...
Reading points: 0%
Reading points: 1%
Reading points: 2%
Reading points: 3%
.....
.....

Reading points: 99%
Reading points: 100%
Filtering points: 0%
Filtering points: 1%
Filtering points: 2%
Filtering points: 3%
....
....
Filtering points: 30%
Filtering points: 31%
Filtering points: 32%

Process got stuck at 32% for one on the Lidar file. This percentage varies from Lidar to Lidar.

Expected result:

  • Should convert Lidar to DSM raster
  • Or should fail gracefully

What I Did

Code used:


import whitebox

def convert_to_dsm(laz_file_name, output_file_name):
    wbt_digital_surface_model_lidar(laz_file_name, output_file_name)

def __handle_whitebox_errors__(output):
    if 'panicked' in output or 'Error reading LAZ' in output or 'Warning: No points found' in output:
       
        print(f"whitebox processing of lidar throw error: {output}")
        raise Exception(message = f"whitebox processing of lidar throw error: {output}")       
    else:
        print(f"{output}")

def wbt_digital_surface_model_lidar(lidar_file, converted_file_name) -> str:
    print("#initialize whitebox tool")
    wbt = whitebox.WhiteboxTools()
    print(f"Whitebox tool version: {wbt.version()}")
    wbt.work_dir = "/tmp"
    dsm_output_tif = converted_file_name 
    callback_function = lambda output: __handle_whitebox_errors__(output)
    
    wbt.lidar_digital_surface_model(
        i=lidar_file,
        output=dsm_output_tif,
        resolution=0.5,
        radius=0.5, 
        minz=None, 
        maxz=None, 
        max_triangle_edge_length=None,
        callback=callback_function
    )               
         
    print(f"dsm_output_tif: {dsm_output_tif}")
    return dsm_output_tif

if __name__ == "__main__":
    laz_file = "647910b9d34eac007b50fc55_USGS_LPC_FEMA_R6_AR_Dardanelle_Reservoir_QL2_Lidar_15svv560345.laz"
    tif_file_name = "dsm_from_laz_1.tif"
    convert_to_dsm(laz_file, tif_file_name)

    

wbe.contours_from_raster doesn't work

whitebox version: whitebox-workflows 1.1.0
Python version: 3.11
Operating System: Windows

I am trying to generate contour curves from the following code:

import whitebox_workflows as wbw
wbe = wbw.WbEnvironment()

raster = wbe.read_raster('test.tif')

wbe.contours_from_raster(
raster,
'contours.shp',
contour_interval = 10,
base_contour = 57
)

However, the following error appears:
TypeError: WbEnvironment.contours_from_raster() got multiple values for argument 'contour_interval'

I tried using the default value, however the following error appears:
TypeError: argument 'contour_interval': must be real number, not str

LidarElevationSlice isn't slicing

  • whitebox version: v0.13.0
  • Python version:
    • Python 3.6.7 (v3.6.7:6ec5cf24b7, Oct 20 2018, 03:02:14)
    • [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
  • Operating System: MacOS Mojave 10.14.2

Description

Describe what you were trying to get done.

I have a small, 200 MB, colorized, indoor lidar point cloud of a conference room. I'm trying to extract a slice of it.

The lidar_info output is the following:

File Signature: LASF
File Source ID: 0
Global Encoding:
GPS time=GpsWeekTime,
Waveform data internal=false,
Waveform data external=false,
Return data synthetic=false,
CRS method=WellKnownText
Project ID (GUID): {0-0-0-00-000000}
System ID: EXTRACTION
Generating Software: WhiteboxTools 
Las Version: 1.3
File Creation Day/Year: 18/2019
Header Size: 235
Offset to Points: 440
Number of VLRs: 2
Point Format: 3
Point Record Length: 34
Num. of Points (32-bit): 5869712
Number of Points by Return: [11739424, 0, 0, 0, 0]
X Scale Factor: 0.0001
Y Scale Factor: 0.0001
Z Scale Factor: 0.0001
X Offset: -19.8205
Y Offset: -44.6813
Z Offset: 0.15910000000000002
Max X: 21.220100000000002
Min X: -19.8205
Max Y: 82.7065
Min Y: -44.6813
Max Z: 7.1942
Min Z: 0.15910000000000002
Waveform Data Start: 0
Min Intensity: 514
Max Intensity: 63737

Tell us what happened, what went wrong, and what you expected to happen.

When I try to use the lidar_elevation_slice command, it outputs a file the exact same size and no points have been removed as far as I can tell.

What I Did

Here is the command I'm running:

import whitebox
wbt = whitebox.WhiteboxTools()
wbt.set_working_dir(os.getcwd())
wbt.lidar_elevation_slice("test1.las", "test2.las", minz=3.0, maxz=5.0, cls=False)

The command-line output looks ok:

./whitebox_tools --run="LidarElevationSlice" --wd="<full path removed>/Data" --input='test1.las' --output='test2.las' --minz='3.0' --maxz='5.0' --inclassval=2 --outclassval=1 -v

***********************************
* Welcome to lidar_elevation_slice *
************************************
Reading input LAS file...
Performing analysis...
Saving data: 0%
Saving data: 1%
Saving data: 2%
Saving data: 3%
Saving data: 4%
Saving data: 5%
Saving data: 6%
Saving data: 7%
Saving data: 8%
Saving data: 9%
Saving data: 10%
Saving data: 11%
Saving data: 12%
Saving data: 13%
Saving data: 14%
Saving data: 15%
Saving data: 16%
Saving data: 17%
Saving data: 18%
Saving data: 19%
Saving data: 20%
Saving data: 21%
Saving data: 22%
Saving data: 23%
Saving data: 24%
Saving data: 25%
Saving data: 26%
Saving data: 27%
Saving data: 28%
Saving data: 29%
Saving data: 30%
Saving data: 31%
Saving data: 32%
Saving data: 33%
Saving data: 34%
Saving data: 35%
Saving data: 36%
Saving data: 37%
Saving data: 38%
Saving data: 39%
Saving data: 40%
Saving data: 41%
Saving data: 42%
Saving data: 43%
Saving data: 44%
Saving data: 45%
Saving data: 46%
Saving data: 47%
Saving data: 48%
Saving data: 49%
Saving data: 50%
Saving data: 51%
Saving data: 52%
Saving data: 53%
Saving data: 54%
Saving data: 55%
Saving data: 56%
Saving data: 57%
Saving data: 58%
Saving data: 59%
Saving data: 60%
Saving data: 61%
Saving data: 62%
Saving data: 63%
Saving data: 64%
Saving data: 65%
Saving data: 66%
Saving data: 67%
Saving data: 68%
Saving data: 69%
Saving data: 70%
Saving data: 71%
Saving data: 72%
Saving data: 73%
Saving data: 74%
Saving data: 75%
Saving data: 76%
Saving data: 77%
Saving data: 78%
Saving data: 79%
Saving data: 80%
Saving data: 81%
Saving data: 82%
Saving data: 83%
Saving data: 84%
Saving data: 85%
Saving data: 86%
Saving data: 87%
Saving data: 88%
Saving data: 89%
Saving data: 90%
Saving data: 91%
Saving data: 92%
Saving data: 93%
Saving data: 94%
Saving data: 95%
Saving data: 96%
Saving data: 97%
Saving data: 98%
Saving data: 99%
Saving data: 100%
Writing output LAS file...
Complete!
0

But I get the entire file and not a slice.

What am I doing wrong?

Thanks in advance!

wbt.conditional_evaluation() function return 0,but no result export

  • whitebox version: newest
  • Python version: python 3.8
  • Operating System: Mac

Description

Describe what you were trying to get done.
replace the rasterline values with DEM values

What I Did

wbt.conditional_evaluation(
i='/home/jovyan/data/mynotebook/data/rasterline.tif',
output='/home/jovyan/data/mynotebook/data/boundry.tif',
statement='value >= 0.0',
true='/home/jovyan/data/mynotebook/data/Elevation1.tif',
false='#')

Paste the command(s) you ran and the output.
return 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.