open-geocomputing / OpenEarthEngineLibrary

https://www.open-geocomputing.org/OpenEarthEngineLibrary/
129 stars 39 forks source link

SavatskyGolayFilter #15

Closed zicai1 closed 1 year ago

zicai1 commented 1 year ago

Are there any specific requirements for collections in SavatskyGolayFilter? I have an imagecollection that works in SavatskyGolayFilter, but when I do some processing it can't run, my code is as follows:

var merge_vi = l8_vi.merge(s2_vi).sort('system:time_start')
var smooth_vi=oeel.ImageCollection.movingWindow(merge_vi,ee.Filter.maxDifference(1000*3600*24*25, 'system:time_start', null, 'system:time_start'))
                                  .select(['NDVI_mean','EVI_mean','NIRv_mean','kNDVI_mean'],['NDVI','EVI','NIRv','kNDVI']);
var size = merge_vi.size().getInfo()
var ori_list = merge_vi.toList(size)
var smooth_list = smooth_vi.toList(size)
var res_list = ee.List([])
for(var i=0;i<size;i++){
  var ori = ee.Image(ori_list.get(i))
  var smo = ee.Image(smooth_list.get(i))
  var res = ee.Image(ori.subtract(smo))
  res_list = res_list.add(res)
}
var vi_sd = ee.Image(ee.ImageCollection(res_list).reduce(ee.Reducer.stdDev()))
var sd_th = vi_sd.multiply(1.5).abs()
var mask_list = res_list.map(function(img){
  var img = ee.Image(img).abs();
  return img.lt(sd_th)
})
var vi_list = ee.List([])
for(var i=0;i<size;i++){
  var ori = ee.Image(ori_list.get(i))
  var smo = ee.Image(smooth_list.get(i))
  var mask = ee.Image(mask_list.get(i))
  var image = ori.updateMask(mask).unmask(smo)
  vi_list = vi_list.add(image)
}
var vi_col = ee.ImageCollection(vi_list)

merge_vi is a VI imagecollection,it can work in SavatskyGolayFilter,but the vi_col can’t work,even when i replace vi_list = vi_list.add(image) withvi_list = vi_list.add(ori),it still can't work

mgravey commented 1 year ago

idk how I can help you.

  1. please provide a link to the code
  2. if you use a for loop to do some processing, it means you didn't get how GEE is working. check this
  3. should never use .getInfo()
  4. Finally if the documentation it written that it require a ImageCollection, then a list is not working, you will need to use an ImageCollection
zicai1 commented 1 year ago

oh,thanks,i replace for with list.map(),it works,It seems that the imgcollection generated by the for loop cannot be used as an argument to the SavatskyGolayFilter parameter

mgravey commented 1 year ago

you should never use for-loops in GEE, but happy to hear that the problem is fixed