NDVI - Charts
Now that we have created a base dataset with added NDVI bands and calculated a Difference Image, we will have a look on how to plot charts and histograms to support our intention of monitoring the NDVI of our Area of Interest.
In case you get an error that the chart couldn't be generated, simply run the script again to fix it. This is also captured in the video.
Time Series and Day of Year Series
To create charts, we will want to work with ImageCollections, as this allows us to work with several reductions (mean, median, ...) of NDVI-values per day/month/year/...
Also, we will be able to look at simple charts of time series via the Inspector!
Let us start by preparing our pre- and post-event ImageCollections. We will use the same data as before, however we will not reduce it.
var pre_event_ic = ls8_ndvi
.filterDate('2014-01-01', '2014-12-31')
.select(['NDVI'],['NDVI_pre']); //This line allows us to select the band 'NDVI' and simultaneously rename it to 'NDVI_pre' in the new variable
print(pre_event_ic, 'Pre-Event ImageCollection 2014');
Map.addLayer(pre_event_ic, ndviParams, 'Pre-Event IC 2014', false);
var post_event_ic = ls8_ndvi
.filterDate('2020-01-01', '2020-12-31')
.select(['NDVI'],['NDVI_post']); //this line allows us to select the band 'NDVI' and simultaneously rename it to 'NDVI_post' in the new variable
print(post_event_ic, 'Post-Event ImageCollection 2020');
Map.addLayer(post_event_ic, ndviParams, 'Post-Event IC 2020', false);
//Add a time series chart of the mean NDVI values
// To keep processing times low and reduce the chance of producing errors, we are going to downsample our data to a spatial resolution of 200m via 'scale: 200'. Feel free to change this to 'Scale: 30' for smaller subsets to increase accuracy.
var chart_pre_event = ui.Chart.image.series({
imageCollection: pre_event_ic,
region: extent_aoi,
reducer: ee.Reducer.mean(),
scale: 200
})
.setOptions({
title: 'Mean NDVI Value by Months Pre Event',
hAxis: {title: 'Month', titleTextStyle: {italic: false, bold: true}},
vAxis: {title: 'NDVI',titleTextStyle: {italic: false, bold: true}},
});
print(chart_pre_event)
var chart_post_event = ui.Chart.image.series({
imageCollection: post_event_ic,
region: extent_aoi,
reducer: ee.Reducer.mean(),
scale: 200
})
.setOptions({
title: 'Mean NDVI Value by Months Post Event',
hAxis: {title: 'Month', titleTextStyle: {italic: false, bold: true}},
vAxis: {title: 'NDVI',titleTextStyle: {italic: false, bold: true}},
});
print(chart_post_event)
//We can also visualize the data in a different way by adding a day-of-year-chart of the mean NDVI values
var doychart_pre_event = ui.Chart.image
.doySeries({
imageCollection: pre_event_ic,
region: extent_aoi,
regionReducer: ee.Reducer.mean(),
scale: 200,
yearReducer: ee.Reducer.mean(),
startDay: 1,
endDay: 365
})
.setOptions({
title: 'Mean NDVI Value by Date Pre Event',
hAxis: {title: 'Day of year', titleTextStyle: {italic: false, bold: true}},
vAxis: {title: 'NDVI',titleTextStyle: {italic: false, bold: true}},
});
print(doychart_pre_event);
var doychart_post_event = ui.Chart.image
.doySeries({
imageCollection: post_event_ic,
region: extent_aoi,
regionReducer: ee.Reducer.mean(),
scale: 200,
yearReducer: ee.Reducer.mean(),
startDay: 1,
endDay: 365
})
.setOptions({
title: 'Mean NDVI Value by Date Post Event',
hAxis: {title: 'Day of year', titleTextStyle: {italic: false, bold: true}},
vAxis: {title: 'NDVI',titleTextStyle: {italic: false, bold: true}},
});
print(doychart_post_event);
Histograms
We can also prepare our data as histograms.This allows us to analyze the frequency of our NDVI values distribution. Histograms only work for Images. Luckily, we already created our pre- and post-event Images as well as a Difference Image a few steps ago.
var histogram_pre_event =
ui.Chart.image
.histogram({
image: pre_event,
region: extent_aoi,
scale: 200,
minBucketWidth: 0.1,
});
print(histogram_pre_event);
var histogram_post_event =
ui.Chart.image
.histogram({
image: post_event,
region: extent_aoi,
scale: 200,
minBucketWidth: 0.1, //define the width of a single bucket; in this example, each bucket shows a range of 0.1
});
print(histogram_post_event);
var histogram_diff_img =
ui.Chart.image
.histogram({
image: ndvi_diff,
region: extent_aoi,
scale: 200,
minBucketWidth: 0.1,
});
print(histogram_diff_img);
Check out the charts in the Console. Keep in mind that they are interactive, so you can hover the mouse over them to receive detailed information.