Geographic Information Systems Asked by sharsid94 on July 2, 2021
Given the monthly Modis Burned Area product, I am trying to get an annual sum for each year for multiple polygons. I wrote a function to map over each of the basins and then nest it within a function to iterate over years 2000 to 2020, but it doesn’t seem to be working. Any suggestions would be appreciated.
Link to script: https://code.earthengine.google.com/f6fb3d56eba7e5f6a40959bdc6072bf0
Link to assets:
https://code.earthengine.google.com/?asset=users/sharsid94/MAPBIOMAS/all_sheds_v2
// Script to calculate number of burned pixels over each basin
//reference script
//https://gis.stackexchange.com/questions/258344/reduce-image-collection-to-get-annual-monthly-sum-precipitation
// Set years and month
var startYear = 2001;
var endYear = 2020;
var years = ee.List.sequence(startYear, endYear);
// calculate basin areas
var areaCalc = function(feature) {
var area = feature.geometry().area().divide(1000 * 1000);
return feature.set('AREA', area)};
var area = ee.Number(basins.map(areaCalc));
// bring in MODIS BA data and filter by dates, layer, basin boundary
// what if we produce an image collection from multiple years?
var modis_collection = ee.ImageCollection('MODIS/006/MCD64A1')
.filterDate('2001-01-01', '2020-12-31')
.select(['BurnDate'])
.map(function(img) {return img.clip(basins)})
// calculate number of pixels in image for each basin
var reduceRegions = function(image) {
var countPixels = image.reduceRegions({
collection: basins,
reducer: ee.Reducer.count(),
scale: 500});
return countPixels
.filter(ee.Filter.notNull(['count']))
.map(function(feature) {
return feature.set({
'imgID': image.id(),
'date': image.date().format('YYYY-MM-dd')})})};
// make monthly summed mosaics
// loop over the years to get summed yearly images
var byYear = ee.FeatureCollection(years.map(function (y) {
var summedImage = modis_collection
.filter(ee.Filter.calendarRange(y, y, 'year'))
.map(reduceRegions)
return summedImage
})).flatten();
print(byYear);
// calculate area and set geometry to NULL for cleaner table
var myproperties=function(feature){
var area = feature.geometry().area().divide(1000 * 1000);
feature=ee.Feature(feature).setGeometry(null);
return feature.set('AREA', area);
};
var results = byYear.map(myproperties);
// export and visualize final results
Export.table.toDrive({
collection: results,
description: 'MODIS_ann_cumulative_BA',
folder: 'earthengine',
fileNamePrefix: 'MODIS_ann_cumulative_BA',
fileFormat: 'CSV'})
** Update: the function works, but still on the monthly basis, how can I get yearly sums?
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP