Currently, I am facing a challenge in plotting monthly and yearly soil moisture time-series in the same chart. The ImageCollection contains 480 images (one per month) for the monthly data and another ImageCollection with 40 images (one per year) for the yearly data.
I have managed to plot them individually, but I'm struggling to combine both plots into a single chart. I explored options such as using innerJoin() beforehand, which resulted in downsampling the monthly collection from 480 to 40 images. Another option was to fill gaps in the yearly collection with Na values, similar to fillNa in pandas, but I couldn't find a suitable method to do so.
Below is a snippet of the code:
// --- 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'}}
};
print(ui.Chart.image.series(yearlySoil, studyArea, ee.Reducer.mean(), scale).setOptions(options2));
For the full code implementation, please visit this link.