簡體   English   中英

使用谷歌地球引擎中的圖像集合計算歸一化差異

[英]Computing normalizeddifference using image collections in Google earth engine

我是 Google Earth Engine 的新手,所以這里是這樣的:我正在嘗試使用 MODIS 波段 1 和 11 來計算一種新型的歸一化差異。它們是 500m 和 1km 的空間分辨率,來自兩個不同的 MODIS Image Collections (sur_refl_b01來自 MOD09GA 的 500m 分辨率和 sur_refl_b11 來自 MODOCGA 的 1km 分辨率)。

我首先將 1km 數據重新采樣到 500m。 我可以正確顯示 sur_refl_b01 和重新采樣的 sur_refl_b11 數據。 然后我將兩個圖像集合合並為一個我稱之為“modis_combined”的圖像集合。它具有正確數量的波段,但沒有正確顯示。 Inspector 指出以下錯誤:“預期為同質圖像集合,但遇到帶不兼容波段的圖像:第一個圖像類型:2 個波段([sur_refl_b01, sur_refl_b01_1])。當前圖像類型:2 個波段([sur_refl_b11, sur_refl_b11_1]) . 圖像 ID:2_2_2001_02_28 某些樂隊可能需要明確的演員陣容。”

我收到此錯誤與調用我使用 normalizedDifference 的 cci 函數有關:

ImageCollection(錯誤)映射錯誤(ID=1_2001_03_01):Image.normalizedDifference:沒有名為“sur_refl_b11”的波段。 可用波段名稱:​​[sur_refl_b01]。

我猜當我合並樂隊名稱時沒有堅持的圖像集合。 如何標記合並后的 imageCollection 中的波段,以便 normalizedDifference 函數能夠識別它們? 或者發生了什么其他混亂?

    // Define a sample Region-of-Interest 
    var roi = ee.Geometry.Polygon(
            [[[-122.0, 45.0],
              [-122.1, 32.0],
              [-108.9, 32.0],
              [-108.9, 45.0]]]);
    
    // Load a collection of MODIS land surface reflectance data (500m)
    // Select band 1 (red)
    // Filter by a date range
    // Subset by the region of interest
    var modis_b01_500m = ee.ImageCollection('MODIS/006/MOD09GA')
                       .select(['sur_refl_b01'])
                       .filterDate('2001-02-28','2001-12-31')
                       .filterBounds(roi)
                       .map(function(image){return image.clip(roi)});
    
    //Check on the number of bands in the collection                   
    print('modis_b01_500m', modis_b01_500m);
    print('Number of images in modis_b01_500m:', modis_b01_500m.size());
    
    // Define a collection of MODIS ocean color reflectance data (1km)
    var modis_b11_1km = ee.ImageCollection('MODIS/006/MODOCGA')
                      .select(['sur_refl_b11'])
                      .filterDate('2001-02-28','2001-12-31')
                      .filterBounds(roi)
                      .map(function(image){return image.clip(roi)});
    
    //Check on the number of bands in this collection.
    print('modis_b11_1km', modis_b11_1km);
    print('Number of images in modis_b11_1km:', modis_b11_1km.size());
    
    //Resample the MODIS 1km collection to 500m spatial resolution
    var modis_b11_resampled = modis_b11_1km.map(function(image) {
      var modis_pro = image.projection();  
      var image_resampled = image.reproject(modis_pro, null, 500)
      .copyProperties(image);
      return image_resampled
    })

    //Check on the number of bands in this resampled collection.
    print('modis_b11_resampled',modis_b11_resampled);
    print('Number of images in modis_b11_resampled:', modis_b11_resampled.size());
    
    //combine the resampled collection with the modis 500m collection
    var modis_combined = modis_b01_500m.merge(modis_b11_resampled);

    //Check on the number of bands in this combined collection.
    print('modis_combined', modis_combined);
    print('Number of images in modis_combined:', modis_combined.size());
    
    //Display the MODIS combined image collection
    //Display the layers
    Map.addLayer(modis_b01_500m,{min:0,max:10000},'modis_b01_500m');
    Map.addLayer(modis_b11_1km,{min:0,max:2000},'modis_b11_1km');   
    Map.addLayer(modis_b11_resampled, {min:0, max:10000}, 'modis_resampled');
    Map.addLayer(modis_combined, {min:0, max:10000}, 'MODIS combined');
    
    var cci = modis_combined.map(function(image){
      var cci = image.normalizedDifference(['sur_refl_b11','sur_refl_b01']);
      return cci;
    })
    print('cci', cci);
    print('Number of images in cci:', cci.size());
          

