The X-rays and the interstellar medium 

Exercises for the Life Cycle of Dust school in Barcelona 2023

The X-rays and the interstellar medium  

Welcome to the Hands-on session

This page belongs to the hands-on session of the X-ray observation of interstellar dust course at the Life Cycle of Dust school in Barcelona organized by the 6th Institute of Space Sciences Summer School. The exercises on this page are licensed through Zenodo (DOI: and are free to use.  You can find more X-ray spectroscopy exercises through the AHEAD2020 high resolution X-ray spectroscopy school website

The slides of the presentation X-ray observations of interstellar dust and gas can be found on  this website after the 5th of July 2023.

During the hands-on session we will make use of the SPEX software package to analyze interstellar dust and gas. The software instructions are given below. We will use python notebooks for the exercises. They are run through Sciserver.  

Software installation 

Sciserver setup (recommended)

Create a HEASOFT image on Sciserver as explained on the HEASOFT Sciserver documentation page. We have tested the exercises with HEASOFT 6.31.1.

Creating a conda environment for SPEX on Sciserver

Once you have the Jupyterlab environment running on Sciserver, write the following commands in the terminal:

(heasoft) idies@aaaa:~$ conda activate base

(base) idies@aaaa:~$ conda create -n spex python=3.9 astropy matplotlib ipykernel

(base) idies@aaaa:~$ conda activate spex

(spex) idies@aaaa:~$ conda install -c spexxray spex pyspextools

(spex) idies@aaaa:~$ python -m ipykernel install --user --name spex --display-name "(spex)"

Next we have to add the following line "conda", "run", "--no-capture-output", "-n", "spex", to this file ~/.local/share/jupyter/kernels/spex/kernel.json to try to make sure that conda starts the spex conda environment: 

(spex) idies@aaaa:~$ vi ~/.local/share/jupyter/kernels/spex/kernel.json

In vi, get into edit mode by typing i. Now, you have a cursor to edit the text file. Add the line "conda", "run", "--no-capture-output", "-n", "spex", after the "argv": [ line.

In the end, the contents of ~/.local/share/jupyter/kernels/spex/kernel.json should look like this:


 "argv": [

  "conda", "run", "--no-capture-output", "-n", "spex",







 "display_name": "(spex)",

 "language": "python",

 "metadata": {

  "debugger": true



When the contents of the file look OK, press the <Esc> key on your keyboard, and then type :x followed by the <return> key. The file should be saved now.

It is necessary to restart the Jupyter session on Sciserver to load the new SPEX environment into Jupyter properly. To do that, execute the following steps:

Installation on your own Laptop: 

SPEX can also be installed on your own computer. However, many more things can go wrong and during the school there will be very little time to debug anything. However, if you are interested you can take a look at the SPEX software package website and try to install SPEX yourself. 


Importing SPEX in Jupyter fails

When you have Jupyter installed in multiple places, it sometimes happens that the wrong Jupyter executable is called. If you have trouble importing SPEX, then try to run Jupyterlab like this to force it to use Jupyter from the SPEX environment:

(spex) user@unix:~> $CONDA_PREFIX/bin/jupyter-lab &

For more information please check:

Start SPEX 

You can start the Sciserver image and switch to the (spex) conda environment:

(heasoft) idies@aaaa:~$ conda activate spex

(spex) idies@aaaa:~$


The exercises consist of two parts: 

1) General spex exercises to learn how to work with SPEX.
2) Exercises focused on analysing the interstellar medium. 

1) SPEX exercises 

SPEX: In the first part of the afternoon we will go through the SPEX exercises. 

To import the SPEX exercises in your personal directory, you can download the files for this session with this command:

(spex) idies@aaaa:~$ cd ~/workspace/Storage/<user>/persistent

(spex) idies@aaaa:~/workspace/Storage/<user>/persistent$ git clone

The introduction and exercises can be found here:

They can also be found on this website: 

SPEX Introduction 

SPEX Exercise 1

If you have time left, you can also try this exercise: 

SPEX Exercise 2

2) Interstellar medium exercises

The interstellar medium exercises consist of three exercises. Instructions to start the exercises on Sciserver and information about SPEX and the ISM can be found through this link

To import the exercises into your personal directory, you can download the files for this session with this command:

(spex) idies@aaaa:~/workspace/Storage/<user>/persistent$ git clone 

Introduction: SPEX and the interstellar medium

The introduction provides a summary of the models in SPEX which can be used to model the ISM. 

Exercise 1: Fitting the dust in the X-ray binary of GX 17+2

Exercise 2: Future XRISM observations of an X-ray binary: Fe K edge

Exercise 3: Fitting ISM dust and multi-temperature gas along the line of sight of an X-ray binary