Ejemplo n.º 1
0
def write_trunk_ascii_old(fname, ouput_fname, dt, **kwargs):
    h = ascii_reader.header_len(fname)
    with open(fname, 'r') as f:
        with open(ouput_fname, 'w') as o:
            for _ in xrange(0, h):
                next(f)    
            num_trees = int(next(f))
            tree_id = ""
            first_line = True
            current_tree = []
            i = 0
            for line in f:
                if(line[0]=='#'):
                    if(not first_line):
                        print i
                        arr = np.array(current_tree, dtype = dt) 
                        depth_sort =  arr['haloid_depth_first'].argsort() #sort by depthid
                        trunk = get_trunk(arr[depth_sort])
                        o.write("#" + tree_id + "\n")
                        np.savetxt(ouput_fname, trunk)
                        current_tree = []
                    first_line = False
                    tree_id = line[6:].strip('\n')
                else:
                    current_tree.append(tuple(line.split()))
                    i += 1
            # o.write("#" + tree_id + "\n")
            # arr = np.array(current_tree, dtype = dt)
            # depth_sort =  arr['haloid_depth_first'].argsort()
            # trunk = get_trunk(arr[depth_sort])
            # np.savetxt(ouput_fname, trunk)
        return 
Ejemplo n.º 2
0
def write_trunk_ascii(fname, ouput_fname, dt, **kwargs):
    h = ascii_reader.header_len(fname)
    columns_to_keep = [i for i in range(0, len(dt))]

    with open(fname, 'r') as f:
        with open(ouput_fname, 'w') as o:
            for _ in xrange(0, h):
                f.readline()
            num_trees = int(f.readline())
            tree_index = 0
            while(tree_index < 1):
                line = f.readline()  
                tree_id = line[6:].strip('\n')
                arr = np.array(list(column_cut_tree_gen(columns_to_keep, f, dt)), dtype=dt)
                depth_sort =  arr['haloid_depth_first'].argsort() #sort by depthid
                trunk = get_trunk(arr[depth_sort])
                o.write("#" + tree_id + "\n")
                np.savetxt(ouput_fname, trunk)
                tree_index += 1
        return