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

Reprojection of a multiband Raster on a single band Raster doesn't work #590

Open
Falawiss opened this issue Jul 3, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@Falawiss
Copy link

Falawiss commented Jul 3, 2024

Describe the bug
the Raster.reproject() function raise an error when the reference Raster have less band than the source one.

To Reproduce

import geoutils as gu
raster_3b = gu.Raster(gu.examples.get_path("everest_landsat_rgb")) # 3 bands Raster
raster_1b = gu.Raster(gu.examples.get_path("everest_landsat_b4_cropped")) # 1 band Raster
raster_1b.reproject(raster_3b) # works perfectly
raster_3b.reproject(raster_1b) # Raise an error

Expected behavior
I want the 3 bands of the raster_3b to be reprojected over the raster_1b

System (please complete the following information):

  • macOS
  • Conda (I'm not sure of what is expected here)

Additional context
Can be solved by import separately the bands using Raster.reproject parameters : bands and load_data=True. But it's creating n-bands Raster objects instead of one.

@Falawiss Falawiss added the bug Something isn't working label Jul 3, 2024
@adehecq
Copy link
Member

adehecq commented Jul 3, 2024

Hi Gabin,
Thanks for raising the issue!
Indeed, a quick workaround is to run:

raster_3b = gu.Raster(gu.examples.get_path("everest_landsat_rgb"), load_data=True)  # make sure data is loaded
raster_1b = gu.Raster(gu.examples.get_path("everest_landsat_b4_cropped"))
raster_3b.reproject(raster_1b)

The issue occurs only when the data is not loaded, at this line.
What happens is that we load only 1 band at a time, but in the reproj_kwargs, the output shape is set to same as input. For a 3-band raster, we are creating 3 3-band rasters, so the number of bands end up being 9... I think this can be easily fixed by removing the loop over bands.
We'll fix this when we find time!

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

2 participants