Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]

Unit 5: grating pretreatment

1 Introduction

In this module, we will discuss the following concepts:

  1. Understand the types of data correction commonly used in remote sensing images.
  2. How to intuitively compare the spatial data of different preprocessing levels in the same dataset.
  3. How to perform cloud masking and cloud masking assessment in Google Earth Engine for Landsat 8 surface reflectance images.

2 background

What is preprocessing?
Most of the data you will find in Google Earth engine (GEE) has been preprocessed to some extent. This involves several different quality control methods to ensure the highest accuracy and consistency within the grid set. Depending on the collection, there may be various levels of preprocessing available, and it is important to understand the differences in order to successfully integrate remote sensing data into ecological research. Before providing data in Gee, publishers consistently addressed three common sources of error in image products: atmosphere (i.e. air chemistry), terrain (i.e. elevation), and geometry (i.e. pixel consistency).


Atmospheric correction
As solar energy bounces off the earth's surface and returns to our sensors in space, the atmosphere does a good job in getting in the way. This occurs in the form of scattering and absorption (see for more information) Module 3 ). Identifying and correcting these effects is important for accurately representing and interpreting real surface conditions, such as tree leaf pigments or differences between urban and agricultural pixels.


Terrain and terrain correction
The lighting effects of slope, aspect and elevation pose additional challenges to the collection and processing of remote sensing data. A variety of correction methods have been developed, including the use of digital elevation models to predict problematic terrain. If your research is conducted in high-altitude areas or areas with steep terrain, you will be glad to know that the preprocessing of terrain effects is the responsibility of experts (although manual methods do exist for caution and caution).


geometric correction
This process ensures that the alignment of raster images is systematic and aligned over time and relative to other images. For Landsat, the geographic registration and orthophoto correction processes are completed through independent ground control points and previously created digital elevation models. For archival datasets like Landsat, it is most important to ensure that pixels are arranged year after year and again. Otherwise, remote sensing scientists and ecologists will have little ability to conduct multi temporal analysis.


It is important to remember that these quality assurance methods are not 100% foolproof! Follow the motto "know your data" and carefully examine your images in terms of quality and quantity. We will show several examples later in the module.
 

3 preprocessing in Google Earth Engine using Landsat 8

Before providing data in Google Earth engine (free!) Dedicated support and working behind the scenes is an incredible advantage. However, you may still find it necessary to manipulate the dataset you are interested in to promote specific research applications. In this module, we will use Landsat 8 data. The following figure details several use cases at different processing levels.
 

Young et al, 2017 The decision workflow shows the recommended use cases for different levels of Landsat data preprocessing.

3.1 example of pretreatment level.

In order to qualitatively understand the differences between different preprocessing levels, we can view several true color images of Southern Oregon in late summer 2018. In this time range, our standard atmospheric interference is due to the interference from Northern California Karl fire . To evaluate our initial image, we will load the "original" Landsat 8 collection. Raw data (also known as "sensor radiation") have not been corrected for any form of potential impact and are not usually used for ecological studies. However, it is helpful to establish a baseline for upcoming levels. Run the following script to generate an image similar to the following.

Note: in addition to the following preprocessing levels, Landsat data is divided into two quality levels, layer 1 and layer 2. Tier 1 is a higher quality option. single click here Learn more about the differences between levels.

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Center our map on southern Oregon, USA.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">setCenter</span>(<span style="color:#ce5c00"><strong>-</strong></span><span style="color:#0000cf">122.3158</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">42.4494</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">12</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Import Tier 1 Raw Landsat 8 scene.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> raw <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1/LC08_045031_20180811'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define the true-color vis params.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> rawvis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">30000.0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">gamma</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">1</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add the raw image to your map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(raw<span style="color:#ce5c00"><strong>,</strong></span> rawvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'raw'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

Original Landsat 8 image from southern Oregon. Our image is centered on MT McLoughlin (2893 m) and to the East is Upper Klamath Lake. If you zoom out, you can see the two cities of Medford (West) and kramas falls (East).

