def setup_class(cls): cls.pulse_frequency = 1 / 0.101 cls.tstart = 0 cls.tend = 25.25 cls.tseg = cls.tend - cls.tstart cls.dt = 0.00606 cls.times = np.arange(cls.tstart, cls.tend, cls.dt) + cls.dt / 2 cls.counts = \ 100 + 20 * np.cos(2 * np.pi * cls.times * cls.pulse_frequency) lc = Lightcurve(cls.times, cls.counts, gti=[[cls.tstart, cls.tend]]) events = EventList() events.simulate_times(lc) events.mjdref = 57000. cls.event_times = events.time cls.dum = 'events' + HEN_FILE_EXTENSION save_events(events, cls.dum) curdir = os.path.abspath(os.path.dirname(__file__)) cls.datadir = os.path.join(curdir, 'data') fits_file = os.path.join(cls.datadir, 'monol_testA.evt') command = 'HENreadevents {0}'.format(fits_file) sp.check_call(command.split()) cls.real_event_file = os.path.join( cls.datadir, 'monol_testA_nustar_fpma_ev' + HEN_FILE_EXTENSION)
def test_filter_for_deadtime_evlist(): """Test dead time filter, non-paralyzable case.""" events = np.array([1, 1.05, 1.07, 1.08, 1.1, 2, 2.2, 3, 3.1, 3.2]) events = EventList(events) events.pi=np.array([1, 2, 2, 2, 2, 1, 1, 1, 2, 1]) events.energy=np.array([1, 2, 2, 2, 2, 1, 1, 1, 2, 1]) events.mjdref = 10 filt_events = filter_for_deadtime(events, 0.11) expected = np.array([1, 2, 2.2, 3, 3.2]) assert np.allclose(filt_events.time, expected), \ "Wrong: {} vs {}".format(filt_events, expected) assert np.allclose(filt_events.pi, 1) assert np.allclose(filt_events.energy, 1)
def load_events(fname): """Load events from a file.""" if get_file_format(fname) == 'pickle': out = _load_data_pickle(fname) elif get_file_format(fname) == 'nc': out = _load_data_nc(fname) eventlist = EventList() eventlist.time = out['time'] eventlist.gti = out['gti'] eventlist.pi = out['pi'] eventlist.mjdref = out['mjdref'] if 'instr' in list(out.keys()): eventlist.instr = out["instr"] if 'energy' in list(out.keys()): eventlist.energy = out["energy"] if 'header' in list(out.keys()): eventlist.header = out["header"] return eventlist