Exemple #1
0
def bgc2_test(path='data\\halos_0.1.bgc2'):
    """
    reading data from a sample bgc2 file containing multiple halos
    :param path: path to file
    :return: a Halos instance containing list of halos (<return_variable>.halos)
    """
    print("\n\t->Reading only header data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=0)
    if len(t.header) == 1:
        print("\t\tSUCCESS: Header read.")
    else:
        print("\t\tFAILURE: Header not read.")

    print("\n\t->Reading header + halo data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=1)
    if t.header[0].ngroups == len(t.h):
        print("\t\tSUCCESS: Halo data read.")
    else:
        print("\t\tFAILURE: Halo data improperly read.")
    sample_ids = np.random.choice(t.h.id, 100, replace=False)

    print("\n\t->Reading header + only halo id + only particle id data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=2, onlyid=True)
    if len(t.h.id) == t.header[0].ngroups and len(t.halos[0].particles.id) > 0:
        print("\t\tSUCCESS: ID data read.")
    else:
        print("\t\tFAILURE: ID data improperly read.")

    print("\n\t->Reading header + halo + particle data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=2, sieve=sample_ids)
    if len(t.h.id) == len(sample_ids) and len(
            t.halos[0].particles.id) == t.h[0].npart:
        print("\t\tSUCCESS: Full data read.")
    else:
        print("\t\tFAILURE: Full data improperly read.")

    print("\n\t->Performing calculations. ")
    t.filter(100)  # filter out halos w/ less than 4 particles
    t.center_halos()
    t.get_covariance_matrices()
    t.get_eigenvectors()
    t.convert_bases()
    t.get_radii(
    )  # center_halo(), get_covariance_matrices() and get_eigenvectors() functions must be called before
    t.get_half_mass_radii()
    print("\t\tSUCCESS: All calculations finished.")
Exemple #2
0
def bgc2_test(path='data\\halos_0.1.bgc2'):
    """
    reading data from a sample bgc2 file containing multiple halos
    :param path: path to file
    :return: a Halos instance containing list of halos (<return_variable>.halos)
    """
    print("\n\t->Reading only header data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=0)
    if len(t.header)==1:
        print("\t\tSUCCESS: Header read.")
    else:
        print("\t\tFAILURE: Header not read.")

    print("\n\t->Reading header + halo data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=1)
    if t.header[0].ngroups==len(t.h):
        print("\t\tSUCCESS: Halo data read.")
    else:
        print("\t\tFAILURE: Halo data improperly read.")
    sample_ids = np.random.choice(t.h.id, 100, replace=False)

    print("\n\t->Reading header + only halo id + only particle id data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=2, onlyid=True)
    if len(t.h.id)==t.header[0].ngroups and len(t.halos[0].particles.id)>0:
        print("\t\tSUCCESS: ID data read.")
    else:
        print("\t\tFAILURE: ID data improperly read.")

    print("\n\t->Reading header + halo + particle data: ")
    t = Halos(path, verbose=False)
    t.read_data(level=2, sieve=sample_ids)
    if len(t.h.id)==len(sample_ids) and len(t.halos[0].particles.id)==t.h[0].npart:
        print("\t\tSUCCESS: Full data read.")
    else:
        print("\t\tFAILURE: Full data improperly read.")

    print("\n\t->Performing calculations. ")
    t.filter(100)         # filter out halos w/ less than 4 particles
    t.center_halos()
    t.get_covariance_matrices()
    t.get_eigenvectors()
    t.convert_bases()
    t.get_radii()    # center_halo(), get_covariance_matrices() and get_eigenvectors() functions must be called before
    t.get_half_mass_radii()
    print("\t\tSUCCESS: All calculations finished.")
    def worker(self, pool_ids, files, queue, args):
        try:
            while len(args[1]) < 3:
                args[1] = '0' + args[1]
            path_2lpt = '/scratch/sissomdj/projects/simulations/rockstar/' + args[0] \
                        + '/2lpt/snap' + args[1] + '/halos/*1.bgc2'
            path_za = '/scratch/sissomdj/projects/simulations/rockstar/' + args[0] \
                        + '/za/snap' + args[1] + '/halos/*1.bgc2'
            #path_2lpt = '../data/halos_0.1.bgc2'
            #path_2lpt = '../data/halos_0.2.bgc2'
            H2 = Halos(path_2lpt, verbose=False)
            HZ = Halos(path_za, verbose=False)

            bins = np.linspace(1, 5, 26)  # 25 bins
            bins_mean = [
                0.5 * (bins[i] + bins[i + 1]) for i in range(len(bins) - 1)
            ]

            H2.read_data()
            H2.filter(100)
            H2.center_halos()
            H2.get_covariance_matrices()
            H2.get_eigenvectors()
            H2.convert_bases()
            H2.get_radii()
            H2.get_half_mass_radii()
            ratios2 = [max(h.radii) / h.half_mass_radius for h in H2.halos]
            del H2

            HZ.read_data()
            HZ.filter(100)
            HZ.center_halos()
            HZ.get_covariance_matrices()
            HZ.get_eigenvectors()
            HZ.convert_bases()
            HZ.get_radii()
            HZ.get_half_mass_radii()
            ratiosz = [max(h.radii) / h.half_mass_radius for h in HZ.halos]
            del HZ

            counts2, _ = np.histogram(ratios2, bins)
            countsz, _ = np.histogram(ratiosz, bins)
            n2 = sum(counts2)
            nz = sum(countsz)

            fig = plt.figure()
            ax1 = fig.add_subplot(111)
            _ = ax1.hist(bins_mean,
                         bins,
                         label='2LPT',
                         weights=counts2,
                         color='r',
                         histtype='step')
            _ = ax1.hist(bins_mean,
                         bins,
                         label='ZA',
                         color='b',
                         weights=countsz,
                         histtype='step')
            ax1.set_xlabel('Outer to Inner halo radius')
            ax1.set_ylabel('Frequency')
            fig.suptitle('2LPT vs. ZA')
            ax1.set_title('2LPT: $\\mu $= ' + '{:.3f}'.format(np.mean(ratios2)) + \
                        ', N= ' + str(n2) + '\tZA: $\\mu $= ' + '{:.3f}'.format(np.mean(ratiosz)) + \
                        ', N= ' + str(nz))
            _ = ax1.legend()
            ax1.grid(True)

            fig.savefig('results/' + args[0] + '/' + args[1] + '.png')
            queue.put((0, None))
            return (0, None)
        except Exception as e:
            queue.put((-1, e))
            return -1