forked from fitoprincipe/geetools-code-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud_masks_test
155 lines (139 loc) · 4.38 KB
/
cloud_masks_test
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
/**** Start of imports. If edited, may not auto-convert in the playground. ****/
var imageCollection = ee.ImageCollection("MODIS/006/MOD09GA");
/***** End of imports. If edited, may not auto-convert in the playground. *****/
/***
* Tests for cloud mask functions
*
* Author: Rodrigo E. Principe
* email: [email protected]
* License: MIT
*/
var s2mask = require('users/fitoprincipe/geetools:cloud_masks').sentinel2
var landsatSR = require('users/fitoprincipe/geetools:cloud_masks').landsatSR
var cloud = require('users/fitoprincipe/geetools:cloud_masks')
var show = function(colid, cloud_prop, viz, name, func, params, cloud_percent) {
var percent = cloud_percent || 40;
var cent = Map.getCenter();
var col = ee.ImageCollection(colid)
.filterBounds(cent)
.filterMetadata(cloud_prop, 'greater_than', percent)
//.filterDate('2017-01-01', '2017-03-01')
.sort(cloud_prop);
if (col.size().getInfo() !== 0) {
var img = ee.Image(col.first());
//var vis = {bands:['B8', 'B12', 'B4'], min:0, max:5000}
var masked = func(params)(img)
Map.addLayer(masked, viz, name+' masked');
Map.addLayer(img, viz, name+' NOT masked', false);
Map.centerObject(img)
}
else {
print('Collection is empty')
}
}
var sentinel2 = function(options) {
var opt = options || null
show('COPERNICUS/S2',
'CLOUDY_PIXEL_PERCENTAGE',
{bands:['B8', 'B12', 'B4'], min:0, max:5000},
'SENTINEL 2',
cloud.make.sentinel2,
opt)
}
var landsat8SR = function(options) {
var opt = options || null
show('LANDSAT/LC08/C01/T1_SR',
'CLOUD_COVER',
{bands:['B5', 'B7', 'B4'], min:0, max:5000},
'Landsat 8 SR',
cloud.make.landsatSR,
opt)
}
var landsat5SR = function(options) {
var opt = options || null
show('LANDSAT/LT05/C01/T1_SR',
'CLOUD_COVER',
{bands:['B4', 'B5', 'B3'], min:0, max:5000},
'Landsat 5 SR',
cloud.make.landsatSR,
opt)
}
var landsat7SR = function(options) {
var opt = options || null
show('LANDSAT/LE07/C01/T1_SR',
'CLOUD_COVER',
{bands:['B4', 'B5', 'B3'], min:0, max:5000},
'Landsat 7 SR',
cloud.make.landsatSR,
opt)
}
var landsat4SR = function(options) {
var opt = options || null
show('LANDSAT/LT04/C01/T1_SR',
'CLOUD_COVER',
{bands:['B4', 'B5', 'B3'], min:0, max:5000},
'Landsat 4 SR',
cloud.make.landsatSR,
opt)
}
var landsat4TOA = function(options) {
var opt = options || null
show('LANDSAT/LT04/C01/T1_TOA',
'CLOUD_COVER',
{bands:['B4', 'B5', 'B3'], min:0, max:0.5},
'Landsat 4 TOA',
cloud.make.landsatTOA,
opt)
}
var landsat5TOA = function(options) {
var opt = options || null
show('LANDSAT/LT05/C01/T1_TOA',
'CLOUD_COVER',
{bands:['B4', 'B5', 'B3'], min:0, max:0.5},
'Landsat 5 TOA',
cloud.make.landsatTOA,
opt)
}
var landsat7TOA = function(options) {
var opt = options || null
show('LANDSAT/LE07/C01/T1_TOA',
'CLOUD_COVER',
{bands:['B4', 'B5', 'B3'], min:0, max:0.5},
'Landsat 7 TOA',
cloud.make.landsatTOA,
opt)
}
var landsat8TOA = function(options) {
var opt = options || null
show('LANDSAT/LC08/C01/T1_TOA',
'CLOUD_COVER',
{bands:['B5', 'B7', 'B4'], min:0, max:0.5},
'Landsat 8 TOA',
cloud.make.landsatTOA,
opt)
}
var modis = function(date, options, name) {
var opt = options || null
var col = ee.ImageCollection('MODIS/006/MOD09GA')
var vis = {bands:['sur_refl_b02', 'sur_refl_b06', 'sur_refl_b01'], min:0, max:5000}
var d = date || '2017-03-01'
var eedate = ee.Date(d)
var n = name || 'MODIS TERRA 500m'
var filtered = col.filterDate(eedate, eedate.advance(1, 'day'))
if (filtered.size().getInfo() !== 0) {
var i = ee.Image(filtered.first())
var masked = cloud.make.modis(opt)(i)
Map.addLayer(masked, vis, n+' masked');
Map.addLayer(i, vis, n+' NOT masked', false);
}
else {
print('Collection is empty')
}
}
exports.sentinel2 = sentinel2
exports.landsat8SR = landsat8SR
exports.landsat5SR = landsat5SR
exports.landsat4SR = landsat4SR
exports.landsat7SR = landsat7SR
exports.landsat4TOA = landsat4TOA
exports.modis = modis