-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_tutorial.html
367 lines (288 loc) · 13.4 KB
/
filter_tutorial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1"><meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Alerts tutorial</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/theme.css " type="text/css" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<!-- sphinx script_files -->
<script src="_static/documentation_options.js?v=5929fcd5"></script>
<script src="_static/doctools.js?v=9a2dae69"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<!-- bundled in js (rollup iife) -->
<!-- <script src="_static/theme-vendors.js"></script> -->
<script src="_static/theme.js" defer></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
</head>
<body>
<div id="app">
<div class="theme-container" :class="pageClasses"><navbar @toggle-sidebar="toggleSidebar">
<router-link to="index.html" class="home-link">
<span class="site-name">Fritz Marshal</span>
</router-link>
<div class="links">
<navlinks class="can-hide">
</navlinks>
</div>
</navbar>
<div class="sidebar-mask" @click="toggleSidebar(false)">
</div>
<sidebar @toggle-sidebar="toggleSidebar">
<navlinks>
</navlinks><div id="searchbox" class="searchbox" role="search">
<div class="caption"><span class="caption-text">Quick search</span>
<div class="searchformwrapper">
<form class="search" action="search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Search" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
</div><div class="sidebar-links" role="navigation" aria-label="main navigation">
<div class="sidebar-group">
<p class="caption">
<span class="caption-text"><a href="index.html#fritz-marshal-manual">fritz marshal manual</a></span>
</p>
<ul class="">
<li class="toctree-l1 ">
<a href="user_guide.html" class="reference internal ">Fritz User Guide</a>
</li>
<li class="toctree-l1 ">
<a href="run_your_own.html" class="reference internal ">Run your own Fritz</a>
</li>
<li class="toctree-l1 ">
<a href="api.html" class="reference internal ">API</a>
</li>
<li class="toctree-l1 ">
<a href="catalogs.html" class="reference internal ">Kowalski collection schemas</a>
</li>
<li class="toctree-l1 ">
<a href="technical_implementation.html" class="reference internal ">Technical implementation</a>
</li>
<li class="toctree-l1 ">
<a href="developer.html" class="reference internal ">Developer Guidelines</a>
</li>
<li class="toctree-l1 ">
<a href="license.html" class="reference internal ">License</a>
</li>
</ul>
</div>
</div>
</sidebar>
<page>
<div class="body-header" role="navigation" aria-label="navigation">
<ul class="breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Alerts tutorial</li>
</ul>
<ul class="page-nav">
</ul>
</div>
<hr>
<div class="content" role="main" v-pre>
<section id="alerts-tutorial">
<h1>Alerts tutorial<a class="headerlink" href="#alerts-tutorial" title="Link to this heading">¶</a></h1>
<p>This document will help you navigate through the simulated Rubin alerts ingested in the MongoDB Compass, so that you can try different filtering schemes using the MongoDB syntax, which is compatible with Fritz.
First a summary of what you’ll do:</p>
<ul class="simple">
<li><p>Install MongoDB Compass</p></li>
<li><p>Connect to cluster with Rubin alerts</p></li>
<li><p>Create your filter</p></li>
<li><p>Save your candidates</p></li>
<li><p>Explore your results</p></li>
</ul>
<section id="note">
<h2>0. Note<a class="headerlink" href="#note" title="Link to this heading">¶</a></h2>
<p>I based most of this work on the tutorial you can find <a class="reference external" href="https://docs.fritz.science/user_guide.html#alert-filters-in-fritz">the alert filters tutorial you can find here</a>, so I recommend looking at it if you run into an issue.</p>
</section>
<section id="to-install-mongodb-compass">
<h2>1. To install MongoDB Compass<a class="headerlink" href="#to-install-mongodb-compass" title="Link to this heading">¶</a></h2>
<p>Go to https://www.mongodb.com/products/compass and click in ‘Download now’</p>
</section>
<section id="connecting-to-cluster">
<h2>2. Connecting to cluster<a class="headerlink" href="#connecting-to-cluster" title="Link to this heading">¶</a></h2>
<p>Once Mongo DB Compass is installed, launch it, and connect to the cluster by</p>
<ul>
<li><p>Opening Mongo DB Compass</p></li>
<li><p>Copy the following into the box under New Connection, and click Connect. <br/>
mongodb+srv://alert_digger:WhereIsTheKN@cluster0.s0ada.mongodb.net/test <br/></p>
<p><img alt="tutorial: cluster info" src="_images/tutorial1.png" /></p>
</li>
<li><p>To see the alerts (around 4000 of them) navigate in the left menu to the folder ZTF > lsst_800</p>
<p><img alt="tutorial: alerts" src="_images/tutorial2.png" /></p>
</li>
</ul>
<p><strong>Tab description</strong>
From https://www.mongodb.com/docs/</p>
<ul class="simple">
<li><p>Documents: here you can see all the avro packages, and their individual properties. You can add Data or export a collection. You can apply filters here too, but it is easier in the Aggregation tab. It displays only 20 alerts.</p></li>
<li><p>Aggregations: Here you can make a new filter and apply it to the collection. After each step, you can visualize how many alerts passed the filters and modify the filter step to check how things change. You can export the results and resulting filter.</p></li>
<li><p>Scheme: provides an overview of the data type and shape of the fields in a particular collection. Databases and collections are visible in the left-side navigation.</p></li>
<li><p>Explain plan: it shows the details of your filter.</p></li>
<li><p>Indexes: Indexes are special data structures that improve query performance. Indexes store a portion of a collection’s data in an easy-to-traverse form. The Indexes tab lists the existing indexes for a collection</p></li>
<li><p>Validation: <em>Schema validation</em> ensures that all documents in a collection follow a defined set of rules, such as conforming to a specific shape or only allowing a specified range of values in fields. This tab allows you to manage <em>schema validation</em> rules for a collection.</p></li>
</ul>
</section>
<section id="to-make-a-new-filter">
<h2>3. To make a new filter<a class="headerlink" href="#to-make-a-new-filter" title="Link to this heading">¶</a></h2>
<p>In the Aggregation tab, click on Create New > Pipeline from text. This will promt a new window where you can write/paste your filter.</p>
<p><img alt="tutorial: pipeline" src="_images/tutorial3.png" /></p>
<p>At the end of this document there is a filtering example, used by the multi-messenger astronomy (MMA) group to vet short gamma-ray burst (SGRB) candidates. Once you plug in your filter, MongoDB Compass will break it down for you in different steps. This filter has two $project stages before the $match stage. You can play around with these to modify your filter.</p>
<p><img alt="tutorial: filter steps" src="_images/tutorial4.png" /></p>
</section>
<section id="saving-candidates">
<h2>4. Saving candidates<a class="headerlink" href="#saving-candidates" title="Link to this heading">¶</a></h2>
<p>Once you are done with the filtering, you can</p>
<ol class="arabic simple">
<li><p>‘Export to language’ (recommended, as MongoDB Compass is not good for saving your filters) - button next to ‘Create new +’.</p></li>
<li><p>Save your current filter – Save button next to ‘Create new +’.
3. Export your results as a json or csv file – click on the export button next to ‘Run’ and then choose your preferred format.</p></li>
</ol>
</section>
<section id="exploring">
<h2>5. Exploring<a class="headerlink" href="#exploring" title="Link to this heading">¶</a></h2>
<p>Use your favorite language to explore your json or csv file.</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>import pandas as pd
name_csv = 'your_file.csv'
results_filter = pd.read_csv(name_csv)
sources = [int(f[-5:]) for f in results_filter['objectId']]
print('The number of surces that passed our MMA SGRB filter:',len(results_filter))
</pre></div>
</div>
</section>
<section id="future-work">
<h2>Future work:<a class="headerlink" href="#future-work" title="Link to this heading">¶</a></h2>
<p>Add ZTF alerts</p>
</section>
<section id="filter-example">
<h2>Filter example<a class="headerlink" href="#filter-example" title="Link to this heading">¶</a></h2>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>[{
$project: {
_id: 1,
candid: 1,
objectId: 1,
'prv_candidates.jd': 1,
'prv_candidates.magpsf': 1,
'prv_candidates.fid': 1,
'prv_candidates.isdiffpos': 1,
'prv_candidates.diffmaglim': 1,
isdiffpos: '$candidate.isdiffpos',
m_now: '$candidate.magpsf',
m_app: '$candidate.magap',
t_now: '$candidate.jd',
fid_now: '$candidate.fid',
sgscore: '$candidate.sgscore1',
sgscore2: '$candidate.sgscore2',
sgscore3: '$candidate.sgscore3',
srmag: '$candidate.srmag1',
srmag2: '$candidate.srmag2',
srmag3: '$candidate.srmag3',
sgmag: '$candidate.sgmag1',
simag: '$candidate.simag1',
rbscore: '$candidate.rb',
drbscore: '$candidate.drb',
magnr: '$candidate.magnr',
distnr: '$candidate.distnr',
distpsnr1: '$candidate.distpsnr1',
distpsnr2: '$candidate.distpsnr2',
distpsnr3: '$candidate.distpsnr3',
scorr: '$candidate.scorr',
fwhm: '$candidate.fwhm',
elong: '$candidate.elong',
nbad: '$candidate.nbad',
chipsf: '$candidate.chipsf',
gal_lat: '$coordinates.b',
ssdistnr: '$candidate.ssdistnr',
ssmagnr: '$candidate.ssmagnr',
ssnamenr: '$candidate.ssnamenr',
t_start: '$candidate.jdstarthist',
age: {$subtract: ['$candidate.jd','$candidate.jdstarthist']},
psfminap: {$subtract: ['$candidate.magpsf','$candidate.magap']}}
},
{
$project: {
objectId: 1,
t_now: 1,
t_start: 1,
m_now: 1,
fid_now: 1,
sgscore: 1,
rbscore: 1,
drbscore: 1,
magnr: 1,
distnr: 1,
scorr: 1,
gal_lat: 1,
ssdistnr: 1,
ssnamenr: 1,
ssmagnr: 1,
age: 1,
nbad: 1,
fwhm: 1,
elong: 1,
psfminap: 1,
prv_candidates: 1,
positivesubtraction: {$in: ['$isdiffpos',[1,'1','t',true]]},
real: {$and: [
{$gt: ['$drbscore',0.3]},
{$lt: ['$nbad',5]},
{$gt: ['$fwhm',0.5]},
{$lt: ['$fwhm',5]},
{$lt: [{$abs: '$psfminap'},0.75]}]},
rock: {$and: [{$gte: ['$ssdistnr',0]},
{$lt: ['$ssdistnr',10]},
{$lt: [{$abs: '$ssmagnr'},20]}]},
young: {$lt: ['$age',10]},
pointunderneath: {$and: [{$gt: ['$sgscore',0.76]},
{$lt: ['$distpsnr1',2]}]},
brightstar: {$or:[{$and: [{$lt: ['$distpsnr1',15]},
{$lt: ['$srmag',15]},
{$gt: ['$srmag',0]},
{$gt: ['$sgscore',0.49]}]},
{$and: [{$lt: ['$distpsnr2',15]},
{$lt: ['$srmag2',15]},
{$gt: ['$srmag2',0]},
{$gt: ['$sgscore2',0.49]}]},
{$and: [{$lt: ['$distpsnr3',15]},
{$lt: ['$srmag3',15]},
{$gt: ['$srmag3',0]},
{$gt: ['$sgscore3',0.49]}]},
{$and: [{$eq: ['$sgscore',0.5]},
{$lt: ['$distpsnr1',0.5]},
{$or: [{$lt: ['$sgmag',17]},
{$lt: ['$srmag',17]},
{$lt: ['$simag',17]}]}]
}]}}},
{
$match: {
brightstar: false,
pointunderneath: false,
positivesubtraction: true,
real: true,
rock: false,
young: true
}
}]
</pre></div>
</div>
</section>
</section>
</div>
<div class="page-nav">
<div class="inner"><ul class="page-nav">
</ul><div class="footer" role="contentinfo">
© Copyright 2020, The Fritz Marshal authors.
<br>
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 7.4.7 with <a href="https://github.com/schettino72/sphinx_press_theme">Press Theme</a> 0.9.1.
</div>
</div>
</div>
</page>
</div></div>
</body>
</html>