|
3 | 3 | import os |
4 | 4 | import pytest |
5 | 5 | import numpy as np |
| 6 | +from numpy.testing import assert_allclose, assert_array_equal, assert_equal |
| 7 | + |
| 8 | +from astropy.io import fits |
6 | 9 | from astropy.time import Time |
7 | 10 |
|
8 | 11 | from ..events import EventList |
@@ -359,6 +362,39 @@ def test_pandas_roundtrip(self): |
359 | 362 | assert getattr(ev, attr) == getattr(new_ev, attr) |
360 | 363 |
|
361 | 364 |
|
| 365 | +class TestEventsFermi(object): |
| 366 | + @classmethod |
| 367 | + def setup_class(self): |
| 368 | + self.fermi_file = os.path.join(datadir, "fermi_gbm_tte.fits") |
| 369 | + with fits.open(self.fermi_file) as hdul: |
| 370 | + self.header = hdul[0].header |
| 371 | + self.time = hdul[2].data["TIME"] |
| 372 | + self.gti = hdul[3].data[0] |
| 373 | + |
| 374 | + self.pi = hdul[2].data["PHA"] |
| 375 | + elower = hdul[1].data["E_MIN"] |
| 376 | + ehigher = hdul[1].data["E_MAX"] |
| 377 | + emid = elower + (ehigher - elower) / 2.0 |
| 378 | + self.energy = np.array([emid[c] for c in self.pi]) |
| 379 | + |
| 380 | + def test_read_fermi(self): |
| 381 | + assert EventList.read(self.fermi_file) is not None |
| 382 | + |
| 383 | + def test_check_energy_pi(self): |
| 384 | + evt = EventList.read(self.fermi_file) |
| 385 | + |
| 386 | + assert_allclose(evt.energy, self.energy, atol=1e-8) |
| 387 | + assert_array_equal(evt.pi, self.pi) |
| 388 | + |
| 389 | + def test_check_time_gti(self): |
| 390 | + evt = EventList.read(self.fermi_file) |
| 391 | + |
| 392 | + assert_allclose(evt.time, self.time, atol=1e-8) |
| 393 | + assert_array_equal(evt.gti, np.array(self.gti).reshape(1, 2)) |
| 394 | + assert_equal(evt.ncounts, self.time.shape[0]) |
| 395 | + assert_allclose(evt.mjdref, self.header["MJDREFI"]) |
| 396 | + |
| 397 | + |
362 | 398 | class TestJoinEvents: |
363 | 399 | def test_join_without_times_simulated(self): |
364 | 400 | """Test if exception is raised when join method is |
|
0 commit comments