0

I am using CHIRPS data set (daily precipitation) to derive mean, median, min and max precipitation within a certain time frame. Then, I want to extract the values at specific locations included in a point shapefile and save the results in a table. The script seem to work but the output table only has zeros (0) as values for the 4 variables. Please see the script below

var lng = 65.64; 
var lat = 34.35;
var point = ee.Geometry.Point(lat, lng); 
//var aoi = point.buffer(100000); // Create an area (1km buffer around point)
var country = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
.filter(ee.Filter.eq('country_co', 'AF'));
var aoi = country;

Map.setCenter(lng, lat, 5); // Center the map on this location, zoom level 10

var start = '2018-02-15'; // initial date of the image collection
var end = '2018-07-15'; //final date of the image collection

var p1 = ee.Geometry.Point([69.78086, 34.65411])
var p2 = ee.Geometry.Point([61.82234, 30.66048])
var table = ee.FeatureCollection(ee.List([ee.Feature(p1),ee.Feature(p2)]))

var AddPrMean = function(image) {
  var PrMean = image.reduce(ee.Reducer.mean()).rename('PrMean');
  return image.addBands(PrMean);
};

var AddPrMedian = function(image) {
  var PrMedian = image.reduce(ee.Reducer.median()).rename('PrMedian');
  return image.addBands(PrMedian);
};

var AddPrMin = function(image) {
  var PrMin = image.reduce(ee.Reducer.min()).rename('PrMin');
  return image.addBands(PrMin);
};

var AddPrMax = function(image) {
  var PrMax = image.reduce(ee.Reducer.max()).rename('PrMax');
  return image.addBands(PrMax);
};

var dataset = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
    .filterDate(start, end)
    .filterBounds(aoi)
    .map(AddPrMean)
    .map(AddPrMedian)
    .map(AddPrMin)
    .map(AddPrMax);
    
var composites = dataset.select(['PrMean','PrMedian','PrMin','PrMax']).first();   

var YieldLocations = ee.FeatureCollection(table);

var YPrec = composites.reduceRegions(YieldLocations, ee.Reducer.max(), 1);

print(YPrec); ``` 
Lollo
  • 119
  • 3

1 Answers1

1

I found a solution that seems to work, however, the median always gives 0 as result.

var lat = 34.35;
var point = ee.Geometry.Point(lat, lng); 
//var aoi = point.buffer(100000); // Create an area (1km buffer around point)
var country = ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')
.filter(ee.Filter.eq('country_co', 'AF'));
var aoi = country;

Map.setCenter(lng, lat, 5); // Center the map on this location, zoom level 10

var start = '2018-02-15'; // initial date of the image collection
var end = '2018-07-15'; //final date of the image collection

var p1 = ee.Geometry.Point([69.78086, 34.65411])
var p2 = ee.Geometry.Point([61.82234, 30.66048])
var table = ee.FeatureCollection(ee.List([ee.Feature(p1),ee.Feature(p2)]))

var dataset = ee.ImageCollection('UCSB-CHG/CHIRPS/DAILY')
    .filterDate(start, end)
    .filterBounds(aoi);
    
var PrMean = dataset.mean().rename('PrMean');

var PrMedian = dataset.median().rename('PrMedian');

var PrMin = dataset.min().rename('PrMin');

var PrMax = dataset.max().rename('PrMax');

var composites = PrMean
      .addBands(PrMedian)
      .addBands(PrMin)
      .addBands(PrMax);
  



var YieldLocations = ee.FeatureCollection(table);

var YPrec = composites.reduceRegions(YieldLocations, ee.Reducer.max(), 1);

print(YPrec);```
Lollo
  • 119
  • 3