Overloaded Operators for the ee.Number Object Class
Tutorial created by **David Montero Loaiza**: GitHub | Twitter
GitHub Repo: https://github.com/davemlz/eemont
PyPI link: https://pypi.org/project/eemont/
Conda-forge: https://anaconda.org/conda-forge/eemont
Documentation: https://eemont.readthedocs.io/
More tutorials: https://github.com/davemlz/eemont/tree/master/docs/tutorials
Let’s start!
If required, please uncomment:
[1]:
#!pip install eemont
#!pip install geemap
Import the required packages.
[2]:
import ee, eemont, geemap
Authenticate and Initialize Earth Engine and geemap.
[3]:
Map = geemap.Map()
Let’s define some ee.Number objects as NIR and Red values for NDVI computation:
[4]:
R1 = ee.Number(0.20)
R2 = ee.Number(0.12)
N1 = ee.Number(0.64)
N2 = ee.Number(0.58)
Overloaded Operators
eemont has overloaded the binary operators, rich comparisons and unary operators in the following list for the ee.Number class:
(+, -, *, /, //, %, **, <<, >>, &, |, <, <=, ==, !=, >, >=, -, ~)
Therefore, you can now use them for number operations!
[5]:
NDVI1 = (N1 - R1)/(N1 + R1)
NDVI2 = (N2 - R2)/(N2 + R2)
The result is stored as an ee.Number class. Let’s check the first one:
[6]:
NDVI1.getInfo()
[6]:
0.5238095238095237
Now, let’s see the second result:
[7]:
NDVI2.getInfo()
[7]:
0.6571428571428571