Skip to content

dixondan/GEE-UCD-intro-training

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

GEE training material for UC Davis ESM 186

Access GEE code editor at https://code.earthengine.google.com/

Table of Contents

Dan Dixon

[email protected]

Outline


  • GEE Introductory Overview ~ 1 h 10 min
  • Wrapping Up ~ 20 min
  • Q&A ~

Prerequisites to Using GEE


We assume everyone is registered and have access to GEE
Otherwise, just follow the discussion and try on your own time

Resources


Earth Engine Developer's Page https://developers.google.com/earth-engine

  • Guides - JavaScript & Python
  • Reference - Client Libraries & Code Editor
  • Help & Support
  • Data Catalog, etc.

Introduction to GEE


Questions
  • What is Google Earth Engine?
  • Why use Google Earth Engine? *Strengths and limitations
Learning Points
  • Understand the power of Google Earth Engine
  • Understand the system architecture and philosophy

What is Google Earth Engine?


A cloud-based platform for planetary-scale geospatial analysis

Why Google Earth Engine?


An interactive environment for development at scale
  • Fast prototyping & computation
  • Easy dissemination of research outputs through GEE Apps
  • High-impact & data-driven science
  • Free cloud processing with built-in functions optimized for parallel computing
| Many use cases https://earthengine.google.com/case_studies/

Timelapse

Online public data archive$~$
  • A petabyte (> 50) storage accessible through GEE APIs
  • Unfortunately, ocean colour data repository still very poor

However...
> We can upload own datasets (up to 10 GB)
> Make dataset requests

Flexible access through APIs
Rapid visualization of complex spatial analyses
API → application programming interface

Introductory materials

How GEE works
Server-side
Written commands can be sent as requests object to Google's cloud for compution
Client-side
Results sent back can be visualized in the browser

Aim to tackle some of the world’s greatest challenges using open Earth data

Summary

  • GEE is great tool operating on petabyte imagery using Google’s cloud

  • Allows complex analysis and visualizations with basic JavaScript

  • Eliminates most of the hurdles with satellite data analysis
    → e.g., downloading, data formats, etc (not so for ocean colour)

  • Easy dissemination of output results through GEE Apps

  • Allows import/export of your own assets
    → raster and vector data, e.g., projected swath or in situ data points

  • GEE is changing the way we study and understand the Earth

  • Only works with internet connection

  • Users have no control on how computations are run in GEE

  • Non-parallelizable operations cannot be performed effectively

  • GEE performs poorly for long-running iterative processes
    → e.g. finite element, etc.

questions if any
GEE Code Editor

GEE Code Editor


Questions
  • What are the key features of the Google Earth Engine online code editor?
  • How do I search for and import datasets?
  • How do I create, save and share scripts?
Learning Points
  • Get familiar with the code editor and the tools available

Data Search & Help


Scripts, Docs & Assets


## Code Editor

Inspector, Console & Tasks


The Map


code editor

Summary


  • The Code Editor provides an easy and abstract way to

  • accessing GEE data catalog as well as personal assets

  • conducting geospatial analysis

  • displaying and sharing the results

  • Provide ways to import, export, share and manage personal assets

  • Example scripts, Docs and help are valuable resources to explore

Basics of EE Javascript


Questions
  • What are the basics of EE JavaScript ?
  • What is client-side vs. server-side JavaScript?
Learning Points
  • Gain a basic understanding JavaScript
  • Make a distintion between EE objects and other JavaScript objects

Javascript Syntax In General


// And, the first thing you do in any programming language:
print('Hello World!')


// Line comments start with two forward slashes. Like this line.


/* Multi-line comments start with a forward slash and a star,
and end with a star and a forward slash. */

Variable Declaration


// variables store objects and are defined using the keyword var
var thisNumber = 1;

// string objects start and end with a single quote
var thisString = 'I am a string';

// string objects can also use double quotes
// But don't mix the two
var thatString = "I am a string";

Statements


// statements end with a semi-colon, or the editor will complain
var feelsIncomplete = "I feel incomplete..."
var feelsComplete = "I feel complete!";

Statements

How to Pass Function Parameters


// use parentheses to pass parameters to functions
print('This string will print in the Console tab.');

List Definition


/* square brackets are used for items in a list
The zero index refers to the first item in a list*/
var myList = ['corn','wheat','soybeans']; 

print(myList[0]);
print(myList[3]);

Dictionary Definition


/* Use curly brackets (or braces) to define dictionaries 
   {key:value} pairs. */
var myDict = {'food':'bread', 'color':"red", 'number':42};

// Use square brackets to access dictionary items by key
print(myDict['color']);

//Or use the dot notation to get the same result
print(myDict.color);

Dictionary

Function Expression


/*function can be defined as a way to reuse 
  code and make it easier to read*/ 
