{ "cells": [ { "cell_type": "markdown", "id": "0781d934", "metadata": {}, "source": [ "
\n",
"\t\t\t Introduction \n", "\t\t\tThis thread contains a step-by-step recipe to extract a light curve and a spectrum of a point-like source which is valid for all the EPIC X-ray cameras. In the case of the light curve, it includes subtracting the background and correcting the light curve for exposure losses. \n", "The purpose of this jupyter notebook thread is to illustrate how to use SAS within python notebooks. For an in-depth explanation on how to extract light curves and spectra for an EPIC point-like source using SAS, please refer to the standard SAS threads, \n", "
Expected Outcome \n", "\t\t\tSpectrum and corrected light curve of a point-like source extracted from the XMM-Newton EPIC instruments. \n", "\t\t\tSAS Tasks to be Used \n", "\t\t\t
Prerequisites \n", "\t\t\tIt is assumed that the processed event lists, like the ones produced by the SAS tasks epproc and emproc, and corresponding attitude and summary files as well as the ccf.cif file are available. Calibrated event lists may also be obtained as a starting point for this thread from the archive. \n", "\t\t\t
Useful Links \n", "\t\t\t
Last Reviewed: 31 January 2025, for SAS v22.0\n", "\t\t\tLast Updated: 31 January 2025\n", "\t\t\t | \n",
"\t\t
As an example case, we will consider the extraction of a spectrum and a light curve from a pn event list (PN_evt.fits). The same recipe applies for MOS. We highlight here the general steps which are included in the notebook cells below.
\n",
"
In order to run the following blocks, SAS needs to be initialized in the terminal from which the Jupyter nootebook has been opened. This has to be done prior to launching the notebook. Follow the steps provided in the SAS Startup Thread (or SAS Startup Thread in Python).
" ] }, { "cell_type": "markdown", "id": "ed3fa35f", "metadata": {}, "source": [ "Import the following Python libraries,
" ] }, { "cell_type": "code", "execution_count": null, "id": "d4f1153a", "metadata": {}, "outputs": [], "source": [ "from pysas.wrapper import Wrapper as w\n", "import os\n", "import os.path\n", "from os import path\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from astropy.io import fits\n", "import pyds9\n", "from xspec import *\n", "import re\n", "from IPython.display import SVG, display" ] }, { "cell_type": "markdown", "id": "da545c1c", "metadata": {}, "source": [ "Before we start, let's see what we have already defined in terms of SAS variables,
" ] }, { "cell_type": "code", "execution_count": null, "id": "c1f4f737", "metadata": {}, "outputs": [], "source": [ "inargs = []\n", "t = w('sasver', inargs)\n", "t.run()" ] }, { "cell_type": "markdown", "id": "df50747c", "metadata": {}, "source": [ "We still need to define the SAS_ODF and SAS_CCF variables (make sure the SAS_CCFPATH is also defined). Use the SAS task startsas as described in the SAS Startup Thread in Python to download an ODF. For this thread, we will assume that an ODF has already been downloaded. We will use the ODF with id 0104860501 as an example and assume that there is already a directory (sas_file in the block below) with an existing CIF and SAS Summary File. In the block below introduce the absoute path to the Working directory (finished with '/') and the location of the CIF and SAS Summary File,
\n", "\n", "Note: the path to the CIF and SAS Summary File must be an absolute path begining with '/'." ] }, { "cell_type": "code", "execution_count": null, "id": "a4bf1eb7", "metadata": {}, "outputs": [], "source": [ "work_dir = 'absolute_path_to_wrk_directory'\n", "sas_file = 'absolute_path_to_cifSUMSAS_directory'" ] }, { "cell_type": "code", "execution_count": null, "id": "9d4b800c", "metadata": {}, "outputs": [], "source": [ "inargs = [f'sas_ccf={sas_file}ccf.cif', f'sas_odf={sas_file}0466_0104860501_SCX00000SUM.SAS', f'workdir={work_dir}']" ] }, { "cell_type": "code", "execution_count": null, "id": "a153ceef", "metadata": {}, "outputs": [], "source": [ "w('startsas', inargs).run()" ] }, { "cell_type": "markdown", "id": "6617c2fe", "metadata": {}, "source": [ "This process should have defined the SAS_CCF an SAS_ODF variables.
" ] }, { "cell_type": "markdown", "id": "d9ef2a6c", "metadata": {}, "source": [ "In the following blocks, we will produce an EPIC-pn image and define source and background extraction regions for lightcurve and spectral extraction. The same procedure is valid as well for an EPIC-MOS event file.
" ] }, { "cell_type": "markdown", "id": "2792dc68", "metadata": {}, "source": [ "\n", "\t\t\t\n", "\t\t\t | \n", "\t\t
" ] }, { "cell_type": "code", "execution_count": null, "id": "072ac622", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "PythonSAS", "language": "python", "name": "localpython" }, "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.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }