{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Fitting a real point source\n", "\n", "_Weights used:_\n", "* Spatial\n", "* Spectral\n", "\n", "This jupyter notebook fits for the phase-averaged polarization of the point source GX 301-2, observed with observation ID 01002601. Please refer to the previous notebook for help downloading and processing this data set." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[93m>>> PyXSPEC is not installed, you will no be able to use it.\u001b[0m\n" ] } ], "source": [ "import leakagelib" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Performing a polarization fit to these data is almost identical to the steps we performed for the simulated source. The only difference is the command to load the data. Here we need to specify that the data is stored in the \"event_l2_weight\" directory (which we created in the previous notebook.)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ">>> Reading (in memory) /opt/homebrew/anaconda3/lib/python3.12/site-packages/ixpeobssim/caldb/ixpe/xrt/bcf/vign/ixpe_d2_obssim20240101_vign_v013.fits...\n", "WARNING: FITSFixedWarning: RADECSYS= 'ICRS ' / Celestial coordinate system \n", "the RADECSYS keyword is deprecated, use RADESYSa. [astropy.wcs.wcs]\n", "WARNING: FITSFixedWarning: 'datfix' made the change 'Set DATEREF to '2017-01-01T00:01:09.184' from MJDREF.\n", "Set MJD-OBS to 59789.109204 from DATE-OBS.\n", "Set MJD-END to 59794.248844 from DATE-END'. [astropy.wcs.wcs]\n", ">>> Reading (in memory) /opt/homebrew/anaconda3/lib/python3.12/site-packages/ixpeobssim/caldb/ixpe/xrt/bcf/vign/ixpe_d1_obssim20240101_vign_v013.fits...\n", ">>> Reading (in memory) /opt/homebrew/anaconda3/lib/python3.12/site-packages/ixpeobssim/caldb/ixpe/xrt/bcf/vign/ixpe_d3_obssim20240101_vign_v013.fits...\n" ] } ], "source": [ "datas = leakagelib.IXPEData.load_all_detectors_with_path(\"data\", \"01002601\", event_dir=\"event_l2_weight\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next we center the data and cut to 2-8 keV." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "for data in datas:\n", " data.iterative_centroid_center()\n", " data.retain(data.evt_energies > 2)\n", " data.retain(data.evt_energies < 8)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We create the same fit settings object as before, but this time skipping spectral weights for simplicity." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "59535 events were cut for being outside the region of interest.\n" ] } ], "source": [ "settings = leakagelib.FitSettings(datas)\n", "settings.apply_circular_roi(280)\n", "\n", "settings.add_point_source() # Named \"src\" by default\n", "settings.fix_flux(\"src\", 1)\n", "settings.set_initial_qu(\"src\", (0.5,0))\n", "\n", "settings.add_background() # Named \"bkg\" by default\n", "settings.set_initial_qu(\"bkg\", (0, 0)) # Assume an unpolarized background\n", "settings.set_initial_flux(\"bkg\", 0.1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we perform the fit." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Your data set has background characters assigned, but you did not add a particle component. Particles will not be modeled. Was this intentional?\n" ] }, { "data": { "text/plain": [ "FitResult:\n", "\tq (src) = 0.0032 +/- 0.0057\n", "\tu (src) = -0.0047 +/- 0.0057\n", "\tq (bkg) = -0.0009 +/- 0.0197\n", "\tu (bkg) = 0.0038 +/- 0.0197\n", "\tf (bkg) = 0.1461 +/- 0.0008\n", "\n", "Polarization:\n", "\tPD (src): 0.0057 +/- 0.0057\n", "\tPA (src): -27.8768 deg +/- 28.4854\n", "\tPD (bkg): 0.0039 +/- 0.0197\n", "\tPA (bkg): 51.5529 deg +/- 146.2607\n", "Likelihood 1332618.773507991, dof 447936\n", "Optimization terminated successfully." ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fitter = leakagelib.Fitter(settings)\n", "result = fitter.fit()\n", "result" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you see, this source has no detectable averaged polarization. The [original analysis](https://arxiv.org/pdf/2305.15309) also found no net polarization, though phase-resolved polarization was detected. This could be probed with LeakageLib as well using the `set_sweep` function (defined later).\n", "\n", "Note the warning \"Your data set has background characters assigned, but you did not add a particle component. Particles will not be modeled. Was this intentional?\". We can fix that warning by adding a particle weight component, described in the next notebook." ] } ], "metadata": { "kernelspec": { "display_name": "base", "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.12.2" } }, "nbformat": 4, "nbformat_minor": 2 }