【问题标题】:How to reduce the spatial resolution of an image collection in Google Earth Engine?如何降低 Google Earth Engine 中图像集的空间分辨率?
【发布时间】:2021-02-23 12:23:41
【问题描述】:

美好的一天

请您协助我完成以下工作。

我正在尝试使用 Landsat 7 和 8 为特定感兴趣区域 (ROI) 生成 NDVI 估计的时间序列。然后,我想将这些估计值与从 MODIS 16 天 NDVI 复合数据中获得的 NDVI 值进行比较。虽然,我熟悉如何在 Landsat 空间分辨率(30 m)下获取我的 ROI 的平均 Landsat NDVI 值,但我想将此分辨率的像素聚合到 MODIS NDVI 产品分辨率(500 m)。

我已尝试根据https://developers.google.com/earth-engine/guides/resample 提供的示例在下面提供的代码中执行此操作,但我的尝试没有成功。我收到错误“ndvi.reduceResolution 不是函数”

我是否需要为此创建一个函数并将其映射到图像集合上,还是应该只指定在绘制图表或将数据导出为 csv 时执行平均的比例?

非常感谢。

///Add region of interest
var ROI = ROI
Map.addLayer(ROI, {}, 'ROI')
Map.centerObject(ROI, 10)

//Define time of interest
// Ensure that the first image that is collected possesses data to calculate NDVI otherwise the script will not work as required
var startdate = '2013-01-01' 
var enddate = '2021-01-01' 

var years = ee.List.sequence(ee.Date(startdate).get('year'), ee.Date(enddate).get('year'));

///Create functions to mask clouds
/// see: https://landsat.usgs.gov/sites/default/files/documents/landsat_QA_tools_userguide.pdf

///This function masks clouds in Landsat 7 imagery.
function maskL7(im) {
  var qa = im.select('BQA');
  var mask = qa.eq(672);
  return im.updateMask(mask).copyProperties(im);
}

///This function masks clouds in Landsat 8 imagery.
function maskL8(im) {
  var qa = im.select('BQA');
  var mask = qa.eq(2720);
  return im.updateMask(mask).copyProperties(im);
}

///Import image collections, filter by date and ROI, apply cloud mask and clip to ROI

///Landsat 7 Collection 1 Tier 1 calibrated top-of-atmosphere (TOA) reflectance
var ls7toa = ee.ImageCollection('LANDSAT/LE07/C01/T1_TOA')
  .filterBounds(ROI)
    .filterDate(startdate, enddate)
      .map(function(im) {return maskL7(im)})
        .map(function(image){return image.clip(ROI)})

///Landsat 8 Collection 1 Tier 1 calibrated top-of-atmosphere (TOA) reflectance
var ls8toa = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
.filterBounds(ROI)
  .filterDate(startdate, enddate)
    .map(function(im) {return maskL8(im)})
      .map(function(image){return image.clip(ROI)})

///Create function to calculate NDVI using Landsat data
    
///Calculate NDVI for Landsat 7
var ls7_ndvi = ls7toa.map(function(image) {
  var ndvi = image.normalizedDifference(['B4', 'B3']).rename('ndvi');
  return image.addBands(ndvi);
});

///Calculate NDVI for Landsat 8
var ls8_ndvi = ls8toa.map(function(image) {
  var ndvi = image.normalizedDifference(['B5', 'B4']).rename('ndvi');
  return image.addBands(ndvi);
});

///Merge the image collections into one and only select the NDVI data
var landsat = ee.ImageCollection(ls7_ndvi.merge(ls8_ndvi));
var ndvi = landsat.select(['ndvi'])
print(ndvi, 'ndvi')

// Load a MODIS NDVI Collection
var modis = ee.Image(ee.ImageCollection("MODIS/006/MOD13A1")
            .first()
              .select('NDVI'))
                    
// Get information about the MODIS projection.
var modisProjection = modis.projection();
print('MODIS projection:', modisProjection);

// Get the Landsat NDVI collection at MODIS scale and projection.
var ndviMean = ndvi
    // Force the next reprojection to aggregate instead of resampling.
    .reduceResolution({
      reducer: ee.Reducer.mean(),
    })
    // Request the data at the scale and projection of the MODIS image.
    .reproject({
      crs: modisProjection
    });
                    
