GEE影像集合ImageCollection中的統計計算
阿新 • • 發佈:2021-08-28
GEE影像集合ImageCollection中的統計計算
a. reduce(reducer,parallelScale)
- reducer:計算方法,如均值、最大值等
- parallelScale:縮放比例,為一個後臺優化引數,如果計算記憶體溢位可以設定2、4等
影像集合中的reduce主要是所有影像提取對應波段計算生成單景影像。此外,需要注意Earth Engine中的所有操作底層本質都是在操作畫素,這裡計算結果為逐畫素的結果。
案例:計算ImageCollection內的NDVI均值影像
var roi = /* color: #98ff00 */ee.Geometry.Polygon( [[[114.62959747314449, 33.357067677774594], [114.63097076416011, 33.32896028884253], [114.68315582275386, 33.33125510961763], [114.68178253173824, 33.359361757948754]]]); Map.centerObject(roi, 7); Map.setOptions("SATELLITE"); //set SATELLITE basemap var l8Col = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA") //Note:TOA!!! .filterBounds(roi) .filterDate("2018-1-1", "2019-1-1") .map(ee.Algorithms.Landsat.simpleCloudScore)//add cloud property .map(function(image) { //select cloud <= 20 return image.updateMask(image.select("cloud").lte(20)); }) .map(function(image) { // add NDVI band var ndvi = image.normalizedDifference(["B5", "B4"]).rename("NDVI"); return image.addBands(ndvi); }) .select("NDVI"); print(l8Col); var img = l8Col.reduce(ee.Reducer.mean(),4); // or var img = l8Col.mean(); print(img); Map.addLayer(roi, {color: "red"}, "roi");
由此程式碼也可以延伸開來,例如:
- 計算ImageCollection中的雲量少於xx%的影像數量結果進行匯出
- 計算ImageCollection中最大值或者最小值NDVI指數啥的作為分類的物候特徵指標
注意:這裡的.filterBounds(roi)出來的只是與roi相交的行列號影像
b. reduceColumns(reducer,selectors,weightSelectors)
- reducer:計算方法,如均值、最大值等
- selectors:屬性列表
- weightSelectors:屬性列表對應的權重資訊,通常預設
該方法用於統計屬性的基本資訊,例如統計影像結合所有的索引資訊,並且返回列表,
主要使用Reducer中的.toList()方法,將影像集合中每一個元素的屬性資訊聚合在一起以列表形式返回。
案例:提取影像集合中所有影像ID的列表
var roi = /* color: #98ff00 */ee.Geometry.Polygon( [[[114.62959747314449, 33.357067677774594], [114.63097076416011, 33.32896028884253], [114.68315582275386, 33.33125510961763], [114.68178253173824, 33.359361757948754]]]); Map.centerObject(roi, 7); var l8Col = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA") .filterBounds(roi) .filterDate("2018-1-1", "2019-1-1") .map(ee.Algorithms.Landsat.simpleCloudScore) .map(function(image) { return image.updateMask(image.select("cloud").lte(20)); }); print(l8Col); // 需要將物件型別中的list取出 var indexs = l8Col.reduceColumns(ee.Reducer.toList(), ["system:index"]) .get("list"); print("indexs", indexs);