1

This code was working normally and now it's giving this error, does anyone know what changed?

https://code.earthengine.google.com/db01303623e6f1a4d0e417f1c3c0713e

The following errors appear:

print bands:
List (Error) reduce.median: Error in map(ID=20200526T144731_20200526T145503_T19LFJ):
Element.copyProperties: The source parameter is required.

RGB Lago Amapá: Layer error: reduce.median: Error in map(ID=20200526T144731_20200526T145503_T19LFJ):
Element.copyProperties: The source parameter is required.

pan-sharpened: Layer error: reduce.median: Error in map(ID=20200526T144731_20200526T145503_T19LFJ):
Element.copyProperties: The source parameter is required.

/////////STUDY SITE 

var inpe = ee.FeatureCollection("users/dfadeljunior/ucs_INPE_2020");
//print(inpe)
var LE = inpe.filterMetadata('NOME_UC1', 'equals', 'ÁREA DE PROTEÇÃO AMBIENTAL LAGO DO AMAPÁ')


/////////SENTINEL - 2 DATA

/******************************************ÍNDICES FENOLÓGICOS E DE ÁGUA*************************************/                       
function f_index_ (image) {
  var ndvi =  image.normalizedDifference(['B8','B4']).rename('NDVI');// Rouse 1973
  var evi = image.expression('2.5 * ((N - R) / (N + (6 * R) - (7.5 * B) + 1))', { //Huete 2002
        'N': image.select('B8'), 'R': image.select('B4'), 'B': image.select('B2')}).rename('EVI')
  var mndwi = image.normalizedDifference(['B3', 'B12']).rename('MNDWI'); // Xu 2005
  var ndwi = image.normalizedDifference(['B3', 'B8']).rename ('NDWI'); //Mc Feeters 1996
  return image.addBands([ndvi, evi, mndwi, ndwi])}

var inBands = ee.List(['QA60','B1','B2','B3','B4','B5','B6','B7','B8','B8A','B9','B11','B12']);
var outBands = ee.List(['QA60','cb','blue','green','red','re1','re2','re3','nir','re4','waterVapor','swir1','swir2']);
 
var CloudCoverMax = 1; //Vá alterando aqui até encontrar imagem adequada
var startDate = "2020-05-01";
var endDate = "2020-07-24";
var studyArea = LE;

// Get Sentinel-2 data
var s2 = ee.ImageCollection('COPERNICUS/S2_SR') //or COPERNICUS/S2
           .filterDate(startDate,endDate)
           .filterBounds(studyArea)
           .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',CloudCoverMax))
           .filter(ee.Filter.lt('CLOUD_COVERAGE_ASSESSMENT',CloudCoverMax))
           .map(f_index_);


// scale the data  (10 metros de resolução com 0,001 de escala  = 10000, portanto divide por 10000)
var scaleData = function scaleBands(img){
  var prop = img.toDictionary();
  var myImg = img.select(['B1','B2','B3','B4','B5','B6','B7','B8','B8A','B9','B11','B12']).divide(10000);
      myImg = myImg.addBands(img.select(['QA60'])).set(prop).copyProperties(img,['system:time_start','system:footprint']);
  return ee.Image(myImg);
};
var sentinel2 = s2.map(scaleData).select(inBands, outBands);


var s2VisParam = {"opacity":1,"bands":["red","green","blue"],"min":0.016,"max":0.175,"gamma":1.6};
Map.addLayer(sentinel2.median().clip(LE), s2VisParam, 'RGB Lago Amapá'); //10 m resolution - Natural Color

// Convert the RGB bands to the HSV color space.
var s2b = sentinel2.median().clip(LE)
var hsv = s2b.select(['red', 'green', 'blue']).rgbToHsv(); //'blue','green','red'
//print(hsv)
//Swap in the panchromatic band and convert back to RGB.
var sharpened = ee.Image.cat([
  hsv.select('hue'), hsv.select('saturation'), s2b.select('nir')
]).hsvToRgb();
// Display the pan-sharpened result.
Map.addLayer(sharpened,
             {min: 0.150, max: 0.355, gamma: [1.3, 1.3, 1.3]},
             'pan-sharpened');

1 Answer 1

0

I'm not sure what the specific issue it here, but in general, copyProperties can be avoided when you are scaling bands and wanting to retain the image's metadata by overwriting the original bands (set the overwrite parameter of ee.Image.addBands to true). Whenever possible, this is a better practice than copying properties. Your scaling function would be something like the following (untested).

var scaleData = function scaleBands(img){
  var refl = img.select('B.*').divide(10000);
  return img.addBands(refl, null, true).select('B.*|QA60');
};

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.