Esempio n. 1
0
def test_thermal(answer_store, answer_dir):

    prng = RandomState(71)

    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    spectrum_answer_testing(spec, "thermal_spec.h5", answer_store, answer_dir)

    pt_src_pos = PointSourceModel(30.0, 45.0)
    sim_cat = SimputCatalog.from_models("thermal_model", "thermal_model", spec,
                                        pt_src_pos, exp_time, area, prng=prng)
    sim_cat.write_catalog(overwrite=True)

    instrument_simulator("thermal_model_simput.fits", "thermal_model_evt.fits", exp_time, 
                         inst_name, [30.0, 45.0], ptsrc_bkgnd=False, foreground=False,
                         instr_bkgnd=False, prng=prng)

    write_spectrum("thermal_model_evt.fits", "thermal_model_evt.pha", overwrite=True)

    file_answer_testing("EVENTS", "thermal_model_evt.fits", answer_store, answer_dir)
    file_answer_testing("SPECTRUM", "thermal_model_evt.pha", answer_store, answer_dir)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 2
0
def test_absorption_line(answer_store, answer_dir):
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    const_flux = 1.0e-3
    line_pos = 1.0
    line_width = 0.02
    line_amp = 1.0e-5

    exp_time = (100.0, "ks")
    inst_name = "lynx_xgs"

    spec = Spectrum.from_constant(const_flux, 0.1, 3.0, 100000)
    spec.add_absorption_line(line_pos, line_width, line_amp)

    spectrum_answer_testing(spec, "absorption_line_test.h5", answer_store,
                            answer_dir)

    simulate_spectrum(spec,
                      inst_name,
                      exp_time,
                      "absorption_line_evt.pha",
                      overwrite=True,
                      prng=prng)

    file_answer_testing("SPECTRUM", "absorption_line_evt.pha", answer_store,
                        answer_dir)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 3
0
def plaw_fit(alpha_sim, answer_store, answer_dir):

    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    nH_sim = 0.02
    norm_sim = 1.0e-4
    redshift = 0.01

    exp_time = (50.0, "ks")
    area = 40000.0
    inst_name = "new_hdxi"

    spec = Spectrum.from_powerlaw(alpha_sim, redshift, norm_sim, 0.1, 10.0,
                                  20000)
    spec.apply_foreground_absorption(nH_sim, model="tbabs")

    spectrum_answer_testing(spec, f"power_law_{alpha_sim}.h5", answer_store,
                            answer_dir)

    pt_src_pos = PointSourceModel(30.0, 45.0)
    pt_src = SimputPhotonList.from_models("plaw_model",
                                          spec,
                                          pt_src_pos,
                                          exp_time,
                                          area,
                                          prng=prng)
    cat = SimputCatalog.from_source("plaw_model_simput.fits",
                                    pt_src,
                                    overwrite=True)

    instrument_simulator("plaw_model_simput.fits",
                         f"plaw_model_{alpha_sim}_evt.fits",
                         exp_time,
                         inst_name, [30.0, 45.0],
                         instr_bkgnd=False,
                         ptsrc_bkgnd=False,
                         foreground=False,
                         prng=prng)

    write_spectrum(f"plaw_model_{alpha_sim}_evt.fits",
                   f"plaw_model_{alpha_sim}_evt.pha",
                   overwrite=True)

    file_answer_testing("EVENTS", f"plaw_model_{alpha_sim}_evt.fits",
                        answer_store, answer_dir)
    file_answer_testing("SPECTRUM", f"plaw_model_{alpha_sim}_evt.pha",
                        answer_store, answer_dir)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 4
