Closed gltyree closed 2 years ago
hi @gltyree, sorry, but in R, u have to use ee_utils_pyfunc when u work with ee.List objects. There are other headaches. Please see the next link: https://r-spatial.github.io/rgee/articles/rgee02.html#the-map-message-error to get more information. Let us know if the problem persists.
Hi all,
I want to reduce a daily dataset to monthly averages in rgee. The approach for doing this in GEE and the GEE Python API has been to set a list of months (1...n), then define a function using filter(ee.Filter.calendarRange() to map over the list to retrieve monthly images of the reduced variable. Here is an example of that approach (https://gis.stackexchange.com/questions/258344/reduce-image-collection-to-get-annual-monthly-sum-precipitation):
var modis = ee.ImageCollection('MODIS/MOD13A1');
var months = ee.List.sequence(1, 12);
// Group by month, and then reduce within groups by mean(); // the result is an ImageCollection with one image for each // month. var byMonth = ee.ImageCollection.fromImages( months.map(function (m) { return modis.filter(ee.Filter.calendarRange(m, m, 'month')) .select(1).mean() .set('month', m); })); print(byMonth);
Map.addLayer(ee.Image(byMonth.first()));
I adapted that code for rgee as the following:
modisx = ee$ImageCollection('MODIS/MOD13A1')
months = ee$List$sequence(1, 12)
toMonthly <- function(m) { img = modisx$filter(ee$Filter$calendarRange(m, m, 'month'))$ select(1)$mean()$ set('month', m) return (img) }
byMonth = modisx$fromImages(months$map(toMonthly))
However, I received this error after running the 'byMonth' line:
Error in py_call_impl(callable, dots$args, dots$keywords) : RuntimeError: Evaluation error: argument "m" is missing, with no default.
Why does this snippet work in GEE but not in rgee? Is there another way to reduce daily values over a series of months that is more appropriate for rgee?