Beispiel #1
0
    parser.add_option('-m',
                      '--model',
                      default='LAMBDACDM',
                      type='string',
                      metavar='model',
                      help='model (default: LAMBDACDM)')
    parser.add_option('-s',
                      '--source',
                      default=None,
                      type='string',
                      metavar='source',
                      help='source class')
    (opts, args) = parser.parse_args()
    init_plotting()
    # read in the events
    events = readdata.read_event(opts.source, opts.data)
    # read in the posterior samples
    try:
        f**k
        posteriors = np.genfromtxt(opts.posteriors, names=True)
    except:
        from cpnest import nest2pos
        x = np.genfromtxt('test_logP_dv/chain_1000_1234.txt', names=True)
        posteriors = nest2pos.draw_posterior_many([x], [1000], verbose=False)
        names = ''
        for n in posteriors.dtype.names:
            names += n + '\t'
        np.savetxt('test_logP_dv/posterior.dat', posteriors, header=names)

    dl = [e.dl / 1e3 for e in events]
    ztrue = [e.potential_galaxy_hosts[0].redshift for e in events]
    parser.add_option('--postprocess',
                      default=0,
                      type='int',
                      metavar='postprocess',
                      help='run only the postprocessing')
    (opts, args) = parser.parse_args()

    em_selection = opts.em_selection

    if opts.event_class == "MBH":
        # if running on SMBH override the selection functions
        em_selection = 0

    if opts.event_class == "EMRI" and opts.joint != 0:
        np.random.seed(opts.seed)
        events = readdata.read_event(opts.event_class, opts.data, None)
        N = opts.joint  #np.int(np.random.poisson(len(events)*4./10.))
        print("Will run a random catalog selection of {0} events:".format(N))
        print("==================================================")
        selected_events = []
        count = 0
        if 1:
            while len(selected_events) < N - count and not (len(events) == 0):

                while True:
                    if len(events) > 0:
                        idx = np.random.randint(len(events))
                        selected_event = events.pop(idx)
                    else:
                        break
                    if selected_event.z_true < opts.zhorizon:
Beispiel #3
0
                      metavar='model',
                      help='model (default: LAMBDACDM)')
    parser.add_option('-s',
                      '--source',
                      default=None,
                      type='string',
                      metavar='source',
                      help='source class')
    (opts, args) = parser.parse_args()
    init_plotting()

    os.system('mkdir -p {0}'.format(opts.outdir))

    # Read in the events
    events = readdata.read_event(opts.source,
                                 opts.data,
                                 None,
                                 snr_threshold=100.0)
    # Read in the posterior samples
    filename = os.path.join(opts.posteriors, 'CPNest', 'cpnest.h5')
    print("\nReading {} averaged posterior stored in {}".format(
        opts.source, filename))
    h5_file = h5py.File(filename, 'r')
    posteriors = h5_file['combined'].get('posterior_samples')

    # Injected cosmology
    omega_true = CosmologicalParameters(0.73, 0.25, 0.75, -1, 0)

    dlmeasured = []
    zmeasured = []
    dzmeasured = []
    ddlmeasured = []
    parser.add_option('-o','--out',action='store',type='string',default=None,help='Output folder', dest='output')
    parser.add_option('-d',action='store',type='string',default=None,help='data folder', dest='data')
    parser.add_option('-c',action='store',type='string',default=None,help='source class (MBH, EMRI, sBH)', dest='source_class')
    parser.add_option('-m',action='store',type='string',default='LambdaCDM',help='model (LambdaCDM, LambdaCDMDE)', dest='model')
    parser.add_option('-r',action='store',type='int',default=0,help='realisation number', dest='realisation')
    parser.add_option('-p',action='store',type='int',default=0,help='unpickle precomputed posteriors', dest='pickle')
    parser.add_option('-N',action='store',type='int',default=None,help='Number of bins for the grid sampling', dest='N')
    parser.add_option('-e',action='store',type='int',default=None,help='Number of events to combine', dest='Nevents')
    parser.add_option('--nlive',action='store',type='int',default=5000,help='Number of live points', dest='nlive')
    (options,args)=parser.parse_args()

    out_folder = os.path.join(options.output,str(options.realisation))
    os.system("mkdir -p %s"%out_folder)
    np.random.seed(options.realisation)

    events = readdata.read_event(options.source_class, options.data, None)

    N = len(events)
#    if options.source_class == "EMRI":
#        N = np.int(np.random.poisson(len(events)*4./10.))#len(events)
#        events = np.random.choice(events,size = N,replace=False)

    omega_true = CosmologicalParameters(truths['h'],
                                        truths['om'],
                                        truths['ol'],
                                        truths['w0'],
                                        truths['w1'])

    Nbins = options.N
    joint_posterior = np.zeros((Nbins,Nbins),dtype=np.float64)#-2.0*np.log(Nbins)
    
Beispiel #5
0
import numpy as np

import readdata

events = readdata.read_event(
    "EMRI", "./data/EMRI_SAMPLE_MODEL101_TTOT10yr_SIG2_GAUSS", None)

densities = np.array([e.n_hosts / e.VC for e in events])
densities.sort()
print([d for d in densities])
print(np.average(densities, weights=[e.VC for e in events]))

import matplotlib.pyplot as plt
zs = []
for e in events:
    zs.append(np.average([g.redshift for g in e.potential_galaxy_hosts]))

x = [e.VC for e in events]
y = densities
p = np.polyfit(np.log(x), np.log(y), 1)
print(p)
plt.scatter(np.log(x), np.log(y))
xp = np.linspace(np.log(x).min(), np.log(x).max(), 1000)
plt.plot(xp, np.poly1d(p)(xp))
plt.show()