Main modules

Angular coordinates

Bubble Statistics

Cosmological calculators

Foreground model

Identifying regions

Lightcone

Telescope noise

Power spectrum

Primary beam

Reading simuation outputs

Smoothing

Methods to smooth or reduce resolution of the data to reduce noise.

tools21cm.smoothing.convolve_uvmap_coeval(cube, z, box_size_mpc=False, max_baseline=2.0, ratio=1.0, nu_axis=2, verbose=True, filename=None, total_int_time=6.0, int_time=10.0, declination=-30.0, uv_map=None)[source]

This smooths the coeval cube by Gaussian in angular direction and by tophat along the third axis.

Parameters:
  • coeval_cube (numpy array) – The data cube that is to be smoothed.

  • z (float) – The redshift of the coeval cube.

  • box_size_mpc (float) – The box size in Mpc. Default value is determined from the box size set for the simulation (set_sim_constants)

  • max_baseline (float) – The maximun baseline of the telescope in km. Default value is set as 2 km (SKA core).

  • ratio (int) – It is the ratio of smoothing scale in frequency direction and the angular direction (Default value: 1).

  • nu_axis (int) – Frequency axis

Returns:

Smoothed_coeval_cube

tools21cm.smoothing.gauss_kernel(size, sigma=1.0, fwhm=None)[source]

Generate a normalized gaussian kernel, defined as exp(-(x^2 + y^2)/(2sigma^2)).

Parameters:
  • size (int) – Width of output array in pixels.

  • sigma = 1.0 (float) – The sigma parameter for the Gaussian.

  • fwhm = None (float or None) – The full width at half maximum. If this parameter is given, it overrides sigma.

Returns:

numpy array with the Gaussian. The dimensions will be size x size or size x sizey depending on whether sizey is set. The Gaussian is normalized so that its integral is 1.

tools21cm.smoothing.gauss_kernel_3d(size, sigma=1.0, fwhm=None)[source]

Generate a normalized gaussian kernel, defined as exp(-(x^2 + y^2 + z^2)/(2sigma^2)).

Parameters:
  • size (int) – Width of output array in pixels.

  • sigma = 1.0 (float) – The sigma parameter for the Gaussian.

  • fwhm = None (float or None) – The full width at half maximum. If this parameter is given, it overrides sigma.

Returns:

numpy array with the Gaussian. The dimensions will be size x size x size. The Gaussian is normalized so that its integral is 1.

tools21cm.smoothing.get_beam_w(baseline, z)[source]

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

Parameters:
  • baseline (float) – the maximum baseline in meters

  • z (float) – the redshift

Returns:

The beam width in arcminutes

tools21cm.smoothing.hubble_parameter(z)[source]

It calculates the Hubble parameter at any redshift.

tools21cm.smoothing.interpolate2d(input_array, x, y, order=0)[source]

Same as interpolate2d but for 2D data

Parameters:
  • input_array (numpy array) – the array to interpolate

  • x (numpy array) – the output coordinates along the x axis expressed as (fractional) indices

  • y (numpy array) – the output coordinates along the y axis expressed as (fractional) indices

  • order (int) – the order of the spline interpolation. Default is 0 (linear interpolation). Setting order=1 gives the same results as IDL’s interpolate function

Returns:

Interpolated array with shape (nx, ny), where nx and ny are the lengths of the arrays x and y respectively.

tools21cm.smoothing.interpolate3d(input_array, x, y, z, order=0)[source]

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.

Parameters:
  • input_array (numpy array) – the array to interpolate

  • x (numpy array) – the output coordinates along the x axis expressed as (fractional) indices

  • y (numpy array) – the output coordinates along the y axis expressed as (fractional) indices

  • z (numpy array) – the output coordinates along the z axis expressed as (fractional) indices

  • order (int) – the order of the spline interpolation. Default is 0 (linear interpolation). Setting order=1 gives the same behaviour as IDL’s interpolate function with default parameters.

Returns:

Interpolated array with shape (nx, ny, nz), where nx, ny and nz are the lengths of the arrays x, y and z respectively.

tools21cm.smoothing.lanczos_kernel(size, kernel_width)[source]

Generate a 2D Lanczos kernel.

Parameters:
  • size (int) – the size of the array

  • kernel_width (int) – the width of the kernel

Returns:

The kernel as a (size,size) array

tools21cm.smoothing.smooth_coeval(cube, z, box_size_mpc=False, max_baseline=2.0, ratio=1.0, nu_axis=2, verbose=True)[source]

This smooths the coeval cube by Gaussian in angular direction and by tophat along the third axis.

Parameters:
  • coeval_cube (numpy array) – The data cube that is to be smoothed.

  • z (float) – The redshift of the coeval cube.

  • box_size_mpc (float) – The box size in Mpc. Default value is determined from the box size set for the simulation (set_sim_constants)

  • max_baseline (float) – The maximun baseline of the telescope in km. Default value is set as 2 km (SKA core).

  • ratio (int) – It is the ratio of smoothing scale in frequency direction and the angular direction (Default value: 1).

  • nu_axis (int) – Frequency axis

Returns:

Smoothed_coeval_cube

tools21cm.smoothing.smooth_coeval_gauss(cube, fwhm, nu_axis)[source]

