2

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 seems to work but the output for the median returns zeros (0) as value. Please see the script below

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);```
0

1 Answer 1

2

It looks like your code is working as expected. Try adding the following chart to the bottom of your script:

var chart = ui.Chart.image.seriesByRegion({
    imageCollection: dataset,
    regions: YieldLocations,
    reducer: ee.Reducer.mean()
    }).setOptions({
      interpolateNulls: true,
      lineWidth: 1,
      pointSize: 3,
      title: 'Precip over Time',
      colors: ["ff0000","0000ff"],
      vAxis: {title: 'Precip'},
      hAxis: {title: 'Date', format: 'YYYY-MMM', gridlines: {count: 12}}
    });
print(chart);

You will see that the majority of your precipitation data for both points falls on 0. Because more than half of the values are 0, the median is 0 (for example, in the series 0,0,0,0,0,0,1,3,5,8 the mean is 1.7 but the median is 0).

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.