for Dummies

Part I

Earth Engine

Michael A Menarguez

mamenarguez@ou.edu

Contents

  1. What has Google Earth Engine (GEE)?
  2. GEE examples
  3. GEE interfaces (visual + coding)
  4. Hands on with JavaScript programming (The basics)

What has GEE

Remote Sensing Archive:  Petabytes merged in one location  https://earthengine.google.org/#index

Distributed computational power: one million CPU hours in a few days http://earthenginepartners.appspot.com/science-2013-global-forest

Server side programming: we don't need to store data and the CPU power is provided by their cluster 

Results from time-series analysis of 654,178 Landsat images in characterizing forest extent and change, 2000–2012.

How does GEE engine work?

HPC Computing clusters

(Thousands of CPUs)

HPC Storage clusters

(Petabytes of data)

Divides data in independent grids

Merges all grid calculations

GEE Examples

Interactive Landsat timelapse of deforestation of the Amazon rainforest, 1984-2012.

Interactive Landsat timelapse of the drying of the Aral Sea, 1984-2012

Interactive Landsat timelapse of deforestation of the Amazon rainforest, 1984-2012.

Interactive Landsat timelapse of the drying of the Aral Sea, 1984-2012

GEE Examples

MOD09A1 (surface reflectance 500m) rgb(B4,B3,B1) 2010 aggregated removing clouds using median.

 Click here to view code

GEE Interfaces (I)

  1. Easy to use

  2. Fast classifications from selectable points polygons

  3. Good for non-programmers

  1. Does not exploit full GEE power (Restricted actions allowed).

  2. Does not allow to map functions at the pixel level.

Pros:

Cons:

Coding User Interface https://ee-api.appspot.com/​

Pros:

  1. Visual User Interface capabilities + anything you can code in Python or JavaScript

  2. Can create batch tasks and download their results once they are done

Cons:

  1. Requires JavaScript or python knowledge

  2. Need to learn how to use GEE objects and their functions

  3. Server side programming may limit some functionalities

GEE Interfaces (II)

Nighttime lights from DMSP (linear fit) from 1991 to 2013 code here

Coding User Interface https://ee-api.appspot.com/​

GEE Interfaces (III)

Saved Scripts

Documentation

Coding console

Inspector

Output console

List of batch tasks

Map

Nighttime lights from DMSP from 1991 to 2013 (code here)

Hands on with JavaScript!

  1. Introduction
  2. Variables  (var a = ...)
  3. Doing Math (1+1?)
  4. Boolean operations (=,>,<, ...)
  5. Bit operations (AND, OR,)
  6. Conditional (if .. then ..)
  7. Loops  (for i=1 to 10 ...)
  8. Functions 

1 - Introduction (I)

Executes in order

var a = 3;
a = 4;
console.log(a)

Prints 4

1 - Introduction (II)

Be careful with upper and lower characters!

Case sensitive

var myVariable = "I am a String";
console.log(myvariable);

Uncaught ReferenceError: myvariable is not defined

1 - Introduction (III)

How should I call you? I got it! asdsd... right?

 

 Methods, variables and properties start with lowercase and the first letter of each word is Capitalized

// Do not worry about how to write functions, nor define variables, just look at the naming! 

var myFunctionName = function(){}
var myVariableNameIsUpperCased = "I am a cool and correct variable name";
var my_variable_name_bad_notation= "I will work..."
            + "but I should not be written in this way. Are you a python programmer?";

Naming: "Camel-back" style.

1 - Introduction (IV)

Be careful with upper and lower characters!

Whitespaces

var     myVariable = "I am a variable defined with spaces between var and my name";
var test= "   will I print three spaces"
console.log(test);

Prints: '   will I print three spaces'

Ignores them when there are more than 1 spaces

1 - Introduction (V)

- I forgot a semicolon, are you mad at me JavaScript?

Statements

var one=1,two=2,three=3;
one=1
two=2;

three=3

Careful! Statement will continue if there is no semicolon and the next line compiles as part of the previous one.

End with semicolon or a line break

var multiLineString = "line1"
    +" line2"
       + " line3"
console.log(multiLineString )

Prints: line1 line2 line3 

- No, I will get over it...

2 - Variables (I)

Defining & Assigning:

var stringVariable = "I can have any text!"
var integerVariable, otherVar
integerVariable = 2

var VariableName [= value] [, Variable2Name [= value]]

[ ] means optional

JavaScript is dynamically (weakly) typed... Great! like python or R!

This means that the type is determined when assigned

var stringVariable = "I can have any text!"
var integerVariable = 1
stringVariable  = integerVariable 
console.log(stringVariable)

That is crazy! my stringVariable now contains an integer!

Lesson: Never name variables after its type if they are dynamicly changing

Prints: 1

2 - Variables (II)

Main types: (more here)

var booleanVariable = true //String assigned using a Boolean literal (true / false)
var stringVariable = "I can have any text!" // String assigned using a String literal
var numericVariable = 3.14159265359 // Number assigned using a numerical literal
var arrayWithInitialValues=["val1",numericVariable ] //Array assigned using an array literal
var x = {firstName:"John", lastName:"Doe"};    // Object assigned by an object literal

1: Boolean   2: String   3: Number   4: Array   5: Object

