I am trying to calculate NVDI Z-score from monthly mean and std NVDI, for the time series, but it showing this error:
"Image (Error) Parameter 'delta' is required."
My code link: https://code.earthengine.google.com/35292e8ec6c157eb19250fbd65863336
Below is the code:
// Import country borders
var countries = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017');
// Get Feature for Golivia
var my_aoi = countries.filter(ee.Filter.eq('country_na', 'Germany'));
Map.addLayer(my_aoi, {}, 'my_aoi');
// Zoom to Germany
Map.centerObject(my_aoi);
// Define roi for plotting original and z-score values
var my_roi = ee.Geometry.Rectangle([[10.457, 49.916], [10.534, 49.956]]);
Map.addLayer(my_roi, {}, 'my_roi');
// IMAGE COLLECTION
var imagecollection = ee.ImageCollection('COPERNICUS/S2_SR');
var S2 = imagecollection
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 10)
.filterBounds(my_roi);
// Vegetation and Soil pixels
function fieldpixel(image){
var scl = image.select('SCL');
var veg = scl.eq(4);
var soil = scl.eq(4);
var mask = (veg.neq(1).or (soil.neq(1)));
return image.updateMask(mask);
}
// Filter applied
var S2 = S2.map(fieldpixel);
// FUnction to mask clouds
function maskS2clouds (image) {
var qa = image.select ('QA60');
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
.and(qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask);
}
// Define the time period
var startDate = '2017-01-01';
var endDate = '2022-12-31';
// Function to calculate NDVI using normalizedDifference
var addNDVI = function(image) {
var ndvi = image.normalizedDifference(['B8', 'B4']).rename('NDVI');
return image.addBands(ndvi);
};
// Apply the addNDVI function to your Sentinel-2 image collection
var S2_with_NDVI = S2.filterDate(startDate, endDate).map(addNDVI);
// Create a sequence of dates for monthly aggregation
var sequence = ee.List.sequence(1, 72); // 1 to 72 months (6 years)
// Calculate monthly NDVI
var monthlyNDVI = ee.ImageCollection.fromImages(sequence.map(function (i) {
var start = ee.Date(startDate).advance(i - 1, 'month');
var end = ee.Date(startDate).advance(i, 'month');
var monthlyImage = S2_with_NDVI.filterDate(start, end).mean();
var yearMonth = start.format('YYYY-MM');
return monthlyImage.set('system:time_start', start.millis()).set('date', yearMonth);
}));
// Calculate monthly mean NDVI
var monthlyMeanNDVI = monthlyNDVI.select('NDVI').mean();
// Calculate monthly standard deviation of NDVI
var monthlyStdNDVI = monthlyNDVI.select('NDVI').reduce(ee.Reducer.stdDev());
// Calculate Z-scores (standardized NDVI) for each month
var zScoreCollection = monthlyNDVI.map(function(image) {
var ndvi = image.select('NDVI');
var mean = monthlyMeanNDVI.select('NDVI');
var stdDev = monthlyStdNDVI.select('NDVI');
var zScore = ndvi.subtract(mean).divide(stdDev).rename('NDVI_ZScore');
return zScore.set('system:time_start', image.get('system:time_start'))
.set('date', image.get('date'));
});
// Print the resulting ImageCollections
print("Monthly Mean NDVI", monthlyMeanNDVI);
print("Monthly StdDev NDVI", monthlyStdNDVI);
print("Monthly Z-Scores", zScoreCollection);
Stand58
asset, but I notice an error on line 69 of the linked script:var start = ee.Date(startDate).advance(i - 1, 'month');
.i
is anee.Number
, so you should useee.Number(i).subtract(1)
instead ofi - 1
.