Beispiel #1
0
def Read_SubHalo_Part_Paulina_V02():
    pos_St = E.readArray("PARTDATA", sim, tag, "/PartType0/Coordinates")
    vel_St = E.readArray("PARTDATA", sim, tag, "/PartType0/Velocity")
    Mass_St = E.readArray("PARTDATA", sim, tag, "/PartType0/Mass")
    num_St = E.readArray("PARTDATA", sim, tag, "/PartType0/GroupNumber")
    num_St_SH = E.readArray("PARTDATA", sim, tag, "/PartType0/SubGroupNumber")
    Ab_1_O = E.readArray("PARTDATA", sim, tag,
                         "/PartType0/ElementAbundance/Oxygen")
    Ab_2_O = E.readArray("PARTDATA", sim, tag,
                         "/PartType0/SmoothedElementAbundance/Oxygen")
    Ab_1_H = E.readArray("PARTDATA", sim, tag,
                         "/PartType0/ElementAbundance/Hydrogen")
    Ab_2_H = E.readArray("PARTDATA", sim, tag,
                         "/PartType0/SmoothedElementAbundance/Hydrogen")
    SFR = E.readArray("PARTDATA", sim, tag, "/PartType0/StarFormationRate")

    num_St = abs(num_St)
    num_St_SH = abs(num_St_SH)

    ind = lexsort((num_St_SH, num_St))

    pos_St = pos_St[ind]
    vel_St = vel_St[ind]
    Mass_St = Mass_St[ind]
    num_St = num_St[ind]
    num_St_SH = num_St_SH[ind]
    Ab_1_O = Ab_1_O[ind]
    Ab_2_O = Ab_2_O[ind]
    Ab_1_H = Ab_1_H[ind]
    Ab_2_H = Ab_2_H[ind]
    SFR = SFR[ind]

    return pos_St, vel_St, Mass_St, num_St, num_St_SH, Ab_1_O, Ab_2_O, Ab_1_H, Ab_2_H, SFR
Beispiel #2
0
def Read_Halo_Prop_Sergio_V01():
    M_Group = E.readArray("SUBFIND_GROUP", sim, tag,
                          "FOF/Group_M_Crit200") * 1e10
    Cen_Group = E.readArray("SUBFIND_GROUP", sim, tag,
                            "FOF/GroupCentreOfPotential")
    R_Group = E.readArray("SUBFIND_GROUP", sim, tag, "FOF/Group_R_Crit200")
    return M_Group, Cen_Group, R_Group
Beispiel #3
0
def Read_OnlyDM_Halo_V01():  #TODO CHECK ME!
    M_Group = E.readArray("SUBFIND_GROUP", sim_DM, tag,
                          "FOF/Group_M_Crit200") * 1e10
    Cen_Group = E.readArray("SUBFIND_GROUP", sim_DM, tag,
                            "FOF/GroupCentreOfPotential")
    Vel_Group = E.readArray("FOF", sim_DM, tag, "FOF/Velocity")
    return M_Group, Cen_Group, Vel_Group
 def get_xyz(self, gns):  # returns an array of the centre coordinates (in kpc) for a list of group numbers
     print 'Finding centre coordinates...'
     gn_inds = np.asarray(gns) - 1
     simpath = '/data5/simulations/EAGLE/' + self.sim + '/' + self.run + '/data/'
     num_subs = np.array(E.readArray("SUBFIND_GROUP", simpath, self.tag, "/FOF/NumOfSubhalos"))
     first_subhalo = np.array(E.readArray("SUBFIND_GROUP", simpath, self.tag, 'FOF/FirstSubhaloID')[num_subs > 0])
     subfind_centres = np.array(E.readArray('SUBFIND', simpath, self.tag, 'Subhalo/CentreOfPotential'))[first_subhalo, :]
     return subfind_centres[gn_inds] * 1e3
Beispiel #5
0
def Read_Particles_ID(sim, tag):
	ParticleID = E.readArray("SUBFIND_PARTICLES", sim, tag, "/IDs/ParticleID")
	Particle_Binding_Energy = E.readArray("SUBFIND_PARTICLES", sim, tag, "/IDs/Particle_Binding_Energy")
	
	ind = np.argsort(ParticleID)
	ParticleID = ParticleID[ind]
	Particle_Binding_Energy = Particle_Binding_Energy[ind]
	
	return ParticleID,Particle_Binding_Energy
Beispiel #6
0
def Read_Part_Prop_Sergio_V01():
    pos = E.readArray("PARTDATA", sim, tag, "/PartType1/Coordinates")
    vel = E.readArray("PARTDATA", sim, tag, "/PartType1/Velocity")
    num = E.readArray("PARTDATA", sim, tag, "/PartType1/GroupNumber")
    num = abs(num)
    indices = argsort(num)
    num = num[indices]
    pos = pos[indices]
    vel = vel[indices]
    return pos, vel, num
Beispiel #7
0
 def __init__(self,
              gnum,
              run='L0100N1504',
              model='REFERENCE',
              tag='028_z000p000'):
     self.run, self.model, self.tag = run, model, tag
     sim = '/data5/simulations/EAGLE/' + run + '/' + model + '/data'
     fsid = np.array(
         E.readArray("SUBFIND_GROUP", sim, tag, "/FOF/FirstSubhaloID"))
     groupnumber = np.array(
         E.readArray("SUBFIND", sim, tag, "/Subhalo/GroupNumber"))[fsid]
     subgroupnumber = np.array(
         E.readArray("SUBFIND", sim, tag, "/Subhalo/SubGroupNumber"))[fsid]
     self.gnum = gnum
     ind = np.where(np.in1d(groupnumber, gnum) & (subgroupnumber == 0))
     print ind
     self.CoP = np.array(
         E.readArray("SUBFIND", sim, tag,
                     "/Subhalo/CentreOfPotential"))[fsid][ind]
     self.subhalovel = np.array(
         E.readArray("SUBFIND", sim, tag, "/Subhalo/Velocity"))[fsid][ind]
     self.r_200 = np.array(
         E.readArray("SUBFIND_GROUP", sim, tag,
                     "/FOF/Group_R_Crit200"))[ind]
     self.m_200 = np.array(
         E.readArray("SUBFIND_GROUP", sim, tag, "/FOF/Group_M_Crit200") *
         1e10)[ind]
     self.tot_ang_mom = np.array(
         E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/Spin"))[fsid][ind]
     self.stellar_mass = np.array(
         E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/Mass") *
         1e10)[fsid][ind]
Beispiel #8
0
	plt.savefig(plttitle, format='png', dpi=1200)

def selectdiskies(path="/data5/astjmack/halos/"):
	mass = E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/Mass") * 1e10
	group = E.readArray("SUBFIND", sim, tag, "/Subhalo/GroupNumber")
	subgroup = E.readArray("SUBFIND", sim, tag, "/Subhalo/SubGroupNumber")
	mask = [(mass > 6e10) & (mass < 8e10)]
	mass = mass[mask]
	group = group[mask]
	subgroup = subgroup[mask]
	array = np.array([group, subgroup, mass])
Beispiel #9
0
def Read_Part_Prop_Sergio_V00():
    pos = E.readArray("PARTDATA", sim, tag, "/PartType0/Coordinates")
    vel = E.readArray("PARTDATA", sim, tag, "/PartType0/Velocity")
    num = E.readArray("PARTDATA", sim, tag, "/PartType0/GroupNumber")
    mass = E.readArray("PARTDATA", sim, tag, "/PartType0/Mass")
    temp = E.readArray("PARTDATA", sim, tag, "/PartType0/Temperature")
    num = abs(num)
    indices = argsort(num)
    num = num[indices]
    pos = pos[indices]
    vel = vel[indices]
    mass = mass[indices]
    temp = mass[indices]
    return pos, vel, num, mass, temp
Beispiel #10
0
def Read_Particles(sim, tag):
	pos_St = E.readArray("PARTDATA", sim, tag, "/PartType4/Coordinates")
	num_St = E.readArray("PARTDATA", sim, tag, "/PartType4/GroupNumber")
	num_St_SH = E.readArray("PARTDATA", sim, tag, "/PartType4/SubGroupNumber")
	Mass_St = E.readArray("PARTDATA", sim, tag, "/PartType4/Mass")
		###
	num_St = abs(num_St)
	num_St_SH = abs(num_St_SH)
	ind = np.lexsort((num_St_SH,num_St))
	
	num_St = num_St[ind]
	num_St_SH = num_St_SH[ind]
	Mass_St = Mass_St[ind]
	pos_St = pos_St[ind]
	return pos_St,Mass_St,num_St,num_St_SH
Beispiel #11
0
def Read_Subhaloes(sim, tag):
	#Cen_Group = E.readArray("SUBFIND_GROUP", sim, tag, "FOF/GroupCentreOfPotential")
	SubHalo_gr = E.readArray("SUBFIND", sim, tag, "Subhalo/GroupNumber")
	SubHalo_sgr = E.readArray("SUBFIND", sim, tag, "Subhalo/SubGroupNumber")
	SubHalo_pos = E.readArray("SUBFIND", sim, tag, "Subhalo/CentreOfPotential")
	
	SubHalo_gr = abs(SubHalo_gr)
	SubHalo_sgr = abs(SubHalo_sgr)
	ind = np.lexsort((SubHalo_sgr,SubHalo_gr))
	
	SubHalo_gr = SubHalo_gr[ind]
	SubHalo_sgr = SubHalo_sgr[ind]
	SubHalo_pos = SubHalo_pos[ind]
	
	return SubHalo_gr,SubHalo_sgr,SubHalo_pos
Beispiel #12
0
def loadparticles(run=default_run,sim=default_sim,tag=default_tag):
	""" This loads the particle data for a given simulation and returns an array with that data. """
	groupnum_type = np.array( [E.readArray("PARTDATA", sim, tag, "/PartType0/GroupNumber"), E.readArray("PARTDATA", sim, tag, "/PartType1/GroupNumber"), E.readArray("PARTDATA", sim, tag, "/PartType4/GroupNumber"), E.readArray("PARTDATA", sim, tag, "/PartType5/GroupNumber")] )
	subgroupnum_type = np.array( [E.readArray("PARTDATA", sim, tag, "/PartType0/SubGroupNumber"), E.readArray("PARTDATA", sim, tag, "/PartType1/SubGroupNumber"), E.readArray("PARTDATA", sim, tag, "/PartType4/SubGroupNumber"), E.readArray("PARTDATA", sim, tag, "/PartType5/SubGroupNumber")] )
	pos_type = np.array( [E.readArray("PARTDATA", sim, tag, "/PartType0/Coordinates"), E.readArray("PARTDATA", sim, tag, "/PartType1/Coordinates"), E.readArray("PARTDATA", sim, tag, "/PartType4/Coordinates"), E.readArray("PARTDATA", sim, tag, "/PartType5/Coordinates")] )
	mass_type = np.array( [E.readArray("PARTDATA", sim, tag, "/PartType0/Mass"), (np.ones(len(pos_type[1]))*masstable[1]) , E.readArray("PARTDATA", sim, tag, "/PartType4/Mass"), E.readArray("PARTDATA", sim, tag, "/PartType5/Mass")])
	vel_type = np.array( [E.readArray("PARTDATA", sim, tag, "/PartType0/Velocity"), E.readArray("PARTDATA", sim, tag, "/PartType1/Velocity"), E.readArray("PARTDATA", sim, tag, "/PartType4/Velocity"), E.readArray("PARTDATA", sim, tag, "/PartType5/Velocity")] )
	stars_abundances = np.array( [E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Hydrogen"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Helium"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Carbon"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Nitrogen"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Oxygen"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Neon"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Magnesium"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Silicon"), E.readArray("PARTDATA", sim, tag, "/PartType4/SmoothedElementAbundance/Iron")])
	return np.array([groupnum_type, subgroupnum_type, pos_type, mass_type, vel_type, stars_abundances])
