如何降低 Google Earth Engine 中图像集的空间分辨率?

问题描述

美好的一天

请您在以下方面帮助我。

我正在尝试使用 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") 

解决方法

确实,在 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") 

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...