Skip to content

PATTERNS

gather raster data

One of the first things you will usually do with Earth Engine is gather some data from the cloud. Before we get too deep into this, we should review the basic templates for storing geographic data (geographic data models) and how they are implemented in Earth Engine.


raster data model

A raster stores geographic data with a grid of pixels. Each pixel, or cell in the grid, stores a value as a digital number. The data type defines the length of binary numbers used to store the digital number. In the diagram below, the values shown on the left can be stored as a 8 bit unsigned integer, or byte, data type shown on the right.


raster-model


image data object

In Earth Engine, the raster model underlies the image data object, where an image is composed of one or more bands and each band is a raster.


image-bands


accessing images from cloud

The diagram below shows a typical pattern for accessing cloud data.


graph LR

  step01("Construct from address") ;
  step02("Inspect data object") ;

  step01 --> step02

  classDef task fill:#C9C3E6,stroke-width:0px,color:#000000;

  class step01 task; 
  class step02 task;

The pattern is to first construct the object and then immediately inspect the properties of the object.


construct image from address

Use the ee.Image() method to construct an image from the cloud. This method takes the address for the data asset as an argument.

graph LR
  step02("ee.Image()") ;
  step03[/"image"/]  ;
  arg01["'address/of/cloud/data'"] ;

  step02 --> step03
  arg01 --o step02


  classDef in-out fill:#FFFFFF,stroke-width:1px,stroke: #000000, color:#000000; 
  classDef op fill:#000000,stroke-width:0px,color:#FFFFFF;
  classDef arg fill:#CCCCCC,stroke-width:0px,color:#000000;


  class step01 in-out; 
  class step02 op;
  class step03 in-out;
  class arg01 arg; 

To adapt the snippet below, you will just need to replace 'address/of/cloud/data' with the data address. The address must be a string.

var image = ee.Image('address/of/cloud/data');

inspect data properties

After constructing or altering a data object, I usually want to quickly familiarize myself the properties of the data. To do this, use the print() method to print the properties of the data object to the Console.

print(
    "A helpful label",
    image
    )
;

To adapt the snippet below, replace "A helpful label" with a label that describes the image you are working with. This label must be a string. As necessary, replace image in the following line with the name of the variable that contains the image data.


full pattern

Here are the two parts of the pattern together.

var image = ee.Image('address/of/cloud/data');

print(
    "A helpful label",
    image
    )
;

image collection data object

In Earth Engine, an image collection is what it sounds like: a collection of images. Earth Engine often uses these raster data objects to store satellite observations, because most satellites observe a region of the earth’s surface (often called a scene) at a moment in time and then return to this scene at regular intervals to create a time series. In these cases, an image collection provides a way to store all the different scenes observed at all the different times by a satellite mission.

image forthcoming

Image collections are also useful for storing high-resolution rasters as a set of small tiles, or images with relatively small geographic extent, that can be stitched together into larger images as needed. For example, Earth Engine will often store Lidar products and high resolution imagery as image collections.

image-collections



construct from address

Use the ee.ImageCollection() method to construct an image collection from the cloud. The method takes the cloud address as an argument.


graph LR
  step02("ee.ImageCollection()") ;
  step03[/"ic"/]  ;
  arg01["'address/of/cloud/data'"] ;

  step02 --> step03
  arg01 --o step02


  classDef in-out fill:#FFFFFF,stroke-width:1px,stroke: #000000, color:#000000; 
  classDef op fill:#000000,stroke-width:0px,color:#FFFFFF;
  classDef arg fill:#CCCCCC,stroke-width:0px,color:#000000;


  class step01 in-out; 
  class step02 op;
  class step03 in-out;
  class arg01 arg; 

Here is the pattern in javascript:

var ic = ee.ImageCollection('address/of/cloud/data');

inspect data

After constructing an ic object, I tend to use a print() method to learn a couple things about the data.

print(
    "IC Name",
    ic.size(),          // Consider commenting out this line to make script run faster. 
    ic.first(),
    )
;

The ic.size() method tells me how many images the collection contains. If the collection is huge, this method can take a while to run, so often I will comment out this line after I have looked at the result to help make the script run faster on subsequent runs. The ic.first() method tells me some details about the first image in the collection and usually the other images in the collection will have the same band names and property keys.

full pattern

Here are the two parts of the pattern together.


This work is licensed under CC BY-NC-SA 4.0