Exemplo n.º 1
0
def stream_into_stripe(params,
                       sn,
                       N_stars,
                       batch=1000,
                       fileout="streamgen82.txt",
                       detection=1,
                       convolve=1,
                       append=0,
                       progbar=1,
                       primary=0):
    """ sn is stream number"""
    # Initialize file
    if append == 0:
        out = open(fileout, 'w')
        out.write("# " + str(N_stars) + " stars, l,b,r \n")
        out.close()
    # Get constants
    mu,R,theta,phi,sigma,wedge = \
        params.mu[sn],params.R[sn],params.theta[sn],params.phi[sn],params.sigma[sn], params.wedge
    print("Stream Parameters", mu, R, theta, phi, sigma, wedge)
    u_min, u_max = get_stream_length(params, sn, accuracy=0.0001)
    nu_min, nu_max = params.nu_lim[0], params.nu_lim[1]
    mu_min, mu_max = params.mu_lim[0], params.mu_lim[1]
    g_min, g_max = params.stripe[2][0], params.stripe[2][1]
    #print "# - Generating Stream {0}, using parameters {1}, {2}, {3}, {4}, {5}".format(
    #    sn, mu, R, theta, phi, sigma)
    N_out = 0
    pb = pr.Progressbar(steps=N_stars,
                        prefix="Stream {0} progress:".format(sn),
                        suffix="Generating {0} Stars".format(N_stars),
                        symbol="#",
                        active="=",
                        brackets="[]",
                        percent=True,
                        size=40)
    while N_out < N_stars:
        mu_killed, nu_killed, mu_saved = 0, 0, 0
        u, v, w = generate_stream(batch, u_min, u_max, sigma)
        holder = []
        for i in range(len(u)):
            mu1, nu1, r1 = co.streamToGC(u[i], v[i], w[i], mu, R, theta * deg,
                                         phi * deg, wedge)
            if (nu1 < nu_min) or (nu1 > nu_max):
                nu_killed = nu_killed + 1
                continue
            if (mu_max > 360.0):
                if (mu1 > (mu_max - 360.0)) and (mu1 < mu_min):
                    mu_killed = mu_killed + 1
                    continue
            else:
                if (mu1 < mu_min) or (mu1 > mu_max):
                    mu_killed = mu_killed + 1
                    continue
            if primary == 1:
                if co.SDSS_primary(mu1, nu1, wedge, low=9, high=25) == 0:
                    continue
            # 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
            # When a point passes all the testsm add it to the set
            l, b, r1 = co.GC2lbr(mu1, nu1, r1, wedge)
            #co.stream2xyz(u[i],v[i],w[i],mu,R,theta,phi,wedge)
            holder.append([round(l, 6), round(b, 6), round(r1, 6)])
            N_out = N_out + 1
        if N_out > N_stars:
            slice = -1 * (N_out - N_stars)
            holder = holder[:slice]
            #print "#---Sliced {0} stars to make quota".format(str(-1*slice))
            N_out = N_out + slice  #Slice is negative
        #append to file
        if len(holder) != 0:
            if fi.append_data(sc.array(holder), fileout, delimiter=" ") == 1:
                #print "#---Stream Progress: {0} stars of {1} total stars generated".format(N_out, N_stars)
                #print "# !!! - mu killed: {0}, mu_saved: {1}, nu_killed: {2}".format(mu_killed, mu_saved, nu_killed)
                pb.updatebar(float(N_out) / float(N_stars))
    print("#---Stream {0} generation succeeded, written as {1}".format(
        sn, fileout))
    return fileout