在您的代碼中,您使用.merge()命令來組合兩個 ImageCollections。 兩個 ImageCollections 組合在一起,但來自兩個集合的圖像彼此保持獨立,因此無法執行需要來自兩個波段的圖像的.normalizedDifference函數。

您需要做的是根據日期加入兩個集合,以便將兩個集合中具有相同日期的圖像合並為一個具有 2 個波段的圖像。 這將允許您執行.normalizedDifference函數。 這是它的過程:

    // Define a sample Region-of-Interest 
    var roi = ee.Geometry.Polygon(
            [[[-122.0, 45.0],
              [-122.1, 32.0],
              [-108.9, 32.0],
              [-108.9, 45.0]]]);
    
    // Load a collection of MODIS land surface reflectance data (500m)
    // Select band 1 (red)
    // Filter by a date range
    // Subset by the region of interest
    var modis_b01_500m = ee.ImageCollection('MODIS/006/MOD09GA')
                       .select(['sur_refl_b01'])
                       .filterDate('2001-02-28','2001-12-31')
                       .filterBounds(roi)
                       .map(function(image){return image.clip(roi)});
    
    //Check on the number of bands in the collection                   
    print('modis_b01_500m', modis_b01_500m);
    print('Number of images in modis_b01_500m:', modis_b01_500m.size());
    
    // Define a collection of MODIS ocean color reflectance data (1km)
    var modis_b11_1km = ee.ImageCollection('MODIS/006/MODOCGA')
                      .select(['sur_refl_b11'])
                      .filterDate('2001-02-28','2001-12-31')
                      .filterBounds(roi)
                      .map(function(image){return image.clip(roi)});
    
    //Check on the number of bands in this collection.
    print('modis_b11_1km', modis_b11_1km);
    print('Number of images in modis_b11_1km:', modis_b11_1km.size());
    
    //Resample the MODIS 1km collection to 500m spatial resolution
    var modis_b11_resampled = modis_b11_1km.map(function(image) {
      var modis_pro = image.projection();  
      var image_resampled = image.reproject(modis_pro, null, 500)
      .copyProperties(image);
      return image_resampled
    })

    //Check on the number of bands in this resampled collection.
    print('modis_b11_resampled',modis_b11_resampled);
    print('Number of images in modis_b11_resampled:', modis_b11_resampled.size());
    
//combine the resampled collection with the modis 500m collection

// 1. Join datasets. First, define filter. This is based on the date.

var filter = ee.Filter.equals({
  leftField: 'system:time_start',
  rightField: 'system:time_start'
});

// 2. Create the join.
var innerJoin = ee.Join.inner('primary', 'secondary');

// 3. Apply the join.
var merge = innerJoin.apply(modis_b01_500m, modis_b11_resampled, filter)

// 4. Merge both collections.
var merged = merge.map(function(f){
  var b01 = ee.Image(f.get('primary')).rename('b01')
  var b11 = ee.Image(f.get('secondary')).rename('b11')
  return b01.addBands(b11).copyProperties(b01)
  })

print(merged, 'merged')

// 5. Add NormalizedDifference band
var normalizedBand = merged.map(function(image) {
  var normalize = ee.Image(image).normalizedDifference(["b01", "b11"]).rename("normalizedBand")
  return ee.Image(image).addBands(normalize).copyProperties(image)
  })

print(normalizedBand, 'normalized band added')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM