Getting Started with Google Earth Engine
Tags: googlecloud, googleearth, remotesensing, climateinnovation
Published: 2023-04-23 14:07:33

Google Earth Engine (EE) is a planetary cloud platform which supports data catalogue and the online IDE. It runs on Google’s cloud infrastructure and boasts a petabyte-scale database. The Earth Engine's public [data catalog](https://developers.google.com/earth-engine/datasets) provides more than 40 years of historical imagery and scientific datasets, including satellite data like Landsat, Sentinel-2, and MODIS, as well as geophysical, weather, climate, and demographic data.

EE is a useful Earth Observation cloud platform using Geospatial Data to Fight Climate Change which can help us;

- Monitor area of water body, vegetation, and other land uses
- Monitor the atmosphere
- Correlate area with production in agriculture

Google Earth Engine present the following benefits that makes it easy for use.

- Completely cloud-native (No image download, no HPC)
- JavaScript and Python
- Easy web app
- Intergradation with external API and visualization with Kepler.gl
- Petabyte worth of datasets
- Free for non-profit

Two Dataset Types: Image VS Image Collection

1. Things which do not change much over time e.g. elevation
2. Things that change e.g. temperature, precipitation

Loading image in GEE Code Editor in JavaScript 
We declare `var name`  then use the `ee.Image` an object used to represent an Earth Engine Image followed by the Image itself. 

`var elevation_dataset = ee.Image("NASA/NASADEM_HGT/001")`

More detailed 

```
// Import the dataset and select the elevation band.
var dataset = ee.Image('NASA/NASADEM_HGT/001');
var elevation = dataset.select('elevation');

// Add a white background image to the map.
var background = ee.Image(1);
Map.addLayer(background, {min: 0, max: 1});

// Set elevation visualization properties.
var elevationVis = {
  min: 0,
  max: 2000,
};
// Set elevation <= 0 as transparent and add to the map.
Map.addLayer(elevation.updateMask(elevation.gt(0)), elevationVis, 'Elevation');
Map.setCenter(17.93, 7.71, 2);
```

Alternatively when loading Image Collection we use the  `ImageCollection` object.

An ImageCollection is a stack or sequence of images. An ImageCollection can be loaded by pasting an Earth Engine asset ID into the ImageCollection constructor found in ImageCollection IDs in the data catalog. For example, to load the Sentinel-2 surface reflectance collection:

`var sentinelCollection = ee.ImageCollection('COPERNICUS/S2_SR');`

More detailed 

```
var ImageColl = ee.ImageCollection('MODIS/006/MOD13A1')
                                  // Filter by dates
                  .filter(ee.Filter.date('2015-03-01', '2020-03-31'))
                  .select('NDVI') //select the NDVI
                  .mean()         //create a composite of mean
                  .clip(Roi);     //clip the map to region of interest

var ndviParams = {min: -2000, max: 10000, palette: [
    'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
    '66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
    '012E01', '011D01', '011301'
  ]};
                                  // zoom the map at the center 
Map.centerObject(Roi, 7)
                                  // create the layers to be printed 
Map.addLayer(ImageColl,ndviParams,'NDVI2')
```

## Reducing an ImageCollection

Reducers in EE are used to aggregate data over time, space, and other data structures. To composite images in an `ImageCollection`, use `imageCollection.reduce()`. This will composite all the images in the collection to a single image representing. They belong to the `ee.Reducer` class. Specifically, the output is computed pixel-wise, such that each pixel in the output is composed of the median value of all the images in the collection at that location. To get other statistics, such as min, max, standard deviation, mean, sum, variance, or even an arbitrary percentile, of the images. The appropriate reducer should be selected and applied appropriately. 
Reducers take an input dataset and produce a single output. When a single input reducer is applied to a multi-band image, Earth Engine automatically replicates the reducer and applies it separately to each band. As a result, the output image has the same number of bands as the input image; each band in the output is the reduction of pixels from the corresponding band in the input data. Some reducers take tuples of input datasets. These reducers will not be automatically replicated for each band. For example, `ee.Reducer.LinearRegression()` takes multiple predictor datasets (representing independent variables in the regression) in a particular order.
Learn more about Reducers from [Reducer Overview](https://developers.google.com/earth-engine/guides/reducers_intro) page and [Image Reduction](ImageCollection Reductions) approaches  

There two types of reducers 

1. Vertical Reduce (over time) 


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/686ed06qq73m1wnct2u7.png)




2. Horizontal Reduce on Image (over space)



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1ij3ezqmetz8hxvtb2o.png)

## Google Earth Engine integration with Kepler.gl

This integration facilitates and presents EE scalability with external platforms. Kepler is a Python library for visualizing geospatial data in Jupyter notebooks. [Kepler.gl](https://kepler.gl/) is a high-performance web-based tool created by the Uber’s Visualization Team for visual exploration of large scale geospatial datasets. It is used to render large-scale interactive maps. EE Python API and Kepler.gl works best for deployment and non-geospatial scientists.
Google Earth Engine comes with some challenges, 

## To search for locations with similar metadata:

1. How to divide the globe into small grid tiles?
2. How to handle the enormous computing requirement?
3. How to save the tile results?