-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Python bindings: Add Dataset.ReadAsMaskedArray #12172
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
Python bindings: Add Dataset.ReadAsMaskedArray #12172
Conversation
swig/include/python/gdal_python.i
Outdated
xoff=xoff, yoff=yoff, | ||
win_xsize=xsize, win_ysize=ysize, | ||
buf_xsize=buf_xsize, buf_ysize=buf_ysize, | ||
resample_alg=gdalconst.GRIORA_Mode) != 255 |
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.
Perhaps indicate in the doc that when downsampling the mask resampling algorithm is Mode (ie majority) ?
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.
Documented this and also changed behavior of Band.ReadAsMaskedArray
to match.
Hmm, I'm not sure how my tests were passing locally before. Right now I'm puzzled by
|
I believe this is due to: https://github.com/OSGeo/gdal/blob/master/gcore/overview.cpp#L4453 / https://github.com/OSGeo/gdal/blob/master/gcore/overview.cpp#L5798 |
I don't think GRA_Mode downscaling works for NoData mask bands. If I'm following the code right, it performs a downscaled read from the parent band (using GRA_Mode, and excluding NoData pixels) and then sets all valid pixels to 255. Which is different from performing a full resolution read on the parent, setting valid pixels to 255, and then downscaling. |
yes the logic I pointed out where the mask band of the mask band is the mask band itself should probably be modified for Mode, and just get the GetMaskBand() of the mask band, which would be a AllValid mask band |
I don't see either of these lines hit in this case. The issue I see is gdal/gcore/gdalnodatamaskband.cpp Lines 404 to 407 in bfb3825
where a downscaled read is performed from the parent band, and the result reclassified to 0/255. To get a correct result for All this said, the current behavior of |
ffd3c4e
to
3198ece
Compare
@rouault any thoughts on me marking
|
Only for mode ? Otherwise I'm slightly concerned that if using a different downscaling algorithm for the mask than the actualband, there could be situations where this would lead to the downscaled mask indicating a pixel as valid whereas the actual downscaled band would have determined it not to be valid. In particular, for cubic or lanczos, there are subtelties regarding that determination (cf overview.cpp lines 3447-3471 (horizontal pass), 3654-3684 (vertical pass)) |
It's hard for me to picture what cubic resampling of a binary mask should yield, so it wouldn't bother me to keep the status quo there. I'm approaching this from the expectation that resampling a mask band should yield the same results as resampling an ordinary band with the same values (0 or 255). Is that the wrong way to look at it? |
I'm not sure what the "right" way is. I'm just underlying that the overview resampling code (also used by RasterIO() for non-nearest resampling) uses the mask band as its own mask band, ignoring 0 values. Both approaches (current GDAL one or the one you suggest) have their pros and cons depending use cases (if you want to be "optimistic" or "pessimistic" regarding pixel validity). Perhaps we should have a way for the user to specify which it prefers, but that would further complicates things... |
3198ece
to
519632d
Compare
519632d
to
4f495bc
Compare
I've exposed a This also sidesteps questions about the behavior of those algorithms for now. |
Resolves #12005