目录
1 数据介绍
2 完整代码
// 定义研究区域
var geometry = table;
// 加载 ERA5 数据集
var era5Dataset = ee.ImageCollection("ECMWF/ERA5_LAND/MONTHLY_AGGR");
// 筛选土壤水分和土壤温度相关波段
var soilMoistureBands = [
'volumetric_soil_water_layer_1', // 0-7 cm
'volumetric_soil_water_layer_2', // 7-28 cm
'volumetric_soil_water_layer_3', // 28-100 cm
'volumetric_soil_water_layer_4' // 100-289 cm
];
var soilTemperatureBands = [
'soil_temperature_level_1', // 0-7 cm
'soil_temperature_level_2', // 7-28 cm
'soil_temperature_level_3', // 28-100 cm
'soil_temperature_level_4' // 100-289 cm
];
// 定义年份范围
var years = ee.List.sequence(1951, 2023);
// 计算年度均值
function calculateAnnualMean(year, bands) {
var startDate = ee.Date.fromYMD(year, 1, 1);
var endDate = startDate.advance(1, 'year');
// 筛选对应年份的数据并计算均值
var annualMean = era5Dataset.filterDate(startDate, endDate)
.select(bands)
.mean()
.reduceRegion({
reducer: ee.Reducer.mean(),
geometry: geometry,
scale: 11132, // 数据分辨率
maxPixels: 1e13
});
return ee.Feature(null, annualMean).set('year', year);
}
// 生成年度土壤水分的统计数据
var soilMoistureStats = years.map(function(year) {
return calculateAnnualMean(year, soilMoistureBands);
});
// 生成年度土壤温度的统计数据
var soilTemperatureStats = years.map(function(year) {
return calculateAnnualMean(year, soilTemperatureBands);
});
// 转换为 FeatureCollection
var soilMoistureFC = ee.FeatureCollection(soilMoistureStats);
var soilTemperatureFC = ee.FeatureCollection(soilTemperatureStats);
// 可视化折线图
// 土壤水分折线图
var soilMoistureChart = ui.Chart.feature.byFeature(soilMoistureFC, 'year', soilMoistureBands)
.setChartType('LineChart')
.setOptions({
title: 'Annual Soil Water (2000-2023)',
hAxis: { title: 'Year' },
vAxis: { title: 'Soil Water (m³/m³)' },
lineWidth: 2,
pointSize: 4,
series: {
0: { color: 'blue', label: 'Layer 1 (0-7 cm)' },
1: { color: 'green', label: 'Layer 2 (7-28 cm)' },
2: { color: 'orange', label: 'Layer 3 (28-100 cm)' },
3: { color: 'red', label: 'Layer 4 (100-289 cm)' }
}
});
// 土壤温度折线图
var soilTemperatureChart = ui.Chart.feature.byFeature(soilTemperatureFC, 'year', soilTemperatureBands)
.setChartType('LineChart')
.setOptions({
title: 'Annual Soil Temperature (2000-2023)',
hAxis: { title: 'Year' },
vAxis: { title: 'Soil Temperature (K)' },
lineWidth: 2,
pointSize: 4,
series: {
0: { color: 'blue', label: 'Layer 1 (0-7 cm)' },
1: { color: 'green', label: 'Layer 2 (7-28 cm)' },
2: { color: 'orange', label: 'Layer 3 (28-100 cm)' },
3: { color: 'red', label: 'Layer 4 (100-289 cm)' }
}
});
// 打印折线图
print(soilMoistureChart);
print(soilTemperatureChart);
// 导出年度土壤水分统计数据为 CSV
Export.table.toDrive({
collection: soilMoistureFC,
description: 'Annual_Soil_Moisture_Stats',
fileNamePrefix: 'Annual_Soil_Moisture',
fileFormat: 'CSV',
folder: 'ERA5_Stats'
});
// 导出年度土壤温度统计数据为 CSV
Export.table.toDrive({
collection: soilTemperatureFC,
description: 'Annual_Soil_Temperature_Stats',
fileNamePrefix: 'Annual_Soil_Temperature',
fileFormat: 'CSV',
folder: 'ERA5_Stats'
});