-
Notifications
You must be signed in to change notification settings - Fork 19
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
Adding overloading functionality for add, sub and neg #173
Conversation
For whatever reason I accidentally included the commit from my previous PR... |
This is looking great!!
|
Well, this is already following numpy's way. Under the hood it's simply an operation between numpy arrays so the output type of the array is set by numpy and then the Raster dtype is set from the numpy array. In my example with the numpy array for example, the output Raster has a type float64.
Mmmh, interesting idea! We sort of have this functionality already with the 'do-it-all' reproject function, which can convert dtype, except that right now if only the data type changes it won't do anything. So it could be a separate method yes.
I will! And r1 * r2.
If data.shape is not the same, an error is raised. So for now, both Rasters need to have the same amount of bands loaded into memory. We could also decide to use the first band by default, but it's so easy to load only a single or part of the bands with |
Sounds good with the dtype handling and band errors! An |
Actually, the question of dtypes is a problem for the subtraction...
That's because running |
Why does it fail? Because -r2 doesn't work with a uint8 dtype? How does that work for uint8 ndarrays? |
Because of this: |
It's actually a simple fix, I just need to make sure that the second argument has a compatible type with self, before doing the negation. |
….astype method to change a raster's dtype
Nice!! Does * and / work or is this still in the works? |
Still in the work. I'm working on the tests for the new methods right now. |
@erikmannerfelt, if that version is ok, should we accept this PR and I'll create the multiplication/division in a new PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make a new PR for the / and * operators!
With this PR, it will now be possible to add, subtract and calculate the opposite of a Raster object.
Here is a quick example:
This also works with numpy arrays or single numbers, e.g.:
Question:
One thing I have completely ignored for now is data type. If the two rasters are 'uint8' like in the example, the output will also be of type uint8. This will lead to weird results for values > 255 (and similarly for other types with larger values).
Should a condition be added to check that the output value is within the dtype range?
Should a warning be raised? Should the output data type be set accordingly?
What do you think @erikmannerfelt @atedstone ?
To Do:
Add some tests.