Ejemplo n.º 1
0
def test_pha_write_no_bkg():
    with within_directory(__example_dir):

        # custom remove background
        f = fits.open("test.pha")
        f["SPECTRUM"].data["BACKFILE"] = "NONE"
        f.writeto("test_pha_nobkg.pha", overwrite=True)

        ogip = OGIPLike("test_ogip", observation="test_pha_nobkg.pha{1}")

        ogip.write_pha("test_write_nobkg", overwrite=True)

        written_ogip = OGIPLike("write_ogip", observation="test_write_nobkg.pha{1}")

        pha_info = written_ogip.get_pha_files()

        for key in ["pha"]:
            assert isinstance(pha_info[key], PHASpectrum)

        f = fits.open("test_write_nobkg.pha")
        assert f["SPECTRUM"].data["BACKFILE"][0] == "NONE"

        assert pha_info["pha"].background_file is None
        assert pha_info["pha"].ancillary_file is None
        assert pha_info["pha"].instrument == "GBM_NAI_03"
        assert pha_info["pha"].mission == "GLAST"
        assert pha_info["pha"].is_poisson == True
        assert pha_info["pha"].n_channels == len(pha_info["pha"].rates)
Ejemplo n.º 2
0
def test_loading_a_loose_ogip_pha_file():

    with within_directory(__example_dir):
        ogip = OGIPLike("test_ogip", observation="example_integral.pha")

        pha_info = ogip.get_pha_files()

        assert ogip.name == "test_ogip"
        assert ogip.n_data_points == sum(ogip._mask)
        assert sum(ogip._mask) == ogip.n_data_points
        # assert ogip.tstart is None
        # assert ogip.tstop is None
        assert "cons_test_ogip" in ogip.nuisance_parameters
        assert ogip.nuisance_parameters["cons_test_ogip"].fix == True
        assert ogip.nuisance_parameters["cons_test_ogip"].free == False

        assert "pha" in pha_info
        # assert 'bak' in pha_info
        assert "rsp" in pha_info

        ogip.__repr__()
Ejemplo n.º 3
0
def test_pha_write():
    with within_directory(__example_dir):

        ogip = OGIPLike("test_ogip", observation="test.pha{1}")

        ogip.write_pha("test_write", overwrite=True)

        written_ogip = OGIPLike("write_ogip", observation="test_write.pha{1}")

        pha_info = written_ogip.get_pha_files()

        for key in ["pha", "bak"]:

            assert isinstance(pha_info[key], PHASpectrum)

        assert pha_info["pha"].background_file == "test_bak.pha{1}"
        assert pha_info["pha"].ancillary_file is None
        assert pha_info["pha"].instrument == "GBM_NAI_03"
        assert pha_info["pha"].mission == "GLAST"
        assert pha_info["pha"].is_poisson == True
        assert pha_info["pha"].n_channels == len(pha_info["pha"].rates)
Ejemplo n.º 4
0
def test_loading_a_generic_pha_file():

    with within_directory(__example_dir):
        ogip = OGIPLike("test_ogip", observation="test.pha{1}")

        pha_info = ogip.get_pha_files()

        assert ogip.name == "test_ogip"
        assert ogip.n_data_points == sum(ogip._mask)
        assert sum(ogip._mask) == ogip.n_data_points
        assert ogip.tstart == 0.0
        assert ogip.tstop == 9.95012
        assert "cons_test_ogip" in ogip.nuisance_parameters
        assert ogip.nuisance_parameters["cons_test_ogip"].fix == True
        assert ogip.nuisance_parameters["cons_test_ogip"].free == False

        assert "pha" in pha_info
        assert "bak" in pha_info
        assert "rsp" in pha_info

        ogip.__repr__()
Ejemplo n.º 5
0
def test_pha_write():
    with within_directory(__example_dir):

        ogip = OGIPLike('test_ogip', observation='test.pha{1}')

        ogip.write_pha('test_write', overwrite=True)

        written_ogip = OGIPLike('write_ogip', observation='test_write.pha{1}')

        pha_info = written_ogip.get_pha_files()

        for key in ['pha', 'bak']:

            assert isinstance(pha_info[key], PHASpectrum)

        assert pha_info['pha'].background_file == 'test_bak.pha{1}'
        assert pha_info['pha'].ancillary_file is None
        assert pha_info['pha'].instrument == 'GBM_NAI_03'
        assert pha_info['pha'].mission == 'GLAST'
        assert pha_info['pha'].is_poisson == True
        assert pha_info['pha'].n_channels == len(pha_info['pha'].rates)
Ejemplo n.º 6
0
def test_loading_a_generic_pha_file():

    with within_directory(__example_dir):
        ogip = OGIPLike('test_ogip', observation='test.pha{1}')

        pha_info = ogip.get_pha_files()

        assert ogip.name == 'test_ogip'
        assert ogip.n_data_points == sum(ogip._mask)
        assert sum(ogip._mask) == ogip.n_data_points
        assert ogip.tstart == 0.
        assert ogip.tstop == 9.95012
        assert 'cons_test_ogip' in ogip.nuisance_parameters
        assert ogip.nuisance_parameters['cons_test_ogip'].fix == True
        assert ogip.nuisance_parameters['cons_test_ogip'].free == False

        assert 'pha' in pha_info
        assert 'bak' in pha_info
        assert 'rsp' in pha_info

        ogip.__repr__()
Ejemplo n.º 7
0
def test_pha_files_in_generic_ogip_constructor_spec_number_in_arguments():
    with within_directory(__example_dir):
        ogip = OGIPLike("test_ogip", observation="test.pha", spectrum_number=1)
        ogip.set_active_measurements("all")

        pha_info = ogip.get_pha_files()

        for key in ["pha", "bak"]:

            assert isinstance(pha_info[key], PHASpectrum)

        assert pha_info["pha"].background_file == "test_bak.pha{1}"
        assert pha_info["pha"].ancillary_file is None
        assert pha_info["pha"].instrument == "GBM_NAI_03"
        assert pha_info["pha"].mission == "GLAST"
        assert pha_info["pha"].is_poisson == True
        assert pha_info["pha"].n_channels == ogip.n_data_points
        assert pha_info["pha"].n_channels == len(pha_info["pha"].rates)

        # Test that Poisson rates cannot call rate error
        assert pha_info["pha"].rate_errors is None

        assert (
            sum(pha_info["pha"].sys_errors == np.zeros_like(pha_info["pha"].rates))
            == pha_info["bak"].n_channels
        )
        assert (
            pha_info["pha"].response_file.split("/")[-1]
            == "glg_cspec_n3_bn080916009_v07.rsp"
        )
        assert pha_info["pha"].scale_factor == 1.0

        assert pha_info["bak"].background_file is None

        # Test that we cannot get a bak file
        #
        # with pytest.raises(KeyError):
        #
        #     _ = pha_info['bak'].background_file
        #
        # Test that we cannot get a anc file
        # with pytest.raises(KeyError):
        #
        #     _ = pha_info['bak'].ancillary_file

        assert pha_info["bak"].response_file is None

        assert pha_info["bak"].ancillary_file is None

        # # Test that we cannot get a RSP file
        # with pytest.raises(AttributeError):
        #      _ = pha_info['bak'].response_file

        assert pha_info["bak"].instrument == "GBM_NAI_03"
        assert pha_info["bak"].mission == "GLAST"

        assert pha_info["bak"].is_poisson == False

        assert pha_info["bak"].n_channels == ogip.n_data_points
        assert pha_info["bak"].n_channels == len(pha_info["pha"].rates)

        assert len(pha_info["bak"].rate_errors) == pha_info["bak"].n_channels

        assert (
            sum(pha_info["bak"].sys_errors == np.zeros_like(pha_info["pha"].rates))
            == pha_info["bak"].n_channels
        )

        assert pha_info["bak"].scale_factor == 1.0

        assert isinstance(pha_info["rsp"], OGIPResponse)
Ejemplo n.º 8
0
def test_pha_files_in_generic_ogip_constructor_spec_number_in_file_name():
    with within_directory(__example_dir):

        ogip = OGIPLike('test_ogip', observation='test.pha{1}')
        ogip.set_active_measurements('all')
        pha_info = ogip.get_pha_files()

        for key in ['pha', 'bak']:

            assert isinstance(pha_info[key], PHASpectrum)

        assert pha_info['pha'].background_file == 'test_bak.pha{1}'
        assert pha_info['pha'].ancillary_file is None
        assert pha_info['pha'].instrument == 'GBM_NAI_03'
        assert pha_info['pha'].mission == 'GLAST'
        assert pha_info['pha'].is_poisson == True
        assert pha_info['pha'].n_channels == ogip.n_data_points
        assert pha_info['pha'].n_channels == len(pha_info['pha'].rates)

        # Test that Poisson rates cannot call rate error
        assert pha_info['pha'].rate_errors is None

        assert sum(pha_info['pha'].sys_errors == np.zeros_like(
            pha_info['pha'].rates)) == pha_info['bak'].n_channels

        assert pha_info['pha'].response_file.split(
            '/')[-1] == 'glg_cspec_n3_bn080916009_v07.rsp'
        assert pha_info['pha'].scale_factor == 1.0

        assert pha_info['bak'].background_file is None

        # Test that we cannot get a bak file
        #
        #
        # with pytest.raises(KeyError):
        #
        #     _ = pha_info['bak'].background_file

        # Test that we cannot get a anc file
        # with pytest.raises(KeyError):
        #
        #     _ = pha_info['bak'].ancillary_file

        # Test that we cannot get a RSP file

        assert pha_info['bak'].response_file is None

        assert pha_info['bak'].ancillary_file is None

        # with pytest.raises(AttributeError):
        #      _ = pha_info['bak'].response_file

        assert pha_info['bak'].instrument == 'GBM_NAI_03'
        assert pha_info['bak'].mission == 'GLAST'

        assert pha_info['bak'].is_poisson == False

        assert pha_info['bak'].n_channels == ogip.n_data_points
        assert pha_info['bak'].n_channels == len(pha_info['pha'].rates)

        assert len(pha_info['bak'].rate_errors) == pha_info['bak'].n_channels

        assert sum(pha_info['bak'].sys_errors == np.zeros_like(
            pha_info['pha'].rates)) == pha_info['bak'].n_channels

        assert pha_info['bak'].scale_factor == 1.0

        assert isinstance(pha_info['rsp'], OGIPResponse)