///Create a timer-series plot of NDVI
var chart = ui.Chart.image.series({
    imageCollection: ndviMean,
    region: ROI,
    reducer: ee.Reducer.mean(),
    scale: 500,
})

print(chart, "ndvi") 

【问题讨论】:

    标签: resolution google-earth-engine landsat


    【解决方案1】:

    确实,在 ImageCollection 上映射一个函数就可以了:

    ///Add region of interest
    var ROI = ROI
    Map.addLayer(ROI, {}, 'ROI')
    Map.centerObject(ROI, 10)
    
    //Define time of interest
    // Ensure that the first image that is collected possesses data to calculate NDVI otherwise the script will not work as required
    var startdate = '2013-01-01' 
    var enddate = '2021-01-01' 
    
    var years = ee.List.sequence(ee.Date(startdate).get('year'), ee.Date(enddate).get('year'));
    
    ///Create functions to mask clouds
    /// see: https://landsat.usgs.gov/sites/default/files/documents/landsat_QA_tools_userguide.pdf
    
    ///This function masks clouds in Landsat 7 imagery.
    function maskL7(im) {
      var qa = im.select('BQA');
      var mask = qa.eq(672);
      return im.updateMask(mask).copyProperties(im);
    }
    
    ///This function masks clouds in Landsat 8 imagery.
    function maskL8(im) {
      var qa = im.select('BQA');
      var mask = qa.eq(2720);
      return im.updateMask(mask).copyProperties(im);
    }
    
    ///Import image collections, filter by date and ROI, apply cloud mask and clip to ROI
    
    ///Landsat 7 Collection 1 Tier 1 calibrated top-of-atmosphere (TOA) reflectance
    var ls7toa = ee.ImageCollection('LANDSAT/LE07/C01/T1_TOA')
      .filterBounds(ROI)
        .filterDate(startdate, enddate)
          .map(function(im) {return maskL7(im)})
            .map(function(image){return image.clip(ROI)})
    
    ///Landsat 8 Collection 1 Tier 1 calibrated top-of-atmosphere (TOA) reflectance
    var ls8toa = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
    .filterBounds(ROI)
      .filterDate(startdate, enddate)
        .map(function(im) {return maskL8(im)})
          .map(function(image){return image.clip(ROI)})
    
    ///Create function to calculate NDVI using Landsat data
        
    ///Calculate NDVI for Landsat 7
    var ls7_ndvi = ls7toa.map(function(image) {
      var ndvi = image.normalizedDifference(['B4', 'B3']).rename('ndvi');
      return image.addBands(ndvi);
    });
    
    ///Calculate NDVI for Landsat 8
    var ls8_ndvi = ls8toa.map(function(image) {
      var ndvi = image.normalizedDifference(['B5', 'B4']).rename('ndvi');
      return image.addBands(ndvi);
    });
    
    ///Merge the image collections into one and only select the NDVI data
    var landsat = ee.ImageCollection(ls7_ndvi.merge(ls8_ndvi));
    var ndvi = landsat.select(['ndvi'])
    print(ndvi, 'ndvi')
    
    // Load a MODIS NDVI Collection
    var modis = ee.Image(ee.ImageCollection("MODIS/006/MOD13A1")
                .first()
                  .select('NDVI'))
                        
    // Get information about the MODIS projection.
    var modisProjection = modis.projection();
    print('MODIS projection:', modisProjection);
    
    // Get the Landsat NDVI collection at MODIS scale and projection.
    var landsat_pro = ndvi.first().projection();    
    var CopyScale = landsat_pro.nominalScale();
    print(CopyScale, 'original scale Landsat (m)')
    
    var landsat_resample = function(image){
      return image.reproject(landsat_pro, null, 500) // insert here the desired scale in meters
    
        // Force the next reprojection to aggregate instead of resampling.
        .reduceResolution({
          reducer: ee.Reducer.mean(),
          maxPixels: 1024
        })
      .copyProperties(image)
    }
    
    var ndviResample = ndvi.map(landsat_resample)
                        
    ///Create a timer-series plot of NDVI
    var chart = ui.Chart.image.series({
        imageCollection: ndviResample,
        region: ROI,
        reducer: ee.Reducer.mean(),
        scale: 500,
    })
    
    print(chart, "ndvi") 
    

    【讨论】:

    • 感谢您的帮助,一切正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    相关资源
    最近更新 更多