{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Fitting for variable sources\n", "\n", "_Weights used:_\n", "* Spatial\n", "* Temporal\n", "* Spectral\n", "\n", "This simulated example source is pulsed and has a sweeping PA. This notebook determines the PD and EVPA of the sweep." ] }, { "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 numpy as np\n", "import leakagelib" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We'll load the data as usual, and cut to within 280 arcsec of the center" ] }, { "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_d1_obssim20240101_vign_v013.fits...\n" ] } ], "source": [ "datas = leakagelib.IXPEData.load_all_detectors_with_path(\"data\", \"pulse\")\n", "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 plan to implement phase weights, but LeakageLib records times, not phases. You should calculate them yourself (e.g. with PINT, or load phases from a separate file), then replace the `evt_times` field with these phases. For this mock data, the frequency is exactly 10 Hz, so the phases are just $10 t$." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# WARNING: only run this box once.\n", "\n", "for data in datas:\n", " # It's convenient to overwrite the \"times\" list with a list of phases. This source sweeps with frequency of 10 Hz, so multiplying by 10 gives the phase\n", " data.evt_times *= 10\n", " data.evt_times = np.fmod(data.evt_times, 1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we create the point source and background sources as usual, setting their spectra. For this fit, we'll fix the background to be unpolarized." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "6462 events were cut for being outside the region of interest.\n", ">>> Reading (in memory) /opt/homebrew/anaconda3/lib/python3.12/site-packages/ixpeobssim/caldb/ixpe/gpd/cpf/arf/ixpe_d1_obssim20240101_v013.arf...\n", ">>> Using cached xEffectiveArea object at /opt/homebrew/anaconda3/lib/python3.12/site-packages/ixpeobssim/caldb/ixpe/gpd/cpf/arf/ixpe_d1_obssim20240101_v013.arf...\n" ] } ], "source": [ "settings = leakagelib.FitSettings(datas)\n", "settings.apply_circular_roi(280)\n", "\n", "settings.add_point_source(\"src\")\n", "settings.fix_flux(\"src\", 1)\n", "\n", "settings.add_background(\"bkg\")\n", "settings.fix_qu(\"bkg\", (0, 0))\n", "settings.set_initial_flux(\"bkg\", 1)\n", "\n", "settings.set_spectrum(\"bkg\", lambda e: e**-2.5)\n", "settings.set_spectrum(\"src\", lambda e: e**-1.5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To implement phase weights, we need to tell `LeakageLib` the source's light curve. This source was simulated with a sine squared light curve. Note that normalization doesn't matter.\n", "\n", "