{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n",
"\t\t\t Introduction \n", "\t\t\tThis thread describes how to filter an EPIC event list for periods of high background flaring activity. \n", "\t\t\tExpected Outcome \n", "\t\t\tThe outcome of this thread is an EPIC filtered event list clean of time intervals of high background activity, and a Good Time Interval (GTI) file containing the definition of GTI for a given observation. \n", "\t\t\tSAS Tasks to be Used \n", "\t\t\t\n", "\t\t\tPrerequisites \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\tIn the following links, a full description is given of the different background components of the EPIC cameras, including the external flaring background component which is treated in this thread. \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 cleaning an event list, EPIC.fits, higlighting the differences between MOS and pn. Below are the main general steps which are included in the notebook cells that follow.
\n",
"
evselect table=EPIC.fits withrateset=Y rateset=rateEPIC.fits \\
\n",
"\t\t maketimecolumn=Y timebinsize=100 makeratecolumn=Y \\
\n",
"\t\t expression='Selection_Expression'
\n",
"\t\t
\n",
"\t\twhere Selection_Expression is:
\n",
"\t\t
\n",
"\t\t #XMMEA_EM && (PI>10000) && (PATTERN==0) for EPIC-MOS
\n",
"\t\t #XMMEA_EP && (PI>10000&&PI<12000) && (PATTERN==0) for EPIC-pn
\n",
"\t\t
\n",
"\t\tNotice how the EPIC-pn energy range selected for producing the background light curve includes events only up to 12 keV. The reason for this is to avoid hot pixels being miss-identified as very high energy events. One can look at the produced light curve by running:
\n",
"\t\t
\n",
"\t\t
dsplot table=rateEPIC.fits x=TIME y=RATE
tabgtigen table=rateEPIC.fits expression='RATE<=Rate_Expression' gtiset=EPICgti.fits
\n",
"\t\t
\n",
"\t\twhere Rate_Expression is:
\n",
"\t\t
\n",
"\t\t RATE<=0.35 for EPIC-MOS
\n",
"\t\t RATE<=0.4 for EPIC-pn
\n",
"\t\t
\n",
"\t\tThis value will be different for each data set (the value given here for each instrument represents a good reference value for a standard observation). Use this expression to filter the event list:
\n",
"\t\t
\n",
"\t\t
evselect table=EPIC.fits withfilteredset=Y filteredset=EPICclean.fits \\
\n",
"\t\t destruct=Y keepfilteroutput=T \\
\n",
"\t\t expression='Selection_Expression'
\n",
"\t\t
\n",
"\t\twhere Selection_Expression is:
\n",
"\t\t
\n",
"\t\t #XMMEA_EM && gti(EPICgti.fits,TIME) && (PI>150) for EPIC-MOS
\n",
"\t\t #XMMEA_EP && gti(EPICgti.fits,TIME) && (PI>150) for EPIC-pn
\n",
"\t\t
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. ollow the steps provided in the SAS Startup Thread (or SAS Startup Thread in Python).
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import the following Python libraries" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pysas.wrapper import Wrapper as w\n", "import os\n", "import os.path\n", "from os import path\n", "import subprocess\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "from astropy.io import fits\n", "from astropy.table import Table\n", "from matplotlib.colors import LogNorm" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before we start, lets see what we have already defined in terms of SAS variables,
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "inargs = []" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t = w('sasver', inargs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t.run()" ] }, { "cell_type": "markdown", "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, "metadata": {}, "outputs": [], "source": [ "work_dir = 'absolute_path_to_wrk_directory'\n", "sas_file = 'absolute_path_to_cifSUMSAS_directory'" ] }, { "cell_type": "code", "execution_count": null, "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, "metadata": {}, "outputs": [], "source": [ "w('startsas', inargs).run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This process should have defined the SAS_CCF an SAS_ODF variables.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following blocks we will filter an EPIC-pn event file for periods of high background flaring activity as an example. The same procedure is valid as well for an EPIC-MOS event file.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "\n", "
The SAS task espfilt, one of the tools within the XMM-ESAS package (available as of SAS v9.0), is able to perform GTI filtering of EPIC event files. The task generates soft proton contamination-filtered products, including clean event lists and GTI files (refer to the espfilt documentation for a description of all the products generated and information on the task input parameters).
\n", "\n", "In its simplest form, the task can be ran by providing the name of the EPIC event list in the following way:
\n",
"
\n",
" espfilt eventfile=EPIC.fits
Relevant to this thread, three files are produced which contain the EPIC clean event list, GTI file and QDP text file of histograms and lightcurves. These files use the following naming convention:
\n",
"
\n",
" ****-allevc.FIT, contains the EPIC clean event list
\n",
" ****-gti.FIT, contains the definition of GTI
\n",
" ****-hist.qdp, contains QDP text file of histograms and lightcurves
\n",
"
\n",
"where **** is a combination of instrument and exposure IDs. More files are produced by espfilt and the user is referred to the documentation of the SAS task. The QDP text file should be examined as it provides an indication of the quality of the data. It can be plotted using the command, for example, qdp ****-hist.qdp
\n",
"
\n",
"Keep in mind that for the case of pn Small Window exposures, there are no corner events, hence, the task does not support this method. For further information please read the documentation of espfilt.
\n",
"\t\t\t Caveats | \n",
"\t\t
" ] }, { "cell_type": "code", "execution_count": null, "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": 4 }