Note
Go to the end to download the full example code.
Python arithmetic#
This example demonstrates arithmetic operations using raster arithmetic on Rasters
. See Support of pythonic operators for more details.
We open a raster
import geoutils as gu
filename_rast = gu.examples.get_path("everest_landsat_b4")
rast = gu.Raster(filename_rast)
rast
rast.plot(cmap="Greys_r")
Performing arithmetic operations implicitly loads the data.
Important
Arithmetic operations cast to new dtypes
automatically following NumPy coercion rules. If we had written (rast + 1)
,
this calculation would have conserved the original numpy.uint8
dtype
of the raster.
Logical comparison operations will naturally cast to a Mask
.
Masks
support python logical operators to be combined together
Finally, Masks
can be used for indexing and assigning to a Rasters
Total running time of the script: (0 minutes 4.754 seconds)