-
Notifications
You must be signed in to change notification settings - Fork 1
/
RIG_GEECode.js
298 lines (214 loc) · 8.04 KB
/
RIG_GEECode.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
294
295
296
297
298
/*
*Script: Rainfall Intensity Graphs (RIG) v.1.0
*/
//Import Dataset (can be GPM, TRMM, or PRISM)
//To change dataset first replace the default ImageCollection ID for GPM with TRMM: 'TRMM/3B42' or PRISM: 'OREGONSTATE/PRISM/AN81d'
//Next replace all "GPM" with "TRMM" or "PRISM"
//Finally replace all "IRprecipitation" with "precipitation" for TRMM or "ppt" for PRISM
//Default ImageCollection ID for GPM - IMPORT
var GPM = ee.ImageCollection('NASA/GPM_L3/IMERG_V05');
//Build geometry polygons for clipping dataset
var Area = ee.Geometry.Polygon([
[[-110.57121276855469,36.79169061907076], [-110.56915283203125,36.63701909682385],
[-110.38719177246094,36.63867203824882], [-110.38581848144531,36.793340236044536],
[-110.57121276855469,36.79169061907076], [-110.08292198443087,36.52805313685172],
[-110.08253574633272,36.52760482676665], [-110.08199930452975,36.52794968090885],
[-110.0820636775461,36.528329018689554], [-110.08260011934908,36.52834626127172],
[-110.08277178072603,36.528225563115676], [-110.08292198443087,36.52805313685172]]
]);
var region = ee.Geometry.Polygon([
[[-110.08244991269748,36.5281481497273], [-110.08277177777927,36.52794985929219], [-110.08242845502537,36.52757051965205],
[-110.08194565740268,36.52781191782011], [-110.08199930158298,36.52806193655711], [-110.08244991269748,36.5281481497273]]
]);
//Create the application for filtering date
var app = {};
//creating the ui panel
app.createPanels = function(){
//intro panel creation
app.intro = {
panel: ui.Panel([
ui.Label({
value: 'GPM Virtual Rain Gauge',
style: {fontWeight:'bold', fontSize:'20px', margin:'10px 5 px'}
}),
ui.Label('This application creates virtual rain gauges from the GPM dataset.'),
ui.Label(' 1.) Type in your year-month-day time period of interest and then push [Execute].'),
ui.Label('2.) Wherever you click a chart showing the IR precipitation intensity based on the selected GPM pixel is created.'),
ui.Label('3.) If you would like to create a map showing the average rainfall for the time period of interest then push the [Make Map] button.'),
])
};
//filter controls setup
app.filters = {
startDate: ui.Textbox('YYYY-MM-DD', '2014-08-01'),
endDate: ui.Textbox('YYYY-MM-DD','2014-09-01'),
applybutton: ui.Button('Execute', app.applyFilters),
mapbutton: ui.Button('Make Map',app.createMap),
//chartButton: ui.Button('Make chart', app.makechart)
loadingLabel: ui.Label({
value:'Loading now....',
style: {stretch: 'vertical', color:'gray', shown:false}
})
};
//filter date panel
app.filters.panel = ui.Panel({
widgets:[
ui.Label('Date Range (YYYY-MM-DD)', {fontWeight:'bold'}),
ui.Label('Start Date', app.HELPER_TEXT_STYLE), app.filters.startDate,
ui.Label('End Date', app.HELPER_TEXT_STYLE), app.filters.endDate,
ui.Panel([
app.filters.applybutton,
app.filters.mapbutton,
// app.filters.chartButton,
app.filters.loadingLabel
], ui.Panel.Layout.flow('horizontal'))
],
style: app.SECTION_STYLE
});
};
//creating function w/in function eliminates bugs
app.create = function(){
//enables loading mode
app.setLoadingMode = function(enabled){
//enabled mode
app.filters.loadinglabel.set('shown',enabled);
//dependent widgets to run
var loadDependedntWidgets = [
app.filters.startDate,
app.filters.endDate,
app.filters.applyButton,
];
loadDependedntWidgets.forEach(function(widget){
widget.setDisabled(enabled);
});
};
//applies the filters that was input by the user
app.applyFilters = function(){
//app.setLoadingMode(true);
var filtered = ee.ImageCollection(app.COLLECTION_ID);
//filter the bounds to NAVA Area
filtered = filtered.filterBounds(Area);
//set filter varibles
var start = app.filters.startDate.getValue();
if (start) start = ee.Date(start);
var end = app.filters.endDate.getValue();
if (end) end = ee.Date(end);
if (start) filtered = filtered.filterDate(start, end);
//print values to make sure all is well
print(filtered);
//Refresh the map when execute happens
};
app.createMap = function(){
//Map.clear();
//Map.addLayer(Country);
var imageId = GPM.filterDate(app.filters.startDate.getValue(),app.filters.endDate.getValue());
if(imageId){
//if found create layer
var image = ee.ImageCollection(GPM).filterDate(app.filters.startDate.getValue(),app.filters.endDate.getValue()).select('IRprecipitation').filterBounds(region);
var visParams = {min: 0, max: 2, palette : ['#b2adac', '#00c3ff', '#0199f3', '#006cf3', '#0028f3'], opacity: .4};
Map.addLayer(image, visParams, 'GPM IR Precipitation Map');
}
// set position of panel
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});
// Create legend title
var legendTitle = ui.Label({
value: 'Precipitation Intensity',
style: {
fontWeight: 'bold',
fontSize: '18px',
margin: '0 0 4px 0',
padding: '0'
}
});
// Add the title to the panel
legend.add(legendTitle);
// Creates and styles 1 row of the legend.
var makeRow = function(color, name) {
// Create the label that is actually the colored box.
var colorBox = ui.Label({
style: {
backgroundColor: '#' + color,
// Use padding to give the box height and width.
padding: '8px',
margin: '0 0 4px 0'
}
});
// Create the label filled with the description text.
var description = ui.Label({
value: name,
style: {margin: '0 0 4px 6px'}
});
// return the panel
return ui.Panel({
widgets: [colorBox, description],
layout: ui.Panel.Layout.Flow('horizontal')
});
};
// Palette with the colors
var palette =['b2adac', '00c3ff', '0199f3', '006cf3', '0028f3'];
// name of the legend
var names = ['very light','light','moderate', 'heavy', 'very heavy'];
// Add color and and names
for (var i = 0; i < 5; i++) {
legend.add(makeRow(palette[i], names[i]));
}
// add legend to map (alternatively you can also print the legend to the console)
Map.add(legend)};
app.createClick = function(){
Map.onClick(function(coords) {
var panel1 = ui.Panel();
panel1.style().set({
width: '800px',
position: 'bottom-right'
});
Map.add(panel1);
//set chart display
var option ={
title: 'GPM IR Precipitation Intensity Over Time',
hAxis: {title:'time (months)'},
vAxis: {title:'precip. rate (mm/hr)'}
};
//panel1.clear();
var startyear = app.filters.startDate.getValue();
var endyear = app.filters.endDate.getValue();
print("in chart",startyear,endyear)
var point = ee.Geometry.Point(coords.lon, coords.lat);
//added startyear and endyear ^ then filtered it V now the chart doesn't time out looking at everyimage in time.
var chart = ui.Chart.image.series(ee.ImageCollection(GPM).filterDate(startyear,endyear).select('IRprecipitation'), point, ee.Reducer.mean(),300);
chart.setOptions(option);
panel1.add(chart);
});
};
};
//Forming the GPM constant to take values from
app.createConstants = function(){
app.COLLECTION_ID = GPM.select('IRprecipitation');
app.SECTION_STYLE = {margin: '20px 0 0 0'};
app.HELPER_TEXT_STYLE = {
margin: '8px 0 -3px 8px',
fontSize: '12px',
color: 'gray'
};
}
//Boot the application and create the interface table
app.boot = function() {
app.createConstants();
app.create();
app.createPanels();
app.createClick();
var main = ui.Panel({
widgets: [
app.intro.panel,
app.filters.panel
],
style: {width:'320px', padding: '8px'}
});
Map.setCenter(-110.3, 36.7, 11);
ui.root.insert(0, main);
app.applyFilters();
};
app.boot();