jblindsay / whitebox-tools

An advanced geospatial data analysis platform
https://www.whiteboxgeo.com/
MIT License
967 stars 161 forks source link

Whitebox 2.3.3 (Python): Unrecognized tool name ConditionalEvaluation #411

Closed geotom closed 5 months ago

geotom commented 5 months ago

Error

I noticed that since the recent release 2.3.3 on PyPi (https://pypi.org/project/whitebox/2.3.3/) a script of mine fails with the following whitebox debug logs

./whitebox_tools --run="ConditionalEvaluation" --wd="/celery" --input='a.tif' --statement=value == minvalue && value < -1000 - -true='b.tif' -v --compress_rasters=True
thread 'main' panicked at whitebox-tools-app/src/main.rs:72:21:
Unrecognized tool name ConditionalEvaluation.
run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Code

The code has not changed and calls this function as follows:

wbt.conditional_evaluation(
                                "a.tif",
                                "b.tif",
                                statement="value == minvalue && value < -1000",
                                true="source.tif",
                                false="a.tif",
                            )

What could the issue be?

giswqs commented 5 months ago

This seems a WBT frontend issue. Please report it at https://github.com/opengeos/whitebox-python

geotom commented 5 months ago

Thanks for the fast feedback @giswqs. I opened this issue now here: https://github.com/opengeos/whitebox-python/issues/67 ...closing this one

giswqs commented 5 months ago

My bad. I think this is a WBT backend issue. You can reopen this issue. image

geotom commented 5 months ago

Opened again. The problem for me is that I cannot revert back to whitebox-python version 2.3.1, because the papi package install seems also broken

giswqs commented 5 months ago

The pypi package automatically downloads the last WBT binary from whiteboxgeo.com. It is not broken. This issue is probably caused by the WBT binary, which doesn't contain the tool you want to use

jblindsay commented 5 months ago

@giswqs I can confirm that the zip files for v2.4 do contain the binary for the conditional evaluation tool. I'm not sure exactly what is causing this error, but I'll take a closer look when I get a chance.

giswqs commented 5 months ago

I notice the Binary is trying to call the tool Confiditionalevaluation. Note the lower case e for evaluation. Would that be an issue?

giswqs commented 5 months ago

Maybe an frontend issue when converting between snake case and camel case? I am not quite sure. Need to look into it

geotom commented 5 months ago

Thanks for looking into that and very much appreciated if this could be solved relatively soon. If it is a case of the "tool" name case conversion, then other tools might be affected as well?

jblindsay commented 5 months ago

Okay, I've just tested with the following script:

from WBT.whitebox_tools import WhiteboxTools

wbt = WhiteboxTools()
print(wbt.version())
wbt.set_working_dir('/Users/johnlindsay/Documents/data/Guelph/')
wbt.conditional_evaluation(
    "campus_DSM.tif",
    "tmp1.tif",
    statement="value>250",
    true="campus_DSM.tif",
    false="1.0",
)

And I got this successful output:

johnlindsay@Johns-MacBook-Pro python % python3 conditional_eval.py WhiteboxTools v2.4.0 (c) Dr. John Lindsay 2017-2023

WhiteboxTools is an advanced geospatial data analysis platform developed at the University of Guelph's Geomorphometry and Hydrogeomatics Research Group (GHRG). See www.whiteboxgeo.com for more details.

./whitebox_tools --run="ConditionalEvaluation" --wd="/Users/johnlindsay/Documents/data/Guelph" --input='campus_DSM.tif' --statement=value>250 --true='campus_DSM.tif' --false='1.0' --output='tmp1.tif' -v --compress_rasters=False


  • Welcome to ConditionalEvaluation *
  • Powered by WhiteboxTools *
  • www.whiteboxgeo.com *

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

Elapsed Time (Including I/O): 1.345s

I also tested with the Whitebox Runner and it also worked without issue. I suspect therefore that this is an issue with the PyPi frontend and not the Whitebox backend.

giswqs commented 5 months ago

Thanks for testing it out. I will look into the pypi frontend

giswqs commented 5 months ago

@jblindsay I did some experiments and found something interesting. The following comand works fine when the WBT binary stays within the WBT folder. However, if we move the binary outside the WBT folder, the following command will fail to find the tool, specificly the ConditionalEvaluation and ConditionedLatinHypercube tools. Other tools are fine. So I think the issue is related to the WBT backend as the PyPI package is not being used here.

./whitebox_tools --toolparameters="ConditionalEvaluation"

image

sg-novelt commented 5 months ago

Disclaimer: co-worker of @geotom here.


The following comand works fine when the WBT binary stays within the WBT folder. However, if we move the binary outside the WBT folder, the following command will fail to find the tool, specificly the ConditionalEvaluation and ConditionedLatinHypercube tools.

I could reproduce this, and I suspect this could be due to some static linking within the WBT directory. An easy workaround is to create a symbolic link to the whitebox_tools binary instead of copying it. I used ln -s /.venv/lib/python${PYTHON_RUNTIME_VERSION}/site-packages/whitebox/WBT/whitebox_tools /.venv/lib/python${PYTHON_RUNTIME_VERSION}/site-packages/whitebox/whitebox_tools and it works. Maybe you might consider using os.symlink instead of shutil.copy here?

jblindsay commented 5 months ago

@giswqs WhiteboxTools assumes a certain file structure. You cannot move the Whitebox_tools binary outside of the WBT folder, otherwise the binary will not be able to locate any of the plugin tools contained within the WBT/plugins folder, which includes both the ConditionalEvaluation and ConditionalLatinHypercube tools (along with many others). The reason that some of the other functions worked for you (e.g., FillDepressions) is because they aren't plugin tools and are literally contained within the whitebox_tools binary. The expanding size of that binary file is the reason why I created the plugin infrastructure. But the plugins folder needs to be a sub-directory of the whitebox_tools binary containing folder.

giswqs commented 5 months ago

Yeah, I figured it out earlier. I just need to move the plugins folder as well so that both the binary and plugins folder are under the same directory. https://github.com/opengeos/whitebox-python/pull/68

jblindsay commented 5 months ago

I still think this is a frontend issue. If the tools works in the Whitebox Runner, then it's not on the backend.

sg-novelt commented 5 months ago

FYI, we just opened a follow-up issue on the front-end repository: https://github.com/opengeos/whitebox-python/issues/69. Mentioning it here because it is tightly bound to the back-end as well.

giswqs commented 5 months ago

This issue has been resolved in https://github.com/opengeos/whitebox-python/pull/68. It can be closed now.