-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
487 lines (407 loc) · 23.2 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Bushfire Simulator</title>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css"/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css" />
<link rel="stylesheet" href="//api.mapbox.com/mapbox.js/v2.2.1/mapbox.css">
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-2">
<!-- <div class="row"> -->
<!-- <div class="col-sm-4 col-sm-offset-4"> -->
<img class="img img-responsive center-block" src="images/icon.png" style="padding: 2em" width="100%"/>
<!-- </div> -->
<!-- </div> -->
</div>
<div class="col-sm-10">
<div class="page-header">
<h1>Bushfire Simulator
<small>A Spaceapps2017 <a href="https://github.com/the-winter/spaceapps2017_matches">project</a> by team <a href="https://2017.spaceappschallenge.org/challenges/warning-danger-ahead/and-you-can-help-fight-fires/teams/matches/stream">Matches</a></small></h1>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-3 col-sm-offset-2">
<div class="buttons-group">
<button id="start" class="btn" type="button"><span class="glyphicon glyphicon-play"></span></button>
<button id="stop" class="btn" type="button"><span class="glyphicon glyphicon-stop"></span></button>
<button id="next" class="btn" type="button"><span class="glyphicon glyphicon-forward"></span></button>
<button id="reset" class="btn" type="button"><span class="glyphicon glyphicon-repeat"></span></button>
</div>
</div>
<div class="col-sm-3">
<div class="buttons-roup">
<!-- Move me -->
<label class="radio-inline">
<input type="radio" name="click-radio" id="click-radio-1" value="ignite" checked></input> ignite
<span class="glyphicon glyphicon-fire" aria-hidden="true"></span>
</label>
<label class="radio-inline">
<input type="radio" name="click-radio" id="click-radio-2" value="respond"> </input> firemen
<span class="glyphicon glyphicon-user" aria-hidden="true"></span>
</label>
</div>
</div>
<div class="col-sm-4">
<button class="pull-right">Register Burn</button>
</div>
</div>
<div class="row">
<div class="col-sm-2">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Conditions
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
<section>
<p>Foliage</p>
<ul>
<p class="checkbox-list">
<input type="checkbox" value="Dry" checked="checked"/> Dry
</p>
<p class="checkbox-list">
<input type="checkbox" value="Wet" /> Wet
</p>
<p class="checkbox-list">
<input type="checkbox" value="Dry" /> Dense
</p>
<p class="checkbox-list">
<input type="checkbox" value="Dry" /> Sparse
</p>
</ul>
</section>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Resources
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
<div class="form-group">
<label for="trucks">Trucks</label>
<input type="text" class="sidebar-input pull-right" id="trucks" aria-describedby="emailHelp" disabled="disabled" value="5">
</div>
<div class="form-group">
<label for="choppers">Choppers</label>
<input type="text" class="sidebar-input pull-right" id="choppers" aria-describedby="emailHelp" disabled="disabled" value="7">
</div>
<div class="form-group">
<label for="roads-traffic">Roads/Traffic</label>
<input type="text" class="sidebar-input pull-right" id="roads-traffic" aria-describedby="emailHelp" disabled="disabled" value="6">
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingThree">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Variables
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<div class="panel-body">
<div class="form-group">
<label for="humidity">Humidity</label>
<input type="text" class="sidebar-input pull-right" id="humidity" aria-describedby="emailHelp" disabled="disabled" value="15%">
</div>
<div class="form-group">
<label for="precipitation">Precepitation</label>
<input type="text" class="sidebar-input pull-right" id="precepitation" aria-describedby="emailHelp" disabled="disabled" value="5%">
</div>
<div class="form-group">
<label for="temperature">Temperature</label>
<input type="text" class="sidebar-input pull-right" id="temperature" aria-describedby="emailHelp" disabled="disabled" value="25°">
</div>
<div class="form-group">
<label for="windkm">Wind (km/h)</label>
<input type="text" class="sidebar-input pull-right" id="windkm" aria-describedby="emailHelp" disabled="disabled" value="141.62">
</div>
<div class="form-group">
<label for="wind-direction">Wind (direction)</label>
<input type="text" class="sidebar-input pull-right" id="wind-direction" aria-describedby="emailHelp" disabled="disabled" value="SSE">
</div>
</div>
</div>
</div>
</div>
<button><span>OK</span></button>
</div>
<div class="col-sm-10 div-padding">
<input type="text" class="location-input" value="Brigadoon, Western Australia 6069"/>
<form>
<div class="slider-div">
<input for="amount" oninput="amount.value=rangeInput.value" id="slider" type="range" min="0" max="240" name="rangeInput" disabled="disabled" value="0" />
Hours: <input oninput="rangeInput.value=amount.value" id= "slider-box" class="hours-box" type="text" value="0" name="amount" for="rangeInput" disabled="disabled" oninput="rangeInput.value=amount.value" />
</div>
</form>
<div id="canvases">
<!-- Hiden canvases used to generate rasters for leaflet, can be used for debugging -->
<canvas id="map" class="layer1 overlay"></canvas>
<canvas id="fuel" class="layer2 overlay"></canvas>
<canvas id="ash" class="layer3 overlay"></canvas>
<canvas id="fire" class="layer4 overlay"></canvas>
<canvas id="elevation" class="layer5 overlay"></canvas>
<canvas id="response" class="layer7 overlay"></canvas>
</div>
<div style="width:100%; height:500px; margin-top: 10px;" id="leaflet-map">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-10 col-sm-offset-2">
<div class="how-it-works">
<h2>About</h2>
<h3>Problem</h3>
Bush fires cause pervasive harm to our communities - they result in damage to wildlife, property, our economy, and worst of all loss of life.
<h3>Solution</h3>
Our application simulates bush fires using real data about the environment to identify preventative actions and ensure the safety of our communities.
<h3>Approach</h3>
This challenge implied creating a real-time fire response tool but instead we approached this problem as a prevention and minimisation problem. That is, a harm reduction solution which directly responds to the United Nations goal. This is because it is more effective to prevent and minimise harm than to response to it once it has already started. So we built a prototype that can identify how to better prepare for bush fires. At the moment there is no statistical feedback to inform communities if they have done enough to prevent the spread of bush fires. But now you can use our application to to verify the fire safety of any specific location using environmental data from NASA. By running our simulation and identifying preventative measures to take, communities are enabled to better prepare and reduce the harm that bush fires unveil, including economic, environmental and human losses.
<h3>Impact</h3>
Our bush fire simulation tool will identify preventative actions that will result in reduced harm to the community. This impact of this app is particularly relevant to regional Australia where vulnerable farmers, property owners and national parks need to regularly burn off excess plant matter to prevent the spread of fires. Using our app, users can clearly identify if their regular burn off is enough to suppress a fire without having to wait for the dangers of a real fire to test it. And then users can incorporate this feedback into the real world to minimise fire damage to their property and to the community.
<h3>Future Development</h3>
In the future we want to add the capability for users to register burn offs which would notify emergency services for monitoring. They could also register the completion of the burn off along with feedback about the environment that might be useful for emergency services. We’d also like to incorporate more information about the local emergency services response to better simulate how the fire might play out. Furthermore, NASA’s thermal sensors are only accurate to 375 metres. Having users register the location of the burn off could enable NASA to increase the accuracy of the sensors. We would also want to incorporate more advanced environmental data from NASA to increase the accuracy of our simulation.<p/>
Our vision for future UI and feature development is shown <a href="https://xd.adobe.com/view/78fe7f57-be6e-4761-a47d-40a7ee775607/">here</a>.
<h2>Authors</h2>
A <a href="https://2017.spaceappschallenge.org/">NASA Spaceapp2017</a> <a href="https://github.com/the-winter/spaceapps2017_matches">project</a> made by <a href="https://github.com/JaycobC">Jaycob</a>, <a href="https://github.com/the-winter">Ivana</a>, <a href="https://github.com/wassname">Mike</a>, and <a href="https://github.com/nicolaruprecht">Nicola</a> in Perth (team <a href="https://2017.spaceappschallenge.org/challenges/warning-danger-ahead/and-you-can-help-fight-fires/teams/matches/stream">Matches</a>).
<h2>Instructions</h2>
<ul>
<li>Click to light a fire</li>
<li>Double click to place a fire engine</li>
<li>Click to light a fire</li>
<li>press start to step the simulation </li>
</ul>
<h2>How it works</h2>
The fire burns fuel (<em>f</em>) which is taken from an estimate of vegetation. This is provided by <a href="https://explorer.earthengine.google.com/#detail/LANDSAT%2FLC8_L1T_ANNUAL_EVI"> an EVI index derived from NASA's Landsat-8 images</a>. Fire spreads uphill easily but struggles to spread downhill so we take into account elevation by using <a href="https://explorer.earthengine.google.com/#detail/USGS%2FSRTMGL1_003"> 30m resolution SRTM Digital elevation data</a>.<p/>
The equation which describes the fires chance to ignite a nearby tile is adapted from <a href="https://www.researchgate.net/publication/229624147_McArthur's_fire-danger_meters_expressed_as_equations"> Noble et al 1980</a>.
<pre>
T = I * W^2 * exp(0.069 *atan(dh/w)) * (FDI + 0.024 * V * cos(theta))
~= I * W^2 * exp(0.069 *dh/w) * (FDI + 0.024 * V * cos(theta))
</pre>
Where I is fire intensity, W is fuel weight, dh is the difference in height between tiles, w is the distance between tiles, V is wind velocity and theta describes the wind direction. FDI is the fire danger index which covers drought factor, temperature, and humidity. We use the small tan approximation to simplify the equation.<p/>
<em>Note that wind direction and velocity are not implemented yet.</em><p/>
</div>
<footer>
<span class="glyphicon glyphicon-copyright-mark"></span> Matches 2017.
</footer>
</div>
</div>
</div>
</body>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/4.8.0/d3.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<!-- mapping -->
<script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js"></script>
<script src="//api.mapbox.com/mapbox.js/v2.2.1/mapbox.js"></script>
<!-- We need matrices with convolution and reshape methods -->
<!-- <script src="//rawgit.com/waylonflinn/weblas/master/dist/weblas.js"></script> -->
<script src="//rawgit.com/nicolaspanel/numjs/893016ec40e62eaaa126e1024dbe250aafb3014b/dist/numjs.js"></script>
<!-- App engine and data -->
<script src="js/simulation.js"></script>
<script src="images/bridagadoon_20170429-065415_3857_60/metadata.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(".js-example-basic-single").select2();
});
</script>
<script type="text/javascript">
// parameters
var simulation
var fuel_src = 'images/bridagadoon_20170429-065415_3857_60/2017.EVI.png'
var elevation_src = 'images/bridagadoon_20170429-065415_3857_60/SRTMGL1_003.elevation_pixel_units.png'
var working = false
/**
* Load png images as an array pf [r,g,b,a,r1,g1,b1,a1,...]
* @param {String} image - image url
* @return {Array}
*/
function loadImage(image){
return new Promise(function(resolve, reject) {
// var canvas = document.createElement('canvas');
var img=new Image();
// https://jsfiddle.net/nicolaspanel/047gwg0q/
img.onload = function() {
// load using numpyjs
var data = nj.images.read(img)
resolve(data)
}
img.onerror=reject
img.src=image;
});
}
// load image into canvases
$(document).ready(function() {
/* leaflet setup */
var southWest = L.latLng(metadata.bounds[0][0],metadata.bounds[0][1]),
northEast = L.latLng(metadata.bounds[1][0],metadata.bounds[1][1]),
bounds = L.latLngBounds(southWest, northEast);
var canvas=document.getElementById('map');
// image_layer1.addTo(leafletMap);
var elevation_layer = new L.ImageOverlay(
canvas.toDataURL(),
bounds,
{opacity:0.5}
)
var fuel_layer = new L.ImageOverlay(
canvas.toDataURL(),
bounds,
{opacity:0.5,attribution:'based on NASA Landsat-8 satellite data'}
)
var ash_layer = new L.ImageOverlay(
canvas.toDataURL(),
bounds,
{opacity:0.5}
)
var fire_layer = new L.ImageOverlay(
canvas.toDataURL(),
bounds,
{opacity:0.5, interactive:true}
)
var response_layer = new L.ImageOverlay(
canvas.toDataURL(),
bounds,
{opacity:0.5, interactive:true}
)
L.mapbox.accessToken = 'pk.eyJ1IjoiZGlnaXRhbGdsb2JlIiwiYSI6ImNpc2t0ZG16NzA2Y2QydW53M2s0c2liNncifQ.YzEK6kmdCrtvssUfrncwKQ';
var base = L.mapbox.tileLayer('digitalglobe.nal0g75k')
var leafletMap = L.map('leaflet-map',{
center:metadata.point,
zoom:14,
maxBounds:bounds, // don't let user move outside bounds
// zoomControl: true,
maxZoom:16,
minZoom:4,
layers: [base,ash_layer,fire_layer,response_layer]
})
baseLayers = {
'DigitalGlobe Maps API: Recent Imagery':base
}
var overlays = {
'fire_layer':fire_layer,
'ash_layer':ash_layer,
'fuel_layer':fuel_layer,
'elevation_layer':elevation_layer,
'response_layer':response_layer
}
L.control.layers(baseLayers, overlays, {collapsed: true}).addTo(leafletMap);
L.control.scale().addTo(leafletMap);
/* there is probobly a better way but this works for now **/
function updateLayers(){
// convert each canvas to a png and load as a map overlay
if (elevation_layer._image) elevation_layer.setUrl(document.getElementById('elevation').toDataURL())
if (fuel_layer._image) fuel_layer.setUrl(document.getElementById('fuel').toDataURL())
if (ash_layer._image) ash_layer.setUrl(document.getElementById('ash').toDataURL())
if (fire_layer._image) fire_layer.setUrl(document.getElementById('fire').toDataURL())
if (response_layer._image) response_layer.setUrl(document.getElementById('response').toDataURL())
// fire_layer.bringToFront()
}
leafletMap.on('overlayadd',updateLayers)
var click_timeout = false
leafletMap.on('click',(e)=>{
var clickRadio = $('[name=click-radio]:checked').val()
if (clickRadio=='respond'){
simulation.respond(e)
simulation.display()
updateLayers()
}
else {
simulation.ignite(e)
simulation.display()
updateLayers()
}
})
// load elevation onto a canvas
var canvas=document.getElementById('elevation');
var im = new Image()
im.src=elevation_src
im.onload=function(){
// set size of all canvases
document.getElementById('canvases').querySelectorAll('canvas').forEach((canvas)=>{
canvas.width=this.width
canvas.height=this.height
})
var ctx = canvas.getContext('2d');
ctx.drawImage(this, 0, 0);
}
// load images
var canvas=document.getElementById('fire');
var prom = Promise.all([
loadImage(fuel_src),
loadImage(elevation_src),
loadImage(elevation_src),
]);
prom.then(([fuel,elev]) => {
// convert to float 32
fuel.dtype="float32"
elev.dtype="float32"
// scale fuel to 0-1 instead of pngs 0-255
fuel=fuel.multiply(1/255)
// HACK for some reason it's read inverted and this is a fix ??
// should fix this in the notebook
fuel= fuel.subtract(1).multiply(-1)
// crop to smallest
var canvas=document.getElementById('fire');
// init simulation
simulation = new Simulation(
canvas,
{
fuel:fuel,
elev:elev,
}
);
/* button hooks */
document.getElementById('start').onclick=function(){
simulation.start(5000, ()=>updateLayers())
}
document.getElementById('stop').onclick=function(){
simulation.stop()
}
document.getElementById('next').onclick=function(){
$('#next').button('loading') // FIXME doesn't work
simulation.tick()
simulation.display()
console.log(simulation.stats())
updateLayers()
$('#next').button('reset')
}
document.getElementById('reset').onclick=function(){
simulation = new Simulation(
canvas,
{
fuel:nj.images.rgb2gray(fuel),
elev:nj.images.rgb2gray(elev),
}
);
document.getElementById('slider').value=0;
document.getElementById('slider-box').value=0;
document.getElementById('tick').innterText="0"
updateLayers()
}
updateLayers()
})
})
</script>
</html>