Exemple #1
0
    def __init__(self, galaxy, snap):

        # inputs:
        #       galaxy: a string with galaxy name, such as "MW" or "M31"
        #       snap:  the snapshot number, such as 0, 1, etc

        # Initialize instance of this class with the following properties:

        # store the name of the galaxy
        self.gname = galaxy

        # add a string of the filenumber to the value "000"
        ilbl = "000" + str(snap)

        # remove all but the last 3 digits
        ilbl = ilbl[-3:]
        self.filename = "%s_" % (galaxy) + ilbl + ".txt"

        # read in the data of our desired file
        self.time, self.total, self.data = Read(self.filename)

        # read in the data for the x, y, z positions and the mass
        self.m = self.data["m"]
        self.x = self.data["x"] * u.kpc
        self.y = self.data["y"] * u.kpc
        self.z = self.data["z"] * u.kpc
    def __init__(self, galaxy, snap):
        ilbl = '000' + str(snap)
        ilbl = ilbl[-3:]
        self.filename = "%s_" % (galaxy) + ilbl + ".txt"

        self.data, self.time, self.total = Read(
            self.filename)  #Read in the file and assign desired values
        self.x = self.data['x'] * u.kpc
        self.y = self.data['y'] * u.kpc
        self.z = self.data['z'] * u.kpc
        self.m = self.data['m']
        self.gname = galaxy
        print(self.gname)
        self.Gravity = G
        self.Gravity = self.Gravity.to(
            u.kpc * u.km**2 / u.s**2 /
            u.Msun)  #convert Gravity to desired units
Exemple #3
0
    def __init__(self, filename, ptype):
        # Initialize the instance of this Class with the following properties:

        # read data in the given file using Read
        self.data, self.time, self.total = Read(filename)

        #create an array to store indexes of particles of desired Ptype
        self.index = np.where(self.data['type'] == ptype)

        # store the mass, positions, velocities of only the particles of the given type
        # the following only gives the example of storing the mass
        self.m = self.data['m'][self.index]
        # write your own code to complete this for positions and velocities
        self.x = self.data['x'][self.index]
        self.y = self.data['y'][self.index]
        self.z = self.data['z'][self.index]
        self.vx = self.data['vx'][self.index]
        self.vy = self.data['vy'][self.index]
        self.vz = self.data['vz'][self.index]
def ComponentMass(
    filename, particleType
):  #Function for summing up mass of a particular type in a galaxy
    data, time, particles = Read(
        filename)  #Read in the data from the given file

    i = 0  #initialize totalMass and loop index values
    totalMass = 0

    #data.size represents the total number of data indexes in the file
    while i < data.size:  #While the index is of the desired type, sum up the masses of all values in dataset
        if (data['type'][i] == particleType):
            totalMass += data['m'][i]
        i += 1

    totalMass *= 1e2 * g.Msun  #Mass is in 1e10, so multiply by 1e2 and g.Msun to make units proper
    totalMass = np.around(totalMass, 3)  #Round

    return totalMass
    def __init__(self, filename, ptype):
        # Function that takes inputs: object(self), the filename, and particle type

        # read in the file and particle type
        self.time, self.total, self.data = Read(filename)

        #create an array to store indexes of particles of desired Ptype
        self.index = np.where(self.data['type'] == ptype)

        # store the mass of only the particles of the given type
        self.m = self.data['m'][self.index]

        # store the positions of only the particles of the given type
        self.x = self.data['x'][self.index]
        self.y = self.data['y'][self.index]
        self.z = self.data['z'][self.index]

        # store the velocity of only the particles of the given type
        self.vx = self.data['vx'][self.index]
        self.vy = self.data['vy'][self.index]
        self.vz = self.data['vz'][self.index]
        ##### PLACE other particle properties here: x,y,z,vx,vy,vz #####
        """Completed this section"""
Exemple #6
0
def ComponentMass(filename, Ptype):
    # inputs:
    #      filename: the name of the txt file you wish to read
    #      Ptype: the type of particle you wish to find the mass of.
    #             options for Ptype = 1, 2, or 3.
    #             1 = Halo matter, 2 = Disk material, 3 = Bulge stuff

    # returns:
    #      The total mass of your desired galactic component, in 1e12Msun

    # read in the file
    time, number, data = Read(filename)

    # select only that data of your selected material type
    select_data = data[np.where(data["type"] == Ptype)]

    # extract mass data from your selected data
    mass_array = select_data["m"]

    # find total mass of the selected material
    total_mass = np.around(np.sum(mass_array) * u.Msun, 3) * 1e10

    return np.around(total_mass / 1e12, 3)
def ParticleInfo(filename, type, number):

    data, time, total = Read(filename)  #Read in data from file
    Dist_Mag = math.sqrt((data['x'][number])**2 + (data['y'][number])**2 +
                         (data['z'][number])**2)  #Calculate distance magnitude
    Vel_Mag = math.sqrt((data['vx'][number])**2 + (data['vy'][number])**2 +
                        (data['vz'][number])**2)  #Calculate Velocity magnitude
    mass = data['m'][number]

    Dist_Mag *= g.kpc  #Convert Distance to kpc
    Vel_Mag *= g.km / g.s  #Convert Velocity to km/s
    Dist_Mag = np.around(Dist_Mag, 3)  #Round
    Vel_Mag = np.around(Vel_Mag, 3)

    index = np.where(data['type'] == type)  #catalogue values of desired type
    mnew = data['m'][index] * 1e10 * g.Msun
    xnew = data['x'][index] * g.kpc
    ynew = data['y'][index] * g.kpc
    znew = data['z'][index] * g.kpc
    vxnew = data['vx'][index] * g.km / g.s
    vynew = data['vy'][index] * g.km / g.s
    vznew = data['vz'][index] * g.km / g.s

    return Dist_Mag, Vel_Mag, mass
Exemple #8
0
def ParticleInfo(particle_type, particle_num):

    #import data
    time, P_total, data = Read("MW_000")

    #located specific particle type
    index = np.where(data["type"] == particle_type)

    #specify quantities
    """Mass [Particle Type] [ith particle select]"""
    m = data['m'][index][
        particle_num -
        1]  # array containing all mass values of particle types and ith particle
    #m = m*1e10*u.M_sun #Calculate quantity with appropiate units
    """Positions [Particle Type] [ith particle select]"""
    x = data['x'][index][
        particle_num - 1]  # array containing all x coordinates [Particle Type]
    y = data['y'][index][particle_num -
                         1]  # array containing all y coordinates
    z = data['z'][index][particle_num -
                         1]  # array containing all z coordinates
    """Velocities [Particle Type] [ith particle select]"""
    vx = data['vx'][index][particle_num -
                           1]  # array containing all vx coordinates
    vy = data['vy'][index][particle_num -
                           1]  # array containing all vy coordinates
    vz = data['vz'][index][particle_num -
                           1]  # array containing all vz coordinates
    """3D Magnitude Calculations"""
    R = x * x + y * y + z * z  #x^2+y^2+z^2
    V_R = vx * vx + vy * vy + vz * vz  #vx^2+vy^2+vz^2
    #calculate magnitues
    r = np.round(np.sqrt(R),
                 3) * u.kpc  #round 3D position magnitude to 3 decimal places
    v_r = np.round(np.sqrt(V_R), 3) * u.km / u.s  #round 3D velocity magnitude
    """Print Results"""