-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
719 lines (639 loc) · 28.4 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
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
<!DOCTYPE html>
<html land="en">
<head>
<link rel="stylesheet" href="style.css">
<title>WoFS U-Net Tornado Viewer</title>
<script src="https://d3js.org/d3.v7.min.js"></script>
<script src="https://cdn.plot.ly/plotly-2.24.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.8.0/proj4.js"></script>
<script src="https://unpkg.com/@msgpack/msgpack@2.8.0/dist.es5+umd/msgpack.min.js"></script>
<!--<script src="https://cdn.jsdelivr.net/gh/nicolaspanel/numjs@0.15.1/dist/numjs.min.js"></script>-->
<script>
async function init() {
let run_dates = await read_valid_dates()
let date_sel = document.getElementById("model_run");
const formatTimeValue = d3.utcFormat("%Y%m%d%H%M");
const formatTimeLabel = d3.utcFormat("%Y %b %d %H%M UTC");
run_dates.forEach(function(rd) {
let default_selected = false;
let opt = new Option(formatTimeLabel(rd), formatTimeValue(rd), default_selected, default_selected);
date_sel.add(opt);
})
let msg_file_len = get_ens_file_strings("wofs_sparse_prob_",5,"ML_PREDICTED_TOR").length;
let json = {};
let progress_bar = document.getElementById('load_prog');
let progress_buff = 10;
progress_bar.max = msg_file_len*2 + progress_buff;
await load_data_parallel("wofs_sparse_prob_","ML_PREDICTED_TOR",0,1,json);
let wofs_x_length = 300;
let wofs_y_length = 300;
let resolution = 3000;
let radius = resolution / 2;
let orig_proj = "WGS84";
let base_proj = "+proj=lcc +lat_0=34.321392 +lon_0=-98.0134 +lat_1=30 +lat_2=60 +a=6370000 +b=6370000 +ellps=WGS84";
let base_transformer = proj4(base_proj, orig_proj);
let base_coord = base_transformer.inverse(json['fm_0']['se_coords']);
let wofs_proj = derive_new_proj(base_transformer, base_coord);
let transformer = proj4(wofs_proj, orig_proj);
let coord = transformer.inverse(json['fm_0']['se_coords']);
let spaghetti_traces = [];
let cell_i, cell_j;
let plot_d = {}
build_data_object(0,1,json,plot_d);
let total_grid_cells = json['fm_0']['MEM_median']['rows'].length;
let lon_array_m = create_coord_array(coord[0], wofs_x_length, resolution);
let lat_array_m = create_coord_array(coord[1], wofs_y_length, resolution);
let domain = get_wofs_domain_geom(lon_array_m, lat_array_m);
let plot_data = plot_d['0_median'];
let plot_geom = plot_data[0];
let plot_coords = plot_data[1];
let refl_data, total_grid_cells_r, plot_geom_r, plot_coords_r;
let config = {mapboxAccessToken: "pk.eyJ1IjoiYnBldHprZSIsImEiOiJjbGtsY2I1cTAwNnR1M21wY3kxZnk3NG0xIn0.VBcAZDXsltnUxPWsj6TJPA"};
let fcst_dates = get_fcst_date_range(5);
let map_data = {type: "choroplethmapbox",
locations: d3.range(total_grid_cells),
marker: {line: {width: 0},
opacity: 0.7},
z: json['fm_0']['MEM_median']['values'],
zmin: 0, zmax: 0.75,
colorbar: {x: -0.05, thickness: 20},
hoverinfo: "z",
customdata: plot_coords,
colorscale: 'YlGnBu',
// hovertemplate: "%{customdata}",
geojson: plot_geom};
let init_trace = {
x: [fcst_dates[Math.floor(msg_file_len/2)]],
y: [0.25],
text: ['Click on a probability grid cell to display a spaghetti plot of all ensemble members.'],
textfont: {size: 16},
mode: 'text',
xaxis: 'x2',
yaxis: 'y2',
type: 'scatter',
showlegend: false
};
wofs_domain = {
type: "scattermapbox",
showlegend: false,
mode: 'lines',
line: {color: 'grey', width: 2},
lon: domain[0],
lat: domain[1],
};
let cell_domain = {
type: "scattermapbox",
showlegend: false,
mode: 'lines',
line: {color: 'black', width: 2},
lon: null,
lat: null};
let all_traces = [map_data, init_trace, wofs_domain, cell_domain].flat();
let layout = {
title: {text: get_title_timestamp(), x: 0.05, font: {size: 22}},
mapbox: {
style: "dark",
layers: [
{
sourcetype: "geojson",
source: "data_geojson/geojson-counties-fips.json",
type: "line",
color: "#BA9DD5",
line: {"width": 0.25},
below: "traces"
},
{
sourcetype: "geojson",
source: "data_geojson/cnty_warn_bnds.json",
type: "line",
color: "yellow",
line: {"width": 0.4, opacity: 0.0},
below: "traces"
}
],
center: {lon: domain[2][0], lat: domain[2][1]},
zoom: 5},
showlegend: true,
grid: {rows: 1, columns: 2, pattern: 'independent'},
height: 800,
yaxis2: {range: [0, 1.0], title: {text:'Probability of Tornado', font: {size: 20}}},
xaxis2: {range: [fcst_dates[0], fcst_dates[fcst_dates.length-1]], title: {text:'Forecast Date/Time', font: {size: 20}}, tickformat: '%m-%d %H:%M', tickangle: 35},
// xaxis2: {range: get_timestamp(5), title: {text:'Forecast Minute', font: {size: 20}}, tickformat: '%H:%M:%S'},
shapes: [{type: 'line',
x0: fcst_dates[0],
y0: 0,
x1: fcst_dates[0],
y1: 1.0,
opacity: 0.3,
line: {color: 'rgba(0,128,26,0.68)',
width: 10,
opacity: 0.5}}],
legend: {
y: 1,
x: 0.95,
xaxis: 'x2',
yaxis: 'y2',
font: {size: 18},
},
annotations: [
{
y: 1,
yshift: 20,
text: 'Press . key to advance forward in time and , key to advance back in time',
showarrow: false,
align: "center",
valigh: "bottom",
}
]
};
Plotly.newPlot(document.getElementById("mapview"), all_traces, layout, config);
await load_data_parallel("wofs_sparse_prob_","ML_PREDICTED_TOR",1,msg_file_len,json);
build_data_object(1,msg_file_len,json,plot_d);
let fms = Object.keys(json);
let max_fm_str = fms[fms.length - 1];
let max_minutes = parseInt(max_fm_str.substring(3, max_fm_str.length));
let reflectivity = {};
await load_data_parallel("wofs_sparse_prob_","COMPOSITE_REFL_10CM",0,msg_file_len,reflectivity);
plot_r = {};
document.getElementById('refl').addEventListener('change', async function() {
build_data_object(0,msg_file_len,reflectivity,plot_r);
update();
});
document.getElementById('refl_alpha').addEventListener('change', update);
document.getElementById('mapview').on('plotly_click', get_spaghetti);
document.getElementById('ens_mem').addEventListener('change', update_mem);
document.getElementById('forecast_minute').addEventListener('change', update);
document.getElementById('model_run').addEventListener('change', update_init_time);
document.addEventListener('keypress', function(event) {
let code = event.code;
if (code === "Period") {update_time("forward");}
if (code === "Comma") {update_time("backward");}},
false);
progress_bar.value += progress_buff;
//Sleep
await new Promise(r => setTimeout(r, 500));
//Hide progress bar
document.getElementById('loading').style.display = "none";
async function update() {
let trace = select_trace(json, plot_d)
plot_geom = trace[1][0]
plot_coords = trace[1][1]
let trace_values = trace[0]
total_grid_cells = trace_values['rows'].length
let minuteIdx = document.getElementById("forecast_minute").selectedIndex;
let refl_alpha = document.getElementById("refl_alpha").value / 100
map_data = {type: "choroplethmapbox",
locations: d3.range(total_grid_cells),
marker: {line: {width: 0},
opacity: 0.7},
z: trace_values['values'],
zmin: 0, zmax: 0.75,
colorbar: {x: -0.05, thickness: 20},
hoverinfo: "z",
colorscale: 'YlGnBu',
customdata: plot_coords,
geojson: plot_geom};
wofs_domain = {
type: "scattermapbox",
showlegend: false,
mode: 'lines',
line: {color: 'grey', width: 2},
lon: domain[0],
lat: domain[1]};
fcst_dates = get_fcst_date_range(5);
layout['xaxis2']['range'] = [fcst_dates[0], fcst_dates[fcst_dates.length-1]];
layout["title"]["text"] = get_title_timestamp()
layout["shapes"][0]["x0"] = fcst_dates[minuteIdx];
layout["shapes"][0]["x1"] = fcst_dates[minuteIdx];
if (document.getElementById("refl").checked) {
let trace_r = select_trace(reflectivity, plot_r)
plot_geom_r = trace_r[1][0]
plot_coords_r = trace_r[1][1]
let trace_values_r = trace_r[0]
total_grid_cells_r = trace_values_r['rows'].length
refl_data = {type: "choroplethmapbox",
locations: d3.range(total_grid_cells_r),
marker: {line: {width: 0},
opacity: refl_alpha},
z: trace_values_r['values'],
zmin: 0, zmax: 80,
colorbar: {x: 0.22, y: -0.1, orientation: 'h', thickness: 15, len: 0.45},
hoverinfo: "skip",
customdata: plot_coords_r,
colorscale: 'Jet',
geojson: plot_geom_r};
all_traces = [map_data, refl_data, spaghetti_traces, wofs_domain, cell_domain].flat();
} else { all_traces = [map_data, spaghetti_traces, wofs_domain, cell_domain].flat();}
Plotly.react(document.getElementById("mapview"), all_traces, layout);
}
function derive_new_proj(base_transformer, coord) {
let center_proj_x = coord[1] + (3000 * 150) + 1500
let center_proj_y = coord[0] + (3000 * 150) + 1500
let center_lonlat = base_transformer.forward([center_proj_y, center_proj_x])
let proj ="+proj=lcc +lat_0=" + center_lonlat[1] + " +lon_0=" + center_lonlat[0] + " +lat_1=30 +lat_2=60 +a=6370000 +b=6370000 +ellps=WGS84";
return proj
}
function get_selected_cell_geom(i, j, lon_array_m, lat_array_m) {
let geom = create_geom(i, j, lon_array_m, lat_array_m)
let lons = geom.map(item => item[0])
let lats = geom.map(item => item[1])
cell_domain = {
type: "scattermapbox",
showlegend: false,
mode: 'lines',
line: {color: 'red', width: 2},
lon: lons,
lat: lats,
hoverinfo: "skip"};
return cell_domain}
function get_wofs_domain_geom(lon_array_m, lat_array_m) {
let se = transformer.forward([lon_array_m[0], lat_array_m[0]]);
let sw = transformer.forward([lon_array_m[wofs_x_length - 1], lat_array_m[0]]);
let nw = transformer.forward([lon_array_m[wofs_x_length - 1], lat_array_m[wofs_y_length - 1]]);
let ne = transformer.forward([lon_array_m[0], lat_array_m[wofs_y_length - 1]]);
let center = transformer.forward([lon_array_m[Math.floor(wofs_x_length / 2)], lat_array_m[Math.floor(wofs_y_length / 2)]])
let lons = [se[0], sw[0], nw[0], ne[0], se[0]]
let lats = [se[1], sw[1], nw[1], ne[1], se[1]]
return [lons, lats, center]
}
function select_trace(data, geom) {
let member = document.getElementById("ens_mem").value
let time = document.getElementById("forecast_minute").value
let p = data["fm_" + String(parseInt(time))]['MEM_' + member]
let geo = geom[String(parseInt(time)) + "_" + member]
return [p, geo]
}
function build_traces(trace_data) {
let all_traces = []
let forecast_minutes = get_fcst_date_range(5);
for (let i=1; i<=trace_data.length; i++) {
var trace = {
x: forecast_minutes,
y: trace_data[i],
xaxis: 'x2',
yaxis: 'y2',
type: 'scatter',
showlegend: false,
line: {color: 'lightgrey', width: 1}
};
all_traces.push(trace)
}
var mean = {
name: "Mean",
x: forecast_minutes,
y: trace_data["ens_mean"],
xaxis: 'x2',
yaxis: 'y2',
type: 'scatter',
line: {color: 'black', width: 4}
};
all_traces.push(mean)
var median = {
name: 'Median',
x: forecast_minutes,
y: trace_data["ens_median"],
xaxis: 'x2',
yaxis: 'y2',
type: 'scatter',
line: {color: 'black', width: 2, dash: 'dot'}
};
all_traces.push(median)
return all_traces
}
async function get_spaghetti(point_data) {
let pt = (point_data.points || [])[0]
let index = pt.customdata
cell_i = index[0]
cell_j = index[1]
let spaghetti_data = await spaghetti(cell_i, cell_j)
spaghetti_traces = build_traces(spaghetti_data)
cell_domain = get_selected_cell_geom(index[0], index[1], lon_array_m, lat_array_m)
if (document.getElementById("refl").checked) {
all_traces = [map_data, refl_data, spaghetti_traces, wofs_domain, cell_domain].flat();
} else { all_traces = [map_data, spaghetti_traces, wofs_domain, cell_domain].flat();}
Plotly.react(document.getElementById("mapview"), all_traces, layout);
}
async function spaghetti(i, j) {
const calc_mean = array => array.reduce((a, b) => a + b) / array.length
const calc_median = (arr) => {return arr.slice().sort((a, b) => a - b)[Math.floor(arr.length / 2)]; };
let d = {'length': 18, 'ens_mean': [], 'ens_median': []}
for (let m of d3.range(0, max_minutes + 5, 5)) {
let fm = "fm_" + m
let f = json[fm]
let ens_all_ts = []
for (mem=1; mem<19; mem++) {
if (m===0) { d[mem] = [] }
var member = "MEM_" + String(mem)
var found = false
let row_indices = f[member]['rows'].flatMap((x, z) => x === i ? z : [])
for (index=0; index<row_indices.length; index++) {
if (f[member]['columns'][row_indices[index]] === j) {
d[mem].push(f[member]['values'][row_indices[index]])
found = true
}
}
if (found === false) { d[mem].push(0) }
ens_all_ts.push(d[mem][m/5])
}
let mean_ens = calc_mean(ens_all_ts)
let median_ens = calc_median(ens_all_ts)
d['ens_mean'].push(mean_ens)
d['ens_median'].push(median_ens)
}
return d
}
function get_ens_file_strings(file_prefix, interval, variable) {
const formatTime = d3.timeFormat("%Y%m%d%H%M00");
var datetime = document.getElementById("model_run").value;
var year = datetime.substring(0, 4);
var month = parseInt(datetime.substring(4, 6)) - 1
var day = datetime.substring(6, 8)
var start_hour = datetime.substring(8, 10)
var start_min = datetime.substring(10, 12)
var start_hour_int = parseInt(start_hour)
if (start_hour_int <=4)
{
var start_date = new Date(year, month, day, start_hour, start_min);
start_date = new Date(start_date.getTime() + 86400000);
}
else
{
start_date = new Date(year, month, day, start_hour, start_min);
}
end_date = new Date(start_date.getTime() + 3 * 3600000 + 5 * 60000)
console.log("Start and End dates");
console.log(start_date);
console.log(end_date)
var end_hour = end_date.getHours()
var date_range = d3.timeMinutes(start_date,
end_date, interval)
console.log("Date Range")
console.log(date_range)
let file_list = [];
let init_time = document.getElementById("model_run").value.substring(0, 8)
date_range.forEach(function(x) {file_list.push("https://wofsdltornado.blob.core.windows.net/wofs-dl-preds/"
+ init_time + start_hour + start_min + "/" + file_prefix + formatTime(x) + "_" + variable + ".msgpk")});
console.log(file_list);
return file_list;
}
// function get_timestamp(interval) {
//
// const formatTime = d3.timeFormat("%H%M")
// var datetime = document.getElementById("model_run").value
// var year = datetime.substring(0, 4)
// var month = parseInt(datetime.substring(4, 6)) - 1
// var day = datetime.substring(6, 8)
// var start_hour = datetime.substring(8, 10)
// var end_hour = parseInt(start_hour) + 3
// var date_range = d3.timeMinutes(new Date(year, month, day, start_hour, 0),
// new Date(year, month, day, end_hour, 5), interval)
// return date_range;
// }
async function read_valid_dates(valid_init_hours=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23])
{
let date_filename = "https://wofsdltornado.blob.core.windows.net/wofs-dl-preds/available_dates.csv";
console.log(date_filename)
let date_resp = await fetch(date_filename);
let date_str = await date_resp.text();
let run_date_strs = date_str.split("\n");
let dates = [];
for (let i=0; i< run_date_strs.length; i++) {
dates.push(new Date(Date.UTC(parseInt(run_date_strs[i].substring(0, 4)),
parseInt(run_date_strs[i].substring(4, 6)) -1,
parseInt(run_date_strs[i].substring(6, 8)),
parseInt(run_date_strs[i].substring(8, 10)),
parseInt(run_date_strs[i].substring(10, 12)))
));
}
dates = dates.filter(function(d) {return valid_init_hours.includes(d.getUTCHours());});
dates = dates.reverse();
return dates;
}
async function load_data_parallel(file_prefix, variable, start, end, json_out) {
var file_list = get_ens_file_strings(file_prefix, 5, variable).slice(start,end)
return Promise.all(file_list.map(url => fetch(url)))
.then(responses => Promise.all(responses.map(response => MessagePack.decodeAsync(response.body))))
.then(messages => {
j = start
for (let i=0; i<messages.length; i++) {
progress_bar.value += 1
let key = "fm_" + String(j*5)
json_out[key] = messages[i]
j += 1
}
});
}
function build_data_object(start,end,data,obj_dict_out) {
let member = document.getElementById("ens_mem").value
let coord = transformer.inverse(data['fm_0']['se_coords'])
let lon_array_m = create_coord_array(coord[0], wofs_x_length, resolution)
let lat_array_m = create_coord_array(coord[1], wofs_y_length, resolution)
for (let i of d3.range(start, end)) {
let minutes = i*5
let subset = data["fm_" + minutes]["MEM_" + member]
let plot_data = create_geom_object(subset["rows"], subset["columns"], lon_array_m, lat_array_m)
obj_dict_out[minutes + "_" + member] = plot_data
}
}
function update_mem() {
plot_d = {};
build_data_object(0,msg_file_len,json,plot_d);
if (document.getElementById("refl").checked) {
plot_r = {};
build_data_object(0,msg_file_len,reflectivity,plot_r);
}
update();
}
async function update_init_time() {
document.getElementById("refl").checked = false;
msg_file_len = get_ens_file_strings("wofs_sparse_prob_",5,"ML_PREDICTED_TOR").length;
json = {};
await load_data_parallel("wofs_sparse_prob_","ML_PREDICTED_TOR",0,msg_file_len,json);
reflectivity = {};
await load_data_parallel("wofs_sparse_prob_","COMPOSITE_REFL_10CM",0,msg_file_len,reflectivity);
base_coord = base_transformer.inverse(json['fm_0']['se_coords']);
wofs_proj = derive_new_proj(base_transformer, base_coord);
transformer = proj4(wofs_proj, orig_proj);
coord = transformer.inverse(json['fm_0']['se_coords']);
lon_array_m = create_coord_array(coord[0], wofs_x_length, resolution);
lat_array_m = create_coord_array(coord[1], wofs_y_length, resolution);
domain = get_wofs_domain_geom(lon_array_m, lat_array_m);
layout["mapbox"]["center"] = {lon: domain[2][0], lat: domain[2][1]};
layout["mapbox"]["zoom"] = 5
fms = Object.keys(json);
max_fm_str = fms[fms.length - 1];
max_minutes = parseInt(max_fm_str.substring(3, max_fm_str.length));
plot_d = {};
build_data_object(0,msg_file_len,json,plot_d);
let spaghetti_data = await spaghetti(cell_i, cell_j)
spaghetti_traces = build_traces(spaghetti_data)
await update();
}
function create_coord_array(coord, len, resolution) {
let array = new Array(len);
for (let i=0; i<len; i++) { array[i] = coord + (resolution * i); }
return array
}
function get_title_timestamp() {
var datetime = document.getElementById("model_run").value
var year = datetime.substring(0, 4)
var month = parseInt(datetime.substring(4, 6)) - 1
var day = datetime.substring(6, 8)
var hour = datetime.substring(8, 10)
var minute = datetime.substring(10, 12)
var forecast_minutes = document.getElementById("forecast_minute").value
var time_ms = new Date(Date.UTC(year, month, day, hour, minute)).getTime()
var forecast_mins_in_ms = forecast_minutes * 60 * 1000
var date_string = new Date(time_ms + forecast_mins_in_ms).toUTCString()
return "Probability of Tornado: " + date_string
}
function create_geom(i, j, lons, lats) {
let south_lat_m = lats[i] - radius
let north_lat_m = lats[i] + radius
let west_lon_m = lons[j] - radius
let east_lon_m = lons[j] + radius
let se = transformer.forward([east_lon_m, south_lat_m])
let ne = transformer.forward([east_lon_m, north_lat_m])
let sw = transformer.forward([west_lon_m, south_lat_m])
let nw = transformer.forward([west_lon_m, north_lat_m])
return [sw, nw, ne, se, sw]}
function create_geom_object(i_indices, j_indices, lons, lats) {
let coords = new Array(i_indices.length)
let grid_obj = {type: "FeatureCollection", features: new Array(i_indices.length)}
for (index of d3.range(i_indices.length)) {
coords[index] = [i_indices[index], j_indices[index]]
let geom = create_geom(i_indices[index], j_indices[index], lons, lats)
let grid_cell_obj = {type: "Feature",
id: index,
geometry: {type: "Polygon", coordinates: [geom]}}
grid_obj["features"][index] = grid_cell_obj
}
return [grid_obj, coords]
}
function update_time(direction) {
let selectElement = document.querySelectorAll('[name=forecast_minute]');
let valid_times = [...selectElement[0].options].map(o => o.value)
let current = document.getElementById("forecast_minute").value;
let current_int = parseInt(current);
var new_time;
if (direction == "forward") {
new_time = String(current_int + 5).padStart(2, '0');
if (!valid_times.includes(new_time)) {new_time = valid_times[0]}}
if (direction == "backward") {
new_time = String(current_int - 5).padStart(2, '0');
if (!valid_times.includes(new_time)) {new_time = valid_times[valid_times.length - 1]}}
document.getElementById("forecast_minute").value = new_time;
update();
}}
function get_fcst_date_range(interval) {
let datetime = document.getElementById("model_run").value;
let year = datetime.substring(0, 4);
let month = parseInt(datetime.substring(4, 6)) - 1;
let day = datetime.substring(6, 8);
let start_hour = datetime.substring(8, 10);
let start_min = datetime.substring(10, 12);
let start_hour_int = parseInt(start_hour);
let start_date = new Date(year, month, day, start_hour, start_min);
if (start_hour_int <=4)
{
start_date = new Date(start_date.getTime() + 86400000);
}
end_date = new Date(start_date.getTime() + 3 * 3600000 + 5 * 60000);
let date_range = d3.timeMinutes(start_date,
end_date, interval);
return date_range;
}
</script>
<style>
progress{
width: 300px;
height: 20px;
accent-color: light-purple;
}
</style>
<body onload="init()">
<div id="menubar">
<label for="model_run">Model Run: </label>
<select id="model_run" name="model_run">
</select>
<label for="ens_mem">Ensemble Member: </label>
<select id="ens_mem" name="ens_mem">
<option value="median" selected>Median</option>
<option value="mean">Mean</option>
<option value="max">Max</option>
<option value="1">Member 1</option>
<option value="2" >Member 2</option>
<option value="3">Member 3</option>
<option value="4">Member 4</option>
<option value="5">Member 5</option>
<option value="6">Member 6</option>
<option value="7">Member 7</option>
<option value="8">Member 8</option>
<option value="9">Member 9</option>
<option value="10">Member 10</option>
<option value="11">Member 11</option>
<option value="12">Member 12</option>
<option value="13">Member 13</option>
<option value="14">Member 14</option>
<option value="15">Member 15</option>
<option value="16">Member 16</option>
<option value="17">Member 17</option>
<option value="18">Member 18</option>
</select>
<label for="forecast_minute">Forecast Hour: </label>
<select id="forecast_minute" name="forecast_minute">
<option value="00" selected>00:00</option>
<option value="05">00:05</option>
<option value="10">00:10</option>
<option value="15">00:15</option>
<option value="20">00:20</option>
<option value="25">00:25</option>
<option value="30">00:30</option>
<option value="35">00:35</option>
<option value="40">00:40</option>
<option value="45">00:45</option>
<option value="50">00:50</option>
<option value="55">00:55</option>
<option value="60">01:00</option>
<option value="65">01:05</option>
<option value="70">01:10</option>
<option value="75">01:15</option>
<option value="80">01:20</option>
<option value="85">01:25</option>
<option value="90">01:30</option>
<option value="95">01:35</option>
<option value="100">01:40</option>
<option value="105">01:45</option>
<option value="110">01:50</option>
<option value="115">01:55</option>
<option value="120">02:00</option>
<option value="125">02:05</option>
<option value="130">02:10</option>
<option value="135">02:15</option>
<option value="140">02:20</option>
<option value="145">02:25</option>
<option value="150">02:30</option>
<option value="155">02:35</option>
<option value="160">02:40</option>
<option value="165">02:45</option>
<option value="170">02:50</option>
<option value="175">02:55</option>
<option value="180">03:00</option>
</select>
<input type="checkbox", id="refl">
<label for="refl">Reflectivity Overlay</label>
<input type="range" min="0" max="100" value="10" class="slider" id="refl_alpha">
</div>
<div id="loading" style="display: flex; justify-content: flex-end">
<label>Loading: </label>
<progress id="load_prog" value="0"></progress>
</div>
<div id="mapview">
</div>
</div>
<div id="spaghetti">
</div>
<div id="dvals">
</div>
</body>
</html>