{ "cells": [ { "cell_type": "markdown", "metadata": { "vscode": { "languageId": "plaintext" } }, "source": [ "# Preparing real IXPE data for fitting\n", "\n", "Before fitting to real IXPE data of point sources, a few pre-processing steps must be performed. This notebook walks through how to perform these steps." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Download the data from the IXPE archive\n", "\n", "IXPE data can be downloaded from the archive [here](https://heasarc.gsfc.nasa.gov/db-perl/W3Browse/w3table.pl?tablehead=name%3Dixmaster&Action=More+Options). To use all weights, please download all the data. This includes level 2 data (for the event polarizations and positions), hk data (for the telescope orientation), auxil data (for the exposure map) and level 1 data (for the track images to perform particle weighting.)\n", "\n", "For this tutorial, download observation ID 01002601, which is an observation of GX 301-2. Once you have downloaded and unzipped the data, proceed to the next step." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. (Optional) Neural nets\n", "\n", "Once you have downloaded the data, you can reprocess it with Lawrence Peirson's neural net code. This will improve the precision of the event EVPA, position, and modulation factor estimates. The code for doing this is not part of leakagelib; it requires installing the [ixpenn package](https://github.com/jack-dinsmore/ixpenn) separately. Please see the documentation therein.\n", "\n", "
\n", "\n", "**Note**: This step is optional. You can still run LeakageLib on the mission-standard, Moments-processed data without NN reconstruction, and it will still give improved uncertainties.\n", "\n", "
\n", "\n", "If you do reprocess your data with that neural net, its polarimetric weights will automatically be applied." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. (Optional) Estimate particle weights\n", "\n", "You can use the `leakagelib_bkg` script to flag each event with a probability of being a particle, named BG_CHAR in the fits file. Low BG_CHAR events are likely photons, and high BG_CHAR events are likely particles. Leakagelib will use these \"particle characters\" to de-weight likely-particle events. If you do not want to use these weights, you can still run the `leakagelib_bkg` script and then cut all events with BG_CHAR above some number --- it will just be less efficient.\n", "\n", "The below script displays the `leakagelib_bkg` help menu:" ] }, { "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", "STARTING\n", "usage: clean [-h] l2 l1 outfile\n", "\n", "Flags background particles in IXPE datasets with a probability (BG_CHAR\n", "column) of being background. l1 should be the level 1 file, l2 should be the\n", "level 2 file you wish to add background probabilities to, and outfile is the\n", "output. If outfile already exists, it will be overwritten.\n", "\n", "positional arguments:\n", " l2 Name of the input l2 file\n", " l1 Name of the input l1 file\n", " outfile Name of the output file\n", "\n", "options:\n", " -h, --help show this help message and exit\n" ] } ], "source": [ "!python -m leakagelib_bkg -h" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For the GX 301-2 observation, you can run this script to calculate particle weights. Some modification to the file paths may be necessary. It will take some time to run." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "mkdir: data/01002601/event_l2_weight: File exists\n", "\u001b[93m>>> PyXSPEC is not installed, you will no be able to use it.\u001b[0m\n", "STARTING\n", "L1 file: data/01002601/event_l1/ixpe01002601_det1_evt1_v02.fits\n", "L2 file: data/01002601/event_l2/ixpe01002601_det1_evt2_v01.fits\n", "Wrote background probabilities to data/01002601/event_l2_weight/ixpe01002601_det1_evt2_v01.fits\n", "\u001b[93m>>> PyXSPEC is not installed, you will no be able to use it.\u001b[0m\n", "STARTING\n", "L1 file: data/01002601/event_l1/ixpe01002601_det2_evt1_v02.fits\n", "L2 file: data/01002601/event_l2/ixpe01002601_det2_evt2_v01.fits\n", "Wrote background probabilities to data/01002601/event_l2_weight/ixpe01002601_det2_evt2_v01.fits\n", "\u001b[93m>>> PyXSPEC is not installed, you will no be able to use it.\u001b[0m\n", "STARTING\n", "L1 file: data/01002601/event_l1/ixpe01002601_det3_evt1_v02.fits\n", "L2 file: data/01002601/event_l2/ixpe01002601_det3_evt2_v01.fits\n", "Wrote background probabilities to data/01002601/event_l2_weight/ixpe01002601_det3_evt2_v01.fits\n" ] } ], "source": [ "!mkdir data/01002601/event_l2_weight\n", "!python -m leakagelib_bkg\\\n", " data/01002601/event_l2/ixpe01002601_det1_evt2_v01.fits\\\n", " data/01002601/event_l1/ixpe01002601_det1_evt1_v02.fits\\\n", " data/01002601/event_l2_weight/ixpe01002601_det1_evt2_v01.fits\n", "!python -m leakagelib_bkg\\\n", " data/01002601/event_l2/ixpe01002601_det2_evt2_v01.fits\\\n", " data/01002601/event_l1/ixpe01002601_det2_evt1_v02.fits\\\n", " data/01002601/event_l2_weight/ixpe01002601_det2_evt2_v01.fits\n", "!python -m leakagelib_bkg\\\n", " data/01002601/event_l2/ixpe01002601_det3_evt2_v01.fits\\\n", " data/01002601/event_l1/ixpe01002601_det3_evt1_v02.fits\\\n", " data/01002601/event_l2_weight/ixpe01002601_det3_evt2_v01.fits" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An alternative to `leakagelib_bkg` is the background removal script created by Alessandro Di Marco, which cuts events likely to be particles. You should use only one of these methods; do not apply both. We recommend using `leakagelib_bkg` for two reasons: (1) it can be used to de-weight events which could be particles or photons without completely removing them, increasing the precision of the final result. (2) Even if you decide to cut all events based on BG_CHAR, you can adjust the cut to a value suitable for your data set." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This concludes the pre-processing steps that are specific to LeakageLib. However, most IXPE analyses require more reprocessing, e.g.\n", "\n", "* Ensuring the images are properly aligned, and aligning them to an external coordinate system if necessary\n", "* Removing flares\n", "* Removing events outside the GTIs\n", "\n", "LeakageLib does not provide tools to execute these steps, but you should perform them as necessary." ] } ], "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 }