forked from Dhruvi-Goyal/Tree-Health-Monitoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodal_change_analysis_ch.js
More file actions
793 lines (650 loc) · 33.6 KB
/
Copy pathmodal_change_analysis_ch.js
File metadata and controls
793 lines (650 loc) · 33.6 KB
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
// This script is for doing a modal analysis while analysing forest cover change over the years between any 2 given years.
// This is the updated modal computation, where we won't have missing data apart from the area where data is missing for all 3 years.
// It also gives the change quantification
// Set year_1 and year_2. These are the 2 years between which comparison has to be made
// Note that year_2 must be > year_1 and both must be of Integer type
var year_1 = 2017;
var year_2 = 2021;
var india_boundary = ee.FeatureCollection("projects/ee-mtpictd/assets/harsh/Agroclimatic_regions");
var agroclimaticZoneAcronymDict = {
'Eastern Plateau & Hills Region': 'EPAHR',
'Southern Plateau and Hills Region': 'SPAHR',
'East Coast Plains & Hills Region': 'ECPHR',
'Western Plateau and Hills Region': 'WPAHR',
'Central Plateau & Hills Region': 'CPAHR',
'Lower Gangetic Plain Region': 'LGPR',
'Middle Gangetic Plain Region': 'MGPR',
'Upper Gangetic Plain Region': 'UGPR',
'Trans Gangetic Plain Region': 'TGPR',
'Eastern Himalayan Region': 'EHR',
'Western Himalayan Region': 'WHR'
};
var acz = 'Eastern Plateau & Hills Region';
// var acz = 'Lower Gangetic Plain Region';
// var acz = 'Western Himalayan Region';
// var acz = 'Eastern Himalayan Region';
// var acz = 'Upper Gangetic Plain Region';
// var acz = 'Middle Gangetic Plain Region';
// var acz = 'Trans Gangetic Plain Region';
// var acz = 'Central Plateau & Hills Region';
// var acz = 'Western Plateau and Hills Region';
// var acz = 'Southern Plateau and Hills Region';
// var acz = 'East Coast Plains & Hills Region';
// Set the AOI
var aoi = india_boundary.filter(ee.Filter.eq('regionname', acz)).geometry();
// Set the change list according to the following:
// -2 -> Deforestation
// -1 -> Degradation
// 0 -> No Change
// 1 -> Improvement
// 2 -> Afforestation
// 3 -> Missing Data
var change_list = [-1, 1];
Map.addLayer(aoi, {'color': 'black'}, 'AOI');
Map.centerObject(aoi, 7);
var year_in_0 = String(year_1-1);
var year_in_1 = String(year_1);
var year_in_2 = String(year_1+1);
var year_fi_0 = String(year_2-1);
var year_fi_1 = String(year_2);
var year_fi_2 = String(year_2+1);
var tree_cover_in_0 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/tree_cover_' + year_in_0)
.filterBounds(aoi)
.mode()
.clip(aoi);
tree_cover_in_0 = tree_cover_in_0.rename(['label_' + year_in_0.slice(-2)]);
var tree_cover_in_1 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/tree_cover_' + year_in_1)
.filterBounds(aoi)
.mode()
.clip(aoi);
tree_cover_in_1 = tree_cover_in_1.rename(['label_' + year_in_1.slice(-2)]);
var tree_cover_in_2 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/tree_cover_' + year_in_2)
.filterBounds(aoi)
.mode()
.clip(aoi);
tree_cover_in_2 = tree_cover_in_2.rename(['label_' + year_in_2.slice(-2)]);
var tree_cover_fi_0 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/tree_cover_' + year_fi_0)
.filterBounds(aoi)
.mode()
.clip(aoi);
tree_cover_fi_0 = tree_cover_fi_0.rename(['label_' + year_fi_0.slice(-2)]);
var tree_cover_fi_1 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/tree_cover_' + year_fi_1)
.filterBounds(aoi)
.mode()
.clip(aoi);
tree_cover_fi_1 = tree_cover_fi_1.rename(['label_' + year_fi_1.slice(-2)]);
var tree_cover_fi_2 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/tree_cover_' + year_fi_2)
.filterBounds(aoi)
.mode()
.clip(aoi);
tree_cover_fi_2 = tree_cover_fi_2.rename(['label_' + year_fi_2.slice(-2)]);
tree_cover_in_0 = tree_cover_in_0.rename(['label_in_0']);
tree_cover_in_1 = tree_cover_in_1.rename(['label_in_1']);
tree_cover_in_2 = tree_cover_in_2.rename(['label_in_2']);
tree_cover_fi_0 = tree_cover_fi_0.rename(['label_fi_0']);
tree_cover_fi_1 = tree_cover_fi_1.rename(['label_fi_1']);
tree_cover_fi_2 = tree_cover_fi_2.rename(['label_fi_2']);
var tree_cover_initial = tree_cover_in_0.addBands(tree_cover_in_1).addBands(tree_cover_in_2);
tree_cover_initial = tree_cover_initial.unmask(-9999);
tree_cover_initial = tree_cover_initial.expression(
"((b('label_in_1')!=-9999)) ? (b('label_in_1'))"+
":((b('label_in_0')!=-9999) and (b('label_in_1')==-9999) and (b('label_in_2')!=-9999)) ? (b('label_in_0'))"+
":(-9999)"
).clip(aoi);
tree_cover_initial = tree_cover_initial.rename(['label']);
tree_cover_initial = tree_cover_initial.updateMask(tree_cover_initial.neq(-9999));
// print(tree_cover_initial);
var tree_cover_final = tree_cover_fi_0.addBands(tree_cover_fi_1).addBands(tree_cover_fi_2);
tree_cover_final = tree_cover_final.unmask(-9999);
tree_cover_final = tree_cover_final.expression(
"((b('label_fi_1')!=-9999)) ? (b('label_fi_1'))"+
":((b('label_fi_0')!=-9999) and (b('label_fi_1')==-9999) and (b('label_fi_2')!=-9999)) ? (b('label_fi_0'))"+
":(-9999)"
).clip(aoi);
tree_cover_final = tree_cover_final.rename(['label']);
tree_cover_final = tree_cover_final.updateMask(tree_cover_final.neq(-9999));
Map.addLayer(tree_cover_initial, {palette: ['white']}, 'tree cover initial');
Map.addLayer(tree_cover_final, {palette: ['white']}, 'tree cover final');
// CH visualizations
var ch_in_0 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/ch_' + year_in_0)
.filterBounds(aoi)
.mean()
.clip(aoi);
var ch_in_1 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/ch_' + year_in_1)
.filterBounds(aoi)
.mean()
.clip(aoi);
var ch_in_2 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/ch_' + year_in_2)
.filterBounds(aoi)
.mean()
.clip(aoi);
var ch_fi_0 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/ch_' + year_fi_0)
.filterBounds(aoi)
.mean()
.clip(aoi);
var ch_fi_1 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/ch_' + year_fi_1)
.filterBounds(aoi)
.mean()
.clip(aoi);
var ch_fi_2 = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/ch_' + year_fi_2)
.filterBounds(aoi)
.mean()
.clip(aoi);
var correction_img = ee.ImageCollection('projects/ee-mtpictd/assets/harsh/corrections_ch')
.filterBounds(aoi)
.mode()
.clip(aoi);
var correction_in_0 = correction_img.select(['ch_'+year_in_0, 'rh98_'+year_in_0, 'rh75_'+year_in_0, 'rh50_'+year_in_0]);
var correction_in_1 = correction_img.select(['ch_'+year_in_1, 'rh98_'+year_in_1, 'rh75_'+year_in_1, 'rh50_'+year_in_1]);
var correction_in_2 = correction_img.select(['ch_'+year_in_2, 'rh98_'+year_in_2, 'rh75_'+year_in_2, 'rh50_'+year_in_2]);
var correction_fi_0 = correction_img.select(['ch_'+year_fi_0, 'rh98_'+year_fi_0, 'rh75_'+year_fi_0, 'rh50_'+year_fi_0]);
var correction_fi_1 = correction_img.select(['ch_'+year_fi_1, 'rh98_'+year_fi_1, 'rh75_'+year_fi_1, 'rh50_'+year_fi_1]);
var correction_fi_2 = correction_img.select(['ch_'+year_fi_2, 'rh98_'+year_fi_2, 'rh75_'+year_fi_2, 'rh50_'+year_fi_2]);
correction_in_0 = correction_in_0.rename(['ch_in_0', 'rh98_in_0', 'rh75_in_0', 'rh50_in_0']);
correction_in_1 = correction_in_1.rename(['ch_in_1', 'rh98_in_1', 'rh75_in_1', 'rh50_in_1']);
correction_in_2 = correction_in_2.rename(['ch_in_2', 'rh98_in_2', 'rh75_in_2', 'rh50_in_2']);
correction_fi_0 = correction_fi_0.rename(['ch_fi_0', 'rh98_fi_0', 'rh75_fi_0', 'rh50_fi_0']);
correction_fi_1 = correction_fi_1.rename(['ch_fi_1', 'rh98_fi_1', 'rh75_fi_1', 'rh50_fi_1']);
correction_fi_2 = correction_fi_2.rename(['ch_fi_2', 'rh98_fi_2', 'rh75_fi_2', 'rh50_fi_2']);
var ch_in_0_ch = ch_in_0.select('ch_class');
ch_in_0_ch = ch_in_0_ch.addBands(correction_in_0);
ch_in_0_ch = ch_in_0_ch.unmask(-9999);
ch_in_0_ch = ch_in_0_ch.expression(
"((b('ch_in_0')!=b('ch_class')) and (b('ch_in_0')!=-9999)) ? (b('ch_in_0'))"+
":b('ch_class')"
).clip(aoi);
ch_in_0_ch = ch_in_0_ch.updateMask(ch_in_0_ch.neq(-9999));
ch_in_0_ch = ch_in_0_ch.rename(['ch_in_0_ch']);
var ch_in_0_rh98 = ch_in_0.select('rh98_class');
ch_in_0_rh98 = ch_in_0_rh98.addBands(correction_in_0);
ch_in_0_rh98 = ch_in_0_rh98.unmask(-9999);
ch_in_0_rh98 = ch_in_0_rh98.expression(
"((b('rh98_in_0')!=b('rh98_class')) and (b('rh98_in_0')!=-9999)) ? (b('rh98_in_0'))"+
":b('rh98_class')"
).clip(aoi);
ch_in_0_rh98 = ch_in_0_rh98.updateMask(ch_in_0_rh98.neq(-9999));
ch_in_0_rh98 = ch_in_0_rh98.rename(['ch_in_0_rh98']);
var ch_in_0_rh75 = ch_in_0.select('rh75_class');
ch_in_0_rh75 = ch_in_0_rh75.addBands(correction_in_0);
ch_in_0_rh75 = ch_in_0_rh75.unmask(-9999);
ch_in_0_rh75 = ch_in_0_rh75.expression(
"((b('rh75_in_0')!=b('rh75_class')) and (b('rh75_in_0')!=-9999)) ? (b('rh75_in_0'))"+
":b('rh75_class')"
).clip(aoi);
ch_in_0_rh75 = ch_in_0_rh75.updateMask(ch_in_0_rh75.neq(-9999));
ch_in_0_rh75 = ch_in_0_rh75.rename(['ch_in_0_rh75']);ch_in_0_rh75
var ch_in_0_rh50 = ch_in_0.select('rh50_class');
ch_in_0_rh50 = ch_in_0_rh50.addBands(correction_in_0);
ch_in_0_rh50 = ch_in_0_rh50.unmask(-9999);
ch_in_0_rh50 = ch_in_0_rh50.expression(
"((b('rh50_in_0')!=b('rh50_class')) and (b('rh50_in_0')!=-9999)) ? (b('rh50_in_0'))"+
":b('rh50_class')"
).clip(aoi);
ch_in_0_rh50 = ch_in_0_rh50.updateMask(ch_in_0_rh50.neq(-9999));
ch_in_0_rh50 = ch_in_0_rh50.rename(['ch_in_0_rh50']);
ch_in_0 = ch_in_0_ch.addBands(ch_in_0_rh98).addBands(ch_in_0_rh75).addBands(ch_in_0_rh50);
var ch_in_1_ch = ch_in_1.select('ch_class');
ch_in_1_ch = ch_in_1_ch.addBands(correction_in_1);
ch_in_1_ch = ch_in_1_ch.unmask(-9999);
ch_in_1_ch = ch_in_1_ch.expression(
"((b('ch_in_1')!=b('ch_class')) and (b('ch_in_1')!=-9999)) ? (b('ch_in_1'))"+
":b('ch_class')"
).clip(aoi);
ch_in_1_ch = ch_in_1_ch.updateMask(ch_in_1_ch.neq(-9999));
ch_in_1_ch = ch_in_1_ch.rename(['ch_in_1_ch']);
var ch_in_1_rh98 = ch_in_1.select('rh98_class');
ch_in_1_rh98 = ch_in_1_rh98.addBands(correction_in_1);
ch_in_1_rh98 = ch_in_1_rh98.unmask(-9999);
ch_in_1_rh98 = ch_in_1_rh98.expression(
"((b('rh98_in_1')!=b('rh98_class')) and (b('rh98_in_1')!=-9999)) ? (b('rh98_in_1'))"+
":b('rh98_class')"
).clip(aoi);
ch_in_1_rh98 = ch_in_1_rh98.updateMask(ch_in_1_rh98.neq(-9999));
ch_in_1_rh98 = ch_in_1_rh98.rename(['ch_in_1_rh98']);
var ch_in_1_rh75 = ch_in_1.select('rh75_class');
ch_in_1_rh75 = ch_in_1_rh75.addBands(correction_in_1);
ch_in_1_rh75 = ch_in_1_rh75.unmask(-9999);
ch_in_1_rh75 = ch_in_1_rh75.expression(
"((b('rh75_in_1')!=b('rh75_class')) and (b('rh75_in_1')!=-9999)) ? (b('rh75_in_1'))"+
":b('rh75_class')"
).clip(aoi);
ch_in_1_rh75 = ch_in_1_rh75.updateMask(ch_in_1_rh75.neq(-9999));
ch_in_1_rh75 = ch_in_1_rh75.rename(['ch_in_1_rh75']);ch_in_1_rh75
var ch_in_1_rh50 = ch_in_1.select('rh50_class');
ch_in_1_rh50 = ch_in_1_rh50.addBands(correction_in_1);
ch_in_1_rh50 = ch_in_1_rh50.unmask(-9999);
ch_in_1_rh50 = ch_in_1_rh50.expression(
"((b('rh50_in_1')!=b('rh50_class')) and (b('rh50_in_1')!=-9999)) ? (b('rh50_in_1'))"+
":b('rh50_class')"
).clip(aoi);
ch_in_1_rh50 = ch_in_1_rh50.updateMask(ch_in_1_rh50.neq(-9999));
ch_in_1_rh50 = ch_in_1_rh50.rename(['ch_in_1_rh50']);
ch_in_1 = ch_in_1_ch.addBands(ch_in_1_rh98).addBands(ch_in_1_rh75).addBands(ch_in_1_rh50);
// print(ch_in_1);
var ch_in_2_ch = ch_in_2.select('ch_class');
ch_in_2_ch = ch_in_2_ch.addBands(correction_in_2);
ch_in_2_ch = ch_in_2_ch.unmask(-9999);
ch_in_2_ch = ch_in_2_ch.expression(
"((b('ch_in_2')!=b('ch_class')) and (b('ch_in_2')!=-9999)) ? (b('ch_in_2'))"+
":b('ch_class')"
).clip(aoi);
ch_in_2_ch = ch_in_2_ch.updateMask(ch_in_2_ch.neq(-9999));
ch_in_2_ch = ch_in_2_ch.rename(['ch_in_2_ch']);
var ch_in_2_rh98 = ch_in_2.select('rh98_class');
ch_in_2_rh98 = ch_in_2_rh98.addBands(correction_in_2);
ch_in_2_rh98 = ch_in_2_rh98.unmask(-9999);
ch_in_2_rh98 = ch_in_2_rh98.expression(
"((b('rh98_in_2')!=b('rh98_class')) and (b('rh98_in_2')!=-9999)) ? (b('rh98_in_2'))"+
":b('rh98_class')"
).clip(aoi);
ch_in_2_rh98 = ch_in_2_rh98.updateMask(ch_in_2_rh98.neq(-9999));
ch_in_2_rh98 = ch_in_2_rh98.rename(['ch_in_2_rh98']);
var ch_in_2_rh75 = ch_in_2.select('rh75_class');
ch_in_2_rh75 = ch_in_2_rh75.addBands(correction_in_2);
ch_in_2_rh75 = ch_in_2_rh75.unmask(-9999);
ch_in_2_rh75 = ch_in_2_rh75.expression(
"((b('rh75_in_2')!=b('rh75_class')) and (b('rh75_in_2')!=-9999)) ? (b('rh75_in_2'))"+
":b('rh75_class')"
).clip(aoi);
ch_in_2_rh75 = ch_in_2_rh75.updateMask(ch_in_2_rh75.neq(-9999));
ch_in_2_rh75 = ch_in_2_rh75.rename(['ch_in_2_rh75']);ch_in_2_rh75
var ch_in_2_rh50 = ch_in_2.select('rh50_class');
ch_in_2_rh50 = ch_in_2_rh50.addBands(correction_in_2);
ch_in_2_rh50 = ch_in_2_rh50.unmask(-9999);
ch_in_2_rh50 = ch_in_2_rh50.expression(
"((b('rh50_in_2')!=b('rh50_class')) and (b('rh50_in_2')!=-9999)) ? (b('rh50_in_2'))"+
":b('rh50_class')"
).clip(aoi);
ch_in_2_rh50 = ch_in_2_rh50.updateMask(ch_in_2_rh50.neq(-9999));
ch_in_2_rh50 = ch_in_2_rh50.rename(['ch_in_2_rh50']);
ch_in_2 = ch_in_2_ch.addBands(ch_in_2_rh98).addBands(ch_in_2_rh75).addBands(ch_in_2_rh50);
var ch_fi_0_ch = ch_fi_0.select('ch_class');
ch_fi_0_ch = ch_fi_0_ch.addBands(correction_fi_0);
ch_fi_0_ch = ch_fi_0_ch.unmask(-9999);
ch_fi_0_ch = ch_fi_0_ch.expression(
"((b('ch_fi_0')!=b('ch_class')) and (b('ch_fi_0')!=-9999)) ? (b('ch_fi_0'))"+
":b('ch_class')"
).clip(aoi);
ch_fi_0_ch = ch_fi_0_ch.updateMask(ch_fi_0_ch.neq(-9999));
ch_fi_0_ch = ch_fi_0_ch.rename(['ch_fi_0_ch']);
var ch_fi_0_rh98 = ch_fi_0.select('rh98_class');
ch_fi_0_rh98 = ch_fi_0_rh98.addBands(correction_fi_0);
ch_fi_0_rh98 = ch_fi_0_rh98.unmask(-9999);
ch_fi_0_rh98 = ch_fi_0_rh98.expression(
"((b('rh98_fi_0')!=b('rh98_class')) and (b('rh98_fi_0')!=-9999)) ? (b('rh98_fi_0'))"+
":b('rh98_class')"
).clip(aoi);
ch_fi_0_rh98 = ch_fi_0_rh98.updateMask(ch_fi_0_rh98.neq(-9999));
ch_fi_0_rh98 = ch_fi_0_rh98.rename(['ch_fi_0_rh98']);
var ch_fi_0_rh75 = ch_fi_0.select('rh75_class');
ch_fi_0_rh75 = ch_fi_0_rh75.addBands(correction_fi_0);
ch_fi_0_rh75 = ch_fi_0_rh75.unmask(-9999);
ch_fi_0_rh75 = ch_fi_0_rh75.expression(
"((b('rh75_fi_0')!=b('rh75_class')) and (b('rh75_fi_0')!=-9999)) ? (b('rh75_fi_0'))"+
":b('rh75_class')"
).clip(aoi);
ch_fi_0_rh75 = ch_fi_0_rh75.updateMask(ch_fi_0_rh75.neq(-9999));
ch_fi_0_rh75 = ch_fi_0_rh75.rename(['ch_fi_0_rh75']);ch_fi_0_rh75
var ch_fi_0_rh50 = ch_fi_0.select('rh50_class');
ch_fi_0_rh50 = ch_fi_0_rh50.addBands(correction_fi_0);
ch_fi_0_rh50 = ch_fi_0_rh50.unmask(-9999);
ch_fi_0_rh50 = ch_fi_0_rh50.expression(
"((b('rh50_fi_0')!=b('rh50_class')) and (b('rh50_fi_0')!=-9999)) ? (b('rh50_fi_0'))"+
":b('rh50_class')"
).clip(aoi);
ch_fi_0_rh50 = ch_fi_0_rh50.updateMask(ch_fi_0_rh50.neq(-9999));
ch_fi_0_rh50 = ch_fi_0_rh50.rename(['ch_fi_0_rh50']);
ch_fi_0 = ch_fi_0_ch.addBands(ch_fi_0_rh98).addBands(ch_fi_0_rh75).addBands(ch_fi_0_rh50);
var ch_fi_1_ch = ch_fi_1.select('ch_class');
ch_fi_1_ch = ch_fi_1_ch.addBands(correction_fi_1);
ch_fi_1_ch = ch_fi_1_ch.unmask(-9999);
ch_fi_1_ch = ch_fi_1_ch.expression(
"((b('ch_fi_1')!=b('ch_class')) and (b('ch_fi_1')!=-9999)) ? (b('ch_fi_1'))"+
":b('ch_class')"
).clip(aoi);
ch_fi_1_ch = ch_fi_1_ch.updateMask(ch_fi_1_ch.neq(-9999));
ch_fi_1_ch = ch_fi_1_ch.rename(['ch_fi_1_ch']);
var ch_fi_1_rh98 = ch_fi_1.select('rh98_class');
ch_fi_1_rh98 = ch_fi_1_rh98.addBands(correction_fi_1);
ch_fi_1_rh98 = ch_fi_1_rh98.unmask(-9999);
ch_fi_1_rh98 = ch_fi_1_rh98.expression(
"((b('rh98_fi_1')!=b('rh98_class')) and (b('rh98_fi_1')!=-9999)) ? (b('rh98_fi_1'))"+
":b('rh98_class')"
).clip(aoi);
ch_fi_1_rh98 = ch_fi_1_rh98.updateMask(ch_fi_1_rh98.neq(-9999));
ch_fi_1_rh98 = ch_fi_1_rh98.rename(['ch_fi_1_rh98']);
var ch_fi_1_rh75 = ch_fi_1.select('rh75_class');
ch_fi_1_rh75 = ch_fi_1_rh75.addBands(correction_fi_1);
ch_fi_1_rh75 = ch_fi_1_rh75.unmask(-9999);
ch_fi_1_rh75 = ch_fi_1_rh75.expression(
"((b('rh75_fi_1')!=b('rh75_class')) and (b('rh75_fi_1')!=-9999)) ? (b('rh75_fi_1'))"+
":b('rh75_class')"
).clip(aoi);
ch_fi_1_rh75 = ch_fi_1_rh75.updateMask(ch_fi_1_rh75.neq(-9999));
ch_fi_1_rh75 = ch_fi_1_rh75.rename(['ch_fi_1_rh75']);ch_fi_1_rh75
var ch_fi_1_rh50 = ch_fi_1.select('rh50_class');
ch_fi_1_rh50 = ch_fi_1_rh50.addBands(correction_fi_1);
ch_fi_1_rh50 = ch_fi_1_rh50.unmask(-9999);
ch_fi_1_rh50 = ch_fi_1_rh50.expression(
"((b('rh50_fi_1')!=b('rh50_class')) and (b('rh50_fi_1')!=-9999)) ? (b('rh50_fi_1'))"+
":b('rh50_class')"
).clip(aoi);
ch_fi_1_rh50 = ch_fi_1_rh50.updateMask(ch_fi_1_rh50.neq(-9999));
ch_fi_1_rh50 = ch_fi_1_rh50.rename(['ch_fi_1_rh50']);
ch_fi_1 = ch_fi_1_ch.addBands(ch_fi_1_rh98).addBands(ch_fi_1_rh75).addBands(ch_fi_1_rh50);
var ch_fi_2_ch = ch_fi_2.select('ch_class');
ch_fi_2_ch = ch_fi_2_ch.addBands(correction_fi_2);
ch_fi_2_ch = ch_fi_2_ch.unmask(-9999);
ch_fi_2_ch = ch_fi_2_ch.expression(
"((b('ch_fi_2')!=b('ch_class')) and (b('ch_fi_2')!=-9999)) ? (b('ch_fi_2'))"+
":b('ch_class')"
).clip(aoi);
ch_fi_2_ch = ch_fi_2_ch.updateMask(ch_fi_2_ch.neq(-9999));
ch_fi_2_ch = ch_fi_2_ch.rename(['ch_fi_2_ch']);
var ch_fi_2_rh98 = ch_fi_2.select('rh98_class');
ch_fi_2_rh98 = ch_fi_2_rh98.addBands(correction_fi_2);
ch_fi_2_rh98 = ch_fi_2_rh98.unmask(-9999);
ch_fi_2_rh98 = ch_fi_2_rh98.expression(
"((b('rh98_fi_2')!=b('rh98_class')) and (b('rh98_fi_2')!=-9999)) ? (b('rh98_fi_2'))"+
":b('rh98_class')"
).clip(aoi);
ch_fi_2_rh98 = ch_fi_2_rh98.updateMask(ch_fi_2_rh98.neq(-9999));
ch_fi_2_rh98 = ch_fi_2_rh98.rename(['ch_fi_2_rh98']);
var ch_fi_2_rh75 = ch_fi_2.select('rh75_class');
ch_fi_2_rh75 = ch_fi_2_rh75.addBands(correction_fi_2);
ch_fi_2_rh75 = ch_fi_2_rh75.unmask(-9999);
ch_fi_2_rh75 = ch_fi_2_rh75.expression(
"((b('rh75_fi_2')!=b('rh75_class')) and (b('rh75_fi_2')!=-9999)) ? (b('rh75_fi_2'))"+
":b('rh75_class')"
).clip(aoi);
ch_fi_2_rh75 = ch_fi_2_rh75.updateMask(ch_fi_2_rh75.neq(-9999));
ch_fi_2_rh75 = ch_fi_2_rh75.rename(['ch_fi_2_rh75']);ch_fi_2_rh75
var ch_fi_2_rh50 = ch_fi_2.select('rh50_class');
ch_fi_2_rh50 = ch_fi_2_rh50.addBands(correction_fi_2);
ch_fi_2_rh50 = ch_fi_2_rh50.unmask(-9999);
ch_fi_2_rh50 = ch_fi_2_rh50.expression(
"((b('rh50_fi_2')!=b('rh50_class')) and (b('rh50_fi_2')!=-9999)) ? (b('rh50_fi_2'))"+
":b('rh50_class')"
).clip(aoi);
ch_fi_2_rh50 = ch_fi_2_rh50.updateMask(ch_fi_2_rh50.neq(-9999));
ch_fi_2_rh50 = ch_fi_2_rh50.rename(['ch_fi_2_rh50']);
ch_fi_2 = ch_fi_2_ch.addBands(ch_fi_2_rh98).addBands(ch_fi_2_rh75).addBands(ch_fi_2_rh50);
var initial_image = ch_in_0.addBands(ch_in_1).addBands(ch_in_2);
// print(initial_image);
var initial_image_ch = initial_image.select(['ch_in_0_ch', 'ch_in_1_ch', 'ch_in_2_ch']);
initial_image_ch = initial_image_ch.unmask(-9999);
initial_image_ch = initial_image_ch.expression(
"((b('ch_in_0_ch')==b('ch_in_2_ch')) and (b('ch_in_0_ch')!=-9999)) ? (b('ch_in_0_ch'))"+
":((b('ch_in_0_ch')==-9999 or b('ch_in_2_ch')==-9999) and (b('ch_in_1_ch')!=-9999)) ? (b('ch_in_1_ch'))"+
":((b('ch_in_0_ch')!=-9999 and b('ch_in_1_ch')==-9999 and b('ch_in_2_ch')==-9999)) ? (b('ch_in_0_ch'))"+
":((b('ch_in_1_ch')==-9999 and b('ch_in_2_ch')!=-9999) and (b('ch_in_0_ch')!=b('ch_in_2_ch'))) ? (b('ch_in_2_ch'))"+
":(b('ch_in_1_ch'))"
).clip(aoi);
initial_image_ch = initial_image_ch.rename(['ch_class']);
initial_image_ch = initial_image_ch.updateMask(initial_image_ch.neq(-9999));
var initial_image_rh98 = initial_image.select(['ch_in_0_rh98', 'ch_in_1_rh98', 'ch_in_2_rh98']);
initial_image_rh98 = initial_image_rh98.unmask(-9999);
initial_image_rh98 = initial_image_rh98.expression(
"((b('ch_in_0_rh98')==b('ch_in_2_rh98')) and (b('ch_in_0_rh98')!=-9999)) ? (b('ch_in_0_rh98'))"+
":((b('ch_in_0_rh98')==-9999 or b('ch_in_2_rh98')==-9999) and (b('ch_in_1_rh98')!=-9999)) ? (b('ch_in_1_rh98'))"+
":((b('ch_in_0_rh98')!=-9999 and b('ch_in_1_rh98')==-9999 and b('ch_in_2_rh98')==-9999)) ? (b('ch_in_0_rh98'))"+
":((b('ch_in_1_rh98')==-9999 and b('ch_in_2_rh98')!=-9999) and (b('ch_in_0_rh98')!=b('ch_in_2_rh98'))) ? (b('ch_in_2_rh98'))"+
":(b('ch_in_1_rh98'))"
).clip(aoi);
initial_image_rh98 = initial_image_rh98.rename(['rh98_class']);
initial_image_rh98 = initial_image_rh98.updateMask(initial_image_rh98.neq(-9999));
var initial_image_rh75 = initial_image.select(['ch_in_0_rh75', 'ch_in_1_rh75', 'ch_in_2_rh75']);
initial_image_rh75 = initial_image_rh75.unmask(-9999);
initial_image_rh75 = initial_image_rh75.expression(
"((b('ch_in_0_rh75')==b('ch_in_2_rh75')) and (b('ch_in_0_rh75')!=-9999)) ? (b('ch_in_0_rh75'))"+
":((b('ch_in_0_rh75')==-9999 or b('ch_in_2_rh75')==-9999) and (b('ch_in_1_rh75')!=-9999)) ? (b('ch_in_1_rh75'))"+
":((b('ch_in_0_rh75')!=-9999 and b('ch_in_1_rh75')==-9999 and b('ch_in_2_rh75')==-9999)) ? (b('ch_in_0_rh75'))"+
":((b('ch_in_1_rh75')==-9999 and b('ch_in_2_rh75')!=-9999) and (b('ch_in_0_rh75')!=b('ch_in_2_rh75'))) ? (b('ch_in_2_rh75'))"+
":(b('ch_in_1_rh75'))"
).clip(aoi);
initial_image_rh75 = initial_image_rh75.rename(['rh75_class']);
initial_image_rh75 = initial_image_rh75.updateMask(initial_image_rh75.neq(-9999));
var initial_image_rh50 = initial_image.select(['ch_in_0_rh50', 'ch_in_1_rh50', 'ch_in_2_rh50']);
initial_image_rh50 = initial_image_rh50.unmask(-9999);
initial_image_rh50 = initial_image_rh50.expression(
"((b('ch_in_0_rh50')==b('ch_in_2_rh50')) and (b('ch_in_0_rh50')!=-9999)) ? (b('ch_in_0_rh50'))"+
":((b('ch_in_0_rh50')==-9999 or b('ch_in_2_rh50')==-9999) and (b('ch_in_1_rh50')!=-9999)) ? (b('ch_in_1_rh50'))"+
":((b('ch_in_0_rh50')!=-9999 and b('ch_in_1_rh50')==-9999 and b('ch_in_2_rh50')==-9999)) ? (b('ch_in_0_rh50'))"+
":((b('ch_in_1_rh50')==-9999 and b('ch_in_2_rh50')!=-9999) and (b('ch_in_0_rh50')!=b('ch_in_2_rh50'))) ? (b('ch_in_2_rh50'))"+
":(b('ch_in_1_rh50'))"
).clip(aoi);
initial_image_rh50 = initial_image_rh50.rename(['rh50_class']);
initial_image_rh50 = initial_image_rh50.updateMask(initial_image_rh50.neq(-9999));
initial_image_ch = initial_image_ch.addBands(tree_cover_initial);
initial_image_ch = initial_image_ch.unmask(-9999);
// 4 denotes missing data
initial_image_ch = initial_image_ch.expression(
"((b('ch_class') == -9999) and (b('label') != -9999)) ? (4)"+
":b('ch_class')"
).clip(aoi);
initial_image_ch = initial_image_ch.rename(['ch_class']);
initial_image_ch = initial_image_ch.updateMask(initial_image_ch.neq(-9999));
initial_image = initial_image_ch.addBands(initial_image_rh98).addBands(initial_image_rh75)
.addBands(initial_image_rh50);
var final_image = ch_fi_0.addBands(ch_fi_1).addBands(ch_fi_2);
var final_image_ch = final_image.select(['ch_fi_0_ch', 'ch_fi_1_ch', 'ch_fi_2_ch']);
final_image_ch = final_image_ch.unmask(-9999);
final_image_ch = final_image_ch.expression(
"((b('ch_fi_0_ch')==b('ch_fi_2_ch')) and (b('ch_fi_0_ch')!=-9999)) ? (b('ch_fi_0_ch'))"+
":((b('ch_fi_0_ch')==-9999 or b('ch_fi_2_ch')==-9999) and (b('ch_fi_1_ch')!=-9999)) ? (b('ch_fi_1_ch'))"+
":((b('ch_fi_0_ch')!=-9999 and b('ch_fi_1_ch')==-9999 and b('ch_fi_2_ch')==-9999)) ? (b('ch_fi_0_ch'))"+
":((b('ch_fi_1_ch')==-9999 and b('ch_fi_2_ch')!=-9999) and (b('ch_fi_0_ch')!=b('ch_fi_2_ch'))) ? (b('ch_fi_2_ch'))"+
":(b('ch_fi_1_ch'))"
).clip(aoi);
final_image_ch = final_image_ch.rename(['ch_class']);
final_image_ch = final_image_ch.updateMask(final_image_ch.neq(-9999));
var final_image_rh98 = final_image.select(['ch_fi_0_rh98', 'ch_fi_1_rh98', 'ch_fi_2_rh98']);
final_image_rh98 = final_image_rh98.unmask(-9999);
final_image_rh98 = final_image_rh98.expression(
"((b('ch_fi_0_rh98')==b('ch_fi_2_rh98')) and (b('ch_fi_0_rh98')!=-9999)) ? (b('ch_fi_0_rh98'))"+
":((b('ch_fi_0_rh98')==-9999 or b('ch_fi_2_rh98')==-9999) and (b('ch_fi_1_rh98')!=-9999)) ? (b('ch_fi_1_rh98'))"+
":((b('ch_fi_0_rh98')!=-9999 and b('ch_fi_1_rh98')==-9999 and b('ch_fi_2_rh98')==-9999)) ? (b('ch_fi_0_rh98'))"+
":((b('ch_fi_1_rh98')==-9999 and b('ch_fi_2_rh98')!=-9999) and (b('ch_fi_0_rh98')!=b('ch_fi_2_rh98'))) ? (b('ch_fi_2_rh98'))"+
":(b('ch_fi_1_rh98'))"
).clip(aoi);
final_image_rh98 = final_image_rh98.rename(['rh98_class']);
final_image_rh98 = final_image_rh98.updateMask(final_image_rh98.neq(-9999));
var final_image_rh75 = final_image.select(['ch_fi_0_rh75', 'ch_fi_1_rh75', 'ch_fi_2_rh75']);
final_image_rh75 = final_image_rh75.unmask(-9999);
final_image_rh75 = final_image_rh75.expression(
"((b('ch_fi_0_rh75')==b('ch_fi_2_rh75')) and (b('ch_fi_0_rh75')!=-9999)) ? (b('ch_fi_0_rh75'))"+
":((b('ch_fi_0_rh75')==-9999 or b('ch_fi_2_rh75')==-9999) and (b('ch_fi_1_rh75')!=-9999)) ? (b('ch_fi_1_rh75'))"+
":((b('ch_fi_0_rh75')!=-9999 and b('ch_fi_1_rh75')==-9999 and b('ch_fi_2_rh75')==-9999)) ? (b('ch_fi_0_rh75'))"+
":((b('ch_fi_1_rh75')==-9999 and b('ch_fi_2_rh75')!=-9999) and (b('ch_fi_0_rh75')!=b('ch_fi_2_rh75'))) ? (b('ch_fi_2_rh75'))"+
":(b('ch_fi_1_rh75'))"
).clip(aoi);
final_image_rh75 = final_image_rh75.rename(['rh75_class']);
final_image_rh75 = final_image_rh75.updateMask(final_image_rh75.neq(-9999));
var final_image_rh50 = final_image.select(['ch_fi_0_rh50', 'ch_fi_1_rh50', 'ch_fi_2_rh50']);
final_image_rh50 = final_image_rh50.unmask(-9999);
final_image_rh50 = final_image_rh50.expression(
"((b('ch_fi_0_rh50')==b('ch_fi_2_rh50')) and (b('ch_fi_0_rh50')!=-9999)) ? (b('ch_fi_0_rh50'))"+
":((b('ch_fi_0_rh50')==-9999 or b('ch_fi_2_rh50')==-9999) and (b('ch_fi_1_rh50')!=-9999)) ? (b('ch_fi_1_rh50'))"+
":((b('ch_fi_0_rh50')!=-9999 and b('ch_fi_1_rh50')==-9999 and b('ch_fi_2_rh50')==-9999)) ? (b('ch_fi_0_rh50'))"+
":((b('ch_fi_1_rh50')==-9999 and b('ch_fi_2_rh50')!=-9999) and (b('ch_fi_0_rh50')!=b('ch_fi_2_rh50'))) ? (b('ch_fi_2_rh50'))"+
":(b('ch_fi_1_rh50'))"
).clip(aoi);
final_image_rh50 = final_image_rh50.rename(['rh50_class']);
final_image_rh50 = final_image_rh50.updateMask(final_image_rh50.neq(-9999));
final_image_ch = final_image_ch.addBands(tree_cover_final);
final_image_ch = final_image_ch.unmask(-9999);
// 4 denotes missing data
final_image_ch = final_image_ch.expression(
"((b('ch_class') == -9999) and (b('label') != -9999)) ? (4)"+
":b('ch_class')"
).clip(aoi);
final_image_ch = final_image_ch.rename(['ch_class']);
final_image_ch = final_image_ch.updateMask(final_image_ch.neq(-9999));
final_image = final_image_ch.addBands(final_image_rh98).addBands(final_image_rh75)
.addBands(final_image_rh50);
var palette =['FFA500', 'DEE64C', 'DEE64C','007500', '000000'];
Map.addLayer(initial_image, {bands:['ch_class'], min: 0, max: 4, palette: palette}, 'initial modal image ch');
Map.addLayer(final_image, {bands:['ch_class'], min: 0, max: 4, palette: palette}, 'final modal image ch');
initial_image = initial_image.unmask(-9999);
initial_image = initial_image.expression(
"((b('ch_class') == 4)) ? (8)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 0) and (b('rh98_class') == 0)) ? (0)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 0) and (b('rh98_class') == 1)) ? (1)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 1) and (b('rh98_class') == 0)) ? (2)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 1) and (b('rh98_class') == 1)) ? (3)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 0) and (b('rh98_class') == 0)) ? (4)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 0) and (b('rh98_class') == 1)) ? (5)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 1) and (b('rh98_class') == 0)) ? (6)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 1) and (b('rh98_class') == 1)) ? (7)"+
": ((b('rh50_class') != -9999) or (b('rh75_class') != -9999) and (b('rh98_class') != -9999)) ? (8)"+
":-9999"
).clip(aoi);
initial_image = initial_image.updateMask(initial_image.neq(-9999));
initial_image = initial_image.rename(['ch_class']);
final_image = final_image.unmask(-9999);
final_image = final_image.expression(
"((b('ch_class') == 4)) ? (8)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 0) and (b('rh98_class') == 0)) ? (0)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 0) and (b('rh98_class') == 1)) ? (1)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 1) and (b('rh98_class') == 0)) ? (2)"+
": ((b('rh50_class') == 0) and (b('rh75_class') == 1) and (b('rh98_class') == 1)) ? (3)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 0) and (b('rh98_class') == 0)) ? (4)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 0) and (b('rh98_class') == 1)) ? (5)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 1) and (b('rh98_class') == 0)) ? (6)"+
": ((b('rh50_class') == 1) and (b('rh75_class') == 1) and (b('rh98_class') == 1)) ? (7)"+
": ((b('rh50_class') != -9999) or (b('rh75_class') != -9999) and (b('rh98_class') != -9999)) ? (8)"+
":-9999"
).clip(aoi);
final_image = final_image.updateMask(final_image.neq(-9999));
final_image = final_image.rename(['ch_class']);
var palette =['FFA500', 'FFA500', 'DEE64C', 'DEE64C', 'DEE64C', 'DEE64C', '007500', '007500', '000000'];
Map.addLayer(initial_image, {bands:['ch_class'], min: 0, max: 8, palette: palette}, 'initial modal image ch');
Map.addLayer(final_image, {bands:['ch_class'], min: 0, max: 8, palette: palette}, 'final modal image ch');
var change = initial_image.addBands(final_image);
change = change.unmask(-9999);
// 3 denotes missing data
change = change.expression(
"((b('ch_class') == -9999) and (b('ch_class_1') != -9999)) ? (2)" +
": ((b('ch_class') != -9999) and (b('ch_class_1') == -9999)) ? (-2)"+
": ((b('ch_class') == 8) or (b('ch_class_1') == 8)) ? (3)" +
": ((b('ch_class') == b('ch_class_1')) and (b('ch_class') != -9999)) ? (0)" +
": ((b('ch_class') < b('ch_class_1')) and (b('ch_class') != -9999) and ((b('ch_class') <= 1) or (b('ch_class') >= 4))) ? (1)" +
": ((b('ch_class') > b('ch_class_1')) and (b('ch_class_1') != -9999)) ? (-1)" +
": ((b('ch_class') == 2) and ((b('ch_class_1') == 3) or (b('ch_class_1') == 6) or (b('ch_class_1') == 7))) ? (1)" +
": ((b('ch_class') == 3) and ((b('ch_class_1') == 6) or (b('ch_class_1') == 7))) ? (1)" +
": (((b('ch_class') == 2) or (b('ch_class') == 3)) and ((b('ch_class_1') == 4) or (b('ch_class_1') == 5))) ? (-1)"+
":-9999"
).clip(aoi);
change = change.updateMask(change.neq(-9999));
// var palette = ['red', 'orange', 'white', 'lightgreen', 'green', 'black'];
var palette = ['FF0000', 'FFA500', 'FFFFFF', '8AFF8A', '007500', '000000'];
Map.addLayer(change, {min: -2, max: 3, palette: palette}, 'change layer ch');
// Export modal initial image
Export.image.toAsset({
image: initial_image,
description: 'ch_' + year_in_1 + '_' + agroclimaticZoneAcronymDict[acz],
assetId: 'projects/ee-mtpictd/assets/dhruvi/modal_ch_' + year_in_1 + '/' + agroclimaticZoneAcronymDict[acz],
region: aoi,
scale: 25,
crs: 'EPSG:4326',
maxPixels: 10000000000
});
// Export modal final image
Export.image.toAsset({
image: final_image,
description: 'ch_' + year_fi_1 + '_' + agroclimaticZoneAcronymDict[acz],
assetId: 'projects/ee-mtpictd/assets/dhruvi/modal_ch_' + year_fi_1 + '/' + agroclimaticZoneAcronymDict[acz],
region: aoi,
scale: 25,
crs: 'EPSG:4326',
maxPixels: 10000000000
});
// Export CH change image
Export.image.toAsset({
image: change,
description: 'ch_change_' + agroclimaticZoneAcronymDict[acz],
assetId: 'projects/ee-mtpictd/assets/dhruvi/ch_change_' + year_in_1 + '_' + year_fi_1 + '/' + agroclimaticZoneAcronymDict[acz],
region: aoi,
scale: 25,
crs: 'EPSG:4326',
maxPixels: 10000000000
});
// Quantifying CH change classes statistics
// var change_chm = change;
// for (var c=0; c<change_list.length; c++) {
// var change_num = change_list[c];
// var img = change.updateMask(change.eq(change_num));
// var proj = ee.Projection('EPSG:4326');
// var grid = aoi.coveringGrid(proj, 100000);
// var total_count = ee.Number(0);
// var features = grid.getInfo().features;
// for (var i = 0; i < features.length; i++) {
// var feature = features[i];
// var coord = feature.geometry.coordinates[0];
// var poly = ee.Geometry.Polygon(coord);
// poly = poly.intersection(aoi);
// var count = img.reduceRegion({
// reducer: ee.Reducer.count(),
// geometry: poly,
// scale: 25,
// maxPixels: 1000000000
// });
// total_count = total_count.add(count.get('constant'));
// }
// print(total_count.multiply(625).divide(10000));
// }
// Adding Legend on GEE map
// set position of panel
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});
// Create legend title
var legendTitle = ui.Label({
value: 'Legend',
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',
border: '1px solid black'
}
});
// 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 =['FFA500', 'DEE64C', '007500', '000000'];
// var palette = ['FF0000', 'FFA500', 'FFFFFF', '8AFF8A', '007500', '000000'];
// name of the legend
var names = ['Short Trees', 'Medium Height Trees', 'Tall Trees', 'Missing Data'];
// var names = ['Deforestation','Degradation','No Change','Improvement','Afforestation','Missing Data'];
// Add color and and names
for (var i = 0; i < names.length; 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);