Objective:
In Lab 6 we are introduced to the Earth Engine API. Earth Engine is an online platform designed to facilitate scientific analysis and the visualization of geospatial datasets. Using Javascript, we perform some basic data analysis using Earth Engine, including the application of computation to an image, the application of a spatial reducer, the loading and filtering of an image collection, modification of image bands, reducing image collections, isolating an image, computing NDVI, writing a function, mapping a function over a collection, building a greenest-pixel composite, charting NDVI over time, and exporting an RGB image. The following write up includes discussion and images of the results of these processes.
Earth Engine is an API. An API, or Application Coding Interface, is a set of functions and procedures that allow for the creation of applications that access the features or data of an operating system, application, or other service. It is the part of a remote server that specifically receives requests and sends responses (Gazarov, 2016). It is, more or less, the user interface for the remote server.
Earth Engine is an open platform that allows for huge repositories of data to be freely accessed. One of the main contributions of Earth Engine is it's storage capacity; one can perform analysis on databases that would be much too large to store on an individual computer (EarthEngine, n.d.).
Until now, we have been using the Python language for our GIS analyses. However, the primary programming language used in Earth Engine is Javascript. Javascript is considered a frontend, which differs from python which is generally located on server side or backend programming (EDUCBA.com, n.d.). There are several similarities and differences; though I will not get into those here, it is worth noting that Javascript is an object -oriented language. Though the difference may not be apparent within the simple exercises we are performing here, the approach to programming with Javascript will differ compared to that used with Python, especially as programs become more complicated and involved.
An example of the Earth Engine coding interface is shown in Figure 1.
Figure 1: Earth Engine coding interface -- Hello, world!
Earth Engine contains a repository of image data. By searching "elevation" we are presented with dozens of results of digital elevation models from various sources (see Figure 2). We choose SRTM Digital Elevation Data 30m, which is data from the Shuttle Radar Topography Mission, and add the image object it to our exercise using the print(mapName);
command. We are able to add the image to the interactive map using Map.addLayer(mapName);
(see Figure 3) , and set visualization parameters using Map.addLayer(mapName, {min: 0, max: 3000});
(see Figure 4).
Figure 2: Sample of results from 'elevation' search on Earth Engine
Figure 3: SRTM data added to map, no visualization parameters specified.
Figure 4: SRTM data added to map, visualization parameters specified as: min = 0m, max = 3000m.
Calculations like slope can be computed easily in Earth Engine. Figure 5 shows the results of a slope calculation over the Grand Canyon. The function ee.Terrain.slope(mapName);
was used to this end.
Figure 5: Slope Calculation applied to the Grand Canyon. Slope classified from 0-60, with 0 being minimum, and 60 being the maximum.
A user may want to reduce image collections to simplify future data analyses and shorten computation time. Essentially, this process composites all images in an image collection to a single image that may represent the min, max, mean, or standard deviation of the images. The command imageCollection.reduce()
is used. The result of the command is a single image in which each pixel is composed of the median value (or standard deviation, max, or min, depending on the specified reducer type) of all the images in the collection at the specified location (Google Earth Engine, 2019b). Figure 6 shows the results of a filtered image of the Grand Canyon, with no reducer applied. The cloud cover obscuring the land makes the details difficult to see. Figure 7 shows the same area, with the median reducer applied. In this image, the prevalence of white pixels (clouds) are reduced, and the terrain is much more visible compared to the non-reduced image.
The reduce tool can also be used to calculate characteristics like elevation. Figure 8 shows how the Add Geometry tool can be used with the .reduceRegion() tool to calculate the mean elevation within the area determined by the user. The data output of this tool is presented in Figure 9.
Figure 6: West Coast USA, filtered by date, no reducer applied
Figure 7: West Coast USA, filtered by date, median reducer applied
Figure 8: Result of the add geometry tool. The mean elevation of the terrain inside this user created geometry will be calculated
Figure 9: Output of the mean elevation calculation.
In order to reduce computation time and more exactly specify the region of study, a point or location can be isolated. Once a point of interest is specified using the geometry tool, the bounds of analysis can be limited to the area immediately around this point. The command is: imageCollection.filterBounds(pointOfInterest);
. The output is another image collection. Figure 10 shows the output of this function applied to the current dataset. The command ee.Image(filtered.first());
is used to extract a sample from the output, which can then be added to Earth Engine as a separate layer.
Figure 10: Point of Interest Isolated
NVDI refers to the normalized difference vegetation index. This is a graphical indicator that is often used in analysis of remote sensing data. The objective of this index it so assess whether or not an area under study contains living green vegetation. It does this through quantification of near-infrared wavelengths, which are absorbed by vegetation, and reflected, to varying degrees, by surfaces that do not contain vegetation (GIS Geography, 2018).
NVDI can be displayed directly in Earth Engine using more than one technique. The .select() tool can be employed to pick out NIR and Red bands from the image, and some basic user calculations can be used to filter the band data based on NVDI criteria. The results for this method are shown in Figure 11. Alternatively, the ee.Image.normalizedDifference() function can be used. This is a more direct function that has been built into Earth Engine to simplify the popular NVDI calculation. These results can be seen in Figure 12. As you can see, the built in function produces the same as the results of the more labor intensive technique listed above.
Figure 11: Results of NVDI manual calculation
Figure 12: Results of Earth Engine build-in Normalized Difference function
To simplify a program, it can be useful to define a function that carries out an action specific to the results you desire, so that the function can be called throughout the code, and the steps to completing the action do not have to be completed. In this case, a function was defined to calculate NVDI data, and return an image composed of only this data. The function is as follows:
var rgb_vis = {min: 0, max: 0.3, bands: ['B4', 'B3', 'B2']};
function addNDVI(image) {
var ndvi = image.normalizedDifference(['B5', 'B4']);
return image.addBands(ndvi);
}
var filtered = L8.filterDate('2015-09-01', '2015-10-30') .filterBounds(roi);
var image = ee.Image(filtered.first());
var ndvi = addNDVI(image);
Map.addLayer(image, rgb_vis, 'RGB');
Map.addLayer(ndvi, {min: 0, max: 1}, 'NDVI');
Note that the function returns an image. This is important, otherwise the function would run, and the data would be processed, but it would not be callable from outside the function itself. The results produced by this function, as is, are shown in Figure 13. Note that, in this first iteration, the image is difficult to see. This is because Band B1 is the default when visualizing the image. We can change this by specifying that we wish to see the NVDI band ('nd') using: Map.addLayer(ndvi, {bands: 'nd', min: 0, max: 1}, 'NDVI');
. This produces the expected image, shown in Figure 14.
The developed function can be applied over an entire image collection. Figure 15 shows the results of the function applied to the full Landsat 8 Image Collection.
Figure 13: Result of NVDI function, showing Grand Canyon - Band 'B1'
Figure 14: Results of NVDI function, showing Grand Canyon - Band 'nd'
Figure 15: Results of NVDI function applied to entire Landsat Image Collection (showing West Coast USA)
Creating composite images is another way to produce mosaics with less cloud cover, or to produce mosaics that disply the characteristics of interest, greenery, for example. According to Earth Engine Documentation (2019a) "compositing refers to the process of combining spatially overlapping images into a single image based on an aggregation function". The ee.ImageCollection.qualityMosaic() method can be employed to order image bands based on a specific metric, in this case, NDVI (Cardille, 2019). The goal is to display only the pixels that that have the highest NDVI values, as these will contain the most greenery. The results are displayed in Figure 16.
Figure 16: Results of Greenest Pixel function, applied to Central USA
NVDI can be charted over time. Figure 17 shows the graph of the fluctuations in NVDI in an agricultural region in the United States. This chart can be downloaded as an .svg, .png, or a .csv file for further analysis.
Figure 17: NVDI fluctuations over time in study area.
An Earth Engine user may wish to configure the output data from the Earth Engine Analysis in different ways, depending on the purpose of the project. Outputs can be exported in many ways, from tables, to images, to videos. The outputs can be sent directly to an online folder. 3-band RGB images are widely compatible across platforms. Earth Engine outputs can be exported as RGB images using the .visualize(rgb_vis)
function. They can then be exported using Export.image(rgb, 'fileName');
or directly to a drive using: Export.image.toDrive(rgb, 'GreenestPixel');
. The export appears in the 'Task' window, where upon pressing 'run' the user manually determines parameters such as file name, destination, and resolution. The file is processed and added to the indicated folder.
Note: the RGB output file took approximately 10 minutes to fully process. Considering the amount of data, this is quite impressive. The results are shown in Figure 18.
Figure 18: RGB Output File
References:
Done for Advanced GIS for Natural Resource Management, in the McGill University Department of Natural Resource Sciences, Professor Jeffrey Cardille