Masks, nodata, rasters, arrays

2149
0
04-29-2016 07:50 PM
Labels (1)
DanPatterson_Retired
MVP Emeritus
0 0 2,149

Masks ... nodata ... nulls

The attached pdf will serve for now.  I will add additional documentation here on how to work with rasters with nodata areas here soon.

A simple example here, using Matplotlib to do the mapping.  The -- cells are nodata values

FullSizeRender-1 1.jpg

Raster/array valuesSample properties
>>> print(c.filled())  # -9 is nodata
[[ 3  1  3 -9  3  2 -9 -9 -9  2  2  2  3 -9  1 -9  3  3 -9  1]
 [ 1  3  2  3 -9 -9 -9  3  1  3  3 -9  3  2  3  3  3  3  1  1]
 [ 2  2  2 -9  1  2  2 -9  2  2  3 -9  3 -9  3 -9  2  2  1  3]
 [ 3  1  3  2 -9 -9  2 -9  2 -9 -9  1  2  1  1  2  1  3  3 -9]
 [-9  2 -9  2 -9 -9  1  2  1 -9 -9  2  2  1  1  1  3  1  3  3]
 [-9  2  3  3  1  2  2  3 -9  1  1  3  1 -9 -9 -9  2  1  3 -9]
 [-9 -9 -9  2  1  1 -9  2  2  1  1  2  2  3  2  3  2  2  2 -9]
 [ 3 -9  3 -9 -9  2  3 -9  3  2  2  2  1 -9  3  2 -9  2  2  1]
 [ 1 -9  2  2  1 -9  2  1  2  2 -9 -9  3 -9  2  2 -9  1 -9  1]
 [ 1  1 -9 -9 -9  2 -9  2  3  2 -9  1  2  1  3  1 -9 -9  1  3]
 [ 1 -9 -9  1  2  1 -9  1 -9 -9 -9 -9  1 -9 -9 -9 -9  2 -9  3]
 [-9  3 -9 -9 -9  2  3 -9 -9  1  2  1  1  2  1  1  3  2  3  2]
 [ 3  3  3 -9  3  1  3 -9 -9 -9  3  2 -9 -9  3  2  3 -9  1 -9]
 [-9  2  2  3  3  1  3  1 -9 -9  2  3  3  1  1  1  1  1 -9  1]
 [-9  1 -9  3  1  1 -9  2 -9  1  1  2  2  1 -9  2  2  3 -9  3]
 [ 3  2 -9  2  2 -9 -9  2  1  2  1  2 -9  3  2  1  1  1  3  1]
 [-9 -9  3  2  2 -9  2  2  1  2 -9  3  1  2  2 -9  3  3  2  1]
 [ 1 -9  1 -9  2  2  3 -9  3  2  2 -9  1  2  3 -9 -9 -9  3  3]
 [ 3  1  1  1  2  1  2 -9 -9  2  2  1  2 -9 -9 -9  2 -9  3  2]
 [-9  2  3  1 -9  1  1 -9  2 -9  1  1  1  2  1  2  3 -9 -9  3]]

>>> c.mean()

1.96028880866426

>>> c.min()  = 1

>>> c.max() = 3

>>>

np.histogram(c, bins=[1,2,3,4])

(array([ 92, 104,  81]),

array([1, 2, 3, 4]))

About the Author
Retired Geomatics Instructor at Carleton University. I am a forum MVP and Moderator. Current interests focus on python-based integration in GIS. See... Py... blog, my GeoNet blog...
Labels