-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMODIS_overlay
125 lines (92 loc) · 3.38 KB
/
MODIS_overlay
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
// Monterey_Fire
var Monterey_geom = ee.Geometry.Point(-121.7326, 36.3395)
var Monterey_date = ee.Date('2016-07-31')
// Landsat 8 collection
var ic = ee.ImageCollection('LANDSAT/LC8_L1T_TOA')
.filterBounds(Monterey_geom)
.filterDate(Monterey_date,'3000-01-01')
.select(['B2','B3','B4','B5','B6','B7'],['blue','green','red','nir','swir1','swir2']);
// HOTMAP detection
function HOTMAP(img) {
// wavebands
var n = img.select('nir')
var s1 = img.select('swir1')
var s2 = img.select('swir2')
// alpha detection
var a1 = s2.divide(s1).gt(1.4)
var a2 = s2.divide(n).gt(1.4)
var a3 = s2.gt(0.15)
var alpha = a1.and(a2).and(a3).rename('alpha')
// beta detection
var b1 = s1.divide(n).gt(2)
var b2 = s1.gt(0.5)
var beta = b1.and(b2).rename('beta')
// potential hot pixels
var potentialHot = alpha.or(beta)
var hotPixels = potentialHot.updateMask(potentialHot)
// hot pixel clusters (count alpha pixels)
var hotClusters = hotPixels.addBands(alpha).reduceToVectors({
eightConnected:true,
maxPixels:2e8,//might seem like a lot but MOST pixels are masked
reducer:ee.Reducer.count()
})
// hot pixel clusters must contain alpha pixels
var validHotClusters = hotClusters.filter(ee.Filter.gt('count', 0));
// Image properties
var fileID = img.get('system:index')
var satID = ee.String(fileID).slice(0,3)
var timestamp = img.get('system:time_start')
// Assign properties
var clusters = validHotClusters.map(function(feature) {
var clusterGeom = feature.geometry()
var clusterArea = feature.geometry().area(1) // i.e. to within 1 m2
var cluster = ee.Feature(clusterGeom,{
fileID:fileID,
satID:satID,
timestamp:timestamp,
area:clusterArea
})
return cluster
})
return clusters
}
var img = ee.Image(ic.first())
Map.addLayer(img.select(['swir2','swir1','nir']),{min:0,max:0.4},'infrared')
var hot = HOTMAP(img)
Map.addLayer(hot,{color:'red'},'hot_vectors')
Map.centerObject(Monterey_geom,10)
// Landsat geom, date and projection
var LandsatImg = img.select(['blue']);
var LandsatGeom = LandsatImg.geometry();
var LandsatDate = ee.Date(LandsatImg.get('system:time_start'));
var crs = LandsatImg.projection().crs()
//var scale = LandsatImg.projection().nominalScale()
// MODIS fire collection
var FIRMS = ee.ImageCollection('FIRMS');
//var crs = ee.Image(FIRMS.first()).projection().crs()
var scale = ee.Image(FIRMS.first()).projection().nominalScale()
// MODIS fire alerts within 24 hours of Landsat image acquisition
var startDate = LandsatDate.advance(-12,'hour');
var stopDate = LandsatDate.advance(+12,'hour');
var MODISalerts = FIRMS.select(['T21']).filterDate(startDate,stopDate)
// Reduce MODIS alerts to single binary image
var MODIScount = ee.Image(MODISalerts.count())
var MODISbinary = MODIScount.eq(MODIScount).rename('MODIS_binary_alert')
// Reproject alerts
var MODISreproject = MODISbinary.reproject({crs:crs,scale:scale})
// MODIS fire vectors
var MODISvectors = MODISreproject.reduceToVectors({
geometry: LandsatGeom,
eightConnected:true,
labelProperty:'modis_fire',
maxPixels:2e8,
crs:crs,
scale:scale
});
// MODIS display
var vectorDisplay = ee.Image(0).updateMask(0)
.clip(LandsatGeom)
.paint(MODISvectors, '000000', 3);
//Map.addLayer(MODISreproject, {palette: 'gray'})
Map.addLayer(vectorDisplay, {palette: '00FF00'}, 'MODIS fire alerts');
Map.setCenter(-121.7093, 36.3538,10)