Displaying data and creating charts
Welcome to our next module!
In this module, we'll take our analysis to the next level by displaying data. This is the first step towards using charts and graphs to display quantifiable results from our visualizations. Together, we'll go over an example of displaying two different bands in a time series using a scatterplot. We'll also learn about reducers, which are tools that enable us to summarize large amounts of data for a region or timeframe, making it easier to digest our results.
.
“We go together
Like rama lama lama ka dinga da dinga dong”
Making visualizations
So, you know how to create visualizations and layers in the map, but how do we display the pixel values of the image in a readable, interpretable way?
The GEE developers have put together some great guides. Some of them (here) actually go over creating charts, which is exactly what we want to do!
Example: Scatter plots
Dig around the guides in the link above to find the plotting tool that will best suit your needs. Let’s go over one of the examples here for scatter plots, because scatter plots are generally useful for visualizing discrete data points.
// Import the example feature collection and subset the forest feature. var forest = ee.FeatureCollection('projects/google/charts_feature_example') .filter(ee.Filter.eq('label', 'Forest')); Map.addLayer(forest) // Load MODIS vegetation indices data and subset a decade of images. var vegIndices = ee.ImageCollection('MODIS/006/MOD13A1') .filter(ee.Filter.date('2010-01-01', '2020-01-01')) .select(['NDVI', 'EVI']);
The above code simply imports a region of interest into the variable ‘forest’. We add this region to the map using Map.addLayer so we can visualize the area we are analyzing. Then, we load a MODIS dataset into the variable ‘vegIndices’ and filter it by date and band. The NDVI band is a vegetation index which gives information on vegetation density and health. EVI is the enhanced vegetation index which is more sensitive and removes things like smoke and thin clouds from the data. Let’s use the code below to display pixel values for each index in a chart for comparison.
// Define the chart and print it to the console. var chart = ui.Chart.image .series({ imageCollection: vegIndices, region: forest, reducer: ee.Reducer.mean(), scale: 500, xProperty: 'system:time_start' }) .setSeriesNames(['EVI', 'NDVI']) .setOptions({ title: 'Average Vegetation Index Value by Date for Forest', hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}}, vAxis: { title: 'Vegetation index (x1e4)', titleTextStyle: {italic: false, bold: true} }, lineWidth: 5, colors: ['e37d05', '1d6b99'], curveType: 'function' }); print(chart);
Now this looks like a lot of code just for a chart, but it’s mostly just formatting! We start by creating a variable called chart and use the ui.Chart.image.series function. This particular ui.Chart function is useful for image collections and time series.
For our inputs, we specify the image collection we want to display as vegIndices. The region we want to chart is our region of interest (the variable ‘forest’). We then take the average of the band values using the mean Reducer
(Note: a reducer is a method that is used to aggregate data over a certain area or time period. A reducer is applied to an image collection or a single image to produce a single output value, such as a mean, median, maximum, minimum, or standard deviation, for each band or band combination of the image. Reducers are used to summarize and extract information from large datasets. See the Docs tab on the left pane of the GEE code editor for more reducer types).
The rest is formatting: Series names, title, x and y axis titles, etc. Just like you would see in MATLAB or Python.
Finally, we print the chart to the Console using the print function.
Recap
Here’s what we learned in this training:
We worked so hard to visualize satellite data in many different ways. Now we make use of charts to display quantifiable results from our visualizations.
The GEE devs have put together guides for every type of chart in GEE. Together, we went over an example of displaying two different bands in a time series using a scatter plot chart.
New code elements:
ui.chart is a family of functions used to create charts of many different types.
Reducers are tools that enable us to summarize large amounts of data for a region or timeframe, so we can easily digest results.