Exemplo n.º 2
0
def get_stream_length(params, N=0, accuracy=0.0001):
    """ gets the length of a stream within an SDSS wedge; N=stream number"""
    mu, R, theta, phi, wedge = params.mu[N], params.R[N], params.theta[
        N], params.phi[N], params.wedge
    # make a point (or points) in xyz along stream direction
    u1, v1, w1 = 0.1, 0.0, 0.0
    u2, v2, w2 = -0.1, 0.0, 0.0
    #check to see which is closest to the nu = +2.5 boundry, flip if necessary
    mu1, nu1, r1 = co.streamToGC(u1, v1, w1, mu, R, theta * deg, phi * deg,
                                 wedge)
    mu2, nu2, r2 = co.streamToGC(u2, v2, w2, mu, R, theta * deg, phi * deg,
                                 wedge)
    if np.fabs(nu1 - 2.5) > np.fabs(nu2 - 2.5):
        u1, u2 = (-1.0 * u1), (-1.0 * u2)
        temp = nu1
        nu1, nu2 = nu2, temp
    # check them against wedge boundries (mu, nu, r)
    test = 0
    while test == 0:
        mu1, nu1, r1 = co.streamToGC(u1, v1, w1, mu, R, theta * deg, phi * deg,
                                     wedge)
        # account for wrap-around
        if params.mu_lim[1] > 360.0:
            if mu1 < params.mu_lim[0]: mu1 = mu1 + 360.0
        if (mu1 < params.mu_lim[0]) or (mu1 > params.mu_lim[1]):
            #print "u1 ({0}) finished due to mu lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        if (nu1 > 2.5):
            #print "u1 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        if (nu1 < -2.5):
            #print "!!! WARNING:  u1 EXITED DUE TO OPPOSITE THRESHOLD"
            #print "u1 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        if (r1 < params.r_lim[0]) or (r1 > params.r_lim[1]):
            #print "u1 ({0}) finished due to r lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        u1 = u1 + 0.1
        if u1 > 100.0:
            print("!!! u1 {0} reached threshold limit!".format(u1))
            test = 1
    # Do for u2
    test = 0
    while test == 0:
        mu2, nu2, r2 = co.streamToGC(u2, v2, w2, mu, R, theta * deg, phi * deg,
                                     wedge)
        # account for wrap-around
        if params.mu_lim[1] > 360.0:
            if mu2 < params.mu_lim[0]: mu2 = mu2 + 360.0
        if (mu2 < params.mu_lim[0]) or (mu2 > params.mu_lim[1]):
            #print "u2 ({0}) finished due to mu lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        if (nu2 < -2.5):
            #print "u2 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        if (nu2 > 2.5):
            #print "!!! WARNING:  u2 EXITED DUE TO OPPOSITE THRESHOLD"
            #print "u2 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        if (r2 < params.r_lim[0]) or (r2 > params.r_lim[1]):
            #print "u2 ({0}) finished due to r lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        u2 = u2 - 0.1
        if u2 < -100.0:
            print("!!! u1 {0} reached threshold limit!".format(u1))
            test = 1
    # finish up
    length = np.fabs(u1 - u2)
    print("# Stream is {0} kpc long within wedge boundaries".format(length))
    while np.fabs(u1 - u2) < 60.0:
        u1 = u1 * 2.0
        u2 = u2 * 2.0
    if u2 > u1: return u1, u2
    else: return u2, u1