3.2 top of atmosphere (TOA)

The next level of preprocessing uses our "raw" data and corrects the effects of solar activity, including solar irradiance, earth sun distance and solar elevation. For researchers, the top of the atmosphere (TOA) is usually suitable for evaluating images of a single date and a single scene (i.e. land cover classification in a relatively small study area). This is because different degrees of solar effect depend on the date, time and latitude of collection. Attach the generated image to your script, similar to the following.

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// To begin your comparison, bring in an image from Tier 1 Landsat 8 Top of Atmosphere.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> toa <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1_TOA/LC08_045031_20180811'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define the true-color vis params.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> toavis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.4</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add the TOA image to your map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(toa<span style="color:#ce5c00"><strong>,</strong></span> toavis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'toa'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

After loading the TOA set, some images look clearer due to some correction for the influence of solar effect. However, there seems to be work to be done!

3.3 surface reflectance (SR)

These data have been subjected to the highest level of preprocessing in an attempt to best represent the actual situation on the ground, in which a certain amount of solar energy bounces (reflects) to air and spaceborne sensors. However, even surface reflectance products can be adversely affected by low solar angles, excessive clouds, and coverage locations above 65 degrees north latitude (Young et al., 2017). Nevertheless, it is recommended to use Landsat surface reflectance data for analysis of multiple dates (e.g. change detection) or large geographical ranges (e.g. algorithm prediction). Add the last piece of code to your script to view the image below in your map viewer pane.

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Finally, source an image from Tier 1 Landsat 8 surface reflection.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> sr <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1_SR/LC08_045031_20180811'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define the true-color vis params.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> srvis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">3000</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">gamma</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">1.4</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add the surface reflectance image to your map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(sr<span style="color:#ce5c00"><strong>,</strong></span> srvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'sr'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

The application of atmospheric correction seems to greatly improve our image clarity, especially in the agricultural area west of upper kramas lake and Mt McGloughlin.

3.4 complete code of Landsat Image comparison

The code for these examples comes from a specific Landsat Image, but you now have a framework to investigate any area of interest (that is, your study area) to compare different levels of preprocessing.

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Center our map on southern Oregon, USA.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">setCenter</span>(<span style="color:#ce5c00"><strong>-</strong></span><span style="color:#0000cf">122.3158</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">42.4494</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">12</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Import Tier 1 Raw Landsat 8 scene.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> raw <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1/LC08_045031_20180811'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define the true-color vis params.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> rawvis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">30000.0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">gamma</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">1</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add the raw image to your map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(raw<span style="color:#ce5c00"><strong>,</strong></span> rawvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'raw'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// To begin your comparison, bring in an image from Tier 1 Landsat 8 Top of Atmosphere.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> toa <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1_TOA/LC08_045031_20180811'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define the true-color vis params.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> toavis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.4</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add the TOA image to your map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(toa<span style="color:#ce5c00"><strong>,</strong></span> toavis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'toa'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Finally, source an image from Tier 1 Landsat 8 surface reflection.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> sr <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1_SR/LC08_045031_20180811'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define the true-color vis params.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> srvis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">3000</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">gamma</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">1.4</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add the TOA image to your map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(sr<span style="color:#ce5c00"><strong>,</strong></span> srvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'sr'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

3.5 cloud shielding

As we have found, when we get the surface reflectance product, the pretreatment of atmospheric, topographic and geometric correction has been completed. Before being available in Google Earth Engine, a very important step not included in Landsat data processing is to eliminate near earth weather phenomena. This usually occurs in the form of clouds. Clouds are particularly common in the tropics (i.e. dense rainforests) and water bodies. In this section, we will look at the Quetico superior region in Northeast Minnesota and southwest Ontario, which is partially covered by hundreds of small to medium-sized lakes due to large clouds.


