def extract_particles(galID, SHI, subdir):
    SubLength = st.eagleread(subdir,
                             'Subhalo/SubLength',
                             astro=False,
                             silent=True)
    SubLengthType = st.eagleread(subdir,
                                 'Subhalo/SubLengthType',
                                 astro=False,
                                 silent=True)
    SubOffset = st.eagleread(subdir,
                             'Subhalo/SubOffset',
                             astro=False,
                             silent=True)
    particleIDs = st.eagleread(subdir,
                               'IDs/ParticleID',
                               astro=False,
                               silent=True)

    length = SubLength[SHI]
    type = SubLengthType[SHI]
    offset = SubOffset[SHI]
    particles = particleIDs[offset:offset + length]

    dm_particles = particles[np.where(particles % 2 == 0)[0]]
    star_particles = particles[np.where(particles % 2 == 1)[0]]
    return type, dm_particles, star_particles
def extract_coords_of_particles(simdir, dm, stars):
    beg = time.time()
    star_IDs = st.eagleread(
        simdir + 'data/snapshot_029_z000p000/snap_029_z000p000.0.hdf5',
        'PartType4/ParticleIDs',
        astro=False,
        silent=True)
    print('read IDs', len(star_IDs))
    # star_coords = star['Coordinates']
    # star_mass = star['Mass']
    # star_IDs = star['IDs']

    ind = np.zeros(len(star_IDs))
    for i in range(len(star_IDs)):
        if star_IDs[i] in stars:
            ind[i] = 1
        mid = time.time()
        if mid - beg > 60:
            print(i)
            break
    print(ind)
    print(stars)
    print(star_IDs[ind])

    end = time.time()
    print(end - beg)
def read_dist(subdir):
    print('\nReading distance...')
    dist_read = st.eagleread(subdir,
                             'Subhalo/CentreOfMass',
                             astro=True,
                             silent=True)[0]
    distx = dist_read[:, 0] - dist_read[0, 0]
    disty = dist_read[:, 1] - dist_read[0, 1]
    distz = dist_read[:, 2] - dist_read[0, 2]
    dist = np.sqrt(distx**2 + disty**2 + distz**2)
    return dist
def read_masses(subdir):
    print('\nReading masses...')
    mass_types = st.eagleread(subdir,
                              'Subhalo/MassType',
                              astro=True,
                              silent=True)[0]

    mass_DM = mass_types[:, 1]
    mass_stars = mass_types[:, 4]

    mass_DM_log = np.log10(mass_DM) + 10
    mass_stars_log = np.log10(mass_stars) + 10

    return mass_DM_log, mass_stars_log
def ReadSubhaloIDs(subdir):
    print('\nReading IDs...\n')
    FirstSubhaloID = st.eagleread(subdir,
                                  'FOF/FirstSubhaloID',
                                  astro=False,
                                  silent=True)

    # Makes a list of Subhalo IDs
    IDs = []
    # print(FirstSubhaloID.shape)
    for i in range(len(FirstSubhaloID) - 1):
        IDs.append(range(FirstSubhaloID[i], FirstSubhaloID[i + 1]))

    # print(IDs)
    return IDs
def ReadDist(subdir):
    # if all:
    print('\nReading distance...')
    dist_read = st.eagleread(subdir,
                             'Subhalo/CentreOfMass',
                             astro=True,
                             silent=True)[0]
    # else:
    #     GalaxyPositions = h5py.File(simdir + 'highlev/GalaxyPositionsSnap.hdf5')['Centre']
    #     dist_read = GalaxyPositions[galID, :]
    #     central = GalaxyPositions[760, :]

    distx = dist_read[:, 0] - dist_read[0, 0]
    disty = dist_read[:, 1] - dist_read[0, 1]
    distz = dist_read[:, 2] - dist_read[0, 2]
    dist = np.sqrt(distx**2 + disty**2 + distz**2)
    # print(len(dist))
    return dist
Ejemplo n.º 7
0
    def read_data(self,
                  dataSetName,
                  astro=False,
                  verbose=False,
                  return_conv=False,
                  exact=None,
                  filename=None,
                  PTName=None):

        if filename is None:
            filename = self.filename

        if PTName is None:
            PTName = self.PTName
        """
        Reads a specified dataset for a previously set up region.
        """

        stime = time.clock()

        if self.NumSegments == 0:

            if return_conv:
                return [None, None, None]
            else:
                return

        if self.loadFull:
            data_full = st.eagleread(filename,
                                     PTName + '/' + dataSetName,
                                     astro=astro)
            if astro and not return_conv:
                data_full = data_full[0]
            return data_full

        if exact is None:
            exact = self.exact

        Counter = 0
        for iiseg in range(self.NumSegments):
            CurrFileName = self._swap_filename(filename, self.Files[iiseg])

            if verbose:
                print("CurrFileName = '" + CurrFileName + "'")

            f = h5.File(CurrFileName, 'r')

            if PTName is not "":
                if self.PTName not in f:
                    continue

                MainGroup = f[self.PTName]
                DSet = MainGroup[dataSetName]

            else:
                DSet = f[dataSetName]

            CurrFirst = self.Offsets[iiseg]
            CurrLength = self.Lengths[iiseg]
            CurrBeyLast = CurrFirst + CurrLength

            if iiseg == 0:
                full_shape = list(DSet.shape)
                full_shape[0] = self.NumParticles
                data_full = np.empty(full_shape, DSet.dtype)

            if len(DSet.shape) == 1:
                data_full[Counter:Counter +
                          CurrLength] = DSet[CurrFirst:CurrBeyLast]
            else:

                #print("iiseg = {:d}" .format(iiseg))
                #if (iiseg == 732):
                #    set_trace()
                data_full[Counter:Counter +
                          CurrLength, :] = DSet[CurrFirst:CurrBeyLast, :]

            Counter += CurrLength

        #Limit selection if 'exact' is set:
        if exact:
            if len(data_full.shape) == 1:
                data_full = data_full[self.ind_sel]
            else:
                data_full = data_full[self.ind_sel, :]

        if astro:

            # Determine code --> physical conversion factors
            hscale_exponent = DSet.attrs["h-scale-exponent"]
            ascale_exponent = DSet.attrs["aexp-scale-exponent"]

            header = f["/Header"]
            aexp = header.attrs["ExpansionFactor"]
            h_hubble = header.attrs["HubbleParam"]
            conv_astro = aexp**ascale_exponent * h_hubble**hscale_exponent

            data_full *= conv_astro

        else:

            aexp = -100
            conv_astro = -100

        print("Reading '" + dataSetName +
              "' took {:.3f} sec.".format(time.clock() - stime))

        if return_conv:
            return data_full, conv_astro, aexp
        else:
            return data_full