FlatSkyLab package

flatsky.py

flatsky.py

Contains necessary function for performing flatsky analysis and generating correlated Gaussian realisations across different bands.

flatsky.apod_mask(x_grid, y_grid, mask_radius, perform_apod=True, mask_shape='circle', taper_radius_fac=6.0)

Interpolating a 1d power spectrum (cl) defined on multipoles (el) to 2D assuming azimuthal symmetry (i.e:) isotropy.

Parameters:
  • x_grid (array) – x grid of the map (like ra).

  • y_grid (array) – y grid of the map (like dec).

  • mask_radius (float) – mask radius in same units as x_grid and y_grid

  • perform_apod (boolean) – Apodise the binary mask. Default is True.

  • mask_shape (str) – circle or a square mask. default is circle. Must be on of [‘circle’, ‘square’]

  • taper_radius_fac (float) – radius for apodisation. taper_radius = taper_radius_fac * mask_radius. default is 6 (FIX ME: which works well but need to be explored further).

Returns:

mask – binary or apodised mask.

Return type:

array, shape is x_grid.shape.

flatsky.cl_to_cl2d(el, cl, map_shape, pixel_res_radians, left=0.0, right=0.0)

Interpolating a 1d power spectrum (cl) defined on multipoles (el) to 2D assuming azimuthal symmetry (i.e:) isotropy.

Parameters:
  • el (array) – Multipoles over which the power spectrium is defined.

  • cl (array) – 1d power spectrum that needs to be interpolated on the 2D grid.

  • map_shape (array_like, shape (2 x 1)) – dimension on the flatskymap.

  • pixel_res_radians (float) – map pixel resolution in radians.

  • left (float) – value to be used for interpolation outside of the range (lower side). default is zero.

  • right (float) – value to be used for interpolation outside of the range (higher side). default is zero.

Returns:

cl2d – interpolated power spectrum on the 2D grid.

Return type:

array, shape is map_shape.

flatsky.get_fourier_filters(map_shape, pixel_res_radians, l1_cutoff, l2_cutoff=None, filter_type='lpf')

get_fourier_filters module - Get Fourier space filters. Supports low-pass, high-pass, and band-pass filters.

Parameters:
  • map_shape (array_like, shape (2 x 1)) – dimension on the flatskymap.

  • pixel_res_radians (float) – map pixel resolution in radians.

  • l1_cutoff (int) – First ell cutoff for the filter. LPF –> modes ell<l1_cutoff will be retained. HPF –> modes ell>l1_cutoff will be retained.

  • l2_cutoff (int) – Second ell cutoff for the filter. Used for band pass filter. BPF –> Modes ell in [l1_cutoff, l2_cutoff] will be retained.

  • filter_type (str) – ‘lpf’: Low-pass filter. ‘hpf’: High-pass filter. ‘bpf’: Band-pass filter. Default is lpf.

Returns:

fft_filter – 2D Fourier filter.

Return type:

array.

flatsky.get_lxly(map_shape, pixel_res_radians)

return lx, ly modes (kx, ky Fourier modes) for a flatsky map grid.

Parameters:
  • map_shape (array_like, shape (2 x 1)) – dimension on the flatskymap.

  • pixel_res_radians (float) – map pixel resolution in radians.

Returns:

lx, ly

Return type:

array, shape is map_shape.

flatsky.get_wiener_filter(map_shape, pixel_res_radians, cl_signal, cl_noise, el=None, return_2D=True)

get_wiener_filter module - Get the Wiener filter.

Parameters:
  • map_shape (array_like, shape (2 x 1)) – dimension on the flatskymap.

  • pixel_res_radians (float) – map pixel resolution in radians.

  • cl_signal (array) – Signal power spectrum.

  • cl_noise (array) – Noise power spectrum.

  • el (array) – Multipoles over which the signal and noise spectra are defined. Default is None and will be calculated as arange(len(cl_signal))

  • return_2D (Bool) – Return the Wiener filter either in 1d or 2D. Default is True.

Returns:

wiener_filter – 1d or 2D Fourier-space Wiener filter.

Return type:

array.

flatsky.make_gaussian_realisations(el, cl_dict, sim_shape, pixel_res_radians_or_inv_samp_freq)

return (correlated) Gaussian realisations of flat sky maps with an underlying power spectrum defined by cl_dict.

