javascriptgoogle-earth-engine

Google Earth Engine - IDW: mean and stdDev are null values


I'm trying to perform an interpolation using IDW method. But i'm getting mean and stdDev as null values.

I'm trying to make the interpolation of rainfall data acquired on Chirps Data, and after a i need to perform idw to interpolate data.

var bahia = ee.FeatureCollection("projects/ee-username/assets/BA_Municipios_2022");

var cairu = bahia.filter(ee.Filter.eq('NM_MUN','Cairu'));

Map.addLayer(cairu, {color: '#9F0D7F', opacity: 0.5}, 'Cairu');
Map.centerObject(cairu, 10);


// Coleção Chirps
var chirps = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
               .filterBounds(cairu)
               .filter(ee.Filter.date('2006-01-01', '2006-12-31'));

//acumulando os dados de precipitação por pixel
var precipitation = chirps.select('precipitation')
                          .sum()
                          .clip(cairu).rename('precipitation');
                          
// definindo valores de visualização

var precipitationVis = {
  min: 544.5530428535374,
  max: 2954.394200325012,
  palette: ['red', 'orange', '#b3f8ff', 'cyan', 'blue'] 
};

Map.addLayer(precipitation, precipitationVis, 'Precipitation');

var samples = precipitation.addBands(ee.Image.pixelLonLat())
                           .sample({
                             region: cairu,
                             scale: 5566,
                             numPixels: 16, projection: 'EPSG:4326'}).map(function(sample){
                                var lat = sample.get('latitude');
                                var lon = sample.get('longitude');
                                var prec = sample.get('precipitation');
                                return ee.Feature(ee.Geometry.Point([lon, lat]), {prec: prec});
                            });
                            
var samples = ee.FeatureCollection(samples);
print(samples);

// combinando media e desvio padrao para eficiencia
var combinedReducer = ee.Reducer.mean().combine({
  reducer2: ee.Reducer.stdDev(),
  sharedInputs: true});

// Estima media global e desvio padrao dos pontos
var stats = samples.reduceColumns({
  reducer: combinedReducer,
  selectors: ['precipitation']});

var stdDev = stats.get('stdDev');
print(stdDev);

var interpolated = samples.inverseDistance({
  range: 5e3,
  propertyName: 'precipitation',
  mean: stats.get('mean'),
  stdDev: stats.get('stdDev'),
  gamma: 0.3
});
 

Map.addLayer(interpolated, precipitationVis, 'Precipitação Anual Acumulada');

any ideas of why i'm getting null values?

I tried everything i read on google developer's documentation.


Solution

  • You get null when there is not data to reduce. In your case it's because samples doesn't contain a precipitation column, but a prec column. This should work:

    var stats = samples.reduceColumns({
      reducer: combinedReducer,
      selectors: ['prec']});