Beispiel #13
0
 def get_xyz(
     self, gns
 ):  # returns an array of the centre coordinates (in kpc) for a list of group numbers
     if not self.quiet:
         print 'Finding centre coordinates...'
     gn_inds = np.asarray(gns) - 1
     #if self.run == 'REFERENCE_ApogeeRun':
     #    simpath = self.storage_loc+'/simulations/EAGLE/' + self.sim + '/' + self.run + '/data2/'
     #else:
     simpath = self.storage_loc + '/simulations/EAGLE/' + self.sim + '/' + self.run + '/data/'
     #num_subs = np.array(E.readArray("SUBFIND_GROUP", simpath, self.tag, "/FOF/NumOfSubhalos"))
     first_subhalo = np.array(
         E.readArray("SUBFIND_GROUP", simpath, self.tag,
                     'FOF/FirstSubhaloID'))
     subfind_centres = np.array(
         E.readArray('SUBFIND', simpath, self.tag,
                     'Subhalo/CentreOfPotential'))[first_subhalo, :]
     return subfind_centres[gn_inds] * 1e3
Beispiel #14
0
def loadfofdat(run=default_run,sim=default_sim,tag=default_tag):
	""" Load Relevant FOF data """
	fsid = np.array(E.readArray("SUBFIND_GROUP", sim, tag, "FOF/FirstSubhaloID"))
	groupnumber = np.array(E.readArray("SUBFIND" , sim, tag, "/Subhalo/GroupNumber"))[fsid]
	CoP = np.array(E.readArray("SUBFIND", sim, tag, "/Subhalo/CentreOfPotential"))[fsid]
	subhalovel = np.array(E.readArray("SUBFIND", sim, tag, "/Subhalo/Velocity"))[fsid]
	r_200 = np.array(E.readArray("SUBFIND_GROUP", sim, tag, "/FOF/Group_R_Crit200"))
	tot_ang_mom = np.array(E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/Spin"))[fsid]
	stellar_mass = np.array(E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/Mass") * 1e10)[fsid]
	stellar_abundances = np.array( [ E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Hydrogen")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Helium")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Carbon")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Nitrogen")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Oxygen")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Neon")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Magnesium")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Silicon")[fsid], E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/SmoothedElementAbundance/Iron")[fsid]]) 
	return np.array([fsid,groupnumber,CoP,subhalovel,r_200,tot_ang_mom, stellar_mass, stellar_abundances ])
Beispiel #15
0
def Read_PrintPart_DM_V01(DMonly=False):
    Simu = sim
    if DMonly: Simu = sim_DM
    pos_DM = E.readArray("PARTDATA", Simu, tag, "/PartType1/Coordinates")
    vel_DM = E.readArray("PARTDATA", Simu, tag, "/PartType1/Velocity")
    num_DM = E.readArray("PARTDATA", Simu, tag, "/PartType1/GroupNumber")
    num_DM_SH = E.readArray("PARTDATA", Simu, tag, "/PartType1/SubGroupNumber")

    num_DM = abs(num_DM)
    num_DM_SH = abs(num_DM_SH)

    ind = lexsort((num_DM_SH, num_DM))

    pos_DM = pos_DM[ind]
    vel_DM = vel_DM[ind]
    num_DM = num_DM[ind]
    num_DM_SH = num_DM_SH[ind]

    return pos_DM, vel_DM, num_DM, num_DM_SH
Beispiel #16
0
def Read_PrintPart_Stars_V01():
    pos_St = E.readArray("PARTDATA", sim, tag, "/PartType4/Coordinates")
    vel_St = E.readArray("PARTDATA", sim, tag, "/PartType4/Velocity")
    Mass_St = E.readArray("PARTDATA", sim, tag, "/PartType4/Mass")
    num_St = E.readArray("PARTDATA", sim, tag, "/PartType4/GroupNumber")
    num_St_SH = E.readArray("PARTDATA", sim, tag, "/PartType4/SubGroupNumber")

    num_St = abs(num_St)
    num_St_SH = abs(num_St_SH)

    ind = lexsort((num_St_SH, num_St))

    pos_St = pos_St[ind]
    vel_St = vel_St[ind]
    Mass_St = Mass_St[ind]
    num_St = num_St[ind]
    num_St_SH = num_St_SH[ind]

    return pos_St, vel_St, Mass_St, num_St, num_St_SH
Beispiel #17
0
def load_array(array_label,
               parttype,
               array_type='SNAP',
               run='L0100N1504',
               model='REFERENCE',
               tag='028_z000p000'):
    sim = '/data5/simulations/EAGLE/' + run + '/' + model + '/data'
    return np.array(
        E.readArray(array_type, sim, tag,
                    '/PartType' + parttype + '/' + array_label))
Beispiel #18
0
def Read_Part_Prop_Idit_V01():
    vel_DM = E.readArray("PARTDATA", sim, tag, "/PartType1/Velocity")
    num_DM = E.readArray("PARTDATA", sim, tag, "/PartType1/GroupNumber")

    num_DM = abs(num_DM)
    indices = argsort(num_DM)
    vel_DM = vel_DM[indices]
    num_DM = num_DM[indices]

    ###################

    vel_St = E.readArray("PARTDATA", sim, tag, "/PartType4/Velocity")
    Mass_St = E.readArray("PARTDATA", sim, tag, "/PartType4/Mass")
    num_St = E.readArray("PARTDATA", sim, tag, "/PartType4/GroupNumber")

    num_St = abs(num_St)
    indices = argsort(num_St)
    vel_St = vel_St[indices]
    Mass_St = Mass_St[indices]
    num_St = num_St[indices]
    return vel_DM, num_DM, vel_St, Mass_St, num_St
