-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fix interp_points + add assertion in test #120
Conversation
Upstream update
fixing bug with None when no metadata is found
Update upstream
Fix issue with from_array and add tests (GlacioHack#116)
Upstream update
EDIT: adding "Resolves" in comment doesn't seem to link to the 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.
I only have some performance suggestions.
No wonder I couldn't get my head around those tests. r.ds.index(x,y)
Out[33]: (75, 301)
r.ds.index(x,y,op=np.float32)
Out[34]: (75.0, 302.0) Just by changing operator, you shift y by 1. Right now How should we go about this? |
Hahaha what!? That should probably be added as an issue on rasterio, no? A quick search in their issues shows no result corresponding to this phenomenon. Could this be circumvented for now, and then hopefully be fixed by rasterio in time? |
Wait for the next level: r.ds.index(x,y,op=np.float32,precision=10)
Out[20]: (138.0, 504.0)
r.ds.index(x,y,op=np.float32)
Out[21]: (138.0, 504.0)
r.ds.index(x,y)
Out[22]: (138, 503)
r.ds.index(x,y,precision=0)
Out[23]: (137, 504)
r.ds.index(x,y,precision=1)
Out[24]: (137, 504)
r.ds.index(x,y,precision=10)
Out[25]: (138, 504) What's problematic is that the "math.floor" argument is by default in the underlying function, and is the one showing all those changes: def rowcol(transform, xs, ys, op=math.floor, precision=None): which is wrapped by |
Need to test this in more details, but it looks like the "right" solution is the r.bounds
Out[27]: BoundingBox(left=478000.0, bottom=3088490.0, right=502000.0, top=3108140.0)
xmin = 478000
yax=3108140
ymax=3108140
r.ds.index(xmin,ymax)
Out[31]: (0, 0)
r.ds.index(xmin,ymax,op=np.float32)
Out[32]: (0.0, 0.0)
r.ds.index(xmin,ymax,op=np.float32,precision=10)
Out[33]: (0.0, 3.637979e-12)
r.ds.index(xmin,ymax,precision=10)
Out[34]: (0, 0)
r.ds.index(xmin,ymax,precision=1)
Out[35]: (-1, 0)
r.ds.index(xmin,ymax,precision=0)
Out[36]: (-1, 0)
r.ds.index(xmin,ymax)
Out[37]: (0, 0) |
Call an exorcist! This should definitely be an issue in rasterio, no? Also, why do they need |
I thought we had discussed this before, but I cannot find any mention to it. But I agree, the use of floor by default is a bit strange. Maybe float32 should be the default. We could add an optional argument opt to xy2ij too. |
@rhugonnet what is the status of this?? |
@rhugonnet Tomorrow, your first challenge will be to merge this PR! :-P |
@erikmannerfelt @adehecq |
There seems to be a merge conflict. Otherwise, it looks very good! |
There should be an |
I've fixed some additional bugs after merging. |
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.
Great job!!
Changed
interp_points()
toscipy.ndimage.map_coordinates
instead of griddata. Commented the rest of the code that might allow to write a mutiprocessing loop if needed in the future.Added assertions to
test_interp()
.All tests passing.
Resolves #100
Resolves #69
One current limitation: we need to know if the pixel coordinates refers to center or corner (is_area or is_point). Right now I shift x/y by 0.5 pixel assuming it's the center, which works for our test Raster.
For robustness, we'd need to add the is_area or is_point info from GDAL into the Raster class. This is necessary to further improve the inter_points method.