var myHelloFunction = function(string) {
  return 'Hello ' + string + '!';
};
print(myHelloFunction('world'));

FunctionExpression

Client vs. Server Objects


  • Everything we saw so far lives in the browser (client-side)
  • Client-side useful, for example, when making EE user interfaces
  • Server-side objects are proxy objects and start with ee

Server-side (proxy) objects are just handles for objects on the server

Strings


var clientString = 'I am a String';
print(typeof clientString);  // string
      
var serverString = ee.String('I am not a String!');
print(typeof serverString);  // object
print('Is this an EE object?', 
      serverString instanceof ee.ComputedObject);  // true
/* Observe that "serverString" is an "object", 
   more specifically, "ee.computedObject" */

client-server-00

/* Client doesn't know what's in the container, 
   so we can find out by printing it */
print(serverString);  // I am not a String


/* To see what the container itself looks like, 
   call toString() on the object: */
print(serverString.toString());  
// ee.String("I am not a String!")
/* we can get the contents of the container 
   and assign them to a variable */

var someString = serverString.getInfo();
var strings = someString + '  Am I?';
print(strings);  // I am not a String!  Am I?

/* getInfo() is synchronous, thus it blocks code execution,
   so should avoid using it unless absolutely needed */

client-server-string

getInfo vs. evaluate


var something = ee.thing.getInfo(); // synchronous call

// A good way to request a value of the server object is to use
// evaluate() - this call is asynchronous
ee.Number(7).evaluate(function(n) {
    var clientNum = n + 3;
    print('Should be 10. Found ' + clientNum);
});

client-server-evaluate

Lists


// This exists in the browser
var clientList = [0, 1, 2, 3, 4, 5, 6, 7];
print(clientList); 

// This is a handle for some object on the cloud
var serverList = ee.List(clientList);
print(serverList); // They look the same!

var anotherList = ee.List.sequence(0, 7);
print(anotherList); // Also the same!

client-server-list

Mutable vs. Immutable


// Client-side objects are mutable
clientList.push(8);
print(clientList);

// However, the same won't work on the server list
// serverList.push(8); // Error!
var longerList = serverList.add(8);
// Use docs tab to discover methods on server objects

client-server-list-01

Operations With Server Objects


// A constant Image
var constantImage = ee.Image(7);

// This is NOT what we want:
var junkString = constantImage + 42;
/* Note that the browser calls toString() on the object and 
  then appends '42' to it. The JSON you see contains the 
  instructions sent to the server to execute your code */
print('JunkString:', junkString);

client-server-images

// This is the right way:
var someImage = constantImage.add(42);
// Click with the inspector to observe 
Map.addLayer(someImage, {}, 'someImage')

client-server-images-01

Mapping (what to do instead of a for-loop)


  • In EE we use map() instead of for-loops
  • This is key to making EE work
  • for-loops may still be useful for client-side (user interfaces)
  • However, server-side is best served with map

.map(...) vs. for(...)


code editor

Summary


  • In EE computations are parallel (map instead of for)
  • .getInfo() can cause browser lock (.evaluate instead)
  • Mixing client and server functions can cause errors
  • Cast client into server objects using the ee.Thing constructor
    e.g., ee.List([1, 2]), etc.
  • Server-side objects are immutable. Save changes in a new object
  • i.e., assign the changes to a new variable
e.g., var newImage = oldImage.add(3)
Additional JavaScript Resources

Spatial and Temporal Reducers


Reduce - Aggregate everything in a collection
reducer - an EE operation for aggregating data or computing a statistic

Reduce Region


Apply a reducer over an image with several bands

Questions
  • How to create a time series for a given location?
  • How to plot the time series within GEE?
  • Can we make the plot interactive?
Learning Points
  • Import image collection and crop the region of interest
  • Dynamically select lon/lat for creating time series plots
  • Create time series of chlorophyll and/or sea surface temperature

Wrapping Up


Today we have covered

  1. Introductory Overview to GEE
  2. GEE Code Editor: How to navigate the code editor
  3. Basics JavaScript: What is client-side and server-side

Code Editor: Where you go to write code.

  • This is the best tools for development
  • Also, check Help (?) inside the Code Editor, it provides links to useful pages

Data Catalogue: Details on the available datasets

  • Ocean colour datasets are still in their infancy (far behind land-group)
  • By building a strong (or larger) community progress can be achieved relaively faster

Developers Guide: the closest thing to a manual

  • Other than documentation, this provides useful links to many other resources

Developers Forum: Where you go to post questions

  • If you plan on using GEE, it is advisable to join the EE Forum
  • When posting questions in this forum, include a link to your script for others to help you troubleshoot more easily
  • Code sharing
  • Any private asset in the shared script is only accessible to those allowed of if it is puclic

Additional Learning Resources/References

Q&A

About

GEE training material for UC Davis ESM 186

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published