Beispiel #19
0
    def __init__(self):
        ##############################################################################################################
        ref_sim = 'L0025N0376'
        ref_run = 'REFERENCE'
        sims = ['L0025N0376', 'L0025N0752']
        runs = [['StrongFB', 'WeakFB'], ['REFERENCE', 'RECALIBRATED']]
        snap = '028_z000p000'
        infotype = 'SUBFIND'
        table = 'Subhalo'
        ##############################################################################################################

        simloc = '/data5/simulations/EAGLE/' + ref_sim + '/' + ref_run + '/data/'
        num_subs = np.array(
            E.readArray("SUBFIND_GROUP", simloc, snap, "/FOF/NumOfSubhalos"))
        masslist = np.array(
            E.readArray("SUBFIND_GROUP", simloc, snap,
                        'FOF/Group_M_Crit200')[num_subs > 0]) * 1e10
        COPlist = np.array(
            E.readArray("SUBFIND_GROUP", simloc, snap,
                        'FOF/GroupCentreOfPotential')[num_subs > 0])
        #gns = np.where(num_subs>0)[0]+1
        gns = np.arange(len(masslist)) + 1

        # Perform mass cut to remove dwarfs which pass close to COP
        masscut = np.where(np.log10(masslist) > 11.7)[0]
        ref_COPlist = COPlist[masscut]
        self.ref_gns = gns[masscut]
        ref_masslist = masslist[masscut]

        self.connect_gns = {ref_sim + '_' + ref_run: self.ref_gns}

        for s, sim in enumerate(sims):
            for r, run in enumerate(runs[s]):

                simloc = '/data5/simulations/EAGLE/' + sim + '/' + run + '/data/'
                num_subs = np.array(
                    E.readArray("SUBFIND_GROUP", simloc, snap,
                                "/FOF/NumOfSubhalos"))
                masslist = np.array(
                    E.readArray("SUBFIND_GROUP", simloc, snap,
                                'FOF/Group_M_Crit200')[num_subs > 0]) * 1e10
                COPlist = np.array(
                    E.readArray("SUBFIND_GROUP", simloc, snap,
                                'FOF/GroupCentreOfPotential')[num_subs > 0])
                gns = np.where(num_subs > 0)[0] + 1

                masscut = np.where(np.log10(masslist) > 11.7)[0]
                COPlist = COPlist[masscut]
                gns = gns[masscut]
                masslist = masslist[masscut]

                thisrun_equivalents = np.zeros(len(self.ref_gns))

                for n in range(len(self.ref_gns)):
                    COPdiff = np.sqrt((COPlist[:, 0] - ref_COPlist[n, 0])**2 +
                                      (COPlist[:, 1] - ref_COPlist[n, 1])**2 +
                                      (COPlist[:, 2] - ref_COPlist[n, 2])**2)
                    thisrun_equivalents[n] = gns[np.argmin(COPdiff)]
                self.connect_gns[sim + '_' +
                                 run] = thisrun_equivalents.astype(int)
Beispiel #20
0
def Read_Halo_Prop_Idit_V01():
    M_Group = E.readArray("SUBFIND_GROUP", sim, tag,
                          "FOF/Group_M_Crit200") * 1e10
    Cen_Group = E.readArray("SUBFIND_GROUP", sim, tag,
                            "FOF/GroupCentreOfPotential")
    CenM_Group = E.readArray("FOF", sim, tag, "FOF/CentreOfMass")
    Vel_Group = E.readArray("FOF", sim, tag, "FOF/Velocity")
    R_Group = E.readArray("SUBFIND_GROUP", sim, tag, "FOF/Group_R_Crit200")
    Nsub_Group = E.readArray("SUBFIND_GROUP", sim, tag, "FOF/NumOfSubhalos")
    return M_Group, Cen_Group, Vel_Group, R_Group, CenM_Group, Nsub_Group
Beispiel #21
0
def Read_SubHalo_Prop_Idit_V01():
    StellMass030_SH = E.readArray(
        "SUBFIND", sim, tag,
        "Subhalo/ApertureMeasurements/Mass/030kpc")[:, 4] * 1e10
    M_Group = E.readArray("SUBFIND_GROUP", sim, tag,
                          "FOF/Group_M_Crit200") * 1e10
    Cen_SH = E.readArray("SUBFIND", sim, tag, "Subhalo/CentreOfPotential")
    Vel_SH = E.readArray("SUBFIND", sim, tag, "Subhalo/Velocity")
    GroupID_SH = E.readArray("SUBFIND", sim, tag, "Subhalo/GroupNumber")
    SubGroupID_SH = E.readArray("SUBFIND", sim, tag, "Subhalo/SubGroupNumber")
    return StellMass030_SH, Cen_SH, Vel_SH, GroupID_SH, SubGroupID_SH, M_Group
Beispiel #22
0
    def __init__(self,
                 sim='L0100N1504',
                 run='REFERENCE',
                 tag='028_z000p000',
                 pdata_type='SNAPSHOT',
                 data_location='/hpcdata5/simulations/EAGLE/'):

        # Initialises everything and loads in information about the entire simulation volume

        if run == 'EagleVariation_NOAGN':
            self.incBH = False
        else:
            self.incBH = True

        self.sim = sim
        self.run = run
        self.tag = tag

        sim_path = data_location + sim + '/' + run + '/data/'

        # Name of one file from the snapshot
        self.snapfile = sim_path + 'snapshot_' + tag + '/snap_' + tag + '.0.hdf5'

        # Get volume information
        boxsize = E.readAttribute(pdata_type, sim_path, tag, "/Header/BoxSize")
        self.h = E.readAttribute(pdata_type, sim_path, tag,
                                 "/Header/HubbleParam")
        self.Omega0 = E.readAttribute(pdata_type, sim_path, tag,
                                      "/Header/Omega0")
        self.OmegaLambda = E.readAttribute(pdata_type, sim_path, tag,
                                           "/Header/OmegaLambda")
        self.OmegaBaryon = E.readAttribute(pdata_type, sim_path, tag,
                                           "/Header/OmegaBaryon")
        self.a_0 = E.readAttribute(pdata_type, sim_path, tag,
                                   "/Header/ExpansionFactor")
        self.physical_boxsize = boxsize * self.a_0 / self.h
        self.masstable = E.readAttribute(pdata_type, sim_path, tag,
                                         "/Header/MassTable") / self.h
        self.r200s = E.readArray("SUBFIND_GROUP", sim_path, tag,
                                 "/FOF/Group_R_Crit200")
def load_array(datafield):
    sim_location = '/data5/simulations/EAGLE/' + sim + '/' + run + '/data'
    return np.array(
        E.readArray(datatype, sim_location, tag,
                    '/PartType' + ptype(parttype) + '/' + datafield))
Beispiel #24
0
                               "/Header/Redshift")
aex = eagle.readAttribute("SNAP", sim, input_filename_base_pos,
                          "/Header/ExpansionFactor")
hubble_param = eagle.readAttribute("SNAP", sim, input_filename_base_pos,
                                   "/Header/HubbleParam")
boxsize = eagle.readAttribute("SNAP", sim, input_filename_base_pos,
                              "/Header/BoxSize")

boxsize = boxsize / hubble_param * aex
print "boxsize=", boxsize
center = center / hubble_param * aex
print "center= ", center

coords_pos = eagle.readArray("SNAP",
                             sim,
                             input_filename_base_pos,
                             "/PartType0/Coordinates",
                             numThreads=1)
velocity = eagle.readArray("SNAP",
                           sim,
                           input_filename_base_pos,
                           "/PartType0/Velocity",
                           numThreads=1)
mass_pos = eagle.readArray(
    "SNAP", sim, input_filename_base_pos, "/PartType0/Mass",
    numThreads=1) * 1e+10
print "mass= ", mass_pos

