imagerasterio

difference in raster values between array and qgis


I have 256 images (NDVI, NDWI), when I open them like this :

import os, rasterio
src_mois = (rasterio.open(path))
array_mois = src_mois.read(1)
print(array_mois)

On one hand, some problematic one look like this (while on Qgis values are between -0.607159 and -0.681409):

[[-3.4028235e+38 -3.4028235e+38 -3.4028235e+38 ... -3.4028235e+38
  -3.4028235e+38 -3.4028235e+38]
 [-3.4028235e+38 -3.4028235e+38 -3.4028235e+38 ... -3.4028235e+38
  -3.4028235e+38 -3.4028235e+38]
 [-3.4028235e+38 -3.4028235e+38 -3.4028235e+38 ... -3.4028235e+38
  -3.4028235e+38 -3.4028235e+38]
 ...
 [-3.4028235e+38 -6.2753040e-01 -6.2753040e-01 ... -3.4028235e+38
  -3.4028235e+38 -3.4028235e+38]
 [-3.4028235e+38 -6.1740422e-01 -6.1740422e-01 ... -3.4028235e+38
  -3.4028235e+38 -3.4028235e+38]
 [-3.4028235e+38 -6.5297663e-01 -6.5297663e-01 ... -3.4028235e+38
  -3.4028235e+38 -3.4028235e+38]]

On the other hand, majority of my images are the same as in Qgis :

[[ 0.34498805  0.4038521   0.45953733 ... -0.00084021 -0.01416653
  -0.01416653]
 [ 0.33337444  0.36398682  0.41986722 ... -0.00888733 -0.02618947
  -0.02618947]
 [ 0.3356307   0.323984    0.34316206 ... -0.0089799  -0.01649707
  -0.01649707]
 ...
 [-0.28778303 -0.312718   -0.312718   ...  0.49572146  0.5651871
   0.5805117 ]
 [-0.2846862  -0.2940772  -0.2940772  ...  0.413783    0.46547
   0.5263974 ]
 [-0.27166343 -0.2786367  -0.2786367  ...  0.3622923   0.37553316
   0.40998626]]

My goal is to average these images and plot them with seaborn. It seems like it understands that -3.4028235e+38 means -3 when I plot it directly like this so it's problematic. Do you have any clue on what's happening ?

enter image description here

enter image description here


Solution

  • That suggests that -3.4028235e+38 is used as the NODATA flag (that value is commonly used, it is the lowest single precision float value). You should be able to read the NODATA flag used from the file; and replace these values. QGIS automatically does that for you.