def empty_dataset(source_pos_radec, map_geom, e_reco_binning, livetime,
                          irf_file, offset):

            source_pos_ra = source_pos_radec["ra"]
            source_pos_dec = source_pos_radec["dec"]

            source = SkyCoord(source_pos_ra,
                              source_pos_dec,
                              unit="deg",
                              frame="icrs")

            e_reco_min = u.Quantity(e_reco_binning["e_reco_min"]).to("TeV")
            e_reco_min = e_reco_min.value
            e_reco_max = u.Quantity(e_reco_binning["e_reco_max"]).to("TeV")
            e_reco_max = e_reco_max.value
            n_e_reco = e_reco_binning["n_e_reco"]

            energy_axis = MapAxis.from_edges(np.logspace(
                np.log10(e_reco_min), np.log10(e_reco_max), n_e_reco),
                                             unit="TeV",
                                             name="energy",
                                             interp="log")

            geom = WcsGeom.create(
                skydir=source,
                binsz=u.Quantity(map_geom["binsize"]).to("deg").value,
                width=(u.Quantity(map_geom["width"]).to("deg").value,
                       u.Quantity(map_geom["width"]).to("deg").value),
                frame="icrs",
                axes=[energy_axis])

            energy_axis_true = MapAxis.from_edges(np.logspace(
                np.log10(e_reco_min), np.log10(e_reco_max), n_e_reco),
                                                  unit="TeV",
                                                  name="energy",
                                                  interp="log")

            pointing = SkyCoord(u.Quantity(source_pos_ra).to("deg"),
                                u.Quantity(source_pos_dec).to("deg") + offset,
                                frame="icrs",
                                unit="deg")

            irfs = load_cta_irfs(irf_file)

            obs = Observation.create(pointing=pointing,
                                     livetime=livetime,
                                     irfs=irfs)

            empty = MapDataset.create(geom, energy_axis_true=energy_axis_true)
            maker = MapDatasetMaker(
                selection=["exposure", "background", "psf", "edisp"])
            maker_safe_mask = SafeMaskMaker(
                methods=["offset-max"],
                offset_max=u.quantity.Quantity(map_geom["width"]) +
                1.0 * u.deg)

            dataset = maker.run(empty, obs)
            dataset = maker_safe_mask.run(dataset, obs)

            return dataset
Ejemplo n.º 2
0
def test_cta_irf():
    """Test that CTA IRFs can be loaded and evaluated."""
    irf = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    energy = Quantity(1, "TeV")
    offset = Quantity(3, "deg")

    val = irf["aeff"].data.evaluate(energy_true=energy, offset=offset)
    assert_allclose(val.value, 545269.4675, rtol=1e-5)
    assert val.unit == "m2"

    val = irf["edisp"].data.evaluate(offset=offset,
                                     energy_true=energy,
                                     migra=1)
    assert_allclose(val.value, 3183.6882, rtol=1e-5)
    assert val.unit == ""

    psf = irf["psf"].psf_at_energy_and_theta(energy=energy, theta=offset)
    val = psf(Quantity(0.1, "deg"))
    assert_allclose(val, 3.56989, rtol=1e-5)

    val = irf["bkg"].data.evaluate(energy=energy,
                                   fov_lon=offset,
                                   fov_lat="0 deg")
    assert_allclose(val.value, 9.400071e-05, rtol=1e-5)
    assert val.unit == "1 / (MeV s sr)"
Ejemplo n.º 3
0
def test_observation_cta_1dc():
    ontime = 5.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    t_ref = Time('2020-01-01T00:00:00')
    tstart = 20 * u.hour
    location = EarthLocation(lon="-70d18m58.84s",
                             lat="-24d41m0.34s",
                             height="2000m")

    obs = Observation.create(
        pointing,
        irfs=irfs,
        deadtime_fraction=0.1,
        tstart=tstart,
        tstop=tstart + ontime,
        reference_time=t_ref,
        location=location,
    )

    assert_skycoord_allclose(obs.pointing_radec, pointing.icrs)
    assert_allclose(obs.observation_live_time_duration, 0.9 * ontime)
    assert_allclose(obs.target_radec.ra, np.nan)
    assert not np.isnan(obs.pointing_zen)
    assert_allclose(obs.muoneff, 1)
Ejemplo n.º 4
0
def test_events_datastore(tmp_path, dataset, models):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 10.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(
        obs_id=1001,
        pointing=pointing,
        livetime=livetime,
        irfs=irfs,
        location=LOCATION,
    )

    dataset.models = models
    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    primary_hdu = fits.PrimaryHDU()
    hdu_evt = fits.BinTableHDU(events.table)
    hdu_gti = fits.BinTableHDU(dataset.gti.table, name="GTI")
    hdu_all = fits.HDUList([primary_hdu, hdu_evt, hdu_gti])
    hdu_all.writeto(str(tmp_path / "events.fits"))

    DataStore.from_events_files([str(tmp_path / "events.fits")])
Ejemplo n.º 5
0
def test_cta_irf_alpha_config_north():
    """Test that CTA IRFs can be loaded and evaluated."""
    irf = load_cta_irfs(
        "$GAMMAPY_DATA/cta-caldb/Prod5-North-20deg-AverageAz-4LSTs09MSTs.180000s-v0.1.fits.gz"
    )

    energy = Quantity(1, "TeV")
    offset = Quantity(3, "deg")

    val = irf["aeff"].evaluate(energy_true=energy, offset=offset)
    assert_allclose(val.value, 277301.26585409, rtol=1e-5)
    assert val.unit == "m2"

    val = irf["edisp"].evaluate(offset=offset, energy_true=energy, migra=1)
    assert_allclose(val.value, 0.04070749, rtol=1e-5)
    assert val.unit == ""

    val = irf["psf"].evaluate(rad=Quantity(0.1, "deg"),
                              energy_true=energy,
                              offset=offset)
    assert_allclose(val, 6.20107085 * u.Unit("deg-2"), rtol=1e-5)

    val = irf["bkg"].evaluate(energy=energy, fov_lon=offset, fov_lat="0 deg")
    assert_allclose(val.value, 5.43334659e-05, rtol=1e-5)
    assert val.unit == "1 / (MeV s sr)"
Ejemplo n.º 6
0
def simulate_map_dataset(random_state=0, name=None):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    skydir = SkyCoord("0 deg", "0 deg", frame="galactic")
    edges = np.logspace(-1, 2, 15) * u.TeV
    energy_axis = MapAxis.from_edges(edges=edges, name="energy", interp="log")

    geom = WcsGeom.create(
        skydir=skydir, width=(4, 4), binsz=0.1, axes=[energy_axis], frame="galactic"
    )

    gauss = GaussianSpatialModel(
        lon_0="0 deg", lat_0="0 deg", sigma="0.4 deg", frame="galactic"
    )
    pwl = PowerLawSpectralModel(amplitude="1e-11 cm-2 s-1 TeV-1")
    skymodel = SkyModel(spatial_model=gauss, spectral_model=pwl, name="source")

    obs = Observation.create(pointing=skydir, livetime=1 * u.h, irfs=irfs)
    empty = MapDataset.create(geom, name=name)
    maker = MapDatasetMaker(selection=["exposure", "background", "psf", "edisp"])
    dataset = maker.run(empty, obs)

    dataset.models.append(skymodel)
    dataset.fake(random_state=random_state)
    return dataset
    def __init__(self, lambda_true: u.quantity.Quantity, index_true: float,
                 normalization_true: u.quantity.Quantity,
                 livetime: u.quantity.Quantity, pointing_galactic: dict,
                 e_reco_binning: dict, on_region_radius: str, irf_file: str):

        normalization_true = normalization_true.to("cm-2 s-1 TeV-1")
        self.lambda_true = lambda_true
        self.index_true = index_true
        self.normalization_true = normalization_true

        pointing_l = pointing_galactic["pointing_l"]
        pointing_b = pointing_galactic["pointing_b"]
        pointing = SkyCoord(pointing_l,
                            pointing_b,
                            unit="deg",
                            frame="galactic")
        e_reco_min = u.Quantity(e_reco_binning["e_reco_min"]).to("TeV").value
        e_reco_max = u.Quantity(e_reco_binning["e_reco_max"]).to("TeV").value
        n_e_reco = e_reco_binning["n_e_reco"]
        self.energy_axis = np.logspace(np.log10(e_reco_min),
                                       np.log10(e_reco_max), n_e_reco) * u.TeV

        on_region_radius = Angle(on_region_radius)
        self.on_region = CircleSkyRegion(center=pointing,
                                         radius=on_region_radius)

        irfs = load_cta_irfs(irf_file)

        self.obs = Observation.create(pointing=pointing,
                                      livetime=livetime,
                                      irfs=irfs)
Ejemplo n.º 8
0
def test_mde_sample_weak_src(dataset, models):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 10.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(
        obs_id=1001,
        pointing=pointing,
        livetime=livetime,
        irfs=irfs,
        location=LOCATION,
    )

    models[0].parameters["amplitude"].value = 1e-25

    dataset.models = models

    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    assert len(events.table) == 18
    assert_allclose(len(np.where(events.table["MC_ID"] == 0)[0]),
                    len(events.table),
                    rtol=1e-5)
Ejemplo n.º 9
0
def test_mde_run_switchoff(dataset, models):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 1.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(obs_id=1001,
                             pointing=pointing,
                             livetime=livetime,
                             irfs=irfs)

    dataset.models = models

    dataset.psf = None
    dataset.edisp = None
    dataset.background = None

    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    assert len(events.table) == 88
    assert_allclose(events.table["ENERGY"][0], 2.751205, rtol=1e-5)
    assert_allclose(events.table["RA"][0], 266.559566, rtol=1e-5)
    assert_allclose(events.table["DEC"][0], -28.742429, rtol=1e-5)

    meta = events.table.meta

    assert meta["RA_PNT"] == 266.4049882865447
    assert meta["ONTIME"] == 3600.0
    assert meta["OBS_ID"] == 1001
    assert meta["RADECSYS"] == "icrs"
Ejemplo n.º 10
0
def test_mde_run(dataset):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 10.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(obs_id=1001,
                             pointing=pointing,
                             livetime=livetime,
                             irfs=irfs)

    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    dataset_bkg = dataset.copy()
    dataset_bkg.models = dataset_bkg.models[1]
    events_bkg = sampler.run(dataset=dataset_bkg, observation=obs)

    assert len(events.table) == 2422
    assert_allclose(events.table["ENERGY"][0], 1.56446303986587, rtol=1e-5)
    assert_allclose(events.table["RA"][0], 268.8180057255861, rtol=1e-5)
    assert_allclose(events.table["DEC"][0], -28.45051813404372, rtol=1e-5)

    assert len(events_bkg.table) == 12
    assert_allclose(events_bkg.table["ENERGY"][0], 1.377619454, rtol=1e-5)
    assert_allclose(events_bkg.table["RA"][0], 265.09135019, rtol=1e-5)
    assert_allclose(events_bkg.table["DEC"][0], -30.631115659801, rtol=1e-5)
    assert_allclose(events_bkg.table["MC_ID"][0], 0, rtol=1e-5)

    meta = events.table.meta

    assert meta["RA_PNT"] == 266.4049882865447
    assert meta["ONTIME"] == 36000.0
    assert meta["OBS_ID"] == 1001
    assert meta["RADECSYS"] == "icrs"
Ejemplo n.º 11
0
def simulate_map_dataset(random_state=0):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    skydir = SkyCoord("0 deg", "0 deg", frame="galactic")
    edges = np.logspace(-1, 2, 15) * u.TeV
    energy_axis = MapAxis.from_edges(edges=edges, name="energy", interp="log")

    geom = WcsGeom.create(
        skydir=skydir, width=(4, 4), binsz=0.1, axes=[energy_axis], coordsys="GAL"
    )

    gauss = GaussianSpatialModel(
        lon_0="0 deg", lat_0="0 deg", sigma="0.4 deg", frame="galactic"
    )
    pwl = PowerLawSpectralModel(amplitude="1e-11 cm-2 s-1 TeV-1")
    skymodel = SkyModel(spatial_model=gauss, spectral_model=pwl, name="source")
    dataset = simulate_dataset(
        skymodel=skymodel,
        geom=geom,
        pointing=skydir,
        irfs=irfs,
        random_state=random_state,
    )
    return dataset
Ejemplo n.º 12
0
def test_cta_irf_alpha_config_south():
    """Test that CTA IRFs can be loaded and evaluated."""
    irf = load_cta_irfs(
        "$GAMMAPY_DATA/cta-caldb/Prod5-South-20deg-AverageAz-14MSTs37SSTs.180000s-v0.1.fits.gz"
    )

    energy = Quantity(1, "TeV")
    offset = Quantity(3, "deg")

    val = irf["aeff"].evaluate(energy_true=energy, offset=offset)
    assert_allclose(val.value, 493538.4460737773, rtol=1e-5)
    assert val.unit == "m2"

    val = irf["edisp"].evaluate(offset=offset, energy_true=energy, migra=1)
    assert_allclose(val.value, 0.0499099, rtol=1e-5)
    assert val.unit == ""

    val = irf["psf"].evaluate(rad=Quantity(0.1, "deg"),
                              energy_true=energy,
                              offset=offset)
    assert_allclose(val, 3.31135957 * u.Unit("deg-2"), rtol=1e-5)

    val = irf["bkg"].evaluate(energy=energy, fov_lon=offset, fov_lat="0 deg")
    assert_allclose(val.value, 8.98793486e-05, rtol=1e-5)
    assert val.unit == "1 / (MeV s sr)"
Ejemplo n.º 13
0
def prepare_dataset_simple(filename_dataset):
    """Prepare dataset for a given skymodel."""
    log.info(f"Reading {IRF_FILE}")

    irfs = load_cta_irfs(IRF_FILE)

    edisp_gauss = EnergyDispersion2D.from_gauss(
        e_true=ENERGY_AXIS_TRUE.edges,
        migra=MIGRA_AXIS.edges,
        sigma=0.1,
        bias=0,
        offset=[0, 2, 4, 6, 8] * u.deg,
    )

    irfs["edisp"] = edisp_gauss
    # irfs["aeff"].data.data = np.ones_like(irfs["aeff"].data.data) * 1e6

    observation = Observation.create(
        obs_id=1001, pointing=POINTING, livetime=LIVETIME, irfs=irfs
    )

    empty = MapDataset.create(
        WCS_GEOM, energy_axis_true=ENERGY_AXIS_TRUE, migra_axis=MIGRA_AXIS
    )
    # maker = MapDatasetMaker(selection=["exposure", "edisp"])
    # maker = MapDatasetMaker(selection=["exposure", "edisp", "background"])
    maker = MapDatasetMaker(selection=["exposure", "edisp", "psf", "background"])
    dataset = maker.run(empty, observation)

    filename_dataset.parent.mkdir(exist_ok=True, parents=True)
    log.info(f"Writing {filename_dataset}")
    dataset.write(filename_dataset, overwrite=True)
Ejemplo n.º 14
0
def simulate():

    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    # Reconstructed and true energy axis
    center = SkyCoord(0.0, 0.0, unit="deg", frame="galactic")
    energy_axis = MapAxis.from_edges(
        np.logspace(-0.5, 1.0, 10), unit="TeV", name="energy", interp="log",
    )
    energy_axis_true = MapAxis.from_edges(
        np.logspace(-1.2, 2.0, 31), unit="TeV", name="energy_true", interp="log",
    )

    on_region_radius = Angle("0.11 deg")
    on_region = CircleSkyRegion(center=center, radius=on_region_radius)

    pointing = SkyCoord(0.5, 0.5, unit="deg", frame="galactic")

    spectral_model = PowerLawSpectralModel(
        index=3, amplitude="1e-11 cm-2 s-1 TeV-1", reference="1 TeV"
    )
    temporal_model = ExpDecayTemporalModel(t0="6 h", t_ref=gti_t0.mjd * u.d)
    model_simu = SkyModel(
        spectral_model=spectral_model, temporal_model=temporal_model, name="model-simu",
    )

    lvtm = np.ones(N_OBS) * 1.0 * u.hr
    tstart = 1.0 * u.hr

    datasets = []
    for i in range(N_OBS):
        obs = Observation.create(
            pointing=pointing,
            livetime=lvtm[i],
            tstart=tstart,
            irfs=irfs,
            reference_time=gti_t0,
        )
        empty = SpectrumDataset.create(
            e_reco=energy_axis,
            e_true=energy_axis_true,
            region=on_region,
            name=f"dataset_{i}",
        )
        maker = SpectrumDatasetMaker(selection=["aeff", "background", "edisp"])
        dataset = maker.run(empty, obs)
        dataset.models = model_simu
        dataset.fake()
        datasets.append(dataset)
        tstart = tstart + 2.0 * u.hr

    return datasets
