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

mosaic raster issue: Bounds and transform are inconsistent #59

Open
iamtekson opened this issue Dec 6, 2023 · 4 comments
Open

mosaic raster issue: Bounds and transform are inconsistent #59

iamtekson opened this issue Dec 6, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@iamtekson
Copy link
Member

---------------------------------------------------------------------------
WindowError                               Traceback (most recent call last)
/mnt/d/tek/sm/code/prediction_merge.ipynb Cell 24 line 3
      1 from geotile import mosaic
----> 3 mosaic(f'{PLACE_NAME}_S2_{YM}', f'../data/img&pred/s2_rivers/pred/{PLACE_NAME}_S2_{YM}_pred.tif')

File ~/miniconda3/envs/tf212/lib/python3.9/site-packages/geotile/utils.py:49, in mosaic(input_folder, output_file, image_format, **kwargs)
     46     src_files_to_mosaic.append(src)
     48 # Merge the rasters
---> 49 mosaic, out_trans = merge(src_files_to_mosaic, **kwargs)
     51 # update the metadata
     52 meta = src.meta.copy()

File ~/miniconda3/envs/tf212/lib/python3.9/site-packages/rasterio/merge.py:344, in merge(datasets, bounds, res, nodata, dtype, precision, indexes, output_count, resampling, method, target_aligned_pixels, dst_path, dst_kwds)
    341 src_window = windows.from_bounds(int_w, int_s, int_e, int_n, src.transform)
    343 # 3. Compute the destination window
--> 344 dst_window = windows.from_bounds(
    345     int_w, int_s, int_e, int_n, output_transform
    346 )
    348 # 4. Read data in source window into temp
    349 src_window_rnd_shp = src_window.round_lengths()

File ~/miniconda3/envs/tf212/lib/python3.9/site-packages/rasterio/windows.py:324, in from_bounds(left, bottom, right, top, transform, height, width, precision)
    322     raise WindowError("Bounds and transform are inconsistent")
    323 if (bottom - top) / transform.e < 0:
--> 324     raise WindowError("Bounds and transform are inconsistent")
    326 rows, cols = rowcol(
    327     transform,
    328     [left, right, right, left],
    329     [top, top, bottom, bottom],
    330     op=float,
    331 )
    332 row_start, row_stop = min(rows), max(rows)

WindowError: Bounds and transform are inconsistent
@iamtekson iamtekson added the bug Something isn't working label Dec 6, 2023
@iamtekson
Copy link
Member Author

Possible solution

Here are a few steps you can take to troubleshoot this issue:

  1. Check Coordinate Systems: Verify that all the datasets or images involved in the mosaic operation share the same coordinate system. Even a slight difference could cause inconsistency.

  2. Confirm Bounds: Ensure that the bounding coordinates (left, bottom, right, top) are correctly defined and consistent with the coordinate system used.

  3. Transformation Information: Double-check the transformation or georeferencing information associated with your raster datasets. Ensure they are accurate and consistent.

  4. Data Integrity: Check the integrity of your raster data files. Sometimes corrupt or incomplete files can cause issues with their transformation information.

@iamtekson
Copy link
Member Author

iamtekson commented Dec 7, 2023

This might be an issue from rasterio library: rasterio/rasterio#2976

@iamtekson

This comment was marked as outdated.

@iamtekson
Copy link
Member Author

By doing so many tests, I found that if the raster have float64 dtype, it create the problem. When I check, I found that, in float64 dtype raster, generate_tiles start creating the tiles from bottom left of the raster moving in the top and right direction while for other dtype raster, it start creating the tiles from top left moving in the bottom and right direction. It is still kind of strange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant