SamSweere / xmm-epicpn-simulator

Simulation code for XMM-Newton EPIC-pn data using SIXTE and SIMPUT, designed to create training data for deep learning based super-resolution and de-noising.
https://academic.oup.com/mnras/article/517/3/4054/6694110
4 stars 2 forks source link
simulation sixte xmm-newton

XMM EPIC-pn Simulator

This repository hosts simulation code for generating XMM-Newton EPIC-pn observations, utilizing the SIXTE and SIMPUT frameworks.

The simulations are tailored to produce training datasets for deep learning algorithms aimed at super-resolution enhancement and noise reduction of XMM-Newton EPIC-pn data. For details on the deep learning implementation, refer to the xmm-superres-denoise repository. The findings from this research are documented in the paper Deep Learning-Based Super-Resolution and De-Noising for XMM-Newton Images, published in MNRAS, 517, 4054 (2022). Please cite this publication when using the simulation code for your research.

Installation

Given the complex dependencies and the need for external software, the code is best run in a Docker container. See the Installation Guide for detailed instructions on installing the necessary software, optionally using Docker.

Configuring the code

The good thing: You'll need to fill out config.toml only once! Every step relies on this configuration file and everything will be done accordingly. This file is divided into environment, energy, download, simput and simulation:

environment

This gives paths and some general information to the code:

energy

Set the energy boundaries in keV:

download

simput

simulation

Running the code

Running the code in a Docker container

Assuming you have the Docker image ready (see the Installation Guide), you can run the code in the Docker container. First navigate to the root of this project:

cd /path/to/xmm-epicpn-simulator

Next we can run the Docker container and mount the current directory into the container. This way the code is available in the container and the results will be saved on your local machine. Run the following command:

docker run --rm -it -v $(pwd):/home/xmm_user/xmm-epicpn-simulator samsweere/xmm-epicpn-simulator:latest

The --rm flag will remove the container and the volume after it has finished running. The -it flags are for interactive mode.

Optionally you can replace $(pwd) with the path to the directory where the xmm-epicpn-simulator code is located.

Note that the code will write the results to the xmm-epicpn-simulator/data directory. It needs to have write permissions to this directory. By default the docker will run with the uid of 1000. If your user is not 1000, then you'll need to change the permissions of the directory. You chan check your user id by running:

id -u

You can change the permissions of the directory by running. First if it doesn't exist, create the directory:

mkdir /path/to/xmm-epicpn-simulator/data

Then change the permissions:

sudo chmod -R 777 /path/to/xmm-epicpn-simulator/data

Running the code

First make sure your working directory is the root of this project (also when running this from the docker container). I.e.

cd /path/to/xmm-epicpn-simulator

The code is split up into different steps, represented by different scripts. If you want to go through the whole process, then you must execute the steps in the correct order. They are numbered accordingly. There are following steps:

  1. 01_download_files.py: Download files from the Illustris Project. Before you can do that you'll need an API key. For this check out their registration page. After your request has been approved, you'll see your personal API key after you login. Please keep this key to yourself! If you do not want to re-enter the api key every time you can add it to a .env file in the root of the project. The file should look like this:
    TNG_API_KEY="{your_api_key_here}"

By default the code will use config.toml as the configuration file. If you want to use another file, then you can pass the path to the file as a command line argument (--config_path). The script will then use this file instead of config.toml.

  1. 02_generate_simput.py: Create SIMPUT files based on the previously downloaded files.

  2. 03_xmm_simulation.py: Simulate XMM-Newton for the previously created SIMPUT files. TBD: I will add at least one other satellite to choose from.

  3. 04_combine_simulations.py: Not used right now! I will rewrite this step to merge images from different satellites/different sensors.

Executing any of the scripts is same for both setups:

  1. Set your configuration parameters as needed (see above)
  2. Initialise external tools:
. ${HEADAS}/headas-init.sh && . ${SAS_DIR}/setsas.sh && . ${SIXTE}/bin/sixte-install.sh
  1. Choose what step you want to run
  2. Run conda run -n xmm --no-capture-output python /path/to/script with the needed command line arguments:

    1. 01_download_files.py requires two arguments:

      1. -k followed by your personal Illustris API key (see below)
      2. -p followed by the path to the config.json
    2. 02_generate_simput.py requires three arguments:
      1. -a followed by the path to the agn_counts.cgi file in res
      2. -p followed by the path to the config.json
      3. -s followed by the path to res/spectrums
    3. 03_xmm_simulation.py requires one argument:
      1. -p followed by the path to the config.json

IllustrisTNG simulations

For our XMM simulations we need sources to simulate (simulation input). In our project we are especially interested in extended sources. We take these extended sources from the Illustris TNG project (https://www.tng-project.org/). This is a large cosmological hydrodynamical simulation of galaxy formation containing hundreds of terabytes of simulated data. From this we take the most massive objects and take x-ray projections and x-ray slices (less realistic but contains more clearly defined structure). Note that cutout files are relatively large (100-1000 mb) and can take a while to download, it will first download all the relevant cutouts before generating the images.

Notes on extended sources (images as simput)

To create the simput for extended sources we use fits image files. In order to have a realistic distribution we augment these images using:

XMM Simulation

The XMM simulations are done using SIXTE X-ray simulation software (https://www.sternwarte.uni-erlangen.de/research/sixte/). All the elements that make up a XMM observation are simulated separately: extended source, agn and background. These can then in the future be combined with a detector-mask to create a realistic XMM observation. Since this is a simulation we can also simulate observations where XMM has a higher resolution (both spatial and psf wise).

Acknowledgements

Many thanks to Bojan Todorkov for his code improvements and bug fixes to the codebase!