-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonthly_pair_compare
469 lines (406 loc) · 15.4 KB
/
monthly_pair_compare
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
var select_water_year = function(water_year){
if(water_year == 2015){
var methods={
itrc:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-itrc-metric/itrc_et_wy2015_v2-0-1")},
disalexi:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-disalexi/disalexi_et_wy2015_v2-1-0")},
ucdpt:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-ucd-priestley-taylor/ucd-pt_et_wy2015_v2-2-0")},
ucdmetric:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-ucd-metric/ucd-metric_et_wy2015_v2-1-0")},
sims:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-sims/sims_et_wy2015_v2-0-0")},
eto:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-weather/eto_wy2015")},
calsimetaw:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-calsimetaw/calsimetaw_et_wy2015_v2-0-0")},
detaw:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-detaw/detaw_et_wy2015_v2-0-1")},
};
var landIQ = ee.Image('users/ucd-cws-ee-data/ssj-delta-cu/ssj-landuse/landuse_2015_v2016-06-16');
var landcover = landIQ.select(['b2']).rename('level_2');
// fusion table with the station points 2015
var station_points = ee.FeatureCollection('ft:1vGYHsi1INwYjWj62xbrcQMewrRJQLbbE_jyqFwL7');
}
else if(water_year == 2016){
var methods={
itrc:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-itrc-metric/itrc_et_wy2016_v2-0-3")},
disalexi:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-disalexi/disalexi_et_wy2016_v2-1-0")},
ucdpt:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-ucd-priestley-taylor/ucd-pt_et_wy2016_v2-2-0")},
ucdmetric:{image:ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-ucd-metric/ucd-metric_et_wy2016_v2-1-0")},
sims:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-sims/sims_et_wy2016_v2-0-0")},
eto:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-weather/eto_wy2016")},
calsimetaw:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-calsimetaw/calsimetaw_et_wy2016_v2-0-2")},
detaw:{image: ee.Image("users/ucd-cws-ee-data/ssj-delta-cu/ssj-detaw/detaw_et_wy2016_v2-0-1")},
};
var landIQ = ee.Image('users/ucd-cws-ee-data/ssj-delta-cu/ssj-landuse/landuse_2016_v2017-04-25');
var landcover = landIQ.select(['b1']).rename('level_2');
// fusion table with the station points 2016
var station_points = ee.FeatureCollection('ft:1TedFG6u5KqIKghK23OyhPQC7ZIk-H_Qy74rkBvYL');
}
return({methods: methods, landcover: landcover, stations: station_points});
};//updated 6-6-17
var station_points_3x3 = ee.FeatureCollection('ft:1ZGZRl8zMoyLpsf6s1d8NsxNq0DCDS_BNldFPZvUV').select(["Station_ID", "Crop"]);
var DELTA = (function() {
function bbox() {
return delta_service_region().geometry().bounds();
}
function delta_service_region() {
var dsa_w_bbx = ee.FeatureCollection('ft:1OE_ETOZ9Wc2ffFa_B7YWTof9LP2YcuWNcOccSHO7');
var dsa = dsa_w_bbx.filterMetadata("name", "equals", "Delta Service Area");
return dsa;
}
return {
bbox:bbox,
delta_service_region:delta_service_region};
}());
var bbox=DELTA.bbox();
var dsa=DELTA.delta_service_region();
// select month
var month_bands = {
'October': 'b1',
'November': 'b2',
'December': 'b3',
'January': 'b4',
'February': 'b5',
'March': 'b6',
'April': 'b7',
'May': 'b8',
'June': 'b9',
'July': 'b10',
'August': 'b11',
'September': 'b12',
};
// Level 2 crops
var crops = {
"Alfalfa": 1,
"Safflower": 12,
"Sunflower": 22,
"Corn": 23,
"Rice": 24,
"Bush Berries": 108,
"Vineyards": 109,
"Potatoes": 246,
"Cucurbit": 277,
"Tomatoes": 278,
"Truck Crops": 279,
"Cherries": 403,
"Olives": 409,
"Pears": 412,
"Citrus": 425,
"Almonds": 500,
"Pistachios": 502,
"Walnuts": 503,
"Pasture": 800,
"Turf": 908,
"Semi-agricultural/ROW": 913,
"Other Deciduous": 914,
"Fallow": 916,
"Floating Vegetation": 2002,
"Forage Grass": 2003,
"Riparian": 2004,
"Upland Herbaceous": 2005,
"Urban": 2006,
"Water": 2007,
"Wet herbaceous/sub irrigated pasture": 2008,
"No Filter" : -1,
"Crop Filter": -2
};
// returns cropname (key) from the crop id (value) specified in the crop dictionary
var lookup_crop = function(cropid){
var crops_d = ee.Dictionary(crops);
var crops_d_reverse = ee.Dictionary.fromLists(crops_d.values().map(ee.String), crops_d.keys()); // values become keys
var cropname = crops_d_reverse.get(String(cropid));
return cropname;
};
// Masks to landcover category
var landcover_mask = function(image, landcover_cat, landcover){
var id = crops[landcover_cat];
if(id == -1){
return image;
}
else if(id == -2){
// mask by all the non-crops
var mask_bands = landcover.eq([0, 12, 22, 425, 2002, 2004, 2005, 2006, 2007]);
var mask = mask_bands.reduce(ee.Reducer.anyNonZero()).eq(0);
var image_masked = image.updateMask(mask);
return image_masked;
}
else{
var mask = landcover.eq(id);
var image_masked = image.updateMask(mask);
return image_masked;
}
};
var turn_layers_off = function(map_index){
var layers = maps[map_index].layers();
layers.forEach(function(layer){
//layer.setShown(false);
maps[map_index].layers().remove(layer);
});
};
var gyr=["64FF00", "8DFF00", "B6FF00", "DFFF00", "FFF500", "FFCC00", "FFA300", "FF7A00", "FF5100", "FF2800", "FF0000"];
// Create an empty image into which to paint the features, cast to byte.
var empty = ee.Image().byte();
// Paint all the polygon edges with the same number and width, display.
var outline = empty.paint({
featureCollection: station_points_3x3,
color: 1,
width: 3
});
// add the monthly ET band for the selected options
var add_monthly_band = function(selected_method, selected_month, selected_year, selected_crop, map_index){
turn_layers_off(map_index);
var methods = select_water_year(selected_year).methods;
var landcover = select_water_year(selected_year).landcover;
var et = methods[selected_method].image.divide(10);
// mask by selected crop
var et_masked = landcover_mask(et, selected_crop, landcover);
var ZlayerName = selected_method + " " + selected_month + " " + selected_crop;
var selected_band = month_bands[selected_month];
maps[map_index].addLayer(et_masked, {bands:[selected_band],min:0,max:10, palette: gyr}, ZlayerName);
//maps[map_index].addLayer(outline, {palette: '0B0157'}, "FieldStations-2016"); // locations of the field stations
return(et_masked);
};
/////////////////////////////////////////////////////////////////////////////////////////////////
// map controls
// Create two map objects and link them together
var maps = [ui.Map(), ui.Map()]; // map a is on the left, map b on the right
var linker = ui.Map.Linker(maps);
maps[0].setControlVisibility({zoomControl: true}); // Enable zooming on the top-left map.
maps[1].setControlVisibility({scaleControl: true}); // Show the scale (e.g. '500m') on the bottom-right map.
// Create a grid of maps.
var mapGrid = ui.Panel(
[
ui.Panel([maps[0]], null, {stretch: 'both'}),
ui.Panel([maps[1]], null, {stretch: 'both'})
],
ui.Panel.Layout.Flow('horizontal'), {stretch: 'both'}
);
// Add the maps and title to the ui.root.
ui.root.widgets().reset([mapGrid]);
ui.root.setLayout(ui.Panel.Layout.Flow('horizontal'));
////////////////////////////////////////////////////////////////////////////////////
// UI Settings
// a is the left map, b is the right map
// default setting for map a
var a = {
model: 'sims',
month: 'July',
wy: '2015',
crop: 'Crop Filter',
toplayer: select_water_year(2015).methods['sims'].image.divide(10),
};
// UI controls for map a
var selectMethod_a = ui.Select({
items: Object.keys(select_water_year(a.wy).methods),
placeholder: a.model,
onChange: function(key) {
a.model = key;
a.toplayer = add_monthly_band(a.model, a.month, a.wy, a.crop, 0);
}
});
var selectBand_a = ui.Select({
items: Object.keys(month_bands),
placeholder: a.month,
onChange: function(key) {
a.month = key;
a.toplayer = add_monthly_band(a.model, a.month, a.wy, a.crop, 0);
}
});
var selectWY_a = ui.Select({
items: ["2015", "2016"],
placeholder: a.wy,
onChange: function(key) {
a.wy = key;
a.toplayer = add_monthly_band(a.model, a.month, a.wy, a.crop, 0);
}
});
var selectCrop_a = ui.Select({
items: Object.keys(crops),
placeholder: a.crop,
onChange: function(key) {
a.crop = key;
a.toplayer = add_monthly_band(a.model, a.month, a.wy, a.crop, 0);
}
});
// default setting for map b
var b = {
model: 'ucdpt',
month: 'July',
wy: '2015',
crop: 'Crop Filter',
toplayer: select_water_year(2015).methods['ucdpt'].image.divide(10),
};
// UI controls for map b
var selectMethod_b = ui.Select({
items: Object.keys(select_water_year(b.wy).methods),
placeholder: b.model,
onChange: function(key) {
b.model = key;
b.toplayer = add_monthly_band(b.model, b.month, b.wy, b.crop, 1);
}
});
var selectMethod_b = ui.Select({
items: Object.keys(select_water_year(a.wy).methods),
placeholder: b.model,
onChange: function(key) {
b.model = key;
b.toplayer = add_monthly_band(b.model, b.month, b.wy, b.crop, 1);
}
});
var selectBand_b = ui.Select({
items: Object.keys(month_bands),
placeholder: b.month,
onChange: function(key) {
b.month = key;
b.toplayer = add_monthly_band(b.model, b.month, b.wy, b.crop, 1);
}
});
var selectWY_b = ui.Select({
items: ["2015", "2016"],
placeholder: b.wy,
onChange: function(key) {
b.wy = key;
b.toplayer = add_monthly_band(b.model, b.month, b.wy, b.crop, 1);
}
});
var selectCrop_b = ui.Select({
items: Object.keys(crops),
placeholder: b.crop,
onChange: function(key) {
b.crop = key;
b.toplayer = add_monthly_band(b.model, b.month, b.wy, b.crop, 1);
}
});
// Create a panel to hold to UI dropdowns
var panel = ui.Panel({
layout: ui.Panel.Layout.flow('horizontal'),
style: {
position: 'top-center',
padding: '5px 5px',
}
});
maps[0].setOptions("SATELLITE");
maps[0].add(panel);
maps[0].setControlVisibility(false);
panel.add(selectMethod_a);
panel.add(selectBand_a);
panel.add(selectWY_a);
panel.add(selectCrop_a);
add_monthly_band(a.model, a.month, a.wy, a.crop, 0);
var panel = ui.Panel({
layout: ui.Panel.Layout.flow('horizontal'),
style: {
position: 'top-center',
padding: '5px 5px'
}
});
maps[1].setOptions("SATELLITE");
maps[1].add(panel);
maps[1].setControlVisibility(false);
panel.add(selectMethod_b);
panel.add(selectBand_b);
panel.add(selectWY_b);
panel.add(selectCrop_b);
add_monthly_band(b.model, b.month, b.wy, b.crop, 1);
// Center the maps
maps[0].centerObject(bbox);
//////////////////////////////////////////////////////////////////////////////////////////
// legend
// set position of panel
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});
// Create legend title
var legendTitle = ui.Label({
value: 'ET (mm/day)',
style: {
fontWeight: 'bold',
fontSize: '14px',
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')
});
};
// names for the legend
var names = ['0','1.0', '2.0', '3.0', '4.0', '5.0', '6.0', '7.0', '8.0', '9.0', '10.0'];
// Add color and and names
for (var i = 0; i < gyr.length; i++) {
legend.add(makeRow(gyr[i], names[i]));
}
// add legend to map (alternatively you can also print the legend to the console)
maps[0].add(legend);
///////////////////////////////////////////////////////////////////////////////////////////////
// inspector
var inspector = ui.Panel({
layout: ui.Panel.Layout.flow('horizontal'),
style: {
position: 'bottom-center',
padding: '8px 8px',
shown: false,
}
});
maps[1].style().set('cursor', 'crosshair');
// Create the inspector panel, initially hiding it.
//var inspector = ui.Panel({style: {shown: false}});
maps[1].add(inspector);
// Register an onClick handler that populates and shows the inspector panel.
maps[1].onClick(function(coords) {
var point = ee.Geometry.Point(coords.lon, coords.lat);
var leftvalue = a.toplayer.reduceRegion(ee.Reducer.first(), point, 30).get(month_bands[a.month]);
var rightvalue = b.toplayer.reduceRegion(ee.Reducer.first(), point, 30).get(month_bands[b.month]);
var landtype = select_water_year(b.wy).landcover.reduceRegion(ee.Reducer.first(), point, 30).get('level_2'); // landuse will always be for this side. This could be an issue when two different water years are selected
var landtype_name = lookup_crop(landtype.getInfo());
var dot = ui.Map.Layer(point, {color: '0000FF'});
maps[0].layers().set(1, ui.Map.Layer(point, {color: '0000FF'}));
maps[1].layers().set(1, ui.Map.Layer(point, {color: '0000FF'}));
inspector.clear();
inspector.add(ui.Label('Left: ' + leftvalue.getInfo() + ' mm/day'));
inspector.add(ui.Label('Right: ' + rightvalue.getInfo() + ' mm/day'));
inspector.add(ui.Label(landtype_name.getInfo()));
inspector.add(ui.Button('X', function() {
inspector.style().set({shown: false});
}, false, {color:'#FF0000', padding: '-5px', textAlign: 'center'}));
inspector.style().set({shown: true,});
});
// make it work if the left map is clicked
maps[0].style().set('cursor', 'crosshair');
// Register an onClick handler that populates and shows the inspector panel.
maps[0].onClick(function(coords) {
var point = ee.Geometry.Point(coords.lon, coords.lat);
var leftvalue = a.toplayer.reduceRegion(ee.Reducer.first(), point, 30).get(month_bands[a.month]);
var rightvalue = b.toplayer.reduceRegion(ee.Reducer.first(), point, 30).get(month_bands[b.month]);
var landtype = select_water_year(b.wy).landcover.reduceRegion(ee.Reducer.first(), point, 30).get('level_2'); // landuse will always be for this side. This could be an issue when two different water years are selected
var landtype_name = lookup_crop(landtype.getInfo());
var dot = ui.Map.Layer(point, {color: '0000FF'});
maps[0].layers().set(1, ui.Map.Layer(point, {color: '0000FF'}));
maps[1].layers().set(1, ui.Map.Layer(point, {color: '0000FF'}));
inspector.clear();
inspector.add(ui.Label('Left: ' + leftvalue.getInfo() + ' mm/day'));
inspector.add(ui.Label('Right: ' + rightvalue.getInfo() + ' mm/day'));
inspector.add(ui.Label(landtype_name.getInfo()));
inspector.add(ui.Button('X', function() {
inspector.style().set({shown: false});
}, false, {color:'#FF0000', padding: '-5px', textAlign: 'center'}));
inspector.style().set({shown: true,});
});