String (more here)

var stringVariable = "I can have any text!" //variable definition and initialization
console.log(stringVariable.length) // Prints '20'
stringVariable = stringVariable + " I am appending this" //String concatenation
console.log(stringVariable) //prints 'I can have any text! I am appending this'

2 - Variables (III)

Numerical 

var apples = 5, pears = 10;
var piecesOfFruit = apples + pears;
console.log(piecesOfFruit ) //Prints 15

Basic operators: + - / *

var a = (10 + 2) / 2 + 4 * 2 
console.log(a) // What will I print?
(10 + 2) / 2 + 4 * 2 = 12 / 2 + 4 * 2 
12 / 2 + 4 * 2 = 6 + 4 * 2
6 + 4 * 2 = 6 + 8
6 + 8 = 14

Careful! Operator precedence matters

Assignment operators: = += -= *= /= %=

2 - Variables (IV)

Array (more here)

var emptyArray=[]
var myArray = [1,4,9]
var myArray2 = ["phrases are okay", false, 3.14159, 6, "x**2"] //Can have different variable types
var myArray3 = new Array() // {undefined length, empty}
var mayArray4 = new Array(5) // {5-item array, empty}.
console.log(myArray2[2])

Object: (more here)

var jedi = {
    name: "Yoda",
    age: 899,
    isCool: true
};
console.log(jedi.name+jedi.age)
console.log(jedi.isCool)

Yoda899 

true

var myObject = {
    propertyName1: value,
    propertyName2: value,
    ...
};

Careful! Arrays start indexing at 0, not 1!

3.14159

Math object (more here)

prints -5

Math.random();              // returns a random number
Math.min(0, 150, 30, 20, -8);      // returns -8
Math.round(4.7);            // returns 5
Math.round(4.4);            // returns 4
Math.ceil(4.4);             // returns 5
Math.floor(4.4);             // returns 4

Math.E;         // returns Euler's number
Math.PI         // returns PI
Math.SQRT2      // returns the square root of 2
Math.SQRT1_2    // returns the square root of 1/2
Math.LN2        // returns the natural logarithm of 2
Math.LN10       // returns the natural logarithm of 10
Math.LOG2E      // returns base 2 logarithm of E
Math.LOG10E     // returns base 10 logarithm of E

//Math.sin() Math.cos() ... Math.abs()
// NOW A QUESTION FOR YOU
console.log(Math.abs(Math.floor(-4.5))) // What should I return?

3 - Doing some math

4 - Boolean operations 

      NOT

||    OR

&&   AND

==    Equal value

!=     Different value

===  Equal value and type

!==   Different value or type

     Smaller than

     Greater than

>=    Greater or equal than

<=    Smaller or equal than

var a = 5
var b = '5'

console.log(a==b)
console.log(a===b)
console.log(a!=b)
console.log(a!==b || !(a===b))
true
false
false
true 

What will this print?

4 - Bit operators

&     AND

|      OR

~      NOT

^      XOR

<<    Left shift

>>    Right shift

 

var a = 9     // 1001
var b = 3     // 0011
var c = 8     // 1000

console.log(~a)
console.log(a|b)
console.log(a>>2)
-10 // Note a = 1111......0110 Negative
11  // 1001 OR 0011 = 1011 = 11
2 

What will this print?

Warning! JavaScript uses 32-bit signed numbers

5 - Conditionals

if (condition) {

    code...

}else{

    code ...

}

var a = 9    
var b = 3     

if (a>b){
    console.log("a greater than b")
} else if (a<b){
    console.log("b greater than a")
} else {
    console.log("a equals b")
}
A greater than b

What will this print?

Advice! ifs can be nested

if (1==0){
    if (2==2){
        console.log(2)
    }else{
        console.log(1)
    }
}

What will this print?

Nothing!

6 - Loops!

for (variable=initial_val; condition; increment of var) {

    code...

}

for (var i=0; i<5; i++){
    if (i%2){ //true=1;false= 0
        console.log(i)
    }
}
1
3

What will this print?

7 - Functions (I)

function name(param1,param2,...){

     code

     return x;

}

function sayMessage(message){
  alert(message)
}
sayMessage("This function is cool")

7 - Functions (II)

var name = function (param1,param2,...){

     code

     return x;

}

var sayMessage=function(message){
  alert(message)
}
var newVariable = {} //Initialize object variable
newVariable.myFunction = sayMessage //Create property myFunction and assign it our function
newVariable.myFunction("This function is cool")

Really?

Done with JavaScript!!!!

Not really... We just got the basics, but will be more than enough to use Google Earth Engine!

 

In fact, you may not use everything, but it is good to know in case you will need it someday! 

 

Remember... if you do not know how to do something... Google it!

JavaScript full documentation:

http://www.w3schools.com/js/

 

Now... what next?!

Explain GEE objects, how to use them, and some of their important methods

See you next week!

Questions?

Google Earth Engine for Dummies (I)

By Michael a Menarguez

Google Earth Engine for Dummies (I)

This seminar will present the basic concepts required to code using Google Earth engine for Remote Sensing purposes. Part I: Introduction. Several Examples. Basic Javascript (Part I)

  • 9,625
Loading comments...

More from Michael a Menarguez