1

I want to use the LandTrendr (LT) functions in GEE and adjust them to my needs. Basically, I want to the a similar thing that this earthengine.app is doing (only NBR for a start).

I can run the analysis, compute the values. But I cannot figure out how to produce the figure.

// load the LandTrendr.js module
var ltgee = require('users/emaprlab/public:Modules/LandTrendr.js');

// define parameters
var startYear = 1985;
var endYear = 2017;
var startDay = '06-20';
var endDay = '09-20';
var aoi = ee.Geometry.Point(-122.8848, 43.7929);
var index = 'NBR';
var ftvList = ["NBR"];
var runParams = { 
  maxSegments:            6,
  spikeThreshold:         0.9,
  vertexCountOvershoot:   3,
  preventOneYearRecovery: true,
  recoveryThreshold:      0.25,
  pvalThreshold:          0.05,
  bestModelProportion:    0.75,
  minObservationsNeeded:  6
};


// apply LandTrendr.js functions
var lt = ltgee.runLT(startYear, endYear, startDay, endDay, aoi, index, ftvList, runParams);
print(lt);

This should result in an array 4 x nYears dimension array. With years in (0,0,1) and calculated values in rows 2 to 4.

Now, how to plot row 2 over years. And if I create a buffer around the aoi, do I get the values for the other pixels too?

1 Answer 1

1

If you want the chart the original data, you cannot use the ltgee.runLT() convenience method. Though you can still use the library to build your time-series, and extract the fitted values. Then it's a matter of massaging the data so you can chart it.

// load the LandTrendr.js module
var ltgee = require('users/emaprlab/public:Modules/LandTrendr.js');

// define parameters
var startYear = 1985;
var endYear = 2017;
var startDay = '06-20';
var endDay = '09-20';
var aoi = ee.Geometry.Point(-122.8848, 43.7929);
var index = 'NBR';
var ftvList = ["NBR"];
var maskThese = ['cloud', 'shadow', 'snow']

var collection = ltgee.buildSRcollection(startYear, endYear, startDay, endDay, aoi, maskThese)
var timeSeries = ltgee.buildLTcollection(collection, index, ftvList)
var lt = ee.Algorithms.TemporalSegmentation.LandTrendr({ 
  timeSeries:             timeSeries,
  maxSegments:            6,
  spikeThreshold:         0.9,
  vertexCountOvershoot:   3,
  preventOneYearRecovery: true,
  recoveryThreshold:      0.25,
  pvalThreshold:          0.05,
  bestModelProportion:    0.75,
  minObservationsNeeded:  6
})
var fittedImage = ltgee.getFittedData(lt, startYear, endYear, index)
var fittedCollection = ee.ImageCollection(fittedImage.bandNames()
  .map(function (yearString) {
    yearString = ee.String(yearString)
    return fittedImage.select(yearString)
      .set('system:time_start', ee.Date.parse('yyyy', yearString).millis())
      .rename('Fitted')
  })
)

var chart = ui.Chart.image.series({
    imageCollection: fittedCollection.merge(
      timeSeries.map(function (image) { return image.select([1], ['Original']) })
    ), 
    region: aoi, 
    reducer: ee.Reducer.median(), 
    scale: 30
  })

print(chart)

https://code.earthengine.google.com/27a73e0df57e28d3dc1ae4190f5eb52b

Now, how to plot row 2 over years. And if I create a buffer around the aoi, do I get the values for the other pixels too?

You control which value you get with region and reducer in the chart.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.