Parameters:
  • el (array) – Multipoles over which the power spectrium is defined.

  • cl_dict (dictionary) – Contains the auto- and cross-power spectra of multiple bands. Keys are simple band incides. Keys must be 00, 11, 01 for 2 maps; Keys must be 00, 11, 22, 01, 02, 12 for 3 maps; and so on where 00 - 90x90 auto. 11 - 150x150 auto. 22 - 220x220 auto. 01 - 90x150 cross. 02 - 90x220 cross. 12 - 150x220 cross.

  • sim_shape (array_like, shape (N x 1)) – dimension of the sims.

  • pixel_res_radians_or_inv_samp_freq (float) – map pixel resolution in radians or inv tod sampling frequency

Returns:

sim_arr – Correlated simulated maps. returns N maps for N(N+1)/2 spectra.

Return type:

array

flatsky.map2cl(map_shape, pixel_res_radians, flatskymap1, flatskymap2=None, minbin=0, maxbin=10000, binsize=100, mask=None, filter_2d=None, ell_bins=None, return_2D=False)

map2cl module - get the power spectra of map/maps

Parameters:
  • map_shape (array_like, shape (2 x 1)) – dimension on the flatskymap.

  • pixel_res_radians (float) – map pixel resolution in radians.

  • flatskymap1 (array) – flatsky map for power spectrum calculation. Computes the auto-power spectrum is flatskymap2 is None. else computes the cross-power spectrium for flatskymap1 and flatskymap2.

  • flatskymap2 (array) – flatsky map 2 for cross-power spectrum calculation. default is None

  • minbin (int) – mininum scale for power spectrum calculation. default is ell_min = 0

  • maxbin (int) – maximum scale for power spectrum calculation. default is ell_max = 15000

  • binsize (int) – binning factor. default is Delta_ell = 100

  • mask (array) – (Apodisation) mask for the maps for power spectrum calculations. Assumes that the mask is already applied to the mask. Default is None.

  • filter_2d (array) – Filter transfer function that has information about the modes that are filtered. Default is None.

  • ell_bins (array) – Custom multipoles for averaging the power spectra.

  • return_2D (bool) – If True, return the 2D PSD. Default is False.

Returns:

  • el (array.) – Multipoles (scales) over which the power spectrum is defined.

  • cl (array.) – 2D PSD or 1d azimuthally averaged (binned) equivalent of FFT( abs(map)^2 ).

flatsky.radial_profile(z, xy=None, minbin=0.0, maxbin=10.0, binsize=1.0, get_errors=False, radial_bins=None)

get the radial profile of an image (both real and fourier space). Can be used to compute radial profile of stacked profiles or 2D power spectrum.

Parameters:
  • z (array) – image to get the radial profile.

  • xy (array) – x and y grid. Same shape as the image z. Default is None. If None, x, y = np.indices(image.shape)

  • minbin (float) – minimum bin for radial profile default is 0.

  • maxbin (float) – minimum bin for radial profile default is 10.

  • binsize (float) – radial binning factor. default is 1.

  • get_errors (bool) – obtain scatter in each bin. This is not the error due to variance. Just the sample variance. Default is False.

  • radial_bins (None) – Supply your own radial bins for radial averaging.

Returns:

radprf – Array with three elements cotaining radprf[:,0] = radial bins radprf[:,1] = radial binned values if get_errors: radprf[:,2] = radial bin errors.

Return type:

array.

tod_tools.py

tod_tools.py Contains necessary function for performing TOD simulations.

tod_tools.detector_noise_model(noise_level, fknee, alphaknee, total_samples, sample_freq)

TOD noise model (1/f, white noise, and total).

\[P(f) = A^2 \left[ 1+ \left( \frac{f_{\rm knee}}{f}\right)^{\alpha_{\rm knee}} \right].\]
Parameters:
  • noise_level (float) – White noise level (A in the above equation) for the detector.

  • fknee (float) – Knee frequency for 1/f (f_knee in the above equation).

  • alphaknee (float) – Slope for 1/f (alpha_knee in the above equation).

  • total_samples (int) – Total TOD samples.

  • sample_freq (float) – Sampling frequency of the TOD.

Returns:

  • freq (array) – TOD frequencies length = total_samples

  • noise_powspec (array) – Noise power spectrum.

  • noise_powspec_one_over_f (array) – 1/f portion of the noise power spectrum.

  • noise_powspec_white (array) – White noise portion of the noise power spectrum.

tod_tools.get_correlated_powspec(rho, powspec1, powespec2)

Returns correalted noise given rho and the auto-power spectrum of two detectors.

\[P_{ij} = \rho_{ij} \sqrt{P_{ii} P_{jj}}\]
Parameters:
  • rho (float) – Correlation coefficient (rho_ij).

  • powspec1 (array) – Power spectrum 1 (P_ii).

  • powspec2 (array) – Power spectrum 2 (P_jj).

Returns:

corr_powspec – Cross-power spectrum.

Return type:

array