0% found this document useful (0 votes)
67 views

Introduction To Google Earth Engine Python API

Uploaded by

ramzan41278
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views

Introduction To Google Earth Engine Python API

Uploaded by

ramzan41278
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Introduction to Google Earth

Engine Python API


End-to-End Google Earth Engine

Ujaval Gandhi
[email protected]

CC BY 4.0
The GEE Python API
● Google Earth Engine API can be used via Python
● The client library can be installed via the earthengine-api package
● It can be used in many different environments
○ Colab/Jupyter Notebooks
○ Standalone scripts
○ Web Frameworks
■ AppEngine [example]
■ Streamlit [ example] [example]
■ Greppo
○ QGIS
■ Google Earth Engine Plugin [example][example]
Why use the Python API
● Python API provides additional features and integrations
● Automation
○ Run scripts without user intervention
● Batch Processing and Exports
○ Ability to launch and manage tasks automatically
● Deep Learning
○ Integration with Tensorflow and Keras
● Integrate with Python workflows
○ Integration with XArray, Matplotlib, Pandas etc.
● Create Custom Web Apps
○ Create fully features web applications using any web framework
How is the Python API Different?
● Most of the API is identical between Javascript and Python
● All ee modules are available in Python
● Some key differences
○ ee.batch module for Exports
○ ee.data.getPixels and ee.data.computePixels to get image pixels
○ No ui module (no built-in charting or apps support)
Installing and Using the Python API
● Google Colab
○ Easiest way to start using the GEE Python API
○ The earthengine-api module is pre-installed and can be imported directly via import ee
○ Need to authenticate for every colab session using ee.Authenticate()
● Installation Client Libraries on your machine
○ Install the earthengine-api package via pip or conda
○ Install and configure the gcloud utility
○ Authentication
■ Need to do a one-time authentication for using in standalone scripts by running earthengine
authenticate from a terminal
■ Need to authenticate for every jupyterlab session ee.Authenticate()
■ Need to authenticate via a service accounts for apps
○ Step-by-Step Instructions
Module Overview
1. Earth Engine API Syntax
2. Automatic Conversion from Javascript to Python
3. Batch Exports
4. Using Earth Engine with XArray

Demos

● Automating Downloads and Exports


● Google Earth Engine plugin for QGIS
● Deep Learning with Earth Engine
Let’s get coding
Module Content

https://courses.spatialthoughts.com/end-to-end-gee.html
Demo: Automating Downloads and
Exports
Automating Downloads and Exports
● We can run GEE Python API code from a standalone script on a local machine or a
server.
● You must install the Python Client Library on the machine. [instructions]
● Running Scripts Locally
○ Authentication using the earthengine authenticate command
○ Demo
● Running Scripts in Cloud
○ Authentication using a Service Account
○ Demo
Demo: Google Earth Engine Plugin for
QGIS
QGIS Google Earth Engine plugin
● Allows use of GEE Python API from QGIS
● Run Python GEE API Code from
○ QGIS Python Console
○ QGIS Processing Scripts
○ Other QGIS Plugins [example]
● Users need to authenticate on first use
● Adds useful functionality for visualizing GEE Datasets
○ Map tiles are rendered on QGIS Map Canvas
○ Pixels can be queries using QGIS Identify Panel
○ Custom map elements can be added using QGIS Print Layout
● Demo
Demo: Deep Learning with Earth
Engine
Vertex AI
● Earth Engine API provides a tight integration of deep learning models hosted on
Vertex AI on Google Cloud Platform.
● Models created from TensorFlow, PyTorch and AutoML are supported.
● EE API Provides a way to load and use Vertex AI models
○ Load a model using ee.Model.fromVertexAi()
○ Predict on an image using model.predictImage()
○ Predict on a table using model.predictProperties()
● Examples in the User Guide
● Suitable for large online training and prediction jobs using parallel computing
resources offered by Google Cloud.
● Vertex AI platform is NOT free - even for Non-Commercial Earth Engine users.
Offline Deep Learning
● There is another workflow that is suitable for smaller models or for users who want
to use Earth Engine for Deep Learning using their own hardware or freely available
cloud hardware.
● Using Colab notebooks, Google Cloud Storage and Tensorflow - you can use a model
to do model training and prediction at no or little cost.
● We will demonstrate a workflow that uses this approach.
Offline Prediction AI Workflow
Export to
Input Image in Collect Training
Google Cloud Build a Model
GEE Samples
Storage

Train the Model

Export to
Output Image
Import to GEE Google Cloud Run Prediction
in GEE
Storage
Building a Deep Neural Network
● Google Earth Engine supports DNN classification using Tensorflow
● Export Data from GEE as .tfrecords [script]
● DNN (Deep Neural Network) Model in Colab [notebook]*
○ Read and Parse TFRecords
○ Build and Train a DNN using Keras
○ Use the model to predict classes for imagery and export results as TFRecords
○ Import predictions to GEE
● View and Compare the Results in GEE [script]

* Use of Google Cloud Storage may result in charges on your Google Cloud account.

You might also like