-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path00 monthly bias-1971-2000
142 lines (115 loc) · 5.54 KB
/
00 monthly bias-1971-2000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var geometry = ee.FeatureCollection("projects/heatwave0214/assets/basicpolygon/Chinaregion_NOTW").geometry();
// 加载数据集
var era5 = ee.ImageCollection("ECMWF/ERA5_LAND/DAILY_AGGR").filterBounds(geometry);
var cmip6 = ee.ImageCollection("NASA/GDDP-CMIP6").filterBounds(geometry);
// 定义时间范围
var startDate = '1971-05-01';
var endDate = '2000-09-30';
// 筛选时间范围内的数据
var era5_filtered = era5.filterDate(startDate, endDate).select('temperature_2m');
var cmip6_filtered = cmip6.filter(ee.Filter.eq('scenario', 'historical'))
.filterDate(startDate, endDate)
.select('tas');
// 计算1971-2000年间各月份的ERA5和CMIP6的平均气温
var calculateMonthlyMean = function(collection, startYear, endYear, month, daysInMonth) {
var start = ee.Date.fromYMD(startYear, month, 1);
var end = ee.Date.fromYMD(endYear, month, daysInMonth);
return collection.filterDate(start, end).mean().clip(geometry); // 转换为摄氏度
};
// 计算ERA5和CMIP6每月平均值
var era5_may_mean = calculateMonthlyMean(era5_filtered, 1971, 2000, 5, 31).rename('tas');
var era5_june_mean = calculateMonthlyMean(era5_filtered, 1971, 2000, 6, 30).rename('tas');
var era5_july_mean = calculateMonthlyMean(era5_filtered, 1971, 2000, 7, 31).rename('tas');
var era5_august_mean = calculateMonthlyMean(era5_filtered, 1971, 2000, 8, 31).rename('tas');
var era5_september_mean = calculateMonthlyMean(era5_filtered, 1971, 2000, 9, 30).rename('tas');
// print("era5_may_mean",era5_may_mean)
var visualization1 = {
bands: ['tas'],
min: -10.0,
max: 300.0,
palette: [
'000080', '0000d9', '4000ff', '8000ff', '0080ff', '00ffff',
'00ff80', '80ff00', 'daff00', 'ffff00', 'fff500', 'ffda00',
'ffb000', 'ffa400', 'ff4f00', 'ff2500', 'ff0a00', 'ff00ff',
]
};
// Map.addLayer(era5_may_mean, visualization1, 'era5_may_mean');
var cmip6_may_mean = calculateMonthlyMean(cmip6_filtered, 1971, 2000, 5, 31).rename('tas');
var cmip6_june_mean = calculateMonthlyMean(cmip6_filtered, 1971, 2000, 6, 30).rename('tas');
var cmip6_july_mean = calculateMonthlyMean(cmip6_filtered, 1971, 2000, 7, 31).rename('tas');
var cmip6_august_mean = calculateMonthlyMean(cmip6_filtered, 1971, 2000, 8, 31).rename('tas');
var cmip6_september_mean = calculateMonthlyMean(cmip6_filtered, 1971, 2000, 9, 30).rename('tas');
// print("cmip6_may_mean",cmip6_may_mean)
var visualization1 = {
bands: ['tas'],
min: -10.0,
max: 300.0,
palette: [
'000080', '0000d9', '4000ff', '8000ff', '0080ff', '00ffff',
'00ff80', '80ff00', 'daff00', 'ffff00', 'fff500', 'ffda00',
'ffb000', 'ffa400', 'ff4f00', 'ff2500', 'ff0a00', 'ff00ff',
]
};
// Map.addLayer(cmip6_may_mean, visualization1, 'cmip6_may_mean');
// 计算每月的差值(ERA5 - CMIP6)
var may_diff = era5_may_mean.subtract(cmip6_may_mean).set('month', 'May');
var june_diff = era5_june_mean.subtract(cmip6_june_mean).set('month', 'June');
var july_diff = era5_july_mean.subtract(cmip6_july_mean).set('month', 'July');
var august_diff = era5_august_mean.subtract(cmip6_august_mean).set('month', 'August');
var september_diff = era5_september_mean.subtract(cmip6_september_mean).set('month', 'September');
print("may_diff",may_diff)
var visualization = {
bands: ['tas'],
min: -17.0,
max: 10.0,
palette: [
'000080', '0000d9', '4000ff', '8000ff', '0080ff', '00ffff',
'00ff80', '80ff00', 'daff00', 'ffff00', 'fff500', 'ffda00',
'ffb000', 'ffa400', 'ff4f00', 'ff2500', 'ff0a00', 'ff00ff',
]
};
Map.setCenter(122.2, 21.2, 3);
Map.addLayer(image, visualization, 'may_diff');
// 创建包含所有月份差值的ImageCollection
// var monthly_diff_collection = ee.ImageCollection([may_diff, june_diff, july_diff, august_diff, september_diff]);
// 打印以调试
// print("Monthly Difference Collection", monthly_diff_collection);
// // 显示结果
// var visParams = {min: -5, max: 5, palette: ['blue', 'white', 'red']};
// Map.centerObject(geometry, 6);
// Map.addLayer(may_diff.clip(geometry), visParams, 'Difference May');
// Map.addLayer(june_diff.clip(geometry), visParams, 'Difference June');
// Map.addLayer(july_diff.clip(geometry), visParams, 'Difference July');
// Map.addLayer(august_diff.clip(geometry), visParams, 'Difference August');
// Map.addLayer(september_diff.clip(geometry), visParams, 'Difference September');
// export_img(may_diff, "projects/heatwave0214/assets/History_HW", "diff_05");
// export_img(june_diff, "projects/heatwave0214/assets/History_HW", "diff_06");
// export_img(july_diff, "projects/heatwave0214/assets/History_HW", "diff_07");
// export_img(august_diff, "projects/heatwave0214/assets/History_HW", "diff_08");
// export_img(september_diff, "projects/heatwave0214/assets/History_HW", "diff_09");
// function export_img(img, folder, task){
// Export.image.toAsset({
// image : img,
// description: task,
// assetId: folder.concat('/').concat(task),
// //range: [-0.125, -90.125, 179.875, 90.125],
// //dimensions:"1440x721",
// crs:"EPSG:4326",
// scale: 11132,
// region:geometry.bounds(),
// //crsTransform: [0.25, 0, -180, 0, -0.25, 89.875],
// maxPixels: 1e13
// });
// }
function exportImage(image, region, fileName) {
Export.image.toDrive({
image: image,
description: fileName,
folder: "futureheatwave-batch-change3",
scale: 11132,
region: geometry.bounds(),
maxPixels: 1e13,
crs: "EPSG:4326"
});
}
// exportImage(cmip6_may_mean, geometry.bounds(), "cmip6_may_mean");