def test_annulus(answer_store, answer_dir): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) r_in = 10.0 r_out = 30.0 ann_pos = AnnulusModel(ra0, dec0, r_in, r_out) ann_src = SimputPhotonList.from_models("ann", spec, ann_pos, exp_time, area, prng=prng) sim_cat = SimputCatalog.from_source("ann_simput.fits", ann_src, overwrite=True) instrument_simulator("ann_simput.fits", "ann_evt.fits", exp_time, "lynx_hdxi", [ra0, dec0], ptsrc_bkgnd=False, instr_bkgnd=False, foreground=False, prng=prng) write_radial_profile("ann_evt.fits", "ann_evt_profile.fits", [ra0, dec0], 1.1*r_in, 0.9*r_out, 100, ctr_type="celestial", emin=0.5, emax=7.0, overwrite=True) file_answer_testing("EVENTS", "ann_evt.fits", answer_store, answer_dir) file_answer_testing("PROFILE", "ann_evt_profile.fits", answer_store, answer_dir) os.chdir(curdir) shutil.rmtree(tmpdir)
def test_beta_model(answer_store, answer_dir): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) prng = 32 r_c = 20.0 beta = 1.0 exp_time = Quantity(500.0, "ks") beta_src_pos = BetaModel(ra0, dec0, r_c, beta) beta_src = SimputPhotonList.from_models("beta", spec, beta_src_pos, exp_time, area, prng=prng) sim_cat = SimputCatalog.from_source("beta_simput.fits", beta_src, overwrite=True) instrument_simulator("beta_simput.fits", "beta_evt.fits", exp_time, "chandra_acisi_cy0", [ra0, dec0], ptsrc_bkgnd=False, instr_bkgnd=False, foreground=False, prng=prng) write_radial_profile("beta_evt.fits", "beta_evt_profile.fits", [ra0, dec0], 0.0, 100.0, 200, ctr_type="celestial", emin=0.5, emax=7.0, overwrite=True) file_answer_testing("EVENTS", "beta_evt.fits", answer_store, answer_dir) file_answer_testing("PROFILE", "beta_evt_profile.fits", answer_store, answer_dir) os.chdir(curdir) shutil.rmtree(tmpdir)
def test_point_source(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) pt_src = SimputSpectrum.from_spectrum("pt_src", spec, ra0, dec0) cat = SimputCatalog.from_source("pt_src_simput.fits", pt_src, overwrite=True) inst = get_instrument_from_registry("lynx_hdxi") inst["name"] = "hdxi_big_psf" inst["psf"] = ["gaussian", 5.0] add_instrument_to_registry(inst) instrument_simulator("pt_src_simput.fits", "pt_src_evt.fits", exp_time, "hdxi_big_psf", [ra0, dec0], ptsrc_bkgnd=False, instr_bkgnd=False, foreground=False, prng=prng) psf_scale = inst["psf"][1] dtheta = inst["fov"]*60.0/inst["num_pixels"] f = pyfits.open("pt_src_evt.fits") x = f["EVENTS"].data["X"] y = f["EVENTS"].data["Y"] f.close() scalex = np.std(x)*sigma_to_fwhm*dtheta scaley = np.std(y)*sigma_to_fwhm*dtheta assert (scalex - psf_scale)/psf_scale < 0.03 assert (scaley - psf_scale)/psf_scale < 0.03 os.chdir(curdir) shutil.rmtree(tmpdir)
def test_annulus(answer_store, answer_dir): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) r_in = 10.0 r_out = 30.0 ann_pos = AnnulusModel(ra0, dec0, r_in, r_out) sim_cat = SimputCatalog.from_models("ann", "ann", spec, ann_pos, exp_time, area, prng=prng) sim_cat.write_catalog(overwrite=True) instrument_simulator("ann_simput.fits", "ann_evt.fits", exp_time, "hdxi", [ra0, dec0], ptsrc_bkgnd=False, instr_bkgnd=False, foreground=False, prng=prng) write_radial_profile("ann_evt.fits", "ann_evt_profile.fits", [ra0, dec0], 1.1*r_in, 0.9*r_out, 100, ctr_type="celestial", emin=0.5, emax=7.0, overwrite=True) file_answer_testing("EVENTS", "ann_evt.fits", answer_store, answer_dir) file_answer_testing("PROFILE", "ann_evt_profile.fits", answer_store, answer_dir) os.chdir(curdir) shutil.rmtree(tmpdir)
def test_beta_model_flux(answer_store, answer_dir): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) r_c = 20.0 beta = 1.0 prng = 34 beta_src_pos = BetaModel(ra0, dec0, r_c, beta) sim_cat = SimputCatalog.from_models("beta", "beta", spec, beta_src_pos, exp_time, area, prng=prng) sim_cat.write_catalog(overwrite=True) instrument_simulator("beta_simput.fits", "beta_flux_evt.fits", exp_time, "acisi_cy0", [ra0, dec0], ptsrc_bkgnd=False, instr_bkgnd=False, foreground=False, roll_angle=37.0, prng=prng) wspec = spec.new_spec_from_band(0.5, 7.0) make_exposure_map("beta_flux_evt.fits", "beta_expmap.fits", wspec.emid.value, weights=wspec.flux.value, overwrite=True) write_radial_profile("beta_flux_evt.fits", "beta_flux_evt_profile.fits", [ra0, dec0], 0.0, 100.0, 200, ctr_type="celestial", emin=0.5, emax=7.0, expmap_file="beta_expmap.fits", overwrite=True) file_answer_testing("EVENTS", "beta_flux_evt.fits", answer_store, answer_dir) file_answer_testing("PROFILE", "beta_flux_evt_profile.fits", answer_store, answer_dir) os.chdir(curdir) shutil.rmtree(tmpdir)
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)
def test_beta_model(answer_store, answer_dir): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) prng = 32 r_c = 20.0 beta = 1.0 exp_time = Quantity(500.0, "ks") beta_src_pos = BetaModel(ra0, dec0, r_c, beta) sim_cat = SimputCatalog.from_models("beta", "beta", spec, beta_src_pos, exp_time, area, prng=prng) sim_cat.write_catalog(overwrite=True) instrument_simulator("beta_simput.fits", "beta_evt.fits", exp_time, "acisi_cy0", [ra0, dec0], ptsrc_bkgnd=False, instr_bkgnd=False, foreground=False, prng=prng) write_radial_profile("beta_evt.fits", "beta_evt_profile.fits", [ra0, dec0], 0.0, 100.0, 200, ctr_type="celestial", emin=0.5, emax=7.0, overwrite=True) file_answer_testing("EVENTS", "beta_evt.fits", answer_store, answer_dir) file_answer_testing("PROFILE", "beta_evt_profile.fits", answer_store, answer_dir) os.chdir(curdir) shutil.rmtree(tmpdir)
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)
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)
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)
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)
def test_append(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) exp_time = (50.0, "ks") area = (4.0, "m**2") ra0 = 30.0 dec0 = 45.0 spec = Spectrum.from_powerlaw(1.1, 0.05, 1.0e-4, 0.1, 10.0, 10000) pos1 = PointSourceModel(ra0+0.05, dec0+0.05) pos2 = PointSourceModel(ra0-0.05, dec0-0.05) pl1 = SimputPhotonList.from_models("pt_src1", spec, pos1, exp_time, area) pl2 = SimputPhotonList.from_models("pt_src2", spec, pos2, exp_time, area) sc = SimputCatalog.from_source("pt_src_simput.fits", pl1, src_filename="pt_src1_phlist.fits", overwrite=True) sc.append(pl2, src_filename="pt_src2_phlist.fits", overwrite=True) assert os.path.exists("pt_src1_phlist.fits") assert os.path.exists("pt_src2_phlist.fits") assert os.path.exists("pt_src_simput.fits") f = pyfits.open("pt_src_simput.fits") cat = f["SRC_CAT"].data["SPECTRUM"] assert cat[0] == "pt_src1_phlist.fits[PHLIST,1]" assert cat[1] == "pt_src2_phlist.fits[PHLIST,1]" f.close() os.chdir(curdir) shutil.rmtree(tmpdir)
def test_point_source(): tmpdir = tempfile.mkdtemp() curdir = os.getcwd() os.chdir(tmpdir) pt_src_pos = PointSourceModel(ra0, dec0) sim_cat = SimputCatalog.from_models("pt_src", "pt_src", spec, pt_src_pos, exp_time, area, prng=prng) sim_cat.write_catalog(overwrite=True) inst = get_instrument_from_registry("hdxi") inst["name"] = "hdxi_big_psf" inst["psf"] = ["gaussian", 5.0] add_instrument_to_registry(inst) instrument_simulator("pt_src_simput.fits", "pt_src_evt.fits", exp_time, "hdxi_big_psf", [ra0, dec0], ptsrc_bkgnd=False, instr_bkgnd=False, foreground=False, prng=prng) psf_scale = inst["psf"][1] dtheta = inst["fov"]*60.0/inst["num_pixels"] f = pyfits.open("pt_src_evt.fits") x = f["EVENTS"].data["X"] y = f["EVENTS"].data["Y"] f.close() scalex = np.std(x)*sigma_to_fwhm*dtheta scaley = np.std(y)*sigma_to_fwhm*dtheta assert (scalex - psf_scale)/psf_scale < 0.03 assert (scaley - psf_scale)/psf_scale < 0.03 os.chdir(curdir) shutil.rmtree(tmpdir)
def make_point_sources_file(filename, name, exp_time, fov, sky_center, absorb_model="wabs", nH=0.05, area=40000.0, prng=None, append=False, overwrite=False, src_filename=None, input_sources=None, output_sources=None): """ Make a SIMPUT catalog made up of contributions from point sources. Parameters ---------- filename : string The filename for the SIMPUT catalog. name : string The name of the SIMPUT photon list. exp_time : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The exposure time of the observation in seconds. fov : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The field of view in arcminutes. sky_center : array-like The center RA, Dec of the field of view in degrees. absorb_model : string, optional The absorption model to use, "wabs" or "tbabs". Default: "wabs" nH : float, (value, unit) tuple, or :class:`~astropy.units.Quantity`, optional The hydrogen column in units of 10**22 atoms/cm**2. Default: 0.05 area : float, (value, unit) tuple, or :class:`~astropy.units.Quantity`, optional The effective area in cm**2. It must be large enough so that a sufficiently large sample is drawn for the ARF. Default: 40000. prng : :class:`~numpy.random.RandomState` object, integer, or None A pseudo-random number generator. Typically will only be specified if you have a reason to generate the same set of random numbers, such as for a test. Default is None, which sets the seed based on the system time. append : boolean, optional If True, the photon list source will be appended to an existing SIMPUT catalog. Default: False overwrite : boolean, optional Set to True to overwrite previous files. Default: False src_filename : string, optional If set, this will be the filename to write the source to. By default, the source will be written to the same file as the SIMPUT catalog. input_sources : string, optional If set to a filename, input the source positions, fluxes, and spectral indices from an ASCII table instead of generating them. Default: None output_sources : string, optional If set to a filename, output the properties of the sources within the field of view to a file. Default: None """ events = make_ptsrc_background(exp_time, fov, sky_center, absorb_model=absorb_model, nH=nH, area=area, input_sources=input_sources, output_sources=output_sources, prng=prng) phlist = SimputPhotonList(events["ra"], events["dec"], events["energy"], events["flux"], name=name) if append: cat = SimputCatalog.from_file(filename) cat.append(phlist, src_filename=src_filename, overwrite=overwrite) else: cat = SimputCatalog.from_source(filename, phlist, src_filename=src_filename, overwrite=overwrite) return cat
def make_cosmological_sources_file(filename, name, exp_time, fov, sky_center, cat_center=None, absorb_model="wabs", nH=0.05, area=40000.0, overwrite=False, output_sources=None, write_regions=None, src_filename=None, prng=None, append=False): r""" Make a SIMPUT catalog made up of contributions from galaxy clusters, galaxy groups, and galaxies. Parameters ---------- filename : string The filename for the SIMPUT catalog. name : string The name of the SIMPUT photon list. exp_time : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The exposure time of the observation in seconds. fov : float, (value, unit) tuple, or :class:`~astropy.units.Quantity` The field of view in arcminutes. sky_center : array-like The center RA, Dec of the field of view in degrees. cat_center : array-like The center of the field in the coordinates of the halo catalog, which range from -5.0 to 5.0 degrees along both axes. If None is given, a center will be randomly chosen. absorb_model : string, optional The absorption model to use, "wabs" or "tbabs". Default: "wabs" nH : float, (value, unit) tuple, or :class:`~astropy.units.Quantity`, optional The hydrogen column in units of 10**22 atoms/cm**2. Default: 0.05 area : float, (value, unit) tuple, or :class:`~astropy.units.Quantity`, optional The effective area in cm**2. It must be large enough so that a sufficiently large sample is drawn for the ARF. Default: 40000. overwrite : boolean, optional Set to True to overwrite previous files. Default: False output_sources : string, optional If set to a filename, output the properties of the sources within the field of view to an ASCII file. Default: None write_regions : string, optional If set to a filename, output circle ds9 regions corresponding to the positions of the halos with radii corresponding to their R500 projected on the sky. Default: None src_filename : string, optional If set, this will be the filename to write the source to. By default, the source will be written to the same file as the SIMPUT catalog prng : :class:`~numpy.random.RandomState` object, integer, or None A pseudo-random number generator. Typically will only be specified if you have a reason to generate the same set of random numbers, such as for a test. Default is None, which sets the seed based on the system time. append : boolean, optional If True, the photon list source will be appended to an existing SIMPUT catalog. Default: False """ events = make_cosmological_sources(exp_time, fov, sky_center, cat_center=cat_center, absorb_model=absorb_model, nH=nH, area=area, output_sources=output_sources, write_regions=write_regions,prng=prng) phlist = SimputPhotonList(events["ra"], events["dec"], events["energy"], events["flux"], name=name) if append: cat = SimputCatalog.from_file(filename) cat.append(phlist, src_filename=src_filename, overwrite=overwrite) else: cat = SimputCatalog.from_source(filename, phlist, src_filename=src_filename, overwrite=overwrite) return cat