Exemplo n.º 3
0
def plot_stripe_results(param_string,
                        wedge,
                        data=None,
                        outname=None,
                        mag=0,
                        scale=0,
                        color=1,
                        mu_lim=None,
                        r_lim=None,
                        vm=None,
                        nu_flatten=0,
                        bar=1):
    """ Graphically plots a parameter set, with or without the accompanying data
		param_string:  a list of MLE fit parameters
		"""
    halo = param_string[:2]
    p1, p2, p3 = None, None, None
    if len(param_string) > 2: p1 = param_string[2:8]
    if len(param_string) > 8: p2 = param_string[8:14]
    if len(param_string) > 14: p3 = param_string[14:]
    t = sc.arange(0.0, 360.0, 0.1) * rad
    fig = plt.figure(1, frameon=False)
    if data != None:
        sp = single_stripe_mur(data, wedge, mag, scale, color, 111, mu_lim,
                               r_lim, vm, nu_flatten, bar)
    else:
        sp = single_stripe_mur(sc.array([[0.0, 0.0, 0.0]]), wedge, mag, scale,
                               color, 111, mu_lim, r_lim, vm, nu_flatten, bar)
    # Halo
    xhalo, yhalo = (halo[1] * sc.cos(t)), (halo[1] * sc.sin(t))
    sp.plot(xhalo, yhalo, "k--")
    # Stream 1
    if p1 != None:
        u1, v1 = p1[5] * sc.cos(t), p1[5] * sc.sin(t)
        mu1, nu1, r1 = sc.zeros(len(t)), sc.zeros(len(t)), sc.zeros(len(t))
        for i in range(len(t)):
            mu1[i], nu1[i], r1[i] = coor.streamToGC(u1[i], v1[i], 0.0, p1[1],
                                                    p1[2], p1[3], 2.2 * p1[4],
                                                    wedge)
        sp.plot(r1 * sc.cos(mu1 * rad), r1 * sc.sin(mu1 * rad), "k-")
    # Stream 2
    if p2 != None:
        u2, v2 = p2[5] * sc.cos(t), p2[5] * sc.sin(t)
        mu2, nu2, r2 = sc.zeros(len(t)), sc.zeros(len(t)), sc.zeros(len(t))
        for i in range(len(t)):
            mu2[i], nu2[i], r2[i] = coor.streamToGC(u2[i], v2[i], 0.0, p2[1],
                                                    p2[2], p2[3], 2.2 * p2[4],
                                                    wedge)
        sp.plot(r2 * sc.cos(mu2 * rad), r2 * sc.sin(mu2 * rad), "b-")
    # Stream 3
    if p3 != None:
        u3, v3 = p3[5] * sc.cos(t), p3[5] * sc.sin(t)
        mu3, nu3, r3 = sc.zeros(len(t)), sc.zeros(len(t)), sc.zeros(len(t))
        for i in range(len(t)):
            mu3[i], nu3[i], r3[i] = coor.streamToGC(u3[i], v3[i], 0.0, p3[1],
                                                    p3[2], p3[3], 2.2 * p3[4],
                                                    wedge)
        sp.plot(r3 * sc.cos(mu3 * rad), r3 * sc.sin(mu3 * rad), "r-")
    """ Draw Plot """
    plt.xlim(-60.0, 60.0)
    plt.ylim(-60.0, 60.0)
    if outname == None: plt.show()
    else:
        plt.savefig(outname +
                    ".png")  #;plt.savefig((outname+".ps"), papertype='letter')
    plt.close('all')
Exemplo n.º 4
0
def stream_gen(params,
               sn,
               N_stars,
               batch=1000,
               fileout="streamgen82.txt",
               detection=1,
               convolve=1,
               append=0):
    """ sn is stream number"""
    # Initialize file
    if append == 0:
        out = open(fileout, 'w')
        out.write("# " + str(N_stars) + " stars, l,b,r,flag \n")
        out.close()
    # Get constants
    mu,R,theta,phi,sigma,wedge = \
        params.mu[sn],params.R[sn],params.theta[sn],params.phi[sn],params.sigma[sn], params.wedge
    u_min, u_max = twg.get_stream_length(params, sn, accuracy=0.00001)
    nu_min, nu_max = params.nu_lim[0], params.nu_lim[1]
    mu_min, mu_max = params.mu_lim[0], params.mu_lim[1]
    g_min, g_max = params.stripe[2][0], params.stripe[2][1]
    print "# - Generating Stream {0}, using parameters {1}, {2}, {3}, {4}, {5}".format(
        sn, mu, R, theta, phi, sigma)
    X_out, Y_out = 0, 0  # X_out is stars detected in stripe, Y_out is stars generated that should be there.
    while X_out < N_stars:
        mu_killed, nu_killed, mu_saved = 0, 0, 0
        u, v, w = twg.generate_stream(batch, u_min, u_max, sigma)
        holder = []
        for i in range(len(u)):
            mu1, nu1, r1 = coor.streamToGC(u[i], v[i], w[i], mu, R, theta, phi,
                                           wedge)
            l, b, r1 = coor.GC2lbr(mu1, nu1, r1, wedge)
            # Convolve
            if convolve == 1:
                r1 = twg.star_convolution(r1)
            # Test nu, kill if invalid
            if (nu1 < nu_min) or (nu1 > nu_max):
                nu_killed = nu_killed + 1
                #Y_out=Y_out+1   # COMMENT
                #holder.append([round(l,6),round(b,6),round(r1,6), 1])  # COMMENT
                continue
            # Test mu, keep in Y if out of bounds
            if (mu_max > 360.0):
                if (mu1 > (mu_max - 360.0)) and (mu1 < mu_min):
                    mu_killed = mu_killed + 1
                    Y_out = Y_out + 1
                    holder.append([round(l, 6), round(b, 6), round(r1, 6), 1])
                    continue
            else:
                if (mu1 < mu_min) or (mu1 > mu_max):
                    mu_killed = mu_killed + 1
                    Y_out = Y_out + 1
                    holder.append([round(l, 6), round(b, 6), round(r1, 6), 1])
                    continue
            # Detection
            if detection == 1:
                m_g = coor.getg(r1)
                if np.random.uniform() > (twg.sigmoid_error(m_g)):
                    Y_out = Y_out + 1
                    holder.append([round(l, 6), round(b, 6), round(r1, 6), 1])
                    continue
            # test g-limits
            if (coor.getg(r1) < g_min) or (coor.getg(r1) > g_max):
                Y_out = Y_out + 1
                holder.append([round(l, 6), round(b, 6), round(r1, 6), 1])
                continue
            # When a point passes all the tests add it to the set
            #co.stream2xyz(u[i],v[i],w[i],mu,R,theta,phi,wedge)
            holder.append([round(l, 6), round(b, 6), round(r1, 6), 0])
            X_out = X_out + 1
        if X_out > N_stars:
            slice = -1 * (X_out - N_stars)
            holder = holder[:slice]
            print "#---Sliced {0} stars to make quota".format(str(-1 * slice))
            X_out = X_out + slice  #Slice is negative
        #append X and Y to files
        if len(holder) != 0:
            if fi.append_data(sc.array(holder), fileout, delimiter=" ") == 1:
                print "#---Stream Progress: {0} stars of stars generated out of {1} detected".format(
                    Y_out + X_out, N_stars)
                print "# !!! - out of mu: {0}, nu_killed: {1}".format(
                    mu_killed, nu_killed)
    print "#---Stream {0} generation succeeded, written as {1}".format(
        sn, fileout)
    print " ### -----  Stream {0} Complete ----- ### \n"
    return fileout
Exemplo n.º 5
0
def get_stream_length(params, N=0, accuracy=0.0001):
    """ gets the length of a stream within an SDSS wedge; N=stream number"""
    mu, R, theta, phi, wedge = params.mu[N],params.R[N],params.theta[N],params.phi[N],params.wedge
    # make a point (or points) in xyz along stream direction
    u1,v1,w1 = 0.1,  0.0, 0.0
    u2,v2,w2 = -0.1,  0.0, 0.0
    #check to see which is closest to the nu = +2.5 boundry, flip if necessary
    mu1, nu1, r1 = co.streamToGC(u1,v1,w1,mu, R, theta*deg, phi*deg, wedge)
    mu2, nu2, r2 = co.streamToGC(u2,v2,w2,mu, R, theta*deg, phi*deg, wedge)
    if np.fabs(nu1 - 2.5) > np.fabs(nu2 - 2.5):
        u1, u2 = (-1.0*u1), (-1.0*u2)
        temp = nu1
        nu1, nu2 = nu2, temp
    # check them against wedge boundries (mu, nu, r)
    test = 0
    while test==0:
        mu1, nu1, r1 = co.streamToGC(u1,v1,w1,mu, R, theta*deg, phi*deg, wedge)
        # account for wrap-around
        if params.mu_lim[1] > 360.0:
            if mu1 < params.mu_lim[0]:  mu1 = mu1 + 360.0
        if (mu1 < params.mu_lim[0]) or (mu1 > params.mu_lim[1]):
            #print "u1 ({0}) finished due to mu lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        if (nu1 > 2.5):
            #print "u1 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        if (nu1 < -2.5):
            #print "!!! WARNING:  u1 EXITED DUE TO OPPOSITE THRESHOLD"
            #print "u1 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        if (r1 < params.r_lim[0]) or (r1 > params.r_lim[1]):
            #print "u1 ({0}) finished due to r lim: {1}, {2}, {3}".format(u1, mu1, nu1, r1)
            break
        u1 = u1 + 0.1
        if u1 > 100.0:  print "!!! u1 {0} reached threshold limit!".format(u1); test=1
    # Do for u2
    test = 0
    while test==0:
        mu2, nu2, r2 = co.streamToGC(u2,v2,w2,mu, R, theta*deg, phi*deg, wedge)
        # account for wrap-around
        if params.mu_lim[1] > 360.0:
            if mu2 < params.mu_lim[0]:  mu2 = mu2 + 360.0
        if (mu2 < params.mu_lim[0]) or (mu2 > params.mu_lim[1]):
            #print "u2 ({0}) finished due to mu lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        if (nu2 < -2.5):
            #print "u2 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        if (nu2 > 2.5):
            #print "!!! WARNING:  u2 EXITED DUE TO OPPOSITE THRESHOLD"
            #print "u2 ({0}) finished due to nu lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        if (r2 < params.r_lim[0]) or (r2 > params.r_lim[1]):
            #print "u2 ({0}) finished due to r lim: {1}, {2}, {3}".format(u2, mu2, nu2, r2)
            break
        u2 = u2 - 0.1
        if u2 < -100.0:  print "!!! u1 {0} reached threshold limit!".format(u1); test=1
    # finish up
    length = np.fabs(u1-u2)
    print "# Stream is {0} kpc long within wedge boundaries".format(length)
    while np.fabs(u1-u2) < 60.0:
        u1 = u1*2.0
        u2 = u2*2.0
    if u2 > u1:  return u1, u2
    else:        return u2, u1
Exemplo n.º 6
0
def stream_into_stripe(params, sn, N_stars, batch=1000, fileout="streamgen82.txt",
                       detection=1, convolve=1, append=0, progbar=1, primary=0):
    """ sn is stream number"""
    # Initialize file
    if append==0:
        out = open(fileout, 'w')
        out.write("# "+str(N_stars)+" stars, l,b,r \n")
        out.close()
    # Get constants
    mu,R,theta,phi,sigma,wedge = \
        params.mu[sn],params.R[sn],params.theta[sn],params.phi[sn],params.sigma[sn], params.wedge
    print "Stream Parameters", mu, R, theta, phi, sigma, wedge
    u_min, u_max = get_stream_length(params, sn, accuracy=0.0001)
    nu_min, nu_max = params.nu_lim[0], params.nu_lim[1]
    mu_min, mu_max = params.mu_lim[0], params.mu_lim[1]
    g_min, g_max = params.stripe[2][0], params.stripe[2][1]
    #print "# - Generating Stream {0}, using parameters {1}, {2}, {3}, {4}, {5}".format(
    #    sn, mu, R, theta, phi, sigma)
    N_out = 0
    pb = pr.Progressbar(steps=N_stars, prefix="Stream {0} progress:".format(sn), 
        suffix="Generating {0} Stars".format(N_stars), symbol="#", 
                active="=", brackets="[]", percent=True, size=40)
    while N_out < N_stars:
        mu_killed, nu_killed, mu_saved = 0,0,0
        u,v,w = generate_stream(batch, u_min, u_max, sigma)
        holder = []
        for i in range(len(u)):
            mu1, nu1, r1 = co.streamToGC(u[i],v[i],w[i],mu,R,theta*deg,phi*deg,wedge)
            if (nu1 < nu_min) or (nu1 > nu_max):  nu_killed=nu_killed+1; continue
            if (mu_max > 360.0):
                if (mu1 > (mu_max-360.0)) and (mu1 < mu_min):  mu_killed=mu_killed+1; continue
            else:
                if (mu1 < mu_min) or (mu1 > mu_max):  mu_killed=mu_killed+1; continue
            if primary == 1:
                if co.SDSS_primary(mu1,nu1,wedge,low=9,high=25) == 0:  continue
            # 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
            # When a point passes all the testsm add it to the set
            l,b,r1 = co.GC2lbr(mu1, nu1, r1, wedge)
            #co.stream2xyz(u[i],v[i],w[i],mu,R,theta,phi,wedge)
            holder.append([round(l,6),round(b,6),round(r1,6)])
            N_out = N_out + 1
        if N_out > N_stars:
            slice = -1*(N_out-N_stars)
            holder = holder[:slice]
            #print "#---Sliced {0} stars to make quota".format(str(-1*slice))
            N_out = N_out + slice #Slice is negative
        #append to file
        if len(holder) != 0:
            if fi.append_data(sc.array(holder), fileout, delimiter=" ") == 1:
                #print "#---Stream Progress: {0} stars of {1} total stars generated".format(N_out, N_stars)
                #print "# !!! - mu killed: {0}, mu_saved: {1}, nu_killed: {2}".format(mu_killed, mu_saved, nu_killed)
                pb.updatebar(float(N_out)/float(N_stars))
    print "#---Stream {0} generation succeeded, written as {1}".format(sn, fileout)
    return fileout
