3

Using monthly VIIRS data, I'm trying to estimate a weighted average of radiance where I want to weight by the number of cloud free days. Each image in the image collection has two bands: "avg_rad" and "cf_cvg." The below code calculates the average radiance in 2015; however, I'm wondering if there's a convenient way to calculate a weighted average, where "cf_cvg" is used as the weight.

var viirs = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG');
var viirs_2015 = ee.ImageCollection(
    viirs.filterDate("2015-01-01","2015-12-31")
);

var viirs_2015_mean = viirs_2015.reduce(ee.Reducer.mean()); 
var viirs_2015_mean_rad = viirs_2015_mean.select("avg_rad_mean")
2

Something like this maybe (reference):

var viirs = ee.ImageCollection('NOAA/VIIRS/DNB/MONTHLY_V1/VCMCFG');
var viirs_2015 = ee.ImageCollection(
    viirs.filterDate("2015-01-01","2015-12-31")
);

var viirs_2015_mean = viirs_2015.reduce(ee.Reducer.sum().splitWeights())
    .divide(viirs_2015.select('cf_cvg').reduce(ee.Reducer.sum())); 

Map.addLayer(viirs_2015_mean, {}, 'weighted')
Map.addLayer(viirs_2015.select('avg_rad').reduce('mean'), {}, 'unweighted')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.