I want to count the no data values, because when I loaded them with rioxarray they seemed to be oddly many pixel to be non-valid.
When I open the given file in qgis the valid pixel percentage is 89.6 %.
My attempt to measure it with raster was:
import rioxarray as rxa
import numpy as np
raster = rxa.open_rasterio("Z:/path/to/test.tif")
data = raster.data
print(np.sum(data == raster.rio.nodata) /data.size * 100)
output: 10.122128919010978
Background: I wanted to use numpy masked arrays and mask the e.g. the nodata, black pixels, or values above a threshold. But when I use this method, to mask the nodata pixels, almost everypixel is getting masked.