This smooths the slices parallel to the given axis of the cube by Gaussian filter.

Parameters:
  • cube (numpy array) – The data cube that is to be smoothed.

  • fwhm (float) – The fwhm of the Gaussian filter.

  • nu_axis (int) – Frequency axis

Returns:

Smoothed_cube

tools21cm.smoothing.smooth_coeval_tophat(cube, width, nu_axis, verbose=True)[source]

This smooths the slices perpendicular to the given axis of the cube by tophat filter.

Parameters:
  • cube (numpy array) – The data cube that is to be smoothed.

  • width (float) – The width of the tophat filter.

  • nu_axis (int) – Frequency axis

Returns:

Smoothed_cube

tools21cm.smoothing.smooth_gauss(input_array, sigma=1.0, fwhm=None)[source]

Smooth the input array with a Gaussian kernel specified either by sigma (standard deviation of the Gaussian function) or FWHM (Full Width Half Maximum). The latter is more appropriate when considering the resolution of a telescope.

Parameters:
  • input_array (numpy array) – the array to smooth

  • sigma=1.0 (float) – the width of the kernel (variance)

  • fwhm = None (float or None) – The full width at half maximum. If this parameter is given, it overrides sigma.

Returns:

The smoothed array. A numpy array with the same dimensions as the input.

tools21cm.smoothing.smooth_lanczos(input_array, kernel_width)[source]

Smooth the input array with a Lanczos kernel.

Parameters:
  • input_array (numpy array) – the array to smooth

  • kernel_width (int) – the width of the kernel in cells

Returns:

The smoothed array. A numpy array with the same dimensions as the input.

tools21cm.smoothing.smooth_lightcone(lightcone, z_array, box_size_mpc=False, max_baseline=2.0, ratio=1.0)[source]

This smooths in both angular and frequency direction assuming both to be smoothed by same scale.

Parameters:
  • lightcone (numpy array) – The lightcone that is to be smoothed.

  • z_array (float) – The lowest value of the redshift in the lightcone or the whole redshift array.

  • box_size_mpc (float) – The box size in Mpc. Default value is determined from the box size set for the simulation (set_sim_constants)

  • max_baseline (float) – The maximun baseline of the telescope in km. Default value is set as 2 km (SKA core).

  • ratio (int) – It is the ratio of smoothing scale in frequency direction and the angular direction (Default value: 1).

Returns:

(Smoothed_lightcone, redshifts)

tools21cm.smoothing.smooth_lightcone_gauss(lightcone, fwhm, nu_axis=2)[source]

This smooths the slices perpendicular to the third axis of the lightcone by tophat filter.

Parameters:
  • lightcone (numpy array) – The lightcone that is to be smoothed.

  • fwhm (numpy array) – The fwhm values of the Gaussian filter at each slice along frequency axis.

  • nu_axis (int) – frequency axis

Returns:

Smoothed_lightcone

tools21cm.smoothing.smooth_lightcone_tophat(lightcone, redshifts, dz, verbose=True)[source]

This smooths the slices perpendicular to the third axis of the lightcone by tophat filter.

Parameters:
  • lightcone (numpy array) – The lightcone that is to be smoothed.

  • redshifts (numpy array) – The redshift of each slice along the third axis.

  • dz (float) – redshift width

Returns:

Smoothed_lightcone

tools21cm.smoothing.smooth_lightcone_uv_threshold(lightcone, uv_box, threshold=0.0)[source]

Smoothing (de-noising) the lightcone by removing noisy UV cells below threshold.

Beware, if maximal baseline is to be set, one should clean the uv_box beforehand.

Parameters:
  • lightcone (numpy array) – The lightcone to be smoothed.

  • uv_box (numpy array) – The UV box.

  • threshold (float) – The threshold below which UV cells are removed.

Returns:

Smoothed lightcone.

tools21cm.smoothing.smooth_tophat(input_array, tophat_width)[source]

Smooth the input array with a square tophat kernel.

Parameters:
  • input_array (numpy array) – the array to smooth

  • tophat_width (int) – the width of the kernel in cells

Returns:

The smoothed array. A numpy array with the same dimensions as the input.

tools21cm.smoothing.smooth_with_kernel(input_array, kernel)[source]

Smooth the input array with an arbitrary kernel.

Parameters:
  • input_array (numpy array) – the array to smooth

  • kernel (numpy array) – the smoothing kernel. Must be the same size as the input array

Returns:

The smoothed array. A numpy array with the same dimensions as the input.

tools21cm.smoothing.tophat_kernel(size, tophat_width)[source]

Generate a square tophat kernel

Parameters:
  • size (int) – the size of the array

  • tophat_width (int) – the size of the tophat kernel

Returns:

The kernel as a (size,size) array

tools21cm.smoothing.tophat_kernel_3d(size, tophat_width, shape='cube')[source]

Generate a 3-dimensional tophat kernel with the specified size

Parameters:
  • size (integer or list-like) – the size of the tophat kernel along each dimension.

  • tophat_width (int) – the size of the tophat kernel

  • shape (string) – “cube”: cubic tophat; “sphere”: spherical tophat

Returns:

The normalized kernel

Point statistics

Temperature

Topology