whitebox-tools icon indicating copy to clipboard operation
whitebox-tools copied to clipboard

'mosaic' tool panicking with unspecified inputs

Open wyowill opened this issue 5 years ago • 7 comments
trafficstars

I'm trying to create a single mosaic from many (~12,000) tif tiles and keep receiving the following:

thread 'main' panicked at 'There is something incorrect about the input files. At least two inputs are required to operate this tool.', src\main.rs:72:21 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

I am running WB v1.3.1 in a Jupyter Notebook in Python 3.7 on a Windows 7 Pro PC.

given:

in_folder = "C:\\Users\\SomeUser\\LiDAR_Tiles\\"
out_raster = "D:\\SpatialData\\Topo\\LiDARDEM_2013_AOI.tif"

os.chdir(in_folder)
print("Working directory: {}".format(in_folder))

I've tried: wbt.mosaic(out_raster, inputs=None) wbt.mosaic(out_raster) wbt.mosaic(,out_raster)

I've also tried inputting from a list:

tiles = []
for file in glob.glob("*.tif"):
    tiles.append(file)

wbt.mosaic((i for i in tiles), output=out_raster)

wbt.mosaic(tiles, out_raster)

Any help is appreciated.

wyowill avatar Aug 06 '20 21:08 wyowill

Try the WBT Runner to see if it works. If yes, then the issue is either caused by your source code or the Python frontend. Try mosaicking a few files first before using ~12,000 files.

import whitebox
whitebox.Runner()

giswqs avatar Aug 06 '20 21:08 giswqs

Also try this:

tiles = []
for file in glob.glob("*.tif"):
    tiles.append(file)

in_rasters = ';'.join(tiles)

wbt.mosaic(inputs=in_rasters, output=out_raster)

giswqs avatar Aug 06 '20 21:08 giswqs

Good suggestions.

re:

  • 'mosaic' through Runner() works with limited test set
  • adding the join statement to the notebook allows the 'mosaic' to run, but I get the following:

*********************
* Welcome to Mosaic *
*********************
Number of tiles: 5
Reading data...
Warning: Error reading file DEM_BN33_2013_1000_3111.tif
Progress: 0%
Warning: Error reading file DEM_BN33_2013_1000_3112.tif
Progress: 25%
Warning: Error reading file DEM_BN33_2013_1000_3211.tif
Progress: 50%
Warning: Error reading file DEM_BN33_2013_1000_3212.tif
Progress: 75%
Warning: Error reading file DEM_BN33_2013_1000_3213.tif
Progress: 100%
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', src\tools\image_analysis\mosaic.rs:422:29
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

However, your join suggestion led me to try: in_rasters = ';'.join((in_folder+i) for i in tiles)

So the solution is passing the entire path and name with each file.

Cheers

wyowill avatar Aug 06 '20 22:08 wyowill

solution was passing the entire path and name with each file:

in_rasters = ';'.join((in_folder+i) for i in tiles)

wyowill avatar Aug 06 '20 23:08 wyowill

When mosacing large numbers of tiles, the best approach is to set the working directory to a directory containing your input images (and no other rasters) and then run the mosaic tool without specifying any input file names. The input files parameter is optional for this reason. When left unspecified, the tool will simply discover all rasters in the working directory. This approach has worked for me when I have mosaiced over 23,000 tiles at one time. I should really do a better job of documenting this feature in the user manual.

jblindsay avatar Aug 06 '20 23:08 jblindsay

Cheers John. I attempted that initially (as indicated in the user-manual), but unsuccessfully.

In addition to the syntax variants I tried (see initial my post), I get the following when I run on the test data:

in_folder = "C:\\Users\\Will\\Desktop\\Temp\\LiDAR_Tiles\\test\\"
os.chdir(in_folder)
wbt.mosaic(out_raster)

  • Welcome to Mosaic *

Number of tiles: 0 thread 'main' panicked at 'There is something incorrect about the input files. At least two inputs are required to operate this tool.', src\main.rs:72:21 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

if trying as a keyword arg:

wbt.mosaic(output=out_raster)


  • Welcome to Mosaic *

Number of tiles: 0 thread 'main' panicked at 'There is something incorrect about the input files. At least two inputs are required to operate this tool.', src\main.rs:72:21 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

The only way I seem to be able to get it to run successfully (on test data set) is if I compile a list of files, then join to a single string. Any other thoughts on what to try?

wyowill avatar Aug 07 '20 05:08 wyowill

reopening as I get the following error when scaling-up the list-based workaround I used on test data:

[WinError 206] The filename or extension is too long

Which makes sense given the full path X number of files.

wyowill avatar Aug 07 '20 05:08 wyowill