Exemplo n.º 7
0
def stream_gen(params, sn, N_stars, batch=1000, fileout="streamgen82.txt",
                       detection=1, convolve=1, append=0):
    """ sn is stream number"""
    # Initialize file
    if append==0:
        out = open(fileout, 'w')
        out.write("# "+str(N_stars)+" stars, l,b,r,flag \n")
        out.close()
    # Get constants
    mu,R,theta,phi,sigma,wedge = \
        params.mu[sn],params.R[sn],params.theta[sn],params.phi[sn],params.sigma[sn], params.wedge
    u_min, u_max = twg.get_stream_length(params, sn, accuracy=0.00001)
    nu_min, nu_max = params.nu_lim[0], params.nu_lim[1]
    mu_min, mu_max = params.mu_lim[0], params.mu_lim[1]
    g_min, g_max = params.stripe[2][0], params.stripe[2][1]
    print "# - Generating Stream {0}, using parameters {1}, {2}, {3}, {4}, {5}".format(
        sn, mu, R, theta, phi, sigma)
    X_out, Y_out = 0, 0 # X_out is stars detected in stripe, Y_out is stars generated that should be there.
    while X_out < N_stars:
        mu_killed, nu_killed, mu_saved = 0,0,0
        u,v,w = twg.generate_stream(batch, u_min, u_max, sigma)
        holder = []
        for i in range(len(u)):
            mu1, nu1, r1 = coor.streamToGC(u[i],v[i],w[i],mu,R,theta,phi,wedge)
            l,b,r1 = coor.GC2lbr(mu1, nu1, r1, wedge)
            # Convolve
            if convolve==1:
                r1 = twg.star_convolution(r1)
            # Test nu, kill if invalid
            if (nu1 < nu_min) or (nu1 > nu_max):
                nu_killed=nu_killed+1
                #Y_out=Y_out+1   # COMMENT
                #holder.append([round(l,6),round(b,6),round(r1,6), 1])  # COMMENT
                continue
            # Test mu, keep in Y if out of bounds
            if (mu_max > 360.0):
                if (mu1 > (mu_max-360.0)) and (mu1 < mu_min):
                    mu_killed=mu_killed+1
                    Y_out=Y_out+1
                    holder.append([round(l,6),round(b,6),round(r1,6), 1])
                    continue
            else:
                if (mu1 < mu_min) or (mu1 > mu_max):
                    mu_killed=mu_killed+1
                    Y_out=Y_out+1
                    holder.append([round(l,6),round(b,6),round(r1,6), 1])
                    continue
            # Detection
            if detection==1:
                m_g = coor.getg(r1)
                if np.random.uniform() > (twg.sigmoid_error(m_g)):
                    Y_out=Y_out+1
                    holder.append([round(l,6),round(b,6),round(r1,6), 1])
                    continue
            # test g-limits
            if (coor.getg(r1) < g_min) or (coor.getg(r1) > g_max):
                Y_out=Y_out+1
                holder.append([round(l,6),round(b,6),round(r1,6), 1])
                continue
            # When a point passes all the tests add it to the set
            #co.stream2xyz(u[i],v[i],w[i],mu,R,theta,phi,wedge)
            holder.append([round(l,6),round(b,6),round(r1,6), 0])
            X_out = X_out + 1
        if X_out > N_stars:
            slice = -1*(X_out-N_stars)
            holder = holder[:slice]
            print "#---Sliced {0} stars to make quota".format(str(-1*slice))
            X_out = X_out + slice #Slice is negative
        #append X and Y to files
        if len(holder) != 0:
            if fi.append_data(sc.array(holder), fileout, delimiter=" ") == 1:
                print "#---Stream Progress: {0} stars of stars generated out of {1} detected".format(Y_out+X_out, N_stars)
                print "# !!! - out of mu: {0}, nu_killed: {1}".format(mu_killed, nu_killed)
    print "#---Stream {0} generation succeeded, written as {1}".format(sn, fileout)
    print " ### -----  Stream {0} Complete ----- ### \n"
    return fileout