Make Background File

The make_background_file() function allows one to create an event file of a background for a particular instrument configuration. This event file can then be added as background to any source event file one creates using instrument_simulator(). make_background_file() also allows one to specify a particular set of point sources to make the point-source contribution to the background, or to create the point-source properties on the fly. In this example, we will show how to do the former using a point source table created by make_point_source_list().

First, import our modules:

[1]:
import matplotlib

matplotlib.rc("font", size=18)
import soxs

Second, define our parameters:

[2]:
exp_time = (100.0, "ks")  # in seconds
fov = 50.0  # in arcmin, used only for the point source generation
sky_center = [22.0, -27.0]  # in degrees

Now, use make_point_source_list() to create an ASCII table of point source properties that can be used when creating the background. We’ll set a random seed using the prng parameter to use a unique set of random numbers.

[3]:
soxs.make_point_source_list("point_source_table.dat", fov, sky_center, prng=24)

We can use this table of point source properties as an input to make_point_sources_file() or to make_background_file() to control precisely the properties of the generated sources. Because in this example we want to create a background, we’ll use make_background_file(). We have to pass the name of the table we created to the input_sources parameter if we want to use it:

[4]:
soxs.make_background_file(
    "bkgnd_evt.fits",
    exp_time,
    "chandra_aciss_cy0",
    sky_center,
    input_pt_sources="point_source_table.dat",
    overwrite=True,
    prng=24,
)
soxs : [INFO     ] 2024-06-19 16:00:17,114 Adding in point-source background.
soxs : [INFO     ] 2024-06-19 16:00:17,114 Reading in point-source properties from point_source_table.dat.
soxs : [INFO     ] 2024-06-19 16:00:27,388 Detecting events from source ptsrc_bkgnd.
soxs : [INFO     ] 2024-06-19 16:00:27,388 Applying energy-dependent effective area from aciss_aimpt_cy0.arf.
soxs : [INFO     ] 2024-06-19 16:00:27,433 Pixeling events.
soxs : [INFO     ] 2024-06-19 16:00:27,474 Scattering events with a multi_image-based PSF.
soxs : [INFO     ] 2024-06-19 16:00:27,565 40058 events were detected from the source.
soxs : [INFO     ] 2024-06-19 16:00:27,572 Scattering energies with RMF aciss_aimpt_cy0.rmf.
soxs : [INFO     ] 2024-06-19 16:00:27,717 Generated 40058 photons from the point-source background.
soxs : [INFO     ] 2024-06-19 16:00:27,717 Adding in astrophysical foreground.
soxs : [INFO     ] 2024-06-19 16:00:28,229 Adding in instrumental background.
soxs : [INFO     ] 2024-06-19 16:00:28,269 Making 37053 events from the galactic foreground.
soxs : [INFO     ] 2024-06-19 16:00:28,270 Making 479486 events from the instrumental background.
soxs : [INFO     ] 2024-06-19 16:00:28,293 Writing events to file bkgnd_evt.fits.

We can use the write_image() function in SOXS to bin the events into an image and write them to a file:

[5]:
soxs.write_image("bkgnd_evt.fits", "bkgnd_img.fits", overwrite=True)

We can now show the resulting image:

[6]:
fig, ax = soxs.plot_image(
    "bkgnd_img.fits",
    stretch="sqrt",
    cmap="plasma",
    width=0.5,
    vmin=0.0,
    vmax=1.0,
    center=[22.0, -27.0],
)
../_images/cookbook_Make_Background_File_13_0.png