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)
def test_simulate_bkgnd_spectrum(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) prng = RandomState(29) hdxi_arf = AuxiliaryResponseFile("xrs_hdxi_3x10.arf") hdxi_rmf = RedistributionMatrixFile("xrs_hdxi.rmf") exp_time = 50000.0 fov = 3600.0 simulate_spectrum(None, "lynx_hdxi", exp_time, "test_bkgnd.pha", instr_bkgnd=True, foreground=True, prng=prng, overwrite=True, bkgnd_area=(fov, "arcsec**2")) ch_min = hdxi_rmf.eb_to_ch(0.7)-hdxi_rmf.cmin ch_max = hdxi_rmf.eb_to_ch(2.0)-hdxi_rmf.cmin with pyfits.open("test_bkgnd.pha") as f: ncts = f["SPECTRUM"].data["COUNTS"][ch_min:ch_max].sum() S = ncts/exp_time/fov dS = np.sqrt(ncts)/exp_time/fov foreground = ConvolvedBackgroundSpectrum.convolve(hm_astro_bkgnd, hdxi_arf) f_sum = foreground.get_flux_in_band(0.7, 2.0)[0] i_sum = acisi_particle_bkgnd.get_flux_in_band(0.7, 2.0)[0]*(u.cm/u.arcmin)**2 b_sum = (f_sum+i_sum).to_value("ph/(arcsec**2*s)") assert np.abs(S-b_sum) < 1.645*dS os.chdir(curdir) shutil.rmtree(tmpdir)
def test_simulate_bkgnd_spectrum(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) prng = RandomState(29) hdxi_arf = AuxiliaryResponseFile("xrs_hdxi_3x10.arf") hdxi_rmf = RedistributionMatrixFile("xrs_hdxi.rmf") exp_time = 50000.0 fov = 3600.0 simulate_spectrum(None, "hdxi", exp_time, "test_bkgnd.pha", instr_bkgnd=True, foreground=True, prng=prng, overwrite=True, bkgnd_area=(fov, "arcsec**2")) ch_min = hdxi_rmf.e_to_ch(0.7)-hdxi_rmf.cmin ch_max = hdxi_rmf.e_to_ch(2.0)-hdxi_rmf.cmin f = pyfits.open("test_bkgnd.pha") ncts = f["SPECTRUM"].data["COUNTS"][ch_min:ch_max].sum() f.close() S = ncts/exp_time/fov dS = np.sqrt(ncts)/exp_time/fov foreground = ConvolvedBackgroundSpectrum(hm_astro_bkgnd, hdxi_arf) f_sum = foreground.get_flux_in_band(0.7, 2.0)[0] i_sum = acisi_particle_bkgnd.get_flux_in_band(0.7, 2.0)[0] b_sum = (f_sum+i_sum).to("ph/(arcsec**2*s)").value assert np.abs(S-b_sum) < 1.645*dS os.chdir(curdir) shutil.rmtree(tmpdir)
def test_thermal_from_spectrum(answer_store, answer_dir): prng = RandomState(89) tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) inst = get_instrument_from_registry(inst_name) simulate_spectrum(spec, inst["name"], exp_time, "thermal_model_spec_evt.pha", prng=prng) file_answer_testing("SPECTRUM", "thermal_model_spec_evt.pha", answer_store, answer_dir) os.chdir(curdir) shutil.rmtree(tmpdir)
def test_nolines_thermal_from_spectrum(answer_store, answer_dir): prng = RandomState(101) tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) inst = get_instrument_from_registry(inst_name) simulate_spectrum(spec_nolines, inst["name"], exp_time, "nolines_thermal_model_evt.pha", prng=prng) file_answer_testing("SPECTRUM", "nolines_thermal_model_evt.pha", answer_store, answer_dir) os.chdir(curdir) shutil.rmtree(tmpdir)