-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
1035 lines (963 loc) · 51.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
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
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<!--Import Google Icon Font-->
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="d3/jquery.range.css">
<style>
body {
background-color: ghostwhite;
}
code {
font-family: Courier, 'New Courier', monospace;
font-size: 12px;
}
.chord path {
fill-opacity: .67;
stroke: #000;
stroke-width: .5px;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.dot {
stroke: #000;
}
/* disable text selection */
svg *::selection {
background: transparent;
}
svg *::-moz-selection {
background: transparent;
}
svg *::-webkit-selection {
background: transparent;
}
rect.selection {
stroke: #333;
stroke-dasharray: 4px;
stroke-opacity: 0.5;
fill: transparent;
}
rect.cell-border {
stroke: #eee;
stroke-width: 0.3px;
}
rect.cell-selected {
stroke: rgb(51, 102, 153);
stroke-width: 0.5px;
}
rect.cell-hover {
stroke: #F00;
stroke-width: 0.3px;
}
text.mono {
font-size: 9pt;
font-family: Consolas, courier;
fill: #aaa;
}
text.text-selected {
fill: #000;
}
text.text-highlight {
fill: #c00;
}
text.text-hover {
fill: #00C;
}
#tooltip {
position: absolute;
width: 200px;
height: auto;
padding: 10px;
background-color: white;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;
-webkit-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
-moz-box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
box-shadow: 4px 4px 10px rgba(0, 0, 0, 0.4);
pointer-events: none;
}
#tooltip.hidden {
display: none;
}
#tooltip p {
margin: 0;
font-family: sans-serif;
font-size: 12px;
line-height: 20px;
}
</style>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/css/materialize.min.css">
<link rel="stylesheet" href="d3/shepherd-theme-arrows.css">
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>EEG Sleep Data Visualization</title>
<link rel="icon" href="favicon.ico?v=3">
</head>
<body>
<div class="parallax-container">
<div class="parallax"><img src="media/EEG.jpg"></div>
</div>
<!--<div class="progress" id="preloader" style="padding-top: 20%; margin: 0;">-->
<!--<div class="indeterminate"></div>-->
<!--</div>-->
<div id="content">
<div id="tooltip" class="hidden card-panel">
<p><span id="value"></span></p>
</div>
<h2 class="card-panel center">Networks in Electroencephalogram Sleep Data</h2>
<div class="row container">
<div class="col s12">
<div class="card">
<div class="card-content">
<h4>What is this?</h4>
<p>Electroencephalography (EEG) is a method to record electrical activity of the brain. Electrodes
are placed on different parts of the scalp. Voltages are then measured and all 64 channels
(nodes)
<a href="http://www.bem.fi/book/13/13.htm">[1]</a>
provide a point of data every millisecond. This means that there will be 64,000 points per
second. This is challenging to visualize because of the high number of dimensions.
This visualization shows
correlations between channels at the full interval on 30s timesteps for one session.
Since the last three
channels <code>ROC</code>, <code>LOC</code>,
and <code>AUX1</code> do not contribute to correlation, they have been dropped.
<code>ROC/LOC</code> can be used to remove
some artifacts, like eye blinks.</p>
<br>
<a class="btn waves-effect waves-light start-tour blue">Start Tour</a>
</div>
</div>
</div>
</div>
<div class="card-panel white">
<div id="matrixContainer" class="container">
<h3 class="center">Edges <span class="chip">Channel vs Channel</span> vs Time <span
class="chip">30s Intervals</span>
Matrix</h3>
<div class="card grey lighten-3">
<p class="card-content">
The matrix visualization displays correlations from -1 to +1. The rows represent time intervals (30s
each). <br>
The columns represent edges; channel vs channel. There are 61 channels that are relevent for
correlation, so there are 1891 edges.
The block structures represents networks in time.
</p>
</div>
<div class="row form-inline">
<div class="input-field col s5 step-1">
<select id="preprocessorSelect">
<option value="z">Z Score</option>
<option value="bandpass">Bandpass</option>
<option value="median">Median Filter</option>
<option value="bandpass-median">Bandpass, Median Filter</option>
<option value="z-bandpass">Z Score, Bandpass</option>
<option value="bandpass-z">Bandpass, Z Score</option>
</select>
<label>Preprocessor</label>
</div>
<div class="input-field col s5 step-2">
<select id="postprocessorSelect">
<option value="pearson">Pearson</option>
<option value="cosine">Cosine</option>
<option value="spearman">Spearman</option>
<option value="ssim">SSIM</option>
</select>
<label>Postprocessor</label>
</div>
<div class="input-field col s2">
<a class="waves-light waves-effect btn blue" id="visualize">Visualize</a>
</div>
</div>
<a class="waves-effect waves-light btn red step-3" id="cluster"><i class="material-icons left">clear_all</i>Sort
by cluster</a>
</div>
<br>
<div id="matrix" style="width: 100%; height: 620px; overflow: auto;"></div>
</div>
<div class="card-panel white">
<div class="container" id="chordContainer">
<h3>Correlations Between Channels</h3>
<strong class="step-4">Current Time Interval (in seconds) <span class="btn disabled" id="timeStep">0:00 - 0:30</span></strong>
<div class="card grey lighten-3">
<p class="card-content">
The chord diagram shows the correlations between channels at the selected time interval. By moving
the range slider, the correlations for that range will be shown. <br>
If the chord diagram does not show up, even after clicking a row on the matrix visualization, change
the range on the slider.
</p>
</div>
<input type="hidden" class="range-slider" id="boundInput" value="0.02"/>
<div id="chord">Click <code><a href="#visualize">Visualize</a></code> to populate this field.</div>
<hr>
<div class="row">
<div class="col s6 m6">
<ul class="collection">
<li class="collection-item">Spindles
<span class="badge teal white-text" id="spindle">0</span></li>
<li class="collection-item">Markon: w
<span class="badge teal white-text" id="m-on-w">0</span></li>
<li class="collection-item">Markoff: w
<span class="badge teal white-text" id="m-off-w">0</span></li>
<li class="collection-item">Markon: 1
<span class="badge teal white-text" id="m-on-1">0</span></li>
<li class="collection-item">Markoff: 1
<span class="badge teal white-text" id="m-off-1">0</span></li>
<li class="collection-item">Markon: 2
<span class="badge teal white-text" id="m-on-2">0</span></li>
<li class="collection-item">Markoff: 2
<span class="badge teal white-text" id="m-off-2">0</span></li>
<li class="collection-item">Markon: 3
<span class="badge teal white-text" id="m-on-3">0</span></li>
<li class="collection-item">Markoff: 3
<span class="badge teal white-text" id="m-off-3">0</span></li>
</ul>
</div>
<div class="col s6 m6">
<img src="media/eeg_nodes.gif">
</div>
</div>
</div>
</div>
<div class="row container">
<div class="col s12">
<div class="card">
<div class="card-content">
<h4>Why</h4>
<div>
The main goals of the project are as follows: <br>
<ol>
<li><strong>Analyze</strong>
<ol>
<li>Networks at different timesteps</li>
<li>Explore phases of sleep in those timesteps</li>
</ol>
</li>
<li><strong>Query</strong>
<ol>
<li>Compare correlated channels at different timesteps</li>
<li>Identify networks in the data</li>
</ol>
</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<div class="row container">
<div class="col s12">
<div class="card">
<div class="card-content">
<h4>How</h4>
<strong>Preprocessing</strong>
<div id="preprocessing-reason">Click <code><a href="#visualize">Visualize</a></code> to populate
this field.
</div>
<strong>Post-processing</strong>
<div id="postprocessing-reason">Click <code><a href="#visualize">Visualize</a></code> to populate
this field.
</div>
<strong>Visualization</strong>
<div>
The two visualizations, matrix and chord, were generated using D3. Tooltips were used to show
correlation values, the column, and row numbers for the matrix visualization. The matrix
visualization is very intensive since it draws 213683 (113 timesteps and 1891 edges)
individual rectangles.
</div>
</div>
</div>
</div>
</div>
<div class="row container">
<div class="col s12">
<div class="card">
<div class="card-content">
<h4>Significance</h4>
<div>
By finding networks during EEG sessions, we can:
<ol>
<li>Explore which node is active during a certain time step or stage of sleep.</li>
<li>Further analyze which parts of the brain work together at certain time steps.</li>
</ol>
</div>
</div>
</div>
</div>
</div>
<div class="row container">
<div class="col s12">
<div class="card">
<div class="card-content">
<h4>About & Contributions</h4>
<div>
This visualization project was a semester long project for
<a href="http://www-cs.ccny.cuny.edu/~grossberg/teaching.html">Data Visualization (CSc
59969)</a>
at The City College of New York.
We would like to thank <a href="https://www.ccny.cuny.edu/profiles/timothy-ellmore">Professor
Timothy Ellmore</a>
for giving us access to this EEG dataset and providing us guidance through this project.
Additionally, this would not have been possible
without the mentorship of <a href="http://www-cs.ccny.cuny.edu/~grossberg/">Professor Michael
Grossberg</a>.
</div>
<br>
<div>
Authors
<ul class="collection">
<li class="collection-item"><a href="https://exp0nge.github.io">MD R. Islam</a></li>
<li class="collection-item"><a href="https://gitlab.com/Fioger">Fioger Shahollari</a></li>
<li class="collection-item"><a href="https://www.linkedin.com/in/enan-rahman-a53499a3">Enan
Rahman</a></li>
<li class="collection-item"><a href="#">Paul Tan</a></li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<!--Import jQuery before materialize.js-->
<script type="application/javascript" src="d3/jquery-2.2.3.min.js"></script>
<!-- Compiled and minified JavaScript -->
<script type="application/javascript" src="d3/materialize.min.js"></script>
<script type="application/javascript" src="d3/d3.min.js"></script>
<script type="application/javascript" src="d3/jquery.range-min.js"></script>
<script type="application/javascript">
$(document).ready(function () {
var i;
var end_sec_time;
var start;
var end_min_time;
var start_sec_time;
var end;
var start_min_time;
var PROCESSED_JSON;
var POSTPROCESSING_REASONS;
var initSelected;
var MARKS;
var TIMESTEPS;
var boundInput;
var chordContainer;
var generateViz;
var NODE_LABELS = ['FP1', 'Fz', 'F3', 'F7', 'FT9', 'FC5', 'FC1', 'C3', 'T7', 'CP5', 'CP1', 'Pz', 'P3', 'P7', 'O1', 'Oz', 'O2', 'P4', 'P8', 'TP10', 'CP6', 'CP2', 'Cz', 'C4', 'T8', 'FT10', 'FC6', 'FC2', 'F4', 'F8', 'FP2', 'AF7', 'AF3', 'AFz', 'F1', 'F5', 'FT7', 'FC3', 'FCz', 'C1', 'C5', 'TP7', 'CP3', 'P1', 'P5', 'PO7', 'PO3', 'POz', 'PO4', 'PO8', 'P6', 'P2', 'CPz', 'CP4', 'TP8', 'C6', 'C2', 'FC4', 'FT8', 'F6', 'F2', 'LOC', 'ROC'];
var EFFECTIVE_NODES = 61;
var preprocessorSelect = $('#preprocessorSelect');
var postprocessorSelect = $('#postprocessorSelect');
var clusterButton = $('#cluster');
var visualizeButton = $('#visualize');
var preprocessingReason = $('#preprocessing-reason');
var postprocessingReason = $('#postprocessing-reason');
var biclustered;
var CONVERTED_TIMESTEPS = {};
var JSON_MEDIA_ROOT = 'media/json/';
var BANDPASS_DIR = 'band_clipped/';
var BANDPASS_MED_DIR = 'band_median/';
var BANDPASS_Z = 'band_z_score/';
var MEDIAN_DIR = 'median_subtract/';
var Z_DIR = 'z_score/';
var Z_BANDPASS = 'z_score_band/';
var BANDPASS_Z = 'band_z_score/';
var COSINE_DIR = 'cosine/';
var PEARSON_DIR = 'pearson/';
var SPEARMAN_DIR = 'spearman/';
var SSIM_DIR = 'ssim/';
var PREPROCESSING_REASONS = {
'bandpass': 'Bandpass filter removes the data that lays outside of frequencies 0.3-30 Hz; this frequency ' +
'is where the significant EEG data is. This reduces noises such as muscle movement. SciPy\'s ' +
'<code>signal.butter</code> can be used for low, high, and bandpass filters. By doing this we can reduce ' +
'the noise so our correlations are more accurate.',
'median': 'Using median filter dampens the amplitude of each of the channels. This is then used to ' +
'subtract from the original data to reduce outliers in the data. SciPy\'s <code>signal.medfiltr</code> ' +
'was used for this preprocessing step. This ultimately reduces large outliers which will throw our ' +
'postprocessors off.',
'z': 'Using z score allows us to subtract the mean and divide by the standard deviation. SciPy\'s ' +
'<code>stats.mstats.zscore</code> was used for this preprocessing step. Ultimately, this allows us to ' +
'remove some outliers.'
};
PREPROCESSING_REASONS['bandpass-median'] = PREPROCESSING_REASONS['bandpass'] + ' ' + PREPROCESSING_REASONS['median'];
PREPROCESSING_REASONS['z-bandpass'] = PREPROCESSING_REASONS['z'] + ' ' + PREPROCESSING_REASONS['bandpass'];
PREPROCESSING_REASONS['bandpass-z'] = PREPROCESSING_REASONS['bandpass'] + ' ' + PREPROCESSING_REASONS['z'];
POSTPROCESSING_REASONS = {
'pearson': 'Pearson correlation measures the linear correlation between 2 sets of data and returns a ' +
'value in a range between -1 and +1. A Pearson correlation of -1 means the 2 sets have complete negative ' +
'correlation, 0 means no correlation at all and +1 means complete positive correlation. ' +
'SciPy\'s <code>stats.pearsonr</code> was used to calculate this value. This allows us to illustrate linear ' +
'relationships between two nodes.',
'spearman': 'Spearman correlation measures the monotonic correlation between 2 sets of data and returns ' +
'a value in a range between -1 and +1. A Spearman correlation of -1 means the 2 sets have complete ' +
'negative correlation, 0 means no correlation at all and +1 means complete positive correlation. We used ' +
'Spearman correlation because we thought it would complement Pearson correlation well, since Spearman ' +
'isn\'t based on the linearity of the data. SciPy\'s <code>stats.spearmanr</code> was used. ' +
'This measure shows us a ' +
'monotonic relationship between two nodes and show what Pearson correlation might\'ve had trouble showing.',
'ssim': 'Structural similarity, or SSIM, is often used to measure the similarity between 2 images and ' +
'returns a value in a range between -1 and +1. A SSIM value of -1 means the 2 sets of data have no ' +
'resemblance and +1 means the data sets are identical to each other. ' +
'Scikit-learn has <code>skimage.measure.compare_ssim</code> for this measure. ' +
'This similarity measure shows how much ' +
'a value changes at a timestep.',
'cosine': 'Cosine similarity measure uses best fit line for two plots of data, then the angle is ' +
'calculated, and the cosine of the angle is then taken. If the angles are close, the cosine gets closer to ' +
'1, otherwise it will get get closer to 0. This is one of the most popular similarity measures and it ' +
'seemed applicable. Scikit-learn\'s <code>metrics.pairwise.cosine_similarity</code> was used.'
};
PROCESSED_JSON = {
"z": {
"pearson": [JSON_MEDIA_ROOT + PEARSON_DIR + Z_DIR + 'z-score-matrix-30s.json',
JSON_MEDIA_ROOT + PEARSON_DIR + Z_DIR + 'fitted-indices-z-score-pearson-30s.json'],
"cosine": [JSON_MEDIA_ROOT + COSINE_DIR + Z_DIR + 'z-score-cos-matrix-30s.json',
JSON_MEDIA_ROOT + COSINE_DIR + Z_DIR + 'fitted-indices-z-score-cos-30s_float.json'],
"spearman": [JSON_MEDIA_ROOT + SPEARMAN_DIR + Z_DIR + 'z-score-matrix-30s.json',
JSON_MEDIA_ROOT + SPEARMAN_DIR + Z_DIR + 'fitted-indices-z-score-spearman-30s.json'],
"ssim": [JSON_MEDIA_ROOT + SSIM_DIR + Z_DIR + 'z-score-matrix-30s.json',
JSON_MEDIA_ROOT + SSIM_DIR + Z_DIR + 'fitted-indices-z-score-pearson-30s.json']
},
"bandpass": {
"pearson": [JSON_MEDIA_ROOT + PEARSON_DIR + BANDPASS_DIR + 'band-clipped-matrix-30s.json',
JSON_MEDIA_ROOT + PEARSON_DIR + BANDPASS_DIR + 'fitted-indices-band-clipped-pearson-30s.json'],
"cosine": [JSON_MEDIA_ROOT + COSINE_DIR + BANDPASS_DIR + 'band-clipped-cos-matrix-30s.json',
JSON_MEDIA_ROOT + COSINE_DIR + BANDPASS_DIR + 'fitted-indices-band-clipped-cos-30s_float.json'],
"spearman": [JSON_MEDIA_ROOT + SPEARMAN_DIR + BANDPASS_DIR + 'band-clipped-matrix-30s.json',
JSON_MEDIA_ROOT + SPEARMAN_DIR + BANDPASS_DIR + 'fitted-indices-band-clipped-pearson-30s.json'],
"ssim": [JSON_MEDIA_ROOT + SSIM_DIR + BANDPASS_DIR + 'band-clipped-matrix-30s.json',
JSON_MEDIA_ROOT + SSIM_DIR + BANDPASS_DIR + 'fitted-indices-band_clipped-pearson-30s.json']
},
"median": {
"pearson": [JSON_MEDIA_ROOT + PEARSON_DIR + MEDIAN_DIR + 'median-filter-matrix-30s.json',
JSON_MEDIA_ROOT + PEARSON_DIR + MEDIAN_DIR + 'fitted-indices-median-filter-pearson-30s.json'],
"cosine": [JSON_MEDIA_ROOT + COSINE_DIR + MEDIAN_DIR + 'median-sub-cos-matrix-30s.json',
JSON_MEDIA_ROOT + COSINE_DIR + MEDIAN_DIR + 'fitted-indices-median-sub-cos-30s_float.json'],
"spearman": [JSON_MEDIA_ROOT + SPEARMAN_DIR + MEDIAN_DIR + 'median-filter-matrix-30s.json',
JSON_MEDIA_ROOT + SPEARMAN_DIR + MEDIAN_DIR + 'fitted-indices-median-filter-pearson-30s.json'],
"ssim": [JSON_MEDIA_ROOT + SSIM_DIR + MEDIAN_DIR + 'median-filter-matrix-30s.json',
JSON_MEDIA_ROOT + SSIM_DIR + MEDIAN_DIR + 'fitted-indices-median-filter-pearson-30s.json']
},
"bandpass-median": {
"pearson": [JSON_MEDIA_ROOT + PEARSON_DIR + BANDPASS_MED_DIR + 'band-median-matrix-30s.json',
JSON_MEDIA_ROOT + PEARSON_DIR + BANDPASS_MED_DIR + 'fitted-indices-band-median-pearson-30s.json'],
"cosine": [JSON_MEDIA_ROOT + COSINE_DIR + BANDPASS_MED_DIR + 'band-med-cut-cos-matrix-30s.json',
JSON_MEDIA_ROOT + COSINE_DIR + BANDPASS_MED_DIR + 'fitted-indices-band-med-cut-cos-30s_float.json'],
"spearman": [JSON_MEDIA_ROOT + PEARSON_DIR + BANDPASS_MED_DIR + 'band-median-matrix-30s.json',
JSON_MEDIA_ROOT + SPEARMAN_DIR + BANDPASS_MED_DIR + 'fitted-indices-band-median-pearson-30s.json'],
"ssim": [JSON_MEDIA_ROOT + SSIM_DIR + BANDPASS_MED_DIR + 'band-median-matrix-30s.json',
JSON_MEDIA_ROOT + SSIM_DIR + BANDPASS_MED_DIR + 'fitted-indices-band_median-pearson-30s.json']
},
"z-bandpass": {
"pearson": [JSON_MEDIA_ROOT + PEARSON_DIR + Z_BANDPASS + 'z-score-band-matrix-30s.json',
JSON_MEDIA_ROOT + PEARSON_DIR + Z_BANDPASS + 'fitted-indices-z-score-band-pearson-30s.json'],
"cosine": [JSON_MEDIA_ROOT + COSINE_DIR + Z_BANDPASS + 'z-score-band-cos-matrix-30s.json',
JSON_MEDIA_ROOT + COSINE_DIR + Z_BANDPASS + 'fitted-indices-z-score-band-cos-30s_float.json'],
"spearman": [JSON_MEDIA_ROOT + SPEARMAN_DIR + Z_BANDPASS + 'z-score-band-matrix-30s.json',
JSON_MEDIA_ROOT + SPEARMAN_DIR + Z_BANDPASS + 'fitted-indices-z-score-band-spearman-30s.json'],
"ssim": [JSON_MEDIA_ROOT + SSIM_DIR + Z_BANDPASS + 'z-score-band-matrix-30s.json',
JSON_MEDIA_ROOT + SSIM_DIR + Z_BANDPASS + 'fitted-indices-z-score-band-ssim-30s.json']
},
"bandpass-z": {
"pearson": [JSON_MEDIA_ROOT + PEARSON_DIR + BANDPASS_Z + 'band-z-score-matrix-30s.json',
JSON_MEDIA_ROOT + PEARSON_DIR + BANDPASS_Z + 'fitted-indices-band-z-score-pearson-30s.json'],
"cosine": [JSON_MEDIA_ROOT + COSINE_DIR + BANDPASS_Z + 'band-z-score-cos-matrix-30s.json',
JSON_MEDIA_ROOT + COSINE_DIR + BANDPASS_Z + 'fitted-indices-band-z-score-cos-30s_float.json'],
"spearman": [JSON_MEDIA_ROOT + SPEARMAN_DIR + BANDPASS_Z + 'band-z-score-matrix-30s.json',
JSON_MEDIA_ROOT + SPEARMAN_DIR + BANDPASS_Z + 'fitted-indices-band-z-score-pearson-30s.json'],
"ssim": [JSON_MEDIA_ROOT + SSIM_DIR + BANDPASS_Z + 'band-z-score-matrix-30s.json',
JSON_MEDIA_ROOT + SSIM_DIR + BANDPASS_Z + 'fitted-indices-band-z-score-pearson-30s.json']
}
};
// load converted timesteps
for (i = 0; i < 112; i++) {
start = i * 30;
end = (i + 1) * 30;
start_min_time = Math.floor(start / 60);
start_sec_time = start % 60;
end_min_time = Math.floor(end / 60);
end_sec_time = end % 60;
if (start_sec_time < 10) {
start_sec_time = "0" + start_sec_time.toString();
}
if (end_sec_time < 10) {
end_sec_time = "0" + end_sec_time.toString();
}
CONVERTED_TIMESTEPS[i] = start_min_time.toString() + ":" + start_sec_time.toString() + " - " +
end_min_time.toString() + ":" + end_sec_time.toString();
}
CONVERTED_TIMESTEPS[112] = '56:00 - 56:24';
visualizeButton.on('click', function (e) {
biclustered = false;
$('#visualize').addClass('disabled');
initSelected = PROCESSED_JSON[preprocessorSelect.val()][postprocessorSelect.val()];
postprocessingReason.html(POSTPROCESSING_REASONS[postprocessorSelect.val()]);
preprocessingReason.html(PREPROCESSING_REASONS[preprocessorSelect.val()]);
console.log(initSelected);
generateViz(initSelected[0], initSelected[1]);
e.preventDefault();
});
clusterButton.hide();
boundInput = $('#boundInput');
chordContainer = $('#chordContainer');
d3.json('media/json/phases_of_sleep.json', function (data) {
console.log(data);
TIMESTEPS = data['timesteps'];
MARKS = data['marks'];
console.log('marks loaded');
});
$('.parallax').parallax();
$('select').material_select();
generateViz = function (processedDataPath, fittedDataPath) {
d3.json(processedDataPath, function (data) {
clusterButton.show();
clusterButton.removeClass('disabled');
$('#chord').empty();
$('#matrix').empty();
currentTimestep = $('#timeStep');
ROWS = data['data'].length;
COLUMNS = data['data'][0].length;
matrix = [];
for (i = 0; i < ROWS; i++) {
for (var j = 0; j < COLUMNS; j++) {
matrix.push({
row: i,
col: j,
value: data['data'][i][j]
});
}
}
console.log('MATRIX LOADED');
MIN = d3.min(matrix, function (d, i) {
return d.value;
}),
margin = {top: 30, right: 0, bottom: 0, left: 30},
cellSize = 5,
legendElementWidth = cellSize * 2.5,
col_number = d3.max(matrix, function (d, i) {
return d.col;
}),
row_number = d3.max(matrix, function (d, i) {
return d.row;
}),
WIDTH = cellSize * col_number,
HEIGHT = cellSize * row_number,
hcrow = d3.range(1, row_number + 1, 1),
hccol = d3.range(1, col_number + 1, 1),
colors = ['#005824', '#1A693B', '#347B53', '#4F8D6B', '#699F83', '#83B09B', '#9EC2B3', '#B8D4CB', '#D2E6E3', '#EDF8FB', '#FFFFFF', '#F1EEF6', '#E6D3E1', '#DBB9CD', '#D19EB9', '#C684A4', '#BB6990', '#B14F7C', '#A63467', '#9B1A53', '#91003F'],
colorScale = d3.scale.quantile()
.domain([-1, 0, 1])
.range(colors);
svg = d3.select("#matrix").append("svg")
.attr("width", WIDTH)
.attr("height", HEIGHT + 40) // +40 for the legend
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
svg.append('text')
.attr("x", margin.left)
.attr("class", "mono")
.attr("y", -10)
.text("Channel vs Channel");
svg.append('text')
.attr("transform", "rotate(-90)")
.attr("class", "mono")
.attr("x", -130)
.attr("y", -10)
.text("Time Interval");
svg.selectAll(".legend")
.append("g")
.attr("class", "legend")
.data(colorScale.range())
.enter()
.append("rect")
.attr("x", function (d, i) {
return margin.left + 300 + legendElementWidth + (i * 20);
})
.attr("y", -margin.top)
.attr("width", 20)
.attr("height", 20)
.style("fill", function (d, i) {
return colors[i];
});
svg.append('text')
.attr("class", "mono")
.attr("x", margin.left + 300 + legendElementWidth - 20)
.attr("y", -margin.top / 2)
.text("-1");
svg.append('text')
.attr("class", "mono")
.attr("x", margin.left + 305 + legendElementWidth + (colorScale.range().length * 20))
.attr("y", -margin.top / 2)
.text("+1");
SELECTED_ROW = 0;
heat = svg.append("g").attr("class", "g3")
.selectAll(".cellg")
.data(matrix, function (d, i) {
return d.row + ":" + d.col;
})
.enter()
.append("rect")
.attr("x", function (d) {
return hccol.indexOf(d.col) * cellSize;
})
.attr("y", function (d) {
return hcrow.indexOf(d.row) * cellSize;
})
.attr("class", 'cell')
.attr("width", cellSize)
.attr("height", cellSize)
.style("fill", function (d, idx) {
return colorScale(d.value);
})
.on("mouseover", function (d, idx) {
//highlight text
d3.select(this).classed("cell-hover", true);
d3.selectAll(".rowLabel").classed("text-highlight", function (r, ri) {
return ri == (d.row - 1);
});
d3.selectAll(".colLabel").classed("text-highlight", function (c, ci) {
return ci == (d.col - 1);
});
//Update the tooltip position and value
d3.select("#tooltip")
.style("left", (d3.event.pageX + 10) + "px")
.style("top", (d3.event.pageY - 10) + "px")
.select("#value")
.text("Correlation:" + matrix[idx].value + "\nTimestep:" + matrix[idx].row + ", col:" + matrix[idx].col);
//Show the tooltip
d3.select("#tooltip").classed("hidden", false);
})
.on("mouseout", function () {
d3.select(this).classed("cell-hover", false);
d3.selectAll(".rowLabel").classed("text-highlight", false);
d3.selectAll(".colLabel").classed("text-highlight", false);
d3.select("#tooltip").classed("hidden", true);
})
.on('click', function (d, idx) {
SELECTED_ROW = matrix[idx].row;
var lowerUpper = boundInput.attr('value').split(',');
generateChord(parseFloat(lowerUpper[0]), parseFloat(lowerUpper[1]), d.row);
markers = TIMESTEPS[SELECTED_ROW * 30];
markToID = {
'spindle': '#spindle',
'Markon: w': '#m-on-w',
'Markoff: w': '#m-off-w',
'Markoff: 1': '#m-on-1',
'Markon: 1': '#m-off-1',
'Markoff: 2': '#m-on-2',
'Markon: 2': '#m-off-2',
'Markon: 3': '#m-on-3',
'Markoff: 3': '#m-off-3'
};
currentTimestep.html(CONVERTED_TIMESTEPS[SELECTED_ROW]);
$('html,body').animate({
scrollTop: chordContainer.offset().top
});
console.log('----------------------');
$('.badge').html(0);
$('.badge').removeClass('teal');
for (var i = 0; i < markers.length; i++) {
console.log('PHASE: ', MARKS[markers[i]]);
markId = $(markToID[MARKS[markers[i]]]);
markId.html(parseInt(markId.html()) + 1);
markId.addClass('teal');
}
});
bicluster = function (originalData) {
biclustered = true;
clusterButton.addClass('disabled');
d3.json(fittedDataPath, function (indices) {
console.log(indices['data'].length, originalData.length);
console.log(d3.selectAll('.cell'));
d3.selectAll('.cell')
.style("fill", function (d, idx) {
var rowCol = indices['data'][idx];
matrix[idx] = {
'row': rowCol[0],
'col': rowCol[1],
'value': originalData[rowCol[0]][rowCol[1]]
};
return colorScale(originalData[rowCol[0]][rowCol[1]]);
});
console.log('done fitting');
});
};
clusterButton.on('click', function (e) {
if (!biclustered) {
bicluster(data['data']);
}
e.preventDefault();
});
MAX_ROW_TIME = data['data'].length;
d3.select("#timeInput").attr("max", MAX_ROW_TIME - 1);
console.log('data retrieved');
// TODO: Find min/max of data and alter bound
// TODO: get actual labels
generateMatrix = function (ROW_TIME) {
var START_COLUMN = 0;
var END_COLUMN = 61;
var ROW_TIME = ROW_TIME;
var matrix = new Array(61);
// insert into node 0 first
var rowData = data['data'][ROW_TIME].slice(START_COLUMN, END_COLUMN);
matrix[0] = rowData;
START_COLUMN = END_COLUMN;
END_COLUMN += 60;
// fill in rest of array, not forgetting to store the previously calculated value (eg. 1 vs 0 is not in the interval)
for (var i = 1; i < 61; i++) {
rowData = data['data'][ROW_TIME].slice(START_COLUMN, END_COLUMN);
//rowData.splice(i - 1, 0, data['data'][ROW_TIME][i]); // insert i vs i - 1 since it's not in JSON
matrix[i] = rowData;
START_COLUMN = END_COLUMN;
END_COLUMN += (60 - i);
}
// fill in missing values in matrix
for (var i = 1; i < 61; i++) {
for (j = 0; j < i; j++) {
matrix[i].splice(j, 0, matrix[j][i]);
}
}
return matrix;
};
generateChord = function (lowerBound, upperBound, time) {
d3.selectAll('.chordDiagram').remove();
var alteredMatrix = generateMatrix(time);
// threshold test
for (var i = 0; i < 61; i++) {
for (var j = 0; j < 61; j++) {
//check if it's negative
if (alteredMatrix[i][j] >= lowerBound && alteredMatrix[i][j] <= upperBound) {
if (alteredMatrix[i][j] < 0) {
// chord messes up on negatives
alteredMatrix[i][j] = Math.abs(alteredMatrix[i][j]);
} else {
alteredMatrix[i][j] = alteredMatrix[i][j];
}
} else {
alteredMatrix[i][j] = 0;
}
}
}
chord = d3.layout.chord()
.padding(0.05)
.sortSubgroups(d3.descending)
.matrix(alteredMatrix);
//DIMENSIONS
width = 1000,
height = 600,
innerRadius = Math.min(width, height) * 0.41,
outerRadius = innerRadius * 1.05,
names = [];
for (var i = 0; i < 64; i++) {
names[i] = NODE_LABELS[i];
}
//COLORS
fill = d3.scale.ordinal()
.domain(d3.range(5)) // number of colors
.range(["#000000", "#FFDD89", "#957244", "#F26223", "#E0E000"]);
//Setting the Dimensions
svg = d3.select("#chord").append("svg")
.attr("width", width)
.attr("height", height)
.attr("class", "chordDiagram")
.append("g")
.attr("transform", "translate(" + width / 2 + "," + height / 2 + ")");
//Setting Colors and Mouseover/Mouseout effects
svg.append("g").selectAll("path")
.data(chord.groups)
.enter().append("path")
.style("fill", function (d) {
return fill(d.index);
})
.style("stroke", function (d) {
return fill(d.index);
})
.attr("d", d3.svg.arc().innerRadius(innerRadius).outerRadius(outerRadius))
.on("mouseover", fade(.2))
.on("mouseout", fade(1))
.on("click", function (d) {
console.log(d['index']);
});
//Ticks and it's labels
ticks = svg.append("g").selectAll("g")
.data(chord.groups)
.enter().append("g").selectAll("g")
.data(groupTicks)
.enter().append("g")
.attr("transform", function (d) {
return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")"
+ "translate(" + outerRadius + ",0)";
});
//tick markers lengths (don't mess with y, it change's the angle of the lines)
ticks.append("line")
.attr("x1", 1)
.attr("y1", 0)
.attr("x2", 1)
.attr("y2", 0)
.style("stroke", "#000");
//tick labels
ticks.append("text")
.attr("x", 8)
.attr("dy", ".35em")
.attr("text-anchor", function (d) {
return d.angle > Math.PI ? "end" : null;
})
.attr("transform", function (d) {
return d.angle > Math.PI ? "rotate(180)translate(-16)" : null;
})
.style('font', '10px sans-serif');
//.text(function(d) { return d.label; });
chordgroups = chord.groups()
.map(function (d) {
d.angle = (d.startAngle + d.endAngle) / 2;
return d;
});
svg.selectAll(".text")
.data(chordgroups)
.enter()
.append("text")
.attr("class", "text")
.attr("text-anchor", function (d) {
return d.angle > Math.PI ? "end" : null;
})
.attr("transform", function (d) {
//rotate each label around the circle
return "rotate(" + (d.angle * 180 / Math.PI - 90) + ")" +
"translate(" + (outerRadius + 10) + ")" +
(d.angle > Math.PI ? "rotate(180)" : "");
})
.text(function (d) {
//set the text content
return names[d.index];
})
.style('font', '10px sans-serif');
//
svg.append("g")
.attr("class", "chord")
.selectAll("path")
.data(chord.chords)
.enter().append("path")
.attr("d", d3.svg.chord().radius(innerRadius))
.style("fill", function (d) {
return fill(d.target.index);
})
.style("opacity", 1);
// Returns an array of tick angles and labels, given a group.
function groupTicks(d) {
var k = (d.endAngle - d.startAngle) / d.value;
return d3.range(0, d.value, 1).map(function (v, i) {
return {
angle: v * k + d.startAngle,
label: i % 1 ? null : v
};
});
}
// Returns an event handler for fading a given chord group.
function fade(opacity) {
return function (g, i) {
svg.selectAll(".chord path")
.filter(function (d) {
return d.source.index != i && d.target.index != i;
})
.transition()
.style("opacity", opacity);
};
}
};
generateChord(0, 0.5, SELECTED_ROW);
visualizeButton.removeClass('disabled');
// d3.select('#boundInput').on('change', function (e) {
// console.log('changed');
// generateChord(this.value, SELECTED_ROW);
// });
// // d3.select("#timeInput").on('change', function(e){
// // d3.selectAll('.chordDiagram').remove();
// //// generateChord(d3.select("#boundInput")[0][0].value, this.value);
// // });
$('.range-slider').jRange({
from: -0.99,
to: 0.99,
step: 0.01,
format: '%s',
width: $('#chordContainer').width(),
showLabels: true,
showScale: true,
ondragend: function (bound) {
var upperLower = bound.split(',');
generateChord(parseFloat(upperLower[0]), parseFloat(upperLower[1]), SELECTED_ROW);
},
isRange: true
});
});
};
// initSelected = PROCESSED_JSON[preprocessorSelect.val()][postprocessorSelect.val()];
// console.log(initSelected);
// generateViz(initSelected[0], initSelected[1])
}
);
</script>
<script type="application/javascript" src="d3/tether.js"></script>
<script type="application/javascript" src="d3/shepherd.min.js"></script>
<script type="application/javascript">
$(document).ready(function () {
var tour = new Shepherd.Tour({
defaults: {
classes: 'shepherd-theme-arrows shepherd-element shepherd-open',
showCancelLink: true,
scrollTo: true
}
});
tour.addStep('step-1', {
text: 'First start off by selecting a preprocessor.',
attachTo: '.step-1 bottom',
buttons: [
{
text: 'Next',
action: tour.next
}
]
});
tour.addStep('step-2', {
text: 'Then select a post-processor and click <strong>Visualize</strong>. ' +
'<br>This process takes a bit of time and can freeze the browser.' +
'<br>The visualization will show channel vs channel' +
'<br>on the horizontal axis and timesteps (30s intervals)<br> on the vertical. Each row/column represents one unit;' +
'<br>a row is a 30s timestep and<br> a column is a channel vs channel (e.g. T7 vs P10).',
attachTo: '.step-2 bottom',
buttons: [
{