Example #1
0
def pulsar_events_mp(length,
                     period,
                     ctrate,
                     pulsed_fraction,
                     mean_obs,
                     bkg_ctrate,
                     detlev,
                     nbin=128):

    nustar_orb = 5808

    dt = period / 20
    # The total length of the time series should be the number of pointings times the time per orbit.
    # Add one orbit for buffer.
    N_orb = int(round(length / mean_obs, 0))
    tot_len = (N_orb + 1) * nustar_orb

    # The orbital period is 5808s. Every 5808s, a continuous observation with min_obs < length < max_obs begins
    start_t = numpy.multiply(
        numpy.arange(N_orb),
        numpy.random.normal(loc=nustar_orb, scale=60, size=N_orb))
    point_t = numpy.random.uniform(low=mean_obs - 500,
                                   high=mean_obs + 500,
                                   size=N_orb)
    end_t = numpy.add(start_t, point_t)

    times = numpy.arange(dt / 2, tot_len + dt / 2, dt)
    cont_lc = numpy.random.poisson(
        (ctrate *
         (1 + pulsed_fraction * numpy.cos(2 * numpy.pi / period * times)) *
         dt)) + numpy.random.poisson(bkg_ctrate * dt)

    lc = Lightcurve(time=times,
                    counts=cont_lc,
                    gti=numpy.column_stack((start_t, end_t)),
                    dt=dt)
    exposure = numpy.sum(point_t)
    events = EventList()
    events.gti = lc.gti
    events.simulate_times(lc)
    phase = numpy.arange(0, 1, 1 / nbin)
    zsq = z_n(phase,
              n=2,
              norm=fold_events(events.time, 1 / period, nbin=nbin)[1])
    detected = zsq > detlev
    return (detected, exposure)
Example #2
0
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