Overview
Teaching: 5 min Exercises: 25 minQuestions
How do I create a time series for a given location?
How can I plot that time series within Google Earth Engine?
How do I make that plot interactive?
Objectives
Load MODIS imagery and calculate snow index.
Plot timeseries of average snow index by counties in WA
Dynamically select lat/longs for creating time series plots.
Create a time series of NDSI for a selected point.
This code allows users to dynamically generate time series plots for from points that are dynamically chosen on a map on the fly. The time series show the 8 day composites of Normalized Difference Snow Index at 500 m resolution. These indices are derived from MODIS.
Link to a static version of the full script used in this module: https://code.earthengine.google.com/6a6470a8ee527aeec31dcd492bf6b98e
This script is structured to make it easy for the user to select different images, dates and regions. For this exercise, we are going to leave the parameters as they are to set the extent as a study area in Skagit County, Washington.
NDSI is a spectral index calculated from green and shortwave-infrared bands. Here, we are deriving our own NDSI from MODIS 8 day composite surface reflectance product using the normalizedDifference
function. NDSI ranges from -1 to 1, with values greater than 0 generallyconsidered to have snow present.
Here we make a plot of 8-day spatially averaged NDSI in Skagit County. The following code creates a chart and maps a spatial mean reducer across each image in the MODIS collection, using the Skagit County border as our region. We then print the chart to show it in the console.
The type of chart we use (“seriesByRegion”) accepts mutiple regions as input and reduces the image collection in each region individually. Try returning to the line where we selected Skagit County and remove the “COUNTYFP” filter. This will result in all counties in Washington being selected. Running the code again will result in a timeseries plot of averaged NDSI in all counties.
You can alter the client-side user interface (UI) through the ui package by adding widgets to the Code Editor interface. You can read about the ui package in the UI Overview section of the Developers Guide
The general idea is that you make a widget, which could be simple (a button) or complex (a chart). Then you define the behavior of the widget and then add it to the display. Here we create a panel, define the contents of the panel using labels, and create a callback function so the user can click a point and it will record the lat/long as an object called points.
You can read more about how to define the panel and layouts in the Panels section of the Developers Guide.
Now that we have set up our user interface and built the call-back, we can define a time series chart. The chart uses the lat/long selected by the user and builds a time series for NDSI at that point. It takes the average NDSI at that point, extracts it, and then adds it to the time series. This series is then plotting as a chart.
You should see something like this appear in the bottom left:
If you are computing the indices on the fly, or you have many points or areas of interest, you may have the unpleasant experience of your code timing out. One way to avoid that is to just export the time series as a .csv to Google Drive or Cloud Storage. An example of how to do this can be found in Episode 04: Reducers of this tutorial.
Key Points
Time series data can be extracted and plotted from Image Collections for points and regions.
GEE has increasing functionality for making interactive plots.
The User Interface can be modified through the addition of widget.