Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to use the mosaic function in whitebox (python script) #309

Closed
lthough123 opened this issue Jan 5, 2023 · 4 comments · May be fixed by #313
Closed

Failed to use the mosaic function in whitebox (python script) #309

lthough123 opened this issue Jan 5, 2023 · 4 comments · May be fixed by #313

Comments

@lthough123
Copy link

Hello,

I find that there is a problem when I tried to use the mosaic function in the whitebox python package.
I used the following codes (according to the example in the tutorial):

import os,glob
import whitebox

wbt=whitebox.WhiteboxTools()

wbt.set_verbose_mode(True)
input_directory = r"M:\Clumpingindex\test"
output_directory = r"M:\Clumpingindex\output"

if os.path.isdir(output_directory) != True:
os.mkdir(output_directory)

wbt.set_working_dir(input_directory)
outfile = os.path.join(output_directory,"test.tif")
wbt.mosaic(
output=outfile,
method = "nn"
)

and here is the error report:
.\whitebox_tools.exe --run="Mosaic" --wd="M:\Clumpingindex\test" --output='M:\Clumpingindex\output\NAME_OF_FILE.tif' --method=nn -v --compress_rasters=True



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

Can you help me fix this problem? Thanks a lot.

Best regards

@jfbourdon
Copy link
Contributor

Your issue most likely has to do with your input files. The number of bits per sample of the files seems to not have been parsed correctly. Can you share your two input files?

@lthough123
Copy link
Author

Hello,

Here are the tif files.
test.zip
In addition, I tried to use the gdal_merge tool and it works. I hope this information will help you to find out the problem.

Best regards

@jfbourdon
Copy link
Contributor

I made some tests found two things that are wrong:

First, the header of your TIFF files is not complety right. I can't say exactly what, but it's something minor enough that GDAL can bypass it but major enough that WhiteboxTools cannot. In fact, if you do a gdal_translate with both of your files simply to resave them in a new file, those two new files won't crash WhiteboxTools.

The second issue is that the Mosaic tool expect only single band rasters even thought the documentation doesn't specify it. Using a two band raster will interleave both bands in the merged (single band) raster instead of merging each band independently.

Also, it doesn't play here, but if the input raster doesn't have a NoData defined (like yours), the tool will force one anyway in the output raster according to the data type, in this case -32768 for an Int16.

@lthough123
Copy link
Author

Now I understand it. Thank you for your response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants