Earth Engine Authentication#
Before using Ndvi2Gif, you need to authenticate with Google Earth Engine.
Creating an Earth Engine Account#
Sign in with your Google account
Fill out the registration form
Wait for approval (usually instant for
.eduemails, or within 1-2 days)
Note
Earth Engine is free for research, education, and non-profit use!
Authentication Methods#
Method 1: Interactive Authentication (Recommended for First Time)#
import ee
# Trigger authentication flow
ee.Authenticate()
# Initialize Earth Engine
ee.Initialize()
This will:
Open a browser window
Ask you to sign in with Google
Generate a verification code
Store credentials locally for future use
Method 2: Notebook Authentication#
In Jupyter notebooks or Colab:
import ee
# Authenticate using notebook mode
ee.Authenticate(force=True) # Use force=True to re-authenticate
# Initialize
ee.Initialize()
Method 3: Using Service Accounts (Advanced)#
For production environments or automated workflows:
import ee
# Path to your service account key file
service_account = 'your-service-account@project.iam.gserviceaccount.com'
credentials = ee.ServiceAccountCredentials(service_account, 'path/to/key.json')
# Initialize with service account
ee.Initialize(credentials)
Note
Service accounts require setting up credentials in Google Cloud Platform. See EE documentation for details.
Testing Your Authentication#
Verify that authentication works:
import ee
# Initialize
ee.Initialize()
# Test with a simple computation
point = ee.Geometry.Point([-3.7, 40.4]) # Madrid, Spain
image = ee.Image('COPERNICUS/S2_SR_HARMONIZED/20230601T110621_20230601T110616_T30TVK')
# Get a value
value = image.select('B8').reduceRegion(
reducer=ee.Reducer.mean(),
geometry=point,
scale=10
).getInfo()
print(f"✓ Authentication successful! NIR value: {value['B8']}")
Authentication Storage#
Credentials are stored in:
Linux/Mac:
~/.config/earthengine/Windows:
C:\Users\YourName\.config\earthengine\
You only need to authenticate once per machine.
Common Authentication Issues#
Issue: “Permission denied” errors#
Try re-authenticating:
import ee
ee.Authenticate(force=True)
ee.Initialize()
Issue: “Project not found”#
Specify your project explicitly:
import ee
ee.Initialize(project='your-project-id')
Find your project ID at Google Cloud Console.
Issue: Browser doesn’t open during authentication#
Use the command-line authentication:
earthengine authenticate
Or manually copy the authentication URL from the error message.
Issue: Token expired#
Re-run the authentication:
import ee
ee.Authenticate(force=True)
Google Colab Specifics#
In Google Colab, use:
import ee
ee.Authenticate()
ee.Initialize(project='your-project-id')
Colab requires specifying a project ID.
Best Practices#
Don’t share credentials: Never commit
.config/earthengine/to version controlRe-authenticate periodically: Tokens can expire after long periods
Use service accounts for production: Better for automated scripts
Test after authentication: Always verify with a simple query
Next Steps#
Now that you’re authenticated, let’s create your first analysis in the Quick Start guide.