我目前正在尝试在同一张图表中绘制每月和每年土壤湿度的时间序列。我有一个 ImageCollection,其中包含 480 张图像(每月一张),另一个 ImageCollection 包含 40 张图像(每年一张)。
我可以单独绘制它们,但我还没有找到将两个图堆叠在一个图表中的方法。我查找的一些选项是(a)预先执行innerJoin(),但这会将每月收集的图像从480张图像缩减到40张,或者(b)用Na填充年度收集中的空白(类似于用pandas填充Na) ,但我想不出办法来做到这一点。
这是代码示例:
// --- GLOBALS ---
var dateStart = ee.Date('1980-01-01');
var dateEnd = ee.Date('2019-12-31');
var scale = 1000;
var studyArea = ee.FeatureCollection('TIGER/2018/States').filterMetadata('NAME', 'equals', 'Nevada');
var monthlySoil = ee.ImageCollection('IDAHO_EPSCOR/TERRACLIMATE') // Load data
.filter(ee.Filter.date(dateStart, dateEnd))
.select('soil');
// --- TIME SERIES ---
// Create list of dates for time series
var dateListYearly = ee.List.sequence(0,dateEnd.difference(dateStart,'year').round(),1);
var makeDateListYearly = function(n) {return dateStart.advance(n,'year')};
dateListYearly = dateListYearly.map(makeDateListYearly);
// Yearly data
var yearlySoil = [];
yearlySoil = dateListYearly.map(function(d){ // Resample yearly
var start = ee.Date(d);
var end = ee.Date(d).advance(1,'year');
var dateRange = ee.DateRange(start,end);
var yearlySoilInter = monthlySoil
.filterDate(dateRange)
.mean()
.clip(studyArea)
.rename('Yearly');
return(yearlySoilInter.set('system:time_start', start.millis())); // Add time band
});
yearlySoil = ee.ImageCollection(yearlySoil);
// --- PLOT ---
var options1 = { // Monthly
title: 'SM Monthly',
fontSize: 12,
hAxis: {title: 'Date'},
vAxis: {title: 'SM (mm)'},
series: {0: {color: 'red'}}
};
print(ui.Chart.image.series(monthlySoil, studyArea, ee.Reducer.mean(), scale).setOptions(options1));
var options2 = { // Yearly
title: 'SM yearly',
fontSize: 12,
hAxis: {title: 'Date'},
vAxis: {title: 'SM (mm)'},
series: {0: {color: 'blue'}}
};
和链接:https://code.earthengine.google.com/1443f7796cd2d1527e4ca9fec145f4b7
临摹微笑
相关分类