Hi,
First of all, really excited to see this code available as I can't get Sentinel BoA reflectance from the level 2 products in Sentinel_S2/SR for 2017 for my study site.
I'm getting the below error using the SIAC code, but probably more a problem with my code structure.
Error:
In users/marcyinfeng/utils:SIAC
Line 152: image.addBands is not a function
Can you advise please?
My code:
var site = table.geometry();
Map.centerObject(site);
Map.addLayer(site, {color: 'red'}, 'site');
var label = ee.String('Trangie');
// Map.addLayer(roi);
// Map.addLayer(pad)
// This field contains UNIX time in milliseconds.
var timeField = 'system:time_start';
var addVariables = function(image) {
// Compute time in fractional years since the epoch.
var date = ee.Date(image.get(timeField));
var years = date.difference(ee.Date('1970-01-01'), 'year');
// Return the image with the added bands.
return image
// Add a time band.
.addBands(ee.Image(years).rename('t').float())
// Add a constant band.
.addBands(ee.Image.constant(1))
};
//function for masking clouds
var maskClouds= function(img) {
var qa = img.select('QA60');
var mask = qa.bitwiseAnd(0x400).eq(0).and( // no clouds
qa.bitwiseAnd(0x800).eq(0)); // no cirrus
return img.updateMask(mask).resample('bicubic');
};
//call sentinel2 galery for t1: May 2020
var im_toa = ee.ImageCollection('COPERNICUS/S2').select(['B2','B3','B4', 'B5', 'B8', 'B7', 'B6','B9','B11','QA60'])
.filterBounds(site)
.filterDate('2017-05-30','2017-11-30')
.map(maskClouds);
var siac = require('users/marcyinfeng/utils:SIAC');
//var im = siac.get_sur(im_toa);
var im = im_toa.map(function(image){
return siac.get_sur(im_toa);
})
var Blue = im.select('B2');
var Green = im.select('B3');
var Red = im.select('B4');
var NIR = im.select('B8');
var REP1 = im.select('B5');
var REP2 = im.select('B6');
var REP3 = im.select('B7');
var SWIR = im.select('B11');
var max=17
//List Blue
var list=Blue.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export Blue
Export.image.toDrive({
image: image,
description: 'Blue_'+i.toString()+''+date,
fileNamePrefix: 'Blue'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}
//List Green
var list=Green.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export Blue
Export.image.toDrive({
image: image,
description: 'Green_'+i.toString()+''+date,
fileNamePrefix: 'Green'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}
//List Red
var list=Red.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export Blue
Export.image.toDrive({
image: image,
description: 'Red_'+i.toString()+''+date,
fileNamePrefix: 'Red'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}
//List REP1
var list=REP1.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export Blue
Export.image.toDrive({
image: image,
description: 'REP1_'+i.toString()+''+date,
fileNamePrefix: 'REP1'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}
//List REP2
var list=REP2.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export Blue
Export.image.toDrive({
image: image,
description: 'REP2_'+i.toString()+''+date,
fileNamePrefix: 'REP2'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}
//List REP3
var list=REP3.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export REP3
Export.image.toDrive({
image: image,
description: 'REP3_'+i.toString()+''+date,
fileNamePrefix: 'REP3'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}
//List NIR
var list=NIR.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export NIR
Export.image.toDrive({
image: image,
description: 'NIR_'+i.toString()+''+date,
fileNamePrefix: 'NIR'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}
//List SWIR
var list=SWIR.toList(150);
for (var i=0;i<max;i++){
var image=ee.Image(list.get(i));
//var image_toa=ee.Image(list.get(i));
//var image = siac.get_sur(image_toa);
var date = image.date().format('yyyy-MM-dd').getInfo();
// Export Blue
Export.image.toDrive({
image: image,
description: 'SWIR_'+i.toString()+''+date,
fileNamePrefix: 'SWIR'+i.toString()+'_'+date,
scale: 20,
region:site,
crs : 'EPSG:3857'
});
}