1

Need as final product a table with monthly precipitation mean for all brazlian municipalities in the year of 2006. I did this code, which I think it calculated this, but there's no date reference in feature properties, so I don't know of which month is the data.

Can someone help me?

Code link: https://code.earthengine.google.com/f9dc0699062630a105032cbff1c10413

Script:

var mun = ee.FeatureCollection("users/rodrigoccuri/BRMUE250GC_SIR");
var chirps = ee.ImageCollection("UCSB-CHG/CHIRPS/DAILY");


var monthlyPrecip = ee.FeatureCollection([]);

var monthly = chirps
        .filter(ee.Filter.calendarRange(2006, 2006, 'year'))
        .filter(ee.Filter.calendarRange(1, 12, 'month'))
        .sum();

var mun_month=monthly.reduceRegions(mun, ee.Reducer.mean(), 1000);
monthlyPrecip=monthlyPrecip.merge(mun_month);

print(monthlyPrecip.first());


Export.table.toDrive(monthlyPrecip, 'precipbymun2', 'munprecip', 'MunPrecipitation');
0

Doesn't mun_month already provide you with the answer when you export it?

// set start and end year
var start = 1;
var end = 12;



// make a list with years
var month = ee.List.sequence(start, end);

var monthlyPrecip = ee.FeatureCollection([]);

var monthly = chirps
        .filter(ee.Filter.calendarRange(2006, 2006, 'year'))
        .filter(ee.Filter.calendarRange(1, 12, 'month'))
        .sum();
print(monthly)

var mun_month=ee.FeatureCollection(monthly.reduceRegions(mun, ee.Reducer.mean(), 1000));
print(mun_month.limit(10))

If you want to have it for each month in each year (time series) you'l have to put the collection filters and reduce region in a mapped function..

  • Thanks for the answer! I adapted the code to run for each month for each municipality. But idk why in the final result features are still without a property of month (I introduce in the code set function for this). Do you know what ould be worg? – Rodrigo Curi Nov 28 '19 at 18:58
0

Thanks for the answer! I adapted the code to run for each month for each municipality. But idk why in the final result features are still without a property of month (I introduce in the code set function for this). Do you know what ould be wrong? Here's script:

// Filtering for year of reference:
var chirps06 = chirps.filterDate('2006-01-01', '2006-12-31');

// Set start and end year
var start = 1;
var end = 12;

// Make a list with years
var month = ee.List.sequence(start, end);

// Creating an empty Feature Collection:
var monthlyPrecip = ee.FeatureCollection([]);

// Creating a map function to run for every month:
var monthlyPrecip = function(mon) {
  var chirps_mon=chirps06.
  filter(ee.Filter.calendarRange(mon, mon, 'month')).
  sum();
  var chirps_mean=chirps_mon.reduceRegions(mun, ee.Reducer.mean(),1000);
  return chirps_mean.set('month', mon);
}

// Mapping function to elements list (1:12):
var monthly = ee.FeatureCollection(month.map(monthlyPrecip)).flatten();

print(monthly.first());

//Export.table.toDrive(monthly, 'monthprecip06', 'Precipitation', 'monthprecip06');

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.