1

I have been looking all over the internet for a possible cause of this, but without luck, and was hoping it's some standard Rasterio quirk that I just can't track down. I am trying to load the Tanzania poverty map from World Pop, which is a 1km resolution raster grid of population rates (available here). Values for each grid square can be between 0 and 1, and the raster looks like this:

tanzania worldpop raster in qgis

Using the following Python code I've been loading the raster with Rasterio:

import os
import rasterio

file_path = os.path.abspath('path/to/tza10povcons125.tif')
raster = rasterio.open(file_path)
band = raster.read(1)

Based on my understanding of Rasterio, I would expect the band variable to contain a 2 dimensional array of values between 0 and 1 (or, rather, 0.664994 and 0.950991, which are the min and max values according to QGIS). However, when I print out the band variable I see:

array([[ -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38, ...,
         -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38],
       [ -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38, ...,
         -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38],
       [ -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38, ...,
         -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38],
       ..., 
       [ -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38, ...,
         -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38],
       [ -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38, ...,
         -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38],
       [ -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38, ...,
         -3.39999995e+38,  -3.39999995e+38,  -3.39999995e+38]], dtype=float32)

The recurring value, -3.39999995e+38, is also suspiciously close to the minimum value for numpy's float32 datatype:

>>> import numpy as np
>>> np.finfo('float32').min
-3.4028235e+38

I am just wondering if anyone has seen this kind of behaviour for Rasterio before, or if there is something obvious that I am missing?

2

Probably those -3.39999995e+38 are NO_DATA values of the raster. In rasterio you can check which cells have NO_DATA values using a mask.

msk = raster.read_masks(1)
  • 1
    Thanks, that was exactly it. Similarly, seeing now that raster.meta shows (among other things): 'nodata': -3.4e+38 – Owen Dec 6 '16 at 9:13
0

You can use the following to identify a NODATA value:

print(raster.nodata)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.