如何在 Google Earth Engine 上的单个图中将时间序列数据集与不同时间步长结合起来

我目前正在尝试在同一张图表中绘制每月和每年土壤湿度的时间序列。我有一个 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


泛舟湖上清波郎朗
浏览 128回答 1
1回答

临摹微笑

与您用 NA 填充间隙的想法类似,我向每个集合添加了一个空带,以匹配其他集合中的相应带。然后我合并了这些集合并制作了一个图表。s2sr = s2sr.filterBounds(roi).filter(ee.Filter.calendarRange(2020, 2020, 'year'))l8sr = l8sr.filterBounds(roi).filter(ee.Filter.calendarRange(2020, 2020, 'year'))// compute some bands to add to each collectionvar addS2Bands = function(image){  var s2nd = image.normalizedDifference(['B4','B3']).rename('s2_nd')  var l8nd = ee.Image().rename('l8_nd') // must add an empty band for select() to work on all images  return image.addBands(s2nd).addBands(l8nd)}var addL8Bands = function(image){  var l8nd = image.normalizedDifference(['B4','B3']).rename('l8_nd')  var s2nd = ee.Image().rename('s2_nd')  return image.addBands(l8nd).addBands(s2nd)}l8sr = l8sr.map(addL8Bands)s2sr = s2sr.map(addS2Bands)// merge the collectionsvar merged = l8sr.merge(s2sr).select(['l8_nd', 's2_nd'])// plot the collectionvar chart = ui.Chart.image.series({  imageCollection: merged,  region: roi,  reducer: ee.Reducer.mean(),  scale: 30})print(chart)https://code.earthengine.google.com/?scriptPath=users%2Fcaseyengstrom%2Freprex%3AuiChartMultiCollection
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript