Skip to content

ioodderskov/VelocityField

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The main program is found in hubble.py. 
Parameters are read from parameterfiles using yaml.

An outline of what is done at different steps during the program:

1) Read parameterfile, save relevant parameters for use throughout the program
2) Read either snapshot or halo catalogue, and save the particles/halos.  
3) (Option, if use_HOD) Identify galaxies in the halos, and save to parameters.galaxies
	3.1) Find central galaxies
		3.1.1) For each halo:
			3.1.1.2) (Either) If dist_central_galaxies > 0.5 for a halo of this mass:
				3.1.1.2.1) Set the galaxy position to the halo position
				3.1.1.2.2) Calculate the central galaxy velocity dispersion
				         (as alpha_c times the particle velocity dispersion in the halo)
				3.1.1.2.3) Calculate the difference between the halo and the galaxy velocity by pulling a number from a Laplace dist
				3.1.1.2.4) Calculate the galaxy velocity by adding the difference to the halo velocity
				3.1.1.2.5) Set the host ID for the galaxy to the halo ID
				3.1.1.2.6) Create an instance of the Galaxy class, and add it to central_galaxies
			3.1.1.3) (Or) If dist_central_galaxies < 0.5 for a halo of this mass: Print that there is no central galaxy
	3.2) Identify satellite galaxies as specific particles in the halos
		3.2.1) Find out which halos are listed in which particle files
			3.2.1.1) For each particle files (parameters.particle_files):
				3.2.1.1.1) Skip 24 lines (header)
				3.2.1.1.2) Read the 25th line (first halo in file, if there are any at all)
				3.2.1.1.3) While the second letter of the current line isn't P ('#Particle table begins here:'):
					3.2.1.1.3.1) Read the halo ID
					3.2.1.1.3.2) Find the halo (in parameters.halos) corresponding to this ID
					3.2.1.1.3.3) (Either) If no halo has this ID: Print that there are found particles without any halo
					3.2.1.1.3.4) (Or) If exactly one halo has this ID:
						3.2.1.1.3.4.1) Save the number of particles to the halo instance
						3.2.1.1.3.4.2) Save the name of the particle file to the halo instance
					3.2.1.1.3.5) (Or) If more than one halo has this ID: Print that there are non-unique halo IDs
					3.2.1.1.3.6) Continue with the next line
		3.2.2) Find the satellites from the particle files
			3.2.2.1) For each particle file:
				3.2.2.1.1) Find the halos whos particles are listed in the given file
				3.2.2.1.2) If there are any halos in the file:
					3.2.2.1.2.1) Choose galaxies in the halos in the file
						3.2.2.1.2.1.1) Get the name of the particle file as the particle file for the first halo
						3.2.2.1.2.1.2) Sort the halos in the file by their IDs
						3.2.2.1.2.1.3) For each halo in the sorted list:
							3.2.2.1.2.1.3.1) Get the mean number of satellites for this halo mass from dist_satellites
							3.2.2.1.2.1.3.2) Choose the number of satellites from a Poisson dist with this mean
							3.2.2.1.2.1.3.3) Choose which of the particles get to be satellites
							3.2.2.1.2.1.3.4) Sort the particles numbers
							3.2.2.1.2.1.3.5) For each satellite number:
								3.2.2.1.2.1.3.5.1) Read the corresponding line in the particle file
								3.2.2.1.2.1.3.5.2) Assert that the host ID correspond to the ID of the halo
								3.2.2.1.2.1.3.5.3) Get the position of the particle
								3.2.2.1.2.1.3.5.4) Get the velocities of the particle and the halo
								3.2.2.1.2.1.3.5.5) Calculate the galaxy velocity from these and the 
										   satellite velocity bias
								3.2.2.1.2.1.3.5.6) Create an instance of the galaxy class, and add it to
										   the satellites in this file
							3.2.2.1.2.1.3.6) Move to the next halo in the file
							3.2.2.1.2.1.3.7) Return all the satellites found in the file
					3.2.2.1.2.2) If any galaxies are chosen: Add these to the satellite galaxies
	3.3) Save the central and satellite galaxies to parameters.galaxies
4) (Option) Assign density and velocity values to a grid
	4.1) Calculate tsc (triangular shaped cloud) positions and densities
		4.1.1) ...
	4.2) Get the positions and densities on a grid
	4.3) (Option) Get the halo velocities, and interpolate the velocities to the grid
             Note: If this option is not chosen, the velocities on the grid will be set to zero
		4.3.1) For the x,y and z components of the velocities: Calculate ngp (nearest grid point) velocities on the grid
			4.3.1.1) Create a Ng**3-grid
			4.3.1.2) Calculate the cell-size of the grid
           		4.3.1.3) For each velocity, find the nearest gridpoint
			4.3.1.4) For each gridpoint, calculate the mean of all the assigned velocities
		4.3.2) (Option: if parameters.smoothing) Smooth the velocities on the grid
			4.3.2.1) Calculate the cellsize of the grid
			4.3.2.2) Calculate the smoothing radius (parameters.smoothing_radius) in cellsize-units
			4.3.2.3) Set the kernel resolution to 3 
				(that means that only the 8 nearest neighbour cells are used. See astropy_make_kernel.py) 
			4.3.2.3) Create the smoothing kernel (see astropy_make_kernel.py)
			4.3.2.4) While there are any nan-values in the smoothed grid:
				4.3.2.4.1) Convolve the x,y and z grid-values with the smoothing kernel.
		4.3.3) Return either the pure npg or the smoothed ngp values of the velocities on the grid
	4.4) Write the positions, densities and velocities on the grid to a file
			
