{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n",
"\t\t\t Introduction \n", "\t\t\tThis thread contains a step-by-step recipe to process RGS data of point-like sources. \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 reduce RGS data using SAS, please refer to the standard SAS threads, \n", " \n", "\t\t\tExpected Outcome \n", "\t\t\tSource and background RGS spectra and the associated response matrices as well as light curves. \n", "\t\t\tSAS Tasks to be Used \n", "\t\t\t
Prerequisites \n", "\t\t\t
Useful Links \n", "\t\t\t
Last Reviewed: 31 January 2025, for SAS v22.0\n", "\t\t\tLast Updated: 25 May 2023\n", "\t\t\t | \n",
"\t\t
This thread is intended to show the steps to follow to extract RGS spectra and light curves from a Jupyter notebook. It expects that the ODF or PPS have been downloaded into separate folders and that the SAS Startup Thread has been followed.
\n", "\n", "The task rgsproc can redo different stages of processing without starting from scratch. Allow enough time for it to finish. It may take between 5-10 minutes depending on the ODF size and your computer. The different entry and exit points are called processing stages, of which there are six:
\n", "If the task has been run only through spectra neither the response matrices nor the fluxed spectra or the light curves are created. The fluxing stage is the most time consuming, and therefore it is recommended to run it only once the results of the previous stages are satisfactory.
\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", "metadata": {}, "source": [ "Import the following Python libraries,
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from pysas.wrapper import Wrapper as w\n", "import os, sys,glob,shutil\n", "import pathlib\n", "from astropy.io import fits\n", "from astropy import coordinates as coo\n", "from astropy import units as u\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 astropy.convolution import Gaussian2DKernel, convolve" ] }, { "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 = []\n", "t = w('sasver', inargs)\n", "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 00096020101 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}0082_0096020101_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 produce an RGS event file and associated files to extract a spectra and light curves of point-like source.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For most analysis, this is all is needed, however, there are a number of checks we can do.
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In line with the other XMM-Newton instruments, RGS observations can be affected by high particle background periods caused by solar activity or by the Earth radiation belts. You should check your observations and, if necessary, filter out these periods before extracting any scientific products. In the blocks that follow will we use RGS1. The equivalent commands can be used for RGS2. We will use the ODF with id 0096020101 as an example.
\n", "\n", "\t\t\t\n", "\t\t\t | \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 }