0

I'd like to reduce all the conties' data histogram with a custom bin, but what I got is a auto bin histogram, it seems ee.Reducer.fixedHistogram() can help, but I don't know how to pass the parameters(min,max,steps) for all conties.

// load precip data (mm, daily total): 365 images per year

var precipCollection = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET')
                    .select('pr')   // select  precip band only
                    .filterDate('2017-01-01', '2017-12-31');
print(precipCollection, 'precipCollection');
// load precip data (mm, daily total): 365 images per year
var precipCollection = ee.ImageCollection('IDAHO_EPSCOR/GRIDMET')
                    .select('pr')   // select  precip band only
                    .filterDate('2017-01-01', '2017-12-31');
print(precipCollection);  

// reduce the image collection to one image by summing the 365 daily rasters

var annualPrecip = precipCollection.reduce(ee.Reducer.sum());
print(annualPrecip);
// equivalent shortcut syntax
var annualPrecip2 = precipCollection.sum();

// visualize annual precipitation
var precipPal = ['white','blue'] // store palette as variable               
Map.addLayer(annualPrecip, {min: 60, max: 3000, palette: precipPal}, 'precip');

// load regions: counties from a public fusion table, removing non-conus states // by using a custom filter

var nonCONUS = [2,15,60,66,69,72,78] // state FIPS codes that we don't want
var counties = ee.FeatureCollection('ft:1ZMnPbFshUI3qbk9XE0H7t1N5CjsEGyl8lZfWfVn4')
        .filter(ee.Filter.inList('STATEFP',nonCONUS).not());
print(counties, 'counties');

// visualize

Map.addLayer(counties,{},'counties');  
var steps = 128;

// get histogram precipitation values by county polygon(how to obtain custom bin histogram,such as 64/128/256 bins)

var countyPrecip = annualPrecip.reduceRegions({
  collection: counties,
  reducer: ee.Reducer.autoHistogram(),
  scale: 4000 // the resolution of the GRIDMET dataset
});


print(countyPrecip);
// drop .geo column (not needed if goal is tabular data)
var polyOut = countyPrecip.select(['.*'],null,false);
// add a new column for year to each feature in the feature collection
polyOut = polyOut.map(function(feature){
return feature.set('Year',2017);
});
// Table to Drive Export Example
Export.table.toDrive({
  collection: polyOut,
  description: 'GRIDMET_annual_precip_by_county',
  folder: 'GEE_geohackweek',
  fileFormat: 'CSV'
});  

1 Answer 1

0

You can specify the maximum number of bins for an autohistogram with the maxBuckets argument. Unless you have fewer values than that, you should get that many buckets.

1
  • Thanks for your answer. Yes, a maximum number of bins can be specified, but GEE can only return a histogram with bins less than the maximum number , however, what i want is a fixed bins histogram such as 32/64/128 . If I set the maximum number to 128, GEE maybe give me a result with 100 bins which is not equal to the expected num 128
    – Jsun
    Jan 20, 2019 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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