Beispiel #1
0
def run_pop_synth(input_sys, N_sys=10000, t_low=15.0, t_high=60.0, delta_t=1):
    """ Run a forward population synthesis

    Parameters
    ----------
    input_sys : ra_sys, dec_sys, P_orb_sys, ecc_sys, M2_d_sys
        Observed values of individual system
    N_sys : int
        Number of systems per age calculated (10000)
    t_low : float
        Lower limit to age range tested (15 Myr)
    t_high : float
        Upper limit to age range tested (60 Myr)
    delta_t : float
        Age resolution (1 Myr)

    Returns
    -------
    HMXB_sys : numpy recarray
        Systems that evolve into the observed system
        names = ["ra", "dec", "ra_b", "dec_b", "P_orb", "ecc", "M_2_d", "theta_proj", "age", "norm"]
    init_params_sys : numpy recarray
        Initial conditions for the observed Systems
        names = ["M1","M2","A","ecc","v_k","theta","phi","ra_b","dec_b","t_b"]
    """


    ra_sys, dec_sys, P_orb_sys, ecc_sys, M2_d_sys = input_sys

    # First thing is to load the sse data and SF_history data
    load_sse.load_sse()
    sf_history.load_sf_history()

    names = ["ra", "dec", "ra_b", "dec_b", "P_orb", "ecc", "M_2_d", "theta_proj", "age", "norm"]

    HMXB = np.recarray(0, names=names, formats=['float64,float64,float64,float64,float64,float64,float64,float64,float64,float64'])
    HMXB_sys = np.recarray(0, names=names, formats=['float64,float64,float64,float64,float64,float64,float64,float64,float64,float64'])

    names = ["M1","M2","A","ecc","v_k","theta","phi","ra_b","dec_b","t_b"]
    init_params_sys = np.recarray(0, names=names, formats=['float64,float64,float64,float64,float64,float64,float64,float64,float64,float64'])


    theta_sep = np.array([])

    batch_size = 1000
    n_batch = int(np.ceil(float(N_sys)/float(batch_size)))

    for t_b in np.linspace(14.0, 56.0, 43):

        for batch in np.arange(n_batch):
            n_run = min(batch_size, N_sys - (batch)*batch_size)
            HMXB_t, init_params_t = create_HMXBs(t_b, N_sys=n_run, ra_in=ra_sys, dec_in=dec_sys)
            HMXB = np.concatenate((HMXB, HMXB_t))

            for i in np.arange(len(HMXB_t)):

                h = HMXB_t[i]
                p = init_params_t[i]

                angle = c.rad_to_deg * sf_history.get_theta_proj_degree(ra_sys, dec_sys, h["ra"], h["dec"])
                theta_sep = np.append(theta_sep, angle)

                if angle < 0.2 \
                    and np.abs(h["P_orb"] - P_orb_sys) < 5.0 \
                    and np.abs(h["ecc"] - ecc_sys) < 0.1 \
                    and np.abs(h["M_2_d"] - M2_d_sys) < 1.0:

                    HMXB_sys = np.append(HMXB_sys, h)
                    init_params_sys = np.append(init_params_sys, p)


    return HMXB_sys, init_params_sys
Beispiel #2
0
def get_random_positions(N, t_b, ra_in=None, dec_in=None):
    """ Use the star formation history to generate a population of new binaries

    Parameters
    ----------
    N : integer
        Number of positions to calculate
    t_b : float
        Birth time to calculate star formation history (Myr)
    ra_in : float
        RA of system (optional)
    dec_in : float
        Dec of system (optional)

    Returns
    -------
    ra_out : ndarray
        Array of output RA's (degrees)
    dec_out : ndarray
        Array of output Dec's (degrees)
    N_stars : int
        Normalization constant calculated from number of stars formed at time t_b
    """

    if sf_history.smc_sfh is None or sf_history.smc_coor is None:
        sf_history.load_sf_history()

    N_regions = len(sf_history.smc_sfh)

    # If provided with an ra and dec, only generate stars within 3 degrees of input position
    SF_regions = np.zeros((2,N_regions))
    for i in np.arange(N_regions):
        SF_regions[0,i] = i

        if ra_in is None or dec_in is None:
            SF_regions[1,i] = sf_history.smc_sfh[i](np.log10(t_b*1.0e6))
        elif sf_history.get_theta_proj_degree(sf_history.smc_coor["ra"][i], sf_history.smc_coor["dec"][i], ra_in, dec_in) < c.deg_to_rad * 3.0:
            SF_regions[1,i] = sf_history.smc_sfh[i](np.log10(t_b*1.0e6))
        else:
            SF_regions[1,i] = 0.0

    N_stars = np.sum(SF_regions, axis=1)[1]

    # Normalize
    SF_regions[1] = SF_regions[1] / N_stars

    # Sort
    SF_sort = SF_regions[:,SF_regions[1].argsort()]

    # Move from normed PDF to CDF
    SF_sort[1] = np.cumsum(SF_sort[1])

    # TEST #
#    ra_out = lmc_coor["ra"][SF_sort[0][-100:].astype(int)]
#    dec_out = lmc_coor["dec"][SF_sort[0][-100:].astype(int)]
#    return ra_out, dec_out
    # TEST #

    # Random numbers
    y = uniform.rvs(size=N)

    # Create a 2D grid of CDFs, and random numbers
    SF_out, y_out = np.meshgrid(SF_sort[1], y)

    # Get index of closest region in sorted array
    indices = np.argmin((SF_out - y_out)**2,axis=1)

    # Move to indices of stored LMC SFH data array
    indices = SF_sort[0][indices].astype(int)

    # Get random ra's and dec's of each region
    ra_out = sf_history.smc_coor["ra"][indices]
    dec_out = sf_history.smc_coor["dec"][indices]

    # Width is 12 arcmin or 12/60 degrees for outermost regions
    # Width is 6 arcmin or 6/60 degrees for inner regions
#    width = 12.0 / 60.0 * np.ones(len(indices))
    width = 6.0 / 60.0 * np.ones(len(indices))
#    for i in np.arange(len(indices)):
#        if str(smc_coor["region"][indices[i]]).find("_") != -1:
#            width[i] = 6.0 / 60.0

    tmp_delta_ra = width * (2.0 * uniform.rvs(size=len(indices)) - 1.0) / np.cos(c.deg_to_rad * dec_out) * 2.0
    tmp_delta_dec = width * (2.0 * uniform.rvs(size=len(indices)) - 1.0)

    ra_out = ra_out + tmp_delta_ra
    dec_out = dec_out + tmp_delta_dec

    return ra_out, dec_out, N_stars