Exemple #1
0
    def log_prior(self,x):
    
        logP = super(MassFunctionModel,self).log_prior(x)
        
        if np.isfinite(logP):
        
            if   (self.model == "LambdaCDM"):
                self.O = cs.CosmologicalParameters(x['h'],x['om'],1.0-x['om'],truths['w0'],truths['w1'])
            elif (self.model == "CLambdaCDM"):
                self.O = cs.CosmologicalParameters(x['h'],x['om'],x['ol'],truths['w0'],truths['w1'])
            elif (self.model == "LambdaCDMDE"):
                self.O = cs.CosmologicalParameters(x['h'],x['om'],x['ol'],x['w0'],x['w1'])
            elif (self.model == "DE"):
                self.O = cs.CosmologicalParameters(truths['h'],truths['om'],truths['ol'],x['w0'],x['w1'])
#            self.O = cs.CosmologicalParameters(truths['h'],truths['om'],truths['ol'],truths['w0'],truths['w1'])
            self.mass_model = gal.GalaxyMassDistribution(self.O,
                                                         x['phistar'],
                                                         x['phistar_exponent'],
                                                         x['logMstar'],
                                                         x['logMstar_exponent'],
                                                         x['alpha'],
                                                         x['alpha_exponent'],
                                                         mmin,
                                                         mmax,
                                                         self.data[:,1].min(),
                                                         self.data[:,1].max(),
                                                         ramin,
                                                         ramax,
                                                         decmin,
                                                         decmax,
                                                         threshold,
                                                         slope_model_choice,
                                                         cutoff_model_choice,
                                                         density_model_choice)
        return logP
Exemple #2
0
    def find_redshift_limits(self,
                             h_w=(0.6, 0.86),
                             om_w=(0.04, 0.5),
                             w0_w=(-1, -1),
                             w1_w=(0, 0)):
        from cosmolisa.likelihood import find_redshift

        def limits(O, Dmin, Dmax):
            return find_redshift(O, Dmin), find_redshift(O, Dmax)

        redshift_min = np.zeros(self.catalog.shape[0])
        redshift_max = np.zeros(self.catalog.shape[0])
        redshift_fiducial = np.zeros(self.catalog.shape[0])

        for k in range(self.catalog.shape[0]):
            sys.stderr.write(
                "finding redshift limits for event {0} out of {1}\r".format(
                    k + 1, self.catalog.shape[0]))
            z_min = np.zeros(100)
            z_max = np.zeros(100)
            for i in range(100):
                h = np.random.uniform(h_w[0], h_w[1])
                om = np.random.uniform(om_w[0], om_w[1])
                ol = 1.0 - om
                w0 = np.random.uniform(w0_w[0], w0_w[1])
                w1 = np.random.uniform(w1_w[0], w1_w[1])
                O = cs.CosmologicalParameters(h, om, ol, w0, w1)
                z_min[i], z_max[i] = limits(
                    O, self.catalog[k, 1] *
                    (np.maximum(0.0, 1.0 - 3 * self.catalog[k, 5])),
                    self.catalog[k, 1] * (1.0 + 3 * self.catalog[k, 5]))
            redshift_min[k] = z_min.min()
            redshift_max[k] = z_max.max()
            redshift_fiducial[k] = find_redshift(self.fiducial_O,
                                                 self.catalog[k, 1])
        sys.stderr.write("\n")
        self.catalog = np.column_stack(
            (self.catalog, redshift_fiducial, redshift_min, redshift_max))
        return self.catalog
Exemple #3
0
    colors = [
        'royalblue', 'gold', 'olive', 'lime', 'orange', 'magenta', 'cyan',
        'turquoise', 'teal', 'purple'
    ]
    from gwmodel.utils.utils import McQ2Masses, chi_eff
    #    events = ['gw151226']
    #    path = "/Users/wdp/repositories/MLGW/paper/img/GWTC-1_results/"
    path = "/Users/wdp/Desktop/GWTC1/LALPSD/"
    init_plotting()
    fig1 = plt.figure()
    ax1 = fig1.add_subplot(111)
    fig2 = plt.figure()
    ax2 = fig2.add_subplot(111)

    handles = []
    O = cs.CosmologicalParameters(0.68, 0.31, 0.69, -1.0, 0.0)
    for c, e in zip(colors, events):
        try:
            print(os.path.join(path, e + '/Nested_sampler/posterior.dat'))
            #            BBH_file = '/Users/wdp/Desktop/GWTC-1_sample_release'+e.upper()+'_GWTC-1.hdf5'
            #            BBH = h5py.File(BBH_file, 'r')
            p = np.genfromtxt(os.path.join(path, e +
                                           '/Nested_sampler/posterior.dat'),
                              names=True)
            z = np.array(
                [find_redshift(O, np.exp(d)) for d in p['logdistance']])
            m1, m2 = McQ2Masses(p['mc'] / (1 + z), p['q'])
            X, Y, PDF = twod_kde(m1, m2)
            string = e.upper() + format_90CR(m1) + format_90CR(
                m2) + format_90CR(p['mc'] /
                                  (1 + z)) + format_90CR(p['q']) + format_90CR(
Exemple #4
0
    def __init__(self,
                 redshift_min=0.0,
                 redshift_max=1.0,
                 ra_min=0.0,
                 ra_max=2.0 * np.pi,
                 dec_min=-np.pi / 2.0,
                 dec_max=np.pi / 2.0,
                 *args,
                 **kwargs):
        self.A0 = 0.000405736691211125  #in rads^2
        self.V0 = 0.1358e5
        self.SNR0 = 87.
        self.ra_min = ra_min
        self.ra_max = ra_max
        self.dec_min = dec_min
        self.dec_max = dec_max
        self.z_min = redshift_min
        self.z_max = redshift_max

        for key, value in kwargs.items():
            if not hasattr(self, key):
                setattr(self, key, value)

        try:
            self.h = getattr(self, 'h')
        except:
            self.h = 0.73
        try:
            self.omega_m = getattr(self, 'omega_m')
        except:
            self.omega_m = 0.25
        try:
            self.omega_lambda = getattr(self, 'omega_lambda')
        except:
            self.omega_lambda = 0.75
        try:
            self.w0 = getattr(self, 'w0')
        except:
            self.w0 = -1.0
        try:
            self.w1 = getattr(self, 'w1')
        except:
            self.w1 = 0.0
        try:
            self.w2 = getattr(self, 'w2')
        except:
            self.w2 = 0.0
        try:
            self.r0 = getattr(self, 'r0')
        except:
            self.r0 = 1.0
        try:
            self.W = getattr(self, 'W')
        except:
            self.W = 0.0
        try:
            self.Q = getattr(self, 'Q')
        except:
            self.Q = 0.0
        try:
            self.R = getattr(self, 'R')
        except:
            self.R = 0.0

        # galaxy population parameters

        try:
            self.phistar0 = getattr(self, 'phistar0')
        except:
            self.phistar0 = 1e-2  # in galaxies per Mpc^{-3}
        try:
            self.logMstar0 = getattr(self, 'logMstar0')
        except:
            self.logMstar0 = -20.7
        try:
            self.alpha0 = getattr(self, 'alpha0')
        except:
            self.alpha0 = -1.23
        try:
            self.Mmin = getattr(self, 'Mmin')
        except:
            self.Mmin = -25
        try:
            self.Mmax = getattr(self, 'Mmax')
        except:
            self.Mmax = -15
        try:
            self.m_threshold = getattr(self, 'm_threshold')
        except:
            self.m_threshold = 17.7

        self.fiducial_O = cs.CosmologicalParameters(self.h, self.omega_m,
                                                    self.omega_lambda, self.w0,
                                                    self.w1)

        # luminosity function evolution model
        try:
            self.slope_model_choice = getattr(self, 'slope_model_choice')
        except:
            self.slope_model_choice = 0
        try:
            self.cutoff_model_choice = getattr(self, 'cutoff_model_choice')
        except:
            self.cutoff_model_choice = 0
        try:
            self.density_model_choice = getattr(self, 'density_model_choice')
        except:
            self.density_model_choice = 0

        if self.cutoff_model_choice == 1:
            try:
                self.logMstar_exponent = getattr(self, 'logMstar_exponent')
            except:
                print(
                    "must define an exponent for the cutoff luminosity evolution"
                )
                exit(-1)
        else:
            self.logMstar_exponent = 0

        if self.slope_model_choice == 1:
            try:
                self.logMstar_exponent = getattr(self, 'alpha_exponent')
            except:
                print("must define an exponent for the slope evolution")
                exit(-1)
        else:
            self.alpha_exponent = 0

        if self.density_model_choice == 1:
            try:
                self.phistar_exponent = getattr(self, 'phistar_exponent')
            except:
                print("must define an exponent for the density evolution")
                exit(-1)
        else:
            self.phistar_exponent = 0

        # now we are ready to sample the EMRI according to the cosmology and rate that we specified
        # find the maximum of the probability for efficiency
        zt = np.linspace(0, self.z_max, 1000)
        self.norm = lk.integrated_rate(self.r0, self.W, self.R, self.Q,
                                       self.fiducial_O, self.z_min,
                                       self.z_max)  #how many EMRIs per time

        self.rate = lambda z: cs.StarFormationDensity(
            z, self.r0, self.W, self.R, self.Q
        ) * self.fiducial_O.UniformComovingVolumeDensity(z)
        self.dist = lambda z: cs.StarFormationDensity(
            z, self.r0, self.W, self.R, self.Q
        ) * self.fiducial_O.UniformComovingVolumeDensity(
            z) / self.norm  #dist to eventually sample
        self.pmax = np.max([self.dist(zi) for zi in zt])

        self.ra_pdf = scipy.stats.uniform(loc=self.ra_min,
                                          scale=self.ra_max - self.ra_min)
        # dec distributed as cos(dec) in [-np.pi/2, np.pi/2] implies sin(dec) uniformly distributed in [-1,1]
        self.sindec_min = np.sin(self.dec_min)
        self.sindec_max = np.sin(self.dec_max)
        self.sindec_pdf = scipy.stats.uniform(loc=self.sindec_min,
                                              scale=self.sindec_max -
                                              self.sindec_min)

        self.galaxy_pmax = None
        self.galaxy_norm = None
Exemple #5
0
    
#    x = x[:100]
    lM  = np.linspace(9.0,13.0,100)
    Z   = np.linspace(data[:,1].min(),data[:,1].max(),100)
    PMZ = np.zeros((x.shape[0],lM.shape[0],Z.shape[0]))
    PM  = np.zeros((x.shape[0],lM.shape[0]))
    PZ  = np.zeros((x.shape[0],Z.shape[0]))
    
    alpha_law = np.zeros((x.shape[0], Z.shape[0]))
    logMstar_law = np.zeros((x.shape[0], Z.shape[0]))
    phistar_law = np.zeros((x.shape[0], Z.shape[0]))
    
    OM, OZ = np.meshgrid(lM,Z)
    for i,xi in enumerate(x):
        sys.stderr.write("processing sample {0} of {1}\r".format(i+1,x.shape[0]))
        mass_model = gal.GalaxyMassDistribution(cs.CosmologicalParameters(xi['h'],xi['om'],1.0-xi['om'],truths['w0'],truths['w1']),
                                         xi['phistar'],
                                         xi['phistar_exponent'],
                                         xi['logMstar'],
                                         xi['logMstar_exponent'],
                                         xi['alpha'],
                                         xi['alpha_exponent'],
                                         mmin,
                                         mmax,
                                         data[:,1].min(),
                                         data[:,1].max(),
                                         ramin,
                                         ramax,
                                         decmin,
                                         decmax,
                                         threshold,
Exemple #6
0
    A = (ramax - ramin) * (np.cos(decmax + np.pi / 2) -
                           np.cos(decmin + np.pi / 2))
    h = 0.73
    om = 0.25
    n0 = 1e-2
    Mstar = -20.7
    Mstar_exponent = -0.13
    cutoff_model_choice = 0
    alpha = -1.23
    alpha_exponent = 0.054
    slope_model_choice = 0
    density_model_choice = 0
    phistar_exponent = -0.1
    threshold = 17.7

    O = cs.CosmologicalParameters(h, om, 1.0 - om, -1.0, 0.0)
    S = gal.GalaxyDistribution(O, n0, phistar_exponent, Mstar, Mstar_exponent,
                               alpha, alpha_exponent, mmin, mmax, zmin, zmax,
                               ramin, ramax, decmin, decmax, threshold, A,
                               slope_model_choice, cutoff_model_choice,
                               density_model_choice)

    N = int(S.get_number_of_galaxies(zmin, zmax, 1))
    #    N = 1000
    print("sampling {0} galaxies in a field of {1} square deg".format(
        N, A * 3282.8063500117))
    galaxies = S.sample_correlated(N,
                                   zmin,
                                   zmax,
                                   ramin,
                                   ramax,