【问题标题】:why two combined image collections show 0 elements in the console of the google earth engine?为什么两个组合的图像集合在谷歌地球引擎的控制台中显示 0 个元素?
【发布时间】:2022-01-14 22:47:41
【问题描述】:

我使用 .combine 命令将两个图像集合转换为双波段图像集合(在最后一行),以便在下一步的函数中使用。此命令已执行,但在控制台中写入 0 个元素。这个问题是从哪里来的?

代码链接: https://code.earthengine.google.com/5ebed42b397e764e3229e3f224c8b643

代码:

   var Rad1 = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY')
            .filter(ee.Filter.date('2018-10-24','2019-05-20'))
            .select('surface_solar_radiation_downwards');

   var Rad2 = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY')
            .filter(ee.Filter.date('2019-05-20','2019-06-30'))
            .select('surface_solar_radiation_downwards');


   var Rad1_Mj = Rad1.map(function(img){
   var bands = img.multiply(0.000001);
   var clip = bands.clip(geometry);
   return clip
   .copyProperties(img,['system:time_start','system:time_end']); });
   //print(Rad1_Mj);

   var Rad2_Mj = Rad2.map(function(img){
   var bands = img.multiply(0.000001);
   var clip = bands.clip(geometry);
   return clip
   .copyProperties(img,['system:time_start','system:time_end']); });
   //print(Rad2_Mj);

   // time frame change function for median collection
   var daily_product_median = function(collection, start, count, interval, units){
   var sequence = ee.List.sequence(0, ee.Number(count).subtract(1));
   var origin_date = ee.Date(start);

   return ee.ImageCollection(sequence.map(function(i){

    var start_date = origin_date.advance(ee.Number(interval).multiply(i),units);
    var end_date = 
    origin_date.advance(ee.Number(interval).multiply(ee.Number(i).add(1)),units);

    return collection.filterDate(start_date, end_date).median()
     .set('system:time_start',start_date.millis())
     .set('system:time_end',end_date.millis());
    }))};

   // daily radiation product
   var daily_Rad_1 = daily_product_median(Rad1_Mj,'2018-10-24', 208 , 24 , 'hour');
   // print(daily_Rad_1);
   //Map.addLayer(daily_Rad_1, {min: 17.38, max: 26.07, palette : 
   ['white','yellow','orange']}, 
   'Daily solar shortwave radiation 1' ); 

  var daily_Rad_2 = daily_product_median(Rad2_Mj,'2019-05-20', 41 , 24 , 'hour');
  // print(daily_Rad_2);
  // Map.addLayer(daily_Rad_2, {min: 23.77, max: 26.64, palette : 
  ['white','yellow','orange']}, 
  'Daily solar shortwave radiation 2');

  var daily_Rad_total = daily_Rad_1.merge(daily_Rad_2);
  //print(daily_Rad_total);


  var START = '2018-10-24';
  var END = '2019-06-30';

  var DATES = [ '2018-12-19', '2018-12-29', '2019-01-23', '2019-02-12', '2019-03-04',
 '2019-03-19', '2019-04-08', '2019-04-13', '2019-05-13', '2019-05-18', '2019-05-23',
 '2019-05-28', '2019-06-02', '2019-06-07', '2019-06-12', '2019-06-17', '2019-06-22',
 '2019-06-27'];

  var addTime = function(x) {
    return x.set('Date', ee.Date(x.get('system:time_start')).format("YYYY-MM-dd"))};

  var final_Rad = ee.ImageCollection(daily_Rad_total)
          .filter(ee.Filter.date(START, END))
          .map(addTime)
          .filter(ee.Filter.inList('Date',ee.List(DATES)));
  print(final_Rad);



  var ndvi = function(img){
  var bands = img.select(['B2','B3','B4','B8']).multiply(0.0001)
  .clip(geometry);
  var index = bands.normalizedDifference(['B8','B4']);
  return index
 .copyProperties(img,['system:time_start','system:time_end','system:index']);
  };

 var S2 = ee.ImageCollection('COPERNICUS/S2_SR')
 .filterBounds(geometry)
 .filterDate('2018-10-24','2019-06-30')
 .filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE',20))
 .map(ndvi);

 print(S2);

 var NDVI_and_Rad = S2.combine(final_Rad, false);
 print(NDVI_and_Rad);

