├── LICENSE.md ├── Neuroscience and AI.ipynb ├── README.md ├── SpectraVis-Demo.gif ├── app ├── css │ └── spectra.css └── js │ └── main.js ├── bower.json ├── gulpfile.js ├── matlab ├── ES_NetworkData.m ├── createEdges.m └── createNodes.m ├── package.json └── public ├── css ├── main.css └── main.min.css ├── fonts ├── glyphicons-halflings-regular.eot ├── glyphicons-halflings-regular.svg ├── glyphicons-halflings-regular.ttf ├── glyphicons-halflings-regular.woff └── glyphicons-halflings-regular.woff2 ├── index.html └── js ├── main.js ├── main.min.js ├── vendor.js └── vendor.min.js /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /Neuroscience and AI.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Neuroscience and Machine Learning\n", 8 | "\n", 9 | "## Demo - An interactive network visualization tool for exploring functional brain connectivity \n", 10 | "\n", 11 | "![alt text](https://i.imgur.com/ZV4kGlu.jpg \"Logo Title Text 1\")\n", 12 | "\n", 13 | "- History of Neuroscience in AI\n", 14 | "- Contemporary Neuroscience in AI\n", 15 | "- Future of Neuroscience in AI\n", 16 | "\n", 17 | "## The History of Neuroscience in AI\n", 18 | "\n", 19 | "![alt text](https://cdn-images-1.medium.com/max/1600/0*vM6TPG8w6S54DGdC.jpg \"Logo Title Text 1\")\n", 20 | "\n", 21 | "- At the dawn of the computer age, AI research and neuroscience were completely intertwined\n", 22 | "- Early pioneers straddled both fields\n", 23 | "- And the collaborations between disciplines where highly productive\n", 24 | "- Let's look at some examples\n", 25 | "\n", 26 | "### Examples\n", 27 | "\n", 28 | "#### Alan Turing \n", 29 | "\n", 30 | "![alt text](https://image.slidesharecdn.com/thea-171021150200/95/the-artificial-intelligence-ecosystem-9-638.jpg?cb=1508598480 \"Logo Title Text 1\")\n", 31 | "\n", 32 | "###### \"We are not interested in the fact that the brain has the consistency of cold porridge\" (Turing 1952)\n", 33 | "\n", 34 | "- Said the key to understanding the brain is not in mapping its anatomy or measuring its density, but in characterising its behaviour mathematically. \n", 35 | "- His view is still shared by many. \n", 36 | "- Mathematical equations are expressive and unambiguous — and arguably the only language suited to describing so complex an object\n", 37 | "\n", 38 | "![alt text](https://www.bu.edu/research/files/2015/09/h_research_brain_rhythms_seizure.jpg \"Logo Title Text 1\")\n", 39 | "\n", 40 | "- Hearing aids and prosthetic limbs exploit algorithms that mimic the equations of the brain and nervous system\n", 41 | "- Mathematical characterisations of the brain inform the field of AI and the design of novel computer components\n", 42 | "\n", 43 | "![alt text](https://i0.wp.com/www.themanitoban.com/wp-content/uploads/2015/03/Aldo-Rios-Science-turing-brain-Web.jpg?resize=777%2C437 \"Logo Title Text 1\")\n", 44 | "\n", 45 | "- Wrote a short computer program that accepted a single number, performed a series of unspecified calculations on it, and returned a second number. \n", 46 | "- He argued that the brain accept tens-of-thousands of inputs from sensory receptors around the body, but the calculations these inputs undergo are far more complicated than anything written by a single programmer. \n", 47 | "- He underscored his argument with a wager: that it would take an investigator at least a thousand years to guess the full set of calculations his Manchester program employed. \n", 48 | "- Guessing the full set of calculations taking place in the brain, he noted, would appear prohibitively time-consuming\n", 49 | "- With modern supercomputers and neuroimaging techniques, this reduces the complexity orders of magnitude\n", 50 | "\n", 51 | "#### McCulloch and Pitts\n", 52 | "\n", 53 | "![alt text](https://image.slidesharecdn.com/neuralnets-110906041700-phpapp02/95/neural-networks-6-728.jpg?cb=1315282683 \"Logo Title Text 1\")\n", 54 | "\n", 55 | "- Both tried to understand how the brain could produce highly complex patterns by using many basic cells that are connected together\n", 56 | "\n", 57 | "#### Hopfield\n", 58 | "\n", 59 | "![alt text](http://images.slideplayer.com/15/4758037/slides/slide_2.jpg \"Logo Title Text 1\")\n", 60 | "\n", 61 | "- Combined McCulloch Pitts Neurons into a Hopfield Network\n", 62 | "\n", 63 | "#### Hinton \n", 64 | "\n", 65 | "![alt text](https://sebastianraschka.com/images/faq/visual-backpropagation/backpropagation.png \"Logo Title Text 1\")\n", 66 | "\n", 67 | "- Invented backpropagation\n", 68 | "- The motivation for backpropagation is to train a multi-layered neural network such that it can learn the appropriate internal representations to allow it to learn any arbitrary mapping of input to output \n", 69 | "- Big proponent of Dropout, Non-linearities, Layered Networks during AI winter\n", 70 | "\n", 71 | "#### Leading up until now\n", 72 | "\n", 73 | "![alt text](https://docs.opencv.org/2.4/_images/optimal-hyperplane.png \"Logo Title Text 1\")\n", 74 | "\n", 75 | "- More recently, the interaction between neuroscience an AI has become much less common\n", 76 | "- Both subjects have grown enormously in complexity and disciplinary boundaries have solidified.\n", 77 | "- This is a problem, the human brain is the only existing proof that such an intelligence is even possible. \n", 78 | "- Neuroscience provides a rich source of inspiration for new types of algorithms and architectures, independent of and complementary to the mathematical and logic-based methods and ideas that have largely dominated traditional approaches to AI.\n", 79 | "- neuroscience can also provide validation of AI techniques that already exist.\n", 80 | "\n", 81 | "![alt text](https://cdn-images-1.medium.com/max/1200/0*emXbYoppjY65lceR.jpg \"Logo Title Text 1\")\n", 82 | "\n", 83 | "- Biological plausibility is a guide, not a strict requirement.\n", 84 | "- We need a systems neuroscience-level understanding of the brain, namely the algorithms, architectures, functions, and representations it utilizes.\n", 85 | "- By focusing on the computational and algorithmic levels, we can gain transferrable insights into general mechanisms of brain function, while leaving room to accommodate the distinctive opportunities and challenges that arise when building intelligent machines in silico.\n", 86 | "\n", 87 | "\n", 88 | "## Contemporary Neuroscience in AI (4 Key Areas Affected)\n", 89 | "\n", 90 | "### Attention\n", 91 | "\n", 92 | "![alt text](https://i.stack.imgur.com/vmvpD.jpg \"Logo Title Text 1\")\n", 93 | "\n", 94 | "- The brain does not learn by implementing a single, global optimization principle within a uniform and undifferentiated neural network. \n", 95 | "- Rather, biological brains are modular, with distinct but interacting subsystems underpinning key functions such as memory, language, and cognitive control\n", 96 | "\n", 97 | "![alt text](http://kelvinxu.github.io/projects/diags/model_diag.png \"Logo Title Text 1\")\n", 98 | "\n", 99 | "- Up until quite lately, most CNN models worked directly on entire images or video frames, with equal priority given to all image pixels at the earliest stage of processing. \n", 100 | "- The primate visual system works differently. Rather than processing all input in parallel, visual attention shifts strategically among locations and objects, centering processing resources and representational coordinates on a series of regions in turn\n", 101 | "\n", 102 | "### Episodic Memory\n", 103 | "\n", 104 | "![alt text](https://primarytimerydotcom.files.wordpress.com/2017/09/semantic-episodic-slide.png?w=660 \"Logo Title Text 1\")\n", 105 | "\n", 106 | "- A canonical theme in neuroscience is that that intelligent behavior relies on multiple memory systems\n", 107 | "- Reinforcement based mechanisms (incremental) and instance based mechanisms (one shot)\n", 108 | "- Episodic memory is associated with circuits in the medial temporal lobe\n", 109 | "\n", 110 | "![alt text](https://reading-club.github.io/assets/posts/Playing_Atari_with_Deep_Reinforcement_Learning/algorithm.png \"Logo Title Text 1\")\n", 111 | "\n", 112 | "![alt text](https://dnddnjs.gitbooks.io/rl/content/dqn16.png \"Logo Title Text 1\")\n", 113 | "\n", 114 | "- DeepMind's Deep Q Network was inspired by it, using ‘experience replay', where the network stores a subset of the training data in an instance-based way, and then ‘‘replays’’ it offline, \n", 115 | "- It learns anew from successes or failures that occurred in the past.\n", 116 | "- Experience replay is critical to maximizing data efficiency, destabilizing effects of learning from consecutive correlated ex- periences, and allows the network to learn a viable value function even in complex, highly structured sequential environments such as video games.\n", 117 | "\n", 118 | "### Working Memory\n", 119 | "\n", 120 | "![alt text](http://examinedexistence.com//wp-content/uploads/2013/12/working-memory-2.gif \"Logo Title Text 1\")\n", 121 | "\n", 122 | "- Human intelligence can maintain and manipulate information within an active store known as working memory\n", 123 | "- This is thought to be instantiated within the preforntal cortex and interconnected areas\n", 124 | "- Classic theories suggest this depends on interactions between a central controller and speerate domain specific memory buffers\n", 125 | "\n", 126 | "![alt text](https://image.slidesharecdn.com/dlcvd2l6recurrentneuralnetworks-160802094750/95/deep-learning-for-computer-vision-recurrent-neural-networks-upc-2016-26-638.jpg?cb=1470131837 \"Logo Title Text 1\")\n", 127 | "\n", 128 | "- LSTM networks were on step towards implementing this\n", 129 | "- In LSTMs the functions of sequence control and memory storage are closely intertwined\n", 130 | "- But this contrasts with classic models of human working memory, which, separate these two.\n", 131 | "\n", 132 | "![alt text](https://qph.ec.quoracdn.net/main-qimg-08b667f9a7706e0cf2baf70cd00450b4 \"Logo Title Text 1\")\n", 133 | "\n", 134 | "- A possible improvement, the differential neural computer (DNC) involves a neural network controller that attends to and reads/writes from an external memory matrix\n", 135 | "- This externalization allows the network controller to learn from scratch (i.e., via end-to-end optimization) to perform a wide range of complex memory and reasoning tasks that currently elude LSTMs, such as finding the shortest path through a graph-like structure, such as a subway map, or manipulating blocks in a variant of the Tower of Hanoi task\n", 136 | "\n", 137 | "### Continual Learning\n", 138 | "\n", 139 | "![alt text](https://creativesystemsthinking.files.wordpress.com/2014/02/971854_575795465785620_1014001935_n.jpg?w=650 \"Logo Title Text 1\")\n", 140 | "\n", 141 | "- Intelligent agents must be able to learn and remember many different tasks that are encountered over multiple timescales.\n", 142 | "- Continual Learning is an ability to master new tasks without forgetting how to perform prior tasks \n", 143 | "\n", 144 | "![alt text](https://image.slidesharecdn.com/overcomingcatastrophicforgettinginneuralnetwork-170429024916/95/overcoming-catastrophic-forgetting-in-neural-network-3-638.jpg?cb=1493434190 \"Logo Title Text 1\")\n", 145 | "\n", 146 | "- While animals appear relatively adept at continual learning, neural networks suffer from the problem of catastrophic forgetting \n", 147 | "- This occurs as the network parameters shift toward the optimal state for performing the second of two successive tasks, overwriting the configuration that allowed them to perform the first. \n", 148 | "\n", 149 | "![alt text](https://s3-eu-west-1.amazonaws.com/ppreviews-plos-725668748/1876046/preview.jpg \"Logo Title Text 1\")\n", 150 | "\n", 151 | "- Advanced neuroimaging techniques (e.g., two-photon imaging) now allow dynamic in vivo visualization of the structure and function of dendritic spines during learning, at the spatial scale of single synapses\n", 152 | "- This approach can be used to study neocortical plasticity during continual learning\n", 153 | "\n", 154 | "![alt text](https://image.slidesharecdn.com/overcomingcatastrophicforgettinginneuralnetwork-170429024916/95/overcoming-catastrophic-forgetting-in-neural-network-9-638.jpg?cb=1493434190 \"Logo Title Text 1\")\n", 155 | "\n", 156 | "- Elastic Weight Consolidtion is one newer step in this direction\n", 157 | "- acts by slowing down learning in a subset of network weights identified as important to previous tasks, thereby anchoring these parameters to previously found solutions. \n", 158 | "- This allows multiple tasks to be learned without an increase in network capacity, with weights shared efficiently between tasks with related structure. \n", 159 | "\n", 160 | "## The Future (5 Areas of AI Neuroscience will Improve)\n", 161 | "\n", 162 | "![alt text](https://qph.ec.quoracdn.net/main-qimg-67616bfe157abcb81f86aab60ddfc50e \"Logo Title Text 1\")\n", 163 | "\n", 164 | "- The advent of new tools for brain imaging and genetic bioengineering have begun to offer a detailed characterization of the computations occurring in neural circuits\n", 165 | "- This will revolutionize our understanding of mammalian brain function\n", 166 | "\n", 167 | "## Understanding of Physical reality \n", 168 | "\n", 169 | "![alt text](https://i2.wp.com/neurosciencenews.com/files/2018/01/baby-touch-learning-neurosciencenews.jpg \"Logo Title Text 1\")\n", 170 | "\n", 171 | "- Human Infants have knowledge of core concepts relating to the physical world, such as space, number, and objectness, which allow them to construct compositional mental models that can guide inference and prediction \n", 172 | "\n", 173 | "![alt text](https://adriancolyer.files.wordpress.com/2016/12/img_0097.jpeg?w=600 \"Logo Title Text 1\")\n", 174 | "\n", 175 | "- Novel neural network architectures have been developed that interpret and reason about scenes in a humanlike way, by decomposing them into individual objects and their relations\n", 176 | "- Deep RL has been used to capture the processes by which children gain commonsense understanding of the world through interactive experiments\n", 177 | "\n", 178 | "## Efficient learning\n", 179 | "\n", 180 | "![alt text](https://cdn-images-1.medium.com/max/1600/1*jkiFPzRue7h7z1SjUCEarA.png \"Logo Title Text 1\")\n", 181 | "\n", 182 | "- Human cognition is distinguished by its ability to rapidly learn about new concepts from only a handful of examples\n", 183 | "\n", 184 | "## Transfer Learning\n", 185 | "\n", 186 | "![alt text](https://qph.ec.quoracdn.net/main-qimg-a078ed29b350b9b2b1e12c3560dced70-c \"Logo Title Text 1\")\n", 187 | "\n", 188 | "- Humans excel at generalizing or transferring generalized knowledge gained in one context to novel, previously unseen domains\n", 189 | "- one recent report made the very interesting claim that neural codes thought to be important in the representation of map-like spaces might be critical for abstract reasoning in more general domains (Constantinescu et al., 2016). \n", 190 | "\n", 191 | "![alt text](http://nmr.mgh.harvard.edu/mkozhevnlab/wp-content/uploads/images/rp/Spatial_Coding_Systems.png \"Logo Title Text 1\")\n", 192 | "\n", 193 | "- In the mammalian cortex, cells encode the geometry of map-like space with a periodic ‘‘grid’’ code, with receptive fields that tile the local space in a hexagonal pattern\n", 194 | "- Grid codes may be an excellent candidate for organizing conceptual knowledge, because they allow state spaces to be decomposed efficiently, in a way that could support discovery of subgoals and hierarchical planning \n", 195 | "- Using functional neuroimaging, the researchers provided evidence for the existence of such codes while humans performed an abstract categorization task, supporting the view that periodic encoding is a generalized hallmark of human knowledge organization (Constantinescu et al., 2016). \n", 196 | "\n", 197 | "## Imagination and Planning\n", 198 | "\n", 199 | "![alt text](https://rubenfiszel.github.io/posts/rl4j/conv.png \"Logo Title Text 1\")\n", 200 | "\n", 201 | "- Despite their strong performance on goal-directed tasks, deep RL systems such as DQN operate mostly in a reactive way, learning the mapping from perceptual inputs to actions that maximize future value. \n", 202 | "- Two major drawbacks: it is relatively data inefficient, requiring large amounts of experience to derive accurate estimates\n", 203 | "- and it is inflexible, being insensitive to changes in the value of outcomes\n", 204 | "\n", 205 | "https://arxiv.org/abs/1707.06203\n", 206 | "\n", 207 | "\n", 208 | "![alt text](https://pbs.twimg.com/media/DFKIqmUW0AAXj_N.jpg \"Logo Title Text 1\")\n", 209 | "\n", 210 | "- By contrast, humans can more flexibly select actions based on forecasts of long-term future outcomes through simulation-based planning, which uses predictions generated from an internal model of the environment learned through experience\n", 211 | "- An emerging picture from neuroscience research suggests that the hippo- campus supports planning by instantiating an internal model of the environment, with goal-contingent valuation of simulated outcomes occurring in areas downstream of the hippocampus (Redish, 2016)\n", 212 | "- AI research will benefit from a close reading of the related literature on how humans imagine possible scenarios, envision the future, and carry out simulation- based planning, functions that depend on a common neural substrate in the hippocampus\n", 213 | "- Research into human imagination emphasizes its constructive nature, with humans able to construct fictitious mental scenarios by recombining familiar elements in novel ways, necessitating compositional/disentangled representations of the form present in certain generative models\n", 214 | "\n", 215 | "## Virtual Brain Analytics\n", 216 | "\n", 217 | "![alt text](http://www.cfhu.org/sites/files/cfhu.org/quanta-magazine-header-deep-learning.gif \"Logo Title Text 1\")\n", 218 | "\n", 219 | "- Due to their complexity, the products of AI research often remain ‘‘black boxes’’; \n", 220 | "- we understand only poorly the nature of the computations that occur, or representations that are formed, during learning of complex tasks.\n", 221 | "\n", 222 | "![alt text](http://simpleneuroscience.com/wp-content/uploads/2017/03/800px-Two-photon_microscopy_of_in_vivo_brain_function-777x437.jpg \"Logo Title Text 1\")\n", 223 | "\n", 224 | "- But by applying tools from neuroscience to AI systems, synthetic equiv- alents of single-cell recording, neuroimaging, and lesion techniques, we can gain insights into the key drivers of successful learning in AI research and increase the interpretability of these systems. i.e ‘‘virtual brain analytics.'\n", 225 | "- visualizing brain states through dimensionality reduction is commonplace in neuroscience, can be applied more in AI research\n", 226 | "- Important as complexity of neural architecture increases" 227 | ] 228 | }, 229 | { 230 | "cell_type": "code", 231 | "execution_count": null, 232 | "metadata": {}, 233 | "outputs": [], 234 | "source": [] 235 | } 236 | ], 237 | "metadata": { 238 | "kernelspec": { 239 | "display_name": "Python 3", 240 | "language": "python", 241 | "name": "python3" 242 | }, 243 | "language_info": { 244 | "codemirror_mode": { 245 | "name": "ipython", 246 | "version": 3 247 | }, 248 | "file_extension": ".py", 249 | "mimetype": "text/x-python", 250 | "name": "python", 251 | "nbconvert_exporter": "python", 252 | "pygments_lexer": "ipython3", 253 | "version": "3.6.3" 254 | } 255 | }, 256 | "nbformat": 4, 257 | "nbformat_minor": 2 258 | } 259 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | SpectraVis 2 | ========== 3 | 4 | This is the code from [this](https://youtu.be/e_BOJS1BLj8) video on Youtube by Siraj Raval. 5 | 6 | An interactive network visualization tool for exploring [functional brain connectivity](http://www.scholarpedia.org/article/Brain_connectivity) using [d3.js](http://d3js.org/). See [this](http://ericdeno.com/research/SpectraVis/) for an example of SpectraVis in action. 7 | 8 | ![](./SpectraVis-Demo.gif) 9 | 10 | SpectraVis allows you to: 11 | + examine how network dynamics change over time and frequency 12 | + compare local (statistical dependencies between a single pair of nodes) and global (statistical dependencies between all nodes) dynamics. 13 | + compare different types of functional connectivity measures (correlation, coherence). 14 | + compare between different subjects. 15 | + examine only within- or between-brain area connections 16 | + switch between multiple network views for better understanding of the network structure 17 | 18 | ## Installation 19 | To install SpectraVis, download the latest release: 20 | + [https://github.com/edeno/SpectraVis/releases](https://github.com/edeno/SpectraVis/releases) 21 | 22 | Or use Node.js and its package manager (npm): 23 | 24 | 1. Open a terminal (Mac) or a Windows Command Prompt (`Start > All Programs > Accessories > Windows Command Prompt `) 25 | 2. Download or clone the repository: `git clone https://github.com/edeno/SpectraVis.git` 26 | 3. Install Node.js using one of the [installers](https://nodejs.org/). 27 | 4. Enter in the terminal or command prompt: `npm install spectravis` 28 | 29 | This will install the relevant development dependencies. Running `gulp` in the terminal will automatically launch a webserver on [http://localhost:8000/](http://localhost:8000/) where you can view the visualization. 30 | 31 | ## Usage 32 | `spectravis.init(params)` starts the visualization in `index.html`. 33 | 34 | See the [wiki](https://github.com/edeno/SpectraVis/wiki) for more information on how to view the visualization on your local machine, the expected structure of the data, and converting data from Matlab to JSON. 35 | 36 | ## Modifying and Contributing 37 | Fork, then clone the repo: 38 | ```` 39 | git clone git@github.com/your-username/SpectraVis.git 40 | ```` 41 | Use `npm install` to get the development dependencies. Place your Data in `app/DATA/`. 42 | 43 | Push to your fork and submit a pull request to the `develop` branch. 44 | 45 | ## License 46 | [GPL-v2](http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html) 47 | 48 | 49 | ## Credits 50 | 51 | The credits for this code go to [Neurophysvis](https://github.com/NeurophysVis/SpectraVis). I've merely created a wrapper to get people started. 52 | -------------------------------------------------------------------------------- /SpectraVis-Demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llSourcell/machine_learning_and_neuroscience/80319df7d4621964b3ce5c282cc8350b51961dd9/SpectraVis-Demo.gif -------------------------------------------------------------------------------- /app/css/spectra.css: -------------------------------------------------------------------------------- 1 | .axis path, .axis line { 2 | fill: none; 3 | stroke: #000; 4 | shape-rendering: crispEdges; 5 | } 6 | .axis text { 7 | font: 11px sans-serif; 8 | color: #777; 9 | } 10 | .hideAxisLines path { 11 | display: none; 12 | } 13 | .edge { 14 | stroke-opacity: .6; 15 | } 16 | .node { 17 | stroke: #FFF; 18 | stroke-width 0.5px; 19 | } 20 | text.nodeLabel { 21 | font-family: sans-serif; 22 | font-size: 11px; 23 | text-anchor: middle; 24 | line-height: 100%; 25 | dominant-baseline: central; 26 | cursor: pointer; 27 | } 28 | button.dropdown-toggle { 29 | width: 100%; 30 | } 31 | output { 32 | padding-top: 0px; 33 | text-align: center; 34 | } 35 | .bottom-buffer { 36 | margin-bottom: 10px; 37 | } 38 | #export-link-help > button { 39 | border-style: none; 40 | } 41 | #sidebar { 42 | background: rgba(221, 221, 221, 0.4); 43 | padding: 15px 30px; 44 | border-radius: 25px; 45 | } 46 | button#PlayButtonPanel { 47 | width: 50%; 48 | } 49 | .dropdown li { 50 | cursor: pointer; 51 | } 52 | .dropdown button { 53 | overflow: hidden; 54 | } 55 | g#spect2Slice > g#x.axis, g#spect2Slice > g.zeroLine { 56 | display: none; 57 | } 58 | .load { 59 | width: 100%; 60 | height: 100%; 61 | position: relative; 62 | } 63 | #loading { 64 | position: absolute; 65 | left: 0; 66 | top: 0; 67 | right: 0; 68 | bottom: 0; 69 | margin: auto; 70 | z-index: 200; 71 | } 72 | #overlay { 73 | position: fixed; 74 | top: 0; 75 | left: 0; 76 | width: 100%; 77 | height: 100%; 78 | z-index: 200; 79 | background: rgba(0, 0, 0, 0.5); 80 | } 81 | #helpToolTip { 82 | padding: 4px 20px; 83 | font-size: 14px; 84 | background: #f5f5f5; 85 | max-width: 44em; 86 | max-height: 44em; 87 | vertical-align: middle; 88 | visibility: visible; 89 | outline: medium none; 90 | position: fixed; 91 | z-index: 200; 92 | top: 50%; 93 | left: 50%; 94 | transform: translate(-50%, -75%); 95 | border: 1px solid #e3e3e3; 96 | border-radius: 4px; 97 | } 98 | #permalink { 99 | position: absolute; 100 | z-index: 200; 101 | background: #EEE; 102 | border: 1px solid #888; 103 | width: 520px; 104 | margin: 25px 10px; 105 | font-size: 8pt; 106 | display: none; 107 | padding: 10px; 108 | } 109 | #permalink > label { 110 | margin-top: 5px; 111 | } 112 | .copy-link { 113 | width: 100%; 114 | padding: 7px 9px; 115 | overflow: hidden; 116 | resize: none; 117 | } 118 | -------------------------------------------------------------------------------- /app/js/main.js: -------------------------------------------------------------------------------- 1 | (function() { 2 | spectraVis = {}; 3 | params = {}; 4 | var networkWidth; 5 | var networkHeight; 6 | var svgNetworkMap; 7 | var subjectObject; 8 | var curSubject; 9 | var edgeStatID; 10 | var NUM_COLORS = 11; 11 | var NODE_RADIUS = 10; 12 | var EDGE_WIDTH = 2; 13 | var stopAnimation = true; 14 | var curCh1; 15 | var curCh2; 16 | var curFreqInd; 17 | var curTimeInd; 18 | var mouseFlag = true; 19 | var edgeFilter; 20 | var networkView; 21 | var svgCh1; 22 | var svgEdgeStat; 23 | var svgCh2; 24 | var svgSpectraLegend; 25 | var svgEdgeStatLegend; 26 | var edgeStatLegendTitle; 27 | var svgAnatomicalLegend; 28 | var svgTimeSlice; 29 | var panelWidth; 30 | var edgeFilterDropdown; 31 | var networkSpinner; 32 | var spect1Spinner; 33 | var spect2Spinner; 34 | var edgeSpinner; 35 | var panelWidth; 36 | var panelHeight; 37 | var legendWidth; 38 | var timeSliceWidth; 39 | var timeSliceHeight; 40 | var edgeInfo; 41 | var subjectData; 42 | var visInfo; 43 | var margin; 44 | var edgeStatName; 45 | var channel; 46 | var edgeData; 47 | var time; 48 | var freq; 49 | 50 | colorbrewer.PiYG[NUM_COLORS].reverse(); 51 | colorbrewer.RdBu[NUM_COLORS].reverse(); 52 | 53 | spectraVis.init = function(params) { 54 | margin = { 55 | top: 30, 56 | right: 30, 57 | bottom: 30, 58 | left: 30, 59 | }; 60 | panelWidth = document.getElementById('SpectraCh1Panel').offsetWidth - margin.left - margin.right; 61 | panelHeight = document.getElementById('SpectraCh1Panel').offsetWidth * (4 / 5) - margin.top - margin.bottom; 62 | legendWidth = document.getElementById('legendKey').offsetWidth - 5 - 5 - 30; // -30 comes from css padding. Kind of hacky. 63 | var colorbarLegendHeight = 60; 64 | var anatomicalLegendHeight = 100 - margin.top - margin.bottom; 65 | timeSliceWidth = panelWidth; 66 | timeSliceHeight = 180 - margin.top - margin.bottom; 67 | var spinnerOpts = { 68 | zIndex: 100, 69 | }; 70 | freq = +params.freq; 71 | time = +params.time; 72 | edgeFilter = params.edgeFilter || 'All'; 73 | networkView = params.networkView || 'Anatomical'; 74 | curCh1 = params.curCh1; 75 | curCh2 = params.curCh2; 76 | curSubject = params.curSubject; 77 | edgeStatID = params.edgeStatID; 78 | 79 | // Heatmap Panels 80 | svgCh1 = d3.select('#SpectraCh1Panel') 81 | .append('svg') 82 | .attr('width', panelWidth + margin.left + margin.right) 83 | .attr('height', panelHeight + margin.top + margin.bottom) 84 | .append('g') 85 | .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); 86 | svgEdgeStat = d3.select('#EdgeStatPanel') 87 | .append('svg') 88 | .attr('width', panelWidth + margin.left + margin.right) 89 | .attr('height', panelHeight + margin.top + margin.bottom) 90 | .append('g') 91 | .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); 92 | svgCh2 = d3.select('#SpectraCh2Panel') 93 | .append('svg') 94 | .attr('width', panelWidth + margin.left + margin.right) 95 | .attr('height', panelHeight + margin.top + margin.bottom) 96 | .append('g') 97 | .attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'); 98 | 99 | // Legend SVG 100 | svgSpectraLegend = d3.selectAll('#legendKey').select('#spectraLegend') 101 | .append('svg') 102 | .attr('width', legendWidth + 5 + 5) 103 | .attr('height', 50) 104 | .append('g') 105 | .attr('transform', 'translate(' + 5 + ',' + 25 + ')'); 106 | svgSpectraLegend.append('text') 107 | .attr('transform', 'translate(-5, -5)') 108 | .attr('font-size', 12) 109 | .attr('font-weight', 700) 110 | .text('Difference in Power'); 111 | svgEdgeStatLegend = d3.selectAll('#legendKey').select('#edgeStatLegend') 112 | .append('svg') 113 | .attr('width', legendWidth + 5 + 5) 114 | .attr('height', 50) 115 | .append('g') 116 | .attr('transform', 'translate(' + 5 + ',' + 25 + ')'); 117 | edgeStatLegendTitle = svgEdgeStatLegend.append('text') 118 | .attr('transform', 'translate(-5, -5)') 119 | .attr('font-size', 12) 120 | .attr('font-weight', 700) 121 | .text('Edge Statistic'); 122 | svgAnatomicalLegend = d3.selectAll('#legendKey').select('#anatomicalLegend') 123 | .append('svg') 124 | .attr('width', legendWidth + 5 + 5) 125 | .append('g') 126 | .attr('transform', 'translate(' + 5 + ',' + 25 + ')'); 127 | svgAnatomicalLegend.append('text') 128 | .attr('transform', 'translate(-5, -10)') 129 | .attr('font-size', 12) 130 | .attr('font-weight', 700) 131 | .text('Brain Areas'); 132 | 133 | // Time Slice SVG 134 | svgTimeSlice = d3.select('#timeSlice') 135 | .append('svg') 136 | .attr('width', timeSliceWidth + 40 + 40) 137 | .attr('height', timeSliceHeight + 40 + 40) 138 | .append('g') 139 | .attr('transform', 'translate(' + 40 + ',' + 40 + ')'); 140 | 141 | // Set up help overlay 142 | var overlay = d3.select('#overlay'); 143 | var helpButton = d3.select('button#help-button'); 144 | overlay.selectAll('.close') 145 | .on('click', function() { 146 | overlay.style('display', 'none'); 147 | }); 148 | 149 | helpButton 150 | .on('click', function() { 151 | overlay 152 | .style('display', 'block'); 153 | }); 154 | 155 | // Set up permalink button 156 | var permalink = d3.select('#permalink'); 157 | var linkButton = d3.select('button#link'); 158 | linkButton 159 | .on('click', function() { 160 | permalink 161 | .style('display', 'block'); 162 | var linkString = window.location.origin + window.location.pathname + '?' + 163 | 'curSubject=' + curSubject + 164 | '&edgeStatID=' + edgeStatID + 165 | '&edgeFilter=' + edgeFilter + 166 | '&networkView=' + networkView + 167 | '&time=' + visInfo.tax[curTimeInd] + 168 | '&freq=' + visInfo.fax[curFreqInd] + 169 | '&curCh1=' + curCh1 + 170 | '&curCh2=' + curCh2; 171 | permalink.selectAll('textarea').html(linkString); 172 | permalink.selectAll('.bookmark').attr('href', linkString); 173 | }); 174 | 175 | permalink.selectAll('.close') 176 | .on('click', function() { 177 | permalink.style('display', 'none'); 178 | }); 179 | 180 | // Set up export svg button 181 | var exportButton = d3.select('button#export'); 182 | exportButton 183 | .on('click', function() { 184 | var networkSVG = d3.select('#NetworkPanel').select('svg').node(); 185 | var networkSaveName = 'Network' + '_' + 186 | curSubject + '_' + 187 | edgeStatID + '_' + 188 | networkView + '_' + 189 | visInfo.tax[curTimeInd] + visInfo.tunits + '_' + 190 | visInfo.fax[curFreqInd] + visInfo.funits; 191 | 192 | d3_save_svg.save(networkSVG, {filename: networkSaveName}); 193 | 194 | var ch1SaveName = 'Spectra' + '_' + 195 | curSubject + '_' + 196 | 'Ch' + curCh1; 197 | 198 | var ch1SVG = d3.select('#SpectraCh1Panel').select('svg').node(); 199 | d3_save_svg.save(ch1SVG, {filename: ch1SaveName}); 200 | 201 | var ch2SaveName = 'Spectra' + '_' + 202 | curSubject + '_' + 203 | 'Ch' + curCh2; 204 | 205 | var ch2SVG = d3.select('#SpectraCh2Panel').select('svg').node(); 206 | d3_save_svg.save(ch2SVG, {filename: ch2SaveName}); 207 | 208 | var edgeSaveName = edgeStatID + '_' + 209 | curSubject + '_' + 210 | 'Ch' + curCh1 + '_' + 211 | 'Ch' + curCh2; 212 | 213 | var edgeSVG = d3.select('#EdgeStatPanel').select('svg').node(); 214 | d3_save_svg.save(edgeSVG, {filename: edgeSaveName}); 215 | 216 | d3.selectAll('circle.node')[0] 217 | .forEach(function(n) {n.setAttribute('style', ''); 218 | }); 219 | }); 220 | 221 | // Set up edge area dropdown menus 222 | edgeFilterDropdown = d3.select('#EdgeFilterDropdown'); 223 | edgeFilterDropdown.selectAll('button') 224 | .text(edgeFilter) 225 | .append('span') 226 | .attr('class', 'caret'); 227 | 228 | // Spinners 229 | networkSpinner = new Spinner(spinnerOpts); 230 | spect1Spinner = new Spinner(spinnerOpts); 231 | spect2Spinner = new Spinner(spinnerOpts); 232 | edgeSpinner = new Spinner(spinnerOpts); 233 | 234 | // Load subject data 235 | queue() 236 | .defer(d3.json, 'DATA/subjects.json') 237 | .defer(d3.json, 'DATA/visInfo.json') 238 | .defer(d3.json, 'DATA/edgeTypes.json') 239 | .await(createMenu); 240 | }; 241 | 242 | // Functions 243 | function createMenu(error, subjects, vI, eI) { 244 | visInfo = vI; 245 | edgeInfo = eI; 246 | 247 | if (visInfo.tax.indexOf(time) !== -1) { 248 | curTimeInd = visInfo.tax.indexOf(time); 249 | } else { 250 | curTimeInd = 0; 251 | } 252 | 253 | if (visInfo.fax.indexOf(freq) !== -1) { 254 | curFreqInd = visInfo.fax.indexOf(freq); 255 | } else { 256 | curFreqInd = 0; 257 | } 258 | 259 | // Populate dropdown menu with subjects 260 | subjectData = subjects; 261 | var subjectDropdown = d3.select('#SubjectDropdown'); 262 | var subjectMenu = subjectDropdown.selectAll('.dropdown-menu').selectAll('li').data(subjectData); 263 | subjectMenu.enter() 264 | .append('li') 265 | .attr('id', function(d) { 266 | return d.subjectID; 267 | }) 268 | .attr('role', 'presentation') 269 | .append('a') 270 | .attr('role', 'menuitem') 271 | .attr('tabindex', -1) 272 | .text(function(d) { 273 | return d.subjectID; 274 | }); 275 | 276 | // Default to the first subject 277 | curSubject = curSubject || subjectData[0].subjectID; 278 | subjectDropdown.selectAll('button') 279 | .text(curSubject) 280 | .append('span') 281 | .attr('class', 'caret'); 282 | 283 | // Create dropdown for edge types 284 | var edgeDropdown = d3.select('#EdgeStatTypeDropdown'); 285 | var edgeOptions = edgeDropdown.select('ul').selectAll('li').data(edgeInfo); 286 | edgeOptions.enter() 287 | .append('li') 288 | .attr('id', function(d) { 289 | return d.edgeStatID; 290 | }) 291 | .append('a') 292 | .attr('role', 'menuitem') 293 | .attr('tabindex', -1) 294 | .text(function(d) { 295 | return d.edgeStatName; 296 | }); 297 | 298 | edgeOptions.exit() 299 | .remove(); 300 | 301 | // Default to the first subject 302 | edgeStatID = edgeStatID || edgeInfo[0].edgeStatID; 303 | edgeStatName = edgeInfo.filter(function(e) {return e.edgeStatID === edgeStatID;})[0].edgeStatName; 304 | edgeDropdown.selectAll('button') 305 | .text(edgeStatName) 306 | .append('span') 307 | .attr('class', 'caret'); 308 | 309 | // Set brain area legend height 310 | d3.selectAll('#legendKey').selectAll('#anatomicalLegend').selectAll('svg') 311 | .attr('height', 14 + visInfo.brainRegions.length * 15.14); 312 | 313 | // Load channel data 314 | loadChannelData(); 315 | } 316 | 317 | // Load channel file and set the network svg to be the right aspect ratio for the brain 318 | function loadChannelData() { 319 | 320 | var channelFile = 'channels_' + curSubject + '.json'; 321 | 322 | subjectObject = subjectData.filter(function(d) { 323 | return d.subjectID === curSubject; 324 | })[0]; 325 | 326 | var aspectRatio = subjectObject.brainXpixels / subjectObject.brainYpixels; 327 | networkWidth = document.getElementById('NetworkPanel').offsetWidth - margin.left - margin.right; 328 | networkHeight = document.getElementById('NetworkPanel').offsetWidth * (1 / aspectRatio) - margin.top - margin.bottom; 329 | 330 | svgNetworkMap = d3.select('#NetworkPanel').selectAll('svg').data([subjectObject], function(d) { 331 | return d.subjectID; 332 | }); 333 | 334 | svgNetworkMap.exit().remove(); 335 | svgNetworkMap = svgNetworkMap.enter() 336 | .append('svg') 337 | .attr('width', networkWidth) 338 | .attr('height', networkHeight) 339 | .append('g'); 340 | networkSpinner.spin(document.getElementById('NetworkPanel')); 341 | svgNetworkMap.style('display', 'none'); 342 | d3.json('DATA/' + channelFile, function(isError, channelData) { 343 | 344 | channel = channelData; 345 | 346 | // Default to first two channels if no channels are not already specified 347 | curCh1 = curCh1 || channel[0].channelID; 348 | curCh2 = curCh2 || channel[1].channelID; 349 | 350 | loadEdges(); 351 | }); 352 | } 353 | 354 | function loadEdges() { 355 | // Load the edge file for the current subject 356 | var edgeFile = 'edges_' + curSubject + '_' + edgeStatID + '.json'; 357 | d3.json('DATA/' + edgeFile, function(isError, eD) { 358 | edgeData = eD; 359 | loadSpectra(); 360 | }); 361 | } 362 | 363 | function loadSpectra() { 364 | 365 | // Start loading spinners 366 | spect1Spinner.spin(document.getElementById('SpectraCh1Panel')); 367 | spect2Spinner.spin(document.getElementById('SpectraCh2Panel')); 368 | edgeSpinner.spin(document.getElementById('EdgeStatPanel')); 369 | svgCh1.style('display', 'none'); 370 | svgCh2.style('display', 'none'); 371 | svgEdgeStat.style('display', 'none'); 372 | svgTimeSlice.style('display', 'none'); 373 | 374 | var spectCh1File = 'spectrogram_' + curSubject + '_' + curCh1 + '.json'; 375 | var spectCh2File = 'spectrogram_' + curSubject + '_' + curCh2 + '.json'; 376 | 377 | // Load the rest of the files in parallel 378 | queue() 379 | .defer(d3.json, 'DATA/' + spectCh1File) 380 | .defer(d3.json, 'DATA/' + spectCh2File) 381 | .await(display); 382 | } 383 | 384 | // Draw 385 | function display(isError, spect1, spect2) { 386 | 387 | var timeScale; 388 | var timeScaleLinear; 389 | var freqScale; 390 | var powerScale; 391 | var tAx; 392 | var fAx; 393 | var powerScale; 394 | var networkXScale; 395 | var networkYScale; 396 | var force; 397 | var timeSlider; 398 | var freqSlider; 399 | var timeSliderText; 400 | var freqSliderText; 401 | var subjectDropdown; 402 | var edgeStatScale; 403 | var edgeStatTypeDropdown; 404 | var brainRegionColor; 405 | var timeSliderStep; 406 | var timeMaxStepInd; 407 | var networkXExtent; 408 | var networkYExtent; 409 | var edgeStat; 410 | var powerLineFun; 411 | var edgeStatLineFun; 412 | var timeSlicePowerScale; 413 | var timeSliceNetworkStatScale; 414 | var spect1Line; 415 | var spect2Line; 416 | var edgeStatLine; 417 | var powerScale; 418 | var edgeStatScale; 419 | var isFreq; 420 | var isWeightedNetwork; 421 | var corrScale; 422 | var curEdgeInfo; 423 | var scaledChannel; 424 | 425 | tAx = visInfo.tax; // Time Axis 426 | fAx = visInfo.fax; // Frequency Axis 427 | // Get the edge statistic corresponding to the selected channels 428 | edgeStat = edgeData.filter(function(e) { 429 | return (e.source === curCh1 && e.target === curCh2) || 430 | (e.source === curCh2 && e.target === curCh1); 431 | })[0]; 432 | 433 | // Get the edge statastic name and units 434 | curEdgeInfo = edgeInfo 435 | .filter(function(e) { 436 | return e.edgeStatID === edgeStatID; 437 | })[0]; 438 | 439 | isFreq = curEdgeInfo.isFreq; 440 | isWeightedNetwork = curEdgeInfo.isWeightedNetwork; 441 | 442 | // Set up scales and slider values 443 | setupScales(); 444 | setupSliders(); 445 | 446 | // Initialize charts 447 | var powerChart = heatmap() 448 | .height(panelHeight) 449 | .width(panelWidth) 450 | .yScale(freqScale) 451 | .xScale(timeScale) 452 | .xLabel('Time (' + visInfo.tunits + ')') 453 | .yLabel('Frequency (' + visInfo.funits + ')') 454 | .colorScale(powerScale) 455 | .rectMouseOver(rectMouseOver) 456 | .rectMouseClick(rectMouseClick); 457 | 458 | var cohChart = heatmap() 459 | .height(panelHeight) 460 | .width(panelWidth) 461 | .yScale(freqScale) 462 | .xScale(timeScale) 463 | .xLabel('Time (' + visInfo.tunits + ')') 464 | .yLabel('Frequency (' + visInfo.funits + ')') 465 | .colorScale(edgeStatScale) 466 | .rectMouseOver(rectMouseOver) 467 | .rectMouseClick(rectMouseClick); 468 | 469 | var corrChart = timeseries() 470 | .height(panelHeight) 471 | .width(panelWidth) 472 | .yScale(corrScale) 473 | .xScale(timeScale) 474 | .xLabel('Time (' + visInfo.tunits + ')') 475 | .yLabel(edgeStatName) 476 | .rectMouseOver(rectMouseOver) 477 | .rectMouseClick(rectMouseClick); 478 | 479 | var cohTimeSlice = timeseries() 480 | .height(timeSliceHeight) 481 | .width(timeSliceWidth) 482 | .yScale(timeSliceEdgeStatScale) 483 | .xScale(timeScale) 484 | .yAxisOrientation('left') 485 | .xLabel('Time (' + visInfo.tunits + ')') 486 | .yLabel(edgeStatName); 487 | 488 | var powerTimeSlice = timeseries() 489 | .height(timeSliceHeight) 490 | .width(timeSliceWidth) 491 | .yScale(timeSlicePowerScale) 492 | .xScale(timeScale) 493 | .yAxisOrientation('right') 494 | .xLabel('Time (' + visInfo.tunits + ')') 495 | .yLabel('Power Difference') 496 | .lineColor('green'); 497 | 498 | // Draw charts 499 | drawNetwork(); 500 | svgNetworkMap.style('display', ''); 501 | networkSpinner.stop(); 502 | 503 | svgCh1 504 | .datum(spect1.data) 505 | .call(powerChart); 506 | svgCh1.style('display', ''); 507 | spect1Spinner.stop(); 508 | 509 | svgCh2 510 | .datum(spect2.data) 511 | .call(powerChart); 512 | spect2Spinner.stop(); 513 | svgCh2.style('display', ''); 514 | 515 | if (isFreq) { 516 | svgEdgeStat 517 | .html(''); 518 | svgEdgeStat 519 | .datum(edgeStat.data) 520 | .call(cohChart); 521 | drawTimeSlice(); 522 | } else { 523 | // Remove coherence and time slice charts 524 | svgEdgeStat 525 | .html(''); 526 | svgTimeSlice 527 | .html(''); 528 | svgEdgeStat 529 | .datum(edgeStat.data) 530 | .call(corrChart); 531 | } 532 | 533 | svgEdgeStat.style('display', ''); 534 | edgeSpinner.stop(); 535 | svgTimeSlice.style('display', ''); 536 | 537 | // Draw legends and titles 538 | drawTitles(); 539 | drawLegends(); 540 | 541 | // Handle buttons 542 | subjectLoad(); 543 | edgeStatTypeLoad(); 544 | edgeFilterLoad(); 545 | networkViewLoad(); 546 | playButtonStart(); 547 | resetButton(); 548 | 549 | function setupSliders() { 550 | 551 | timeSlider = d3.select('#timeSlider'); 552 | timeSliderText = d3.select('#timeSlider-value'); 553 | freqSlider = d3.select('#freqSlider'); 554 | freqSliderText = d3.select('#freqSlider-value'); 555 | 556 | timeSliderStep = d3.round(tAx[1] - tAx[0], 4); 557 | timeMaxStepInd = tAx.length - 1; 558 | 559 | timeSlider.property('min', d3.min(tAx)); 560 | timeSlider.property('max', d3.max(tAx)); 561 | timeSlider.property('step', timeSliderStep); 562 | timeSlider.property('value', tAx[curTimeInd]); 563 | timeSlider.on('input', updateTimeSlider); 564 | timeSliderText.text(tAx[curTimeInd] + ' ms'); 565 | 566 | freqSlider.property('min', d3.min(fAx)); 567 | freqSlider.property('max', d3.max(fAx)); 568 | freqSlider.property('step', fAx[1] - fAx[0]); 569 | freqSlider.property('value', fAx[curFreqInd]); 570 | freqSlider.on('input', updateFreqSlider); 571 | freqSliderText.text(fAx[curFreqInd] + ' Hz'); 572 | } 573 | 574 | function setupScales() { 575 | var powerColors = colorbrewer.PiYG[NUM_COLORS]; 576 | var edgeStatColors = colorbrewer.RdBu[NUM_COLORS]; 577 | var powerMin; 578 | var powerMax; 579 | var powerExtent; 580 | var edgeStatMin; 581 | var edgeStatMax; 582 | var edgeStatExtent; 583 | 584 | brainRegionColor = d3.scale.ordinal() 585 | .domain(visInfo.brainRegions) 586 | .range(colorbrewer.Pastel1[7]); 587 | 588 | powerMin = d3.min( 589 | [d3.min(spect1.data, function(d) { 590 | return d3.min(d, function(e) { 591 | return e; 592 | }); 593 | }), 594 | 595 | d3.min(spect2.data, function(d) { 596 | return d3.min(d, function(e) { 597 | return e; 598 | }); 599 | }), 600 | ] 601 | 602 | ); 603 | 604 | powerMax = d3.max( 605 | [d3.max(spect1.data, function(d) { 606 | return d3.max(d, function(e) { 607 | return e; 608 | }); 609 | }), 610 | 611 | d3.max(spect2.data, function(d) { 612 | return d3.max(d, function(e) { 613 | return e; 614 | }); 615 | }), 616 | ] 617 | ); 618 | 619 | powerExtent = symmetricExtent(powerMin, powerMax); 620 | 621 | networkXExtent = subjectObject.brainXLim; 622 | networkYExtent = subjectObject.brainYLim; 623 | 624 | edgeStatMin = d3.min(edgeData, function(d) { 625 | return d3.min(d.data, function(e) { 626 | return d3.min(e, function(f) { 627 | return f; 628 | }); 629 | }); 630 | }); 631 | 632 | edgeStatMax = d3.max(edgeData, function(d) { 633 | return d3.max(d.data, function(e) { 634 | return d3.max(e, function(f) { 635 | return f; 636 | }); 637 | }); 638 | }); 639 | 640 | edgeStatExtent = symmetricExtent(edgeStatMin, edgeStatMax); 641 | 642 | powerScale = d3.scale.linear() 643 | .domain(powerExtent) 644 | .range(powerColors); 645 | if (isWeightedNetwork) { 646 | edgeStatScale = d3.scale.linear() 647 | .domain(edgeStatExtent) 648 | .range(edgeStatColors); 649 | } else { 650 | edgeStatColors = [0, (NUM_COLORS - 1) / 2, NUM_COLORS - 1].map(function(n) { return edgeStatColors[n];}); 651 | 652 | edgeStatScale = d3.scale.ordinal() 653 | .domain([-1, 0, 1]) 654 | .range(edgeStatColors); 655 | } 656 | 657 | timeScale = d3.scale.ordinal() 658 | .domain(tAx) 659 | .rangeBands([0, panelWidth]); 660 | 661 | timeScaleLinear = d3.scale.linear() 662 | .domain(d3.extent(tAx)) 663 | .range([0, panelWidth]); 664 | 665 | freqScale = d3.scale.ordinal() 666 | .domain(fAx) 667 | .rangeBands([panelHeight, 0]); 668 | 669 | timeSlicePowerScale = d3.scale.linear() 670 | .domain(powerExtent) 671 | .range(linspace(timeSliceHeight, 0, NUM_COLORS)); 672 | timeSliceEdgeStatScale = d3.scale.linear() 673 | .domain(edgeStatExtent) 674 | .range(linspace(timeSliceHeight, 0, NUM_COLORS)); 675 | 676 | networkXScale = d3.scale.linear() 677 | .domain(networkXExtent) 678 | .range([0, networkWidth]); 679 | networkYScale = d3.scale.linear() 680 | .domain(networkYExtent) 681 | .range([networkHeight, 0]); 682 | 683 | corrScale = d3.scale.linear() 684 | .domain(edgeStatExtent) 685 | .range(linspace(0, panelHeight, NUM_COLORS)); 686 | 687 | function symmetricExtent(min, max) { 688 | if (Math.abs(min) >= Math.abs(max)) { 689 | max = Math.abs(min); 690 | } else { 691 | min = -1 * max; 692 | } 693 | 694 | return linspace(min, max, 11); 695 | } 696 | 697 | // from https://github.com/sloisel/numeric 698 | function linspace(a, b, n) { 699 | if (typeof n === 'undefined') { 700 | n = Math.max(Math.round(b - a) + 1, 1); 701 | }; 702 | 703 | if (n < 2) { 704 | return n === 1 ? [a] : []; 705 | } 706 | 707 | var i; 708 | var ret = Array(n); 709 | n--; 710 | for (i = n; i >= 0; i--) { 711 | ret[i] = (i * b + (n - i) * a) / n; 712 | } 713 | 714 | return ret; 715 | } 716 | } 717 | 718 | function drawNetwork() { 719 | var nodesGroup; 720 | var edgesGroup; 721 | var nodeG; 722 | var strokeStyle; 723 | var nodeClickNames = []; 724 | var brainImage; 725 | var edge; 726 | var edgeLine; 727 | var brainImageG; 728 | var nodeCircle; 729 | var nodeText; 730 | 731 | if (networkView === 'Anatomical') { 732 | scaledChannel = channel.map(function(n) { 733 | var obj = copyObject(n); 734 | obj.x = networkXScale(n.x); 735 | obj.y = networkYScale(n.y); 736 | obj.fixed = true; 737 | return obj; 738 | }); 739 | } else { 740 | scaledChannel = channel.map(function(n, i) { 741 | var obj = copyObject(n); 742 | if (typeof scaledChannel === 'undefined') { 743 | obj.x = networkXScale(n.x); 744 | obj.y = networkYScale(n.y); 745 | } else { 746 | obj.x = scaledChannel[i].x; 747 | obj.y = scaledChannel[i].y; 748 | obj.px = scaledChannel[i].px; 749 | obj.py = scaledChannel[i].py; 750 | } 751 | 752 | obj.fixed = false; 753 | return obj; 754 | }); 755 | } 756 | 757 | // Replace source name by source object 758 | edge = edgeData.map(function(e) { 759 | var obj = copyObject(e); 760 | obj.source = scaledChannel.filter(function(n) { 761 | return n.channelID === e.source; 762 | })[0]; 763 | 764 | obj.target = scaledChannel.filter(function(n) { 765 | return n.channelID === e.target; 766 | })[0]; 767 | 768 | obj.data = obj.data[curTimeInd][curFreqInd]; 769 | return obj; 770 | }); 771 | 772 | edge = edge.filter(edgeFiltering); 773 | 774 | force = d3.layout.force() 775 | .nodes(scaledChannel) 776 | .links(edge) 777 | .charge(-375) 778 | .linkDistance(networkHeight / 3) 779 | .size([networkWidth, networkHeight]) 780 | .start(); 781 | 782 | brainImageG = svgNetworkMap.selectAll('g#BRAIN_IMAGE').data([{}]); 783 | brainImageG.enter() 784 | .append('g') 785 | .attr('id', 'BRAIN_IMAGE'); 786 | edgesGroup = svgNetworkMap.selectAll('g#EDGES').data([{}]); 787 | edgesGroup.enter() 788 | .append('g') 789 | .attr('id', 'EDGES'); 790 | nodesGroup = svgNetworkMap.selectAll('g#NODES').data([{}]); 791 | nodesGroup.enter() 792 | .append('g') 793 | .attr('id', 'NODES'); 794 | 795 | edgeLine = edgesGroup.selectAll('.edge').data(edge, function(e) { 796 | return curSubject + '_' + e.source.channelID + '_' + e.target.channelID; 797 | }); 798 | 799 | edgeLine.enter() 800 | .append('line') 801 | .attr('class', 'edge') 802 | .style('stroke-width', EDGE_WIDTH) 803 | .attr('x1', function(d) { 804 | return xPos(d.source); 805 | }) 806 | .attr('y1', function(d) { 807 | return yPos(d.source); 808 | }) 809 | .attr('x2', function(d) { 810 | return xPos(d.target); 811 | }) 812 | .attr('y2', function(d) { 813 | return yPos(d.target); 814 | }); 815 | 816 | edgeLine.exit() 817 | .remove(); 818 | edgeLine 819 | .style('stroke', function(d) { 820 | return edgeStatScale(d.data); 821 | }) 822 | .on('mouseover', edgeMouseOver) 823 | .on('mouseout', edgeMouseOut) 824 | .on('click', edgeMouseClick); 825 | 826 | nodeG = nodesGroup.selectAll('g.gnode').data(scaledChannel, function(d) { 827 | return curSubject + '_' + d.channelID; 828 | }); 829 | 830 | nodeG.enter() 831 | .append('g') 832 | .attr('class', 'gnode') 833 | .attr('transform', function(d) { 834 | return 'translate(' + [xPos(d), yPos(d)] + ')'; 835 | }) 836 | .on('click', nodeMouseClick); 837 | nodeG.exit().remove(); 838 | 839 | nodeCircle = nodeG.selectAll('circle.node').data(function(d) { 840 | return [d]; 841 | }); 842 | 843 | nodeCircle.enter() 844 | .append('circle') 845 | .attr('class', 'node') 846 | .attr('r', NODE_RADIUS) 847 | .attr('fill', '#ddd') 848 | .attr('opacity', 1); 849 | nodeCircle 850 | .attr('fill', function(d) { 851 | return brainRegionColor(d.region); 852 | }) 853 | .style('stroke', 'white'); 854 | 855 | nodeCircle.filter(function(d) {return d.channelID == curCh1 || d.channelID == curCh2;}) 856 | .style('stroke', 'black'); 857 | 858 | nodeText = nodeG.selectAll('text.nodeLabel').data(function(d) { 859 | return [d]; 860 | }); 861 | 862 | nodeText.enter() 863 | .append('text') 864 | .attr('class', 'nodeLabel') 865 | .text(function(d) { 866 | return d.channelID; 867 | }); 868 | 869 | // For every iteration of force simulation 'tick' 870 | force.on('tick', function() { 871 | 872 | // Translate the groups 873 | nodeG.attr('transform', function(d) { 874 | return 'translate(' + [xPos(d), yPos(d)] + ')'; 875 | }); 876 | 877 | edgeLine.attr('x1', function(d) { 878 | return xPos(d.source); 879 | }) 880 | .attr('y1', function(d) { 881 | return yPos(d.source); 882 | }) 883 | .attr('x2', function(d) { 884 | return xPos(d.target); 885 | }) 886 | .attr('y2', function(d) { 887 | return yPos(d.target); 888 | }); 889 | 890 | if (networkView !== 'Topological') { 891 | force.stop(); 892 | } 893 | 894 | }); 895 | 896 | brainImage = brainImageG.selectAll('image').data([subjectObject], function(d) { 897 | return d.brainFilename; 898 | }); 899 | 900 | if (networkView === 'Anatomical') { 901 | brainImage.enter() 902 | .append('image') 903 | .attr('width', networkWidth) 904 | .attr('height', networkHeight); 905 | 906 | // replace link by data URI 907 | getImageBase64('DATA/brainImages/' + subjectObject.brainFilename, function(err, d) { 908 | brainImage 909 | .attr('xlink:href', 'data:image/png;base64,' + d); 910 | }); 911 | } 912 | 913 | brainImage.exit() 914 | .remove(); 915 | if (networkView === 'Topological') { 916 | brainImage.remove(); 917 | }; 918 | 919 | function xPos(d) { 920 | return Math.max(NODE_RADIUS, Math.min(networkWidth - NODE_RADIUS, d.x)); 921 | } 922 | 923 | function yPos(d) { 924 | return Math.max(NODE_RADIUS, Math.min(networkHeight - NODE_RADIUS, d.y)); 925 | } 926 | 927 | function edgeMouseOver(e) { 928 | 929 | var curEdge = d3.select(this); 930 | strokeStyle = curEdge.style('stroke'); 931 | curEdge 932 | .style('stroke-width', 2 * EDGE_WIDTH) 933 | .style('stroke', function() { 934 | if (e.data < 0) { 935 | return edgeStatScale(d3.min(edgeStatScale.domain())); 936 | } else { 937 | return edgeStatScale(d3.max(edgeStatScale.domain())); 938 | } 939 | }); 940 | 941 | var curNodes = d3.selectAll('circle.node') 942 | .filter(function(n) { 943 | return (n.channelID === e.source.channelID) || (n.channelID === e.target.channelID); 944 | }) 945 | .attr('r', NODE_RADIUS * 1.2); 946 | } 947 | 948 | function edgeMouseOut(e) { 949 | var curEdge = d3.select(this); 950 | if (typeof strokeStyle !== 'undefined') { 951 | curEdge 952 | .style('stroke-width', EDGE_WIDTH) 953 | .style('stroke', strokeStyle); 954 | d3.selectAll('circle.node') 955 | .filter(function(n) { 956 | return (n.channelID === e.source.channelID) || (n.channelID === e.target.channelID); 957 | }) 958 | .attr('r', NODE_RADIUS); 959 | } 960 | } 961 | 962 | function edgeMouseClick(e) { 963 | var re = /\d+/; 964 | curCh1 = re.exec(e.source.channelID)[0]; 965 | curCh2 = re.exec(e.target.channelID)[0]; 966 | mouseFlag = true; 967 | svgNetworkMap.select('text#HOLD').remove(); 968 | loadSpectra(); 969 | edgeMouseOut.call(this, e); 970 | } 971 | 972 | function nodeMouseClick(e) { 973 | var curNode = d3.select(this); 974 | var nodeInd = nodeClickNames.indexOf(+e.channelID); 975 | 976 | if (nodeInd > -1) { 977 | // If clicked on node is in the array, remove 978 | curNode.selectAll('circle') 979 | .attr('r', NODE_RADIUS); 980 | nodeClickNames.splice(nodeInd, 1); 981 | } else { 982 | // Else add to array 983 | curNode.selectAll('circle') 984 | .attr('r', 1.2 * NODE_RADIUS); 985 | nodeClickNames.push(+e.channelID); 986 | } 987 | 988 | if (nodeClickNames.length === 2) { 989 | var re = /\d+/; 990 | curCh1 = re.exec(nodeClickNames[0])[0]; 991 | curCh2 = re.exec(nodeClickNames[1])[0]; 992 | mouseFlag = true; 993 | svgNetworkMap.select('text#HOLD').remove(); 994 | d3.selectAll('circle.node') 995 | .filter(function(n) { 996 | return (n.channelID === nodeClickNames[0].toString()) || (n.channelID === nodeClickNames[1].toString()); 997 | }) 998 | .attr('fill', '#ddd') 999 | .attr('r', NODE_RADIUS); 1000 | nodeClickNames = []; 1001 | loadSpectra(); 1002 | } 1003 | } 1004 | 1005 | function edgeFiltering(e) { 1006 | var showEdge = true; 1007 | 1008 | // If edge type is binary, don't display edges corresponding to no edge 1009 | if (!isWeightedNetwork) { 1010 | showEdge = (e.data !== 0); 1011 | } 1012 | 1013 | // Now filter by edge connection type (within brain area, etc) 1014 | switch (edgeFilter) { 1015 | case 'Within': 1016 | showEdge = (e.source.region === e.target.region) && showEdge; 1017 | break; 1018 | case 'Between': 1019 | showEdge = (e.source.region !== e.target.region) && showEdge; 1020 | break; 1021 | } 1022 | 1023 | return showEdge; 1024 | } 1025 | }; 1026 | 1027 | function heatmap() { 1028 | var colorScale = d3.scale.linear(); 1029 | var xScale = d3.scale.ordinal(); 1030 | var yScale = d3.scale.ordinal(); 1031 | var rectMouseOver = function() {}; 1032 | 1033 | var rectMouseClick = function() {}; 1034 | 1035 | var height = 500; 1036 | var width = 500; 1037 | var xLabel = ''; 1038 | var yLabel = ''; 1039 | 1040 | function chart(selection) { 1041 | 1042 | selection.each(function(data) { 1043 | var heatmapG; 1044 | var heatmapRect; 1045 | var xAxis; 1046 | var yAxis; 1047 | var zeroG; 1048 | var xAxisG; 1049 | var yAxisG; 1050 | var zeroLine; 1051 | var curPlot = d3.select(this); 1052 | 1053 | xScale.rangeBands([0, width]); 1054 | yScale.rangeBands([height, 0]); 1055 | 1056 | heatmapG = curPlot.selectAll('g.heatmapX').data(data); 1057 | heatmapG.enter() 1058 | .append('g') 1059 | .attr('transform', function(d, i) { 1060 | return 'translate(' + xScale(xScale.domain()[i]) + ', 0)'; 1061 | }) 1062 | .attr('class', 'heatmapX'); 1063 | heatmapG.exit() 1064 | .remove(); 1065 | heatmapRect = heatmapG.selectAll('rect').data(function(d) { 1066 | return d; 1067 | }); 1068 | 1069 | heatmapRect.enter() 1070 | .append('rect') 1071 | .attr('x', 0) 1072 | .attr('y', function(d, i) { 1073 | return yScale(yScale.domain()[i]); 1074 | }) 1075 | .attr('height', yScale.rangeBand()) 1076 | .attr('width', xScale.rangeBand()) 1077 | .style('fill', 'white'); 1078 | heatmapRect 1079 | .style('fill', function(d) { 1080 | return colorScale(d); 1081 | }) 1082 | .style('stroke', function(d) { 1083 | return colorScale(d); 1084 | }) 1085 | .on('mouseover', rectMouseOver) 1086 | .on('click', rectMouseClick); 1087 | heatmapRect.exit() 1088 | .remove(); 1089 | 1090 | xAxis = d3.svg.axis() 1091 | .scale(xScale) 1092 | .orient('bottom') 1093 | .ticks(3) 1094 | .tickValues([d3.min(xScale.domain()), 0, d3.max(xScale.domain())]) 1095 | .tickSize(0, 0, 0); 1096 | yAxis = d3.svg.axis() 1097 | .scale(yScale) 1098 | .orient('left') 1099 | .tickValues(['10', '20', '40', '60', '90', '150', '200']) 1100 | .tickSize(0, 0, 0); 1101 | 1102 | xAxisG = curPlot.selectAll('g.axis#x').data([{}]); 1103 | xAxisG.enter() 1104 | .append('g') 1105 | .attr('class', 'axis') 1106 | .attr('id', 'x') 1107 | .attr('transform', 'translate(0,' + height + ')') 1108 | .append('text') 1109 | .attr('x', xScale(0)) 1110 | .attr('y', 0) 1111 | .attr('text-anchor', 'middle') 1112 | .attr('dy', 2 + 'em') 1113 | .text(xLabel); 1114 | xAxisG.call(xAxis); 1115 | 1116 | yAxisG = curPlot.selectAll('g.axis#y').data([{}]); 1117 | yAxisG.enter() 1118 | .append('g') 1119 | .attr('class', 'axis') 1120 | .attr('id', 'y') 1121 | .append('text') 1122 | .attr('x', -height / 2) 1123 | .attr('dy', -2 + 'em') 1124 | .attr('transform', 'rotate(-90)') 1125 | .attr('text-anchor', 'middle') 1126 | .text(yLabel); 1127 | yAxisG.call(yAxis); 1128 | 1129 | zeroG = curPlot.selectAll('g.zeroLine').data([ 1130 | [ 1131 | [0, height], 1132 | ], 1133 | ]); 1134 | zeroG.enter() 1135 | .append('g') 1136 | .attr('class', 'zeroLine'); 1137 | zeroLine = zeroG.selectAll('path').data(function(d) { 1138 | return d; 1139 | }); 1140 | 1141 | zeroLine.enter() 1142 | .append('path'); 1143 | zeroLine 1144 | .attr('d', d3.svg.line() 1145 | .x(xScale(0)) 1146 | .y(function(d) { 1147 | return d; 1148 | }) 1149 | .interpolate('linear')) 1150 | .attr('stroke', 'black') 1151 | .attr('stroke-width', 2) 1152 | .attr('fill', 'none') 1153 | .style('opacity', 0.7); 1154 | }); 1155 | } 1156 | 1157 | chart.colorScale = function(scale) { 1158 | if (!arguments.length) return colorScale; 1159 | colorScale = scale; 1160 | return chart; 1161 | }; 1162 | 1163 | chart.xScale = function(scale) { 1164 | if (!arguments.length) return xScale; 1165 | xScale = scale; 1166 | return chart; 1167 | }; 1168 | 1169 | chart.yScale = function(scale) { 1170 | if (!arguments.length) return yScale; 1171 | yScale = scale; 1172 | return chart; 1173 | }; 1174 | 1175 | chart.rectMouseOver = function(fun) { 1176 | if (!arguments.length) return rectMouseOver; 1177 | rectMouseOver = fun; 1178 | return chart; 1179 | }; 1180 | 1181 | chart.rectMouseClick = function(fun) { 1182 | if (!arguments.length) return rectMouseClick; 1183 | rectMouseClick = fun; 1184 | return chart; 1185 | }; 1186 | 1187 | chart.width = function(value) { 1188 | if (!arguments.length) return width; 1189 | width = value; 1190 | return chart; 1191 | }; 1192 | 1193 | chart.height = function(value) { 1194 | if (!arguments.length) return height; 1195 | height = value; 1196 | return chart; 1197 | }; 1198 | 1199 | chart.yLabel = function(value) { 1200 | if (!arguments.length) return yLabel; 1201 | yLabel = value; 1202 | return chart; 1203 | }; 1204 | 1205 | chart.xLabel = function(value) { 1206 | if (!arguments.length) return xLabel; 1207 | xLabel = value; 1208 | return chart; 1209 | }; 1210 | 1211 | return chart; 1212 | } 1213 | 1214 | function drawTitles() { 1215 | 1216 | spectTitle(svgCh1, curCh1); 1217 | spectTitle(svgCh2, curCh2); 1218 | edgeTitle(); 1219 | edgeStatLegendTitle.text(edgeStatName); 1220 | 1221 | function edgeTitle() { 1222 | var titleEdge = svgEdgeStat.selectAll('g.title').data([edgeStat], function(d) { 1223 | return edgeStatName + '-' + d.source + '-' + d.target; 1224 | }); 1225 | 1226 | titleEdge.exit() 1227 | .remove(); 1228 | titleEdge.enter() 1229 | .append('g') 1230 | .attr('transform', 'translate(' + timeScaleLinear(0) + ', -10)') 1231 | .attr('class', 'title'); 1232 | 1233 | var titleLabel = titleEdge.selectAll('text.infoLabel').data(function(d) { 1234 | return [d]; 1235 | }); 1236 | 1237 | titleLabel.enter() 1238 | .append('text') 1239 | .attr('class', 'infoLabel') 1240 | .attr('text-anchor', 'middle'); 1241 | titleLabel 1242 | .text(edgeStatName + ':'); 1243 | 1244 | var boundBox = titleLabel.node().getBBox(); 1245 | 1246 | var titleLine = titleEdge.selectAll('line.nodeLabel').data([{}]); 1247 | 1248 | titleLine.enter() 1249 | .append('line') 1250 | .attr('class', 'edge') 1251 | .style('stroke-width', EDGE_WIDTH) 1252 | .attr('stroke', 'black'); 1253 | titleLine 1254 | .attr('x1', boundBox.x + boundBox.width + NODE_RADIUS) 1255 | .attr('y1', -NODE_RADIUS / 2) 1256 | .attr('x2', boundBox.x + boundBox.width + NODE_RADIUS + 30) 1257 | .attr('y2', -NODE_RADIUS / 2); 1258 | 1259 | var titleCircleG = titleEdge.selectAll('g').data( 1260 | [ 1261 | channel.filter(function(d) { 1262 | return d.channelID === curCh1; 1263 | }), 1264 | 1265 | channel.filter(function(d) { 1266 | return d.channelID === curCh2; 1267 | }), 1268 | ] 1269 | ); 1270 | 1271 | titleCircleG.enter() 1272 | .append('g'); 1273 | 1274 | titleCircleG 1275 | .attr('transform', function(d, i) { 1276 | return 'translate(' + (boundBox.x + boundBox.width + NODE_RADIUS + i * 30) + ', ' + (-NODE_RADIUS / 2) + ')'; 1277 | }); 1278 | 1279 | var titleCircle = titleCircleG.selectAll('circle.node').data(function(d, i) { 1280 | return [ 1281 | [d, i], 1282 | ]; 1283 | }); 1284 | 1285 | titleCircle.enter() 1286 | .append('circle') 1287 | .attr('class', 'node') 1288 | .attr('r', NODE_RADIUS) 1289 | .attr('fill', '#ddd') 1290 | .attr('opacity', 1); 1291 | 1292 | titleCircle 1293 | .attr('fill', function(d) { 1294 | return brainRegionColor(d[0][0].region); 1295 | }); 1296 | 1297 | var titleText = titleCircleG.selectAll('text.nodeLabel').data(function(d, i) { 1298 | return [ 1299 | [d, i], 1300 | ]; 1301 | }); 1302 | 1303 | titleText.enter() 1304 | .append('text') 1305 | .attr('class', 'nodeLabel'); 1306 | 1307 | titleText 1308 | .text(function(d) { 1309 | return d[0][0].channelID; 1310 | }); 1311 | 1312 | } 1313 | 1314 | function spectTitle(svgCh, channelID) { 1315 | var titleCh = svgCh.selectAll('g.title') 1316 | .data(channel.filter(function(d) { 1317 | return d.channelID === channelID; 1318 | }), function(d) { 1319 | 1320 | return d.SubjectID + '_' + d.channelID; 1321 | }); 1322 | 1323 | titleCh.exit().remove(); 1324 | titleCh.enter() 1325 | .append('g') 1326 | .attr('transform', 'translate(' + timeScaleLinear(0) + ', -10)') 1327 | .attr('class', 'title'); 1328 | 1329 | titleLabel = titleCh.selectAll('text.infoLabel').data(function(d) { 1330 | return [d]; 1331 | }); 1332 | 1333 | titleLabel.enter() 1334 | .append('text') 1335 | .attr('class', 'infoLabel') 1336 | .attr('text-anchor', 'middle') 1337 | .text('Spectra: Ch'); 1338 | 1339 | var boundBox = titleLabel.node().getBBox(); 1340 | 1341 | var titleCircle = titleCh.selectAll('circle.node').data(function(d) { 1342 | return [d]; 1343 | }); 1344 | 1345 | titleCircle.enter() 1346 | .append('circle') 1347 | .attr('class', 'node') 1348 | .attr('r', NODE_RADIUS) 1349 | .attr('transform', 'translate(' + (-boundBox.x + NODE_RADIUS + 5) + ', ' + (-NODE_RADIUS / 2) + ')') 1350 | .attr('fill', '#ddd') 1351 | .attr('opacity', 1); 1352 | 1353 | titleCircle 1354 | .attr('fill', function(d) { 1355 | return brainRegionColor(d.region); 1356 | }); 1357 | 1358 | var titleText = titleCh.selectAll('text.nodeLabel').data(function(d) { 1359 | return [d]; 1360 | }); 1361 | 1362 | titleText.enter() 1363 | .append('text') 1364 | .attr('class', 'nodeLabel') 1365 | .attr('transform', 'translate(' + (-boundBox.x + NODE_RADIUS + 5) + ', ' + (-NODE_RADIUS / 2) + ')'); 1366 | titleText 1367 | .text(function(d) { 1368 | return d.channelID; 1369 | }); 1370 | 1371 | } 1372 | } 1373 | 1374 | function drawLegends() { 1375 | var powerG; 1376 | var powerLegendRect; 1377 | var legendScale; 1378 | var powerAxisG; 1379 | var powerAxis; 1380 | var edgeStatG; 1381 | var edgeStatLegendRect; 1382 | var edgeStatAxisG; 1383 | var edgeStatAxis; 1384 | var anatomicalG; 1385 | var anatomicalCircle; 1386 | var anatomicalText; 1387 | var formatter = d3.format('.1f'); 1388 | 1389 | var rectWidth = legendWidth / (NUM_COLORS + 1); 1390 | var rectHeight = rectWidth * 0.5; 1391 | 1392 | // Power Legend 1393 | powerG = svgSpectraLegend.selectAll('g#powerLegend').data([{}]); 1394 | powerG.enter() 1395 | .append('g') 1396 | .attr('id', 'powerLegend'); 1397 | 1398 | powerLegend = d3.legend.color() 1399 | .shape('rect') 1400 | .shapeWidth(rectWidth) 1401 | .shapeHeight(rectHeight) 1402 | .labelOffset(5) 1403 | .cells(NUM_COLORS) 1404 | .orient('horizontal') 1405 | .scale(powerScale); 1406 | powerG.call(powerLegend); 1407 | 1408 | // Edge Statistic Legend 1409 | edgeStatG = svgEdgeStatLegend.selectAll('g#edgeStatLegend').data([{}]); 1410 | edgeStatG.enter() 1411 | .append('g') 1412 | .attr('id', 'edgeStatLegend'); 1413 | 1414 | edgeLegend = d3.legend.color() 1415 | .shape('rect') 1416 | .shapeWidth(rectWidth) 1417 | .shapeHeight(rectHeight) 1418 | .labelOffset(5) 1419 | .cells(NUM_COLORS) 1420 | .orient('horizontal') 1421 | .scale(edgeStatScale); 1422 | edgeStatG.call(edgeLegend); 1423 | 1424 | // Anatomical legend 1425 | anatomicalLegendG = svgAnatomicalLegend.selectAll('g#anatomicalLegend').data([{}]); 1426 | anatomicalLegendG.enter() 1427 | .append('g') 1428 | .attr('id', 'anatomicalLegend'); 1429 | 1430 | anatomicalLegend = d3.legend.color() 1431 | .shape('circle') 1432 | .shapeRadius(NODE_RADIUS / 2) 1433 | .labelOffset(5) 1434 | .orient('vertical') 1435 | .scale(brainRegionColor); 1436 | anatomicalLegendG.call(anatomicalLegend); 1437 | } 1438 | 1439 | function drawTimeSlice() { 1440 | 1441 | var cohSlice = svgTimeSlice.selectAll('g#cohSlice') 1442 | .data([edgeStat.data.map(function(d) { 1443 | return d[curFreqInd]; 1444 | }), 1445 | ]); 1446 | 1447 | cohSlice.enter() 1448 | .append('g') 1449 | .attr('id', 'cohSlice'); 1450 | cohSlice 1451 | .call(cohTimeSlice); 1452 | 1453 | var spect1Slice = svgTimeSlice.selectAll('g#spect1Slice') 1454 | .data([spect1.data.map(function(d) { 1455 | return d[curFreqInd]; 1456 | }), 1457 | ]); 1458 | 1459 | spect1Slice.enter() 1460 | .append('g') 1461 | .attr('id', 'spect1Slice'); 1462 | spect1Slice 1463 | .call(powerTimeSlice); 1464 | 1465 | var spect2Slice = svgTimeSlice.selectAll('g#spect2Slice') 1466 | .data([spect2.data.map(function(d) { 1467 | return d[curFreqInd]; 1468 | }), 1469 | ]); 1470 | 1471 | spect2Slice.enter() 1472 | .append('g') 1473 | .attr('id', 'spect2Slice'); 1474 | spect2Slice 1475 | .call(powerTimeSlice); 1476 | 1477 | var timeTitle = svgTimeSlice.selectAll('text.title').data([fAx[curFreqInd]]); 1478 | timeTitle.enter() 1479 | .append('text') 1480 | .attr('text-anchor', 'middle') 1481 | .attr('class', 'title') 1482 | .attr('x', timeSliceWidth / 2) 1483 | .attr('y', 0) 1484 | .attr('dy', -1 + 'em'); 1485 | timeTitle 1486 | .text(function(d) { 1487 | return 'Time Slice @ Frequency ' + d + ' ' + visInfo.funits; 1488 | }); 1489 | } 1490 | 1491 | function timeseries() { 1492 | 1493 | var xScale = d3.scale.ordinal(); 1494 | var yScale = d3.scale.linear(); 1495 | var height = 600; 1496 | var width = 600; 1497 | var rectMouseOver = function() {}; 1498 | 1499 | var rectMouseClick = function() {}; 1500 | 1501 | var xLabel = ''; 1502 | var yLabel = ''; 1503 | var yAxisOrientation = 'left'; 1504 | var lineColor = 'blue'; 1505 | 1506 | function chart(selection) { 1507 | 1508 | selection.each(function(data) { 1509 | var curPlot = d3.select(this); 1510 | 1511 | xScale.rangeBands([0, width]); 1512 | 1513 | var orient = (yAxisOrientation === 'right') ? 1 : -1; 1514 | 1515 | var lineFun = d3.svg.line() 1516 | .x(function(d, i) { 1517 | return xScale(xScale.domain()[i]); 1518 | }) 1519 | .y(function(d) { 1520 | return yScale(d); 1521 | }) 1522 | .interpolate('linear'); 1523 | 1524 | var line = curPlot.selectAll('path.timeseries').data([data]); 1525 | line.enter() 1526 | .append('path') 1527 | .attr('class', 'timeseries') 1528 | .attr('fill', 'none') 1529 | .attr('stroke', lineColor); 1530 | line 1531 | .transition() 1532 | .duration(5) 1533 | .ease('linear') 1534 | .attr('d', lineFun); 1535 | 1536 | var yAxis = d3.svg.axis() 1537 | .scale(yScale) 1538 | .orient(yAxisOrientation) 1539 | .ticks(3) 1540 | .tickValues([d3.min(yScale.domain()), 0, d3.max(yScale.domain())]) 1541 | .tickSize(0, 0, 0); 1542 | var yAxisG = curPlot.selectAll('g.axis#y').data([{}]); 1543 | 1544 | yAxisG.enter() 1545 | .append('g') 1546 | .attr('class', 'axis') 1547 | .attr('id', 'y') 1548 | .attr('transform', 'translate(' + (yAxisOrientation === 'right' ? width : 0) + ',0)') 1549 | .append('text') 1550 | .attr('x', orient * height / 2) 1551 | .attr('dy', -2.5 + 'em') 1552 | .attr('transform', 'rotate(' + (orient * 90) + ')') 1553 | .attr('text-anchor', 'middle') 1554 | .text(yLabel); 1555 | yAxisG.call(yAxis); 1556 | 1557 | var xAxis = d3.svg.axis() 1558 | .scale(xScale) 1559 | .orient('bottom') 1560 | .ticks(3) 1561 | .tickValues([d3.min(xScale.domain()), 0, d3.max(xScale.domain())]) 1562 | .tickSize(0, 0, 0); 1563 | var xAxisG = curPlot.selectAll('g.axis#x').data([{}]); 1564 | xAxisG.enter() 1565 | .append('g') 1566 | .attr('class', 'axis') 1567 | .attr('transform', 'translate(0,' + height + ')') 1568 | .attr('id', 'x') 1569 | .append('text') 1570 | .attr('x', xScale(0)) 1571 | .attr('y', 0) 1572 | .attr('text-anchor', 'middle') 1573 | .attr('dy', 3 + 'em') 1574 | .text(xLabel); 1575 | xAxisG.call(xAxis); 1576 | 1577 | var zeroG = curPlot.selectAll('g.zeroLine').data([ 1578 | [ 1579 | [0, height], 1580 | ], 1581 | ]); 1582 | zeroG.enter() 1583 | .append('g') 1584 | .attr('class', 'zeroLine'); 1585 | var zeroLine = zeroG.selectAll('path').data(function(d) { 1586 | return d; 1587 | }); 1588 | 1589 | zeroLine.enter() 1590 | .append('path'); 1591 | zeroLine 1592 | .attr('d', d3.svg.line() 1593 | .x(xScale(0)) 1594 | .y(function(d) { 1595 | return d; 1596 | }) 1597 | .interpolate('linear')) 1598 | .attr('stroke', 'black') 1599 | .attr('stroke-width', 2) 1600 | .attr('fill', 'none') 1601 | .style('opacity', 0.7); 1602 | 1603 | var heatmapG = curPlot.selectAll('g.heatmapX').data(data); 1604 | heatmapG.enter() 1605 | .append('g') 1606 | .attr('transform', function(d, i) { 1607 | return 'translate(' + xScale(xScale.domain()[i]) + ', 0)'; 1608 | }) 1609 | .attr('class', 'heatmapX'); 1610 | heatmapG.exit() 1611 | .remove(); 1612 | var heatmapRect = heatmapG.selectAll('rect').data(function(d) { 1613 | return d; 1614 | }); 1615 | 1616 | heatmapRect.enter() 1617 | .append('rect') 1618 | .attr('opacity', 1e-6) 1619 | .attr('height', height) 1620 | .attr('width', xScale.rangeBand()) 1621 | .style('fill', 'white'); 1622 | heatmapRect 1623 | .on('mouseover', rectMouseOver) 1624 | .on('click', rectMouseClick); 1625 | heatmapRect.exit() 1626 | .remove(); 1627 | }); 1628 | 1629 | } 1630 | 1631 | chart.xScale = function(scale) { 1632 | if (!arguments.length) return xScale; 1633 | xScale = scale; 1634 | return chart; 1635 | }; 1636 | 1637 | chart.yScale = function(scale) { 1638 | if (!arguments.length) return yScale; 1639 | yScale = scale; 1640 | return chart; 1641 | }; 1642 | 1643 | chart.rectMouseOver = function(fun) { 1644 | if (!arguments.length) return rectMouseOver; 1645 | rectMouseOver = fun; 1646 | return chart; 1647 | }; 1648 | 1649 | chart.rectMouseClick = function(fun) { 1650 | if (!arguments.length) return rectMouseClick; 1651 | rectMouseClick = fun; 1652 | return chart; 1653 | }; 1654 | 1655 | chart.width = function(value) { 1656 | if (!arguments.length) return width; 1657 | width = value; 1658 | return chart; 1659 | }; 1660 | 1661 | chart.height = function(value) { 1662 | if (!arguments.length) return height; 1663 | height = value; 1664 | return chart; 1665 | }; 1666 | 1667 | chart.yLabel = function(value) { 1668 | if (!arguments.length) return yLabel; 1669 | yLabel = value; 1670 | return chart; 1671 | }; 1672 | 1673 | chart.xLabel = function(value) { 1674 | if (!arguments.length) return xLabel; 1675 | xLabel = value; 1676 | return chart; 1677 | }; 1678 | 1679 | chart.yAxisOrientation = function(value) { 1680 | if (!arguments.length) return yAxisOrientation; 1681 | yAxisOrientation = value; 1682 | return chart; 1683 | }; 1684 | 1685 | chart.lineColor = function(value) { 1686 | if (!arguments.length) return lineColor; 1687 | lineColor = value; 1688 | return chart; 1689 | }; 1690 | 1691 | return chart; 1692 | 1693 | } 1694 | 1695 | function subjectLoad() { 1696 | subjectDropdown = d3.select('#SubjectDropdown'); 1697 | subjectDropdown.selectAll('li') 1698 | .on('click', function() { 1699 | 1700 | subjectDropdown.selectAll('button') 1701 | .text(this.id) 1702 | .append('span') 1703 | .attr('class', 'caret'); 1704 | curSubject = this.id; 1705 | curCh1 = ''; 1706 | curCh2 = ''; 1707 | loadChannelData(); 1708 | }); 1709 | } 1710 | 1711 | function edgeStatTypeLoad() { 1712 | edgeStatTypeDropdown = d3.select('#EdgeStatTypeDropdown'); 1713 | edgeStatTypeDropdown.selectAll('li') 1714 | .on('click', function() { 1715 | edgeStatTypeDropdown.selectAll('button') 1716 | .text(d3.select(this).select('a').html()) 1717 | .append('span') 1718 | .attr('class', 'caret'); 1719 | edgeStatID = this.id; 1720 | 1721 | isFreq = edgeInfo 1722 | .filter(function(e) { 1723 | return e.edgeStatID === edgeStatID; 1724 | })[0] 1725 | .isFreq; 1726 | curFreqInd = isFreq ? curFreqInd : 0; 1727 | freqSlider.property('value', fAx[curFreqInd]); 1728 | freqSliderText.text(fAx[curFreqInd] + ' Hz'); 1729 | 1730 | loadEdges(); 1731 | }); 1732 | } 1733 | 1734 | function edgeFilterLoad() { 1735 | edgeFilterDropdown = d3.select('#EdgeFilterDropdown'); 1736 | edgeFilterDropdown.selectAll('li') 1737 | .on('click', function() { 1738 | edgeFilterDropdown.selectAll('button') 1739 | .text(this.id) 1740 | .append('span') 1741 | .attr('class', 'caret'); 1742 | edgeFilter = this.id; 1743 | drawNetwork(); 1744 | }); 1745 | } 1746 | 1747 | function networkViewLoad() { 1748 | var networkViewRadio = d3.select('#NetworkViewPanel'); 1749 | networkViewRadio.selectAll('input') 1750 | .on('click', function() { 1751 | var radioValue = this.value; 1752 | networkViewRadio.selectAll('input') 1753 | .property('checked', false); 1754 | d3.select(this).property('checked', true); 1755 | networkView = radioValue; 1756 | drawNetwork(); 1757 | }); 1758 | } 1759 | 1760 | function playButtonStart() { 1761 | var playButton = d3.select('#playButton'); 1762 | playButton.on('click', function() { 1763 | 1764 | d3.select('#playButton').text('Stop'); 1765 | stopAnimation = !stopAnimation; 1766 | var intervalID = setInterval(function() { 1767 | if (curTimeInd < timeMaxStepInd && stopAnimation === false) { 1768 | curTimeInd++; 1769 | updateTimeSlider.call({ 1770 | value: tAx[curTimeInd], 1771 | }); 1772 | } else { 1773 | d3.select('#playButton').text('Start'); 1774 | stopAnimation = true; 1775 | clearInterval(intervalID); 1776 | } 1777 | }, 100); 1778 | }); 1779 | } 1780 | 1781 | function resetButton() { 1782 | var resetButton = d3.select('#resetButton'); 1783 | resetButton.on('click', function() { 1784 | curTimeInd = 0; 1785 | stopAnimation = true; 1786 | updateTimeSlider.call({ 1787 | value: tAx[curTimeInd], 1788 | }); 1789 | }); 1790 | } 1791 | 1792 | function updateTimeSlider() { 1793 | curTimeInd = tAx.indexOf(+this.value); 1794 | timeSlider.property('value', tAx[curTimeInd]); 1795 | timeSliderText.text(tAx[curTimeInd] + ' ms'); 1796 | if (!this.noUpdate) drawNetwork(); 1797 | } 1798 | 1799 | function updateFreqSlider() { 1800 | curFreqInd = isFreq ? fAx.indexOf(+this.value) : 0; 1801 | freqSlider.property('value', fAx[curFreqInd]); 1802 | freqSliderText.text(fAx[curFreqInd] + ' Hz'); 1803 | 1804 | if (!this.noUpdate) drawNetwork(); 1805 | 1806 | if (isFreq & !this.noUpdate) drawTimeSlice(); 1807 | } 1808 | 1809 | function rectMouseOver(d, freqInd, timeInd) { 1810 | // Mouse click can freeze visualization in place 1811 | if (mouseFlag) { 1812 | curFreqInd = isFreq ? freqInd : 0; 1813 | curTimeInd = timeInd; 1814 | 1815 | updateTimeSlider.call({ 1816 | value: tAx[curTimeInd], 1817 | noUpdate: true, 1818 | }); 1819 | updateFreqSlider.call({ 1820 | value: fAx[curFreqInd], 1821 | }); 1822 | }; 1823 | } 1824 | 1825 | function rectMouseClick() { 1826 | mouseFlag = !mouseFlag; 1827 | if (!mouseFlag) { 1828 | svgNetworkMap.append('text') 1829 | .attr('x', networkWidth) 1830 | .attr('y', networkHeight) 1831 | .attr('text-anchor', 'end') 1832 | .attr('id', 'HOLD') 1833 | .text('HOLD'); 1834 | force.stop(); 1835 | } else { 1836 | svgNetworkMap.select('text#HOLD').remove(); 1837 | force.start(); 1838 | } 1839 | } 1840 | 1841 | function converterEngine(input) { // fn BLOB => Binary => Base64 ? 1842 | var uInt8Array = new Uint8Array(input); 1843 | var i = uInt8Array.length; 1844 | var biStr = []; //new Array(i); 1845 | while (i--) { 1846 | biStr[i] = String.fromCharCode(uInt8Array[i]); 1847 | } 1848 | 1849 | var base64 = window.btoa(biStr.join('')); 1850 | return base64; 1851 | }; 1852 | 1853 | function getImageBase64(url, callback) { 1854 | var xhr = new XMLHttpRequest(url); 1855 | var img64; 1856 | xhr.open('GET', url, true); // url is the url of a PNG/JPG image. 1857 | xhr.responseType = 'arraybuffer'; 1858 | xhr.callback = callback; 1859 | xhr.onload = function() { 1860 | img64 = converterEngine(this.response); // convert BLOB to base64 1861 | this.callback(null, img64); // callback : err, data 1862 | }; 1863 | 1864 | xhr.onerror = function() { 1865 | callback('B64 ERROR', null); 1866 | }; 1867 | 1868 | xhr.send(); 1869 | }; 1870 | 1871 | function copyObject(obj) { 1872 | var newObj = {}; 1873 | for (var key in obj) { 1874 | // Copy all the fields 1875 | newObj[key] = obj[key]; 1876 | } 1877 | 1878 | return newObj; 1879 | } 1880 | } 1881 | })(); 1882 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "SpectraVis", 3 | "version": "0.1.0", 4 | "description": "An interactive visualization tool for spectra, coherences, corrrelations, and associated networks", 5 | "keywords": [ 6 | "neuroscience", 7 | "spectra", 8 | "coherence", 9 | "correlation", 10 | "networks" 11 | ], 12 | "authors": [ 13 | "Eric Denovellis" 14 | ], 15 | "license": "GPL-2.0", 16 | "ignore": [ 17 | "**/.*", 18 | "node_modules", 19 | "bower_components", 20 | "test", 21 | "tests" 22 | ], 23 | "dependencies": { 24 | "bootstrap": "~3.3.6", 25 | "d3": "~3.5.10", 26 | "queue-async": "~1.0.7", 27 | "colorbrewer": "~1.0.0", 28 | "spin.js": "~2.3.2", 29 | "d3-legend": "~1.6.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var gutil = require('gulp-util'); 3 | var imagemin = require('gulp-imagemin'); 4 | var pngquant = require('imagemin-pngquant'); 5 | var streamify = require('gulp-streamify'); 6 | var autoprefixer = require('gulp-autoprefixer'); 7 | var cssmin = require('gulp-cssmin'); 8 | var concat = require('gulp-concat'); 9 | var plumber = require('gulp-plumber'); 10 | var uglify = require('gulp-uglify'); 11 | var jsonminify = require('gulp-jsonminify'); 12 | var connect = require('gulp-connect'); 13 | var watch = require('gulp-watch'); 14 | var rename = require('gulp-rename'); 15 | var zip = require('gulp-zip'); 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | Combine all JS libraries into a single file for fewer HTTP requests. 20 | |-------------------------------------------------------------------------- 21 | */ 22 | gulp.task('createVendorJS', function() { 23 | return gulp.src([ 24 | 'app/components/jquery/dist/jquery.js', 25 | 'app/components/bootstrap/js/dropdown.js', 26 | 'app/components/d3/d3.js', 27 | 'app/components/queue-async/queue.js', 28 | 'app/components/colorbrewer/colorbrewer.js', 29 | 'app/components/spin.js/spin.js', 30 | 'app/components/d3-legend/d3-legend.js', 31 | 'node_modules/d3-save-svg/build/d3-save-svg.js', 32 | ]).pipe(concat('vendor.js')) 33 | .pipe(gulp.dest('public/js')) 34 | .pipe(connect.reload()); 35 | }); 36 | 37 | gulp.task('createVendorJS-build', function() { 38 | return gulp.src([ 39 | 'app/components/jquery/dist/jquery.js', 40 | 'app/components/bootstrap/js/dropdown.js', 41 | 'app/components/d3/d3.js', 42 | 'app/components/queue-async/queue.js', 43 | 'app/components/colorbrewer/colorbrewer.js', 44 | 'app/components/spin.js/spin.js', 45 | 'app/components/d3-legend/d3-legend.js', 46 | 'node_modules/d3-save-svg/build/d3-save-svg.js', 47 | ]).pipe(concat('vendor.js')) 48 | .pipe(uglify()) 49 | .pipe(rename({ 50 | suffix: '.min', 51 | })) 52 | .pipe(gulp.dest('public/js')) 53 | .pipe(connect.reload()); 54 | }); 55 | 56 | gulp.task('createMainJS', function() { 57 | return gulp.src('app/js/*.js') 58 | .pipe(concat('main.js')) 59 | .pipe(gulp.dest('public/js')) 60 | .pipe(connect.reload()); 61 | }); 62 | 63 | gulp.task('createMainJS-build', function() { 64 | return gulp.src('app/js/*.js') 65 | .pipe(concat('main.js')) 66 | .pipe(uglify()) 67 | .pipe(rename({ 68 | suffix: '.min', 69 | })) 70 | .pipe(gulp.dest('public/js')); 71 | }); 72 | 73 | gulp.task('copyCSS', function() { 74 | return gulp.src([ 75 | 'app/components/bootstrap/dist/css/bootstrap.css', 76 | 'app/css/*.css', 77 | ]).pipe(cssmin()) 78 | .pipe(concat('main.css')) 79 | .pipe(gulp.dest('public/css')) 80 | .pipe(connect.reload()); 81 | }); 82 | 83 | gulp.task('minifyCSS', function() { 84 | return gulp.src([ 85 | 'app/components/bootstrap/dist/css/bootstrap.css', 86 | 'app/css/*.css', 87 | ]).pipe(cssmin()) 88 | .pipe(concat('main.css')) 89 | .pipe(rename({ 90 | suffix: '.min', 91 | })) 92 | .pipe(gulp.dest('public/css')) 93 | .pipe(connect.reload()); 94 | }); 95 | 96 | gulp.task('compressImages', function() { 97 | return gulp.src('app/DATA/brainImages/*') 98 | .pipe(imagemin({ 99 | progressive: true, 100 | svgoPlugins: [{removeViewBox: false}], 101 | use: [pngquant()], 102 | })) 103 | .pipe(gulp.dest('public/DATA/brainImages')); 104 | }); 105 | 106 | gulp.task('minifyJSON', function() { 107 | return gulp.src('app/DATA/*.json') 108 | .pipe(jsonminify()) 109 | .pipe(gulp.dest('public/DATA')); 110 | }); 111 | 112 | gulp.task('webserver', function() { 113 | connect.server({ 114 | port: 8000, 115 | livereload: true, 116 | root: ['public', 'app'], 117 | }); 118 | }); 119 | 120 | gulp.task('watch', function() { 121 | gulp.watch('app/css/spectra.css', ['copyCSS']); 122 | gulp.watch('app/js/main.js', ['createMainJS']); 123 | gulp.watch('app/js/vendor.js', ['createVendorJS']); 124 | }); 125 | 126 | gulp.task('copyDATA', function() { 127 | return gulp 128 | .src('app/DATA/*.json') 129 | .pipe(gulp.dest('public/DATA')); 130 | }); 131 | 132 | gulp.task('zip', function() { 133 | return gulp 134 | .src(['public/*', 'public/js/*.js', 'public/css/*.css', 'public/fonts/*', '!public/DATA/*.json', './LICENSE.md', './README.md', './SpectraVis-Demo.gif'], {base: '.'}) 135 | .pipe(zip('spectraVis.zip')) 136 | .pipe(gulp.dest('./')); 137 | }); 138 | 139 | gulp.task('default', ['copyDATA', 'createMainJS', 'createVendorJS', 'copyCSS', 'webserver', 'watch']); 140 | gulp.task('build', ['createMainJS', 'createMainJS', 'createVendorJS', 'copyCSS', 'createMainJS-build', 'createVendorJS-build', 'minifyCSS', 'compressImages', 'minifyJSON']); 141 | -------------------------------------------------------------------------------- /matlab/ES_NetworkData.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llSourcell/machine_learning_and_neuroscience/80319df7d4621964b3ce5c282cc8350b51961dd9/matlab/ES_NetworkData.m -------------------------------------------------------------------------------- /matlab/createEdges.m: -------------------------------------------------------------------------------- 1 | %% Creates edges for every node 2 | subjects = {'SIM03_B0.00T0.63','SIM03_B1.00T1.00'}; 3 | 4 | edges_ind = nchoosek(1:9, 2); 5 | 6 | for s = 1:length(subjects), 7 | 8 | for n = 1:length(edges_ind), 9 | edges(n).SubjectID = subjects{s}; 10 | edges(n).source = ['Channel ', num2str(edges_ind(n, 1))]; 11 | edges(n).target = ['Channel ', num2str(edges_ind(n, 2))]; 12 | end 13 | 14 | opt.FileName = ['edges_',subjects{s}, '_C2s_coh','.json']; 15 | savejson('', edges, opt) 16 | end -------------------------------------------------------------------------------- /matlab/createNodes.m: -------------------------------------------------------------------------------- 1 | subjects = {'SIM03_B0.00T0.63','SIM03_B1.00T1.00'}; 2 | 3 | x = [0.6427876097, 0.984807753, 0.8660254038, 0.3420201433, -0.3420201433, -0.8660254038, -0.984807753, -0.6427876097, -2.449293598e-16]; 4 | y = [0.7660444431, 0.1736481777, -0.5, -0.9396926208, -0.9396926208, -0.5, 0.1736481777, 0.7660444431, 1]; 5 | 6 | for s = 1:length(subjects), 7 | for n = 1:length(x), 8 | nodes(n).SubjectID = subjects{s}; 9 | nodes(n).name = ['Channel ', num2str(n)]; 10 | nodes(n).x = x(n); 11 | nodes(n).y = y(n); 12 | nodes(n).fixed = 'true'; 13 | end 14 | 15 | opt.FileName = ['channels_',subjects{s},'.json']; 16 | savejson('', nodes, opt) 17 | end -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "spectravis", 3 | "version": "1.1.0", 4 | "description": "An interactive web-based neuroscience app for analyzing task-related functional networks over time and frequency.", 5 | "main": "index.js", 6 | "scripts": { 7 | "postinstall": "bower cache clean && bower install && gulp", 8 | "prepublish": "gulp build && gulp zip" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/edeno/SpectraVis.git" 13 | }, 14 | "keywords": [ 15 | "neuroscience", 16 | "spectra", 17 | "coherence", 18 | "correlation", 19 | "networks", 20 | "functional connectivity" 21 | ], 22 | "author": { 23 | "name": "Eric Denovellis", 24 | "url": "http://ericdeno.com" 25 | }, 26 | "contributors": [ 27 | { 28 | "name": "Emily Stephen", 29 | "url": "http://emilystephen.com/" 30 | } 31 | ], 32 | "dependencies": { 33 | "d3-save-svg": "0.0.2" 34 | }, 35 | "devDependencies": { 36 | "bower": "^1.4.1", 37 | "gulp": "^3.9.0", 38 | "gulp-autoprefixer": "^2.3.1", 39 | "gulp-concat": "^2.6.0", 40 | "gulp-connect": "^2.2.0", 41 | "gulp-cssmin": "^0.1.7", 42 | "gulp-imagemin": "^2.3.0", 43 | "gulp-jsonminify": "^1.0.0", 44 | "gulp-plumber": "^1.0.1", 45 | "gulp-rename": "^1.2.2", 46 | "gulp-streamify": "0.0.5", 47 | "gulp-uglify": "^1.2.0", 48 | "gulp-util": "^3.0.6", 49 | "gulp-watch": "^4.3.5", 50 | "gulp-zip": "^3.0.2", 51 | "imagemin-pngquant": "^4.1.2" 52 | }, 53 | "license": "GPL-2.0", 54 | "bugs": { 55 | "url": "https://github.com/edeno/SpectraVis/issues" 56 | }, 57 | "homepage": "https://github.com/edeno/SpectraVis#readme" 58 | } 59 | -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llSourcell/machine_learning_and_neuroscience/80319df7d4621964b3ce5c282cc8350b51961dd9/public/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.svg: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llSourcell/machine_learning_and_neuroscience/80319df7d4621964b3ce5c282cc8350b51961dd9/public/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llSourcell/machine_learning_and_neuroscience/80319df7d4621964b3ce5c282cc8350b51961dd9/public/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /public/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/llSourcell/machine_learning_and_neuroscience/80319df7d4621964b3ce5c282cc8350b51961dd9/public/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | SpectraVis 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 |
18 |

