1

I'm trying to download a Sentinel-2 OSAVI time-series from GEE. My workflow is as follows:

// Load Sentinel-2 ImageCollection
var s2RawData = ee.ImageCollection("COPERNICUS/S2_SR")
                  .filterDate('2018-09-01', '2018-09-10')
                  .filterBounds(geometry);

// Generate 'clear_sky' Sentinel-2 images using SCL.
var s2ClearSky = function(image) {
  var scl = image.select('SCL');
  var clearSkyPixels = scl.eq(4).or(scl.eq(5)).or(scl.eq(6)).or(scl.eq(11));
  return image.updateMask(clearSkyPixels);
  };
var s2Data = s2RawData.map(s2ClearSky);

// Compute OSAVI.
var addSpectralIndices = function(image){
  // Sentinel-2 bands
  var s2Bands = 
  {'BLUE': image.select('B2').divide(10000),
   'GREEN': image.select('B3').divide(10000),
   'RED': image.select('B4').divide(10000),
   'NIR': image.select('B8').divide(10000),
   'SWIR1': image.select('B11').divide(10000),
   'SWIR2': image.select('B12').divide(10000)};
  // OSAVI equation
  var osavi = image.expression('(NIR-RED)/(NIR+RED+0.16)*(1+0.16)', s2Bands).rename('OSAVI');
  // Add spectral index
  var newBands = ee.Image([osavi]);
  return image.addBands(newBands);
  };
var s2DataSi = s2Data.map(addSpectralIndices);

// Select OSAVI band
var s2DataIn = s2DataSi.select(['OSAVI']);

// Create Sentinel-2 stack
var s2DataCube = s2DataIn.toBands();
print(s2DataCube);

// Download stack to drive
Export.image.toDrive({
  image: s2DataCube,
  description: 'S2_OSAVI_TS_test2',
  region: geometry,
  fileFormat: 'GeoTIFF',
  scale: 10
});

However, when I open my image into ArcMap I get an empty image with NA values.

enter image description here

1 Answer 1

2

First, the code it's a little bit untidy (despite it works). For instance:

// Compute OSAVI.
var addSpectralIndices = function(image){
  // Sentinel-2 bands
  var s2Bands = 
  {'BLUE': image.select('B2').divide(10000),
   'GREEN': image.select('B3').divide(10000),
   'RED': image.select('B4').divide(10000),
   'NIR': image.select('B8').divide(10000),
   'SWIR1': image.select('B11').divide(10000),
   'SWIR2': image.select('B12').divide(10000)};
  // OSAVI equation
  var osavi = image.expression('(NIR-RED)/(NIR+RED+0.16)*(1+0.16)', s2Bands).rename('OSAVI');
  // Add spectral index
  var newBands = ee.Image([osavi]);
  return image.addBands(newBands);
  };
var s2DataSi = s2Data.map(addSpectralIndices);

And then you:

var s2DataIn = s2DataSi.select(['OSAVI']);

So, if you are adding 'OSAVI' as band and then you are selecting only that band, just don't add the band to the original scene and get the product directly:

// Compute OSAVI.
var getOSAVI = function(image){
  // Sentinel-2 bands
  var s2Bands = 
  {'RED': image.select('B4').divide(10000),
   'NIR': image.select('B8').divide(10000)};
  // OSAVI equation
  return image.expression('(NIR-RED)/(NIR+RED+0.16)*(1+0.16)', s2Bands).rename('OSAVI');
  };
var s2DataSi = s2Data.map(getOSAVI);

Ok, now to the question. As I mentioned, the code works. The problem with the output is the date period. S2_SR product is not well populated prior 2019 (approximately). So you have two options for your date range: use TOA product or apply an atmospheric correction (there are some examples in the official site, or you can use SEN2COR downloading the product from ESA site).

For checking this, try the code with:

var s2RawData = ee.ImageCollection("COPERNICUS/S2_SR")
                  .filterDate('2020-09-01', '2020-09-10')
                  .filterBounds(geometry);

Your Answer

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

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