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'
});