suredream
12/7/2016 - 12:33 AM

array image collection oper

array image collection oper

var check_season_crop = function(arr, threshold) {
  
  var avg = arr.arrayReduce('mean',[0]).arrayGet([0,0])
  var tot = arr.arrayReduce('mean',[1]).arrayGet([0,0])

  return ee.Image.cat(
    avg.rename('avg'),
    tot.rename('tot')
  )
}

var collection = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2015-12-01', '2016-12-31')
.map(function(img) {
  // Opaque and cirrus cloud masks cause bits 10 and 11 in QA60 to be set,
  // so values less than 1024 are cloud-free
  var mask = ee.Image(0).where(img.select('QA60').gte(1024), 1).not();
  img = img.select(['B4','B8'], ['red', 'nir']).normalizedDifference(['nir', 'red']).multiply(1e4)  
           .addBands(ee.Date(img.get('system:time_start')).getRelative('day', 'year')).short()
  return img.updateMask(mask);
})

// Map.addLayer(collection, {}, '', 0)
// var arrNDVI = collection.toArray()//.toArray(1)
// // print(arrNDVI.arrayLength(0))
// var ret = check_season_crop(arrNDVI)
// Map.addLayer(ret)


var foo = function(arr, threshold){
     var mask = arr.eq(threshold).arrayReduce(ee.Reducer.max(), [0]).arrayGet([0,0])
     // actually I want to do some stuff right here, which I've tested with actual array.
     return mask.rename('mask')
}

var image = ee.Image(5000).toArray()
// var collection = ee.ImageCollection('timeseries').toArray()
var ret = foo(collection.toArray(), image)
Map.addLayer(ret, {}, '', 0)