示例#1
0
def make_coord_table(stripes, params):
    """ Makes a table of the Sgr dections, in standard coordinates
        Stripe #, x, y, z, l, b, lam, beta, new_lam, new_beta, R"""
    Sgr_lbr = [5.6, -14.2, 24.0]
    Sgr_xyz = [14.655645800014774, 2.2704309216189817, -5.8873772610912614]
    Stream_North = [-0.199, 0.935, 0.293, -0.988]
    Stream_South = [0.032, 0.987, 0.158, -1.073]
    coords = []
    for i, stripe in enumerate(stripes):
        mu, r, theta, phi = eval(params[i][4]), eval(params[i][5]), \
            eval(params[i][6]), eval(params[i][7])
        x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta*deg, phi*deg, stripe)
        l,b,r = coor.xyz2lbr(x,y,z)
        Xs, Ys, Zs, lam, beta, rs = sl.law_xyz2sgr_sun(x,y,z)
        if lam > 180.0:  lam = lam - 360.0
        # Just going to use Sgr North plane for now
        xp, yp, zp = coor.xyz2plane(x,y,z, new_x=Sgr_xyz, plane=Stream_North, origin=-8.5)
        long, lat, rp = coor.xyz2longlat(xp,yp,zp)
        print r, rs, rp
        coords.append([stripe, x, y, z, l, b, lam, beta, long, lat, r])
    # Now make table
    coord_table = tex.DataTable(sc.array(coords), 'lcccccccccc', "Sagittarius Stream Centers",
            "coordtable", ["Stripe",r"$X_{GC}$",r"$Y_{GC}$",r"$Z_{GC}$",r"$l$",r"$b$",
                           r"$\Lambda_{LM}$",r"$\Beta_{LM}$",r"$\Lambda_{new}$",
                           r"$\Beta_{new}$", r"$R_{\sun} (kpc)$"])
    tex.deluxe_table(coord_table, roundoff=1)
    
    """Sgr_lbr = [5.6, -14.2, 24.0]
def generate_perturbation(num_stars, params, parameters, batch=1000, fail_quit=100,
                          fileout="Pertgen82.txt", detection=1, convolve=1, append=0, primary=0):
    """Density of perturbation added to background, as a function of position"""
    # Initialize file
    if append==0:
        out = open(fileout, 'w')
        out.write("# "+str(num_stars)+" stars, l,b,r \n")
        out.close()
    # Get integral
    tot_prob = get_max_prob_2(params, parameters)
    N_out, fails = 0, 0
    g_min, g_max = params.stripe[2][0], params.stripe[2][1]
    while N_out < num_stars:
        # Generate Points
        mu, nu, r = get_stripe_points(params.mu_lim, params.nu_lim, params.r_lim, batch)
        # Test points for inclusion
        x,y,z = co.GC2xyz(mu, nu, r, params.wedge)
        holder = []
        for i in range(len(mu)):
            rho = perturb_density(x[i],y[i],z[i], parameters)
            #print (rho / tot_prob), rho, tot_prob
            if (rho / tot_prob) > np.random.uniform():
                l,b,r1 = co.xyz2lbr(x[i], y[i], z[i])
                # Convolve
                if convolve==1:
                    r1 = star_convolution(r1, params.modfit)
                # Detection
                if detection==1:
                    m_g = co.getg(r1)
                    if np.random.uniform() > sigmoid_error(m_g, params.modfit):  continue
                if (co.getg(r1) < g_min) or (co.getg(r1) > g_max):  continue
                if primary == 1:
                    if co.SDSS_primary(l,b,wedge,fmt='lb',low=9,high=25) == 0:  continue
                # Add to keepers
                holder.append([round(l,6),round(b,6),round(r1,6)])
                N_out = N_out + 1
        # Failure code
        if len(holder) == 0:  fails = fails + 1
        if fails >= fail_quit:  break
        # Remove possible excess stars
        if N_out > num_stars:
            slice = -1*(N_out-num_stars)
            holder = holder[:slice]
            print "#---Sliced {0} stars to make quota".format(str(-1*slice))
            N_out = N_out + slice #Slice is negative
        # Add to dataset
        if len(holder) != 0:
            if fi.append_data(sc.array(holder), fileout, delimiter=" ") == 1:
                print "#---Perturbation Progress: {0} stars of {1} total stars generated".format(N_out, num_stars)
    if fails >= fail_quit:  
        print "!!! Perturbation generation FAILED due to overstepping empty batch limit: {0}".format(fail_quit)
    else:
        print "#---Perturbation generation succeeded, written as {0}, with {1} empty batches".format(fileout, fails)
    return fileout
示例#3
0
def make_coord_table(stripes, params):
    """ Makes a table of the Sgr dections, in standard coordinates
        Stripe #, x, y, z, l, b, lam, beta, new_lam, new_beta, R"""
    Sgr_lbr = [5.6, -14.2, 24.0]
    Sgr_xyz = [14.655645800014774, 2.2704309216189817, -5.8873772610912614]
    Stream_North = [-0.199, 0.935, 0.293, -0.988]
    Stream_South = [0.032, 0.987, 0.158, -1.073]
    coords = []
    for i, stripe in enumerate(stripes):
        mu, r, theta, phi = eval(params[i][4]), eval(params[i][5]), \
            eval(params[i][6]), eval(params[i][7])
        x, y, z = coor.stream2xyz(0.0, 0.0, 0.0, mu, r, theta * deg, phi * deg,
                                  stripe)
        l, b, r = coor.xyz2lbr(x, y, z)
        Xs, Ys, Zs, lam, beta, rs = sl.law_xyz2sgr_sun(x, y, z)
        if lam > 180.0: lam = lam - 360.0
        # Just going to use Sgr North plane for now
        xp, yp, zp = coor.xyz2plane(x,
                                    y,
                                    z,
                                    new_x=Sgr_xyz,
                                    plane=Stream_North,
                                    origin=-8.5)
        long, lat, rp = coor.xyz2longlat(xp, yp, zp)
        print r, rs, rp
        coords.append([stripe, x, y, z, l, b, lam, beta, long, lat, r])
    # Now make table
    coord_table = tex.DataTable(
        sc.array(coords), 'lcccccccccc', "Sagittarius Stream Centers",
        "coordtable", [
            "Stripe", r"$X_{GC}$", r"$Y_{GC}$", r"$Z_{GC}$", r"$l$", r"$b$",
            r"$\Lambda_{LM}$", r"$\Beta_{LM}$", r"$\Lambda_{new}$",
            r"$\Beta_{new}$", r"$R_{\sun} (kpc)$"
        ])
    tex.deluxe_table(coord_table, roundoff=1)
    """Sgr_lbr = [5.6, -14.2, 24.0]
示例#4
0
def generate_perturbation(num_stars,
                          params,
                          parameters,
                          batch=1000,
                          fail_quit=100,
                          fileout="Pertgen82.txt",
                          detection=1,
                          convolve=1,
                          append=0,
                          primary=0):
    """Density of perturbation added to background, as a function of position"""
    # Initialize file
    if append == 0:
        out = open(fileout, 'w')
        out.write("# " + str(num_stars) + " stars, l,b,r \n")
        out.close()
    # Get integral
    tot_prob = get_max_prob_2(params, parameters)
    N_out, fails = 0, 0
    g_min, g_max = params.stripe[2][0], params.stripe[2][1]
    while N_out < num_stars:
        # Generate Points
        mu, nu, r = get_stripe_points(params.mu_lim, params.nu_lim,
                                      params.r_lim, batch)
        # Test points for inclusion
        x, y, z = co.GC2xyz(mu, nu, r, params.wedge)
        holder = []
        for i in range(len(mu)):
            rho = perturb_density(x[i], y[i], z[i], parameters)
            #print (rho / tot_prob), rho, tot_prob
            if (rho / tot_prob) > np.random.uniform():
                l, b, r1 = co.xyz2lbr(x[i], y[i], z[i])
                # Convolve
                if convolve == 1:
                    r1 = star_convolution(r1, params.modfit)
                # Detection
                if detection == 1:
                    m_g = co.getg(r1)
                    if np.random.uniform() > sigmoid_error(m_g, params.modfit):
                        continue
                if (co.getg(r1) < g_min) or (co.getg(r1) > g_max): continue
                if primary == 1:
                    if co.SDSS_primary(l, b, wedge, fmt='lb', low=9,
                                       high=25) == 0:
                        continue
                # Add to keepers
                holder.append([round(l, 6), round(b, 6), round(r1, 6)])
                N_out = N_out + 1
        # Failure code
        if len(holder) == 0: fails = fails + 1
        if fails >= fail_quit: break
        # Remove possible excess stars
        if N_out > num_stars:
            slice = -1 * (N_out - num_stars)
            holder = holder[:slice]
            print("#---Sliced {0} stars to make quota".format(str(-1 * slice)))
            N_out = N_out + slice  #Slice is negative
        # Add to dataset
        if len(holder) != 0:
            if fi.append_data(sc.array(holder), fileout, delimiter=" ") == 1:
                print(
                    "#---Perturbation Progress: {0} stars of {1} total stars generated"
                    .format(N_out, num_stars))
    if fails >= fail_quit:
        print(
            "!!! Perturbation generation FAILED due to overstepping empty batch limit: {0}"
            .format(fail_quit))
    else:
        print(
            "#---Perturbation generation succeeded, written as {0}, with {1} empty batches"
            .format(fileout, fails))
    return fileout