4 Running LT-GEE
LT-GEE is run using the function: ee.Algorithms.TemporalSegmentation.LandTrendr
which takes a dictionary of parameter arguments as input.
In its most most basic form, running LandTrendr in Google Earth Engine requires 6 steps. The following code snippets help illustrate the steps.
The following snippets are only a demonstration aid. In application, use the provided code examples to learn and build from, and take advantage of the API functions we’ve put together to build collections and run LandTrendr
- Define starting and ending years of the times series
- Define an area to run LandTrendr on as an
ee.Geometry
var coords = [[-123.925, 42.996],
[-122.327, 42.996],
[-122.327, 43.548],
[-123.925, 43.548],
[-123.925, 42.996]];
var aoi = ee.Geometry.Polygon(coords);
- Define the LandTrendr run parameters as a dictionary. See the parameters section for definitions. Note that the image collection will be appended to this dictionary in a later step.
var run_params = {
maxSegments: 6,
spikeThreshold: 0.9,
vertexCountOvershoot: 3,
preventOneYearRecovery: true,
recoveryThreshold: 0.25,
pvalThreshold: 0.05,
bestModelProportion: 0.75,
minObservationsNeeded: 6
};
- Build an image collection that includes only one image per year, subset to a single band or index (you can include other bands - the first will be segmented, the others will be fit to the vertices). Note that we are using a mock function to reduce annual image collections to a single image - this can be accomplished many ways using various best-pixel-compositing methods.
for(var year = startYear; year <= endYear; year++) {
var img = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
.filterBounds(aoi)
.filterDate(year+'-06-15', year+'-09-15');
img = reduceToSingeImageMockFunction(img);
var tempCollection = ee.ImageCollection(img.select(['B5']));
if(year == startYear) {
var srCollection = tempCollection;
} else {
srCollection = srCollection.merge(tempCollection);
}
};
- Append the image collection to the LandTrendr run parameter dictionary
- Run the LandTrendr algorithm
Please note that for the sake of a basic example LT-GEE run, we are not addressing the two really important steps in collection building: 1) to mask cloud and cloud shadow pixels during annual image compositing (step 4) and 2) to ensure that the spectral band or index that is to be segmented is oriented so that vegetation loss is represented by a positive delta (we used a SWIR band, which is the correct orientation for use in LT-GEE).