Esempio n. 1
0
def test_flux_map_read_write_missing_reference_model(tmp_path, wcs_flux_map,
                                                     reference_model):
    fluxmap = FluxMaps(wcs_flux_map, reference_model)
    fluxmap.write(tmp_path / "tmp.fits")

    hdulist = fits.open(tmp_path / "tmp.fits")
    hdulist[0].header["MODEL"] = "non_existent"

    with pytest.raises(FileNotFoundError):
        new_fluxmap = FluxMaps.from_hdulist(hdulist)
Esempio n. 2
0
def test_flux_map_read_write_no_reference_model(tmp_path, wcs_flux_map, caplog):
    fluxmap = FluxMaps(wcs_flux_map)

    fluxmap.write(tmp_path / "tmp.fits")
    new_fluxmap = FluxMaps.read(tmp_path / "tmp.fits")

    assert new_fluxmap.reference_model.spectral_model.tag[0] == "PowerLawSpectralModel"
    assert "WARNING" in [_.levelname for _ in caplog.records]
    assert f"No reference model set for FluxMaps." in [
        _.message for _ in caplog.records
    ]
Esempio n. 3
0
def test_flux_map_read_write_gti(tmp_path, partial_wcs_flux_map, reference_model):
    start = u.Quantity([1, 2], "min")
    stop = u.Quantity([1.5, 2.5], "min")
    gti = GTI.create(start, stop)

    fluxmap = FluxMaps(partial_wcs_flux_map, reference_model, gti=gti)

    fluxmap.write(tmp_path / "tmp.fits", sed_type="dnde")
    new_fluxmap = FluxMaps.read(tmp_path / "tmp.fits")

    assert len(new_fluxmap.gti.table) == 2
    assert_allclose(gti.table["START"], start.to_value("s"))
Esempio n. 4
0
def test_partial_flux_map_read_write(tmp_path, partial_wcs_flux_map,
                                     reference_model, sed_type):
    fluxmap = FluxMaps(partial_wcs_flux_map, reference_model)

    fluxmap.write(tmp_path / "tmp.fits", sed_type=sed_type)
    new_fluxmap = FluxMaps.read(tmp_path / "tmp.fits")

    assert_allclose(new_fluxmap.norm.data[:, 0, 0], [1, 1])
    assert_allclose(new_fluxmap.norm_err.data[:, 0, 0], [0.1, 0.1])

    # check model
    assert new_fluxmap.reference_model.spectral_model.tag[
        0] == "PowerLawSpectralModel"
    assert new_fluxmap.reference_model.spectral_model.index.value == 2

    # check existence and content of additional map
    assert_allclose(new_fluxmap.data["sqrt_ts"].data, 1.0)

    # the TS map shouldn't exist
    with pytest.raises(KeyError):
        new_fluxmap.data["ts"]
Esempio n. 5
0
def test_flux_map_read_write(tmp_path, wcs_flux_map, logpar_reference_model,
                             sed_type):
    fluxmap = FluxMaps(wcs_flux_map, logpar_reference_model)

    fluxmap.write(tmp_path / "tmp.fits", sed_type=sed_type)
    new_fluxmap = FluxMaps.read(tmp_path / "tmp.fits")

    assert_allclose(new_fluxmap.norm.data[:, 0, 0], [1, 1])
    assert_allclose(new_fluxmap.norm_err.data[:, 0, 0], [0.1, 0.1])
    assert_allclose(new_fluxmap.norm_errn.data[:, 0, 0], [0.2, 0.2])
    assert_allclose(new_fluxmap.norm_ul.data[:, 0, 0], [2, 2])

    # check model
    assert new_fluxmap.reference_model.spectral_model.tag[
        0] == "LogParabolaSpectralModel"
    assert new_fluxmap.reference_model.spectral_model.alpha.value == 1.5
    assert new_fluxmap.reference_model.spectral_model.beta.value == 0.5
    assert new_fluxmap.reference_model.spectral_model.amplitude.value == 2e-12

    # check existence and content of additional map
    assert_allclose(new_fluxmap.data["sqrt_ts"].data, 1.0)