def __init__(self, galaxy1, galaxy2, snap, IncludeCompanion=False): # initialize with: # galaxy1, string that contains the name of the galaxy USED TO FIND THE CENTER OF MASS i.e. "MW" #galaxy2, string that contains name of other galaxy # snap, integer that gives the snapshot number, corresponding to time # IncludeCompanion, to develop a mass profile that includes the mass of both galaxies self.IncludeCompanion = IncludeCompanion # use galaxy and snap to reconstruct string name ilbl1 = '000' + str(snap) # remove all but three last digits ilbl1 = ilbl1[-3:] self.filename1 = "./HighRes/%s_" % (galaxy1) + ilbl1 + '.txt' #print (self.filename) #troubleshooting # usual file reading self.time1, self.total1, self.data1 = Read(self.filename1) self.gname1 = galaxy1 # pull data values. no need to distinguish by particle type (yet) self.m1 = self.data1['m'] self.x1 = self.data1['x'] self.y1 = self.data1['y'] self.z1 = self.data1['z'] self.R1 = np.sqrt(self.x1**2 + self.y1**2 + self.z1**2) self.vx1 = self.data1['vx'] self.vy1 = self.data1['vy'] self.vz1 = self.data1['vz'] self.V1 = np.sqrt(self.vx1**2 + self.vy1**2 + self.vz1**2) #print self.z #troubleshoot self.diskindex = np.where(self.data1['type'] == 2) # repeat above with second galaxy # use galaxy and snap to reconstruct string name ilbl2 = '000' + str(snap) # remove all but three last digits ilbl2 = ilbl2[-3:] self.filename2 = "./HighRes/%s_" % (galaxy2) + ilbl2 + '.txt' #print (self.filename) #troubleshooting # usual file reading self.time2, self.total2, self.data2 = Read(self.filename2) self.gname2 = galaxy2 if (self.IncludeCompanion is True): # only do this part if you actually need it # pull data values. no need to distinguish by particle type (yet) self.m2 = self.data2['m'] self.x2 = self.data2['x'] self.y2 = self.data2['y'] self.z2 = self.data2['z'] self.R2 = np.sqrt(self.x2**2 + self.y2**2 + self.z2**2)
def __init__(self, galaxy, snap): """ Inputs: galaxy = string containing abbreviated galaxy name examples are MW, M31,M33 snap = snap number defining the timestep """ # reconstruct data filename from args # add a string of the filenumber to the value "000" snapstring = '000' + str(snap) # remove all but the last 3 digits snapstring = snapstring[-3:] self.filename = "%s_" % (galaxy) + snapstring + ".txt" # read in data time, total, data = Read(self.filename) # save and give x, y, z appropriate units self.x = data['x'] * u.kpc self.y = data['y'] * u.kpc self.z = data['z'] * u.kpc # save mass (in 1e10 Msun, but no astropy units) self.m = data['m'] # save particle types self.type = data['type'] # save galaxy name self.gname = galaxy
def ComponentMass(filename, parttype): # Inputs: # filename is the name of the galaxy from which the data will be read # parttype is the particle type to get the masses of # halo is type 1, disk is type 2, bulge is type 3 # Returns: # total mass of particles of given type in 10^12 solar masses # Need to read file and assign outputs of Read function # time is time in 10 Myr, number is total number of particles, data is data array # data array has particle masses, which will be of interest here time, number, data = Read(filename) # set up an index which specifies all of the particles of the given type in data array index = (np.where(data['type'] == parttype)) # define 'mass' as an array which will be extended in a for loop with all particle masses # by iterating the loop over every value in 'index' mass = [] for i in index: mass.extend(data['m'][i]) # 'mass' should now be a list of all particle masses of a given type. Now will sum all # of these masses and return the total mass, dividing by 100 gets mass in units of # x 10^12 solar masses, as the masses in the data array are in units of 10^10 solar # masses. np.around rounds the answer to 3 decimal places return np.around(sum(mass) / 100., 3) * u.solMass
def ComponentMass(filename, particle_type): time, total, data = Read(filename) index = np.where(data['type'] == particle_type) #select only particle type m_tot = np.sum(data['m'][index]) * 1e10 * u.Msun #sum all masses of particle type, put into units of solar mass return np.around(m_tot, 3) #round to 3 decimal places
def ParticleInfo(filename, ptype, pnum): # defining function time, number, data = Read( filename ) # assigns variables to output of Read function, will only use 'data' in this function index = np.where( data['type'] == ptype ) # creates index array based on particle type specified so that first and last entries correspond to the position of the first # and last particles of that type in the file m = data['m'][index[0][pnum - 1]] * ( 10**10 ) * u.solMass # gets mass of specified particle. '[0]' is needed to specify row of index matrix '[pnum-1]' shifts the index so that # the number inputted actually corresponds to that number particle in the list. gives mass units of 10^10 solar masses x = data['x'][index[0][ pnum - 1]] # getting position and velocity components for particle in the same way mass was retrieved. y = data['y'][index[0][pnum - 1]] z = data['z'][index[0][pnum - 1]] vx = data['vx'][index[0][pnum - 1]] vy = data['vy'][index[0][pnum - 1]] vz = data['vz'][index[0][pnum - 1]] r = sqrt(x**2 + y**2 + z**2) * u.kpc # gets magnitude of position, assigns units of kpc v = sqrt( vx**2 + vy**2 + vz**2 ) * u.km / u.s # gets magnitude of velocity, assigns units of km/s rround = np.around(r, 3) # rounds position magnitude to 3 decimal places vround = np.around(v, 3) # rounds velocity magnitude to 3 decimal places msci = "{:e}".format( m) # makes it so mass is displayed in scientific notation return rround, vround, msci # gives rounded position magnitude, rounded velocity magnitude, and particle mass as outputs
def ParticleInfo(filename, particle_type, particle_num): #read in the text file time, part_total, data = Read(filename) #make an index to only select the particle type we want index = np.where(data['type'] == particle_type) #make new arrays only with the data from the desired particle type xnew = data['x'][index] ynew = data['y'][index] znew = data['z'][index] vxnew = data['vx'][index] vynew = data['vy'][index] vznew = data['vz'][index] mnew = data['m'][index] #pull the desired particle's information from the reduced arrays xpos = xnew[particle_num] ypos = ynew[particle_num] zpos = znew[particle_num] xvel = vxnew[particle_num] yvel = vynew[particle_num] zvel = vznew[particle_num] mass = mnew[particle_num] #acquire the final3D position from the 3 listed positions pos = np.round((np.sqrt(xpos**2 + ypos**2 + zpos**2)), 3) pos = pos * u.kpc #acquire the final 3D velocity from the 3 listed components vel = np.round((np.sqrt(xvel**2 + yvel**2 + zvel**2)), 3) vel = vel * u.km / u.s #return the information as a tuple return pos, vel, mass
def ParticleInfo(filename, ptype, pnum): """ Get a particle's distance, velocity, and mass. ptype can be integer (1, 2, 3) or string (halo, disk, bulge). :param filename: file path to data file :param ptype: particle type; halo (1), disk (2), or bulge (3) :param pnum: particle number; index starts at 1. :return: distance, velocity, mass """ # If ptype is string, then reassign according to indexing rule if isinstance(ptype, str): if ptype.lower() == 'halo': ptype = 1 elif ptype.lower() == 'disk': ptype = 2 elif ptype.lower() == 'bulge': ptype = 3 else: raise ValueError('Wrong particle type') # Read data file, and index corresponding particle number/type time, total, data = Read(filename) particle = data[data['type'] == ptype][pnum - 1] # Calculate the rounded distance/velocity vector magnitudes, and get mass (w/ Msun units) distance = np.round( np.sqrt(particle[2]**2 + particle[3]**2 + particle[4]**2), 3) velocity = np.round( np.sqrt(particle[5]**2 + particle[6]**2 + particle[7]**2), 3) mass = particle[1] * 1e10 * u.M_sun # Return calculated values with units return distance * u.kpc, velocity * u.km / u.s, mass
def __init__(self, filename, particletype): #inputs: #self #filename- for this we are using MW_000.txt, M31_000.txt, and M33_000.txt #particle type: 1.0=halo, 2.0=disk, 3.0=bulge #returns: #sets indices #read data from user given file (detailed in filename above) self.time, self.total, self.data = Read(filename) #creates an array with the user specified particle type self.index = np.where(self.data['type'] == particletype) #storing the mass, position, and velocities of a particle #Same idea as in HW2 ParticleProperties- this time just defining with self #mass self.m = self.data['m'][self.index] #x,y,z position self.x = self.data['x'][self.index] self.y = self.data['y'][self.index] self.z = self.data['z'][self.index] #x,y,z velocity self.Vx = self.data['vx'][self.index] self.Vy = self.data['vy'][self.index] self.Vz = self.data['vz'][self.index]
def __init__(self, filename, ptype): """ Initializing the object PARAMETERS ---------- filename : name of the file containing galaxy info. Type = str ptype : Particle type. Possible values are 'Halo', 'Disk' or 'Bulge'. Type = str """ # 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, positions, velocities of only the particles of the given type kms = u.km / u.s #creating km/s unit for velocity self.m = self.data['m'][self.index] * u.Msun * 1e10 self.x = self.data['x'][self.index] * u.kpc self.y = self.data['y'][self.index] * u.kpc self.z = self.data['z'][self.index] * u.kpc self.vx = self.data['vx'][self.index] * kms self.vy = self.data['vy'][self.index] * kms self.vz = self.data['vz'][self.index] * kms
def ComponentMass(filename, ParticleType): #inputs: #filename: for this Hw it is either MW_000.txt,M31_000.txt, or M33_000.txt #particle type: 1.0 for Halo, 2.0 for Disk, or 3.0 for Bulge #return: #Mass: units of 10e12Msun, rounded to 3 decimal places #reading in the return values from ReadFile code (part 2 of HW) time, total, data = Read(filename) #this creates an index based on the particle type input index = np.where(data['type'] == ParticleType) #creates an array with all of the mass values from a specific particle type input mass = data['m'][index] mass2 = mass * 1e-2 #this is to correct for the units because the given mass value is in 1e10 #To find the total mass of a specific type of particle, using the sum #function to add up every mass value created from the array TotalMass = np.around((sum(mass2) * 1e12 * u.Msun), 3) #multiplying constant at the end to put in units of 10e12Msun return TotalMass
def ParticleInfo(filename, particleType, particleNumber): #First Column type: Particle Type. Type 1 = Dark Matter, Type 2 = Disk Stars, Type 3 = Bulge Stars time, total, data = Read(filename) index = np.where(data['type'] == particleType) # Fetch appropriate variables of a particular particle number within the given particleType and add units # NOTE: particleNumber refers to the number of particle OF THE GIVEN particleType # # For clarity # data matrix representation of dataset from filename # data['x'] list of all 'x' values from dataset # data['x'][index] list of all 'x' values that have 'type' == particleType # data['x'][index][n] nth element of the list of all 'x' values that have 'type' == particleType pos_x = float(data['x'][index][particleNumber]) * u.kpc pos_y = float(data['y'][index][particleNumber]) * u.kpc pos_z = float(data['z'][index][particleNumber]) * u.kpc vel_x = float(data['vx'][index][particleNumber]) * (u.km / u.s) vel_y = float(data['vy'][index][particleNumber]) * (u.km / u.s) vel_z = float(data['vz'][index][particleNumber]) * (u.km / u.s) mass = (float(data['m'][index][particleNumber]) * 10**10) * u.Msun # caluclate magnitudes (if needed) and round values to three decimal places position = np.around(np.sqrt(pos_x**2 + pos_y**2 + pos_z**2), 3) velocity = np.around(np.sqrt(vel_x**2 + vel_y**2 + vel_z**2), 3) mass = np.around(mass, 3) # return values for future use. return position, velocity, mass
def __init__(self, galaxy, snap): # Inputs: # galaxy = name of galaxy # snap = snapshot number # Returns: # Important data from snapshot text files # Add string of filenumber to value 000 ilbl = '000' + str(snap) # Remove all but last 3 digits of string ilbl = ilbl[-3:] # Assign filename based on snapshot and galaxy inputs self.filename = 'C:/Users/Jimmy/400B_Lilly/' + '%s_' % ( galaxy) + ilbl + '.txt' # Read data in the given file using Read self.time, self.total, self.data = Read(self.filename) # Save galaxy name as global variable self.gname = galaxy 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']
def ParticleInfo(PType, PNum, filename): # read in the file time, total, data = Read(filename) #create an array to store indexes of particles of desired Ptype index = np.where(data['type'] == PType) # create new arrays with the m, x, y, z, # vx, vy, vz of just the Ptype desired # Add units using Astropy # Recall Mass was stored in units of Msun/1e10 mnew = data['m'][index]*1e10*u.Msun xnew = data['x'][index]*u.kpc ynew = data['y'][index]*u.kpc znew = data['z'][index]*u.kpc vxnew = data['vx'][index]*u.km/u.s vynew = data['vy'][index]*u.km/u.s vznew = data['vz'][index]*u.km/u.s # 3D position # Value is rounded to 3 decimal places. R3D = np.round(np.sqrt(xnew[PNum-1]**2 + ynew[PNum-1]**2 + znew[PNum-1]**2),3) # 3D velocity # Value is rounded to 3 decimal places. V3D = np.round(np.sqrt(vxnew[PNum-1]**2 + vynew[PNum-1]**2 + vznew[PNum-1]**2),3) # Mass # Value is rounded to 3 decimal places Mass = np.round(mnew[PNum-1],3) return R3D, V3D, Mass
def ParticleInfo(filename, ind): """ A function that provides information about requested particle. PARAMETERS filename : name of the file containing galaxy info. Type = str ind : index of the particle for which information is requested. Type = int RETURNS x, y, z : Distance of partcle from center in kpc. Type = Quantity vx, vy, vz : Velocity of particle in km/s. Type = Quantity mass : Mass of particle in solar mass. Type = Quantity """ time, N, data = Read( filename) #acquiring particle data from MW_000.txt file #collecting position information and setting correct unit (Kpc) x = data['x'][ind] * u.kpc y = data['y'][ind] * u.kpc z = data['z'][ind] * u.kpc #collecting velocity information and setting correct unit (Km/s) kms = u.km / u.s vx = data['vx'][ind] * kms vy = data['vy'][ind] * kms vz = data['vz'][ind] * kms #collecting mass information and setting correct unit (M_sun) mass = data['m'][ind] * u.M_sun return x, y, z, vx, vy, vz, mass
def ParticleInfo(filename,particletype): # read in all data time, n_particles, data = Read(filename) # save row indices of all particles of given type ind = np.where(data['type'] == ParticleTypes[particletype]) # calculate and store array of distances # also round final magnitude to 3 decimal places x = data['x'][ind] y = data['y'][ind] z = data['z'][ind] distances = np.sqrt(x**2+y**2+z**2)*u.kpc distances = np.around(distances,3) # calculate and store velocity magnitudes # round to 3 places vx = data['vx'][ind] vy = data['vy'][ind] vz = data['vz'][ind] velocities = np.sqrt(vx**2+vy**2+vz**2)*(u.km/u.s) velocities = np.around(velocities,3) # store masses, in units of solar masses # data is stored in units of 10^10 solar masses masses = data['m'][ind] masses = masses * 10**10 * u.M_sun return distances, velocities, masses
def __init__(self, galaxy, snap): # Initialize the instance of this Class with the following properties: # galaxy : string, e.g. "MW" # snap : integer, e.g 1 # determine the filename # Determine Filename # add a string of the filenumber to the value "000" ilbl = '000' + str(snap) # remove all but the last 3 digits ilbl = ilbl[-3:] # create filenames self.filename = '%s_HR_' % (galaxy) + ilbl + '.txt' #print 'reading',self.filename # read in the file self.time, self.total, self.data = Read(self.filename) # store the mass, positions, velocities of all particles self.m = self.data['m'] #*u.Msun self.x = self.data['x'] * u.kpc self.y = self.data['y'] * u.kpc self.z = self.data['z'] * u.kpc # store galaxy name self.gname = galaxy
def ComponentMass(filename, p_type): t, p, d = (Read(filename)) # use readfile function index = np.where( d['type'] == p_type) #index the file according to particle type m_comp = d['m'][index] * 1e-2 #get the numbers to look right sum_m_comp = np.sum(m_comp) #sum all components of the same index return (sum_m_comp)
def __init__(self, filename, ptype): # 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, positions, velocities of only the particles of the given type self.m = self.data['m'][self.index]
def ComponentMass(X, Ptype): # data = np.genfromtxt(X,dtype=None,names=True,skip_header=3) time, total, data = Read(X) index = np.where(data['type'] == Ptype) mass = data['m'][index] * u.M_sun / 100 TotMass = np.around(sum(mass), decimals=3) return TotMass
def ParticleInfo(filename, partype, parnumber): time, total, dat = Read(filename) #this will pull the data from the Read function #now we have to initialize the position and velocity function so they are 0 at the start and not #a random variable x = 0 y = 0 z = 0 vx = 0 vy = 0 vz = 0 #we have to define a way to pull the information from the Read file and import it into the code #to perform these tasks index = np.where(dat['type'] == partype) #now we are defining the position and velocities using this index xnew = dat['x'][index] * u.kpc ynew = dat['y'][index] * u.kpc znew = dat['z'][index] * u.kpc vxnew = dat['vx'][index] * u.km / u.s vynew = dat['vy'][index] * u.km / u.s vznew = dat['vz'][index] * u.km / u.s #now we define the components of any given particle from the data set xcomp = xnew[parnumber] ycomp = ynew[parnumber] zcomp = znew[parnumber] vxcomp = vxnew[parnumber] vycomp = vynew[parnumber] vzcomp = vznew[parnumber] #using this information we can calculate the distance and velocity of the particle in 3D d = 0 #making sure the variable is initially set to 0 for proper calculations d = np.around((xcomp**2 + ycomp**2 + zcomp**2)**0.5, 3) #the equation for distance is sqrt(x^2+y^2+z^2) #to convert from kpc to lyr print(np.around(d.to(u.lyr), 3)) #velocity is calculated the same v = 0 v = np.around((vxcomp**2 + vycomp**2 + vzcomp**2)**0.5, 3) #the mass of the particle is given, we just need to define it #the units are given in 10^10 solar masses m = dat['m'][index] * 10**10 * u.solMass mass = m[parnumber] return d, v, mass
def ParticleInfo(filename,ptype,pnum): # Inputs: # filename is the name of the text file # ptype is the number that represents the particle type (1=DarkMatter,2=DiskStars,3=BulgeStars) # pnum is the number of particle desired from a type (ex: 10th Disk particle would be pnum = 10) # Return: # distance is the magnitude of the 3D distance of the particle (kpc) # velocity is the magnitude of the 3D velocity of the particle (km/s) # mass is the mass of the particle (Msun) # Function from "ReadFile.py" used to store time, number of particles and data from the file. # Only data is needed, which stores the desired values (type, mass, distance and velocity in x,y,z) for each particle time,particlenumber,data = Read(filename) # Filter out all other types index = np.where(data['type'] == ptype) #Create a new list of values for the filtered type # Store new values of distances xnew = data['x'][index] ynew = data['y'][index] znew = data['z'][index] # Store new values of velocities vxnew = data['vx'][index] vynew = data['vy'][index] vznew = data['vz'][index] #Store new values of mass mnew = data['m'][index] # Output 0 in the case that pnum is not with in the range of the length of the new list if(index[0].size < pnum or pnum < 1): return 0, 0, 0 # Store the values from the desired particle number # Calculate magnitude of the 3D distance (kpc) # r = sqrt(x^2+y^2+z^2) # Note that if we want the 100th particle, the index in Python would be 99, hence the "pnum-1" distance = np.around(np.sqrt((xnew[pnum-1])**2 + (ynew[pnum-1])**2 + (znew[pnum-1])**2),3) * u.kpc # Calculate magnitude of 3D velocity (km/s) # vr = sqrt(vx^2+vy^2vz^2) velocity = np.around(np.sqrt((vxnew[pnum-1])**2 + (vynew[pnum-1])**2 + (vznew[pnum-1])**2),3) * u.km/u.s # Mass (Msun) mass = np.around((mnew[pnum-1] * 1e10),3) * u.solMass return distance,velocity,mass
def __init__(self, galaxy, snap): ilbl = '000' + str(snap) #FILENAME RECONSTRUCTION ilbl = ilbl[-3:] self.filename = '%s_'%(galaxy) + ilbl + '.txt' # read in the file and particle type self.time, self.total, self.data = Read(self.filename) self.gname = galaxy
def ComponentMass(filename, PType): # function to compute the mass of all particles of a given type for a given galaxy # input: filename (str) , Particle type (1,2,3) # output: Mass in units of 1e12 Msun. # read in the file time, total, data = Read(filename) # gather particles with the same type and sum up the mass # we can directly round the result and adjust the units mass = np.round(data[data['type'] == PType]['m'].sum() * 1e10 / 1e12, 3) # return the mass return mass
def ReadMass(snap, limit): #Inputs: snap -- time step we want to study M33 at # limit -- distance in kpc from the COM that defines the core of M33 # #Outputs: m -- float, total dark matter mass within limit #--------------------------------------- # Determine Filename # add a string of the filenumber to the value "000" ilbl = '000' + str(snap) # remove all but the last 3 digits ilbl = ilbl[-3:] # create filenames filename = '%s_' % ('M33') + ilbl + '.txt' path = '/home/jcalahan/HighRes/' + filename # read in the file time, total, data = Read(path) #create an array to store indexes of dark matter particles index = np.where(data['type'] == 1) # store the mass and positions of only the particles of the given type m = data['m'][index] x = data['x'][index] y = data['y'][index] z = data['z'][index] #Find COM postion of disk particles --> center of the galaxy COM = CenterOfMass(path, 2) COMP = COM.COM_P(.2, 4.0) #<--using values from HW6 #Define the time this snap is at t = time / u.Myr / 1000. #Gyr # store distances of particles from COM (array) dist = np.sqrt((x - COMP[0])**2 + (y - COMP[1])**2 + (z - COMP[2])**2) #Initilize total mass mass = 0 # 1 particle of dark matter mass (assuming all dark matter particles have the same mass) dm_mass = m[0] #if a particle is within the limit, add a dark matter mass to total mass for d in dist: if d <= limit: mass = mass + dm_mass return mass * (1e10), t
def ComponentMass(File, PType): time, total, data = Read(File) #reading the data we need from the ReadFile index = np.where( data['type'] == PType ) #creates an array to store indexes of particles of desired PType mnew = data['m'][ index] * 1e10 * u.Msun #returns mass in solar mass units of the PType # Mass value rounded to 3 decimal places Mass = np.sum(mnew) return Mass
def ComponentMass(filename,particle_type): # Inputs: # filename = name of the file to read. # particle_type = galaxy component: 1 = Halo, 2 = Disk, 3 = Bulge. # Returns: # total mass of the galaxy component. time, particles, data = Read(filename) # finding a particular particle_type. index = np.where(data['type']== particle_type) mass = data['m'][index] comp_mass = sum(mass)/1e2*u.Msun # in units of Msun/1e12. # NOTE:In the file, the mass is already in units of Msun/1e10. return np.around(comp_mass*1e12,3) #rounding off the component mass to 3 decimal places.
def __init__(self, filename, ptype): # Read data in the given file using Read self.time, self.total, self.data = Read(filename) # Create array to store indexes of particles of desired Ptype self.index = np.where(self.data['type'] == ptype) # Store the positions, velocities, and mass 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] self.vx = self.data['vx'][self.index] self.vy = self.data['vy'][self.index] self.vz = self.data['vz'][self.index] self.m = self.data['m'][self.index]
def __init__(self, filename, ptype): # 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, positions, velocities of particles self.m = self.data['m'][self.index] 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] self.position = np.column_stack([self.x, self.y, self.z]) self.velocity = np.column_stack([self.vx, self.vy, self.vz])
def ComponentMass(filename, particletype): #inputs: #particletype is the location or type or particle in the galaxy(Halo, disk, bulge) #filename is the name of the file that contains the data #returns the summed mass of all the particles of a given type in 1e12 Msun (converted from 1e10 Msun) #read in file time, total, data = Read(filename) #store indeices of a certain particle type index = np.where(data['type'] == particletype) #create a new array with the masses of each particle of the given type #mass is stored in units of 1e10 Msun mdata = data['m'][index] * 1e10 * u.Msun #get total mass mtotal = np.round(np.sum(mdata)) #perform conversion mtotal.to(1e12 * u.Msun) return mtotal
def ParticleInfo(particle_type, particle_num): #returns properties for any particle time, total, data = Read('/home/agibbs/MW_000.txt') #separate data types and particle types index = np.where(data['type'] == particle_type) x = np.around( data['x'][index] * u.kpc, 3 ) #only of particle type, keep 3 decimals, units kpc y = np.around( data['y'][index] * u.kpc, 3 ) z = np.around( data['z'][index] * u.kpc, 3 ) vx = np.around( data['vx'][index] * u.km / u.s, 3 ) vy = np.around( data['vy'][index] * u.km / u.s, 3 ) vz = np.around( data['vz'][index] * u.km / u.s, 3 ) m = data['m'][index] * 1e10 * u.Msun n = particle_num #to make the next line shorter return x[n], y[n], z[n], vx[n], vy[n], vz[n], m[n]