Ejemplo n.º 15
0
    def from_caldb(
        cls,
        pointing,
        obs_id=None,
        livetime=None,
        tstart=None,
        tstop=None,
        caldb="prod2",
        irf="South0.5hr",
        deadtime_fraction=0.0,
    ):
        """Create an observation using IRFs from a given CTA CALDB.

        Parameters
        ----------
        pointing : `~astropy.coordinates.SkyCoord`
            Pointing position
        obs_id : int
            Observation ID as identifier
        livetime : ~astropy.units.Quantity`
            Livetime exposure of the simulated observation
        tstart : `~astropy.units.Quantity`
            Start time of observation
        tstop : `~astropy.units.Quantity`
            Stop time of observation
        caldb : str
            Calibration database
        irf : str
            Type of Instrumental response function.
        deadtime_fraction : float, optional
            Deadtime fraction, defaults to 0

        Returns
        -------
        obs : `gammapy.data.Observation`
        """
        from .data_store import CalDBIRF

        irf_loc = CalDBIRF("CTA", caldb, irf)
        filename = irf_loc.file_dir + irf_loc.file_name
        irfs = load_cta_irfs(filename)
        return cls.create(
            pointing=pointing,
            obs_id=obs_id,
            livetime=livetime,
            tstart=tstart,
            tstop=tstop,
            irfs=irfs,
            deadtime_fraction=deadtime_fraction,
        )
Ejemplo n.º 16
0
def test_observation():
    livetime = 5.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    obs = Observation.create(pointing,
                             livetime=livetime,
                             irfs=irfs,
                             deadtime_fraction=0.1)

    assert_skycoord_allclose(obs.pointing_radec, pointing.icrs)
    assert_allclose(obs.observation_live_time_duration, 0.9 * livetime)
Ejemplo n.º 17
0
def test_irf_alpha_config(dataset, models):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-caldb/Prod5-South-20deg-AverageAz-14MSTs37SSTs.180000s-v0.1.fits.gz"
    )
    livetime = 1.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(obs_id=1001,
                             pointing=pointing,
                             livetime=livetime,
                             irfs=irfs)

    dataset.models = models
    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)
    assert events is not None
Ejemplo n.º 18
0
def test_simulate():
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    # Define sky model to simulate the data
    spatial_model = GaussianSpatialModel(lon_0="0 deg",
                                         lat_0="0 deg",
                                         sigma="0.2 deg",
                                         frame="galactic")
    spectral_model = PowerLawSpectralModel(index=2,
                                           amplitude="1e-11 cm-2 s-1 TeV-1",
                                           reference="1 TeV")
    sky_model_simu = SkyModel(spatial_model=spatial_model,
                              spectral_model=spectral_model)

    # Define map geometry
    axis = MapAxis.from_edges(np.logspace(-1, 1.0, 20),
                              unit="TeV",
                              name="energy",
                              interp="log")
    geom = WcsGeom.create(skydir=(0, 0),
                          binsz=0.025,
                          width=(1, 1),
                          frame="galactic",
                          axes=[axis])

    # Define some observation parameters
    pointing = SkyCoord(0 * u.deg, 0 * u.deg, frame="galactic")

    dataset = simulate_dataset(sky_model_simu,
                               geom,
                               pointing,
                               irfs,
                               livetime=10 * u.h,
                               random_state=42)

    assert isinstance(dataset, MapDataset)
    assert isinstance(dataset.models, Models)

    assert dataset.counts.data.dtype is np.dtype("int")
    assert_allclose(dataset.counts.data[5, 20, 20], 2)
    assert_allclose(dataset.exposure.data[5, 20, 20], 16122681486.381285)
    assert_allclose(dataset.background_model.map.data[5, 20, 20],
                    0.9765545345855245,
                    rtol=1e-5)
    assert_allclose(dataset.psf.psf_map.data[5, 5, 0, 0], 91987.862)
    assert_allclose(dataset.edisp.data.data[10, 10], 0.864096, rtol=1e-5)
Ejemplo n.º 19
0
def prepare_dataset(filename_dataset):
    """Prepare dataset for a given skymodel."""
    log.info(f"Reading {IRF_FILE}")
    irfs = load_cta_irfs(IRF_FILE)
    observation = Observation.create(
        obs_id=1001, pointing=POINTING, livetime=LIVETIME, irfs=irfs
    )

    empty = MapDataset.create(
        WCS_GEOM, energy_axis_true=ENERGY_AXIS_TRUE, migra_axis=MIGRA_AXIS
    )
    maker = MapDatasetMaker(selection=["exposure", "background", "psf", "edisp"])
    dataset = maker.run(empty, observation)

    filename_dataset.parent.mkdir(exist_ok=True, parents=True)
    log.info(f"Writing {filename_dataset}")
    dataset.write(filename_dataset, overwrite=True)
Ejemplo n.º 20
0
def simulate_events(filename_model, filename_dataset, dataset, obs_id):
    """Simulate events for a given model and dataset.

    Parameters
    ----------
    filename_model : str
        Filename of the model definition.
    filename_dataset : str
        Filename of the dataset to use for simulation.
    nobs : int
        Number of obervations to simulate.
    """
    log.info(f"Reading {IRF_FILE}")
    irfs = load_cta_irfs(IRF_FILE)

    #    log.info(f"Reading {filename_dataset}")
    #    dataset = MapDataset.read(filename_dataset)

    log.info(f"Reading {filename_model}")
    models = Models.read(filename_model)
    #    dataset.models = models
    dataset.models.extend(models)

    sampler = MapDatasetEventSampler(random_state=0)

    #    obs_id = np.arange(nobs)
    #    with multiprocessing.Pool(processes=core) as pool:
    #        args1 = zip(obs_id, repeat(POINTING), repeat(LIVETIME), repeat(irfs),
    #                    repeat(dataset), repeat(filename_dataset), repeat(filename_model))
    #        pool.starmap(simulate_parallel, args1)

    #    for obs_id in np.arange(nobs):
    observation = Observation.create(obs_id=obs_id,
                                     pointing=POINTING,
                                     livetime=LIVETIME,
                                     irfs=irfs)

    events = sampler.run(dataset, observation)

    path = get_filename_events(filename_dataset, filename_model, obs_id)
    log.info(f"Writing {path}")
    path.parent.mkdir(exist_ok=True, parents=True)
    events.table.write(str(path), overwrite=True)
Ejemplo n.º 21
0
def test_event_det_coords(dataset):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 1.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(
        obs_id=1001, pointing=pointing, livetime=livetime, irfs=irfs
    )

    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    assert len(events.table) == 374
    assert_allclose(events.table["DETX"][0], -2.44563584, rtol=1e-5)
    assert events.table["DETX"].unit == "deg"

    assert_allclose(events.table["DETY"][0], 0.01414569, rtol=1e-5)
    assert events.table["DETY"].unit == "deg"
Ejemplo n.º 22
0
def test_mde_run(dataset):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 1.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(obs_id=1001,
                             pointing=pointing,
                             livetime=livetime,
                             irfs=irfs)

    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    dataset_bkg = dataset.copy()
    dataset_bkg.models = dataset_bkg.models[1]
    events_bkg = sampler.run(dataset=dataset_bkg, observation=obs)

    assert len(events.table) == 374
    assert_allclose(events.table["ENERGY"][0], 4.09979515940, rtol=1e-5)
    assert_allclose(events.table["RA"][0], 263.611383742, rtol=1e-5)
    assert_allclose(events.table["DEC"][0], -28.89318805, rtol=1e-5)

    assert len(events_bkg.table) == 10
    assert_allclose(events_bkg.table["ENERGY"][0], 2.84808850102, rtol=1e-5)
    assert_allclose(events_bkg.table["RA"][0], 266.6138405848, rtol=1e-5)
    assert_allclose(events_bkg.table["DEC"][0], -29.0489180785, rtol=1e-5)
    assert_allclose(events_bkg.table["MC_ID"][0], 0, rtol=1e-5)

    meta = events.table.meta

    assert meta["RA_PNT"] == 266.4049882865447
    assert meta["ONTIME"] == 3600.0
    assert meta["OBS_ID"] == 1001
    assert meta["RADECSYS"] == "icrs"
    assert meta["ALT_PNT"] == "20.000"
    assert meta["AZ_PNT"] == "0.000"
Ejemplo n.º 23
0
def simulate_events(filename_model, filename_dataset, nobs):
    """Simulate events for a given model and dataset.

    Parameters
    ----------
    filename_model : str
        Filename of the model definition.
    filename_dataset : str
        Filename of the dataset to use for simulation.
    nobs : int
        Number of obervations to simulate.
    """
    log.info(f"Reading {IRF_FILE}")
    irfs = load_cta_irfs(IRF_FILE)

    log.info(f"Reading {filename_dataset}")
    dataset = MapDataset.read(filename_dataset)

    log.info(f"Reading {filename_model}")
    models = Models.read(filename_model)
    models.append(FoVBackgroundModel(dataset_name=dataset.name))
    dataset.models = models
#    dataset.models.extend(models)

    sampler = MapDatasetEventSampler(random_state=0)

    for obs_id in np.arange(nobs):
        observation = Observation.create(
            obs_id=obs_id, pointing=POINTING, livetime=LIVETIME, irfs=irfs
        )

        events = sampler.run(dataset, observation)

        path = get_filename_events(filename_dataset, filename_model, obs_id)
        log.info(f"Writing {path}")
        path.parent.mkdir(exist_ok=True, parents=True)
        events.table.write(str(path), overwrite=True)
fig_1.savefig('original_spectra_10tev.png', quality=95, dpi=1000)

#  Define spatial model
spatial_model = PointSpatialModel(lon_0=l * u.Unit("deg"),
                                  lat_0=b * u.Unit("deg"),
                                  frame="galactic")

# Set the sky model to simulate the observation
model = SkyModel(spectral_model=spectral_model,
                 spatial_model=spatial_model,
                 name="perseus")
print("This is the simulated model")
print(model)

# Load the IRFs
irfs = load_cta_irfs("$GAMMAPY_DATA/prod3b-v2/bcf/North_z20_50h/irf_file.fits")

# Create the observation
obs = Observation.create(pointing=pointing, livetime=livetime, irfs=irfs)
print("Characteristics of the simulated observation")
print(obs)

# # Create the On/Off simulations

# Make the SpectrumDataset
# NOTE: Even we don't set different energy ranges for recovered and true energies, if edisp is not considered then the
# FluxPointEstimator breaks
dataset_empty = SpectrumDataset.create(e_reco=energy_axis,
                                       region=on_region,
                                       name="obs-0")
maker = SpectrumDatasetMaker(selection=["exposure", "edisp", "background"])
Ejemplo n.º 25
0
def simulate():

    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )

    center = SkyCoord(0.0, 0.0, unit="deg", frame="galactic")
    energy_reco = MapAxis.from_edges(np.logspace(-1.0, 1.0, 10),
                                     unit="TeV",
                                     name="energy",
                                     interp="log")
    pointing = SkyCoord(0.5, 0.5, unit="deg", frame="galactic")
    geom = WcsGeom.create(
        skydir=center,
        binsz=0.02,
        width=(4, 4),
        frame="galactic",
        axes=[energy_reco],
    )
    energy_true = MapAxis.from_edges(np.logspace(-1.5, 1.5, 30),
                                     unit="TeV",
                                     name="energy_true",
                                     interp="log")

    spectral_model = PowerLawSpectralModel(index=3,
                                           amplitude="1e-11 cm-2 s-1 TeV-1",
                                           reference="1 TeV")
    temporal_model = ExpDecayTemporalModel(t0="6 h", t_ref=gti_t0.mjd * u.d)
    spatial_model = GaussianSpatialModel(lon_0="0.2 deg",
                                         lat_0="0.1 deg",
                                         sigma="0.3 deg",
                                         frame="galactic")
    model_simu = SkyModel(
        spectral_model=spectral_model,
        spatial_model=spatial_model,
        temporal_model=temporal_model,
        name="model-simu",
    )

    lvtm = np.ones(N_OBS) * 1.0 * u.hr
    tstart = 1.0 * u.hr

    datasets = []
    for i in range(N_OBS):
        obs = Observation.create(
            pointing=pointing,
            livetime=lvtm[i],
            tstart=tstart,
            irfs=irfs,
            reference_time=gti_t0,
        )
        empty = MapDataset.create(geom,
                                  name=f"dataset_{i}",
                                  energy_axis_true=energy_true)
        maker = MapDatasetMaker(
            selection=["exposure", "background", "psf", "edisp"])
        maker_safe_mask = SafeMaskMaker(methods=["offset-max"],
                                        offset_max=4.0 * u.deg)
        dataset = maker.run(empty, obs)
        dataset = maker_safe_mask.run(dataset, obs)
        dataset.models = [
            model_simu,
            FoVBackgroundModel(dataset_name=dataset.name)
        ]
        dataset.fake()
        datasets.append(dataset)
        tstart = tstart + 2.0 * u.hr

    return datasets
Ejemplo n.º 26
0
def generate_dataset(Eflux,
                     flux,
                     Erange=None,
                     tstart=Time('2000-01-01 02:00:00', scale='utc'),
                     tobs=100 * u.s,
                     irf_file=None,
                     alpha=1 / 5,
                     name=None,
                     fake=True,
                     onoff=True,
                     seed='random-seed',
                     debug=False):
    """
    Generate a dataset from a list of energies and flux points either as
    a SpectrumDataset or a SpectrumDatasetOnOff

    Note :
    - in SpectrumDataset, the backgound counts are assumed precisely know and
    are not fluctuated.
    - in SpectrumDatasetOnOff, the background counts (off counts) are
    fluctuated from the IRF known values.

    Parameters
    ----------
    Eflux : Quantity
        Energies at which the flux is given.
    flux : Quantity
        Flux corresponding to the given energies.
    Erange : List, optional
        The energy boundaries within which the flux is defined, if not over all
        energies. The default is None.
    tstart : Time object, optional
        Start date of the dataset.
        The default is Time('2000-01-01 02:00:00',scale='utc').
    tobs : Quantity, optional
        Duration of the observation. The default is 100*u.s.
    irf_file : String, optional
        The IRf file name. The default is None.
    alpha : Float, optional
        The on over off surface ratio for the On-Off analysis.
        The default is 1/5.
    name : String, optional
        The dataset name, also used to name tthe spectrum. The default is None.
    fake : Boolean, optional
        If True, the dataset counts are fluctuated. The default is True.
    onoff : Boolean, optional
        If True, use SpectrumDatasetOnOff, otherwise SpectrumDataSet.
        The default is True.
    seed : String, optional
        The seed for the randome generator; If an integer will generate the
        same random series at each run. The default is 'random-seed'.
    debug: Boolean
        If True, let's talk a bit. The default is False.

    Returns
    -------
    ds : Dataset object
        The dataset.

    """
    random_state = get_random_state(seed)

    ### Define on region
    on_pointing = SkyCoord(ra=0 * u.deg, dec=0 * u.deg,
                           frame="icrs")  # Observing region
    on_region = CircleSkyRegion(center=on_pointing, radius=0.5 * u.deg)

    # Define energy axis (see spectrum analysis notebook)
    # edges for SpectrumDataset - all dataset should have the same axes
    # Note that linear spacing is clearly problematic for powerlaw fluxes
    # Axes can also be defined using MapAxis
    unit = u.GeV
    E1v = min(Eflux).to(unit).value
    E2v = max(Eflux).to(unit).value
    #     ereco = np.logspace(np.log10(1.1*E1v), np.log10(0.9*E2v), 20) * unit
    #     ereco_axis = MapAxis.from_edges(ereco.to("TeV").value,
    #                                    unit="TeV",
    #                                    name="energy",
    #                                    interp="log")

    ereco_axis = MapAxis.from_energy_bounds(1.1 * E1v * unit,
                                            0.9 * E2v * unit,
                                            nbin=4,
                                            per_decade=True,
                                            name="energy")

    #     etrue = np.logspace(np.log10(    E1v), np.log10(    E2v), 50) * unit
    #     etrue_axis = MapAxis.from_edges(etrue.to("TeV").value,
    #                                    unit="TeV",
    #                                    name="energy_true",
    #                                    interp="log")
    etrue_axis = MapAxis.from_energy_bounds(E1v * unit,
                                            E2v * unit,
                                            nbin=4,
                                            per_decade=True,
                                            name="energy_true")
    if (debug):
        print("Dataset ", name)
        print("Etrue : ", etrue_axis.edges)
        print("Ereco : ", ereco_axis.edges)

    # Load IRF
    irf = load_cta_irfs(irf_file)

    spec = TemplateSpectralModel(energy=Eflux,
                                 values=flux,
                                 interp_kwargs={"values_scale": "log"})

    model = SkyModel(spectral_model=spec, name="Spec" + str(name))
    obs = Observation.create(obs_id=1,
                             pointing=on_pointing,
                             livetime=tobs,
                             irfs=irf,
                             deadtime_fraction=0,
                             reference_time=tstart)

    ds_empty = SpectrumDataset.create(
        e_reco=ereco_axis,  # Ereco.edges,
        e_true=etrue_axis,  #Etrue.edges,
        region=on_region,
        name=name)
    maker = SpectrumDatasetMaker(containment_correction=False,
                                 selection=["exposure", "background", "edisp"])
    ds = maker.run(ds_empty, obs)
    ds.models = model
    mask = ds.mask_safe.geom.energy_mask(energy_min=Erange[0],
                                         energy_max=Erange[1])

    mask = mask & ds.mask_safe.data
    ds.mask_safe = RegionNDMap(ds.mask_safe.geom, data=mask)

    ds.fake(random_state=random_state)  # Fake is mandatory ?

    # Transform SpectrumDataset into SpectrumDatasetOnOff if needed
    if (onoff):

        ds = SpectrumDatasetOnOff.from_spectrum_dataset(dataset=ds,
                                                        acceptance=1,
                                                        acceptance_off=1 /
                                                        alpha)
        print("Transformed in ONOFF")

    if fake:
        print(" Fluctuations : seed = ", seed)
        if (onoff):
            ds.fake(npred_background=ds.npred_background())
        else:
            ds.fake(random_state=random_state)

    print("ds.energy_range = ", ds.energy_range)

    return ds
Ejemplo n.º 27
0
from gammapy.spectrum.models import ExponentialCutoffPowerLaw
from gammapy.image.models import SkyGaussian
from gammapy.cube.models import SkyModel
from gammapy.cube.simulate import simulate_dataset
from gammapy.utils.fitting import Fit

import emcee
import corner

# ## Simulate an observation
#
# Here we will start by simulating an observation using the `simulate_dataset` method.

# In[ ]:

irfs = load_cta_irfs(
    "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits")

# In[ ]:

# Define sky model to simulate the data
spatial_model = SkyGaussian(lon_0="0 deg", lat_0="0 deg", sigma="0.2 deg")

spectral_model = ExponentialCutoffPowerLaw(
    index=2,
    amplitude="3e-12 cm-2 s-1 TeV-1",
    reference="1 TeV",
    lambda_="0.05 TeV-1",
)

sky_model_simu = SkyModel(spatial_model=spatial_model,
                          spectral_model=spectral_model)
Ejemplo n.º 28
0
from gammapy.cube import MapDataset, PSFKernel
from gammapy.cube import make_map_exposure_true_energy, make_map_background_irf
from gammapy.utils.fitting import Fit
from gammapy.data import FixedPointingInfo

# In[ ]:

get_ipython().system('gammapy info --no-envvar --no-dependencies --no-system')

# ## Simulate

# In[ ]:

filename = (
    "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits")
irfs = load_cta_irfs(filename)

# In[ ]:

# Define sky model to simulate the data
spatial_model = SkyGaussian(lon_0="0.2 deg", lat_0="0.1 deg", sigma="0.3 deg")
spectral_model = PowerLaw(index=3,
                          amplitude="1e-11 cm-2 s-1 TeV-1",
                          reference="1 TeV")
sky_model = SkyModel(spatial_model=spatial_model,
                     spectral_model=spectral_model)
print(sky_model)

# In[ ]:

# Define map geometry
Ejemplo n.º 29
0
def test_mde_run(dataset):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 1.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(obs_id=1001,
                             pointing=pointing,
                             livetime=livetime,
                             irfs=irfs)

    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    dataset_bkg = dataset.copy()
    dataset_bkg.models = dataset_bkg.models[1]
    events_bkg = sampler.run(dataset=dataset_bkg, observation=obs)

    assert len(events.table) == 374
    assert_allclose(events.table["ENERGY"][0], 4.09979515940, rtol=1e-5)
    assert_allclose(events.table["RA"][0], 263.611383742, rtol=1e-5)
    assert_allclose(events.table["DEC"][0], -28.89318805, rtol=1e-5)

    assert len(events_bkg.table) == 10
    assert_allclose(events_bkg.table["ENERGY"][0], 2.84808850102, rtol=1e-5)
    assert_allclose(events_bkg.table["RA"][0], 266.6138405848, rtol=1e-5)
    assert_allclose(events_bkg.table["DEC"][0], -29.0489180785, rtol=1e-5)
    assert_allclose(events_bkg.table["MC_ID"][0], 0, rtol=1e-5)

    meta = events.table.meta

    assert meta["HDUCLAS1"] == "EVENTS"
    assert meta["EXTNAME"] == "EVENTS"
    assert (meta["HDUDOC"] ==
            "https://github.com/open-gamma-ray-astro/gamma-astro-data-formats")
    assert meta["HDUVERS"] == "0.2"
    assert meta["HDUCLASS"] == "GADF"
    assert meta["OBS_ID"] == 1001
    assert_allclose(meta["TSTART"], 0.0)
    assert_allclose(meta["TSTOP"], 3600.0)
    assert_allclose(meta["ONTIME"], 3600.0)
    assert_allclose(meta["LIVETIME"], 3600.0)
    assert_allclose(meta["DEADC"], 0.0)
    assert_allclose(meta["RA_PNT"], 266.4049882865447)
    assert_allclose(meta["DEC_PNT"], -28.936177761791473)
    assert meta["EQUINOX"] == "J2000"
    assert meta["RADECSYS"] == "icrs"
    assert "Gammapy" in meta["CREATOR"]
    assert meta["EUNIT"] == "TeV"
    assert meta["EVTVER"] == ""
    assert meta["OBSERVER"] == "Gammapy user"
    assert meta["DSTYP1"] == "TIME"
    assert meta["DSUNI1"] == "s"
    assert meta["DSVAL1"] == "TABLE"
    assert meta["DSREF1"] == ":GTI"
    assert meta["DSTYP2"] == "ENERGY"
    assert meta["DSUNI2"] == "TeV"
    assert ":" in meta["DSVAL2"]
    assert meta["DSTYP3"] == "POS(RA,DEC)     "
    assert "CIRCLE" in meta["DSVAL3"]
    assert meta["DSUNI3"] == "deg             "
    assert meta["NDSKEYS"] == " 3 "
    assert_allclose(meta["RA_OBJ"], 266.4049882865447)
    assert_allclose(meta["DEC_OBJ"], -28.936177761791473)
    assert_allclose(meta["TELAPSE"], 1000.0)
    assert_allclose(meta["MJDREFI"], 51544)
    assert_allclose(meta["MJDREFF"], 0.0007428703684126958)
    assert meta["TIMEUNIT"] == "s"
    assert meta["TIMESYS"] == "tt"
    assert meta["TIMEREF"] == "LOCAL"
    assert meta["DATE-OBS"] == "2000-01-01"
    assert meta["DATE-END"] == "2000-01-01"
    assert meta["TIME-OBS"] == "00:01:04.184"
    assert meta["TIME-END"] == "00:17:44.184"
    assert_allclose(meta["TIMEDEL"], 1e-09)
    assert meta["CONV_DEP"] == 0
    assert meta["CONV_RA"] == 0
    assert meta["CONV_DEC"] == 0
    assert meta["MID00001"] == 1
    assert meta["MID00002"] == 2
    assert meta["NMCIDS"] == 2
    assert meta["ALTITUDE"] == "20.000"
    assert meta["ALT_PNT"] == "20.000"
    assert meta["AZ_PNT"] == "0.000"
    assert meta["ORIGIN"] == "Gammapy"
    assert meta["CALDB"] == "1dc"
    assert meta["IRF"] == "South_z20_50"
    assert meta["TELESCOP"] == "CTA"
    assert meta["INSTRUME"] == "1DC"
    assert meta["N_TELS"] == ""
    assert meta["TELLIST"] == ""
    assert meta["GEOLON"] == ""
    assert meta["GEOLAT"] == ""
Ejemplo n.º 30
0
def test_mde_run(dataset, models):
    irfs = load_cta_irfs(
        "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
    )
    livetime = 1.0 * u.hr
    pointing = SkyCoord(0, 0, unit="deg", frame="galactic")
    obs = Observation.create(obs_id=1001,
                             pointing=pointing,
                             livetime=livetime,
                             irfs=irfs)

    dataset.models = models
    sampler = MapDatasetEventSampler(random_state=0)
    events = sampler.run(dataset=dataset, observation=obs)

    dataset_bkg = dataset.copy(name="new-dataset")
    dataset_bkg.models = [FoVBackgroundModel(dataset_name=dataset_bkg.name)]

    events_bkg = sampler.run(dataset=dataset_bkg, observation=obs)

    assert len(events.table) == 102
    assert_allclose(events.table["ENERGY"][0], 5.792375, rtol=1e-5)
    assert_allclose(events.table["RA"][0], 263.777097, rtol=1e-5)
    assert_allclose(events.table["DEC"][0], -30.302968, rtol=1e-5)

    assert len(events_bkg.table) == 16
    assert_allclose(events_bkg.table["ENERGY"][0], 4.014328, rtol=1e-5)
    assert_allclose(events_bkg.table["RA"][0], 267.488623, rtol=1e-5)
    assert_allclose(events_bkg.table["DEC"][0], -30.924333, rtol=1e-5)
    assert_allclose(events_bkg.table["MC_ID"][0], 0, rtol=1e-5)

    meta = events.table.meta

    assert meta["HDUCLAS1"] == "EVENTS"
    assert meta["EXTNAME"] == "EVENTS"
    assert (meta["HDUDOC"] ==
            "https://github.com/open-gamma-ray-astro/gamma-astro-data-formats")
    assert meta["HDUVERS"] == "0.2"
    assert meta["HDUCLASS"] == "GADF"
    assert meta["OBS_ID"] == 1001
    assert_allclose(meta["TSTART"], 0.0)
    assert_allclose(meta["TSTOP"], 3600.0)
    assert_allclose(meta["ONTIME"], 3600.0)
    assert_allclose(meta["LIVETIME"], 3600.0)
    assert_allclose(meta["DEADC"], 1.0)
    assert_allclose(meta["RA_PNT"], 266.4049882865447)
    assert_allclose(meta["DEC_PNT"], -28.936177761791473)
    assert meta["EQUINOX"] == "J2000"
    assert meta["RADECSYS"] == "icrs"
    assert "Gammapy" in meta["CREATOR"]
    assert meta["EUNIT"] == "TeV"
    assert meta["EVTVER"] == ""
    assert meta["OBSERVER"] == "Gammapy user"
    assert meta["DSTYP1"] == "TIME"
    assert meta["DSUNI1"] == "s"
    assert meta["DSVAL1"] == "TABLE"
    assert meta["DSREF1"] == ":GTI"
    assert meta["DSTYP2"] == "ENERGY"
    assert meta["DSUNI2"] == "TeV"
    assert ":" in meta["DSVAL2"]
    assert meta["DSTYP3"] == "POS(RA,DEC)     "
    assert "CIRCLE" in meta["DSVAL3"]
    assert meta["DSUNI3"] == "deg             "
    assert meta["NDSKEYS"] == " 3 "
    assert_allclose(meta["RA_OBJ"], 266.4049882865447)
    assert_allclose(meta["DEC_OBJ"], -28.936177761791473)
    assert_allclose(meta["TELAPSE"], 1000.0)
    assert_allclose(meta["MJDREFI"], 51544)
    assert_allclose(meta["MJDREFF"], 0.0007428703684126958)
    assert meta["TIMEUNIT"] == "s"
    assert meta["TIMESYS"] == "tt"
    assert meta["TIMEREF"] == "LOCAL"
    assert meta["DATE-OBS"] == "2000-01-01"
    assert meta["DATE-END"] == "2000-01-01"
    assert meta["CONV_DEP"] == 0
    assert meta["CONV_RA"] == 0
    assert meta["CONV_DEC"] == 0
    assert meta["MID00001"] == 1
    assert meta["MID00002"] == 2
    assert meta["NMCIDS"] == 2
    assert_allclose(float(meta["ALT_PNT"]), float("-13.5345076464"), rtol=1e-7)
    assert_allclose(float(meta["AZ_PNT"]),
                    float("228.82981620065763"),
                    rtol=1e-7)
    assert meta["ORIGIN"] == "Gammapy"
    assert meta["TELESCOP"] == "CTA"
    assert meta["INSTRUME"] == "1DC"
    assert meta["N_TELS"] == ""
    assert meta["TELLIST"] == ""