コード例 #1
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")])
コード例 #2
0
def test_datastore_from_events():
    # Test that `DataStore.from_events_files` works.
    # The real tests for `DataStoreMaker` are below.
    path = "$GAMMAPY_DATA/cta-1dc/data/baseline/gps/gps_baseline_110380.fits"
    data_store = DataStore.from_events_files([path])
    assert len(data_store.obs_table) == 1
    assert len(data_store.hdu_table) == 6

    @requires_data()
    def test_datastore_get_observations(data_store, caplog):
        """Test loading data and IRF files via the DataStore"""
        observations = data_store.get_observations([23523, 23592])
        assert observations[0].obs_id == 23523
        observations = data_store.get_observations()
        assert len(observations) == 105

        with pytest.raises(ValueError):
            data_store.get_observations([11111, 23592])

        observations = data_store.get_observations([11111, 23523],
                                                   skip_missing=True)
        assert observations[0].obs_id == 23523
        assert "WARNING" in [_.levelname for _ in caplog.records]
        assert "Skipping missing obs_id: 11111" in [
            _.message for _ in caplog.records
        ]
コード例 #3
0
def test_datastore_from_events():
    # Test that `DataStore.from_events_files` works.
    # The real tests for `DataStoreMaker` are below.
    path = "$GAMMAPY_DATA/cta-1dc/data/baseline/gps/gps_baseline_110380.fits"
    data_store = DataStore.from_events_files([path])
    assert len(data_store.obs_table) == 1
    assert len(data_store.hdu_table) == 6
コード例 #4
0
def data_store_dc1(monkeypatch):
    paths = [
        f"$GAMMAPY_DATA/cta-1dc/data/baseline/gps/gps_baseline_{obs_id:06d}.fits"
        for obs_id in [110380, 111140, 111630, 111159]
    ]
    caldb_path = Path(os.environ["GAMMAPY_DATA"]) / Path("cta-1dc/caldb")
    monkeypatch.setenv("CALDB", str(caldb_path))
    return DataStore.from_events_files(paths)
コード例 #5
0
 def setup(self):
     paths = [
         f"$GAMMAPY_DATA/cta-1dc/data/baseline/gps/gps_baseline_{obs_id:06d}.fits"
         for obs_id in [110380, 111140, 111630, 111159]
     ]
     self.data_store = DataStore.from_events_files(paths)