Beispiel #1
0
def do_signal_trials(n_sig, N=n_sig_trials):
    # get trial runner
    src = cy.sources(FRB_ra_rad,
                     FRB_dec_rad,
                     mjd=FRB_mjd_time,
                     sigma_t=np.zeros_like(FRB_ra_rad),
                     t_100=FRB_time_window)
    conf = {
        'extended': True,
        'space': "ps",
        'time': "transient",
        'sig': "transient",
        'flux': cy.hyp.PowerLawFlux(args.gamma),
        'rates_by': 'livetime'
    }
    tr = cy.get_trial_runner(conf, src=src, ana=ana)
    # run trials
    trials = tr.get_many_fits(N, n_sig, poisson=True, logging=False)
    # save to disk
    dir = cy.utils.ensure_dir('{}/gamma/{}/dt/{}/n_sig/{}'.format(
        sig_dir, args.gamma, args.dt, n_sig))
    filename = '{}/sig_trials_{}.npy'.format(dir, args.seed)
    print('->', filename)
    # notice: trials.as_array is a numpy structured array, not a cy.utils.Arrays
    np.save(filename, trials.as_array)
Beispiel #2
0
def do_background_trials(N=n_bg_trials):
    src = cy.sources(FRB_ra_rad,
                     FRB_dec_rad,
                     mjd=FRB_mjd_time,
                     sigma_t=np.zeros_like(FRB_ra_rad),
                     t_100=FRB_time_window)
    conf = {
        'extended': True,
        'space': "ps",
        'time': "transient",
        'sig': "transient",
        'flux': cy.hyp.PowerLawFlux(args.gamma)
    }
    tr = cy.get_trial_runner(conf, src=src, ana=ana)
    # run trials
    trials = tr.get_many_fits(N, logging=False)
    # save to disk
    dir = cy.utils.ensure_dir('{}/dt/{}'.format(bg_dir, args.dt))
    filename = '{}/bg_trials_seed_{}.npy'.format(dir, args.seed)
    print('->', filename)
    # notice: trials.as_array is a numpy structured array, not a cy.utils.Arrays
    np.save(filename, trials.as_array)
Beispiel #3
0
def find_n_sig(beta=0.9, nsigma=None):
    # get signal trials, background distribution, and trial runner
    sig_trials = cy.bk.get_best(sig, 'gamma', args.gamma, 'dt', args.dt,
                                'n_sig')
    b = cy.bk.get_best(bg, 'gamma', args.gamma, 'dt', args.dt)
    src = cy.sources(FRB_ra_rad,
                     FRB_dec_rad,
                     mjd=FRB_mjd_time,
                     sigma_t=np.zeros_like(FRB_ra_rad),
                     t_100=FRB_time_window)
    conf = {
        'extended': True,
        'space': "ps",
        'time': "transient",
        'sig': "transient",
        'flux': cy.hyp.PowerLawFlux(args.gamma),
        'box_mode': 'center'
    }
    tr = cy.get_trial_runner(conf, src=src, ana=ana)
    # determine ts threshold
    if nsigma is not None:
        ts = b.isf_nsigma(nsigma)
    else:
        ts = b.median()
    # include background trials in calculation
    trials = {0: b.trials}
    trials.update(sig_trials)
    # get number of signal events
    # (arguments prevent additional trials from being run)
    result = tr.find_n_sig(ts,
                           beta,
                           max_batch_size=0,
                           logging=False,
                           trials=trials,
                           n_bootstrap=1)
    # return flux
    return tr.to_E2dNdE(result, E0=1e5)
Beispiel #4
0
FRB_time_window = np.ones_like(FRB_ra_rad) * dt / 86400.

#Building/loading MESC data from analysis directory
ana_dir = cy.utils.ensure_dir(
    '/data/user/mkovacevich/FRB_analysis/cascades_ana')
repo = cy.selections.Repository()
ana = cy.analysis.Analysis(repo,
                           cy.selections.MESEDataSpecs.mesc_7yr,
                           dir=ana_dir)

cy.CONF['ana'] = ana
cy.CONF['mp_cpus'] = n_cpus

src = cy.sources(FRB_ra_rad,
                 FRB_dec_rad,
                 mjd=FRB_mjd_time,
                 sigma_t=np.zeros_like(FRB_ra_rad),
                 t_100=FRB_time_window)
conf = {
    'extended': True,
    'space': "ps",
    'time': "transient",
    'sig': "transient"
}  #,'flux': cy.hyp.PowerLawFlux(gamma)}

with time('background estimation'):
    allE_tr = cy.get_trial_runner(conf, ana=ana, src=src)
    bg = cy.dists.TSD(allE_tr.get_many_fits(10000, mp_cpus=n_cpus))

# you could also use np.logspace()
Ebins = 10**np.r_[3:7.1:.25]
Beispiel #5
0
        merge=np.concatenate,
        # what to do with items after merge
        post_convert=ndarray_to_Chi2TSD)

TS_above_zero_list = []
for ID in range(0, len(bg)):
    count = 0
    for ts_temp in bg[ID].trials['ts']:
        if ts_temp > 0.0:
            count = count + 1
    TS_above_zero_list.append(count)

TS_above_zero_fraction = np.array(TS_above_zero_list) / len(bg[0].trials['ts'])

sources = cy.sources(GRBs_of_interest['ra'],
                     GRBs_of_interest['decl'],
                     deg=True)
MJD_GRB = GRBs_of_interest['mjd']  #+(GRBs_of_interest['T100']/86400.0)


#Defining the tr
def give_me_tr(raGRB, decGRB, mjd_GRB):
    '''
    This functiom is used to get the trial runners for the prompt+afterglow search for the GRBs to be used 
    in csky.trial.MultiTrialRunner to perform the analysis.
    
    Inputs:
        raGRB: (float) Right Ascension of the GRB in degrees
        decGRB: (float) Declination of the GRB in degrees
        mjd_GRB: (float) 'T_0' of the GRB in Modified Julian Date (in unit of days). This will be the time where
                 the time window is held fixed.