In summer, clouds gather over Jean Lake in ketico Provincial Park. Image source: Tay schulke.

3.5.1 single image masking: Part 1

Let's start by loading an image that we know is cloudy. There are many choices in this part of the world, but this picture in late August shows us many forms of clouds. Another thing to consider is that clouds will cast shadows on the land below, which further expands the geographical scope that we must eventually remove. Start a new script and run the following code to generate the image shown in the figure below.

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Load an initial image to test view a cloudy image.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> sr <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1_SR/LC08_027026_20180829'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define visparams for true-color image.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> srvis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">3000</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">gamma</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">1.4</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add your cloudy image to the map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(sr<span style="color:#ce5c00"><strong>,</strong></span> srvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'single_scene'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">setCenter</span>(<span style="color:#ce5c00"><strong>-</strong></span><span style="color:#0000cf">91.8859</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">48.8936</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">8.81</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

Cloudy image over Quetico superior country.

3.5.2 single image masking: Part 2

Now let's deal with our cloud problem. Landsat provides a pixel_ The QA band, in short, assigns different values based on previously quantified features, such as the likelihood of clouds and haze. You'll find the code to build a cloud mask more complex, but it's a simple, conservative way to remove those annoying white spots from the image. Attach the following code to the existing script and rerun it to see an image similar to the following figure. Remember to uncheck "single_scene" in the layer control!

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Define simple cloud mask, based in values from the 'pixel_qa' band.</em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// Essentially, values of 322 = land and 324 = water.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> qa <span style="color:#ce5c00"><strong>=</strong></span> sr<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">select</span>(<span style="color:#4e9a06">'pixel_qa'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> mask <span style="color:#ce5c00"><strong>=</strong></span> qa<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">eq</span>(<span style="color:#0000cf">322</span>)<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">or</span>(qa<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">eq</span>(<span style="color:#0000cf">324</span>))<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> sr_cm <span style="color:#ce5c00"><strong>=</strong></span> sr<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">updateMask</span>(mask)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add your new map for comparison to the cloudy image.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(sr_cm<span style="color:#ce5c00"><strong>,</strong></span> srvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'single_scene_masked'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

Clouds and cloud shadows are successfully removed, but the resulting image will not leave many available pixels.

3.5.3 shielding across multiple dates

In a single Landsat scene with clouds, we lost considerable geographic coverage. But there is another way! We can also apply masks over multiple date ranges. To do this, we need to create a function that we will Module 9 Detailed in. Now, use the following functions (and the rest of the code) to continue your script. Attach code to an existing script.

