为什么两个组合的图像集合在googleearth引擎的控制台中显示0个元素



我使用.connect命令将两个图像集合转换为一个双波段图像集合(在最后一行(,以便在下一步的函数中使用。执行此命令,但在控制台中写入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);

在这里试试

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


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);

最新更新