0
def test_emission_line(answer_store, answer_dir):
    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    const_flux = 1.0e-4
    line_pos = 5.0
    line_width = 0.02
    line_amp = 1.0e-5

    exp_time = (100.0, "ks")
    area = 30000.0
    inst_name = "lynx_lxm"

    spec = Spectrum.from_constant(const_flux, 1.0, 10.0, 20000)
    spec.add_emission_line(line_pos, line_width, line_amp)

    spectrum_answer_testing(spec, "emission_line_test.h5", answer_store,
                            answer_dir)

    pt_src_pos = PointSourceModel(30.0, 45.0)
    sim_cat = SimputCatalog.from_models("emission_line",
                                        "emission_line",
                                        spec,
                                        pt_src_pos,
                                        exp_time,
                                        area,
                                        prng=prng)
    sim_cat.write_catalog(overwrite=True)

    instrument_simulator("emission_line_simput.fits",
                         "emission_line_evt.fits",
                         exp_time,
                         inst_name, [30.0, 45.0],
                         instr_bkgnd=False,
                         ptsrc_bkgnd=False,
                         foreground=False,
                         prng=prng)

    write_spectrum("emission_line_evt.fits",
                   "emission_line_evt.pha",
                   overwrite=True)

    file_answer_testing("EVENTS", "emission_line_evt.fits", answer_store,
                        answer_dir)
    file_answer_testing("SPECTRUM", "emission_line_evt.pha", answer_store,
                        answer_dir)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 5
0
def test_thermal_nei(answer_store, answer_dir):

    prng = RandomState(71)

    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    spectrum_answer_testing(spec_nei, "thermal_spec_nei.h5", answer_store,
                            answer_dir)

    pt_src_pos = PointSourceModel(30.0, 45.0)
    pt_src = SimputPhotonList.from_models("thermal_model_nei",
                                          spec_nei,
                                          pt_src_pos,
                                          exp_time,
                                          area,
                                          prng=prng)
    sim_cat = SimputCatalog.from_source("thermal_model_nei_simput.fits",
                                        pt_src,
                                        overwrite=True)

    instrument_simulator("thermal_model_nei_simput.fits",
                         "thermal_model_nei_evt.fits",
                         exp_time,
                         inst_name, [30.0, 45.0],
                         ptsrc_bkgnd=False,
                         foreground=False,
                         instr_bkgnd=False,
                         prng=prng)

    write_spectrum("thermal_model_nei_evt.fits",
                   "thermal_model_nei_evt.pha",
                   overwrite=True)

    file_answer_testing("EVENTS", "thermal_model_nei_evt.fits", answer_store,
                        answer_dir)
    file_answer_testing("SPECTRUM", "thermal_model_nei_evt.pha", answer_store,
                        answer_dir)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 6
0
def plaw_fit(alpha_sim, answer_store, answer_dir):

    tmpdir = tempfile.mkdtemp()
    curdir = os.getcwd()
    os.chdir(tmpdir)

    nH_sim = 0.02
    norm_sim = 1.0e-4
    redshift = 0.01

    exp_time = (50.0, "ks")
    area = 40000.0
    inst_name = "new_hdxi"

    spec = Spectrum.from_powerlaw(alpha_sim, redshift, norm_sim, 0.1, 10.0, 20000)
    spec.apply_foreground_absorption(nH_sim, model="tbabs")

    spectrum_answer_testing(spec, "power_law_%s.h5" % alpha_sim, answer_store, 
                            answer_dir)

    pt_src_pos = PointSourceModel(30.0, 45.0)
    sim_cat = SimputCatalog.from_models("plaw_model", "plaw_model", spec, pt_src_pos,
                                        exp_time, area, prng=prng)
    sim_cat.write_catalog(overwrite=True)

    instrument_simulator("plaw_model_simput.fits", "plaw_model_%s_evt.fits" % alpha_sim,
                         exp_time, inst_name, [30.0, 45.0], instr_bkgnd=False,
                         ptsrc_bkgnd=False, foreground=False, prng=prng)

    write_spectrum("plaw_model_%s_evt.fits" % alpha_sim,
                   "plaw_model_%s_evt.pha" % alpha_sim,
                   overwrite=True)

    file_answer_testing("EVENTS", "plaw_model_%s_evt.fits" % alpha_sim,
                        answer_store, answer_dir)
    file_answer_testing("SPECTRUM", "plaw_model_%s_evt.pha" % alpha_sim,
                        answer_store, answer_dir)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)