【问题讨论】:

    标签: element google-earth-engine


    【解决方案1】:

    Try it here

    您可以使用合并而不是组合来获取新的图像集合

    
    var Rad1 = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY')
                    .filter(ee.Filter.date('2018-10-24','2019-05-20'))
                    .select('surface_solar_radiation_downwards');
    
    var Rad2 = ee.ImageCollection('ECMWF/ERA5_LAND/HOURLY')
                    .filter(ee.Filter.date('2019-05-20','2019-06-30'))
                    .select('surface_solar_radiation_downwards');
    
    
    var Rad1_Mj = Rad1.map(function(img){
    var bands = img.multiply(0.000001);
    var clip = bands.clip(geometry);
    return clip
    .copyProperties(img,['system:time_start','system:time_end']); });
    
    //print(Rad1_Mj);
    
    var Rad2_Mj = Rad2.map(function(img){
    var bands = img.multiply(0.000001);
    var clip = bands.clip(geometry);
    return clip
    .copyProperties(img,['system:time_start','system:time_end']); });
    //print(Rad2_Mj);
    
    // time frame change function for median collection
    var daily_product_median = function(collection, start, count, interval, units){
      var sequence = ee.List.sequence(0, ee.Number(count).subtract(1));
      var origin_date = ee.Date(start);
      
      return ee.ImageCollection(sequence.map(function(i){
        
        var start_date = origin_date.advance(ee.Number(interval).multiply(i),units);
        var end_date = origin_date.advance(ee.Number(interval).multiply(ee.Number(i).add(1)),units);
        
        return collection.filterDate(start_date, end_date).median()
        .set('system:time_start',start_date.millis())
        .set('system:time_end',end_date.millis());
      }))};
      
      // daily radiation product
      var daily_Rad_1 = daily_product_median(Rad1_Mj,'2018-10-24', 208 , 24 , 'hour');
     // print(daily_Rad_1);
     //Map.addLayer(daily_Rad_1, {min: 17.38, max: 26.07, palette : ['white','yellow','orange']}, 'Daily solar shortwave radiation 1' ); 
      
      var daily_Rad_2 = daily_product_median(Rad2_Mj,'2019-05-20', 41 , 24 , 'hour');
     // print(daily_Rad_2);
     // Map.addLayer(daily_Rad_2, {min: 23.77, max: 26.64, palette : ['white','yellow','orange']}, 'Daily solar shortwave radiation 2');
    
    var daily_Rad_total = daily_Rad_1.merge(daily_Rad_2);
    //print(daily_Rad_total);
    
    
    var START = '2018-10-24';
    var END = '2019-06-30';
    
    var DATES = [ '2018-12-19', '2018-12-29', '2019-01-23', '2019-02-12', '2019-03-04',
    '2019-03-19', '2019-04-08', '2019-04-13', '2019-05-13', '2019-05-18', '2019-05-23',
    '2019-05-28', '2019-06-02', '2019-06-07', '2019-06-12', '2019-06-17', '2019-06-22',
    '2019-06-27'];
    
    var addTime = function(x) {
      return x.set('Date', ee.Date(x.get('system:time_start')).format("YYYY-MM-dd"))};
      
    var final_Rad = ee.ImageCollection(daily_Rad_total)
                .filter(ee.Filter.date(START, END))
                .map(addTime)
                .filter(ee.Filter.inList('Date',ee.List(DATES)));
                
    print("final_Rad",final_Rad);
    
    
    
    var ndvi = function(img){
      var bands = img.select(['B2','B3','B4','B8']).multiply(0.0001)
      .clip(geometry);
      var index = bands.normalizedDifference(['B8','B4']);
      return index
      .copyProperties(img,['system:time_start','system:time_end','system:index']);
    };
    
    var S2 = ee.ImageCollection('COPERNICUS/S2_SR')
    .filterBounds(geometry)
    .filterDate('2018-10-24','2019-06-30')
    .filter(ee.Filter.lte('CLOUDY_PIXEL_PERCENTAGE',20))
    .map(ndvi);
    
    print("S2", S2);
    
    var NDVI_and_Rad = S2.merge(final_Rad);
    print('Both image collection', NDVI_and_Rad);
    
    
    

    【讨论】:

    • 我想将这两个图像集合相乘,所以我使用 .combine 代码制作一个具有两个波段的图像集合,然后在一个函数代码中将两个波段的 NDVI 和 Radiation 相乘。但我不明白为什么这段代码不能结合这两个图像集合
    • 所以合并对你不起作用?
    • 不,合并只是做一个集合,对于下一步,我不能将这两个参数相乘。我需要正确的组合代码或其他可以将 NDVI 和辐射相乘的代码
    猜你喜欢
    • 1970-01-01
    • 2017-10-07
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2013-08-02
    • 2021-01-10
    • 1970-01-01
    相关资源
    最近更新 更多