jgrss / geowombat

GeoWombat: Utilities for geospatial data
https://geowombat.readthedocs.io
MIT License
184 stars 10 forks source link

Apply on bands error #274

Closed mmann1123 closed 1 year ago

mmann1123 commented 1 year ago

Found a bug.

# Here is a function with 1 argument
def my_func1(w, block, arg):
    return w, block * arg

gw.apply(
    l8_224078_20200518,
    "output.tif",
    my_func1,
    args=(10.0,),
    n_jobs=8,
)

Throws:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[/home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py](https://vscode-interactive+.vscode-resource.vscode-cdn.net/home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py) in line 9
      [97](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=96) def my_func1(w, block, arg):
      [98](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=97)     return w, block * arg
----> [101](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=100) gw.apply(
     [102](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=101)     l8_224078_20200518,
     [103](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=102)     "output.tif",
     [104](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=103)     my_func1,
     [105](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=104)     args=(10.0,),
     [106](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=105)     n_jobs=8,
     [107](file:///home/mmann1123/Documents/github/YM_TZ_crop_classifier/experiments.py?line=106) )

File [~/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py:1522](https://vscode-interactive+.vscode-resource.vscode-cdn.net//~/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py:1522), in apply(infile, outfile, block_func, args, count, scheduler, gdal_cache, n_jobs, overwrite, tags, **kwargs)
   [1517](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1516) for f in tqdm(
   [1518](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1517)     concurrent.futures.as_completed(futures),
   [1519](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1518)     total=len(futures),
   [1520](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1519) ):
   [1521](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1520)     out_window, out_block = f.result()
-> [1522](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1521)     dst.write(
   [1523](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1522)         np.squeeze(out_block),
   [1524](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1523)         window=out_window,
   [1525](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1524)         indexes=out_indexes,
   [1526](file:///home/mmann1123/miniconda3/envs/os_prog/lib/python3.8/site-packages/geowombat/core/io.py?line=1525)     )

File rasterio/_io.pyx:1695, in rasterio._io.DatasetWriterBase.write()

ValueError: Source shape (1, 3, 256, 256) is inconsistent with given indexes 1
mmann1123 commented 1 year ago

Setting count (not documented) doesn't help

gw.apply(
    l8_224078_20200518,
    "output.tif",
    my_func1,
    args=(10.0,),
    n_jobs=8,
    count =3
)
IndexError: band index 2 out of range (not in (1,))