-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
178 lines (176 loc) · 11.9 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>gwcat test page</title>
<!--<script type="text/javascript" src="js/lib/d3.v4.min.js"></script>-->
<script type="text/javascript" src="js/lib/stuquery.js"></script>
<script type="text/javascript" src="js/gwcat.js"></script>
<script type="text/javascript" src="js/lib/d3.v4.min.js"></script>
<style>
ul.unittests {
margin: 0px;
padding: 0px;
list-style: none;
}
.unittest {
padding: 1em;
display: block;
margin-bottom: 0.5em;
position: relative;
}
.unittest:last-child { margin-bottom: 0px; }
.unittest p { margin-top: 0px; }
.unittest code, .unittest pre { line-height: 1.5em; color: rgba(0,0,0,0.7); }
.unittest-fail {
background: rgba(214, 39, 40,0.3);
border: 1px solid rgb(214, 39, 40);
}
.unittest-success {
background: rgba(118, 208, 119, 0.3);
border: 1px solid rgb(118, 208, 119);
}
.unittest .input { margin-bottom: 0.5em; }
.unittest .expect, .unittest .output {
font-style: italic;
}
</style>
</head>
<body>
<h1>GWCat demo</h1>
<p>Summary: <span id="message">It doesn't work :(</span></p>
<h2>Initialisation</h2>
In the <head> of the page, include the <code>gwcat</code> library.
<pre><code><!--
<script type="text/javascript" src="js/lib/d3.v4.min.js"></script>-->
<script type="text/javascript" src="js/gwcat.js"></script>
</code></pre>
<p>To initialise the database of events</p>
<pre><code>
gwcat = new GWCat(<i>callback</i>, {<i>parameters</i>});
</code></pre>
<ul>
<li><b><i>callback</i></b> [function]: a javascript function to be run once data is loaded.</li>
<li><b><i>parameters</i></b> [Object, optional]: a dictionary containing input parameters:
<ul>
<li><i>debug</i>: [boolean] set to print useful debugging scripts to the console (default=true)</li>
<li><i>fileIn</i>: [string] json file to load data from (default=data/events.json)</li>
</ul>
</li>
</ul>
<p>The resulting object contains the following objects:
<ul>
<li><b><i>data</i></b>: An array containing all the events, each one of which is a javascript object.</li>
<li><b><i>datadict</i></b>: An object containing the metadata of all the parameter names, default precisions etc.</li>
<li><b><i>dataOrder</i></b>: An array of the event names, showing the order of <i>data</i>.</li>
</ul>
</p>
<h2>Data format</h2>
<p>The data array contains an object for each event. Each event has a set of parameters (M1, M2, Mchirp, UTC, etc.), within which is an object containing the relevant values.</p>
<pre><code>
gwcat.data = [
{
"Event1 Parameter1": {
"Event1 Parameter1 Value1": string/number/array
},
"Event1 Parameter2": {
"Event1 Parameter2 Value1": string/array/value
"Event1 Parameter2 Value2": string/array/value
},...
},
{
"Event2 Parameter1":{
"Event2 Parameter1 Value1": string/number/array
},...
},...
]
</code></pre>
<p>The parameters are those recorded for each event. Note that not all are present for each event.<p>
<ul>
<li><b><i>name</i></b>: Event name (e.g. GW150914)</li>
<li><b><i>UTC</i></b>: UTC time of detection (YYYY-MM-DDThh:mm:ss)</li>
<li><b><i>GPS</i></b>: GPS time of detection</li>
<li><b><i>M1</i></b>: Primary mass (Msun)</li>
<li><b><i>M2</i></b>: Secondary mass (Msun)</li>
<li><b><i>Mchirp</i></b>: Chirp mass (Msun)</li>
<li><b><i>Mtotal</i></b>: Total mass (Msun)</li>
<li><b><i>Mfinal</i></b>: Final mass (Msun)</li>
<li><b><i>Mratio</i></b>: Mass ratio</li>
<li><b><i>chi</i></b>: Effective inspiral spin</li>
<li><b><i>af</i></b>: Final spin</li>
<li><b><i>DL</i></b>: Luminosity distance (MPc)</li>
<li><b><i>z</i></b>: Redshift</li>
<li><b><i>lpeak</i></b>: Peak luminosity (10<sup>56</sup> erg s<sup>-1</sup>)</li>
<li><b><i>Erad</i></b>: Radiated energy (Msun c<sup>2</sup>)</li>
<li><b><i>FAR</i></b>: False alarm rate (yr<sup>-1</sup>)</li>
<li><b><i>deltaOmega</i></b>: Sky localization area (deg<sup>2</sup>)</li>
<li><b><i>rho</i></b>: Signal-to-noise ratio</li>
</ul>
</p>
<p>The values can be any of:
<ul>
<li><b><i>best</i></b>: exact of best-fit value of parameter. Can be string (e.g. name, UTC), or number (e.g. masses, spins, GPS).</li>
<li><b><i>lower</i></b>: a (numerical) lower limit on the parameter.</li>
<li><b><i>upper</i></b>: a (numerical) upper limit on the parameter.</li>
<li><b><i>lim</i></b>: a two-element array (of numberse) containing the range of plausible values (where applicable), in order [<i>min</i>, <i>max</i>]. Used where a best-fit value and corresponding error isn't appropriate.
<li><b><i>err</i></b>: a two-element array (of numberse) containing the errors on the "best" value (where applicable), in order [<i>upper</i>, <i>lower</i>]. Only accompanies a "best" value.</li>
</ul>
<h2>Built-in functions</h2>
<p>A number of functions exist to allow access to the data.</p>
<ul>
<li><b><i>getParamType</i></b>(<i>event</i>, <i>param</i>): get the type of the value of parameter <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns string of value type, or '' if not found.</li>
<li><b><i>hasError</i></b>(<i>event</i>, <i>param</i>): returns whether the <i>param</i> [string] has an "err" value for event <i>event</i> (name [string] or index [integer]). Returns boolean (true|false), or false if not found.</li>
<li><b><i>getBest</i></b>(<i>event</i>, <i>param</i>): gets "best" value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns value, or NaN if not found.</li>
<li><b><i>getBestErr</i></b>(<i>event</i>, <i>param</i>): gets "best" and "err" value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns array of [best, err].</li>
<li><b><i>getLim</i></b>(<i>event</i>, <i>param</i>): gets "lim" value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns value, or empty array [] if not found.</li>
<li><b><i>getLower</i></b>(<i>event</i>, <i>param</i>): gets "lower" value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns value, or NaN if not found.</li>
<li><b><i>getUpper</i></b>(<i>event</i>, <i>param</i>): gets "upper" value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns value, or NaN if not found.</li>
<li><b><i>getError</i></b>(<i>event</i>, <i>param</i>): gets "err" value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns value, or empty array [] if not found.</li>
<li><b><i>getNominal</i></b>(<i>event</i>, <i>param</i>): gets the nominal value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns best, lower or upper value, or average of lim values.</li>
<li><b><i>getMinValue</i></b>(<i>event</i>, <i>param</i>): gets the minimum value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns "best"-"err[1]", "lower", lower "lim" values, or -Infinity for "upper" values</li>
<li><b><i>getMaxValue</i></b>(<i>event</i>, <i>param</i>): gets the minimum value for <i>param</i> [string] for event <i>event</i> (name [string] or index [integer]). Returns "best"+"err[0]", "upper", higher "lim" values, or +Infinity for "lower" values</li>
<li><b><i>paramName</i></b>(<i>param</i>): returns the name of <i>param</i> [string] as stored in datadict, or '' if not found.</li>
<li><b><i>paramUnit</i></b>(<i>param</i>): returns the unit of <i>param</i> [string] as stored in datadict, or '' if not found.</li>
<li><b><i>getRef</i></b>(<i>event</i>): returns the reference dict of <i>event</i> [string] as stored in datadict, or {} if not found. Result is a dict containing URL and name.</li>
<li><b><i>getOpenData</i></b>(<i>event</i>): returns the data link of <i>event</i> [string] as stored in datadict, or {} if not found. Result is a dict containing URL and name.</li>
</ul>
<h2 id="tests">Example Tests</h2>
<ul class="unittests">
<li class="unittest"><p>Check we can get the mass of the primary object. Note that <code>getBest(event,param)</code> is just an alias for <code>getValue(event,param,'best')</code></p><code><div class="input">gwcat.getBest("GW150914","M1") + " " + gwcat.paramUnit("M1")</div>// Expect: <span class="expect">35.6 M_sun</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><p>Check we can get the mass of the primary object using the <em>this</em> object rather than a global variable. This will allow multiple catalogues to be loaded and a single callback function to process them as it doesn't need to know the name of the variable.</p><code><div class="input">this.getBest("GW150914","M1") + " " + this.paramUnit("M1")</div>// Expect: <span class="expect">35.6 M_sun</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><p>Get the upper limit on the primary mass.</p><code><div class="input">gwcat.getMaxVal("GW150914","M1") + " " + gwcat.paramUnit("M1")</div>// Expect: <span class="expect">40.4 M_sun</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><p>Get the final, combined, mass of the event.</p><code><div class="input">gwcat.getUpper("GW170817","Mfinal") + " " + gwcat.paramUnit("Mfinal")</div>// Expect: <span class="expect">2.8 M_sun</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><code><div class="input">gwcat.getParamType("GW170817","Mfinal")</div>// Expect: <span class="expect">upper</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><p>Get a lower value for an upper limit, to check infinities.</p><code><div class="input">gwcat.getMinVal("GW170817","Mfinal") + " " + gwcat.paramUnit("Mfinal")</div>// Expect: <span class="expect">-Infinity M_sun</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><code><div class="input">gwcat.getValue("GW170817","Erad","lower") + " " + gwcat.paramUnit("Erad")</div>// Expect: <span class="expect">0.04 M_sun c^2</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><p>Return a text description of the parameter.</p><code><div class="input">gwcat.paramName("chi")</div>// Expect: <span class="expect">Effective inspiral spin</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><code><div class="input">gwcat.paramUnit("lpeak")</div>// Expect: <span class="expect">10^56 erg s^-1</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><p>Get the URL of the open data</p><code><div class="input">gwcat.getOpenData("GW150914")['url']</div>// Expect: <span class="expect">https://www.gw-openscience.org/catalog/GWTC-1-confident/single/GW150914</span><br />// Return: <span class="output">ERROR</span></code></li>
<li class="unittest"><p>Get the earliest gravitational wave. To do this we explicitly order the catalogue by the UTC of the event.</p><pre><div class="input">function earliestGW(){
gwcat.orderData("UTC");
return gwcat.data[0].name;
}
earliestGW();</div>// Expect: <span class="expect">GW150914</span><br />// Return: <span class="output">ERROR</span></pre></li>
</ul>
<script type="text/javascript">
function runTests(){
var tests,n,pass,rtn,exp;
tests = S('.unittest');
n = tests.length;
pass = 0;
for(var i = 0; i < n; i++){
el = S(tests[i]);
rtn = eval(el.find('.input').html());
exp = el.find('.expect').html();
el.find('.output').html(rtn);
if(rtn == exp){
el.addClass('unittest-success').removeClass('unittest-fail');
pass++;
}else{
el.addClass('unittest-fail').removeClass('unittest-success');
}
}
S('#message').html('It loads! :-) <a href="#tests">Passed '+pass+' of '+n+' tests</a>');
}
var gwcat = new GWCat(runTests,{datasrc:'gwosc'});
</script>
</body>
</html>