├── .gitignore
├── 0737.png
├── 0_Test_Installation.ipynb
├── 1_Introduction_to_pulsar_search_and_timing.ipynb
├── 2_Aperiodic_Timing.ipynb
├── 3_Fitting_Power_Density_Spectra.ipynb
├── 4_Orbital_Doppler.ipynb
├── License.md
├── QPO_NS_BH.png
├── README.md
├── buriedclock.jpg
├── modeling_tutorial_mcmc_corner.pdf
├── no-binder
├── Timing_Mainstream_Software.ipynb
└── Timing_residuals.ipynb
├── oh_deer.png
├── requirements.txt
└── smallmodpulsar.gif
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 |
--------------------------------------------------------------------------------
/0737.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matteobachetti/timing-lectures/820f14edd68e3495546c77131009837ed895040b/0737.png
--------------------------------------------------------------------------------
/0_Test_Installation.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "import importlib\n",
10 | "\n",
11 | "def check_library(libname, path=None):\n",
12 | " if path is None:\n",
13 | " path = libname\n",
14 | "\n",
15 | " try:\n",
16 | " library = importlib.import_module(libname)\n",
17 | " print(f\"Installed: {library.__version__}\")\n",
18 | " except ImportError:\n",
19 | " print(f\"Please install {libname}:\")\n",
20 | " print(f\"pip install {path}\")"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": null,
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "check_library(\"stingray\", 'git+https://github.com/stingraysoftware/stingray.git')"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": null,
35 | "metadata": {},
36 | "outputs": [],
37 | "source": [
38 | "check_library(\"hendrics\", 'git+https://github.com/stingraysoftware/hendrics.git')"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "metadata": {},
45 | "outputs": [],
46 | "source": [
47 | "check_library(\"emcee\")"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "metadata": {},
54 | "outputs": [],
55 | "source": [
56 | "check_library(\"astropy\")"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": null,
62 | "metadata": {},
63 | "outputs": [],
64 | "source": [
65 | "check_library(\"numba\")"
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {},
72 | "outputs": [],
73 | "source": [
74 | "check_library(\"pint\", \"git+https://github.com/nanograv/pint.git\")"
75 | ]
76 | },
77 | {
78 | "cell_type": "code",
79 | "execution_count": null,
80 | "metadata": {},
81 | "outputs": [],
82 | "source": []
83 | }
84 | ],
85 | "metadata": {
86 | "kernelspec": {
87 | "display_name": "Python 3",
88 | "language": "python",
89 | "name": "python3"
90 | },
91 | "language_info": {
92 | "codemirror_mode": {
93 | "name": "ipython",
94 | "version": 3
95 | },
96 | "file_extension": ".py",
97 | "mimetype": "text/x-python",
98 | "name": "python",
99 | "nbconvert_exporter": "python",
100 | "pygments_lexer": "ipython3",
101 | "version": "3.7.5"
102 | }
103 | },
104 | "nbformat": 4,
105 | "nbformat_minor": 2
106 | }
107 |
--------------------------------------------------------------------------------
/4_Orbital_Doppler.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 17,
6 | "metadata": {
7 | "collapsed": true
8 | },
9 | "outputs": [],
10 | "source": [
11 | "%matplotlib nbagg\n",
12 | "import matplotlib.pyplot as plt\n",
13 | "import numpy as np\n",
14 | "from PyAstronomy import pyasl\n",
15 | "from matplotlib.gridspec import GridSpec"
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {},
21 | "source": [
22 | "## Orbital Doppler"
23 | ]
24 | },
25 | {
26 | "cell_type": "code",
27 | "execution_count": 80,
28 | "metadata": {
29 | "collapsed": false
30 | },
31 | "outputs": [
32 | {
33 | "data": {
34 | "application/javascript": [
35 | "/* Put everything inside the global mpl namespace */\n",
36 | "window.mpl = {};\n",
37 | "\n",
38 | "mpl.get_websocket_type = function() {\n",
39 | " if (typeof(WebSocket) !== 'undefined') {\n",
40 | " return WebSocket;\n",
41 | " } else if (typeof(MozWebSocket) !== 'undefined') {\n",
42 | " return MozWebSocket;\n",
43 | " } else {\n",
44 | " alert('Your browser does not have WebSocket support.' +\n",
45 | " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n",
46 | " 'Firefox 4 and 5 are also supported but you ' +\n",
47 | " 'have to enable WebSockets in about:config.');\n",
48 | " };\n",
49 | "}\n",
50 | "\n",
51 | "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n",
52 | " this.id = figure_id;\n",
53 | "\n",
54 | " this.ws = websocket;\n",
55 | "\n",
56 | " this.supports_binary = (this.ws.binaryType != undefined);\n",
57 | "\n",
58 | " if (!this.supports_binary) {\n",
59 | " var warnings = document.getElementById(\"mpl-warnings\");\n",
60 | " if (warnings) {\n",
61 | " warnings.style.display = 'block';\n",
62 | " warnings.textContent = (\n",
63 | " \"This browser does not support binary websocket messages. \" +\n",
64 | " \"Performance may be slow.\");\n",
65 | " }\n",
66 | " }\n",
67 | "\n",
68 | " this.imageObj = new Image();\n",
69 | "\n",
70 | " this.context = undefined;\n",
71 | " this.message = undefined;\n",
72 | " this.canvas = undefined;\n",
73 | " this.rubberband_canvas = undefined;\n",
74 | " this.rubberband_context = undefined;\n",
75 | " this.format_dropdown = undefined;\n",
76 | "\n",
77 | " this.image_mode = 'full';\n",
78 | "\n",
79 | " this.root = $('
');\n",
80 | " this._root_extra_style(this.root)\n",
81 | " this.root.attr('style', 'display: inline-block');\n",
82 | "\n",
83 | " $(parent_element).append(this.root);\n",
84 | "\n",
85 | " this._init_header(this);\n",
86 | " this._init_canvas(this);\n",
87 | " this._init_toolbar(this);\n",
88 | "\n",
89 | " var fig = this;\n",
90 | "\n",
91 | " this.waiting = false;\n",
92 | "\n",
93 | " this.ws.onopen = function () {\n",
94 | " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n",
95 | " fig.send_message(\"send_image_mode\", {});\n",
96 | " fig.send_message(\"refresh\", {});\n",
97 | " }\n",
98 | "\n",
99 | " this.imageObj.onload = function() {\n",
100 | " if (fig.image_mode == 'full') {\n",
101 | " // Full images could contain transparency (where diff images\n",
102 | " // almost always do), so we need to clear the canvas so that\n",
103 | " // there is no ghosting.\n",
104 | " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n",
105 | " }\n",
106 | " fig.context.drawImage(fig.imageObj, 0, 0);\n",
107 | " };\n",
108 | "\n",
109 | " this.imageObj.onunload = function() {\n",
110 | " this.ws.close();\n",
111 | " }\n",
112 | "\n",
113 | " this.ws.onmessage = this._make_on_message_function(this);\n",
114 | "\n",
115 | " this.ondownload = ondownload;\n",
116 | "}\n",
117 | "\n",
118 | "mpl.figure.prototype._init_header = function() {\n",
119 | " var titlebar = $(\n",
120 | " '');\n",
122 | " var titletext = $(\n",
123 | " '');\n",
125 | " titlebar.append(titletext)\n",
126 | " this.root.append(titlebar);\n",
127 | " this.header = titletext[0];\n",
128 | "}\n",
129 | "\n",
130 | "\n",
131 | "\n",
132 | "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n",
133 | "\n",
134 | "}\n",
135 | "\n",
136 | "\n",
137 | "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n",
138 | "\n",
139 | "}\n",
140 | "\n",
141 | "mpl.figure.prototype._init_canvas = function() {\n",
142 | " var fig = this;\n",
143 | "\n",
144 | " var canvas_div = $('');\n",
145 | "\n",
146 | " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n",
147 | "\n",
148 | " function canvas_keyboard_event(event) {\n",
149 | " return fig.key_event(event, event['data']);\n",
150 | " }\n",
151 | "\n",
152 | " canvas_div.keydown('key_press', canvas_keyboard_event);\n",
153 | " canvas_div.keyup('key_release', canvas_keyboard_event);\n",
154 | " this.canvas_div = canvas_div\n",
155 | " this._canvas_extra_style(canvas_div)\n",
156 | " this.root.append(canvas_div);\n",
157 | "\n",
158 | " var canvas = $('');\n",
159 | " canvas.addClass('mpl-canvas');\n",
160 | " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n",
161 | "\n",
162 | " this.canvas = canvas[0];\n",
163 | " this.context = canvas[0].getContext(\"2d\");\n",
164 | "\n",
165 | " var rubberband = $('');\n",
166 | " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n",
167 | "\n",
168 | " var pass_mouse_events = true;\n",
169 | "\n",
170 | " canvas_div.resizable({\n",
171 | " start: function(event, ui) {\n",
172 | " pass_mouse_events = false;\n",
173 | " },\n",
174 | " resize: function(event, ui) {\n",
175 | " fig.request_resize(ui.size.width, ui.size.height);\n",
176 | " },\n",
177 | " stop: function(event, ui) {\n",
178 | " pass_mouse_events = true;\n",
179 | " fig.request_resize(ui.size.width, ui.size.height);\n",
180 | " },\n",
181 | " });\n",
182 | "\n",
183 | " function mouse_event_fn(event) {\n",
184 | " if (pass_mouse_events)\n",
185 | " return fig.mouse_event(event, event['data']);\n",
186 | " }\n",
187 | "\n",
188 | " rubberband.mousedown('button_press', mouse_event_fn);\n",
189 | " rubberband.mouseup('button_release', mouse_event_fn);\n",
190 | " // Throttle sequential mouse events to 1 every 20ms.\n",
191 | " rubberband.mousemove('motion_notify', mouse_event_fn);\n",
192 | "\n",
193 | " rubberband.mouseenter('figure_enter', mouse_event_fn);\n",
194 | " rubberband.mouseleave('figure_leave', mouse_event_fn);\n",
195 | "\n",
196 | " canvas_div.on(\"wheel\", function (event) {\n",
197 | " event = event.originalEvent;\n",
198 | " event['data'] = 'scroll'\n",
199 | " if (event.deltaY < 0) {\n",
200 | " event.step = 1;\n",
201 | " } else {\n",
202 | " event.step = -1;\n",
203 | " }\n",
204 | " mouse_event_fn(event);\n",
205 | " });\n",
206 | "\n",
207 | " canvas_div.append(canvas);\n",
208 | " canvas_div.append(rubberband);\n",
209 | "\n",
210 | " this.rubberband = rubberband;\n",
211 | " this.rubberband_canvas = rubberband[0];\n",
212 | " this.rubberband_context = rubberband[0].getContext(\"2d\");\n",
213 | " this.rubberband_context.strokeStyle = \"#000000\";\n",
214 | "\n",
215 | " this._resize_canvas = function(width, height) {\n",
216 | " // Keep the size of the canvas, canvas container, and rubber band\n",
217 | " // canvas in synch.\n",
218 | " canvas_div.css('width', width)\n",
219 | " canvas_div.css('height', height)\n",
220 | "\n",
221 | " canvas.attr('width', width);\n",
222 | " canvas.attr('height', height);\n",
223 | "\n",
224 | " rubberband.attr('width', width);\n",
225 | " rubberband.attr('height', height);\n",
226 | " }\n",
227 | "\n",
228 | " // Set the figure to an initial 600x600px, this will subsequently be updated\n",
229 | " // upon first draw.\n",
230 | " this._resize_canvas(600, 600);\n",
231 | "\n",
232 | " // Disable right mouse context menu.\n",
233 | " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n",
234 | " return false;\n",
235 | " });\n",
236 | "\n",
237 | " function set_focus () {\n",
238 | " canvas.focus();\n",
239 | " canvas_div.focus();\n",
240 | " }\n",
241 | "\n",
242 | " window.setTimeout(set_focus, 100);\n",
243 | "}\n",
244 | "\n",
245 | "mpl.figure.prototype._init_toolbar = function() {\n",
246 | " var fig = this;\n",
247 | "\n",
248 | " var nav_element = $('')\n",
249 | " nav_element.attr('style', 'width: 100%');\n",
250 | " this.root.append(nav_element);\n",
251 | "\n",
252 | " // Define a callback function for later on.\n",
253 | " function toolbar_event(event) {\n",
254 | " return fig.toolbar_button_onclick(event['data']);\n",
255 | " }\n",
256 | " function toolbar_mouse_event(event) {\n",
257 | " return fig.toolbar_button_onmouseover(event['data']);\n",
258 | " }\n",
259 | "\n",
260 | " for(var toolbar_ind in mpl.toolbar_items) {\n",
261 | " var name = mpl.toolbar_items[toolbar_ind][0];\n",
262 | " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
263 | " var image = mpl.toolbar_items[toolbar_ind][2];\n",
264 | " var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
265 | "\n",
266 | " if (!name) {\n",
267 | " // put a spacer in here.\n",
268 | " continue;\n",
269 | " }\n",
270 | " var button = $('');\n",
271 | " button.addClass('ui-button ui-widget ui-state-default ui-corner-all ' +\n",
272 | " 'ui-button-icon-only');\n",
273 | " button.attr('role', 'button');\n",
274 | " button.attr('aria-disabled', 'false');\n",
275 | " button.click(method_name, toolbar_event);\n",
276 | " button.mouseover(tooltip, toolbar_mouse_event);\n",
277 | "\n",
278 | " var icon_img = $('');\n",
279 | " icon_img.addClass('ui-button-icon-primary ui-icon');\n",
280 | " icon_img.addClass(image);\n",
281 | " icon_img.addClass('ui-corner-all');\n",
282 | "\n",
283 | " var tooltip_span = $('');\n",
284 | " tooltip_span.addClass('ui-button-text');\n",
285 | " tooltip_span.html(tooltip);\n",
286 | "\n",
287 | " button.append(icon_img);\n",
288 | " button.append(tooltip_span);\n",
289 | "\n",
290 | " nav_element.append(button);\n",
291 | " }\n",
292 | "\n",
293 | " var fmt_picker_span = $('');\n",
294 | "\n",
295 | " var fmt_picker = $('');\n",
296 | " fmt_picker.addClass('mpl-toolbar-option ui-widget ui-widget-content');\n",
297 | " fmt_picker_span.append(fmt_picker);\n",
298 | " nav_element.append(fmt_picker_span);\n",
299 | " this.format_dropdown = fmt_picker[0];\n",
300 | "\n",
301 | " for (var ind in mpl.extensions) {\n",
302 | " var fmt = mpl.extensions[ind];\n",
303 | " var option = $(\n",
304 | " '', {selected: fmt === mpl.default_extension}).html(fmt);\n",
305 | " fmt_picker.append(option)\n",
306 | " }\n",
307 | "\n",
308 | " // Add hover states to the ui-buttons\n",
309 | " $( \".ui-button\" ).hover(\n",
310 | " function() { $(this).addClass(\"ui-state-hover\");},\n",
311 | " function() { $(this).removeClass(\"ui-state-hover\");}\n",
312 | " );\n",
313 | "\n",
314 | " var status_bar = $('');\n",
315 | " nav_element.append(status_bar);\n",
316 | " this.message = status_bar[0];\n",
317 | "}\n",
318 | "\n",
319 | "mpl.figure.prototype.request_resize = function(x_pixels, y_pixels) {\n",
320 | " // Request matplotlib to resize the figure. Matplotlib will then trigger a resize in the client,\n",
321 | " // which will in turn request a refresh of the image.\n",
322 | " this.send_message('resize', {'width': x_pixels, 'height': y_pixels});\n",
323 | "}\n",
324 | "\n",
325 | "mpl.figure.prototype.send_message = function(type, properties) {\n",
326 | " properties['type'] = type;\n",
327 | " properties['figure_id'] = this.id;\n",
328 | " this.ws.send(JSON.stringify(properties));\n",
329 | "}\n",
330 | "\n",
331 | "mpl.figure.prototype.send_draw_message = function() {\n",
332 | " if (!this.waiting) {\n",
333 | " this.waiting = true;\n",
334 | " this.ws.send(JSON.stringify({type: \"draw\", figure_id: this.id}));\n",
335 | " }\n",
336 | "}\n",
337 | "\n",
338 | "\n",
339 | "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
340 | " var format_dropdown = fig.format_dropdown;\n",
341 | " var format = format_dropdown.options[format_dropdown.selectedIndex].value;\n",
342 | " fig.ondownload(fig, format);\n",
343 | "}\n",
344 | "\n",
345 | "\n",
346 | "mpl.figure.prototype.handle_resize = function(fig, msg) {\n",
347 | " var size = msg['size'];\n",
348 | " if (size[0] != fig.canvas.width || size[1] != fig.canvas.height) {\n",
349 | " fig._resize_canvas(size[0], size[1]);\n",
350 | " fig.send_message(\"refresh\", {});\n",
351 | " };\n",
352 | "}\n",
353 | "\n",
354 | "mpl.figure.prototype.handle_rubberband = function(fig, msg) {\n",
355 | " var x0 = msg['x0'];\n",
356 | " var y0 = fig.canvas.height - msg['y0'];\n",
357 | " var x1 = msg['x1'];\n",
358 | " var y1 = fig.canvas.height - msg['y1'];\n",
359 | " x0 = Math.floor(x0) + 0.5;\n",
360 | " y0 = Math.floor(y0) + 0.5;\n",
361 | " x1 = Math.floor(x1) + 0.5;\n",
362 | " y1 = Math.floor(y1) + 0.5;\n",
363 | " var min_x = Math.min(x0, x1);\n",
364 | " var min_y = Math.min(y0, y1);\n",
365 | " var width = Math.abs(x1 - x0);\n",
366 | " var height = Math.abs(y1 - y0);\n",
367 | "\n",
368 | " fig.rubberband_context.clearRect(\n",
369 | " 0, 0, fig.canvas.width, fig.canvas.height);\n",
370 | "\n",
371 | " fig.rubberband_context.strokeRect(min_x, min_y, width, height);\n",
372 | "}\n",
373 | "\n",
374 | "mpl.figure.prototype.handle_figure_label = function(fig, msg) {\n",
375 | " // Updates the figure title.\n",
376 | " fig.header.textContent = msg['label'];\n",
377 | "}\n",
378 | "\n",
379 | "mpl.figure.prototype.handle_cursor = function(fig, msg) {\n",
380 | " var cursor = msg['cursor'];\n",
381 | " switch(cursor)\n",
382 | " {\n",
383 | " case 0:\n",
384 | " cursor = 'pointer';\n",
385 | " break;\n",
386 | " case 1:\n",
387 | " cursor = 'default';\n",
388 | " break;\n",
389 | " case 2:\n",
390 | " cursor = 'crosshair';\n",
391 | " break;\n",
392 | " case 3:\n",
393 | " cursor = 'move';\n",
394 | " break;\n",
395 | " }\n",
396 | " fig.rubberband_canvas.style.cursor = cursor;\n",
397 | "}\n",
398 | "\n",
399 | "mpl.figure.prototype.handle_message = function(fig, msg) {\n",
400 | " fig.message.textContent = msg['message'];\n",
401 | "}\n",
402 | "\n",
403 | "mpl.figure.prototype.handle_draw = function(fig, msg) {\n",
404 | " // Request the server to send over a new figure.\n",
405 | " fig.send_draw_message();\n",
406 | "}\n",
407 | "\n",
408 | "mpl.figure.prototype.handle_image_mode = function(fig, msg) {\n",
409 | " fig.image_mode = msg['mode'];\n",
410 | "}\n",
411 | "\n",
412 | "mpl.figure.prototype.updated_canvas_event = function() {\n",
413 | " // Called whenever the canvas gets updated.\n",
414 | " this.send_message(\"ack\", {});\n",
415 | "}\n",
416 | "\n",
417 | "// A function to construct a web socket function for onmessage handling.\n",
418 | "// Called in the figure constructor.\n",
419 | "mpl.figure.prototype._make_on_message_function = function(fig) {\n",
420 | " return function socket_on_message(evt) {\n",
421 | " if (evt.data instanceof Blob) {\n",
422 | " /* FIXME: We get \"Resource interpreted as Image but\n",
423 | " * transferred with MIME type text/plain:\" errors on\n",
424 | " * Chrome. But how to set the MIME type? It doesn't seem\n",
425 | " * to be part of the websocket stream */\n",
426 | " evt.data.type = \"image/png\";\n",
427 | "\n",
428 | " /* Free the memory for the previous frames */\n",
429 | " if (fig.imageObj.src) {\n",
430 | " (window.URL || window.webkitURL).revokeObjectURL(\n",
431 | " fig.imageObj.src);\n",
432 | " }\n",
433 | "\n",
434 | " fig.imageObj.src = (window.URL || window.webkitURL).createObjectURL(\n",
435 | " evt.data);\n",
436 | " fig.updated_canvas_event();\n",
437 | " fig.waiting = false;\n",
438 | " return;\n",
439 | " }\n",
440 | " else if (typeof evt.data === 'string' && evt.data.slice(0, 21) == \"data:image/png;base64\") {\n",
441 | " fig.imageObj.src = evt.data;\n",
442 | " fig.updated_canvas_event();\n",
443 | " fig.waiting = false;\n",
444 | " return;\n",
445 | " }\n",
446 | "\n",
447 | " var msg = JSON.parse(evt.data);\n",
448 | " var msg_type = msg['type'];\n",
449 | "\n",
450 | " // Call the \"handle_{type}\" callback, which takes\n",
451 | " // the figure and JSON message as its only arguments.\n",
452 | " try {\n",
453 | " var callback = fig[\"handle_\" + msg_type];\n",
454 | " } catch (e) {\n",
455 | " console.log(\"No handler for the '\" + msg_type + \"' message type: \", msg);\n",
456 | " return;\n",
457 | " }\n",
458 | "\n",
459 | " if (callback) {\n",
460 | " try {\n",
461 | " // console.log(\"Handling '\" + msg_type + \"' message: \", msg);\n",
462 | " callback(fig, msg);\n",
463 | " } catch (e) {\n",
464 | " console.log(\"Exception inside the 'handler_\" + msg_type + \"' callback:\", e, e.stack, msg);\n",
465 | " }\n",
466 | " }\n",
467 | " };\n",
468 | "}\n",
469 | "\n",
470 | "// from http://stackoverflow.com/questions/1114465/getting-mouse-location-in-canvas\n",
471 | "mpl.findpos = function(e) {\n",
472 | " //this section is from http://www.quirksmode.org/js/events_properties.html\n",
473 | " var targ;\n",
474 | " if (!e)\n",
475 | " e = window.event;\n",
476 | " if (e.target)\n",
477 | " targ = e.target;\n",
478 | " else if (e.srcElement)\n",
479 | " targ = e.srcElement;\n",
480 | " if (targ.nodeType == 3) // defeat Safari bug\n",
481 | " targ = targ.parentNode;\n",
482 | "\n",
483 | " // jQuery normalizes the pageX and pageY\n",
484 | " // pageX,Y are the mouse positions relative to the document\n",
485 | " // offset() returns the position of the element relative to the document\n",
486 | " var x = e.pageX - $(targ).offset().left;\n",
487 | " var y = e.pageY - $(targ).offset().top;\n",
488 | "\n",
489 | " return {\"x\": x, \"y\": y};\n",
490 | "};\n",
491 | "\n",
492 | "/*\n",
493 | " * return a copy of an object with only non-object keys\n",
494 | " * we need this to avoid circular references\n",
495 | " * http://stackoverflow.com/a/24161582/3208463\n",
496 | " */\n",
497 | "function simpleKeys (original) {\n",
498 | " return Object.keys(original).reduce(function (obj, key) {\n",
499 | " if (typeof original[key] !== 'object')\n",
500 | " obj[key] = original[key]\n",
501 | " return obj;\n",
502 | " }, {});\n",
503 | "}\n",
504 | "\n",
505 | "mpl.figure.prototype.mouse_event = function(event, name) {\n",
506 | " var canvas_pos = mpl.findpos(event)\n",
507 | "\n",
508 | " if (name === 'button_press')\n",
509 | " {\n",
510 | " this.canvas.focus();\n",
511 | " this.canvas_div.focus();\n",
512 | " }\n",
513 | "\n",
514 | " var x = canvas_pos.x;\n",
515 | " var y = canvas_pos.y;\n",
516 | "\n",
517 | " this.send_message(name, {x: x, y: y, button: event.button,\n",
518 | " step: event.step,\n",
519 | " guiEvent: simpleKeys(event)});\n",
520 | "\n",
521 | " /* This prevents the web browser from automatically changing to\n",
522 | " * the text insertion cursor when the button is pressed. We want\n",
523 | " * to control all of the cursor setting manually through the\n",
524 | " * 'cursor' event from matplotlib */\n",
525 | " event.preventDefault();\n",
526 | " return false;\n",
527 | "}\n",
528 | "\n",
529 | "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
530 | " // Handle any extra behaviour associated with a key event\n",
531 | "}\n",
532 | "\n",
533 | "mpl.figure.prototype.key_event = function(event, name) {\n",
534 | "\n",
535 | " // Prevent repeat events\n",
536 | " if (name == 'key_press')\n",
537 | " {\n",
538 | " if (event.which === this._key)\n",
539 | " return;\n",
540 | " else\n",
541 | " this._key = event.which;\n",
542 | " }\n",
543 | " if (name == 'key_release')\n",
544 | " this._key = null;\n",
545 | "\n",
546 | " var value = '';\n",
547 | " if (event.ctrlKey && event.which != 17)\n",
548 | " value += \"ctrl+\";\n",
549 | " if (event.altKey && event.which != 18)\n",
550 | " value += \"alt+\";\n",
551 | " if (event.shiftKey && event.which != 16)\n",
552 | " value += \"shift+\";\n",
553 | "\n",
554 | " value += 'k';\n",
555 | " value += event.which.toString();\n",
556 | "\n",
557 | " this._key_event_extra(event, name);\n",
558 | "\n",
559 | " this.send_message(name, {key: value,\n",
560 | " guiEvent: simpleKeys(event)});\n",
561 | " return false;\n",
562 | "}\n",
563 | "\n",
564 | "mpl.figure.prototype.toolbar_button_onclick = function(name) {\n",
565 | " if (name == 'download') {\n",
566 | " this.handle_save(this, null);\n",
567 | " } else {\n",
568 | " this.send_message(\"toolbar_button\", {name: name});\n",
569 | " }\n",
570 | "};\n",
571 | "\n",
572 | "mpl.figure.prototype.toolbar_button_onmouseover = function(tooltip) {\n",
573 | " this.message.textContent = tooltip;\n",
574 | "};\n",
575 | "mpl.toolbar_items = [[\"Home\", \"Reset original view\", \"fa fa-home icon-home\", \"home\"], [\"Back\", \"Back to previous view\", \"fa fa-arrow-left icon-arrow-left\", \"back\"], [\"Forward\", \"Forward to next view\", \"fa fa-arrow-right icon-arrow-right\", \"forward\"], [\"\", \"\", \"\", \"\"], [\"Pan\", \"Pan axes with left mouse, zoom with right\", \"fa fa-arrows icon-move\", \"pan\"], [\"Zoom\", \"Zoom to rectangle\", \"fa fa-square-o icon-check-empty\", \"zoom\"], [\"\", \"\", \"\", \"\"], [\"Download\", \"Download plot\", \"fa fa-floppy-o icon-save\", \"download\"]];\n",
576 | "\n",
577 | "mpl.extensions = [\"eps\", \"jpeg\", \"pdf\", \"png\", \"ps\", \"raw\", \"svg\", \"tif\"];\n",
578 | "\n",
579 | "mpl.default_extension = \"png\";var comm_websocket_adapter = function(comm) {\n",
580 | " // Create a \"websocket\"-like object which calls the given IPython comm\n",
581 | " // object with the appropriate methods. Currently this is a non binary\n",
582 | " // socket, so there is still some room for performance tuning.\n",
583 | " var ws = {};\n",
584 | "\n",
585 | " ws.close = function() {\n",
586 | " comm.close()\n",
587 | " };\n",
588 | " ws.send = function(m) {\n",
589 | " //console.log('sending', m);\n",
590 | " comm.send(m);\n",
591 | " };\n",
592 | " // Register the callback with on_msg.\n",
593 | " comm.on_msg(function(msg) {\n",
594 | " //console.log('receiving', msg['content']['data'], msg);\n",
595 | " // Pass the mpl event to the overriden (by mpl) onmessage function.\n",
596 | " ws.onmessage(msg['content']['data'])\n",
597 | " });\n",
598 | " return ws;\n",
599 | "}\n",
600 | "\n",
601 | "mpl.mpl_figure_comm = function(comm, msg) {\n",
602 | " // This is the function which gets called when the mpl process\n",
603 | " // starts-up an IPython Comm through the \"matplotlib\" channel.\n",
604 | "\n",
605 | " var id = msg.content.data.id;\n",
606 | " // Get hold of the div created by the display call when the Comm\n",
607 | " // socket was opened in Python.\n",
608 | " var element = $(\"#\" + id);\n",
609 | " var ws_proxy = comm_websocket_adapter(comm)\n",
610 | "\n",
611 | " function ondownload(figure, format) {\n",
612 | " window.open(figure.imageObj.src);\n",
613 | " }\n",
614 | "\n",
615 | " var fig = new mpl.figure(id, ws_proxy,\n",
616 | " ondownload,\n",
617 | " element.get(0));\n",
618 | "\n",
619 | " // Call onopen now - mpl needs it, as it is assuming we've passed it a real\n",
620 | " // web socket which is closed, not our websocket->open comm proxy.\n",
621 | " ws_proxy.onopen();\n",
622 | "\n",
623 | " fig.parent_element = element.get(0);\n",
624 | " fig.cell_info = mpl.find_output_cell(\"\");\n",
625 | " if (!fig.cell_info) {\n",
626 | " console.error(\"Failed to find cell for figure\", id, fig);\n",
627 | " return;\n",
628 | " }\n",
629 | "\n",
630 | " var output_index = fig.cell_info[2]\n",
631 | " var cell = fig.cell_info[0];\n",
632 | "\n",
633 | "};\n",
634 | "\n",
635 | "mpl.figure.prototype.handle_close = function(fig, msg) {\n",
636 | " fig.root.unbind('remove')\n",
637 | "\n",
638 | " // Update the output cell to use the data from the current canvas.\n",
639 | " fig.push_to_output();\n",
640 | " var dataURL = fig.canvas.toDataURL();\n",
641 | " // Re-enable the keyboard manager in IPython - without this line, in FF,\n",
642 | " // the notebook keyboard shortcuts fail.\n",
643 | " IPython.keyboard_manager.enable()\n",
644 | " $(fig.parent_element).html('
');\n",
645 | " fig.close_ws(fig, msg);\n",
646 | "}\n",
647 | "\n",
648 | "mpl.figure.prototype.close_ws = function(fig, msg){\n",
649 | " fig.send_message('closing', msg);\n",
650 | " // fig.ws.close()\n",
651 | "}\n",
652 | "\n",
653 | "mpl.figure.prototype.push_to_output = function(remove_interactive) {\n",
654 | " // Turn the data on the canvas into data in the output cell.\n",
655 | " var dataURL = this.canvas.toDataURL();\n",
656 | " this.cell_info[1]['text/html'] = '
';\n",
657 | "}\n",
658 | "\n",
659 | "mpl.figure.prototype.updated_canvas_event = function() {\n",
660 | " // Tell IPython that the notebook contents must change.\n",
661 | " IPython.notebook.set_dirty(true);\n",
662 | " this.send_message(\"ack\", {});\n",
663 | " var fig = this;\n",
664 | " // Wait a second, then push the new image to the DOM so\n",
665 | " // that it is saved nicely (might be nice to debounce this).\n",
666 | " setTimeout(function () { fig.push_to_output() }, 1000);\n",
667 | "}\n",
668 | "\n",
669 | "mpl.figure.prototype._init_toolbar = function() {\n",
670 | " var fig = this;\n",
671 | "\n",
672 | " var nav_element = $('')\n",
673 | " nav_element.attr('style', 'width: 100%');\n",
674 | " this.root.append(nav_element);\n",
675 | "\n",
676 | " // Define a callback function for later on.\n",
677 | " function toolbar_event(event) {\n",
678 | " return fig.toolbar_button_onclick(event['data']);\n",
679 | " }\n",
680 | " function toolbar_mouse_event(event) {\n",
681 | " return fig.toolbar_button_onmouseover(event['data']);\n",
682 | " }\n",
683 | "\n",
684 | " for(var toolbar_ind in mpl.toolbar_items){\n",
685 | " var name = mpl.toolbar_items[toolbar_ind][0];\n",
686 | " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n",
687 | " var image = mpl.toolbar_items[toolbar_ind][2];\n",
688 | " var method_name = mpl.toolbar_items[toolbar_ind][3];\n",
689 | "\n",
690 | " if (!name) { continue; };\n",
691 | "\n",
692 | " var button = $('');\n",
693 | " button.click(method_name, toolbar_event);\n",
694 | " button.mouseover(tooltip, toolbar_mouse_event);\n",
695 | " nav_element.append(button);\n",
696 | " }\n",
697 | "\n",
698 | " // Add the status bar.\n",
699 | " var status_bar = $('');\n",
700 | " nav_element.append(status_bar);\n",
701 | " this.message = status_bar[0];\n",
702 | "\n",
703 | " // Add the close button to the window.\n",
704 | " var buttongrp = $('');\n",
705 | " var button = $('');\n",
706 | " button.click(function (evt) { fig.handle_close(fig, {}); } );\n",
707 | " button.mouseover('Stop Interaction', toolbar_mouse_event);\n",
708 | " buttongrp.append(button);\n",
709 | " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n",
710 | " titlebar.prepend(buttongrp);\n",
711 | "}\n",
712 | "\n",
713 | "mpl.figure.prototype._root_extra_style = function(el){\n",
714 | " var fig = this\n",
715 | " el.on(\"remove\", function(){\n",
716 | "\tfig.close_ws(fig, {});\n",
717 | " });\n",
718 | "}\n",
719 | "\n",
720 | "mpl.figure.prototype._canvas_extra_style = function(el){\n",
721 | " // this is important to make the div 'focusable\n",
722 | " el.attr('tabindex', 0)\n",
723 | " // reach out to IPython and tell the keyboard manager to turn it's self\n",
724 | " // off when our div gets focus\n",
725 | "\n",
726 | " // location in version 3\n",
727 | " if (IPython.notebook.keyboard_manager) {\n",
728 | " IPython.notebook.keyboard_manager.register_events(el);\n",
729 | " }\n",
730 | " else {\n",
731 | " // location in version 2\n",
732 | " IPython.keyboard_manager.register_events(el);\n",
733 | " }\n",
734 | "\n",
735 | "}\n",
736 | "\n",
737 | "mpl.figure.prototype._key_event_extra = function(event, name) {\n",
738 | " var manager = IPython.notebook.keyboard_manager;\n",
739 | " if (!manager)\n",
740 | " manager = IPython.keyboard_manager;\n",
741 | "\n",
742 | " // Check for shift+enter\n",
743 | " if (event.shiftKey && event.which == 13) {\n",
744 | " this.canvas_div.blur();\n",
745 | " event.shiftKey = false;\n",
746 | " // Send a \"J\" for go to next cell\n",
747 | " event.which = 74;\n",
748 | " event.keyCode = 74;\n",
749 | " manager.command_mode();\n",
750 | " manager.handle_keydown(event);\n",
751 | " }\n",
752 | "}\n",
753 | "\n",
754 | "mpl.figure.prototype.handle_save = function(fig, msg) {\n",
755 | " fig.ondownload(fig, null);\n",
756 | "}\n",
757 | "\n",
758 | "\n",
759 | "mpl.find_output_cell = function(html_output) {\n",
760 | " // Return the cell and output element which can be found *uniquely* in the notebook.\n",
761 | " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n",
762 | " // IPython event is triggered only after the cells have been serialised, which for\n",
763 | " // our purposes (turning an active figure into a static one), is too late.\n",
764 | " var cells = IPython.notebook.get_cells();\n",
765 | " var ncells = cells.length;\n",
766 | " for (var i=0; i= 3 moved mimebundle to data attribute of output\n",
773 | " data = data.data;\n",
774 | " }\n",
775 | " if (data['text/html'] == html_output) {\n",
776 | " return [cell, data, j];\n",
777 | " }\n",
778 | " }\n",
779 | " }\n",
780 | " }\n",
781 | "}\n",
782 | "\n",
783 | "// Register the function which deals with the matplotlib target/channel.\n",
784 | "// The kernel may be null if the page has been refreshed.\n",
785 | "if (IPython.notebook.kernel != null) {\n",
786 | " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n",
787 | "}\n"
788 | ],
789 | "text/plain": [
790 | ""
791 | ]
792 | },
793 | "metadata": {},
794 | "output_type": "display_data"
795 | },
796 | {
797 | "data": {
798 | "text/html": [
799 | "
"
800 | ],
801 | "text/plain": [
802 | ""
803 | ]
804 | },
805 | "metadata": {},
806 | "output_type": "display_data"
807 | }
808 | ],
809 | "source": [
810 | "omega = 32\n",
811 | "ecc = 0.5\n",
812 | "\n",
813 | "T0 = 0\n",
814 | "Porb = 2.5\n",
815 | "aSini = 23\n",
816 | "inclination = 0\n",
817 | "\n",
818 | "p_spin = 1.37\n",
819 | "\n",
820 | "c = 3e10\n",
821 | "\n",
822 | "ke = pyasl.KeplerEllipse(aSini, Porb * 86400, e=ecc, Omega=0, i=inclination, w=omega)\n",
823 | "\n",
824 | "t = np.arange(0, 10, 0.001) * 86400\n",
825 | "pos = ke.xyzPos(t)\n",
826 | "radius = ke.radius(t)\n",
827 | "# Radial velocity\n",
828 | "vel = ke.xyzVel(t)\n",
829 | "\n",
830 | "tminvel = t[np.argmin(vel[::,1])]\n",
831 | "tmaxvel = t[np.argmax(vel[::,1])]\n",
832 | "velmin = vel[::,1][np.argmin(vel[::,1])]\n",
833 | "velmax = vel[::,1][np.argmax(vel[::,1])]\n",
834 | "# Find the nodes of the orbit (Observer at -z)\n",
835 | "\n",
836 | "posmin = ke.xyzPos(tminvel)\n",
837 | "posmax = ke.xyzPos(tmaxvel)\n",
838 | "\n",
839 | "# ascn, descn = ke.xyzNodes_LOSZ()\n",
840 | "\n",
841 | "# Plot x and y coordinates of the orbit\n",
842 | "plt.figure(figsize=(10, 15))\n",
843 | "gs = GridSpec(2, 1, height_ratios=(11, 5))\n",
844 | "ax0 = plt.subplot(gs[0])\n",
845 | "ax1 = plt.subplot(gs[1])\n",
846 | "# plt.title(\"Periapsis (red diamond), Asc. node (green circle), desc. node (red circle)\")\n",
847 | "ax0.set_ylabel(\"<- Observer\")\n",
848 | "ax0.plot([0], [0], 'k+', markersize=9)\n",
849 | "ax0.plot(pos[::,0], pos[::,1], 'b-')\n",
850 | "\n",
851 | "ax0.scatter(posmin[0], posmin[1])\n",
852 | "ax0.scatter(posmax[0], posmax[1])\n",
853 | "# Point of periapsis\n",
854 | "ax0.plot([pos[0,0]], [pos[0,1]], 'rd')\n",
855 | "# Nodes of the orbit\n",
856 | "ax0.plot([posmin[0]], [posmin[1]], 'go', markersize=10)\n",
857 | "ax0.plot([posmax[0]], [posmax[1]], 'ro', markersize=10)\n",
858 | "\n",
859 | "plot_dim = np.max(np.abs(pos))\n",
860 | "ax0.set_xlim([-plot_dim, plot_dim])\n",
861 | "ax0.set_ylim([-plot_dim, plot_dim])\n",
862 | "# Plot RV\n",
863 | "ax1.set_xlabel(\"Time\")\n",
864 | "ax1.set_ylabel(\"Radial velocity [length/time]\")\n",
865 | "ax1.plot(t, vel[::,1], 'r.-')\n",
866 | "ax1.plot([tminvel], [velmin], 'go', markersize=10)\n",
867 | "ax1.plot([tmaxvel], [velmax], 'ro', markersize=10)\n",
868 | "plt.show()"
869 | ]
870 | },
871 | {
872 | "cell_type": "code",
873 | "execution_count": null,
874 | "metadata": {
875 | "collapsed": true
876 | },
877 | "outputs": [],
878 | "source": []
879 | }
880 | ],
881 | "metadata": {
882 | "kernelspec": {
883 | "display_name": "Python 3",
884 | "language": "python",
885 | "name": "python3"
886 | },
887 | "language_info": {
888 | "codemirror_mode": {
889 | "name": "ipython",
890 | "version": 3
891 | },
892 | "file_extension": ".py",
893 | "mimetype": "text/x-python",
894 | "name": "python",
895 | "nbconvert_exporter": "python",
896 | "pygments_lexer": "ipython3",
897 | "version": "3.4.4"
898 | }
899 | },
900 | "nbformat": 4,
901 | "nbformat_minor": 0
902 | }
903 |
--------------------------------------------------------------------------------
/License.md:
--------------------------------------------------------------------------------
1 | ## License
2 |
3 | IPython source code and examples are licensed under the terms of the 3-clause BSD license, as follows:
4 |
5 | Copyright (c) 2016, Matteo Bachetti
6 | All rights reserved.
7 |
8 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9 |
10 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
11 |
12 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
13 |
14 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17 |
18 |
19 | Documentation, examples and other materials are licensed under the terms of the [Creative Commons Attribution 4.0 International (CC BY 4.0) license](http://creativecommons.org/licenses/by/4.0/)
20 |
--------------------------------------------------------------------------------
/QPO_NS_BH.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matteobachetti/timing-lectures/820f14edd68e3495546c77131009837ed895040b/QPO_NS_BH.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Timing lectures #
2 |
3 | [](http://mybinder.org/repo/matteobachetti/timing-lectures)
4 |
5 | This is a work-in-progress repository of my [timing lectures](http://www.matteobachetti.it/Varie/Timing).
6 |
7 | Lectures follow an iPython notebook where I give the relevant "vocabulary" and I explain the concepts by simulating and analyzing data. This iPython notebook can be downloaded and students can play around with it, inspecting, modifying and re-running all the code in order to get a better grip on the concepts explained in the lectures.
8 |
9 | ## Install requirements and download
10 | First of all, install Python and iPython.
11 | There are many ways to do it in each architecture. One possible easy way to get up and running quickly with Python is to [follow the instructions here](http://ipython.org/install.html).
12 |
13 | The presentation and all material in this "Timing lectures" web page is maintained as a git repository, so first of all [install git](http://git-scm.com). On Unix-like machines, this is very simple. It is generally just a matter of
14 | ```
15 | #!console
16 | $ sudo packagemanager install git
17 | ```
18 | where _packagemanager_ can be apt-get, yum, fink, brew, port, or whatever package manager you use in your machine.
19 |
20 | Then clone the repository with
21 | ```
22 | #!console
23 | $ git clone git@bitbucket.org:mbachett/timing-lectures.git
24 | ```
25 | # Run
26 | Go to the directory timing-lectures you just downloaded, then run
27 | ```
28 | #!console
29 | $ ipython notebook
30 | ```
31 | This will open a web browser page like this:
32 | 
33 |
34 | Just click on 'Pulsar_Timing.ipynb'. This will open the notebook:
35 | 
36 |
37 | From here you can change all the code and make experiments. You can still run the notebook as a presentation by giving the following command in your terminal:
38 | ```
39 | #!console
40 | $ ipython nbconvert Pulsar_Timing.ipynb --to slides --config slides_config.py --post serve
41 | ```
42 |
--------------------------------------------------------------------------------
/buriedclock.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matteobachetti/timing-lectures/820f14edd68e3495546c77131009837ed895040b/buriedclock.jpg
--------------------------------------------------------------------------------
/modeling_tutorial_mcmc_corner.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matteobachetti/timing-lectures/820f14edd68e3495546c77131009837ed895040b/modeling_tutorial_mcmc_corner.pdf
--------------------------------------------------------------------------------
/no-binder/Timing_Mainstream_Software.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# A (simplified) search with mainstream software\n",
8 | "\n",
9 | "In this tutorial, we will run a full search for pulsations in real data and obtain the orbital solution of an unknown binary pulsar.\n",
10 | "\n"
11 | ]
12 | },
13 | {
14 | "cell_type": "markdown",
15 | "metadata": {},
16 | "source": [
17 | "## Exercise 1: low-DM pulsar\n",
18 | "\n",
19 | "Enter the directory `data/lowdm`\n",
20 | "\n",
21 | "```\n",
22 | "$ cd data/lowdm\n",
23 | "```\n",
24 | "\n",
25 | "You will find a file named `guppi_55757_B1508+55_0004_0001.fil`. The source in these data is a very well-known pulsar, B1508+55, with a sharp profile and low dispersion measure. Data were collected with the [Green Bank Telescope](https://science.nrao.edu/facilities/gbt/), at 820 Hz, with a total band of 200 MHz split in 1024 channels.\n",
26 | "\n",
27 | "For a rough periodicity search, we do not need all this information. Therefore, as a first step we sum up all these data in a single channel.\n",
28 | "\n",
29 | "```\n",
30 | "$ prepdata guppi_55757_B1508+55_0004_0001.fil -o 1508\n",
31 | "```\n",
32 | "This will create two files: `1508.dat`, containing the light curve, and `1508.inf`, a text file with some information about the observation. Let us see what the Fourier transform (see first lesson, this is actually the absolute value of the Fourier transform, or the square root of the PDS) looks like.\n",
33 | "\n",
34 | "```\n",
35 | "$ realfft 1508.dat\n",
36 | "$ explorefft 1508.fft\n",
37 | "\n",
38 | "\n",
39 | " Interactive FFT Explorer\n",
40 | " by Scott M. Ransom\n",
41 | " October, 2001\n",
42 | "\n",
43 | " Button or Key Effect\n",
44 | " ------------- ------\n",
45 | " Left Mouse or I Zoom in by a factor of 2\n",
46 | " Right Mouse or O Zoom out by a factor of 2\n",
47 | " Middle Mouse or D Show details about a selected frequency\n",
48 | " < Shift left by a full screen width\n",
49 | " > Shift right by a full screen width\n",
50 | " , Shift left by 1/8 of the screen width\n",
51 | " . Shift right by 1/8 of the screen width\n",
52 | " + or = Increase the power scale (make them taller)\n",
53 | " - or _ Decrease the power scale (make them shorter)\n",
54 | " S Scale the powers automatically\n",
55 | " N Re-normalize the nowers by one of several methods\n",
56 | " P Print the current plot to a file\n",
57 | " G Go to a specified frequency\n",
58 | " L Load a zaplist showing potential RFI locations\n",
59 | " Z Add a frequency chunk to the RFI zaplist\n",
60 | " H Show the harmonics of the center frequency\n",
61 | " ? Show this help screen\n",
62 | " Q Quit\n",
63 | "\n",
64 | "Examining B1508+55 data from '1508.fft'.\n",
65 | "\n",
66 | "Memory mapping the input FFT. This may take a while...\n",
67 | "\n",
68 | "```\n",
69 | "The second command will open a PGPLOT window where you will be able to zoom and look at all the periodicities contained in the data. The mouse and keyboard keys to touch to perform the various actions (zoom, scroll, etc) are listed in the terminal.\n",
70 | "\n",
71 | "You will notice that the fundamental frequency of the pulsation (~5 Hz) is not the most prominent peak in the FT. This is due to the shape of the pulse.\n",
72 | "Now, we can use a program that automatically looks at the FT and performs quality checks of the signals contained in it, ranking them (ignore the `-zmax` switch for now, we do that to limit the search to the routine methods and not the advanced ones).\n",
73 | "\n",
74 | "```\n",
75 | "$ accelsearch 1508.fft -zmax 0 -numharm 16\n",
76 | "```\n",
77 | "\n",
78 | "\n",
79 | "```\n",
80 | "prepfold -accelcand 1 -accelfile 1508_ACCEL_0.cand guppi_55757_B1508+55_0004_0001.fil\n",
81 | "```\n",
82 | "\n",
83 | "\n",
84 | ""
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {},
90 | "source": [
91 | "## Exercise 2: high-DM pulsar\n",
92 | "\n",
93 | "\n",
94 | "*TBD*"
95 | ]
96 | },
97 | {
98 | "cell_type": "markdown",
99 | "metadata": {},
100 | "source": [
101 | "## Exercise 3: binary pulsar.\n",
102 | "\n",
103 | "In the directory `data/split` you will find 20 observations, 3 ks each, of a simulated binary pulsar.\n",
104 | "\n",
105 | "### 3.1 Finding the local period and pdot in each observation\n",
106 | "\n",
107 | "We start from an estimate of the period: 0.05124 s. We run an accelerated epoch folding search in each file around this period. The switch `-p` suggests a starting period for the search; `-mjds -events -double` are there only because of the format of the data; `-npfact 10` extends the range of periods and pdots we will be using for the search by a factor 10.\n",
108 | "```\n",
109 | "$ prepfold psr_0.events -p 0.05124 -mjds -events -double -npfact 10\n",
110 | "$ prepfold psr_1.events -p 0.05124 -mjds -events -double -npfact 10\n",
111 | "(...)\n",
112 | "```\n",
113 | "or, to make it quick,\n",
114 | "```\n",
115 | "$ for i in psr_*.events; do prepfold $i -p 0.05124 -mjds -events -double -npfact 10; done\n",
116 | "```\n",
117 | "\n",
118 | "\n"
119 | ]
120 | },
121 | {
122 | "cell_type": "markdown",
123 | "metadata": {},
124 | "source": [
125 | "### 3.2. Approximate values for the orbital modulation\n",
126 | "Plot the best solutions seen so far (`-pb 1 -T0 0 -x 1` is just telling `fitorb.py` to use those starting values for the orbital period, the ascending node passage and the projected semi-major axis respectively.):\n",
127 | "```\n",
128 | "$ fitorb.py psr*.bestprof -p 0.05124 -pb 1 -T0 0 -x 1\n",
129 | "```\n",
130 | "We see a modulation with a period of ~2.3 days. Let's play using different starting values for the parameters until the fit of the parameters is good. `fitorb.py` outputs a series of parameters like\n",
131 | "```\n",
132 | "PEPOCH 49354.042438\n",
133 | "P0 0.0512450030268001\n",
134 | "BINARY BT\n",
135 | "A1 5.00038618340817\n",
136 | "E 0\n",
137 | "T0 -0.469972316212605\n",
138 | "PB 2.30000329860082\n",
139 | "OM 0\n",
140 | "``` \n",
141 | "Let us copy and paste this output to a new file called `fit.par`."
142 | ]
143 | },
144 | {
145 | "cell_type": "markdown",
146 | "metadata": {},
147 | "source": [
148 | "### 3.3a. \"Freezing\" the local solutions\n",
149 | "**Attention**: This step is overly complicated (having to use different approximate parameter files for each chunk, instead of the approximate orbital solution found above for all) because of a bug in PRESTO. I filed an Issue to try to correct it.\n",
150 | "\n",
151 | "To calculate TOAs, PRESTO wants bestprofs obtained without searching. So, we have to rerun `prepfold` giving it already the best parameters found in the previous search, and telling it not to perform additional searches. This can be done in many ways. \n",
152 | "\n",
153 | "1. Easy but possibly inconsistent(?)\n",
154 | "One is to read in each bestprof the lines\n",
155 | "```\n",
156 | "# P_bary (ms) = 51.240437722057 +/- 1.25e-06\n",
157 | "# P'_bary (s/s) = 2.33518439161511e-10 +/- 3.24e-12\n",
158 | "# P''_bary (s/s^2) = 0 +/- 7e-15\n",
159 | "```\n",
160 | "and calling `prepfold` with the options\n",
161 | "```\n",
162 | "$ prepfold psr_0.events -p 0.051240437722057 -pdot 2.33518439161511e-10 -pddot 0 -nosearch -mjds -events -double -npfact 10\n",
163 | "```\n",
164 | "The drawback of this option is that _some .bestprof files will be overwritten, others not_ (because of how the period is used in the file name), and it will be more difficult \n",
165 | "\n",
166 | "2. Slightly trickier, but surely consistent\n",
167 | "In step 1 we obtained local best values for $p$, $\\dot{p}$ and $\\ddot{p}$ in each observation. For each observation file, we have a corresponding file that ends in `.bestprof` and contains these best values. For each of these local solutions, we create a file with the same name but extension `.par`, copying the values of each parameter and converting to the relevant units, as follows:\n",
168 | "\\begin{align}\n",
169 | "\\nu &= \\frac{1}{p} \\\\\n",
170 | "\\dot{\\nu} &= -\\frac{1}{p^2}\\dot{p} \\\\\n",
171 | "\\ddot{\\nu} &= \\frac{2}{p^3}\\dot{p} - \\frac{1}{p^2}\\ddot{p} \\\\\n",
172 | "\\end{align}\n",
173 | "So, the parameter file will look like\n",
174 | "```\n",
175 | "PSRJ FAKE # Just any name, but it must be here!\n",
176 | "PEPOCH 49353.232270000000 # In the bestprof: Epoch_bary (MJD) = 49353.232270000000\n",
177 | "F0 0.051251497947019 # Convert to Hz the line \n",
178 | " # P_bary (ms) = 51.251497947019 +/- 1.39e-06 \n",
179 | "F1 4.46613404291e-08 # Convert to Hz/s the period line plus \n",
180 | " # P'_bary (s/s) = -1.17312659353888e-10 +/- 3.44e-12 \n",
181 | "F2 2.0445609693e-16 # Convert to Hz/s^2 the period and pdot lines, plus\n",
182 | " # P''_bary (s/s^2) = 0 +/- 7.44e-15\n",
183 | "```\n",
184 | "Refold, this time with the `-timing` option\n",
185 | "```\n",
186 | "$ prepfold psr_0.events -timing psr_0_51.24ms_Cand.pfd.par -mjds -events -double\n",
187 | "$ prepfold psr_1.events -timing psr_1_51.24ms_Cand.pfd.par -mjds -events -double\n",
188 | "(...)\n",
189 | "```\n",
190 | "or, more rapidly\n",
191 | "```\n",
192 | "$ for i in psr*.events; do bestprof=\\${i/.events/}*.bestprof; echo $bestprof ; \\\n",
193 | " prepfold $i -timing ${bestprof/.bestprof/.par} -mjds -events -double; done\n",
194 | "```"
195 | ]
196 | },
197 | {
198 | "cell_type": "markdown",
199 | "metadata": {},
200 | "source": [
201 | "### 3.3b. Calculate TOAs\n",
202 | "Now, to calculate TOAs we use the `get_TOA.py` script in PRESTO, with the following syntax\n",
203 | "```\n",
204 | "get_TOAs.py -n 1 -e -g 0.2 psr_1_PSR_FAKE.pfd.par\n",
205 | "```\n",
206 | "`-n 1` says that we are calculating one TOA per file; `-e` is again related to the original file format; `-g 0.2` means to use a Gaussian with width 0.2.\n",
207 | "The TOAs will be printed in the screen:\n",
208 | "```\n",
209 | "$ get_TOAs.py -n 1 -e -g 0.2 psr_0_PSR_51.24.pfd\n",
210 | "/psr/Soft/presto/lib/python/psr_utils.py:669: RuntimeWarning: invalid value encountered in divide\n",
211 | " DM/(0.000241*freq_emitted*freq_emitted), 0.0)\n",
212 | "@ 0.000 49353.0180863062417 1785.39\n",
213 | "```\n",
214 | "You can ignore the first warning message. Beware, instead, of error or warning messages about FFTFIT failing to do something. They often mean that you have bad statistics in your data or the template you chose is not adequate.\n",
215 | "Copy all lines starting by \"@\" to a file called `all.tim`"
216 | ]
217 | },
218 | {
219 | "cell_type": "markdown",
220 | "metadata": {},
221 | "source": [
222 | "### 3.4. Refine the solution with Tempo2\n",
223 | "\n",
224 | "*TBD*"
225 | ]
226 | }
227 | ],
228 | "metadata": {
229 | "kernelspec": {
230 | "display_name": "Python 3",
231 | "language": "python",
232 | "name": "python3"
233 | },
234 | "language_info": {
235 | "codemirror_mode": {
236 | "name": "ipython",
237 | "version": 3
238 | },
239 | "file_extension": ".py",
240 | "mimetype": "text/x-python",
241 | "name": "python",
242 | "nbconvert_exporter": "python",
243 | "pygments_lexer": "ipython3",
244 | "version": "3.4.3"
245 | }
246 | },
247 | "nbformat": 4,
248 | "nbformat_minor": 0
249 | }
250 |
--------------------------------------------------------------------------------
/oh_deer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matteobachetti/timing-lectures/820f14edd68e3495546c77131009837ed895040b/oh_deer.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | maltpynt>=2.0b0
2 | PyAstronomy
3 |
--------------------------------------------------------------------------------
/smallmodpulsar.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/matteobachetti/timing-lectures/820f14edd68e3495546c77131009837ed895040b/smallmodpulsar.gif
--------------------------------------------------------------------------------