Introduction
Welcome to the wonderful world of satellite imagery!
In this module, we'll take a look at Google Earth Engine (GEE) fundamentals and explore how to inspect and visualize data stored in satellite image bands. Satellites see the world in a way that is both similar to and vastly different from the human eye, capturing an incredible range of wavelengths and a much wider field of view. With the GEE API, we'll be able to display and analyze these images in an approachable and powerful way. We'll also learn how to use the inspector tool, a handy "point and click" feature that lets us extract data and information about specific locations. We'll discover a collection of new JavaScript elements that will give us the tools we need to explore our fascinating world, through the eyes of satellites.
“Satellite, in my eyes
Like a diamond in the sky
How I wonder”
Viewing satellite images and spectral bands
This lesson teaches you how to inspect and visualize data stored in satellite image bands.
Google Earth Engine (GEE) fundamentals
Let’s begin by clicking the following link to add the code repository for these trainings (link). Most of the trainings for this hackathon are modified or condensed versions of the trainings found in this free, web-based Earth Engine training book.
When you click the link to the code repository, it should take you to GEE’s code editor. This is a web-based, JavaScript API that is approachable even for those who are not familiar with JavaScript. Here, you can display your results on a map, save your scripts, access documentation, manage tasks, and more.
The image below shows the code editor screen.
The middle pane contains the code editor - this is straightforward.
The left pane contains the Scripts tab and Docs tab. The scripts tab is where you will find all of your different codes (like the file explorer on Windows). The Docs tab is incredibly useful for searching through GEE’s pre-made functions for you to use throughout the hackathon (much like the “help” command in MATLAB).
The right pane contains the Inspector tab and Console tab. The inspector tab allows you to interact with the map itself to “point and click” which will return values for each pixel based on the data you’ve loaded in - you’ll see this in action soon! Finally, the Console tab is where you can display data outputs (much like the command window in MATLAB)
Spectral Bands
A spectral band is a portion of the energy spectrum. The image below shows the entire energy spectrum. The visible waves (blue, green, and red) are what humans see, but satellites are able to monitor so much more!
Different objects reflect different wavelengths of energy. For example, vegetation (chlorophyll) reflects a ton of green light in the visible spectrum, so that's why plants appear green to humans. However, they reflect even more near-infrared light which humans cannot see, but satellites can!
In this hackathon, you will analyze many of the spectral bands that satellites see but humans cannot see! Check out the spectral bands cheat sheet to get more info on specific spectral bands, their uses, and data sources!
Accessing an image
To begin, you will construct an image with the Code Editor. As you encounter code in the lesson, follow along by building the same code in your Code Editor and clicking Run.
By creating the variable with the ee.Image function, Earth Engine loads an image captured by the Landsat 5 satellite on June 6, 2000 but you will not yet see any output. The print function enables you to retrieve data about the image, which will be shown on a dropdown in the Console panel.
You should be able to read that this image consists of 19 different bands. For each band, the metadata lists four properties, but for now let’s simply note that the first property is a name, or label, for the band enclosed in quotation marks. For example, the name of the first band is “SR_B1”.
A satellite sensor like Landsat 5 measures the magnitude of radiation in different portions of the electromagnetic spectrum. The first six bands in our image ("SR_B1" through "SR_B7") contain measurements for six different portions of the spectrum. The first three bands measure visible portions of the spectrum, or quantities of blue, green, and red light. The other three bands measure infrared portions of the spectrum that are not visible to the human eye.
Visualizing an image
Now let’s add one of the bands to the map as a layer (using the Map.addLayer function) so that we can see it. Follow along with the subsequent code example.
Note the different parts of the code: the function, values, comments, and strings. There are four important components of the command above:
first_image: This is the dataset to display on the map. (The variable you created earlier!)
bands: These are the particular bands from the dataset to display on the map. In our example, we displayed a single band named "SR_B1".
min, max: These represent the lower and upper bounds of values from "SR_B1" to display on the screen. By default, the minimum value provided (8000) is mapped to black, and the maximum value provided (17000) is mapped to white. The values between the minimum and maximum are mapped linearly to grayscale between black and white. Values below 8000 are drawn as black. Values above 17000 are drawn as white. Together, the bands, min, and max parameters define instructions for data display.
'Layer 1': This is a label for the map layer to display in the Layer Manager. This label appears in the dropdown menu of layers in the upper right of the map.
When you run the code, you might not notice the image displayed unless you pan around and look for it. To do this, click and drag the map towards Shanghai, China. (You can also jump there by typing “Shanghai” into the Search panel at the top of the Code Editor). Zoom to the small dark square: that's the image you just created!
Congrats! You just wrote your first Earth Engine script and may want to save it. Click the Save button. Clicking Save will prompt you to create a folder whose name cannot be changed in the future. It will also ask you to add the code to a repository. A repository is a convenient way to organize and share your code. Once your script is saved, it will appear in the script manager panel on the left side of your Code Editor.
The inspector tool
Let’s explore this image with the Inspector tool. When you click on the Inspector tab on the right side of the Code Editor, your cursor should now look like crosshairs. When you click on a location in the image, the Inspector panel will report data for that location under three categories as follows:
Point: data about the location on the map. This includes the geographic location (longitude and latitude) and some data about the map display (zoom level and scale).
Pixels: data about the pixel in the layer. If you expand this, you will see the name of the map layer, a description of the data source, and a bar chart. In our example, we see “Layer 1” is drawn from an image dataset that contains 19 bands. Under the layer name, the chart displays the pixel value at the location that you clicked for each band in the dataset. When you hover your cursor over a bar, a panel will pop up to display the band name and “band value” (pixel value). To find the pixel value for “SR_B1”, hover the cursor over the first bar on the left. Alternatively, by clicking on the little blue icon to the right of “Layer 1” (area B), you will change the display from a bar chart to a dictionary that reports the pixel value for each band.
Objects: data about the source dataset. Here you will find metadata about the image that looks very similar to what you retrieved earlier when you directed Earth Engine to print the image to the Console.
var first_image = ee.Image( 'LANDSAT/LT05/C02/T1_L2/LT05_118038_20000606'); print(first_image);
Map.addLayer( first_image, //dataset to display { bands: ['SR_B1'], //band to display min: 8000, //display range max: 17000 }, 'Layer 1' //name to show in layer manager );
In the example above, we're just displaying an image, and we provide the link to an image in China that we previously identified that we know will be clear: "LANDSAT/LT05/C02/T1_L2/LT05_118038_20000606". We use a clear image in the exercise, but we don't really cover how to find and display a new meaningful visual image.
To find a new image, there are two important points. One, in the exercise above, we use raw sensor data from Landsat satellites. We include the direct link to an image that I already know is clear and useful. Most images from Landsat are not clear. The images very often include cloud cover, the physical satellites pass over the land at random times, and sometimes the images come at night. So, it might not automatically give a useful visual image. On top of that the different Landsat satellites actually include up to a dozen bands.
For your reference, let's break down the information contained in the link:
But you can't know ahead of time how to find this information. So when you are looking for a useful image from a raw dataset, like Landsat, one way to find interesting images is filtering. In the Code Editor, you can filter the image collection by metadata (such as acquisition date and geography) and even check cloud cover to ensure the selected scene gives a clear view.
Here below is a coding example that highlights how to filter Landsat 8 raw data by a date range, geography, and cloud cover:
All that being said, the next exercise goes into using pre-processed datasets, which is what I recommend. Issues such as cloud cover, nighttime, and sometimes the dates are usually gone. So there are many datasets out there that you can use quite easily. The filtering is still a very useful tool though.
LANDSAT = The general Landsat "folder" within GEE. LT05 = Landsat 5 Thematic Mapper (TM). C02 = Collection 2 (the newest major collection reprocessing from USGS). T1_L2 = Tier 1, Level-2 data (usually surface reflectance, with atmospheric corrections).
var landsat8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_L2') // Filter by date. .filterDate('2020-01-01', '2020-12-31') // filter by a region, where the region is some geometry you define. .filterBounds(region) // Filter by cloud cover (ie this means less than 10%). .filter(ee.Filter.ltLinks to an external site.('CLOUD_COVER', 10));
Recap
Here’s what we learned in this module:
The GEE API is an approachable and powerful tool for displaying (and later analyzing) satellite imagery
Satellites view the world through spectral bands, just like the human eye sees the world through red, green, and blue bands. However, satellites have the potential to see even more wavelengths outside of the visible spectrum and at a much wider field of view than a human on the ground!
The inspector tool is an easy, “point and click” method for pulling data/information about exact locations on our interactive map
New code elements:
var creates a new variable in GEE that is used to store information. In our exercise we used it to store an image
ee.Image is a function that loads an image from the GEE data catalog, which we can then use throughout our code
print is a function that will display information about our variable in the Console tab
Map.addLayer is a function that enables to add the satellite image that we loaded into the map window below our code editor