Although there are indeed prefabricated NDVI image sets from Landsat in Google Earth Engine, these data sets are only available before 2017. Therefore, we will also calculate NDVI and add it to our image collection. This will enable us to generate a median for each pixel throughout the growing season in 2018 to measure the vegetation health of the study area. Rerun your code and the resulting image should look like this.

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Define how your cloudMask function should work.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> cloudMask <span style="color:#ce5c00"><strong>=</strong></span> <span style="color:#204a87"><strong>function</strong></span>(image) {</span>
<span style="color:inherit">  <span style="color:#8f5902"><em>// var mask = image.select('pixel_qa').eq(322).or(image.select('pixel_qa').eq(324));</em></span></span>
<span style="color:inherit">  <span style="color:#204a87"><strong>var</strong></span> mask <span style="color:#ce5c00"><strong>=</strong></span> image<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">select</span>(<span style="color:#4e9a06">'pixel_qa'</span>)<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">eq</span>(<span style="color:#0000cf">322</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit">  <span style="color:#204a87"><strong>return</strong></span> image<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">mask</span>(mask)<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit">}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// This time we'll look at a more ecologically-focused example, using NDVI.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> collection <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">ImageCollection</span>(<span style="color:#4e9a06">"LANDSAT/LC08/C01/T1_SR"</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filterDate</span>(<span style="color:#4e9a06">'2018-06-01'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'2018-09-30'</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filter</span>(ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#c4a000">Filter</span><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">calendarRange</span>(<span style="color:#0000cf">140</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">270</span>)) <span style="color:#8f5902"><em>// roughly, our potential growing season</em></span></span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filterMetadata</span>(<span style="color:#4e9a06">'WRS_PATH'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'equals'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">27</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filterMetadata</span>(<span style="color:#4e9a06">'WRS_ROW'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'equals'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">26</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">map</span>(cloudMask)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">map</span>(<span style="color:#204a87"><strong>function</strong></span> <span style="color:#000000">NDVI</span>(i){</span>
<span style="color:inherit">  <span style="color:#204a87"><strong>return</strong></span> i<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addBands</span>(i<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">normalizedDifference</span>([<span style="color:#4e9a06">'B5'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B4'</span>])<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">rename</span>(<span style="color:#4e9a06">'NDVI'</span>))  <span style="color:#8f5902"><em>// generates NDVI band</em></span></span>
<span style="color:inherit">})<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> median <span style="color:#ce5c00"><strong>=</strong></span> collection<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">median</span>()<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Red = lower values and darker green = higher values</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> collectionVis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#4e9a06">'NDVI'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.5</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.95</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">palette</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'red'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'yellow'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'green'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'003300'</span>]}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(median<span style="color:#ce5c00"><strong>,</strong></span> collectionVis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'NDVI'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

Visualize the median NDVI for the entire growing season in 2018. Switch different background layers at will. Your image may not be exactly the same as the image shown here.

3.5.4 visual image counting

Our NDVI image looks good. But how confident are we in these values? Specifically, it is important to assess how many images actually make up our median. We can quickly check whether our NDVI median is representative in the whole study area by visualizing the sum of how many images are used at each pixel position. Attach the following code to your script and click Run. You should see an image similar to the following figure.

