Date
1 - 2 of 2
Should rasterio be compatible with numpy.ma?
dreaminghexnut@...
I was just tripped up by the fact that rasterio (I'm on 1.2.10) ignores the mask in numpy masked arrays. It simply writes the masked array's data array. If that underlying data array has the same fill value as the one defined in the profile, that works as expected. However, if the fill value in the data array is different from the one in the profile or if there are original brightness values instead of a fill value, the mask is completely ignored.
There's a simple workaround: ``` meta.update(fill_value=masked_img.fill_value) with open(target, "w", **meta) as dst: dst.write(masked_img.filled()) ``` But shouldn't that be the default behaviour? That rasterio should call .filled() every time it receives a Numpy masked array? Cheers, JOey |
|
Sean Gillies
Hi, I'm in favor of making filling the default for a masked array. In the same vein, I wonder if write should also call write_mask if a masked array is passed? On Thu, Nov 11, 2021 at 8:54 AM <dreaminghexnut@...> wrote: I was just tripped up by the fact that rasterio (I'm on 1.2.10) ignores the mask in numpy masked arrays. It simply writes the masked array's data array. If that underlying data array has the same fill value as the one defined in the profile, that works as expected. However, if the fill value in the data array is different from the one in the profile or if there are original brightness values instead of a fill value, the mask is completely ignored. -- Sean Gillies |
|