I'm getting the error 'subtract is not a function', when I try to substract two images from each other, and eventually get the difference in the NDVI. Both images have an NDVI band with an NDVI value. My input are images, not image collections (which would trigger this error). My code looks like this:
// Mosaic the Imagecollection and clip it to the AOI
var S2_pre_mosaic = S2_pre.mosaic().clip(geometry).copyProperties(S2_pre);
print(S2_pre_mosaic, 'S2_pre_mosaic')
var S2_post_mosaic = S2_post.mosaic().clip(geometry).copyProperties(S2_post);
print(S2_post_mosaic, 'S2_post_mosaic');
// Create a Difference Image from both Images
var diff_img = S2_pre_mosaic.subtract(S2_post_mosaic);
print(diff_img, 'diff_img');
I've noticed that if I exclude the 'copyProperties' argument earlier in the code, then the subtract function works - I honestly don't understand why though.
The problem is that later, I want to plot the results using diff_img as the imageCollection, and if ImageProperties are missing, then I get this error:
var dndvi = ui.Chart.image.series(
diff_img.select('nd'),
geometry,
ee.Reducer.mean(),
20)
.setOptions({
title: 'dNDVI',
hAxis: {title: 'Date', titleTextStyle: {italic: false, bold: true}},
vAxis: {title: 'NDVI',titleTextStyle: {italic: false, bold: true}},
});
print(dndvi)
Error: "system:time_start"
Any ideas how to solve the above?