-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNoah.js
179 lines (157 loc) · 6.12 KB
/
Noah.js
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
This script computes, displays and exports the mean annual temperature,
mean annual precipitation. Climate data is NOAH Global Land Assimulation
System data.
Thanks to the awesome geetools by @author: Rodrigo E. Principe
https://github.com/fitoprincipe/geetools-code-editor/wiki
we could batch export the imageCollection of monthly climate data.
(by default, the batch process of monthly data is commented as it takes
a lot of computing resources)
Note: It would take a long time to compute so it might be good to export
through task. In my own exprience it would take 15 hours to finish 30 yr
of data processing.
Shunan Feng: [email protected]
*/
//-------------------------------------------------------------------//
// preparation //
//-------------------------------------------------------------------//
var worldmap = ee.FeatureCollection('ft:1tdSwUL7MVpOauSgRzqVTOwdfy17KDbw-1d9omPw');//world vector
var roi = worldmap.geometry().dissolve().bounds();
// study time range
var year_start = 1984;
var year_end = 2018;
var month_start = 1;
var month_end = 12;
var date_start = ee.Date.fromYMD(year_start, 1, 1);
var date_end = ee.Date.fromYMD(year_end, 12, 31);
var years = ee.List.sequence(year_start, year_end);// time range of years
var months = ee.List.sequence(month_start, month_end);// time range of months
// load noah data
var gldas1 = ee.ImageCollection("NASA/GLDAS/V20/NOAH/G025/T3H")
.filterDate(date_start, '1999-12-31');
var gldas2 = ee.ImageCollection("NASA/GLDAS/V021/NOAH/G025/T3H")
.filterDate(date_start, date_end);
var gldas = gldas1.merge(gldas2);
var gldasTemp = gldas.select('Tair_f_inst');
var gldasPrec = gldas.select('Rainf_f_tavg');
// print(gldasTemp);
// import batch module
var batch = require('users/fitoprincipe/geetools:batch');
//-------------------------------------------------------------------//
// mean annual temerature //
//-------------------------------------------------------------------//
// MAT is the average of the annual temperature. The unit is converted
// from K to celcius degree
var multTemp = function(image) {
var tempUnit = image.subtract(273.15);
return image.addBands(tempUnit);
};
gldasTemp = gldasTemp.map(multTemp);
var tempAnnual = ee.ImageCollection.fromImages(
years.map(function (y) {
var meanT = gldasTemp.select('Tair_f_inst_1')
.filter(ee.Filter.calendarRange(y, y, 'year'))
.mean()
.rename('MAT');
return meanT.set('year', y)
.set('system:time_start', ee.Date.fromYMD(y, 1, 1));
}).flatten()
);
var MAT = tempAnnual.mean();
// print(MAT, 'mean annual temperature');
// Map.addLayer(MAT, {min: -10, max: 30, palette: ['blue', 'green', 'red']}, 'mean annual temperature');
// mean monthly temperature
var tempMonthly = ee.ImageCollection.fromImages(
years.map(function (y) {
return months.map(function (m) {
var meanT = gldasTemp.select('Tair_f_inst_1')
.filter(ee.Filter.calendarRange(y, y, 'year'))
.filter(ee.Filter.calendarRange(m, m, 'month'))
.mean()
.rename('MMT');
return meanT.set('year', y)
.set('month', m)
.set('system:time_start', ee.Date.fromYMD(y, m, 1));
});
}).flatten()
);
// export
Export.image.toAsset({
image: MAT,
description: 'MAT30yrNoah',
assetId: 'MAT30yrNoah',
scale: 10000,
// region: roi
});
Export.image.toDrive({
image: MAT,
folder: 'gee',
description: 'MAT30yrNoah',
scale: 10000,
// region: roi
});
// // batch export
// batch.Download.ImageCollection.toAsset(tempMonthly.select('MMT'), 'noah/MMT30yr',
// {name: 'MMT30yr',
// scale: 10000,
// region: tempMonthly.first().geometry()
// });
//-------------------------------------------------------------------//
// mean annual precpitation //
//-------------------------------------------------------------------//
// The unit of precipitation (Rainf_f_tavg) is kg/m^2/s. The temporal
// resolution is every 3 hours (8 image per day)
var multPrec = function(image) {
var precUnit = image.multiply(3 * 60 * 60);
return image.addBands(precUnit);
};
gldasPrec = gldasPrec.map(multPrec);
var precAnnual = ee.ImageCollection.fromImages(
years.map(function (y) {
var meanP = gldasPrec.select('Rainf_f_tavg_1')
.filter(ee.Filter.calendarRange(y, y, 'year'))
.sum()
.rename('MAP');
return meanP.set('year', y)
.set('system:time_start', ee.Date.fromYMD(y, 1, 1));
}).flatten()
);
var MAPr = precAnnual.mean();
Map.addLayer(MAPr, {min: 0, max: 2000, palette: ['red', 'green', 'blue']}, 'mean annual precipitation');
print(MAPr, 'mean annual precipitation');
// mean monthly precipitation
var precMonthly = ee.ImageCollection.fromImages(
years.map(function (y) {
return months.map(function (m) {
var meanP = gldasPrec.select('Rainf_f_tavg_1')
.filter(ee.Filter.calendarRange(y, y, 'year'))
.filter(ee.Filter.calendarRange(m, m, 'month'))
.sum()
.rename('MMP');
return meanP.set('year', y)
.set('month', m)
.set('system:time_start', ee.Date.fromYMD(y, m, 1));
});
}).flatten()
);
// export
Export.image.toAsset({
image: MAPr,
description: 'MAP30yrNoah',
assetId: 'MAP30yrNoah',
scale: 10000,
// region: roi
});
Export.image.toDrive({
image: MAPr,
folder: 'gee',
description: 'MAP30yrNoah',
scale: 10000,
// region: roi
});
// // batch export
// batch.Download.ImageCollection.toAsset(precMonthly.select('MMP'), 'noah/MMP30yr',
// {name: 'MMP30yr',
// scale: 10000,
// region: precMonthly.first().geometry()
// });