5) Select the observers
	5.1) ...
6) (Option) Read snapshot, if you need this for the background mass distribution

Observe and analyse (can be done in parallel or on a single processor):
	This branches out in two directions (the lightcone option is actually chosen later, I think).
	You need to choose either 7 or 8:

7) (Either) (Pairwise velocities) For each observer, calculate the distances and relative radial velocities for a subset of the other halos
	7.1) ...
	
8) (Or) Make observations for each observer:
	8.1) (Option) Read in the lightcone halo catalogues for the given observer, and save the halos it contains
	8.2) For each halo in the halo catalogue:
		8.2.1) Calculate the position relative to the observer with periodic boundary conditions
		8.2.2) Calculate the coresponding spherical coordinates
		8.2.3) (Option) Save the halo, if it is within the radius of the local group
		8.2.4) (Option) Save the halo position and mass in a "survey", to be used to correct the peculiar velocities
		8.2.5) Check if the halo is in the distance range between mind and maxd. Otherwise, continue
		8.2.6) Check if the halo is within the observered fraction of the sky 
		8.2.7) Calculate the radial part of the peculiar velocity of the halo
 		8.2.8) Calculate the total radial (peculiar + Hubble) velocity of the halo
		8.2.9) Save the ID, mass, position, and (total) peculiar velocity as an "Observed_halo"
		8.2.10) Choose the halos you want to save from the "observed_halos"
			8.2.10.1) (Either) Use all the observed halos. 
				  NB: This is what you should choose of you want to make the "observations" on a grid! 
			8.2.10.2) (Or) Use a simple mass-weighted selection of of halos (number given in the parameter file)
			8.2.10.3) (Or) Use a random selection of halos (number given in the parameter file)
			8.2.10.4) (Or) Use only halos in a mass range specified in the parameter file
			8.2.10.5) (Or) Find the most massive of the observed halos, and keep halos in a sphere (radius specified in the
				  parameter file) around this halo
		8.2.11) (Option) From the chosen halos, calculate the center of mass position and velocity, and replace the chosen halos
			with the CoM values.
			8.2.11.1)
		8.2.12) (Option) Recalculate the distance to the chosen halos using the perturbed metric
		8.2.13) (Option) Correct for the peculiar velocities calculated from the matter distribution
			8.2.13.1) (Option) Calculate the matter distribution from the snapshot
			8.2.13.2) For each of the chosen halos:
				8.2.13.2.1) Calculate the velocity correction from the matter distribution
				8.2.13.2.2) Save the observed velocity and the velocity correction
				8.2.13.2.3) Replace the velocity of the chosen halo with the corrected velocity
			8.2.13.3) (Option) Plot the velocity field around the first observers.
		8.2.14) (Option) Correct the velocity of the local group for the peculiar velocities calculated from the matter distribution
			...
		8.2.15) Save the chosen_halos to this observer (that is, to this particular instance of the observer class)


These can only be performed if you have chosen 8:
9) (Option) Calculate Hubble constants for each observer:
	9.1) Check if there are any chosen halos for this observer. Otherwise print nans to hubblefile.
	9.2) (Option) Calculate the Hubbleconstants for varying directions
	9.3) (Option) Calculate the Hubbleconstants for varying skyfractions
	9.4) (Option) Calculate the Hubbleconstants for varying number of chosen halos
	9.5) (If non of the above) Calculate the Hubbleconstants with the chosen halos saved to the observer
10) (Option) Calculate Power spectrum for each observer:
	10.1) Save the angular coordinates (theta and phi) together with the radial parts of the peculiar velocities for the chosen halos
	10.2) Create a map of these velocities
		10.2.1) Find the pixels corresponding to the coordinates, with the value of nside given in the parameterfile
		10.2.2) Create a template map, with all pixel values set to "badval"
		10.2.3) For the pixels with multiple values, set the value to the mean
		10.2.4) Calculate the maximal value of theta for the given skyfraction
		10.2.5) Set the value of the pixels with a larger theta than theta_max to "unseen"
		10.2.6) Count how many pixels has a value of either "badval" or "unseen", and print the result
	10.3) Fill the empty cells in the map
		10.3.1) As long there are any pixels with the value "badval":
			10.3.2) For each pixel with the value "badval":
				10.3.2.1) Calculate the angular coordinates of the pixel
				10.3.2.2) Find all the neighbours to this pixel
				10.3.2.3) Throw away the pixels with a value of "badval" or "unseen"
				10.3.2.4) Check if there are still some neighbours left. Otherwise, continue
				10.3.2.5) Set the new value of the pixel to be the mean of the values of the neighbours
	10.4) DISABLED (Option) Smooth the map 
		10.4.1) (Either) Set the smoothing length to some value given in the parameter file
		10.4.2) (Or) Dertermine the size of the largest hole in the skycoverage
			10.4.2.1) ...
		10.4.3) Perform the smooth of the map
	10.5) Perform a harmonic analysis of the map
		10.5.1) Use the healpy "ma"-function (mask) to create a masked map, with the mask being set to the unseen pixels in the map
		10.5.2) Use the healpy "anafast"-function to calculate the Cls coefficients of the masked map
		10.5.3) Use sp.arange to get the corresponding ls
	10.6) Save the ls, Cls and the map to this observer

11) (Option) Print the Hubbleconstants to file
12) (Option) Print the powerspektra to file
13) (Option) Collect pairwise velocities
14) (If there are not too many observers) Save the observers to an npy-file
15) (Option) Calculate the correlation coefficients between the observed velocities and the velocities calculated from the matter dist.



About

Code for analysing the peculiar velocities of halos from snapshots

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published