Calculate the differential brightness temperature assuming T_s >> T_CMB
Calculate the differential brightness temperature assuming T_s >> T_CMB for lightcone data.
fraction file (must be cbin), or the xfrac lightcone data
file (must be cbin), or the density data
lowest_z (float): the lowest redshift of the lightcone volume
los_axis = 2 (int): the line-of-sight axis
Get the mean dT at redshift z
Apply a function, such as np.var() or np.mean(), along the line-of-sight axis of a signal on a per-slice basis.
Calculate the variance of a lightcone along the line-of-sight:
>>> lightcone = c2t.read_cbin('my_lightcone.cbin')
>>> dT_var = c2t.apply_func_along_los(lightcone, np.var, 2)
Calculate the mass-weighted mean ionization fraction.
Divide by the mean of the signal along the los axis and subtract one.
TODO:vectorize
Calculate the skewness of an array. Note that IDL calculates the skewness in a slightly different way than Python. This routine uses the IDL definition.
Subtract the mean of the signal along the los axis.
TODO:vectorize
Calculate the optical depth to Thomson scattering.
in various points along the line-of-sight.
the same points as ionfractions. Must be the same length as ionfractions
num_points = 50 (integer): the number of points used for the integration
Tuple containing (tau_0, tau_z)
tau_0 is the optical depth at each redshift
tau_z is the corresponding redshift
To calculate the optical depth for a scenario where the Universe is instantaneously reionized:
>>> z_reion = 11.
>>> redshifts = np.linspace(z_reion, 1100., 50)
>>> ionfracs = np.zeros(len(redshifts))
>>> tau0, tau_z = tau(ionfracs, redshifts)
>>> print 'Total tau: ', tau0[-1]
0.0884755058758
Calculate the spherically averaged cross power spectrum of two arrays and return it as a one-dimensional array.
input_array1_nd (numpy array): the first data array
input_array2_nd (numpy array): the second data array
or a list containing the bin edges. If an integer is given, the bins are logarithmically spaced.
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
number of modes in each bin
Calculate the cross power spectrum and bin it in mu=cos(theta) and k input_array is the array to calculate the power spectrum from
input_array1 (numpy array): the first data array
input_array2 (numpy array): the second data array
los_axis = 0 (integer): the line-of-sight axis
mubins = 20 (integer): the number of mu bins
or a list containing the bin edges. If an integer is given, the bins are logarithmically spaced.
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
of k equal to zero will be excluded.
Calculate the cross power spectrum two arrays and return it as an n-dimensional array, where n is the number of dimensions in input_array box_side is the size of the box in comoving Mpc. If this is set to None (default), the internal box size is used
power spectrum of. Can be of any dimensions.
dimensions as input_array1.
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
This function is for internal use only.
Calculate the spherically averaged power spectrum of an array and return it as a one-dimensional array.
input_array_nd (numpy array): the data array
or a list containing the bin edges. If an integer is given, the bins are logarithmically spaced.
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
number of modes in each bin
Calculate the power spectrum and bin it in mu=cos(theta) and k input_array is the array to calculate the power spectrum from
input_array (numpy array): the data array
los_axis = 0 (integer): the line-of-sight axis
mubins = 20 (integer): the number of mu bins
or a list containing the bin edges. If an integer is given, the bins are logarithmically spaced.
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
of k equal to zero will be excluded.
Calculate the power spectrum of input_array and return it as an n-dimensional array, where n is the number of dimensions in input_array box_side is the size of the box in comoving Mpc. If this is set to None (default), the internal box size is used
power spectrum of. Can be of any dimensions.
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
Radially average data. Mostly for internal use.
input_array (numpy array): the data array
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
or a list containing the bin edges. If an integer is given, the bins are logarithmically spaced.
Calculate the power spectrum of an array and expand it in the first three Legendre polynomials.
power spectrum of. Can be of any dimensions.
or a list containing the bin edges. If an integer is given, the bins are logarithmically spaced.
box. If this is None, the current box volume is used along all dimensions. If it is a float, this is taken as the box length along all dimensions. If it is an array-like, the elements are taken as the box length along each axis.
los_axis = 0 (integer): the line-of-sight axis
include in the output. For example, to get only the P2 moment, pass in [‘P2’]. Can also contain ‘nmodes’ to return the number of Fourier modes per bin
of k equal to zero will be excluded.
Apply peculiar velocity distortions to a differential temperature box, using the Mesh-Particle-Mesh method, as described in http://arxiv.org/abs/1303.5627
dT (numpy array): the differential temperature box
(3,mx,my,mz) where (mx,my,mz) is dimensions of dT
redsh (float): the redshift
(must be 0, 1 or 2)
velocity_axis = 0 (int): the index that indicates los velocity
A higher number gives better accuracy, but worse performance.
conditions along the line-of-sight. If you are making a lightcone volume, this should be False.
Read a density file, a velocity file and an xfrac file, calculate the brightness temperature, and convert it to redshift space.
>>> vfile = c2t.VelocityFile('/path/to/data/8.515v_all.dat')
>>> dfile = c2t.DensityFile('/path/to/data/8.515n_all.dat')
>>> xfile = c2t.XfracFile('/path/to/data/xfrac3d_8.515.bin')
>>> dT = c2t.calc_dt(xfile, dfile)
>>> kms = vfile.get_kms_from_density(dfile)
>>> dT_zspace = get_distorted_dt(dT, kms, dfile.z, los_axis = 0)
Note
At the moment, it is a requirement that dimensions perpendicular to the line-of-sight are equal. For example, if the box dimensions are (mx, my, mz) and the line-of-sight is along the z axis, then mx has to be equal to my.
Note
If dT is a lightcone volume, los_axis is not necessarily the same as velocity_axis. The lightcone volume methods in c2raytools all give output volumes that have the line-of-sight as the last index, regardless of the line-of-sight axis. For these volumes, you should always use los_axis=2 and set velocity_axis equal to whatever was used when producing the real-space lightcones.
Convenience method to read files and make a distorted box.
dT_filename (string): the name of the dT file
vel_filename (string): the name of the velocity file
dens_filename (string): the name of the density file
z (float): the redshift
los (integer): the line-of-sight axis
to get_distorted_dt
Extract a subvolume from a lightcone, at a given central redshift, and with a given depth. The depth can be specified in Mpc or MHz. You must give exactly one of these parameters.
ligthcone (numpy array): the lightcone
redshifts (numpy array): the redshifts along the LOS
central_z (float): the central redshift of the subvolume
depth_mhz (float): the depth of the subvolume in MHz
depth_mpc (float): the depth of the subvolume in Mpc
be an odd number of cells. This avoids problems with power spectrum calculations.
subtract_mean (bool): if true, subtract the mean of the signal
fov_Mpc (float): the FoV size in Mpc
Make a lightcone from xfrac, density or dT data. Replaces freq_box.
Can be either any of the following:
- An array with the file names
- A text file containing the file names
- The directory containing the files (must only contain
one type of files)
lowest-z coeval cube is used.
highest-z coeval cube is used.
Can be any of the following types:
the number of bits.
the order of the data.
los_axis (int): the axis to use as line-of-sight for the coeval cubes
density file, the raw (simulation units) density will be returned instead of the density in cgs units
‘step_cell’. Determines how slices in between output redshifts are interpolated.
(lightcone, z) tuple
lightcone is the lightcone volume where the first two axes have the same size as the input cubes
z is an array containing the redshifts along the line-of-sight
Note
If z_low is given, that redshift will be the lowest one included, even if there is no coeval box at exactly that redshift. This can give results that are subtly different from results calculated with the old freq_box routine.
Make a lightcone from velocity data. Since velocity files contain momentum rather than actual velocity, you must specify filenames for both velocity and density.
Can be any of the following:
- An array with the file names
- A text file containing the file names
- The directory containing the files (must only contain
one type of files)
Same format as vel_filenames.
lowest-z coeval cube is used.
highest-z coeval cube is used.
Can be any of the following types:
los_axis (int): the axis to use as line-of-sight for the coeval cubes
(lightcone, z) tuple
lightcone is the lightcone volume where the first two axes have the same size as the input cubes
z is an array containing the redshifts along the line-of-sight
Make a frequency axis vector with equal spacing in co-moving LOS coordinates. The comoving distance between each frequency will be the same as the cell size of the box.
set to conv.LB
Created on Sep 17, 2014
@author: Hannes Jensen
Methods to convert data between physical (cMpc) coordinates and observational (angular-frequency) coordinates
Interpolate a slice in angular coordinates to physical
Bin a lightcone in frequency bins.
Bin a lightcone in Mpc slices along the LoS
Interpolate a lightcone volume measured in observational (angle/frequency) units into physical (length) units. The output resolution will be set to the coarest one, as determined either by the angular or the frequency resolution. The lightcone must have the LoS as the last index, with frequencies decreasing along the LoS.
observational_lightcone (numpy array): the input lightcone volume
line of sight of the input
input_dheta (float): the angular size of a cell in arcmin
Interpolate a lightcone volume from physical (length) units to observational (angle/frequency) units.
physical_lightcone (numpy array): the lightcone volume
input_z_low (float): the lowest redshift of the input lightcone
output_dnu (float): the frequency resolution of the output volume in MHz
output_dtheta (float): the angular resolution of the output in arcmin
If None (default), this will be set to conv.LB
Interpolate a slice in physical coordinates to angular coordinates.
input_slice (numpy array): the 2D slice in physical coordinates
z (float): the redshift of the input slice
slice_size_Mpc (float): the size of the input slice in cMpc
padded to match this size
dtheta (float): the target resolution in arcmin
Resample a 2D slice to new dimensions.
Calculate the angular size of an object at a given redshift.
Calculate the angular size in degrees of an object with a given comoving size.
Convert comoving distance to proper distance
Calculate the redshift correspoding to the given redshift.
redshift corresponding to the distance.
Note
Uses a precalculated table for interpolation. Only valid for 0 < z < 100
Calculate the size in cMpc of an object with given angular diameter.
Calculate the luminosity distance for a given redshift.
Calculate the comoving distance to a given 21 cm frequency
Convert frequency to wavelength
Convert 21 cm frequency in MHz to redshift
Convert proper distance to comoving distance
Calculate the comoving distance
Get the 21 cm frequency that corresponds to redshift z
Convolve input_array with a beam of the specified form. The beam can be specified either by a width in arcminutes, or as a maximum baseline. You must specify exctly one of these parameters.
input_array (numpy array): the array to be convolved
z (float): the redshift of the map
fov_mpc (float): the field of view in cMpc
beam_w (float) = None: the width of the beam in arcminutes
(can be specified instead of beam_w)
(only ‘gaussian’ supported at this time)
Generate a normalized gaussian kernel, defined as exp(-(x^2 + y^2)/(2sigma^2)).
size (int): Width of output array in pixels.
sigma = 1.0 (float): The sigma parameter for the Gaussian.
If this parameter is given, it overrides sigma.
Calculate the width of the beam for an interferometer with a given maximum baseline. It is assumed that observations are done at lambda = 21*(1+z) cm
Same as interpolate2d but for 2D data
input_array (numpy array): the array to interpolate
expressed as (fractional) indices
expressed as (fractional) indices
is 0 (linear interpolation). Setting order=1 gives the same results as IDL’s interpolate function
This function is a recreation of IDL’s interpolate routine. It takes an input array, and interpolates it to a new size, which can be irregularly spaced.
input_array (numpy array): the array to interpolate
expressed as (fractional) indices
expressed as (fractional) indices
expressed as (fractional) indices
is 0 (linear interpolation). Setting order=1 gives the same behaviour as IDL’s interpolate function with default parameters.
Generate a 2D Lanczos kernel.
Smooth the input array with a Gaussian kernel.
Smooth the input array with a Lanczos kernel.
Smooth the input array with a square tophat kernel.
Smooth the input array with an arbitrary kernel.
input_array (numpy array): the array to smooth
be the same size as the input array
Generate a square tophat kernel
Generate a 3-dimensional tophat kernel with the specified size
the tophat kernel along each dimension. If size is an integer, the kernel will be cubic.
Created on Apr 23, 2015
@author: Hannes Jensen
Generate a Gaussian random field with the specified power spectrum.
of cells. Can be 2D or 3D.
in cMpc.
spherically-averaged power spectrum of the output. Given as a function of k
random_seed (int): the seed for the random number generation
Generate a Gaussian random field with the same power spectrum as the input field.
from
box_dims (float or tuple): The dimensions of the input_field in cMpc
random_seed (int): the seed for the random number generation
Note
This function is experimental. There are often interpolation issues at low k. Use with care.