0

I am trying to calculate NDVI trends over time using Landsat scenes and the earth engine code below:

var point = /* color: #d63000 */ee.Geometry.Point([-133.49, 69.18]);
var l5 = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
  .filter(ee.Filter.lt('CLOUD_COVER',10))
  .select(['B3', 'B4'])
  .filterBounds(point)
  .filter(ee.Filter.calendarRange(7,8,'month'));

//adds ndvi as band 'B4_1'
var ndvi = function(image) {
  var nir = image.select('B4');
  var red = image.select('B3');
  var ndvi = nir.subtract(red).divide(nir.add(red));
  var proimage = image.addBands(ndvi);
  return proimage;
};

var createTimeBand = function(image) {
  return     image.addBands(image.metadata('system:time_start').divide(3.154e10));
};

var stack = l5.map(ndvi).map(createTimeBand);

var linearFit = stack.select(['system:time_start','B4_1'])
.reduce(ee.Reducer.linearFit());

var linpar = {min: 0, max: [-0.01, 0.01, 5], bands: ['scale', 'scale',         'offset']};
Map.addLayer(linearFit, linpar,'fit');
Map.setCenter(-133.50, 69.19, 9);

However when I zoom in it seems the pixels are misaligned between scenes from different paths/rows.

pixels

I found this code to register an image to a reference, but is there some way to align the geometry of a large stack of images?

2

To directly answer your question, you can "align" the geometry of the pixels of multiple images by using ee.Image.reproject() and ee.Image.resample() and mapping those functions over images in the collection. However, be aware that this will potentially alter/smooth the information provided in each of the original images. (Your example is for a high latitude area, where the imagery is collected from multiple overlapping satellite orbits of a polar orbiting satellite. It is best to avoid smoothing out this valuable information.)

Alternatively, you could call ee.Image.reproject() and ee.Image.resample() on the linearFit image (i.e. after estimating the time series trend) to control the projection of the final result. This approach would reduce the amount of altering/smoothing, which I expect will be preferable for your time series analysis use case.

// Reproject using the CRS parameters of one of the original images.
var reprojected = linearFit.reproject({
  crs:'EPSG:32609', 
  crsTransform:[30,0,278985,0,-30,7849515], 
});
var resampled = reprojected.resample('bicubic');
Map.addLayer(reprojected, linpar, 'reprojected');
Map.addLayer(resampled, linpar, 'resampled');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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