{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Preparing an extended source for LeakageLib fitting\n", "\n", "The steps to process extended source data before fitting are the same as for point sources, with the extra step of extracting spatial weights. This should be done with the `leakagelib_cxo` script, which generates spatial weights from a Chandra image. Note that `leakagelib_cxo` is NOT a replica of IXPEobssim; IXPEobssim incorporates IXPE's PSF and generates a simulated event file. `leakagelib_cxo` does not (and should not).\n", "\n", "This extended source section analyzes Crab OBS ID 02006001. Please download the data from Heasarc. (We will skip particle weights, so you do not need to download the level 1 data). After unzipping the files, the next step is to run `leakagelib_cxo`. Run the help script to see what the script requires." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[93m>>> PyXSPEC is not installed, you will no be able to use it.\u001b[0m\n", "usage: clean [-h] --cxo-evt CXO_EVT [CXO_EVT ...] --cxo-arf CXO_ARF\n", " [CXO_ARF ...] --ixpe-evt IXPE_EVT --ixpe-arf IXPE_ARF\n", " [--expmap EXPMAP] --output OUTPUT [--width WIDTH] [--elow ELOW]\n", " [--ehigh EHIGH] [--centerx CENTERX] [--centery CENTERY]\n", " [--reg-src REG_SRC] [--reg-bkg REG_BKG]\n", " [--clobber | --no-clobber]\n", "\n", "Creates a CXO image, adjusted to the IXPE band. Before running this command,\n", "you should use the ciao tools merge_obs and mkwarf to create a merged image\n", "(including an exposure map) and an arf for each observaton. These are required\n", "as inputs for this script.\n", "\n", "options:\n", " -h, --help show this help message and exit\n", " --cxo-evt CXO_EVT [CXO_EVT ...]\n", " List of Chandra event files to use\n", " --cxo-arf CXO_ARF [CXO_ARF ...]\n", " List of Chandra ARFs to use\n", " --ixpe-evt IXPE_EVT IXPE event file (only one is necessary. Try DU1)\n", " --ixpe-arf IXPE_ARF IXPE ARF (only one is necessary, for simplicity. Try\n", " DU1)\n", " --expmap EXPMAP Chandra merged observation ARF (Optional)\n", " --output OUTPUT Name of the output file\n", " --width WIDTH Width of the image, in arcseconds. Default: as big as\n", " the CXO image (Optional)\n", " --elow ELOW Low end of the energy range (keV). (Default: 2)\n", " --ehigh EHIGH High end of the energy range (keV). (Default: 8)\n", " --centerx CENTERX IXPE pixel on which the fit will be centered in the x\n", " direction. (Default: 300)\n", " --centery CENTERY IXPE pixel on which the fit will be centered in the y\n", " direction. (Default: 300)\n", " --reg-src REG_SRC Source region. Should be saved in CIAO format in fk5\n", " coordinates (Optional)\n", " --reg-bkg REG_BKG Background region. Should be saved in CIAO format in\n", " fk5 coordinates (Optional)\n", " --clobber, --no-clobber\n", " Overwrite files\n" ] } ], "source": [ "!python -m leakagelib_cxo -h" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you see, it requires\n", "* CXO event file(s) to create the Source object from\n", "* IXPE ARF and CXO ARF(s) to find the expected fluxes, taking the different effective areas into account. Provide multiple ARFs if providing multiple CXO event files\n", "* IXPE event file to orient the CXO image relative to the IXPE pointing.\n", "* IXPE energy range used for fitting (2-8 keV by default)\n", "* IXPE pixel used for centering (300,300 by default)\n", "\n", "and optionally\n", "* The width of the output spatial weight image\n", "* A CXO source region to extract an image for\n", "* A CXO background region to estimate background flux\n", "* CXO Exposure map to exposure correct the event file\n", "\n", "`ciao` provides tutorials on how to extract ARFs and exposure maps for Chandra data, so we do not cover that here. If you are using more than one event file, I suggest using the full exposure map generated by the ciao tool merge_obs." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To make this example, I downloaded a short Crab observation from the Chandra archive (obsid 13146) and placed inside a `src.reg` region file containing\n", "```\n", "circle(5:34:31.8424,+22:00:52.502,0.5')\n", "```\n", "(This region was made in DS9 and saved with the ciao format with fk5 coordinates)\n", "\n", "I then ran the following script\n", "```\n", "chandra_repro . repro\n", "asphist \"repro/pcadf13146_000N001_asol1.fits\" asp.hist evtfile=\"repro/acisf13146_repro_evt2.fits[sky=region(src.reg)]\" clobber=yes\n", "sky2tdet \"repro/acisf13146_repro_evt2.fits[sky=region(src.reg)]\" asp.hist tdet[wmap] clobber=yes\n", "mkwarf tdet arf.arf weightfile=none feffile=none spectrum=none egrid=0.3:10:0.1 pbkfile=none clobber=yes\n", "```\n", "\n", "I also downloaded the IXPE data for the Crab from OBSID 02006001 and ran this script to generate an IXPE ARF:\n", "```\n", "ixpecalcarf evtfile=\"event_l2/ixpe02006001_det1_evt2_v01.fits\" attfile=\"hk/ixpe02006001_det1_att_v01.fits\" arfout=\"arf.arf\" specfile=None clobber=yes\n", "```\n", "Then the following code will create a source image. To keep things simple I did not apply background subtraction or exposure correction." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[93m>>> PyXSPEC is not installed, you will no be able to use it.\u001b[0m\n", "Exposure map corrections will not be made because you did not pass an exposure map\n", "You did not provide a background region. The Chandra image will not be background subtracted\n", "Image saved to data/13146/crab.fits. To use it, load the source with LeakageLib using the following code:\n", " \n", "import leakagelib\n", "source = leakagelib.Source.load_file(\"data/13146/crab.fits\")\n", "\n", "This gives a leakagelib.Source object, which you can use as a source in your LeakageLib fit.\n" ] } ], "source": [ "!python -m leakagelib_cxo\\\n", " --output \"data/13146/crab.fits\"\\\n", " --cxo-evt \"data/13146/repro/acisf13146_repro_evt2.fits\"\\\n", " --cxo-arf \"data/13146/arf.arf\"\\\n", " --ixpe-evt \"data/02006001/event_l2/ixpe02006001_det1_evt2_v01.fits\"\\\n", " --ixpe-arf \"data/02006001/arf.arf\"\\\n", " --reg-src \"data/13146/src.reg\"\\\n", " --width 150\\\n", " --clobber" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "