{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# FRB example\n", "\n", "## v2 -- Using PATH object" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# imports\n", "from importlib import reload\n", "import os\n", "from pkg_resources import resource_filename\n", "\n", "import numpy as np\n", "\n", "import pandas\n", "\n", "from astropy.coordinates import SkyCoord\n", "#from astropy.io import fits\n", "\n", "from astropath import path\n", "from astropath import localization" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Dummy FRB (based on 180924)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Instantiate PATH" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "Path = path.PATH()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Localization" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Here is the full data model for the localization options" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'type': {'dtype': str,\n", " 'options': ['eellipse', 'wcs', 'healpix'],\n", " 'help': 'Localization type.'},\n", " 'center_coord': {'dtype': astropy.coordinates.sky_coordinate.SkyCoord,\n", " 'help': '\"Central\" coordinate'},\n", " 'eellipse': {'dtype': dict,\n", " 'help': 'Error ellipse with keys \"a [arcsec]\", \"b [arcsec]\", \"theta [deg]\"'},\n", " 'healpix_data': {'dtype': (numpy.ndarray, astropy.table.table.Table),\n", " 'help': 'Data containing the healpix information. Input either as a simple numpy array for a full NESTED array or an astropy Table for NUNIQ format with columns UNIQ and PROBDENSITY.'},\n", " 'healpix_nside': {'dtype': int, 'help': 'NSIDE value of healpix map.'},\n", " 'healpix_ordering': {'dtype': str,\n", " 'options': ['NESTED', 'NUNIQ'],\n", " 'help': 'Ordering of the healpix information.'},\n", " 'healpix_coord': {'dtype': str,\n", " 'options': ['C'],\n", " 'help': 'Coordinate system of the healpix.'},\n", " 'wcs_data': {'dtype': numpy.ndarray, 'help': 'PDF of localization.'},\n", " 'wcs_WCS': {'dtype': astropy.wcs.wcs.WCS, 'help': 'WCS of the localization.'}}" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "localization.localization_dmodel" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## We will use the Error Ellipse type" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## FRB Coord\n", "frb_coord = SkyCoord('21h44m25.255s -40d54m00.10s', frame='icrs')\n", "frb_coord" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Error ellipse" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "#eellipse = dict(a=0.3, b=0.1, theta=45.)\n", "#eellipse = dict(a=3, b=3, theta=90.)\n", "eellipse = dict(a=0.1, b=0.1, theta=0.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Set it" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "Path.init_localization('eellipse', center_coord=frb_coord, eellipse=eellipse)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'type': 'eellipse',\n", " 'center_coord': ,\n", " 'eellipse': {'a': 0.1, 'b': 0.1, 'theta': 0.0}}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Path.localiz" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Candidates" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "cand_file = os.path.join(resource_filename('astropath', 'data'), 'frb_example', 'frb180924_candidates.csv')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
radechalf_lightVLT_FORS2_g
3326.101738-40.8997710.45886925.295416
7326.105365-40.9002391.30862921.319569
8326.104186-40.9001800.81468324.272838
9326.106237-40.8992790.50124725.474828
\n", "
" ], "text/plain": [ " ra dec half_light VLT_FORS2_g\n", "3 326.101738 -40.899771 0.458869 25.295416\n", "7 326.105365 -40.900239 1.308629 21.319569\n", "8 326.104186 -40.900180 0.814683 24.272838\n", "9 326.106237 -40.899279 0.501247 25.474828" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "candidates = pandas.read_csv(cand_file, index_col=0)\n", "candidates.head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Init in PATH" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "Path.init_candidates(candidates.ra.values,\n", " candidates.dec.values,\n", " candidates.half_light.values,\n", " mag=candidates.VLT_FORS2_g.values)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
radecang_sizemag
0326.101738-40.8997710.45886925.295416
1326.105365-40.9002391.30862921.319569
2326.104186-40.9001800.81468324.272838
3326.106237-40.8992790.50124725.474828
\n", "
" ], "text/plain": [ " ra dec ang_size mag\n", "0 326.101738 -40.899771 0.458869 25.295416\n", "1 326.105365 -40.900239 1.308629 21.319569\n", "2 326.104186 -40.900180 0.814683 24.272838\n", "3 326.106237 -40.899279 0.501247 25.474828" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Path.candidates" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Priors" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Candidate prior" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "Path.init_cand_prior('inverse', P_U=0.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Offset prior" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "Path.init_theta_prior('exp', 6.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculate" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.0316325 , 0.87225473, 0.06831713, 0.02779563])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Path.calc_priors()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
radecang_sizemagP_O
0326.101738-40.8997710.45886925.2954160.031633
1326.105365-40.9002391.30862921.3195690.872255
2326.104186-40.9001800.81468324.2728380.068317
3326.106237-40.8992790.50124725.4748280.027796
\n", "
" ], "text/plain": [ " ra dec ang_size mag P_O\n", "0 326.101738 -40.899771 0.458869 25.295416 0.031633\n", "1 326.105365 -40.900239 1.308629 21.319569 0.872255\n", "2 326.104186 -40.900180 0.814683 24.272838 0.068317\n", "3 326.106237 -40.899279 0.501247 25.474828 0.027796" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Path.candidates" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Posteriors" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Calculate" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "P_Ox, P_Ux = Path.calc_posteriors('fixed', box_hwidth=30.)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Show" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
radecang_sizemagP_Op_xOP_Ox
0326.101738-40.8997710.45886925.2954160.0316330.000000e+000.000000e+00
1326.105365-40.9002391.30862921.3195690.8722555.156772e-029.895195e-01
2326.104186-40.9001800.81468324.2728380.0683176.973468e-031.048049e-02
3326.106237-40.8992790.50124725.4748280.0277969.296108e-205.684350e-20
\n", "
" ], "text/plain": [ " ra dec ang_size mag P_O p_xO \\\n", "0 326.101738 -40.899771 0.458869 25.295416 0.031633 0.000000e+00 \n", "1 326.105365 -40.900239 1.308629 21.319569 0.872255 5.156772e-02 \n", "2 326.104186 -40.900180 0.814683 24.272838 0.068317 6.973468e-03 \n", "3 326.106237 -40.899279 0.501247 25.474828 0.027796 9.296108e-20 \n", "\n", " P_Ox \n", "0 0.000000e+00 \n", "1 9.895195e-01 \n", "2 1.048049e-02 \n", "3 5.684350e-20 " ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Path.candidates" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.8" } }, "nbformat": 4, "nbformat_minor": 4 }