Server-side vs Client-side/Local Objects
Server-side¶
stored on GEE’s servers (not on your local machine)
any variable created with
ee.*is a server-side objectcan’t be used directly with non-
ee.*variables or functions
Client-side or local¶
stored in your local machine
regular Python variable
import ee# Trigger the authentication flow.
ee.Authenticate()
# Initialize the library.
ee.Initialize(project='your-gee-project-id-here') #replace your-gee-project w/ your actual GEE project nameOutput
# Define some local (client-side) variables
local_num1 = 100
local_num2 = 200
# Define some server-side (ee.*) variables with the same value
server_num1 = ee.Number(local_num1)
server_num2 = ee.Number(local_num2)
# Get the sum of the local variables then display it
local_sum = local_num1 + local_num2
print(local_sum)
print(type(local_sum))300
<class 'int'>
⚠️ CAUTION
It is usually not recommended to mix client-side (local) and server-side objects and methods.
👨💻 TRY IT OUT
Get the sum of the server variables then display it
# Try your solution here💡 TIP
When working with server-side objects or variables, you should also use server-side (
ee.*) functions.When in doubt, refer to the GEE API Documentation.
Source
# Checking what class the server-side variables are may give us an idea
print(type(server_num1))
# Use the add method of the ee.Number class (https://developers.google.com/earth-engine/apidocs/ee-number-add)
server_sum = server_num1.add(server_num2)
# Use .getInfo()
print(server_sum.getInfo())
print(type(server_sum.getInfo()))Output
<class 'ee.ee_number.Number'>
300
<class 'int'>
Source
# Just using print()
print(server_sum)
print(type(server_sum))Output
ee.Number({
"functionInvocationValue": {
"functionName": "Number.add",
"arguments": {
"left": {
"constantValue": 100
},
"right": {
"constantValue": 200
}
}
}
})
<class 'ee.ee_number.Number'>
🤔 SOMETHING TO THINK ABOUT
Did you notice any differences between the server-side and client/local computation of the sum?