I am getting different resutls when plotting a np.array
with matplotlib
than when doing it in an external software - QGIS. Here is what I have:
print(wiw[0].shape)
(1, 8433, 9254)
print(wiw[0].min())
nan
print(wiw[0].max())
nan
print(wiw[0].dtype)
float64
print(np.nanmin(wiw[0]))
1.0
print(np.nanmax(wiw[0]))
1.0
This is how it looks like when I plot it with matplotlib
:
fig, ax = plt.subplots(figsize = (20,20))
ax.imshow(wiw[0][0,:,:], cmap='Greys_r');
Next, I save it with rasterio
using the following code:
with rasterio.open(output_path + 'WIW_TEST.tif', 'w', **ras_meta) as dst:
dst.write(wiw[0])
Where ras_meta
is:
{'driver': 'GTiff', 'dtype': 'float64', 'nodata': 0, 'width': 9254, 'height': 8433, 'count': 1, 'crs': CRS.from_epsg(32633), 'transform': Affine(20.0, 0.0, 300000.0,
0.0, -20.0, 1600020.0), 'blockxsize': 640, 'blockysize': 640, 'tiled': True}
If I open this geotiff in QGIS, its appearence is differnet:
But surprisingly, if I open the saved geotiff
again with rasterio
and plot it with matplotlib
, the visualization is correct. What is going on? Is it a dtype
issue, a nodata
problem?
np.nan
and1
. There are not intermediate values. For reference, this array was created with anp.where
and a condition. Where it was met,1
. If not, anp.nan
was putnan
,float
is needed asdtype