I built a function to add a a new band (b1_1) to each image of a image collection and I mapped it. It does seem to work, at least when printing the image collection and inspecting it in the console.
But when I trying to map on the "new collection" another function for charting the new band (b1_1) against some other pre-existing band, the new one doesn't exist anymore.
//mask and add delta DEM band
var add_band = function(image){
var glacier_img = image.select(['b1']);
var glacier_clip = glacier_img.clip(shp);
var dem_glacier = DEM_delta.clip(shp);
var vel_range = glacier_clip.lte(ee.Number(700)).and(glacier_clip.gte(ee.Number(-700)));
var dem_glacier_mask = dem_glacier.updateMask(vel_range);
var final_img = image.updateMask(vel_range).addBands(dem_glacier_mask);
return final_img;
};
//add a DEM band to each image of the images collection
var imgCollection = imgCollection.map(add_band);
print(imgCollection);
//chart
var graph = function(image){
var id = image.id;
var image = ee.Image(image.id);
//print(id);
var result = image.reduceRegion(ee.Reducer.toList(),shp, 200);
var y = ee.Array(result.get('b1'));
var x = ee.Array(result.get('b1_1'));
var chart = ui.Chart.array.values(y, 0, x)
.setSeriesNames(['b1'])
.setOptions({
title: 'Velocity vs. Delta_DEM ',
hAxis: {'title': 'Delta_DEM'},
vAxis: {'title': 'Velocity'},
pointSize: 3,
});
// Print the chart.
return print(chart);
};
imgCollection.evaluate(function(imgCollection) { // use map on client-side
imgCollection.features.map(graph);
});
add_band
function to the question – aldo_tapia Dec 20 '18 at 11:35image
variable defined somewhere above line 48, but you declaring another global variableimage
in line 70. This can't be a good idea. – Stefan Dec 20 '18 at 20:23.rename('L1_1')
or whatever after your.addBands()
argument. – JepsonNomad Dec 20 '18 at 20:31