SpectraVis

19 |
20 | 41 |
42 | 43 |
44 | 45 | 113 |
114 | 115 |
116 |
117 |
118 |
119 |
120 | 121 |
122 |
123 |
124 |
125 | 126 |
127 |
128 | 131 |

How to Use SpectraVis

132 |
133 |

134 | WARNING: This visualization may take a long time to load due to some large files. Please be patient on the first load.

135 |

136 | Click on any two nodes or the edge between them to load the spectra and coherences/correlations between those two nodes.

137 |

138 | Mouse over the spectra or cohereograms/correlograms to see the network at that time and/or frequency

139 |

140 | Click on the spectra or cohereograms/correlograms to freeze the network at a particular time and frequency value

141 |
142 |

143 | Edge Filter allows you to look at only edges between areas, edges within areas, or all edges

144 |

145 | Network View allows you to toggle between viewing the nodes in their anatomical location or in a layout designed to give you a sense of the structure of the network (topological)

146 |
147 |
148 |
149 | 150 | 151 | 171 | 172 | 173 | 174 | -------------------------------------------------------------------------------- /public/js/main.min.js: -------------------------------------------------------------------------------- 1 | !function(){function t(t,n,a,r){z=a,P=r,g=-1!==z.tax.indexOf(R)?z.tax.indexOf(R):0,f=-1!==z.fax.indexOf(G)?z.fax.indexOf(G):0,T=n;var l=d3.select("#SubjectDropdown"),i=l.selectAll(".dropdown-menu").selectAll("li").data(T);i.enter().append("li").attr("id",function(t){return t.subjectID}).attr("role","presentation").append("a").attr("role","menuitem").attr("tabindex",-1).text(function(t){return t.subjectID}),s=s||T[0].subjectID,l.selectAll("button").text(s).append("span").attr("class","caret");var c=d3.select("#EdgeStatTypeDropdown"),o=c.select("ul").selectAll("li").data(P);o.enter().append("li").attr("id",function(t){return t.edgeStatID}).append("a").attr("role","menuitem").attr("tabindex",-1).text(function(t){return t.edgeStatName}),o.exit().remove(),d=d||P[0].edgeStatID,q=P.filter(function(t){return t.edgeStatID===d})[0].edgeStatName,c.selectAll("button").text(q).append("span").attr("class","caret"),d3.selectAll("#legendKey").selectAll("#anatomicalLegend").selectAll("svg").attr("height",14+15.14*z.brainRegions.length),e()}function e(){var t="channels_"+s+".json";o=T.filter(function(t){return t.subjectID===s})[0];var e=o.brainXpixels/o.brainYpixels;l=document.getElementById("NetworkPanel").offsetWidth-N.left-N.right,i=document.getElementById("NetworkPanel").offsetWidth*(1/e)-N.top-N.bottom,c=d3.select("#NetworkPanel").selectAll("svg").data([o],function(t){return t.subjectID}),c.exit().remove(),c=c.enter().append("svg").attr("width",l).attr("height",i).append("g"),L.spin(document.getElementById("NetworkPanel")),c.style("display","none"),d3.json("DATA/"+t,function(t,e){F=e,u=u||F[0].channelID,p=p||F[1].channelID,n()})}function n(){var t="edges_"+s+"_"+d+".json";d3.json("DATA/"+t,function(t,e){H=e,a()})}function a(){_.spin(document.getElementById("SpectraCh1Panel")),B.spin(document.getElementById("SpectraCh2Panel")),E.spin(document.getElementById("EdgeStatPanel")),x.style("display","none"),v.style("display","none"),y.style("display","none"),k.style("display","none");var t="spectrogram_"+s+"_"+u+".json",e="spectrogram_"+s+"_"+p+".json";queue().defer(d3.json,"DATA/"+t).defer(d3.json,"DATA/"+e).await(r)}function r(t,r,T){function N(){St=d3.select("#timeSlider"),kt=d3.select("#timeSlider-value"),wt=d3.select("#freqSlider"),Dt=d3.select("#freqSlider-value"),Et=d3.round(xt[1]-xt[0],4),jt=xt.length-1,St.property("min",d3.min(xt)),St.property("max",d3.max(xt)),St.property("step",Et),St.property("value",xt[g]),St.on("input",it),kt.text(xt[g]+" ms"),wt.property("min",d3.min(yt)),wt.property("max",d3.max(yt)),wt.property("step",yt[1]-yt[0]),wt.property("value",yt[f]),wt.on("input",ct),Dt.text(yt[f]+" Hz")}function R(){function t(t,n){return Math.abs(t)>=Math.abs(n)?n=Math.abs(t):t=-1*n,e(t,n,11)}function e(t,e,n){if("undefined"==typeof n&&(n=Math.max(Math.round(e-t)+1,1)),2>n)return 1===n?[t]:[];var a,r=Array(n);for(n--,a=n;a>=0;a--)r[a]=(a*e+(n-a)*t)/n;return r}var n,a,c,s,d,u,p=colorbrewer.PiYG[V],f=colorbrewer.RdBu[V];Bt=d3.scale.ordinal().domain(z.brainRegions).range(colorbrewer.Pastel1[7]),n=d3.min([d3.min(r.data,function(t){return d3.min(t,function(t){return t})}),d3.min(T.data,function(t){return d3.min(t,function(t){return t})})]),a=d3.max([d3.max(r.data,function(t){return d3.max(t,function(t){return t})}),d3.max(T.data,function(t){return d3.max(t,function(t){return t})})]),c=t(n,a),Ct=o.brainXLim,Ot=o.brainYLim,s=d3.min(H,function(t){return d3.min(t.data,function(t){return d3.min(t,function(t){return t})})}),d=d3.max(H,function(t){return d3.max(t.data,function(t){return d3.max(t,function(t){return t})})}),u=t(s,d),ht=d3.scale.linear().domain(c).range(p),zt?Lt=d3.scale.linear().domain(u).range(f):(f=[0,(V-1)/2,V-1].map(function(t){return f[t]}),Lt=d3.scale.ordinal().domain([-1,0,1]).range(f)),ft=d3.scale.ordinal().domain(xt).rangeBands([0,D]),gt=d3.scale.linear().domain(d3.extent(xt)).range([0,D]),mt=d3.scale.ordinal().domain(yt).rangeBands([j,0]),Pt=d3.scale.linear().domain(c).range(e(M,0,V)),timeSliceEdgeStatScale=d3.scale.linear().domain(u).range(e(M,0,V)),vt=d3.scale.linear().domain(Ct).range([0,l]),At=d3.scale.linear().domain(Ot).range([i,0]),Nt=d3.scale.linear().domain(u).range(e(0,j,V))}function G(){function t(t){return Math.max(W,Math.min(l-W,t.x))}function e(t){return Math.max(W,Math.min(i-W,t.y))}function n(t){var e=d3.select(this);S=e.style("stroke"),e.style("stroke-width",2*X).style("stroke",function(){return Lt(t.data<0?d3.min(Lt.domain()):d3.max(Lt.domain()))});d3.selectAll("circle.node").filter(function(e){return e.channelID===t.source.channelID||e.channelID===t.target.channelID}).attr("r",1.2*W)}function r(t){var e=d3.select(this);"undefined"!=typeof S&&(e.style("stroke-width",X).style("stroke",S),d3.selectAll("circle.node").filter(function(e){return e.channelID===t.source.channelID||e.channelID===t.target.channelID}).attr("r",W))}function d(t){var e=/\d+/;u=e.exec(t.source.channelID)[0],p=e.exec(t.target.channelID)[0],U=!0,c.select("text#HOLD").remove(),a(),r.call(this,t)}function x(t){var e=d3.select(this),n=B.indexOf(+t.channelID);if(n>-1?(e.selectAll("circle").attr("r",W),B.splice(n,1)):(e.selectAll("circle").attr("r",1.2*W),B.push(+t.channelID)),2===B.length){var r=/\d+/;u=r.exec(B[0])[0],p=r.exec(B[1])[0],U=!0,c.select("text#HOLD").remove(),d3.selectAll("circle.node").filter(function(t){return t.channelID===B[0].toString()||t.channelID===B[1].toString()}).attr("fill","#ddd").attr("r",W),B=[],a()}}function y(t){var e=!0;switch(zt||(e=0!==t.data),m){case"Within":e=t.source.region===t.target.region&&e;break;case"Between":e=t.source.region!==t.target.region&&e}return e}var v,A,b,S,w,k,D,I,L,_,B=[];Ft="Anatomical"===h?F.map(function(t){var e=pt(t);return e.x=vt(t.x),e.y=At(t.y),e.fixed=!0,e}):F.map(function(t,e){var n=pt(t);return"undefined"==typeof Ft?(n.x=vt(t.x),n.y=At(t.y)):(n.x=Ft[e].x,n.y=Ft[e].y,n.px=Ft[e].px,n.py=Ft[e].py),n.fixed=!1,n}),k=H.map(function(t){var e=pt(t);return e.source=Ft.filter(function(e){return e.channelID===t.source})[0],e.target=Ft.filter(function(e){return e.channelID===t.target})[0],e.data=e.data[g][f],e}),k=k.filter(y),bt=d3.layout.force().nodes(Ft).links(k).charge(-375).linkDistance(i/3).size([l,i]).start(),I=c.selectAll("g#BRAIN_IMAGE").data([{}]),I.enter().append("g").attr("id","BRAIN_IMAGE"),A=c.selectAll("g#EDGES").data([{}]),A.enter().append("g").attr("id","EDGES"),v=c.selectAll("g#NODES").data([{}]),v.enter().append("g").attr("id","NODES"),D=A.selectAll(".edge").data(k,function(t){return s+"_"+t.source.channelID+"_"+t.target.channelID}),D.enter().append("line").attr("class","edge").style("stroke-width",X).attr("x1",function(e){return t(e.source)}).attr("y1",function(t){return e(t.source)}).attr("x2",function(e){return t(e.target)}).attr("y2",function(t){return e(t.target)}),D.exit().remove(),D.style("stroke",function(t){return Lt(t.data)}).on("mouseover",n).on("mouseout",r).on("click",d),b=v.selectAll("g.gnode").data(Ft,function(t){return s+"_"+t.channelID}),b.enter().append("g").attr("class","gnode").attr("transform",function(n){return"translate("+[t(n),e(n)]+")"}).on("click",x),b.exit().remove(),L=b.selectAll("circle.node").data(function(t){return[t]}),L.enter().append("circle").attr("class","node").attr("r",W).attr("fill","#ddd").attr("opacity",1),L.attr("fill",function(t){return Bt(t.region)}).style("stroke","white"),L.filter(function(t){return t.channelID==u||t.channelID==p}).style("stroke","black"),_=b.selectAll("text.nodeLabel").data(function(t){return[t]}),_.enter().append("text").attr("class","nodeLabel").text(function(t){return t.channelID}),bt.on("tick",function(){b.attr("transform",function(n){return"translate("+[t(n),e(n)]+")"}),D.attr("x1",function(e){return t(e.source)}).attr("y1",function(t){return e(t.source)}).attr("x2",function(e){return t(e.target)}).attr("y2",function(t){return e(t.target)}),"Topological"!==h&&bt.stop()}),w=I.selectAll("image").data([o],function(t){return t.brainFilename}),"Anatomical"===h&&(w.enter().append("image").attr("width",l).attr("height",i),ut("DATA/brainImages/"+o.brainFilename,function(t,e){w.attr("xlink:href","data:image/png;base64,"+e)})),w.exit().remove(),"Topological"===h&&w.remove()}function Y(){function t(t){t.each(function(t){var d,u,p,f,g,m,h,x,y=d3.select(this);n.rangeBands([0,c]),a.rangeBands([i,0]),d=y.selectAll("g.heatmapX").data(t),d.enter().append("g").attr("transform",function(t,e){return"translate("+n(n.domain()[e])+", 0)"}).attr("class","heatmapX"),d.exit().remove(),u=d.selectAll("rect").data(function(t){return t}),u.enter().append("rect").attr("x",0).attr("y",function(t,e){return a(a.domain()[e])}).attr("height",a.rangeBand()).attr("width",n.rangeBand()).style("fill","white"),u.style("fill",function(t){return e(t)}).style("stroke",function(t){return e(t)}).on("mouseover",r).on("click",l),u.exit().remove(),p=d3.svg.axis().scale(n).orient("bottom").ticks(3).tickValues([d3.min(n.domain()),0,d3.max(n.domain())]).tickSize(0,0,0),f=d3.svg.axis().scale(a).orient("left").tickValues(["10","20","40","60","90","150","200"]).tickSize(0,0,0),m=y.selectAll("g.axis#x").data([{}]),m.enter().append("g").attr("class","axis").attr("id","x").attr("transform","translate(0,"+i+")").append("text").attr("x",n(0)).attr("y",0).attr("text-anchor","middle").attr("dy","2em").text(o),m.call(p),h=y.selectAll("g.axis#y").data([{}]),h.enter().append("g").attr("class","axis").attr("id","y").append("text").attr("x",-i/2).attr("dy","-2em").attr("transform","rotate(-90)").attr("text-anchor","middle").text(s),h.call(f),g=y.selectAll("g.zeroLine").data([[[0,i]]]),g.enter().append("g").attr("class","zeroLine"),x=g.selectAll("path").data(function(t){return t}),x.enter().append("path"),x.attr("d",d3.svg.line().x(n(0)).y(function(t){return t}).interpolate("linear")).attr("stroke","black").attr("stroke-width",2).attr("fill","none").style("opacity",.7)})}var e=d3.scale.linear(),n=d3.scale.ordinal(),a=d3.scale.ordinal(),r=function(){},l=function(){},i=500,c=500,o="",s="";return t.colorScale=function(n){return arguments.length?(e=n,t):e},t.xScale=function(e){return arguments.length?(n=e,t):n},t.yScale=function(e){return arguments.length?(a=e,t):a},t.rectMouseOver=function(e){return arguments.length?(r=e,t):r},t.rectMouseClick=function(e){return arguments.length?(l=e,t):l},t.width=function(e){return arguments.length?(c=e,t):c},t.height=function(e){return arguments.length?(i=e,t):i},t.yLabel=function(e){return arguments.length?(s=e,t):s},t.xLabel=function(e){return arguments.length?(o=e,t):o},t}function J(){function t(){var t=y.selectAll("g.title").data([Mt],function(t){return q+"-"+t.source+"-"+t.target});t.exit().remove(),t.enter().append("g").attr("transform","translate("+gt(0)+", -10)").attr("class","title");var e=t.selectAll("text.infoLabel").data(function(t){return[t]});e.enter().append("text").attr("class","infoLabel").attr("text-anchor","middle"),e.text(q+":");var n=e.node().getBBox(),a=t.selectAll("line.nodeLabel").data([{}]);a.enter().append("line").attr("class","edge").style("stroke-width",X).attr("stroke","black"),a.attr("x1",n.x+n.width+W).attr("y1",-W/2).attr("x2",n.x+n.width+W+30).attr("y2",-W/2);var r=t.selectAll("g").data([F.filter(function(t){return t.channelID===u}),F.filter(function(t){return t.channelID===p})]);r.enter().append("g"),r.attr("transform",function(t,e){return"translate("+(n.x+n.width+W+30*e)+", "+-W/2+")"});var l=r.selectAll("circle.node").data(function(t,e){return[[t,e]]});l.enter().append("circle").attr("class","node").attr("r",W).attr("fill","#ddd").attr("opacity",1),l.attr("fill",function(t){return Bt(t[0][0].region)});var i=r.selectAll("text.nodeLabel").data(function(t,e){return[[t,e]]});i.enter().append("text").attr("class","nodeLabel"),i.text(function(t){return t[0][0].channelID})}function e(t,e){var n=t.selectAll("g.title").data(F.filter(function(t){return t.channelID===e}),function(t){return t.SubjectID+"_"+t.channelID});n.exit().remove(),n.enter().append("g").attr("transform","translate("+gt(0)+", -10)").attr("class","title"),titleLabel=n.selectAll("text.infoLabel").data(function(t){return[t]}),titleLabel.enter().append("text").attr("class","infoLabel").attr("text-anchor","middle").text("Spectra: Ch");var a=titleLabel.node().getBBox(),r=n.selectAll("circle.node").data(function(t){return[t]});r.enter().append("circle").attr("class","node").attr("r",W).attr("transform","translate("+(-a.x+W+5)+", "+-W/2+")").attr("fill","#ddd").attr("opacity",1),r.attr("fill",function(t){return Bt(t.region)});var l=n.selectAll("text.nodeLabel").data(function(t){return[t]});l.enter().append("text").attr("class","nodeLabel").attr("transform","translate("+(-a.x+W+5)+", "+-W/2+")"),l.text(function(t){return t.channelID})}e(x,u),e(v,p),t(),S.text(q)}function Q(){var t,e,n=(d3.format(".1f"),C/(V+1)),a=.5*n;t=A.selectAll("g#powerLegend").data([{}]),t.enter().append("g").attr("id","powerLegend"),powerLegend=d3.legend.color().shape("rect").shapeWidth(n).shapeHeight(a).labelOffset(5).cells(V).orient("horizontal").scale(ht),t.call(powerLegend),e=b.selectAll("g#edgeStatLegend").data([{}]),e.enter().append("g").attr("id","edgeStatLegend"),edgeLegend=d3.legend.color().shape("rect").shapeWidth(n).shapeHeight(a).labelOffset(5).cells(V).orient("horizontal").scale(Lt),e.call(edgeLegend),anatomicalLegendG=w.selectAll("g#anatomicalLegend").data([{}]),anatomicalLegendG.enter().append("g").attr("id","anatomicalLegend"),anatomicalLegend=d3.legend.color().shape("circle").shapeRadius(W/2).labelOffset(5).orient("vertical").scale(Bt),anatomicalLegendG.call(anatomicalLegend)}function Z(){var t=k.selectAll("g#cohSlice").data([Mt.data.map(function(t){return t[f]})]);t.enter().append("g").attr("id","cohSlice"),t.call(Vt);var e=k.selectAll("g#spect1Slice").data([r.data.map(function(t){return t[f]})]);e.enter().append("g").attr("id","spect1Slice"),e.call(Wt);var n=k.selectAll("g#spect2Slice").data([T.data.map(function(t){return t[f]})]);n.enter().append("g").attr("id","spect2Slice"),n.call(Wt);var a=k.selectAll("text.title").data([yt[f]]);a.enter().append("text").attr("text-anchor","middle").attr("class","title").attr("x",O/2).attr("y",0).attr("dy","-1em"),a.text(function(t){return"Time Slice @ Frequency "+t+" "+z.funits})}function $(){function t(t){t.each(function(t){var u=d3.select(this);e.rangeBands([0,r]);var p="right"===s?1:-1,f=d3.svg.line().x(function(t,n){return e(e.domain()[n])}).y(function(t){return n(t)}).interpolate("linear"),g=u.selectAll("path.timeseries").data([t]);g.enter().append("path").attr("class","timeseries").attr("fill","none").attr("stroke",d),g.transition().duration(5).ease("linear").attr("d",f);var m=d3.svg.axis().scale(n).orient(s).ticks(3).tickValues([d3.min(n.domain()),0,d3.max(n.domain())]).tickSize(0,0,0),h=u.selectAll("g.axis#y").data([{}]);h.enter().append("g").attr("class","axis").attr("id","y").attr("transform","translate("+("right"===s?r:0)+",0)").append("text").attr("x",p*a/2).attr("dy","-2.5em").attr("transform","rotate("+90*p+")").attr("text-anchor","middle").text(o),h.call(m);var x=d3.svg.axis().scale(e).orient("bottom").ticks(3).tickValues([d3.min(e.domain()),0,d3.max(e.domain())]).tickSize(0,0,0),y=u.selectAll("g.axis#x").data([{}]);y.enter().append("g").attr("class","axis").attr("transform","translate(0,"+a+")").attr("id","x").append("text").attr("x",e(0)).attr("y",0).attr("text-anchor","middle").attr("dy","3em").text(c),y.call(x);var v=u.selectAll("g.zeroLine").data([[[0,a]]]);v.enter().append("g").attr("class","zeroLine");var A=v.selectAll("path").data(function(t){return t});A.enter().append("path"),A.attr("d",d3.svg.line().x(e(0)).y(function(t){return t}).interpolate("linear")).attr("stroke","black").attr("stroke-width",2).attr("fill","none").style("opacity",.7);var b=u.selectAll("g.heatmapX").data(t);b.enter().append("g").attr("transform",function(t,n){return"translate("+e(e.domain()[n])+", 0)"}).attr("class","heatmapX"),b.exit().remove();var S=b.selectAll("rect").data(function(t){return t});S.enter().append("rect").attr("opacity",1e-6).attr("height",a).attr("width",e.rangeBand()).style("fill","white"),S.on("mouseover",l).on("click",i),S.exit().remove()})}var e=d3.scale.ordinal(),n=d3.scale.linear(),a=600,r=600,l=function(){},i=function(){},c="",o="",s="left",d="blue";return t.xScale=function(n){return arguments.length?(e=n,t):e},t.yScale=function(e){return arguments.length?(n=e,t):n},t.rectMouseOver=function(e){return arguments.length?(l=e,t):l},t.rectMouseClick=function(e){return arguments.length?(i=e,t):i},t.width=function(e){return arguments.length?(r=e,t):r},t.height=function(e){return arguments.length?(a=e,t):a},t.yLabel=function(e){return arguments.length?(o=e,t):o},t.xLabel=function(e){return arguments.length?(c=e,t):c},t.yAxisOrientation=function(e){return arguments.length?(s=e,t):s},t.lineColor=function(e){return arguments.length?(d=e,t):d},t}function tt(){It=d3.select("#SubjectDropdown"),It.selectAll("li").on("click",function(){It.selectAll("button").text(this.id).append("span").attr("class","caret"),s=this.id,u="",p="",e()})}function et(){_t=d3.select("#EdgeStatTypeDropdown"),_t.selectAll("li").on("click",function(){_t.selectAll("button").text(d3.select(this).select("a").html()).append("span").attr("class","caret"),d=this.id,Tt=P.filter(function(t){return t.edgeStatID===d})[0].isFreq,f=Tt?f:0,wt.property("value",yt[f]),Dt.text(yt[f]+" Hz"),n()})}function nt(){I=d3.select("#EdgeFilterDropdown"),I.selectAll("li").on("click",function(){I.selectAll("button").text(this.id).append("span").attr("class","caret"),m=this.id,G()})}function at(){var t=d3.select("#NetworkViewPanel");t.selectAll("input").on("click",function(){var e=this.value;t.selectAll("input").property("checked",!1),d3.select(this).property("checked",!0),h=e,G()})}function rt(){var t=d3.select("#playButton");t.on("click",function(){d3.select("#playButton").text("Stop"),K=!K;var t=setInterval(function(){jt>g&&K===!1?(g++,it.call({value:xt[g]})):(d3.select("#playButton").text("Start"),K=!0,clearInterval(t))},100)})}function lt(){var t=d3.select("#resetButton");t.on("click",function(){g=0,K=!0,it.call({value:xt[g]})})}function it(){g=xt.indexOf(+this.value),St.property("value",xt[g]),kt.text(xt[g]+" ms"),this.noUpdate||G()}function ct(){f=Tt?yt.indexOf(+this.value):0,wt.property("value",yt[f]),Dt.text(yt[f]+" Hz"),this.noUpdate||G(),Tt&!this.noUpdate&&Z()}function ot(t,e,n){U&&(f=Tt?e:0,g=n,it.call({value:xt[g],noUpdate:!0}),ct.call({value:yt[f]}))}function st(){U=!U,U?(c.select("text#HOLD").remove(),bt.start()):(c.append("text").attr("x",l).attr("y",i).attr("text-anchor","end").attr("id","HOLD").text("HOLD"),bt.stop())}function dt(t){for(var e=new Uint8Array(t),n=e.length,a=[];n--;)a[n]=String.fromCharCode(e[n]);var r=window.btoa(a.join(""));return r}function ut(t,e){var n,a=new XMLHttpRequest(t);a.open("GET",t,!0),a.responseType="arraybuffer",a.callback=e,a.onload=function(){n=dt(this.response),this.callback(null,n)},a.onerror=function(){e("B64 ERROR",null)},a.send()}function pt(t){var e={};for(var n in t)e[n]=t[n];return e}var ft,gt,mt,ht,xt,yt,ht,vt,At,bt,St,wt,kt,Dt,It,Lt,_t,Bt,Et,jt,Ct,Ot,Mt,Pt,ht,Lt,Tt,zt,Nt,qt,Ft;xt=z.tax,yt=z.fax,Mt=H.filter(function(t){return t.source===u&&t.target===p||t.source===p&&t.target===u})[0],qt=P.filter(function(t){return t.edgeStatID===d})[0],Tt=qt.isFreq,zt=qt.isWeightedNetwork,R(),N();var Ht=Y().height(j).width(D).yScale(mt).xScale(ft).xLabel("Time ("+z.tunits+")").yLabel("Frequency ("+z.funits+")").colorScale(ht).rectMouseOver(ot).rectMouseClick(st),Rt=Y().height(j).width(D).yScale(mt).xScale(ft).xLabel("Time ("+z.tunits+")").yLabel("Frequency ("+z.funits+")").colorScale(Lt).rectMouseOver(ot).rectMouseClick(st),Gt=$().height(j).width(D).yScale(Nt).xScale(ft).xLabel("Time ("+z.tunits+")").yLabel(q).rectMouseOver(ot).rectMouseClick(st),Vt=$().height(M).width(O).yScale(timeSliceEdgeStatScale).xScale(ft).yAxisOrientation("left").xLabel("Time ("+z.tunits+")").yLabel(q),Wt=$().height(M).width(O).yScale(Pt).xScale(ft).yAxisOrientation("right").xLabel("Time ("+z.tunits+")").yLabel("Power Difference").lineColor("green");G(),c.style("display",""),L.stop(),x.datum(r.data).call(Ht),x.style("display",""),_.stop(),v.datum(T.data).call(Ht),B.stop(),v.style("display",""),Tt?(y.html(""),y.datum(Mt.data).call(Rt),Z()):(y.html(""),k.html(""),y.datum(Mt.data).call(Gt)),y.style("display",""),E.stop(),k.style("display",""),J(),Q(),tt(),et(),nt(),at(),rt(),lt()}spectraVis={},params={};var l,i,c,o,s,d,u,p,f,g,m,h,x,y,v,A,b,S,w,k,D,I,L,_,B,E,D,j,C,O,M,P,T,z,N,q,F,H,R,G,V=11,W=10,X=2,K=!0,U=!0;colorbrewer.PiYG[V].reverse(),colorbrewer.RdBu[V].reverse(),spectraVis.init=function(e){N={top:30,right:30,bottom:30,left:30},D=document.getElementById("SpectraCh1Panel").offsetWidth-N.left-N.right,j=.8*document.getElementById("SpectraCh1Panel").offsetWidth-N.top-N.bottom,C=document.getElementById("legendKey").offsetWidth-5-5-30;100-N.top-N.bottom;O=D,M=180-N.top-N.bottom;var n={zIndex:100};G=+e.freq,R=+e.time,m=e.edgeFilter||"All",h=e.networkView||"Anatomical",u=e.curCh1,p=e.curCh2,s=e.curSubject,d=e.edgeStatID,x=d3.select("#SpectraCh1Panel").append("svg").attr("width",D+N.left+N.right).attr("height",j+N.top+N.bottom).append("g").attr("transform","translate("+N.left+","+N.top+")"),y=d3.select("#EdgeStatPanel").append("svg").attr("width",D+N.left+N.right).attr("height",j+N.top+N.bottom).append("g").attr("transform","translate("+N.left+","+N.top+")"),v=d3.select("#SpectraCh2Panel").append("svg").attr("width",D+N.left+N.right).attr("height",j+N.top+N.bottom).append("g").attr("transform","translate("+N.left+","+N.top+")"),A=d3.selectAll("#legendKey").select("#spectraLegend").append("svg").attr("width",C+5+5).attr("height",50).append("g").attr("transform","translate(5,25)"),A.append("text").attr("transform","translate(-5, -5)").attr("font-size",12).attr("font-weight",700).text("Difference in Power"),b=d3.selectAll("#legendKey").select("#edgeStatLegend").append("svg").attr("width",C+5+5).attr("height",50).append("g").attr("transform","translate(5,25)"),S=b.append("text").attr("transform","translate(-5, -5)").attr("font-size",12).attr("font-weight",700).text("Edge Statistic"),w=d3.selectAll("#legendKey").select("#anatomicalLegend").append("svg").attr("width",C+5+5).append("g").attr("transform","translate(5,25)"),w.append("text").attr("transform","translate(-5, -10)").attr("font-size",12).attr("font-weight",700).text("Brain Areas"),k=d3.select("#timeSlice").append("svg").attr("width",O+40+40).attr("height",M+40+40).append("g").attr("transform","translate(40,40)");var a=d3.select("#overlay"),r=d3.select("button#help-button");a.selectAll(".close").on("click",function(){a.style("display","none")}),r.on("click",function(){a.style("display","block")});var l=d3.select("#permalink"),i=d3.select("button#link");i.on("click",function(){l.style("display","block");var t=window.location.origin+window.location.pathname+"?curSubject="+s+"&edgeStatID="+d+"&edgeFilter="+m+"&networkView="+h+"&time="+z.tax[g]+"&freq="+z.fax[f]+"&curCh1="+u+"&curCh2="+p;l.selectAll("textarea").html(t),l.selectAll(".bookmark").attr("href",t)}),l.selectAll(".close").on("click",function(){l.style("display","none")});var c=d3.select("button#export");c.on("click",function(){var t=d3.select("#NetworkPanel").select("svg").node(),e="Network_"+s+"_"+d+"_"+h+"_"+z.tax[g]+z.tunits+"_"+z.fax[f]+z.funits;d3_save_svg.save(t,{filename:e});var n="Spectra_"+s+"_Ch"+u,a=d3.select("#SpectraCh1Panel").select("svg").node();d3_save_svg.save(a,{filename:n});var r="Spectra_"+s+"_Ch"+p,l=d3.select("#SpectraCh2Panel").select("svg").node();d3_save_svg.save(l,{filename:r});var i=d+"_"+s+"_Ch"+u+"_Ch"+p,c=d3.select("#EdgeStatPanel").select("svg").node();d3_save_svg.save(c,{filename:i}),d3.selectAll("circle.node")[0].forEach(function(t){t.setAttribute("style","")})}),I=d3.select("#EdgeFilterDropdown"),I.selectAll("button").text(m).append("span").attr("class","caret"),L=new Spinner(n),_=new Spinner(n),B=new Spinner(n),E=new Spinner(n),queue().defer(d3.json,"DATA/subjects.json").defer(d3.json,"DATA/visInfo.json").defer(d3.json,"DATA/edgeTypes.json").await(t)}}(); --------------------------------------------------------------------------------