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

Numpy representation of Rasters causes issue with arithmetic overloading #256

Closed
adehecq opened this issue Oct 15, 2021 · 2 comments · Fixed by #302
Closed

Numpy representation of Rasters causes issue with arithmetic overloading #256

adehecq opened this issue Oct 15, 2021 · 2 comments · Fixed by #302
Labels
bug Something isn't working

Comments

@adehecq
Copy link
Member

adehecq commented Oct 15, 2021

This is a bug on a yet non-existing code, but related to on-going work on issue #73.
The idea is to enable rout = r1 + r2 with r1 being a Raster and r2 being either a Raster, a numpy array, or a number. This should return a Raster.
This works great in most cases, except in the situation when r1 is a numpy array and r2 a Raster. In that case, numpy's __add__ method is used instead, which returns a numpy array. This is counter-intuitive in my opinion and should be avoided.
I believe the reason behind it is the numpy's interface, related to PR #210. When issue #73 is solved, one needs to check how to have both features working together.

@adehecq adehecq added the bug Something isn't working label Oct 15, 2021
@erikmannerfelt
Copy link
Contributor

Is this still an issue?

Also perhaps this should be done in conjunction with #261

@rhugonnet
Copy link
Contributor

This actually works now with #302 (the numpy interface is not taking over anymore):

test = np.ones(r.shape) + r
type(test)
Out[15]: geoutils.georaster.raster.Raster
test = r + np.ones(r.data.shape)
type(test)
Out[17]: geoutils.georaster.raster.Raster

However, as you can notice, I have to change the shape to .data.shape on one side, and not another, otherwise:

ValueError: Both rasters must have the same shape.

I'll leave this issue to be closed by #302 and open a new one on this.

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
3 participants