Besides new Python-based tasks which can be used from the command line, SAS includes now a Python core infrastructure, known as pysas, which allows the use of all SAS tasks from a Python session, either running it from the command line using ipython or from a web browser using the Jupyter notebook. Such methods, allow users to perform the whole processing of XMM-Newton data completely within Python.
Prior to starting a Python session to work with SAS, the basic SAS environment must be initialised as indicated in § 2.3.1 and the SAS_CCFPATH must be set to the directory which stores all CCFs.
The SAS Python package pysas includes a module named wrapper which must be imported into the Python session as follows,
from pysas.wrapper import Wrapper as w
where w is an alias for the object Wrapper, which can be used from now onwards to run any SAS task by making a specific instance of such object.
To get started, the Python task sasver, provides a sort of about SAS, as an example on how to run any other SAS task.
As seen in § 2.6, every SAS taks can be called using a specific set of parameters and options which can be passed to it through the command line. The equivalent way to do this from a Python session, is through the use of a Python list. Let inargs be the name of such list. To pass the option -version to the sasver task, one must fill in inargs with such options, as follows,
inargs = ['--version']
To run the task, create an instance of the generic object w, with the options defined in inargs. This is done as follows,
t = w('sasver', inargs)
In Python terms, t is known as an 'instantiation' of object Wrapper or, equivalently, its alias w.
Now, the task sasver can be run as follows,
t.run()
which should produce, in this case, the following output:
sasver (sasver-0.4) [xmmsas_20201028_0905-19.0.0]
Figure § 1 shows the previous sequence of commands as executed from a Jupyter notebook. The figure shows four consecutive notebook cells whose inputs are indicated by In [n]: where n are consecutives integer numbers 1, 2, 3, 4, .... The line immediately after the cell beginning with In [4]: shows the output generated by the command entered on this last cell.
Similar sequences of commands could be used to make more ellaborated commands. For example, Figure § 2 shows the execution of task sasver without arguments, using inargs = [] and Figure § 3 shows the execution of another Python task named startsas using as arguments inargs = ['-h']. This option produces some help information, including a list of available options and a table displaying all available parameters, in this case for startsas.
Figure § 4 shows in its last notebook cell how the previous three commands could be condensed in a single one.
The task startsas can be used to start working with SAS. This is done by using the task paramater odfid to set the ID of the XMM-Newton observation of interest. The task will download such observation using the astroquery Python module and will run the SAS tasks cifbuild and odfingest to obtain the CIF and observation summary files. Figure § 4 shows all the available parameters that can be used with startsas. Notice that these paramaters can be used as well when running startsas from the command line.
For further information, a Start-up SAS Analysis Threads in Python guides you on how to begin using the Python interface to SAS and the different startsas funcionalities.
European Space Agency - XMM-Newton Science Operations Centre