Esempio n. 1
0
def test_read_write():

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

    spec1 = Spectrum.from_powerlaw(1.0, 0.05, 1.0e-4)
    spec1.write_file("test_spec.dat", overwrite=True)
    spec2 = Spectrum.from_file("test_spec.dat")

    assert_allclose(spec1.flux, spec2.flux)
    assert_allclose(spec1.emid, spec2.emid)
    assert_allclose(spec1.ebins, spec2.ebins)
    assert_allclose(spec1.cumspec, spec2.cumspec)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 2
0
def test_read_write():

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

    spec1 = Spectrum.from_powerlaw(1.0, 0.05, 1.0e-4, 0.1, 10.0, 10000)
    spec1.write_file("test_spec.dat", overwrite=True)
    spec2 = Spectrum.from_file("test_spec.dat")

    assert_allclose(spec1.flux, spec2.flux)
    assert_allclose(spec1.emid, spec2.emid)
    assert_allclose(spec1.ebins, spec2.ebins)
    assert_allclose(spec1.cumspec, spec2.cumspec)

    os.chdir(curdir)
    shutil.rmtree(tmpdir)
Esempio n. 3
0
    instrument_simulator, make_background_file, simulate_spectrum
from soxs.background.foreground import hm_astro_bkgnd
from soxs.background.spectra import ConvolvedBackgroundSpectrum
from soxs.spectra import Spectrum
from soxs.response import AuxiliaryResponseFile, RedistributionMatrixFile
from soxs.utils import soxs_files_path
from numpy.random import RandomState
from numpy.testing import assert_allclose
import astropy.io.fits as pyfits
import tempfile
import os
import shutil
import numpy as np
import astropy.units as u

acisi_particle_bkgnd = Spectrum.from_file(
    os.path.join(soxs_files_path, "acisi_particle_bkgnd.h5"))


def test_uniform_bkgnd_scale():
    prng = RandomState(25)
    hdxi_arf = AuxiliaryResponseFile("xrs_hdxi_3x10.arf")
    events, event_params = make_background((50, "ks"), "lynx_hdxi", [30., 45.], 
                                           foreground=True, instr_bkgnd=True,
                                           ptsrc_bkgnd=False, prng=prng)
    ncts = np.logical_and(events["energy"] >= 0.7, events["energy"] <= 2.0).sum()
    t_exp = event_params["exposure_time"]
    fov = (event_params["fov"]*60.0)**2
    S = ncts/t_exp/fov
    dS = np.sqrt(ncts)/t_exp/fov
    foreground = ConvolvedBackgroundSpectrum.convolve(hm_astro_bkgnd, hdxi_arf)
    f_sum = foreground.get_flux_in_band(0.7, 2.0)[0]