For the counting layer, if we find spatial anomalies in the NDVI value, there are many options. We can expand our seasonal date range or choose to include multi-year data. In the end, we may accept the failure, think the weather is too cloudy and useless, and decide to explore different data sets - which is completely acceptable!

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Create counts band.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> counts <span style="color:#ce5c00"><strong>=</strong></span> collection<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">select</span>(<span style="color:#4e9a06">'NDVI'</span>)<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">count</span>()<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Find our potential maximum count by getting the size of the initial image collection.</em></span></span>
<span style="color:inherit"><span style="color:#000000">print</span>(collection<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">size</span>())<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// In this palette, red = lower values and blue = higher values.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> countVis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">6</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">palette</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'b2182b'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'ef8a62'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'fddbc7'</span><span style="color:#ce5c00"><strong>,</strong></span> </span>
<span style="color:inherit">                                          <span style="color:#4e9a06">'d1e5f0'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'67a9cf'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'2166ac'</span>]}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(counts<span style="color:#ce5c00"><strong>,</strong></span> countVis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'counts'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

Visualization is used to calculate the number of images in each pixel. Darker red has a lower value and darker blue has a higher value.

3.5.5 generating and exporting histograms

To understand the quantitative distribution of count values, we can construct a histogram of count data. If our study area is so cloudy that the average represents only one or two values, we may need to reconsider our source data or the year of collection. Add this final code block to the script and you will be able to see the histogram in the console tab. You will make your own geometry (if you need to review how to do this, see Module 1). Your histogram may vary slightly depending on your shape, but it is sufficient to contain images, and it should be similar to the distribution in the following figure.

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Draw your own rectangle and try to cover most of the Landsat scene and </em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// then we'll make a histogram of the distribution. Because the scene area </em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// is so large  GEE requires us to perform some aggregating. But this will </em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// give us a general sense of our distribution.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> histogram <span style="color:#ce5c00"><strong>=</strong></span> ui<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#c4a000">Chart</span><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#c4a000">image</span><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">histogram</span>(counts<span style="color:#ce5c00"><strong>,</strong></span> geometry<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">120</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Display the histogram.</em></span></span>
<span style="color:inherit"><span style="color:#000000">print</span>(histogram)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

The histogram function is used to quantify the number of value distributions from the count layer.

4 Conclusion

In this lesson, we reviewed some common corrections applied to remote sensing images that help produce the high-quality products you will find in Google Earth Engine. We also introduced a simple framework for visualizing these differences and understood how changes in processing levels affect the images produced by smoggy summer in southern Oregon. Finally, we build a workflow script, use Google Earth Engine to remove clouds from the growing season image, generate the average vegetation index value, and evaluate the distribution of the used image.

5 complete cloud shielding code

<span style="color:#333333"><span style="background-color:#ffffff"><span style="color:#333333"><span style="background-color:#f8f8f8"><code><span style="color:inherit"><span style="color:#8f5902"><em>// Load an initial image to test view a cloudy image.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> sr <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">Image</span>(<span style="color:#4e9a06">'LANDSAT/LC08/C01/T1_SR/LC08_027026_20180829'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define visparams for true-color image.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> srvis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'B4'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'B3'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'B2'</span>]<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">3000</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">gamma</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">1.4</span>}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add your cloudy image to the map.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(sr<span style="color:#ce5c00"><strong>,</strong></span> srvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'single_scene'</span>)</span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">setCenter</span>(<span style="color:#ce5c00"><strong>-</strong></span><span style="color:#0000cf">91.8859</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">48.8936</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">8.81</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define simple cloud mask, based in values from the 'pixel_qa' band.</em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// Essentially, values of 322 = land and 324 = water.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> qa <span style="color:#ce5c00"><strong>=</strong></span> sr<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">select</span>(<span style="color:#4e9a06">'pixel_qa'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> mask <span style="color:#ce5c00"><strong>=</strong></span> qa<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">eq</span>(<span style="color:#0000cf">322</span>)<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">or</span>(qa<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">eq</span>(<span style="color:#0000cf">324</span>))<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> sr_cm <span style="color:#ce5c00"><strong>=</strong></span> sr<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">updateMask</span>(mask)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Add your new map for comparison to the cloudy image.</em></span></span>
<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(sr_cm<span style="color:#ce5c00"><strong>,</strong></span> srvis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'single_scene_masked'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Define how your cloudMask function should work.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> cloudMask <span style="color:#ce5c00"><strong>=</strong></span> <span style="color:#204a87"><strong>function</strong></span>(image) {</span>
<span style="color:inherit">  <span style="color:#8f5902"><em>// var mask = image.select('pixel_qa').eq(322).or(image.select('pixel_qa').eq(324));</em></span></span>
<span style="color:inherit">  <span style="color:#204a87"><strong>var</strong></span> mask <span style="color:#ce5c00"><strong>=</strong></span> image<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">select</span>(<span style="color:#4e9a06">'pixel_qa'</span>)<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">eq</span>(<span style="color:#0000cf">322</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit">  <span style="color:#204a87"><strong>return</strong></span> image<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">mask</span>(mask)<span style="color:#ce5c00"><strong>;</strong></span></span>
<span style="color:inherit">}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// This time we'll look at a more ecologically-focused example, using NDVI.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> collection <span style="color:#ce5c00"><strong>=</strong></span> ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">ImageCollection</span>(<span style="color:#4e9a06">"LANDSAT/LC08/C01/T1_SR"</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filterDate</span>(<span style="color:#4e9a06">'2018-06-01'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'2018-09-30'</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filter</span>(ee<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#c4a000">Filter</span><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">calendarRange</span>(<span style="color:#0000cf">140</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">270</span>)) <span style="color:#8f5902"><em>// roughly, our potential growing season</em></span></span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filterMetadata</span>(<span style="color:#4e9a06">'WRS_PATH'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'equals'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">27</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">filterMetadata</span>(<span style="color:#4e9a06">'WRS_ROW'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'equals'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">26</span>)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">map</span>(cloudMask)</span>
<span style="color:inherit"><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">map</span>(<span style="color:#204a87"><strong>function</strong></span> <span style="color:#000000">NDVI</span>(i){</span>
<span style="color:inherit">  <span style="color:#204a87"><strong>return</strong></span> i<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addBands</span>(i<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">normalizedDifference</span>([<span style="color:#4e9a06">'B5'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'B4'</span>])<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">rename</span>(<span style="color:#4e9a06">'NDVI'</span>))  <span style="color:#8f5902"><em>// generates NDVI band</em></span></span>
<span style="color:inherit">})<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> median <span style="color:#ce5c00"><strong>=</strong></span> collection<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">median</span>()<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Red = lower values and darker green = higher values.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> collectionVis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">bands</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#4e9a06">'NDVI'</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.5</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0.95</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">palette</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'red'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'yellow'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'green'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'003300'</span>]}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(median<span style="color:#ce5c00"><strong>,</strong></span> collectionVis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'NDVI'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Create counts band.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> counts <span style="color:#ce5c00"><strong>=</strong></span> collection<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">select</span>(<span style="color:#4e9a06">'NDVI'</span>)<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">count</span>()<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Find our potential maximum count by getting the size of the initial image collection.</em></span></span>
<span style="color:inherit"><span style="color:#000000">print</span>(collection<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">size</span>())<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// In this palette, red = lower values and blue = higher values.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> countVis <span style="color:#ce5c00"><strong>=</strong></span> {<span style="color:#204a87">min</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">0</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">max</span><span style="color:#ce5c00"><strong>:</strong></span> <span style="color:#0000cf">6</span><span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#204a87">palette</span><span style="color:#ce5c00"><strong>:</strong></span> [<span style="color:#4e9a06">'b2182b'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'ef8a62'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'fddbc7'</span><span style="color:#ce5c00"><strong>,</strong></span> </span>
<span style="color:inherit">                                          <span style="color:#4e9a06">'d1e5f0'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'67a9cf'</span><span style="color:#ce5c00"><strong>,</strong></span><span style="color:#4e9a06">'2166ac'</span>]}<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit">Map<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">addLayer</span>(counts<span style="color:#ce5c00"><strong>,</strong></span> countVis<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#4e9a06">'counts'</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Draw your own rectangle and try to cover most of the Landsat scene and </em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// then we'll make a histogram of the distribution. Because the scene area </em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// is so large  GEE requires us to perform some aggregating. But this will </em></span></span>
<span style="color:inherit"><span style="color:#8f5902"><em>// give us a general sense of our distribution.</em></span></span>
<span style="color:inherit"><span style="color:#204a87"><strong>var</strong></span> histogram <span style="color:#ce5c00"><strong>=</strong></span> ui<span style="color:#ce5c00"><strong>.</strong></span><span style="color:#c4a000">Chart</span><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#c4a000">image</span><span style="color:#ce5c00"><strong>.</strong></span><span style="color:#000000">histogram</span>(counts<span style="color:#ce5c00"><strong>,</strong></span> geometry<span style="color:#ce5c00"><strong>,</strong></span> <span style="color:#0000cf">120</span>)<span style="color:#ce5c00"><strong>;</strong></span></span>

<span style="color:inherit"><span style="color:#8f5902"><em>// Display the histogram.</em></span></span>
<span style="color:inherit"><span style="color:#000000">print</span>(histogram)<span style="color:#ce5c00"><strong>;</strong></span></span></code></span></span></span></span>

6 references

Young, NE, Anderson, RS, Chignell, SM, Vorster, AG, Lawrence, R., & Evangelista, PH (2017). Landsat pretreatment survival guide. Ecology, 98 (4), 920-932.

Keywords: Javascript Big Data Computer Vision GEE

Added by zarathu on Tue, 15 Feb 2022 03:13:33 +0200