-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.js
180 lines (151 loc) · 4.64 KB
/
example.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
/*
Example: Calculating burn severity metrics for the 2017 Oak Fire
*/
var fire = require("users/aazuspan/geeTools:fire.js");
// L8 imagery prior to the fire
var prefire = ee.Image("LANDSAT/LC08/C01/T1_TOA/LC08_046031_20170628");
// L8 imagery one year after the fire
var postfire = ee.Image("LANDSAT/LC08/C01/T1_TOA/LC08_046031_20180701");
var severity = fire.calculateBurnSeverity(prefire, postfire, "B5", "B6");
Map.addLayer(
severity,
{ min: -250, max: 600, bands: ["preNBR", "postNBR", "postNBR"] },
"severity",
false
);
/*
Example: Calculating HLI from SRTM data.
*/
var hli = require("users/aazuspan/geeTools:HLI.js");
var srtm = ee.Image("CGIAR/SRTM90_V4");
var h = hli.hli(srtm);
Map.addLayer(h, { min: 0.5, max: 1 }, "HLI", false);
/*
Example: Calculating TPI and slope position
*/
var tpi = require("users/aazuspan/geeTools:TPI.js");
var aoi = ee.Geometry.Polygon(
[
[
[-123.92382561385939, 42.39507820959633],
[-123.92382561385939, 41.57642883612384],
[-122.83343254745314, 41.57642883612384],
[-122.83343254745314, 42.39507820959633],
],
],
null,
false
);
// Calculate slope in degrees
var slope = ee.Terrain.slope(srtm);
// Calculate a TPI image using a 300m kernel
var tpi300 = tpi.tpi(srtm, 300, "square", "meters");
// Reclassify TPI to discrete slope positions
var slopePosition300 = tpi.slopePosition(tpi300, slope, null, aoi, 100, 1e12);
Map.addLayer(slopePosition300, { min: 1, max: 6 }, "Slope Position", false);
/*
Example: Applying radiometric correction
*/
var radCor = require("users/aazuspan/geeTools:radiometricCorrection.js");
// Identify a reference dark object, such as deep water
var darkObject = ee.Geometry.Polygon(
[
[
[-124.74266276966597, 42.12268590007055],
[-124.74266276966597, 41.93396768286303],
[-124.52705608021284, 41.93396768286303],
[-124.52705608021284, 42.12268590007055],
],
],
null,
false
);
// Use Dark Object Subtraction to correct for atmospheric distortion
var prefireDOS = radCor.darkObjectSubtraction(prefire, darkObject, 30, 1e13);
var postfireDOS = radCor.darkObjectSubtraction(postfire, darkObject, 30, 1e13);
Map.addLayer(
prefireDOS,
{ min: 0, max: 0.4, bands: ["B5", "B4", "B3"] },
"Prefire DOS",
false
);
Map.addLayer(
postfireDOS,
{ min: 0, max: 0.4, bands: ["B5", "B4", "B3"] },
"Postfire DOS",
false
);
// Identify pseudo-invariant features between prefire and postfire images; in
// this case, ocean and a building.
var PIF = ee.Geometry.MultiPolygon([
[
[
[-124.73859734350975, 41.90979183965181],
[-124.73688072974022, 41.88551473447749],
[-124.71834130102928, 41.88628152101927],
[-124.7216028671914, 41.91426293134146],
],
],
[
[
[-122.87238706850988, 42.428688503225544],
[-122.87242998385412, 42.4279599378424],
[-122.8702842166422, 42.4279124224146],
[-122.87024130129797, 42.42865682664584],
],
],
]);
// Use pseudo-invariant features to match the histogram of postfire imagery to
// prefire imagery. All bands within each image must have the same projection,
// so a subset of bands are selected.
var postfireMatch = radCor.linearHistogramMatch(
postfire.select(["B5", "B4", "B3", "B2"]),
prefire.select(["B5", "B4", "B3", "B2"]),
PIF
);
Map.addLayer(
postfireMatch,
{ min: 0, max: 0.4, bands: ["B5", "B4", "B3"] },
"Postfire Matched",
false
);
/*
Example: Cloud masking Sentinel-2 imagery
*/
var cloudMasking = require("users/aazuspan/geeTools:cloudMasking.js");
// Load a Sentinel-2 image (1C or 2A)
var s2 = ee.Image("COPERNICUS/S2/20190113T190741_20190113T190736_T10TEK");
// Load the corresponding cloud probability image
var prob = ee.Image(
"COPERNICUS/S2_CLOUD_PROBABILITY/20190113T190741_20190113T190736_T10TEK"
);
var cloudMasked = cloudMasking.probabilityCloudMask(s2, prob);
Map.addLayer(s2, { bands: ["B4", "B3", "B2"], min: 0, max: 2000 }, "S2", false);
Map.addLayer(
cloudMasked,
{ bands: ["B4", "B3", "B2"], min: 0, max: 2000 },
"S2 masked",
false
);
/*
Example: Fire perimeter detection
*/
// Select an area near the 2020 Lionshead and Beachie Creek fires
var aoi = ee.Geometry.Point([-122.12284375769744, 44.729350689066244]).buffer(
50000
);
// Select a date range to generate daily fire perimeters for
var start = "2020-09-06";
var end = "2020-09-09";
// Use GOES imagery to generate a daily fire area ImageCollection
var collection = fire.periodicFireBoundaries(start, end, aoi, true);
// Convert the ImageCollection to a FeatureCollection of daily fire perimeters
var perimeters = fire.vectorizeBoundaryCollection(
collection,
250,
aoi,
1e12,
true,
500
);
Map.addLayer(perimeters, {}, "Fire perimeters", false);