coords_neg = eagle.readArray("SNAP",
                             sim,
                             input_filename_base_neg,
sim = '/cosma7/data/dp004/dc-love2/data/G-EAGLE/geagle_0000/data'
tags = [
    '000_z015p048', '001_z012p762', '002_z011p146', '003_z009p934',
    '004_z008p985', '005_z008p218', '006_z007p583', '007_z007p047',
    '008_z006p587', '009_z006p188', '010_z005p837', '011_z005p526',
    '012_z005p248', '013_z004p997', '014_z004p770'
]  #,'015_z004p688']

tag = tags[tag_idx]

## particle properties

coods = E.readArray("SNAPSHOT",
                    sim,
                    tag,
                    "/PartType0/Coordinates",
                    numThreads=1,
                    physicalUnits=False)
pmass = E.readArray("SNAPSHOT",
                    sim,
                    tag,
                    "/PartType0/Mass",
                    numThreads=1,
                    physicalUnits=False)
ptemp = E.readArray("SNAPSHOT",
                    sim,
                    tag,
                    "/PartType0/Temperature",
                    numThreads=1,
                    physicalUnits=False)
# phsml = E.readArray("SNAPSHOT", sim, tag, "/PartType0/SmoothingLength", numThreads=1, physicalUnits=False)
Beispiel #26
0
	ax.scatter(age,feh)
	plt.show()
Beispiel #27
0
redshift = eagle.readAttribute(sniptag, sim, input_filename_base, "/Header/Redshift")
boxsize = eagle.readAttribute(sniptag, sim, input_filename_base, "/Header/BoxSize")

omegaM = 0.307
omegaL = 1-omegaM
omegaratio = (omegaM+omegaL/(1+redshift)**3)

h = 0.6777
R200 = 1.63e-2*(10**float(mhalo)*h)**0.333/omegaratio**0.333/(1+redshift)/h
R200 *= 1e-03 # In Mpc.

boxsize = boxsize/hubble_param*aex
print "boxsize=", boxsize 
center = center/hubble_param*aex
print "center= ", center
coords = eagle.readArray(sniptag, sim, input_filename_base, "/PartType0/Coordinates",numThreads=1)
mass = eagle.readArray(sniptag, sim, input_filename_base, "/PartType0/Mass",numThreads=1)

if(snip=='1'): # Have to back out hsmooth from density
    density = eagle.readArray("SNIP", sim, input_filename_base, "/PartType0/Density",numThreads=1)
    print "density= ", density
    hsmooth = (density/mass)**(-0.3333)*2.39  #2.39 conversion factor for 58 neighbors?  
    print "hsmooth= ",hsmooth
else:
    hsmooth = eagle.readArray(sniptag, sim, input_filename_base, "/PartType0/SmoothingLength",numThreads=1)

mass *= 1.e+10
print "mass= ", mass

hydrogen = eagle.readArray(sniptag, sim, input_filename_base, "/PartType0/ElementAbundance/Hydrogen",numThreads=1)
oxygen = eagle.readArray(sniptag, sim, input_filename_base, "/PartType0/ElementAbundance/Oxygen",numThreads=1)
Beispiel #28
0
def savesubhalo(halo,subgroup,parttype,path="/data5/astjmack/halos/"):
	halo = halo
	subgroup = subgroup
	parttype = parttype
	good_types = [0,4,5]
	boxsize = E.readAttribute("SUBFIND", sim, tag, "/Header/BoxSize")
	h = E.readAttribute("SUBFIND", sim, tag, "/Header/HubbleParam")
	masstable = E.readAttribute("SUBFIND", sim, tag, "/Header/MassTable") / h
	boxsize = boxsize/h
	groupnum = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/GroupNumber")
	subgroupnum = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SubGroupNumber")
	subgroupnum = subgroupnum[groupnum == halo]
	r_200 = E.readArray("SUBFIND_GROUP", sim, tag, "/FOF/Group_R_Crit200")[halo-1]
	fsid = E.readArray("SUBFIND_GROUP", sim, tag, "FOF/FirstSubhaloID")
	pos = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/Coordinates")[groupnum == halo, :]
	pos = pos[subgroupnum == subgroup, :]
	if parttype in good_types:
		mass = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/Mass")[groupnum == halo]
		mass = mass[subgroupnum == subgroup]
	elif parttype == 1:
		mass = np.ones(len(pos))*masstable[1]
		
	vel = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/Velocity")[groupnum == halo, :]
	vel = vel[subgroupnum == subgroup, :]
	if parttype == 4:
		stars_h = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Hydrogen")[groupnum == halo]
		stars_fe = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Iron")[groupnum == halo]
		stars_o = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Oxygen")[groupnum == halo]
		stars_mg = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/SmoothedElementAbundance/Magnesium")[groupnum == halo]
		starformtime = E.readArray("PARTDATA", sim, tag, "/PartType"+str(parttype)+"/StellarFormationTime")[groupnum == halo]
		stars_h = stars_h[subgroupnum == subgroup]
		stars_fe = stars_fe[subgroupnum == subgroup]
		stars_o = stars_o[subgroupnum == subgroup]
		stars_mg = stars_mg[subgroupnum == subgroup]
		starformtime = starformtime[subgroupnum == subgroup]
		solar_h = 0.706498
		solar_fe = 0.00110322
		solar_mg = 0.000590706
		solar_o = 0.00549262
		solar_fe_h = np.log10(solar_fe/solar_h)
		solar_mg_fe = np.log10(solar_mg/solar_h)-(solar_fe_h)
		solar_o_fe = np.log10(solar_o/solar_h)-(solar_fe_h)
		stars_fe_h = np.log10(stars_fe/stars_h)
		stars_mg_fe = np.log10(stars_mg/stars_h)-(stars_fe_h)
		stars_o_fe = np.log10(stars_o/stars_h)-(stars_fe_h)
		fe_h = np.array([str_fe_h - solar_fe_h for str_fe_h in stars_fe_h])
		mg_fe = np.array([str_a_fe - solar_mg_fe for str_a_fe in stars_mg_fe])
		o_fe = np.array([str_o_fe - solar_o_fe for str_o_fe in stars_o_fe])

	subhaloindex = fsid[halo-1]+subgroup
	CoP = E.readArray("SUBFIND", sim, tag, "/Subhalo/CentreOfPotential")[subhaloindex, :]
	subhalovel = E.readArray("SUBFIND", sim, tag, "/Subhalo/Velocity")[subhaloindex, :]

	#Calculate the abundance ratios (relative to solar abundances from EAGLE)
	

	rel_pos = [[pos[0]-CoP[0],pos[1]-CoP[1],pos[2]-CoP[2]] for pos in pos] #Relative positions

	#re-position overlapped particles
	for i in range(0,len(rel_pos)):
		if abs(rel_pos[i][0]) > (boxsize/2):
			if np.sign(rel_pos[i][0]) == -1:
				rel_pos[i][0] = rel_pos[i][0] + boxsize
			else:
				rel_pos[i][0] = rel_pos[i][0] - boxsize
		if abs(rel_pos[i][1]) > (boxsize/2):
			if np.sign(rel_pos[i][1]) == -1:
				rel_pos[i][1] = rel_pos[i][1] + boxsize
			else:
				rel_pos[i][1] = rel_pos[i][1] - boxsize
		if abs(rel_pos[i][2]) > (boxsize/2):
			if np.sign(rel_pos[i][2]) == -1:
				rel_pos[i][2] = rel_pos[i][2] + boxsize
			else:
				rel_pos[i][2] = rel_pos[i][2] - boxsize
	rel_pos = np.array(rel_pos)

	#Make a mask for R_Crit200 and reduce arrays to contain only these values.
	r_crit_mask =[]
	for i in range(0,len(rel_pos)):
		if np.sqrt(rel_pos[i][0]**2+rel_pos[i][1]**2+rel_pos[i][2]**2) <= 0.15*r_200:
			r_crit_mask.append(True)
		else:
			r_crit_mask.append(False)
	r_crit_mask = np.array(r_crit_mask, dtype='bool')
	rel_pos_1 = rel_pos[r_crit_mask]
	mass = mass[r_crit_mask]
	vel = vel[r_crit_mask]
	if parttype == 4:
		fe_h = fe_h[r_crit_mask]
		mg_fe = mg_fe[r_crit_mask]
		o_fe = o_fe[r_crit_mask]
		fe_h = np.array(fe_h)
		mg_fe = np.array(mg_fe)
		o_fe = np.array(o_fe)
	
	"""
	nanmask = np.zeros(len(fe_h))
	for i in range(0, len(fe_h)):
		if (np.isnan(fe_h[i]) == True) | (np.isinf(fe_h[i]) == True) | (np.isnan(mg_fe[i]) == True) | (np.isinf(mg_fe[i]) == True) | (np.isnan(o_fe[i]) == True) | (np.isinf(o_fe[i]) == True):
			nanmask[i] = False
		else:
			nanmask[i] = True

	nanmask = np.array(nanmask, dtype='bool')

	rel_pos_1 = rel_pos_1[nanmask]
	mass = mass[nanmask]
	vel = vel[nanmask]
	fe_h = fe_h[nanmask]
	mg_fe = mg_fe[nanmask]
	o_fe = o_fe[nanmask]
	starformtime = starformtime[nanmask]
	"""
	#Remove galaxy bulk motion from velocities
	vel = [bulkvel-subhalovel for bulkvel in vel]

	#Perform angular momentum calculation
	mv = [m*v for m,v in zip(mass,vel)]	
	ang_mom = [np.cross(rpos,mv) for rpos,mv in zip(rel_pos_1,mv)]
	tot_ang_mom = map(sum, zip(*ang_mom))
	tot_ang_mom = E.readArray("SUBFIND", sim, tag, "/Subhalo/Stars/Spin")[subhaloindex, :]
	print str(tot_ang_mom)
	yaw = np.arccos(tot_ang_mom[1]/(np.sqrt(tot_ang_mom[0]**2+tot_ang_mom[1]**2)))
	pitch = np.arccos(tot_ang_mom[1]/(np.sqrt(tot_ang_mom[1]**2+tot_ang_mom[2]**2)))
	roll = np.arccos(tot_ang_mom[0]/(np.sqrt(tot_ang_mom[0]**2+tot_ang_mom[2]**2)))
	cos = np.cos
	sin = np.sin
	yaw_tran = np.matrix([[cos(yaw), -sin(yaw), 0],[sin(yaw), cos(yaw), 0],[0,0,1]])
	pitch_tran = np.matrix([[cos(pitch), 0, sin(pitch)],[0,1,0],[-sin(pitch), 0, cos(pitch)]])
	roll_tran = np.matrix([[1,0,0],[0,cos(roll),-sin(roll)],[0,sin(roll),cos(roll)]])
	trans = np.array(roll_tran*pitch_tran*yaw_tran)

	#Transform positions and velocities
	r_tran = np.array([np.array([np.dot(i, trans[0]), np.dot(i, trans[1]), np.dot(i,trans[2])]) for i in rel_pos_1])
	vel_tran = np.array([np.array([np.dot(j, trans[0]), np.dot(j, trans[1]), np.dot(j, trans[2])]) for j in vel])

	#Calculate radial position
	R_pos = np.array([np.sqrt(rpos[0]**2 + rpos[2]**2) for rpos in r_tran])
	z_pos = abs(np.array(zip(*r_tran)[1]))
	
	#vertical and Circular angular momentum
	#mv = [m*v for m,v in zip(mass,vel)]
	ang_mom = [np.cross(rpos,v) for rpos,v in zip(r_tran,vel)]

	#Calculate star formation ages
	Mpc = 3.08567758e22
	t_0 = 13.8
	H_0 = h  * 100
	#t_a = [(2*a**(3/2))/(3*H_0)/(1e9*365*24*60*60) for a in starformtime]
	if parttype == 4:
		ages = starformtime #[t_0 - t for t in t_a]
	
	if parttype == 4:
		partarray = np.array([zip(*r_tran)[0], zip(*r_tran)[2], zip(*r_tran)[1], zip(*vel_tran)[0], zip(*vel_tran)[2], zip(*vel_tran)[1], mass, R_pos, z_pos, fe_h, mg_fe, r_200, zip(*ang_mom)[1], ages, o_fe] )
	else:
		partarray = np.array([zip(*r_tran)[0], zip(*r_tran)[2], zip(*r_tran)[1], zip(*vel_tran)[0], zip(*vel_tran)[2], zip(*vel_tran)[1], mass, R_pos, z_pos, r_200, zip(*ang_mom)[1]])
	ensure_dir(path+run+"_FOF"+str(halo)+"_SUB"+str(subgroup)+"/")
	np.save(path+run+"_FOF"+str(halo)+"_SUB"+str(subgroup)+"/part"+str(parttype)+"dat", partarray)
Beispiel #29
0
split_end = split_num * split_length
snaps = snaps[split_start:split_end]

if addDM:
    particle_types = ['1', '4']

for k in range(len(snaps)):
    print 'Running halo isolator for ', simulation, '-', run
    print 'Snap: ', snaps[k]
    print 'Obtaining ', galtype, ' galaxies...'

    snap = snaps[k]

    # FOF quantities
    num_subs = np.array(
        E.readArray("SUBFIND_GROUP", subfind_sim, snap, "/FOF/NumOfSubhalos"))
    masslist = np.array(
        E.readArray("SUBFIND_GROUP", subfind_sim, snap,
                    'FOF/Group_M_Crit200')[num_subs > 0]) * 1e10
    first_subhalo = np.array(
        E.readArray("SUBFIND_GROUP", subfind_sim, snap,
                    'FOF/FirstSubhaloID')[num_subs > 0])
    r200s = np.array(
        E.readArray("SUBFIND_GROUP", subfind_sim, snap,
                    "/FOF/Group_R_Crit200"))[num_subs > 0]

    # SUBFIND quantities
    Mstar_30kpc = np.array(
        E.readArray(
            "SUBFIND", subfind_sim, snap,
            "/Subhalo/ApertureMeasurements/Mass/030kpc"))[first_subhalo,
Beispiel #30
0
redshift = eagle.readAttribute(sniptag, sim, input_filename_base,
                               "/Header/Redshift")
aex = eagle.readAttribute(sniptag, sim, input_filename_base,
                          "/Header/ExpansionFactor")
hubble_param = eagle.readAttribute(sniptag, sim, input_filename_base,
                                   "/Header/HubbleParam")
boxsize = eagle.readAttribute(sniptag, sim, input_filename_base,
                              "/Header/BoxSize")

boxsize = boxsize / hubble_param * aex
print "boxsize=", boxsize
center = center / hubble_param * aex
print "center= ", center
coords = eagle.readArray(sniptag,
                         sim,
                         input_filename_base,
                         "/PartType0/Coordinates",
                         numThreads=1)
mass = eagle.readArray(sniptag,
                       sim,
                       input_filename_base,
                       "/PartType0/Mass",
                       numThreads=1)

if (snip == '1'):  # Have to back out hsmooth from density
    density = eagle.readArray("SNIP",
                              sim,
                              input_filename_base,
                              "/PartType0/Density",
                              numThreads=1)
    print "density= ", density
#import numpy
import eagle
#import sys
#import os
import coldens
#from coldens import *
import numpy as np
sim = '/net/galaxy/data2/oppenheimer/noneqhalozoomtest_snaprestart/data/'
tag = 'ioneq_015_z002p012'

coords = eagle.readArray("SNAP",
                         sim,
                         tag,
                         "/PartType0/Coordinates",
                         numThreads=1)
hsmooth = eagle.readArray("SNAP",
                          sim,
                          tag,
                          "/PartType0/SmoothingLength",
                          numThreads=1)
mass = eagle.readArray("SNAP", sim, tag, "/PartType0/Mass", numThreads=1)
mass *= 1.e+10

hydrogen = eagle.readArray("SNAP",
                           sim,
                           tag,
                           "/PartType0/ElementAbundance/Hydrogen",
                           numThreads=1)

carbon = eagle.readArray("SNAP",
                         sim,
Beispiel #32
0
aex = eagle.readAttribute(sniptag, sim, input_filename_base,
                          "/Header/ExpansionFactor")
hubble_param = eagle.readAttribute(sniptag, sim, input_filename_base,
                                   "/Header/HubbleParam")
redshift = eagle.readAttribute(sniptag, sim, input_filename_base,
                               "/Header/Redshift")
boxsize = eagle.readAttribute(sniptag, sim, input_filename_base,
                              "/Header/BoxSize")

boxsize = boxsize / hubble_param * aex
print "boxsize=", boxsize
center = center / hubble_param * aex
print "center= ", center
coords = eagle.readArray(sniptag,
                         sim,
                         input_filename_base,
                         "/PartType0/Coordinates",
                         numThreads=1)
mass = eagle.readArray(sniptag,
                       sim,
                       input_filename_base,
                       "/PartType0/Mass",
                       numThreads=1)

if (snip == '1'):  # Have to back out hsmooth from density
    density = eagle.readArray("SNIP",
                              sim,
                              input_filename_base,
                              "/PartType0/Density",
                              numThreads=1)
    print "density= ", density
Beispiel #33
0
ngas, ndm, nstar, nbh = numpart_pertype[0], numpart_pertype[1], numpart_pertype[4], numpart_pertype[5]

maxvoid_radius = boxsize / 2.

print('BoxSize = ' + repr(boxsize))
print('Total number of particles: ' + repr(np))
print('ngas: ' + repr(ngas))
print('ndm: ' + repr(ndm))
print('nstar: ' + repr(nstar))
print('nbh: ' + repr(nbh))
print('')
print('Proceeding to read data...')

pos = numpy.zeros([np, 3])

pos[:ngas, :] = eagle.readArray("SNAPSHOT", sim, tag, "/PartType0/Coordinates",\
                     noH=False, physicalUnits=False, verbose=False)

pos[ngas:ngas+ndm, :] = eagle.readArray("SNAPSHOT", sim, tag, "/PartType1/Coordinates",\
                     noH=False, physicalUnits=False, verbose=False)

pos[ngas+ndm:ngas+ndm+nstar, :] = eagle.readArray("SNAPSHOT", sim, tag, "/PartType4/Coordinates",\
                     noH=False, physicalUnits=False, verbose=False)

pos[ngas+ndm+nstar:ngas+ndm+nstar+nbh, :] = eagle.readArray("SNAPSHOT", sim, tag, "/PartType5/Coordinates",\
                     noH=False, physicalUnits=False, verbose=False)


cellsize = boxsize / ((ndm * 1./avgpart_percell) ** (1./3))
ngridcenters = int(boxsize / cellsize)
nincell = numpy.zeros([ngridcenters, ngridcenters, ngridcenters])
rhomed = np / (boxsize ** 3)
    def __init__(self,
                 centers,
                 side_sizes,
                 bulkvels,
                 central_gnums,
                 sgnums,
                 align_radius=0.03,
                 run='L0100N1504',
                 model='REFERENCE',
                 tag='028_z000p000',
                 part_types=['0', '4'],
                 pdata_type='SNAPSHOT',
                 overwrite=True,
                 path='/scratch/eagle/sav/',
                 halotype='any_halos'):
        vol_file = path + run + '_' + model + '/' + tag + '/FOF' + str(
            int(central_gnums[0])) + '_volume.hdf5'

        if overwrite == True or not os.path.exists(vol_file):
            sim = '/data5/simulations/EAGLE/' + run + '/' + model + '/data'
            #get boxsize and particle positions
            boxsize = E.readAttribute(pdata_type, sim, tag, "/Header/BoxSize")
            h = E.readAttribute(pdata_type, sim, tag, "/Header/HubbleParam")
            Omega0 = E.readAttribute(pdata_type, sim, tag, "/Header/Omega0")
            OmegaLambda = E.readAttribute(pdata_type, sim, tag,
                                          "/Header/OmegaLambda")
            OmegaBaryon = E.readAttribute(pdata_type, sim, tag,
                                          "/Header/OmegaBaryon")
            a_0 = E.readAttribute(pdata_type, sim, tag,
                                  "/Header/ExpansionFactor")
            boxsize = boxsize / h
            masstable = E.readAttribute(pdata_type, sim, tag,
                                        "/Header/MassTable") / h

            self.mask_type = []
            self.pos_type = []
            self.vel_type = []
            self.mass_type = []
            self.density_type = []
            self.PID_type = []
            self.abund_type = []
            self.smooths = []
            self.gnum_type = []
            self.sfr_type = []
            self.metal = []
            self.temp = []

            num_subs = E.readArray("SUBFIND_GROUP", sim, tag,
                                   "/FOF/NumOfSubhalos")
            r200 = E.readArray("SUBFIND_GROUP", sim, tag,
                               "/FOF/Group_R_Crit200")[num_subs > 0]
            gns = central_gnums - 1
            self.r200 = r200[gns]

            #re-center to 'center' and remove particles outside box
            for t in part_types:

                posarr = load_array('Coordinates',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                '''
                masks = []
                grouppos = []
                print 'Creating apertures...'
                for ii,center in tqdm(enumerate(centers)):
                    if (np.absolute(center)+side_sizes[ii]/2.).any() > boxsize/2.: # Is the group actually on the edge?
                        pos = posarr - (center - boxsize/2.)
                        pos = np.mod(pos,boxsize)
                        pos -= boxsize/2.

                    else: # Don't bother doing the wrapping if it doesn't affect the current group
                        pos = posarr - center
                        
                    r = np.sqrt(np.einsum('...j,...j->...',pos,pos)) # get the radii from the centre
                    mask = np.where(r<side_sizes[ii]/2.)[0] # make the mask
                    masks.append(mask)
                    grouppos.append(pos[mask])
                '''

                grouppos, masks = create_apertures(posarr, centers, side_sizes,
                                                   boxsize)

                self.pos_type.append(grouppos)
                del posarr

                print len(masks)

                velarr = load_array('Velocity',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                groupvel = []
                for ii, mask in enumerate(masks):
                    vel = velarr[mask]
                    vel -= bulkvels[ii]
                    groupvel.append(vel)
                self.vel_type.append(groupvel)
                del velarr

                groupmass = []
                if t != '1':
                    massarr = load_array('Mass',
                                         t,
                                         array_type=pdata_type,
                                         run=run,
                                         model=model,
                                         tag=tag)
                if t == '1':
                    massarr = np.ones(len(mask)) * masstable[1]
                for ii, mask in enumerate(masks):
                    groupmass.append(massarr[mask])
                self.mass_type.append(groupmass)
                del massarr

                if t in ['0', '4', '5']:
                    groupdensity = []
                    if t == '0':
                        densityarr = load_array('Density',
                                                t,
                                                array_type=pdata_type,
                                                run=run,
                                                model=model,
                                                tag=tag)
                    if t == '4':
                        densityarr = load_array('BirthDensity',
                                                t,
                                                array_type=pdata_type,
                                                run=run,
                                                model=model,
                                                tag=tag)
                    if t == '5':
                        densityarr = load_array('BH_Density',
                                                t,
                                                array_type=pdata_type,
                                                run=run,
                                                model=model,
                                                tag=tag)
                    for ii, mask in enumerate(masks):
                        groupdensity.append(densityarr[mask])
                    self.density_type.append(groupdensity)
                    del densityarr

                grouppids = []
                PIDs = load_array('ParticleIDs',
                                  t,
                                  array_type=pdata_type,
                                  run=run,
                                  model=model,
                                  tag=tag)
                for ii, mask in enumerate(masks):
                    grouppids.append(PIDs[mask])
                self.PID_type.append(grouppids)
                del PIDs

                groupgnums = []
                gnums = load_array('GroupNumber',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                for ii, mask in enumerate(masks):
                    groupgnums.append(gnums[mask])
                self.gnum_type.append(groupgnums)
                del gnums

                if t == '0':
                    groupsfrs = []
                    sfr = load_array('StarFormationRate',
                                     t,
                                     array_type=pdata_type,
                                     run=run,
                                     model=model,
                                     tag=tag)
                    for ii, mask in enumerate(masks):
                        groupsfrs.append(sfr[mask])
                    self.sfr_type = groupsfrs

                    grouptemps = []
                    temps = load_array('Temperature',
                                       t,
                                       array_type=pdata_type,
                                       run=run,
                                       model=model,
                                       tag=tag)
                    for ii, mask in enumerate(masks):
                        grouptemps.append(temps[mask])
                    self.temp = grouptemps

                if t == '4':
                    groupsftimes = []
                    sftimes = load_array('StellarFormationTime',
                                         t,
                                         array_type=pdata_type,
                                         run=run,
                                         model=model,
                                         tag=tag)
                    for ii, mask in enumerate(masks):
                        groupsftimes.append(sftimes[mask])
                    self.sftimes = groupsftimes

                if t in ['0', '4']:
                    H = load_array('SmoothedElementAbundance/Hydrogen',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    He = load_array('SmoothedElementAbundance/Helium',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    C = load_array('SmoothedElementAbundance/Carbon',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    N = load_array('SmoothedElementAbundance/Nitrogen',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    O = load_array('SmoothedElementAbundance/Oxygen',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    Ne = load_array('SmoothedElementAbundance/Neon',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    Mg = load_array('SmoothedElementAbundance/Magnesium',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    Si = load_array('SmoothedElementAbundance/Silicon',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    #S = load_array('SmoothedElementAbundance/Sulphur', t, array_type=pdata_type, run=run, model=model, tag=tag)
                    #Ca = load_array('SmoothedElementAbundance/Calcium', t, array_type=pdata_type, run=run, model=model, tag=tag)
                    Fe = load_array('SmoothedElementAbundance/Iron',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    abunds = np.dstack((H, He, C, N, O, Ne, Mg, Si, Fe))[0]
                    del H, He, C, N, O, Ne, Mg, Si, Fe
                    groupabunds = []
                    for ii, mask in enumerate(masks):
                        groupabunds.append(abunds[mask])
                    self.abund_type.append(groupabunds)
                    del abunds

                    groupmetal = []
                    metal = load_array('SmoothedMetallicity',
                                       t,
                                       array_type=pdata_type,
                                       run=run,
                                       model=model,
                                       tag=tag)
                    for ii, mask in enumerate(masks):
                        groupmetal.append(metal[mask])
                    self.metal.append(groupmetal)
                    del metal

                if t in ['0', '4', '5']:
                    groupsmooths = []
                    smooths = load_array('SmoothingLength',
                                         t,
                                         array_type=pdata_type,
                                         run=run,
                                         model=model,
                                         tag=tag)
                    for ii, mask in enumerate(masks):
                        groupsmooths.append(smooths[mask])
                    self.smooths.append(groupsmooths)
                    del smooths
            self.mask_type.append(masks)

            for n in range(len(part_types)):
                if part_types[n] == '4':
                    print 'Stars are part index ', n
                    si = n
                else:
                    continue
                self.transform = []
                for ii in range(0, len(self.pos_type[0])):
                    #perform alignment to Jz of star particles in a given R
                    Rs = np.sqrt(self.pos_type[si][ii][:, 0]**2 +
                                 self.pos_type[si][ii][:, 1]**2 +
                                 self.pos_type[si][ii][:, 2]**2)
                    radmask = Rs < align_radius
                    starj = np.cross(
                        self.pos_type[si][ii], self.vel_type[si][ii] *
                        self.mass_type[si][ii][:, np.newaxis])
                    r200j = starj[radmask]
                    tot_ang_mom = np.sum(r200j, axis=0)
                    a = np.matrix([
                        tot_ang_mom[0], tot_ang_mom[1], tot_ang_mom[2]
                    ]) / np.linalg.norm(
                        [tot_ang_mom[0], tot_ang_mom[1], tot_ang_mom[2]])
                    b = np.matrix([0, 0, 1])
                    v = np.cross(a, b)
                    s = np.linalg.norm(v)
                    c = np.dot(a, b.T)
                    vx = np.matrix([[0, -v[0, 2], v[0, 1]],
                                    [v[0, 2], 0, -v[0, 0]],
                                    [-v[0, 1], v[0, 0], 0]])
                    transform = np.eye(3, 3) + vx + (vx * vx) * (1 /
                                                                 (1 + c[0, 0]))
                    self.transform.append(transform)
            self.run = run
            self.model = model
            self.tag = tag
            self.halotype = halotype
            self.centers = centers
            self.side_sizes = side_sizes
            self.bulkvels = bulkvels
            self.central_gnums = central_gnums
            self.part_types = part_types

            print 'Applying transformations...'
            for ii, ptype in enumerate(part_types):
                for jj, transform in tqdm(enumerate(self.transform)):
                    try:
                        self.pos_type[ii][jj] = np.array([
                            np.dot(transform, self.pos_type[ii][jj][i].T)
                            for i in range(0, len(self.pos_type[ii][jj]))
                        ])[:, 0]
                        self.vel_type[ii][jj] = np.array([
                            np.dot(transform, self.vel_type[ii][jj][i].T)
                            for i in range(0, len(self.vel_type[ii][jj]))
                        ])[:, 0]
                    except IndexError:
                        continue
Beispiel #35
0
    def __init__(self,
                 centers,
                 side_sizes,
                 bulkvels,
                 central_gnums,
                 sgnums,
                 align_radius=0.03,
                 run='L0100N1504',
                 model='REFERENCE',
                 tag='028_z000p000',
                 part_types=['0', '4'],
                 pdata_type='SNAPSHOT',
                 overwrite=True,
                 path='/scratch/eagle/sav/',
                 halotype='any_halos',
                 timing_flag=False):
        vol_file = path + run + '_' + model + '/' + tag + '/FOF' + str(
            int(central_gnums[0])) + '_volume.hdf5'

        if overwrite == True or not os.path.exists(vol_file):
            sim = '/data5/simulations/EAGLE/' + run + '/' + model + '/data'
            #get boxsize and particle positions
            boxsize = E.readAttribute(pdata_type, sim, tag, "/Header/BoxSize")
            h = E.readAttribute(pdata_type, sim, tag, "/Header/HubbleParam")
            Omega0 = E.readAttribute(pdata_type, sim, tag, "/Header/Omega0")
            OmegaLambda = E.readAttribute(pdata_type, sim, tag,
                                          "/Header/OmegaLambda")
            OmegaBaryon = E.readAttribute(pdata_type, sim, tag,
                                          "/Header/OmegaBaryon")
            a_0 = E.readAttribute(pdata_type, sim, tag,
                                  "/Header/ExpansionFactor")
            boxsize = boxsize / h
            masstable = E.readAttribute(pdata_type, sim, tag,
                                        "/Header/MassTable") / h

            self.mask_type = []
            self.pos_type = []
            self.vel_type = []
            self.mass_type = []
            self.density_type = []
            self.PID_type = []
            self.abund_type = []
            self.smooths = []
            self.gnum_type = []
            self.sfr_type = []
            self.metal = []
            self.temp = []

            num_subs = E.readArray("SUBFIND_GROUP", sim, tag,
                                   "/FOF/NumOfSubhalos")
            r200 = E.readArray("SUBFIND_GROUP", sim, tag,
                               "/FOF/Group_R_Crit200")[num_subs > 0]
            gns = central_gnums - 1
            self.r200 = r200[gns]

            #re-center to 'center' and remove particles outside box
            for t in part_types:

                masks = []
                pos = load_array('Coordinates',
                                 t,
                                 array_type=pdata_type,
                                 run=run,
                                 model=model,
                                 tag=tag)
                grouppos = []

                # Create a list of COPs where each COP is given in the co-ordinate system of the previous COP.
                shift_centres = np.zeros(np.shape(centers))
                shift_centres[0, :] = centers[0, :]
                for c in range(len(centers) - 1):
                    shift_centres[c + 1] = centers[c + 1] - centers[c]

                inds = np.arange(len(pos[:, 0]))
                npart = len(inds)

                print 'Creating apertures...'
                for ii in tqdm(range(len(shift_centres))):
                    centre = shift_centres[ii]

                    if ii == 0:
                        current_centre = np.array([0., 0., 0.])
                    else:
                        current_centre = centers[
                            ii -
                            1]  # the current centre in the true box co-ordinate system

                    #if (np.absolute(centre)+side_sizes[ii]/2.).any() > boxsize/2.:

                    if ((boxsize / 2. + np.absolute(current_centre)) -
                        (np.absolute(centre) + side_sizes[ii] / 2.)
                        ).any() < 0.:  # Is the group actually on the edge?
                        pos = ne.evaluate("pos-centre")
                        pos[pos[:, 0] < (-1. * boxsize / 2.), 0] += boxsize
                        pos[pos[:, 1] < (-1. * boxsize / 2.), 1] += boxsize
                        pos[pos[:, 2] < (-1. * boxsize / 2.), 2] += boxsize
                        '''
                        pos -= (centre - boxsize/2.)
                        pos = np.mod(pos,boxsize)
                        pos -= boxsize/2.
                        '''
                        #if timing_flag:
                        print 'Wrapped box'

                    else:  # Don't bother doing the wrapping if it doesn't affect the current group
                        s = time()
                        pos = ne.evaluate("pos-centre")
                        transform_time = time() - s

                    rmax = side_sizes[ii] / 2.

                    s = time()
                    # Chop along x
                    xs = pos[:, 0]
                    mask = ne.evaluate(
                        'where(abs(xs)<rmax,True,False)').nonzero()[0]
                    cut_pos = pos[mask, :]
                    cut_inds = inds[mask]
                    # Along y
                    ys = cut_pos[:, 1]
                    mask = ne.evaluate(
                        'where(abs(ys)<rmax,True,False)').nonzero()[0]
                    cut_pos = cut_pos[mask, :]
                    cut_inds = cut_inds[mask]
                    # Along z
                    zs = cut_pos[:, 2]
                    mask = ne.evaluate(
                        'where(abs(zs)<rmax,True,False)').nonzero()[0]
                    cut_pos = cut_pos[mask, :]
                    cut_inds = cut_inds[mask]
                    chop_time = time() - s

                    s = time()
                    r2 = np.einsum('...j,...j->...', cut_pos,
                                   cut_pos)  # get the radii from the centre
                    radial_calculation = time() - s

                    s = time()
                    mask = np.where(r2 < rmax**2)[0]  # make the mask
                    radial_masking = time() - s

                    masks.append(cut_inds[mask])
                    grouppos.append(cut_pos[mask])

                    if timing_flag:
                        print 'Time to transform box: ', transform_time
                        print 'Time to chop box up: ', chop_time
                        print 'Time to calculate radial distances: ', radial_calculation
                        print 'Time to mask by radius: ', radial_masking

                self.pos_type.append(grouppos)
                del pos
                del inds

                velarr = load_array('Velocity',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                groupvel = []
                for ii, mask in enumerate(masks):
                    vel = velarr[mask]
                    vel -= bulkvels[ii]
                    groupvel.append(vel)
                self.vel_type.append(groupvel)
                del velarr

                groupmass = []
                if t != '1':
                    massarr = load_array('Mass',
                                         t,
                                         array_type=pdata_type,
                                         run=run,
                                         model=model,
                                         tag=tag)
                if t == '1':
                    massarr = np.ones(npart) * masstable[1]
                for ii, mask in enumerate(masks):
                    groupmass.append(massarr[mask])
                self.mass_type.append(groupmass)
                del massarr

                if t in ['0', '4', '5']:
                    groupdensity = []
                    if t == '0':
                        densityarr = load_array('Density',
                                                t,
                                                array_type=pdata_type,
                                                run=run,
                                                model=model,
                                                tag=tag)
                    if t == '4':
                        densityarr = load_array('BirthDensity',
                                                t,
                                                array_type=pdata_type,
                                                run=run,
                                                model=model,
                                                tag=tag)
                    if t == '5':
                        densityarr = load_array('BH_Density',
                                                t,
                                                array_type=pdata_type,
                                                run=run,
                                                model=model,
                                                tag=tag)
                    for ii, mask in enumerate(masks):
                        groupdensity.append(densityarr[mask])
                    self.density_type.append(groupdensity)
                    del densityarr

                grouppids = []
                PIDs = load_array('ParticleIDs',
                                  t,
                                  array_type=pdata_type,
                                  run=run,
                                  model=model,
                                  tag=tag)
                for ii, mask in enumerate(masks):
                    grouppids.append(PIDs[mask])
                self.PID_type.append(grouppids)
                del PIDs

                groupgnums = []
                gnums = load_array('GroupNumber',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                for ii, mask in enumerate(masks):
                    groupgnums.append(gnums[mask])
                self.gnum_type.append(groupgnums)
                del gnums

                if t == '0':
                    groupsfrs = []
                    sfr = load_array('StarFormationRate',
                                     t,
                                     array_type=pdata_type,
                                     run=run,
                                     model=model,
                                     tag=tag)
                    for ii, mask in enumerate(masks):
                        groupsfrs.append(sfr[mask])
                    self.sfr_type = groupsfrs

                    grouptemps = []
                    temps = load_array('Temperature',
                                       t,
                                       array_type=pdata_type,
                                       run=run,
                                       model=model,
                                       tag=tag)
                    for ii, mask in enumerate(masks):
                        grouptemps.append(temps[mask])
                    self.temp = grouptemps

                if t == '4':
                    groupsftimes = []
                    sftimes = load_array('StellarFormationTime',
                                         t,
                                         array_type=pdata_type,
                                         run=run,
                                         model=model,
                                         tag=tag)
                    for ii, mask in enumerate(masks):
                        groupsftimes.append(sftimes[mask])
                    self.sftimes = groupsftimes

                if t in ['0', '4']:
                    H = load_array('SmoothedElementAbundance/Hydrogen',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    He = load_array('SmoothedElementAbundance/Helium',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    C = load_array('SmoothedElementAbundance/Carbon',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    N = load_array('SmoothedElementAbundance/Nitrogen',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    O = load_array('SmoothedElementAbundance/Oxygen',
                                   t,
                                   array_type=pdata_type,
                                   run=run,
                                   model=model,
                                   tag=tag)
                    Ne = load_array('SmoothedElementAbundance/Neon',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    Mg = load_array('SmoothedElementAbundance/Magnesium',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    Si = load_array('SmoothedElementAbundance/Silicon',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    #S = load_array('SmoothedElementAbundance/Sulphur', t, array_type=pdata_type, run=run, model=model, tag=tag)
                    #Ca = load_array('SmoothedElementAbundance/Calcium', t, array_type=pdata_type, run=run, model=model, tag=tag)
                    Fe = load_array('SmoothedElementAbundance/Iron',
                                    t,
                                    array_type=pdata_type,
                                    run=run,
                                    model=model,
                                    tag=tag)
                    abunds = np.dstack((H, He, C, N, O, Ne, Mg, Si, Fe))[0]
                    del H, He, C, N, O, Ne, Mg, Si, Fe
                    groupabunds = []
                    for ii, mask in enumerate(masks):
                        groupabunds.append(abunds[mask])
                    self.abund_type.append(groupabunds)
                    del abunds

                    groupmetal = []
                    metal = load_array('SmoothedMetallicity',
                                       t,
                                       array_type=pdata_type,
                                       run=run,
                                       model=model,
                                       tag=tag)
                    for ii, mask in enumerate(masks):
                        groupmetal.append(metal[mask])
                    self.metal.append(groupmetal)
                    del metal

                if t in ['0', '4', '5']:
                    groupsmooths = []
                    smooths = load_array('SmoothingLength',
                                         t,
                                         array_type=pdata_type,
                                         run=run,
                                         model=model,
                                         tag=tag)
                    for ii, mask in enumerate(masks):
                        groupsmooths.append(smooths[mask])
                    self.smooths.append(groupsmooths)
                    del smooths
            self.mask_type.append(masks)

            for n in range(len(part_types)):
                if part_types[n] == '4':
                    print 'Stars are part index ', n
                    si = n
                else:
                    continue
                self.transform = []
                for ii in range(0, len(self.pos_type[0])):
                    #perform alignment to Jz of star particles in a given R
                    Rs = np.sqrt(self.pos_type[si][ii][:, 0]**2 +
                                 self.pos_type[si][ii][:, 1]**2 +
                                 self.pos_type[si][ii][:, 2]**2)
                    radmask = Rs < align_radius
                    starj = np.cross(
                        self.pos_type[si][ii], self.vel_type[si][ii] *
                        self.mass_type[si][ii][:, np.newaxis])
                    r200j = starj[radmask]
                    tot_ang_mom = np.sum(r200j, axis=0)
                    a = np.matrix([
                        tot_ang_mom[0], tot_ang_mom[1], tot_ang_mom[2]
                    ]) / np.linalg.norm(
                        [tot_ang_mom[0], tot_ang_mom[1], tot_ang_mom[2]])
                    b = np.matrix([0, 0, 1])
                    v = np.cross(a, b)
                    s = np.linalg.norm(v)
                    c = np.dot(a, b.T)
                    vx = np.matrix([[0, -v[0, 2], v[0, 1]],
                                    [v[0, 2], 0, -v[0, 0]],
                                    [-v[0, 1], v[0, 0], 0]])
                    transform = np.eye(3, 3) + vx + (vx * vx) * (1 /
                                                                 (1 + c[0, 0]))
                    self.transform.append(transform)
            self.run = run
            self.model = model
            self.tag = tag
            self.halotype = halotype
            self.centers = centers
            self.side_sizes = side_sizes
            self.bulkvels = bulkvels
            self.central_gnums = central_gnums
            self.part_types = part_types

            print 'Applying transformations...'
            for ii, ptype in enumerate(part_types):
                for jj, transform in tqdm(enumerate(self.transform)):
                    try:
                        self.pos_type[ii][jj] = np.array([
                            np.dot(transform, self.pos_type[ii][jj][i].T)
                            for i in range(0, len(self.pos_type[ii][jj]))
                        ])[:, 0]
                        self.vel_type[ii][jj] = np.array([
                            np.dot(transform, self.vel_type[ii][jj][i].T)
                            for i in range(0, len(self.vel_type[ii][jj]))
                        ])[:, 0]
                    except IndexError:
                        continue
#filein = h5py.File(path)
#redshift = filein['Header'].attrs['Redshift']
#aex = 1/(1+redshift)
#center = center*aex

aex = eagle.readAttribute("SNAP", sim, input_filename_base,
                          "/Header/ExpansionFactor")
hubble_param = eagle.readAttribute("SNAP", sim, input_filename_base,
                                   "/Header/HubbleParam")

center = center / hubble_param * aex

coords = eagle.readArray("SNAP",
                         sim,
                         input_filename_base,
                         "/PartType0/Coordinates",
                         numThreads=1)
hsmooth = eagle.readArray("SNAP",
                          sim,
                          input_filename_base,
                          "/PartType0/SmoothingLength",
                          numThreads=1)
mass = eagle.readArray("SNAP",
                       sim,
                       input_filename_base,
                       "/PartType0/Mass",
                       numThreads=1)
mass *= 1.e+10

hydrogen = eagle.readArray("SNAP",