-
Notifications
You must be signed in to change notification settings - Fork 5
/
Point_CMIP5_daily_V1.0.js
293 lines (271 loc) · 12.1 KB
/
Point_CMIP5_daily_V1.0.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//SCRIPT PARA DESCARGAR LOS BASES DE DATOS DE MODELOS DE CIRCULACIÓN GENERAL (GCM's)
//COLECCIÓN DEL PRODUCTO NASA NEX GDDP A ESCALA DIARIA
//Insertar coordenadas geográficas de la estación (punto) de interés
//Cambia el nombre de la variable "estac" para tener una carpeta en Google Drive con el nombre de cada estación
//INGRESAMOS DATOS DE LA ESTACIÓN (PUNTO) EN ESTUDIO
//Insertar coordenadas geográficas.
//Cambia el nombre de la variable "estac" para tener una carpeta en Google Drive
//con el nombre de cada estación que desees estudiar.
var estacname = 'AGUADA BLANCA'
var point = ee.Geometry.Point([-71.3332532,-16.226843]);
Map.addLayer(point);
Map.centerObject(point,6);
//DEFINIMOS LOS PERÍODOS PARA LA EXTRACCIÓN
//ESCENARIOS RCP 4.5 Y RCP 8.5
var startDatehist = ee.Date('1950-01-01');
var endDatehist = ee.Date('2005-12-31');
//PERÍODO HISTÓRICO
var startDate = ee.Date('2006-01-01');
var endDate = ee.Date('2099-12-31');
//INGRESAMOS DATOS DEL LA COLECCIÓN A USAR PARA EXTRACCIÓN DE DATOS
var dataset = ee.ImageCollection('NASA/NEX-GDDP')
.filter(ee.Filter.date(startDate, endDate));
var datasethist = ee.ImageCollection('NASA/NEX-GDDP')
.filter(ee.Filter.date(startDatehist, endDatehist));
//**************SOLO HABILITAR PARA VISUALIZACIÓN*******************
/*
var maximumAirTemperatureVis = {
min: 240.0,
max: 300.0,
palette: ['blue', 'purple', 'cyan', 'green', 'yellow', 'red'],
};
Map.setCenter(67, 45, 3.0);
Map.addLayer(
maximumAirTemperature, maximumAirTemperatureVis, 'Maxmum Air Temperature');
*/
//*******************************************************************
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//EXTRACCIÓN DE DATOS DE TEMPERATURA MÁXIMA DIARIA
//ESCENARIOS RCP 4.5 Y 8.5
// get projection information
var maximumAirTemperature = dataset.select('tasmax');
var proj = maximumAirTemperature.first().projection();
// calculate number of days to map and extract data for
var n = endDate.difference(startDate,'day').subtract(1);
// map over each date and extract all climate model values
var timeseries = ee.FeatureCollection(
ee.List.sequence(0,n).map(function(i){
var t1 = startDate.advance(i,'day');
var t2 = t1.advance(1,'day');
var feature = ee.Feature(point);
var dailyColl = maximumAirTemperature.filterDate(t1, t2);
var dailyImg = dailyColl.toBands();
// rename bands to handle different names by date
var bands = dailyImg.bandNames();
var renamed = bands.map(function(b){
var split = ee.String(b).split('_');
return ee.String(split.get(0)).cat('_').cat(ee.String(split.get(1)));
});
// extract the data for the day and add time information
var dict = dailyImg.rename(renamed).reduceRegion({
reducer: ee.Reducer.mean(),
geometry: point,
scale: proj.nominalScale()
}).combine(
ee.Dictionary({'system:time_start':t1.millis(),'isodate':t1.format('YYYY-MM-dd')})
);
return ee.Feature(point,dict);
})
);
//RANGO HISTÓRICO
// calculate number of days to map and extract data for
var maximumAirTemperature = datasethist.select('tasmax');
var proj = maximumAirTemperature.first().projection();
// calculate number of days to map and extract data for
var nhist = endDatehist.difference(startDatehist,'day').subtract(1);
// map over each date and extract all climate model values
var timeserieshist = ee.FeatureCollection(
ee.List.sequence(0,nhist).map(function(i){
var thist1 = startDatehist.advance(i,'day');
var thist2 = thist1.advance(1,'day');
var feature = ee.Feature(point);
var dailyCollhist = maximumAirTemperature.filterDate(thist1, thist2);
var dailyImghist = dailyCollhist.toBands();
// rename bands to handle different names by date
var bandshist = dailyImghist.bandNames();
var renamedhist = bandshist.map(function(b){
var splithist = ee.String(b).split('_');
return ee.String(splithist.get(0)).cat('_').cat(ee.String(splithist.get(1)));
});
// extract the data for the day and add time information
var dicthist = dailyImghist.rename(renamedhist).reduceRegion({
reducer: ee.Reducer.mean(),
geometry: point,
scale: proj.nominalScale()
}).combine(
ee.Dictionary({'system:time_start':thist1.millis(),'isodate':thist1.format('YYYY-MM-dd')})
);
return ee.Feature(point,dicthist);
})
);
//******ÚNICAMENTE HABILITAR PARA FINES DE VISUALIZACIÓN************
//print(timeseries);
// get properties to chart (all climate models)
//var props = timeseries.first().propertyNames().removeAll(['system:time_start','system:index','isodate']);
// Make a chart of the results.
//var chart = ui.Chart.feature.byFeature(timeseries, 'system:time_start', props.getInfo());
//print(chart);
//****************************************************************
//Exportamos en formato .csv los datos de los escenarios RCP 4.5 y 8.5
Export.table.toDrive(timeseries,
'RCP4585TASMAX', // Name of the task
estacname, // Name of the folder in Google Drive to be created
'RCP4585TASMAX'); // Name of the file to be generated with the downloaded datasets
//Exportamos en formato .csv los datos del período histórico
Export.table.toDrive(timeserieshist,
'HISTASMAX', // Name of the task
estacname, // Name of the folder in Google Drive to be created
'HISTASMAX'); // Name of the file to be generated with the downloaded datasets
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//EXTRACCIÓN DE DATOS DE TEMPERATURA MÍNIMA DIARIA
//ESCENARIOS RCP 4.5 Y 8.5
// get projection information
var minimumAirTemperature = dataset.select('tasmin');
var proj = minimumAirTemperature.first().projection();
// calculate number of days to map and extract data for
var n = endDate.difference(startDate,'day').subtract(1);
// map over each date and extract all climate model values
var timeseries = ee.FeatureCollection(
ee.List.sequence(0,n).map(function(i){
var t1 = startDate.advance(i,'day');
var t2 = t1.advance(1,'day');
var feature = ee.Feature(point);
var dailyColl = minimumAirTemperature.filterDate(t1, t2);
var dailyImg = dailyColl.toBands();
// rename bands to handle different names by date
var bands = dailyImg.bandNames();
var renamed = bands.map(function(b){
var split = ee.String(b).split('_');
return ee.String(split.get(0)).cat('_').cat(ee.String(split.get(1)));
});
// extract the data for the day and add time information
var dict = dailyImg.rename(renamed).reduceRegion({
reducer: ee.Reducer.mean(),
geometry: point,
scale: proj.nominalScale()
}).combine(
ee.Dictionary({'system:time_start':t1.millis(),'isodate':t1.format('YYYY-MM-dd')})
);
return ee.Feature(point,dict);
})
);
//RANGO HISTÓRICO
// calculate number of days to map and extract data for
var minimumAirTemperature = datasethist.select('tasmin');
var proj = minimumAirTemperature.first().projection();
// calculate number of days to map and extract data for
var nhist = endDatehist.difference(startDatehist,'day').subtract(1);
// map over each date and extract all climate model values
var timeserieshist = ee.FeatureCollection(
ee.List.sequence(0,nhist).map(function(i){
var thist1 = startDatehist.advance(i,'day');
var thist2 = thist1.advance(1,'day');
var feature = ee.Feature(point);
var dailyCollhist = minimumAirTemperature.filterDate(thist1, thist2);
var dailyImghist = dailyCollhist.toBands();
// rename bands to handle different names by date
var bandshist = dailyImghist.bandNames();
var renamedhist = bandshist.map(function(b){
var splithist = ee.String(b).split('_');
return ee.String(splithist.get(0)).cat('_').cat(ee.String(splithist.get(1)));
});
// extract the data for the day and add time information
var dicthist = dailyImghist.rename(renamedhist).reduceRegion({
reducer: ee.Reducer.mean(),
geometry: point,
scale: proj.nominalScale()
}).combine(
ee.Dictionary({'system:time_start':thist1.millis(),'isodate':thist1.format('YYYY-MM-dd')})
);
return ee.Feature(point,dicthist);
})
);
//Exportamos en formato .csv los datos de los escenarios RCP 4.5 y 8.5
Export.table.toDrive(timeseries,
'RCP4585TASMIN', // Name of the task
estacname, // Name of the folder in Google Drive to be created
'RCP4585TASMIN'); // Name of the file to be generated with the downloaded datasets
//Exportamos en formato .csv los datos del período histórico
Export.table.toDrive(timeserieshist,
'HISTASMIN', // Name of the task
estacname, // Name of the folder in Google Drive to be created
'HISTASMIN'); // Name of the file to be generated with the downloaded datasets
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//EXTRACCIÓN DE DATOS DE PRECIPITACIÓN DIARIA
//La variable "pr" representa la precipitación media diaria en la superficie,
//la cual incluye tanto fases líquidas como sólidas de todo tipo de nubes,
//tanto a gran escala como convectivas.
//ESCENARIOS RCP 4.5 Y 8.5
// get projection information
var precipitation = dataset.select('pr');
var proj = precipitation.first().projection();
// calculate number of days to map and extract data for
var n = endDate.difference(startDate,'day').subtract(1);
// map over each date and extract all climate model values
var timeseries = ee.FeatureCollection(
ee.List.sequence(0,n).map(function(i){
var t1 = startDate.advance(i,'day');
var t2 = t1.advance(1,'day');
var feature = ee.Feature(point);
var dailyColl = precipitation.filterDate(t1, t2);
var dailyImg = dailyColl.toBands();
// rename bands to handle different names by date
var bands = dailyImg.bandNames();
var renamed = bands.map(function(b){
var split = ee.String(b).split('_');
return ee.String(split.get(0)).cat('_').cat(ee.String(split.get(1)));
});
// extract the data for the day and add time information
var dict = dailyImg.rename(renamed).reduceRegion({
reducer: ee.Reducer.mean(),
geometry: point,
scale: proj.nominalScale()
}).combine(
ee.Dictionary({'system:time_start':t1.millis(),'isodate':t1.format('YYYY-MM-dd')})
);
return ee.Feature(point,dict);
})
);
//RANGO HISTÓRICO
var precipitation = datasethist.select('pr');
var proj = precipitation.first().projection();
// calculate number of days to map and extract data for
var nhist = endDatehist.difference(startDatehist,'day').subtract(1);
// map over each date and extract all climate model values
var timeserieshist = ee.FeatureCollection(
ee.List.sequence(0,nhist).map(function(i){
var thist1 = startDatehist.advance(i,'day');
var thist2 = thist1.advance(1,'day');
var feature = ee.Feature(point);
var dailyCollhist = precipitation.filterDate(thist1, thist2);
var dailyImghist = dailyCollhist.toBands();
// rename bands to handle different names by date
var bandshist = dailyImghist.bandNames();
var renamedhist = bandshist.map(function(b){
var splithist = ee.String(b).split('_');
return ee.String(splithist.get(0)).cat('_').cat(ee.String(splithist.get(1)));
});
// extract the data for the day and add time information
var dicthist = dailyImghist.rename(renamedhist).reduceRegion({
reducer: ee.Reducer.mean(),
geometry: point,
scale: proj.nominalScale()
}).combine(
ee.Dictionary({'system:time_start':thist1.millis(),'isodate':thist1.format('YYYY-MM-dd')})
);
return ee.Feature(point,dicthist);
})
);
//Exportamos en formato .csv los datos de los escenarios RCP 4.5 y 8.5
Export.table.toDrive(timeseries,
'RCP4585PR', // Name of the task
estacname, // Name of the folder in Google Drive to be created
'RCP4585PR'); // Name of the file to be generated with the downloaded datasets
//Exportamos en formato .csv los datos del período histórico
Export.table.toDrive(timeserieshist,
'HISTPR', // Name of the task
estacname, // Name of the folder in Google Drive to be created
'HISTPR'); // Name of the file to be generated with the downloaded datasets