I'm wondering if I'm using rio-calc incorrectly to achieve what I'd like to do. I have a floating-point raster that ranges from 0.0-1.0 with areas in the raster that are masked. I'd like to simply create a 0|1 threshold raster based on 0.5 as a threshold value *and* retain the mask which I'd like to set to 255 in a uint8 output. My command is:
"(>= (read 1) 0.5)"
When I run this, I believe the ">=" in the expression gives me a np.bool type which then gets filled here (https://github.com/mapbox/rasterio/blob/master/rasterio/rio/calc.py#L189) before being cast to the output dtype. When I swap these two code chunks: type conversion (lines 194-198) before the masking (lines 189-192), I get the expected result. But I'm guessing I'm introducing some unintended consequences.
One other minor point: In order to use my specified profile nodata value, I had to first cast it to an int (line 192):
res = res.filled(int(kwargs['nodata'])))
Thanks for any advice,
You may get better results using numpy.where, like "(where (>= (read 1) 0.5) 1 0)".
I'll dig into the filling code, that looks like a bug to me.