Full Class List

Parameter Parsing

Parameter parsing of command line arguments and/or configuration files.

class bayeseor.params.BayesEoRParser

Class used to parse command line arguments.

For more information on the command line syntax, please see

python run-analysis.py --help
useGPU

Use GPUs (’–gpu’, True) or CPUs (’–cpu’, False). Defaults to True (use GPUs).

Type:

bool, optional

single_node

Run an analysis on a single node or with an MPI size of 1. Defaults to False (do not run an analysis if MPI size is 1).

Type:

bool, optional

array_dir_prefix

Directory for matrix storage. Defaults to ‘./array-storage’.

Type:

str, optional

sparse_mats

Use sparse matrices (’–sparse-mats’, True) to reduce storage requirements or dense matrices (’–dense-mats’, False). Defaults to True (use sparse matrices).

Type:

bool, optional

overwrite_matrices

Overwrite existing matrix stack. Defaults to False (use existing matrix stack).

Type:

bool, optional

log_priors

Assume priors on power spectrum coefficients are in log_10 units (’–log-priors’, True) or linear units (’–lin-priors’, False). Defaults to True.

Type:

bool, optional

uprior_bins

Array indices of k-bins using a uniform prior. All other bins use the default log-uniform prior. Follows python slicing syntax. Can pass a range via ‘1:4’ (non-inclusive high end), a list of indices via ‘1,4,6’ (no spaces between commas), a single index ‘3’ or ‘-3’, or ‘all’. Defaults to an empty string (all k-bins use log-uniform priors).

Type:

str, optional

output_dir

Directory for sampler output. Defaults to ‘./chains/’.

Type:

str, optional

file_root

If None (default), start a new analysis. Otherwise, resume analysis from file_root.

Type:

str, optional

use_Multinest

Use MultiNest (’–multinest’, True) or Polychord (’–polychord’, False) as the sampler. Defaults to True (use MultiNest). Using Polychord is advised for large parameter spaces.

Type:

bool, optional

verbose

Print info/timing statements from posterior probability calulations. Defaults to False.

Type:

bool, optional

nf

Number of frequency channels.

Type:

int

neta

Number of line-of-sight Fourier modes. Defaults to nf.

Type:

int

freq_min

Minimum frequency in megahertz.

Type:

float

delta_freq

Frequency channel width in megahertz.

Type:

float

nside

HEALPix resolution parameter. Sets the resolution of the sky model. Note, the HEALPix resolution must be chosen such that there are two HEALPix pixels per minimum fringe wavelength from the model uv-plane to satisfy the Nyquist-Shannon sampling theorem.

Type:

int, optional

simple_za_filter

Filter pixels in the sky model by zenith angle only (True). Otherwise, filter pixels in a rectangular region set by the field of view values along the RA and Dec axes (False, default).

Type:

bool, optional

nu

Number of pixels on the u-axis of the model uv-plane for the EoR model.

Type:

int

nv

Number of pixels on the v-axis of the model uv-plane for the EoR model.

Type:

int, optional

fov_ra_eor

Field of view (FoV) of the Right Ascension (RA) axis of the EoR sky model in degrees.

Type:

float

fov_dec_eor

FoV of the Declination (Dec) axis of the EoR sky model in degrees. Defaults to the value of fov_ra_eor (square FoV).

Type:

float, optional

nu_fg

Number of pixels on the u-axis of the model uv-plane for the foreground (FG) model. Defaults to the value of nu.

Type:

int, optional

nv_fg

Number of pixels on the v-axis of the model uv-plane for the FG model. Defaults to the value of nu_fg or nv if nu_fg is not defined.

Type:

int, optional

fov_ra_fg

FoV of the RA axis of the FG sky model in degrees. Defaults to the value of fov_ra_eor.

Type:

float, optional

fov_dec_fg

FoV of the Dec axis of the FG sky model in degrees. Defaults to the value of fov_ra_fg or fov_dec_eor if fov_ra_fg is not defined.

Type:

float, optional

fit_for_monopole

Include (True) or exclude (False) the (u, v) == (0, 0) pixel in the model uv-plane. Defaults to False.

Type:

bool, optional

nq

Number of Large Spectral Scale Model (LSSM) quadratic basis vectors. If passing beta, the quadratic basis vectors are replaced by power law basis vectors according to the spectral indices in beta.

Type:

int, optional

beta

Brightness temperature power law spectral index/indices used in the LSSM. Can be a single spectral index, ‘[2.63]’, or multiple spectral indices can be passed, ‘[2.63,2.82]’, to use multiple power law spectral basis vectors. Do not put spaces after commas if using multiple spectral indices.

Type:

list of float, optional

inverse_LW_power

Prior on the inverse power of the LSSM coefficients. A large value, 1e16, constrains the LSSM coefficients to be zero. A small value, 1e-16, leaves the LSSM coefficients unconstrained (default).

Type:

float, optional

use_LWM_Gaussian_prior

Use a Gaussian prior on the LSSM (True, NOT CURRENTLY IMPLEMENTED). Otherwise, use a uniform prior (False, default).

Type:

bool, optional

fit_for_spectral_model_parameters

Fit for the optimal LSSM spectral indices.

Type:

bool, optional

pl_min

Minimum brightness temperature spectral index when fitting for the optimal LSSM spectral indices.

Type:

float, optional

pl_max

Maximum brightness temperature spectral index when fitting for the optimal LSSM spectral indices.

Type:

float, optional

pl_grid_spacing

Grid spacing for the power law spectral index axis when fitting for the optimal LSSM spectral indices.

Type:

float, optional

sigma

Standard deviation of the visibility noise. Only used if adding noise to the input visibility data. If inputing noise along with the data, sigma is calculated from the noise directly.

Type:

float, optional

noise_seed

Seed for numpy.random. Used to generate the noise vector if adding noise to the input visibility data. Defaults to 742123.

Type:

float, optional

fit_noise

If True, fit for the noise level. Defaults to False.

Type:

bool, optional

model_instrument

Forward model an instrument (’–model-instrument’, True) or exclude instrumental effects (’–no-instrument’, False).

Type:

bool, optional

nt

Number of times/observations.

Type:

int

integration_time_seconds

Time between observations in seconds.

Type:

float

inst_model

Path to a numpy compatible dictionary containing the instrument model. A valid instrument model contains the uv-sampling with shape (Ntimes, Nbls, 3) accessible via the key ‘uvw_model’ and a redundancy array to account for any redundant averaging with shape (Ntimes, Nbls, 1) accessible via the key ‘redundancy_model’.

Type:

str, optional

tele_latlonalt

Telescope location in latitude (deg), longitude (deg), and altitude (meters). Passed as a list of floats, e.g. ‘[30.1,125.6,80.4]’. Do not put spaces after commas. Defaults to the HERA telescope location.

Type:

list of float, optional

central_jd

Central Julian Date of the observations.

Type:

float

beam_type

Can be ‘uniform’, ‘gaussian’, or ‘airy’ (case insensitive).

Type:

str

beam_peak_amplitude

Peak amplitude of the beam. Defaults to 1.0.

Type:

float, optional

beam_center

Beam center offsets from the phase center in RA and Dec in degrees. Default behavior is the beam center aligns with the phase center. Passed as a list of floats, e.g. ‘[-1.3,0.01]’. Do not put a space after the comma.

Type:

list of float, optional

drift_scan

Model the instrument in drift scan mode (’–drift-scan’, True) or in phased mode (’–phased’, False). Defaults to True (drift scan mode).

Type:

bool, optional

fwhm_deg

Full Width at Half Maximum (FWHM) of beam in degrees.

Type:

float, optional

antenna_diameter

Antenna diameter in meters.

Type:

float, optional

cosfreq

Cosine frequency if using a ‘gausscosine’ beam.

Type:

float, optional

achromatic_beam

If True, force the beam to be achromatic. The frequency at which the beam will be calculated is set via beam_ref_freq.

Type:

bool, optional

beam_ref_freq

Beam reference frequency in megahertz. Defaults to the minimum frequency.

Type:

bool, optional

nu_sh

Number of pixels on a side for the u-axis in the SubHarmonic Grid (SHG) model uv-plane.

Type:

int, optional

nv_sh

Number of pixels on a side for the v-axis in the SHG model uv-plane. Defaults to the value of nu_sh.

Type:

int, optional

nq_sh

Number of LSSM quadratic modes for the SHG.

Type:

int, optional

fot_for_shg_amps

If True, fit for the amplitudes of the SHG pixels. Defaults to False.

Type:

bool, optional

taper_func

Tapering function to apply to the frequency axis of the model visibilities. Can be any valid argument to scipy.signal.windows.get_window.

Type:

str, optional

data_path

Path to numpy readable visibility data file in units of mK sr.

Type:

str, optional

noise_data_path

Path to noise file associated with data_path.

Type:

str, optional

eor_sim_path

Path to 21cmFAST EoR simulation cube.

Type:

str, optional

eor_random_seed

Used to seed numpy.random if generating a mock EoR white noise signal, i.e. passing no data file via ‘–data-path’.

Type:

int, optional

config

Path to a yaml configuration file parsable by jsonargparse.ArgumentParser.

Type:

str, optional

Matrix Building

Main class for building all of the necessary matrices used by BayesEoR.

class bayeseor.matrices.BuildMatrices(array_save_directory, include_instrumental_effects, use_sparse_matrices, nu, nv, n_vis, neta, nf, f_min, df, nq, nt, dt, sigma, fit_for_monopole, **kwargs)

Class for handling matrix construction and arithmetic.

Parameters:
  • array_save_directory (str) – Path to the directory where arrays will be saved.

  • include_instrumental_effects (bool) – If True, include instrumental effects like frequency dependent (u, v) sampling and the primary beam.

  • use_sparse_matrices (bool) – If True, use sparse matrices in place of numpy arrays.

  • nu (int) – Number of pixels on a side for the u axis in the model uv-plane.

  • nv (int) – Number of pixels on a side for the v axis in the model uv-plane.

  • n_vis (int) – Number of visibilities per channel, i.e. number of redundant baselines * number of time steps.

  • neta (int) – Number of Line of Sight (LoS) Fourier modes.

  • nf (int) – Number of frequency channels.

  • f_min (float) – Minimum frequency in megahertz.

  • df (float) – Frequency channel width in megahertz.

  • nt (int) – Number of times.

  • nq (int) – Number of quadratic modes in the Large Spectral Scale Model (LSSM).

  • sigma (float) – Expected noise amplitude in the data vector = signal + noise.

  • fit_for_monopole (bool) – If True, fit for (u, v) = (0, 0). Otherwise, exclude it from the fit.

  • npl (int) – Number of power law coefficients which replace quadratic modes in the LSSM.

  • uvw_array_m (numpy.ndarray) – Array containing the (u(t), v(t), w(t)) coordinates of the instrument model with shape (nt, nbls, 3).

  • uvw_array_m_vec (numpy.ndarray) – Reshaped uvw_array_m with shape (nt * nbls, 3). Each set of nbls entries contain the (u, v, w) coordinates for a single integration.

  • bl_red_array (numpy.ndarray) – Array containing the number of redundant baselines at each (u(t), v(t), w(t)) in the instrument model with shape (nt, nbls, 1).

  • bl_red_array_vec (numpy.ndarray) – Reshaped bl_red_array with shape (nt * nbls, 1). Each set of nbls entries contain the redundancy of each (u, v, w) for a single integration.

  • phasor_vec (numpy.ndarray) – Array with shape (ndata,) that contains the phasor term used to phase visibilities after performing the nuDFT from HEALPix (l, m, f) to instrumentally sampled, unphased (u, v, f). Defaults to None, i.e. modelling unphased visibilities.

  • fov_ra_eor (float) – Field of view in degrees of the RA axis of the EoR sky model.

  • fov_dec_eor (float) – Field of view in degrees of the DEC axis of the EoR sky model.

  • fov_ra_fg (float) – Field of view in degrees of the RA axis of the FG sky model.

  • fov_dec_fg (float) – Field of view in degrees of the DEC axis of the FG sky model.

  • simple_za_filter (bool) – If passed, filter pixels in the sky model by zenith angle only. Otherwise, filter pixels in a rectangular region set by the FoV values along the RA and DEC axes (default).

  • nside (int) – HEALPix nside parameter.

  • telescope_latlonalt (tuple) – The latitude, longitude, and altitude of the telescope in degrees, degrees, and meters, respectively.

  • central_jd (float) – Central time step of the observation in JD2000 format.

  • dt (float) – Time cadence of observations in seconds.

  • drift_scan_pb (bool) – If True, model a drift scan primary beam, i.e. the beam center drifts across the image space model with time.

  • beam_type (string) – Beam type to use. Can be ‘uniform’, ‘gaussian’, ‘airy’, ‘taperairy’, or ‘gausscosine’.

  • beam_peak_amplitude (float) – Peak amplitude of the beam.

  • beam_center (tuple of floats) – Beam center in (RA, DEC) coordinates and units of degrees. Assumed to be an tuple of offsets along the RA and DEC axes relative to the pointing center of the sky model determined from the instrument model parameters telescope_latlonalt and central_jd.

  • fwhm_deg (float) – Full Width at Half Maximum (FWHM) of the beam if using a Gaussian beam, or the effective FWHM of the main lobe of an Airy beam from which the diameter of the aperture is calculated.

  • antenna_diameter (float) – Antenna (aperture) diameter in meters. Used in the calculation of an Airy beam pattern or when using a Gaussian beam with a FWHM that varies as a function of frequency. The FWHM evolves according to the effective FWHM of the main lobe of an Airy beam.

  • cosfreq (float) – Cosine frequency in radians if using a ‘gausscosine’ beam.

  • achromatic_beam (bool, optional) – If True, force the beam to be achromatic using beam_ref_freq as the reference frequency.

  • beam_ref_freq (float, optional) – Beam reference frequency in MHz. Used to fix the beam to be achromatic.

  • effective_noise (numpy.ndarray) – If the data vector being analyzed contains signal + noise, the effective_noise vector contains the estimate of the noise in the data vector. Must have the shape and ordering of the data vector, i.e. (ndata,).

  • deta (float) – Fourier mode spacing along the eta (line of sight, frequency) axis in inverse Hz.

  • du_eor (float) – Fourier mode spacing along the u axis in inverse radians of the EoR model uv-plane.

  • dv_eor (float) – Fourier mode spacing along the v axis in inverse radians of the EoR model uv-plane.

  • du_fg (float) – Fourier mode spacing along the u axis in inverse radians of the FG model uv-plane.

  • dv_fg (float) – Fourier mode spacing along the v axis in inverse radians of the FG model uv-plane.

  • use_shg (bool, optional) – If True, use the SubHarmonic Grid (SHG) in the model uv-plane.

  • fit_for_shg_amps (bool, optional) – if True, fit explicitly for the amplitudes of the individual SHG pixels per frequency.

  • nu_sh (int, optional) – Number of pixels on a side for the u-axis in the subharmonic model uv-plane.

  • nv_sh (int, optional) – Number of pixels on a side for the v-axis in the subharmonic model uv-plane.

  • nq_sh (int, optional) – Number of large spectral scale modes for each pixel in the subharmonic grid.

  • npl_sh (int, optional) – Number of power law coefficients used in the large spectral scale model for each pixel in the subharmonic grid.

  • taper_func (str, optional) – Tapering function to apply to the frequency axis of the model visibilities. Can be any valid argument to scipy.signal.windows.get_window.

  • nu_fg (int) – Number of pixels on a side for the u-axis in the FG model uv-plane.

  • nv_fg (int) – Number of pixels on a side for the v-axis in the FG model uv-plane.

build_Finv()

Build a multi-frequency NUDFT matrix for image to measurement space.

Finv is a a non-uniform DFT matrix that takes a vector of (l, m, n) syk model pixel amplitudes and

  1. Applies a beam per time and frequency via multi_chan_beam

  2. Transforms to insttrumentally sampled, unphased (u(f), v(f), w(f)) coordinates from the instrument model

  3. If modelling phased visibilities, applies a phasor vector from the instrument model to phase the visibilities to the central time step

Notes

  • Finv has shape (ndata, npix * nf).

build_Fprime()

Build a multi-frequency NUIDFT matrix fo uv to image space.

Fprime takes a rectilinear (u, v) model as a channel ordered vector and transforms it to HEALPix sky model (l, m) space. Fprime is constructed as a block-diagonal matrix with blocks for the EoR and FG models.

Notes

  • Fprime has shape ((npix_eor + npix_fg) * nf, (nuv_eor + nuv_fg) * nf).

build_Fprime_Fz()

Build Fprime_Fz = Fprime * Fz.

Notes

  • Fprime_Fz has shape (npix, nuv_eor * (neta - 1)

    + (nuv_fg - fit_for_monopole) * (1 + nq) + fit_for_monopole * (neta + nq)).

build_Fz()

Build a block-diagonal IDFT matrix for eta to frequency space.

Fz is constructed as a block-diagonal matrix. Each block is a 1D IDFT matrix which takes a vis ordered eta space vector and transforms it to a chan ordered frequency space data vector.

Notes

  • Fz has shape ((nuv_eor + nuv_fg)*nf,

    nuv_eor*(neta - 1) + nuv_fg*(1 + nq) + fit_for_monopole*(neta + nq)).

build_N()

Build a diagonal covariance matrix.

Each diagonal component contains an estimate of |noise|**2 in the data vector.

Notes

  • N has shape (ndata, ndata).

build_Ninv()

Build a diagonal inverse covariance matrix.

Each diagonal component contains an estimate of 1 / |noise|**2 in the data vector.

Notes

  • Ninv has shape (ndata, ndata).

build_Ninv_T()

Build Ninv_T = Ninv * T.

Ninv_T computes the inverse covariance weighted vector in data space from an eta space data vector.

Notes

  • Ninv_T has shape (ndata, nuv * (neta + nq)).

build_T()

Build T = Finv * Fprime * Fz.

T takes a model (u(eta), v(eta)) space data vector and transforms it to

  1. uv space via Fz

  2. image space via Fprime

  3. measurement space via Finv

Notes

  • T has shape (ndata, nuv * (neta + nq)).

build_T_Ninv_T()

Build T_Ninv_T = T.conjugate().T * Ninv * T.

Notes

  • T_Ninv_T has shape (nuv * (neta + nq), nuv * (neta + nq)).

build_block_T_Ninv_T()

Constructs a block diagonal representation of T_Ninv_T. Only used if self.use_instrumental_effects = False.

build_gridding_matrix_co2vo()

Build a chan ordered to vis ordered gridding matrix.

This matrix is the transposition of gridding_matrix_vo2co.

Notes

  • gridding_matrix_co2vo has shape (nuv * (neta + nq), nuv * (neta + nq)).

build_gridding_matrix_vo2co()

Build a vis ordered to chan ordered gridding matrix.

The gridding matrix takes a (u, v, f) space vector that is vis ordered:
  • the first neta entries correspond to the spectrum of the zeroth index model (u, v) pixel

  • the second neta entries correspond to the spectrum of the first index model (u, v) pixel

  • etc.

and converts it to chan ordered:
  • the first ‘nuv’ entries correspond to the values of the model (u, v) plane at the zeroth frequency channel

  • the second ‘nuv’ entries correspond to the values of the model (u, v) plane at the first frequency channel

  • etc.

Notes

  • Used for the EoR model in Fz.

  • gridding_matrix_vo2co has shape (nuv*nf, nuv*nf).

build_gridding_matrix_vo2co_fg()

Build a vis ordered to chan ordered gridding matrix.

The gridding matrix takes a (u, v, f) space vector that is vis ordered:
  • the first neta entries correspond to the spectrum of the zeroth index model (u, v) pixel

  • the second neta entries correspond to the spectrum of the first index model (u, v) pixel

  • etc.

and converts it to chan ordered:
  • the first ‘nuv’ entries correspond to the values of the model (u, v) plane at the zeroth frequency channel

  • the second ‘nuv’ entries correspond to the values of the model (u, v) plane at the first frequency channel

  • etc.

Notes

  • Used for the FG model in Fz.

  • gridding_matrix_vo2co_fg is a square matrix with dimension (nuv_fg - (not fit_for_monopole)) * nf.

build_idft_array_1d()

Build an IDFT matrix for eta to frequency space.

Constructs one block within multi_vis_idft_array_1d.

Notes

  • Used for the EoR model in Fz.

  • idft_array has shape (nf, neta - 1).

  • Excludes eta=0 which belongs to the FG model.

build_idft_array_1d_fg()

Build a block-diagonal IDFT matrix for eta to freuqency space.

Notes

  • Used for the FG model in Fz.

  • idft_array_1d_fg has shape (nuv_fg * nf, nuv_fg*(1 + nq) + fit_for_monopole*(neta + nq)).

build_idft_array_1d_sh()

Build a block-diagonal IDFT matrix for eta to frequency space.

idft_array_1d_sh is constructted as a block-diagonal matrix. Each block is a 1D IDFT matrix for the eta spectrum of each (u, v) pixel in the SubHarmonic Grid (SHG) model uv-plane.

Notes

  • Used for the SHG model in Fz.

build_matrix_if_it_doesnt_already_exist(matrix_name)

Constructs a matrix with name matrix_name if it doesn’t already exist.

This function doesn’t return anything. It instead calls the corresponding build matrix function.

Parameters:

matrix_name (str) – Name of matrix.

build_minimum_sufficient_matrix_stack(clobber_matrices=False, force_clobber=False)

Construct a minimum sufficient matrix stack needed to run BayesEoR.

Parameters:
  • clobber_matrices (bool) – If True, overwrite the existing matrix stack.

  • force_clobber (bool) – If True, delete the old matrix stack without user input. If False, prompt the user to specify wether the matrix stack should be deleted (‘y’) or archived (‘n’).

build_multi_chan_beam()

Build a matrix contating image space beam amplitudes.

Each block-diagonal entry contains the beam amplitude at each HEALPix sampled (l(t), m(t), n(t)) for a single time and frequency. Each stack contains nf block-diagonal entries containing the beam amplitudes at all frequencies for a single time.

Notes

  • Used to construct Finv.

  • multi_chan_beam has shape (npix * nf * nt, npix * nf).

build_multi_chan_nudft()

Build a multi-frequency NUDFT matrix for image to measurement space.

Each block in this block-diagonal matrix transforms a set of time-dependent image-space (l(t), m(t), n(t)) HEALPix coordinates to unphased, instrumentall sampled, frequency dependent (u(f), v(f), w(f)).

Notes

  • Used to construct Finv.

  • If use_nvis_nt_nchan_ordering = True: model visibilities will be ordered (nvis*nt) per chan for all channels (old default).

  • If use_nvis_nchan_nt_ordering = True: model visibilities will be ordered (nvis*nchan) per time step for all time steps. This ordering is required when using a drift scan primary beam (current default).

  • multi_chan_nudft has shape (ndata, npix * nf * nt).

build_multi_chan_nuidft()

Build a multi-frequency NUIDFT matrix for uv to image space.

multi_chan_nuidft is constructed as a block-diagonal matrix. Each block is constructed via build_nuidft_array and represents a 2D non-uniform DFT matrix from rectilinear (u, v) to HEALPix (l, m) for a single frequency.

Notes

  • Used for the EoR model in Fprime.

  • multi_chan_nuidft has shape (npix_eor * nf, nuv_eor * nf).

build_multi_chan_nuidft_fg()

Build a multi-frequency NUIDFT matrix for uv to image space.

multi_chan_nuidft_fg is constructed as a block-diagonal matrix. Each block is a 2D non-uniform DFT matrix from rectilinear (u, v) to HEALPix (l, m) at a single frequency.

Notes

  • Used for the FG model in Fprime.

  • multi_chan_nuidft_fg has shape (npix_fg * nf, nuv_fg * nf)

build_multi_vis_idft_array_1d()

Build a block-diagonal IDFT matrix from eta to frequency space.

Notes

  • Used for the EoR model in Fz.

  • multi_vis_idft_array_1d has shape (nuv_eor * nf, nuv_eor * (neta - 1)).

build_nuidft_array()

Build a NUIDFT matrix for uv to image space.

This matrix forms a block in multi_chan_nuidft and transforms the EoR model uv-plane to image space at a single frequency. Specifically, nuidft_array transforms a rectilinear (u, v) grid to HEALPix sampled (l, m). The model uv-plane has w=0, so no w or n terms are included in this transformation.

Notes

  • Used for the EoR model in Fprime.

  • nuidft_array has shape (npix, nuv).

  • If the EoR and FG models have different FoV values, nuidft_array is reshaped to match the dimensions of the FG model (FoV_FG >= FoV_EoR). The HEALPix pixel ordering must be preserved in this reshaping so that shared pixels between the EoR and FG models are summed together in image-space.

build_nuidft_array_sh()

Build a multi-frequency NUIDFT matrix for uv to image space.

nuidft_array_sh is constructed as a block diagonal matrix. Each block transforms the SubHarmonic Grid (SHG) model uv-plane to HEALPix sampled (l, m) at a single frequency.

Notes

  • Used for the SHG model in Fprime.

  • nuidft_array_sh has shape (npix*nf, nuv_sh*fit_for_shg_amps + nuv_sh*nq_sh).

build_phasor_matrix()

Build a diagonal matrix used to phase visibilities.

The phasor matrix is multiplied elementwise into the visibility vector from Finv, constructed using unphased (u, v, w) coordinates, to produce phased visibilities.

The phasor matrix is constructed as a diagonal matrix of $e^(i*phi(u(t), v(t), w(t)))$ phasor terms from the optional phasor vector in the instrument model.

Notes

  • Used to construct Finv if modelling phased visibilities.

  • phasor_matrix has shape (ndata, ndata).

  • This function assumes that use_nvis_nchan_nt_ordering = True.

build_taper_matrix()

Build a diagonal matrix containing a frequency taper function.

The taper matrix is a diagonal matrix containing a tapering function on the diagonal multiplied elementwise into the visibility vector.

Notes

  • Used to construct Finv if using a taper function.

  • taper_matrix has shape (ndata, ndata).

  • This function assumes that use_nvis_nchan_nt_ordering = True.

convert_sparse_matrix_to_dense_numpy_array(matrix_a)

Convert scipy.sparse matrix to dense numpy array.

Parameters:

matrix_a (scipy.sparse) – Sparse matrix.

Returns:

matrix_a_dense_np_array – Dense representation of matrix_a.

Return type:

numpy.ndarray

convert_sparse_to_dense_matrix(matrix_a)

Convert scipy.sparse matrix to dense matrix.

Parameters:

matrix_a (scipy.sparse) – Sparse matrix.

Returns:

matrix_a_dense – Dense representation of matrix_a.

Return type:

numpy.matrix

delete_old_matrix_stack(path_to_old_matrix_stack, confirm_deletion)

Delete or archive an existing matrix stack.

Parameters:
  • path_to_old_matrix_stack (str) – Path to the existing matrix stack.

  • confirm_deletion (str) – If ‘y’, delete existing matrix stack. Otherwise, archive the matrix stack.

dot_product(matrix_a, matrix_b)

Calculate the dot product of matrix_a and matrix_b.

Uses sparse or dense matrix algebra based upon the type of each matrix.

Parameters:
  • matrix_a (array) – First argument.

  • matrix_b (array) – Second argument.

Returns:

ab – Matrix dot product of matrix_a and matrix_b.

Return type:

array

Notes

For dot products of sparse and dense matrices: * dot(sparse, dense) = dense * dot(dense, sparse) = dense * dot(sparse, sparse) = sparse

load_prerequisites(matrix_name)

Load or build any prerequisites for a given matrix.

Parameters:

matrix_name (str) – Name of matrix.

Returns:

prerequisite_matrices_dictionary – Dictionary containing any and all loaded matrix prerequisites.

Return type:

dict

prepare_matrix_stack_for_deletion(src, clobber_matrices)

Archive an existing matrix stack on disk by prepending ‘delete_’ to the child directory.

Parameters:
  • src (str) – Path to existing matrix stack directory.

  • clobber_matrices (bool) – If True, overwrite a previously archived matrix stack.

Returns:

dst – If clobber_matrices = True, path to matrix stack directory to be deleted.

Return type:

str

sd_block_diag(block_matrices_list)

Generate a block diagonal matrix from a list of matrices.

Parameters:

block_matrices_list (list) – List of input matrices.

Returns:

block_diag_matrix – If self.use_sparse_matrices = True, return a sparse matrix. Otherwise, return a dense numpy array.

Return type:

array

sd_diags(diagonal_vals)

Generate a diagonal matrix from a list of entries in diagonal_vals.

Parameters:

diagonal_vals (array) – Input values to be placed on the matrix diagonal.

Returns:

diagonal_matrix – If self.use_sparse_matrices = True, return a sparse matrix. Otherwise, return a dense numpy array.

Return type:

array

sd_hstack(matrices_list)

Generate a horizontally stacked matrix from a list of matrices.

Parameters:

matrices_list (list) – List of input matrices.

Returns:

hstack_matrix – If self.use_sparse_matrices = True, return a sparse matrix. Otherwise, return a dense numpy array.

Return type:

array

sd_vstack(matrices_list)

Generate a vertically stacked matrix from a list of matrices.

Parameters:

matrices_list (list) – List of input matrices.

Returns:

vstack_matrix – If self.use_sparse_matrices = True, return a sparse matrix. Otherwise, return a dense numpy array.

Return type:

array

write_version_info()

Write version info to disk.

HEALPix Interface

Class containing HEALPix functions for the image domain model.

class bayeseor.model.healpix.Healpix(fov_ra_eor=None, fov_dec_eor=None, fov_ra_fg=None, fov_dec_fg=None, simple_za_filter=False, nside=256, telescope_latlonalt=(-30.72152777777791, 21.428305555555557, 1073.0000000093132), central_jd=None, nt=1, int_time=None, beam_type=None, peak_amp=1.0, fwhm_deg=None, diam=None, cosfreq=None, tanh_freq=None, tanh_sl_red=None)

Class to store and manipulate HEALPix maps using astropy_healpix functions.

Parameters:
  • fov_ra_eor (float) – Field of view in degrees of the RA axis of the EoR sky model.

  • fov_dec_eor (float, optional) – Field of view in degrees of the DEC axis of the EoR sky model. Defaults to fov_ra_eor.

  • fov_ra_fg (float, optional) – Field of view in degrees of the RA axis of the FG sky model.

  • fov_dec_fg (float, optional) – Field of view in degrees of the DEC axis of the FG sky model. Defaults to fov_ra_fg.

  • simple_za_filter (boolean, optional) – If True, filter pixels in the FoV by zenith angle only. Otherwise, filter pixels in a rectangular region set by the FoV values along RA and DEC.

  • nside (int) – Nside resolution of the HEALPix map. Defaults to 256.

  • telescope_latlonalt (tuple, optional) – Tuple containing the latitude, longitude, and altitude of the telescope in degrees, degrees, and meters, respectively. Defaults to the location of the HERA telescope, i.e. (-30.72152777777791, 21.428305555555557, 1073.0000000093132).

  • central_jd (float) – Central time step of the observation in JD2000 format.

  • nt (int, optional) – Number of time integrations. Defaults to 1.

  • int_time (float, optional) – Integration time in seconds. Required if nt > 1.

  • beam_type (str, optional) – Can be either a path to a pyuvdata.UVBeam compatible file or one of {‘uniform’, ‘gaussian’, ‘airy’}. Defaults to ‘uniform’.

  • peak_amp (float, optional) – Peak amplitude of the beam. Defaults to 1.0.

  • fwhm_deg (float, optional) – Required if beam_type = 'gaussian'. Sets the full width at half maximum of the beam in degrees.

  • diam (float, optional) – Antenna (aperture) diameter in meters. Used if beam_type = 'airy'.

  • cosfreq (float, optional) – Cosine frequency in inverse radians. Used if beam_type = 'gausscosine'.

  • tanh_freq (float, optional) – Exponential frequency (rate parameter) in inverse radians. Used if beam_type = 'tanhairy'.

  • tanh_sl_red (float, optional) – Airy sidelobe amplitude reduction as a fractional percent. For example, passing 0.99 reduces the sidelobes by 0.01, i.e. two orders of magnitude. Used if beam_type = 'tanhairy'.

calc_lmn_from_radec(time, ra, dec, return_azza=False, radec_offset=None)

Return arrays of (l, m, n) coordinates in radians for all (RA, DEC).

Parameters:
  • time (float) – Julian date used in ICRS to AltAz coordinate frame conversion.

  • ra (array) – Array of RA values in degrees.

  • dec (array) – Array of DEC values in degrees.

  • return_azza (boolean) – If True, return both (l, m, n) and (az, za) coordinate arrays. Otherwise return only (l, m, n). Defaults to ‘False’.

  • radec_offset (tuple of floats) – Will likely be deprecated.

Returns:

  • l (np.ndarray of floats) – Array containing the EW direction cosine of each HEALPix pixel.

  • m (np.ndarray of floats) – Array containing the NS direction cosine of each HEALPix pixel.

  • n (np.ndarray of floats) – Array containing the radial direction cosine of each HEALPix pixel.

Notes

get_beam_vals(az, za, freq=None)

Get an array of beam values from (az, za) coordinates.

If self.beam_type = 'gaussian', this function assumes that the beam width is symmetric along the l and m axes.

Parameters:
  • az (np.ndarray of floats) – Azimuthal angle of each pixel in radians.

  • za (np.ndarray of floats) – Zenith angle of each pixel in radians.

  • freq (float, optional) – Frequency in Hz.

Returns:

beam_vals – Array containing beam amplitude values at each (az, za).

Return type:

np.ndarray

get_extent_ra_dec(fov_ra, fov_dec, fov_fac=1.0)

Get the sampled extent of the sky in RA and DEC.

Parameters:
  • fov_ra (float) – Field of view in degrees of the RA axis.

  • fov_dec (float) – Field of view in degrees of the DEC axis.

  • fov_fac (float) – Scaling factor for the sampled extent.

Returns:

  • range_ra (tuple) – fov_fac scaled (min, max) sampled RA values.

  • range_dec (tuple) – fov_fac scaled (min, max) sampled DEC values.

get_pixel_filter(fov_ra, fov_dec, return_radec=False, inverse=False, simple_za_filter=False)

Return HEALPix pixel indices lying inside an observed region.

This function gets the HEALPix pixel indices for all pixel centers lying inside

  • a rectangle with equal arc length on all sides if simple_za_filter = True

  • a circle with radius fov_ra if simple_za_filter = False

Parameters:
  • fov_ra (float) – Field of view in degrees of the RA axis.

  • fov_dec (float) – Field of view in degrees of the DEC axis.

  • return_radec (bool, optional) – Return the (RA, DEC) coordinates associated with each pixel center. Defaults to False.

  • inverse (boolean, optional) – If False, return the pixels within the observed region. If True, return the pixels outside the observed region.

  • simple_za_filter (boolean, optional) – If True, return the pixels inside a circular region defined by za <= fov_ra/2. Otherwise, return the pixels inside a rectangular region with equal arc length on all sides.

Returns:

  • pix (array) – HEALPix pixel numbers lying within the observed region set by fov_ra and fov_dec.

  • ra (array) – Array of RA values for each pixel center. Only returned if return_radec = True.

  • dec (array) – Array of DEC values for each pixel center. Only returned if return_radec = True.

Posterior Probability Calculations

class bayeseor.posterior.PowerSpectrumPosteriorProbability(T_Ninv_T, dbar, k_vals, k_cube_voxels_in_bin, nuv, neta, nf, nq, Ninv, d_Ninv_d, redshift, ps_box_size_ra_Mpc, ps_box_size_dec_Mpc, ps_box_size_para_Mpc, include_instrumental_effects=True, log_priors=False, uprior_inds=None, masked_power_spectral_modes=None, use_LWM_Gaussian_prior=False, inverse_LW_power=0.0, dimensionless_PS=False, block_T_Ninv_T=[], intrinsic_noise_fitting=False, fit_for_spectral_model_parameters=False, pl_max=None, pl_grid_spacing=None, use_shg=False, return_Sigma=False, rank=0, use_gpu=True, print=False, print_rate=100, debug=False, print_debug=False)

Class containing posterior calculation functions.

Parameters:
  • T_Ninv_T (np.ndarray) – Complex matrix product T.conjugate().T * Ninv * T. Used to construct Sigma which is used to solve for the ML 3D Fourier space vector and LSSM amplitudes. T_Ninv_T must be a Hermitian, positive-definite matrix.

  • dbar (np.ndarray) – Noise weighted representation of the data vector (signal + noise) of visibilities in model (u, v, eta) space.

  • k_vals (np.ndarray of floats) – Array containing the mean k for each k bin.

  • k_cube_voxels_in_bin (list) – List of sublists containing the flattened 3D k-space cube index of all k that fall within a given k bin.

  • nuv (int) – Number of model uv-plane points per frequency channel.

  • neta (int) – Number of Line of Sight (LoS, frequency axis) Fourier modes.

  • nf (int) – Number of frequency channels.

  • nq (int) – Number of quadratic modes in the Larse Spectral Scale Model (LSSM).

  • Ninv (np.ndarray) – Covariance matrix of the data (signal + noise) vector of visibilities.

  • d_Ninv_d (np.ndarray) – Single complex number computed as d.conjugate() * Ninv * d.

  • ps_box_size_ra_Mpc (float) – Right ascension (RA) axis extent of the cosmological volume in Mpc from which the power spectrum is estimated.

  • ps_box_size_dec_Mpc (float) – Declination (DEC) axis extent of the cosmological volume in Mpc from which the power spectrum is estimated.

  • ps_box_size_para_Mpc (float) – LoS extent of the cosmological volume in Mpc from which the power spectrum is estimated.

  • include_instrumental_effects (bool) – If True, include instrumental effects like frequency dependent (u, v) sampling and the primary beam. Defaults to True.

  • log_priors (boolean) – If True, power spectrum k bin amplitudes are assumed to be in log units, otherwise they will be treated using linear units.

  • uprior_inds (array) – Boolean array with shape len(k_vals). If True (False), k bin uses a uniform (log-uniform) prior.

  • masked_power_spectral_modes (np.ndarray) – Boolean array used to mask additional (u, v, eta) amplitudes from being included in the posterior calculations. Defaults to using all EoR model modes.

  • use_LWM_Gaussian_prior (bool) – If True, use a Gaussian prior on the LSSM (NOT IMPLEMENTED). Otherwise, use a uniform prior (default).

  • inverse_LW_power (float) – Prior over the long wavelength modes in the LSSM. Defaults to 0.0.

  • dimensionless_PS (boolean) – If True, use a dimensionless power spectrum normalization Delta**2 ~ mK**2, otherwise use a dimensionful power spectrum normalization P(k) ~ mK**2 Mpc**3.

  • block_T_Ninv_T (list) – Block diagonal representation of T_Ninv_T. Only used if ignoring instrumental effects. Defaults to [].

  • intrinsic_noise_fitting (boolean) – If True, fit for the amplitude of the noise in the data instead of using the covariance estimate as is in Ninv. Defaults to False.

  • fit_for_spectral_model_parameters (boolean) – If True, fit for the LSSM parameter values. Defaults to False.

  • pl_max (float) – Maximum brightness temperature spectral index when fitting for the optimal LSSM spectral indices. Defaults to None.

  • pl_grid_spacing (float) – Grid spacing for the power law spectral index axis when fitting for the LSSM parameter values. Defaults to None.

  • use_shg (bool) – If True, use the SubHarmonic Grid (SHG) in the model uv-plane.

  • return_Sigma (boolean) – If True, break and return the matrix Sigma = T_Ninv_T + PhiI. Defaults to False.

  • rank (int) – MPI rank.

  • use_gpu (bool) – If True, try and use GPUs for Cholesky decomposition. Otherwise, use CPUs (inadvisable due to inaccuracy of CPU matrix inversion). Defaults to True.

  • print (boolean) – If True, print execution time messages. Defaults to False.

  • print_rate (int) – Number of iterations between print statements. Defaults to 100.

  • debug (boolean) – If True, execute break statements for debugging. Defaults to False.

  • print_debug (boolean) – If True, print debug related messages. Defaults to False.

add_power_to_diagonals(T_Ninv_T_block, PhiI_block)

Add a matrix and a vector reshaped as a diagonal matrix.

Used only if T_Ninv_T has been constructed as a block-diagonal matrix, i.e. if ignoring instrumental effects.

Parameters:
  • T_Ninv_T_block (np.ndarray) – Single block matrix from block_T_Ninv_T.

  • PhiI_block (np.ndarray) – Vector of the estimated inverse variance of each k voxel present in T_Ninv_T_block.

Returns:

matrix_sum – Sum of T_Ninv_T_block and a diagonal matrix constructed from PhiI_block.

Return type:

np.ndarray

calc_PowerI(x)

Calculate an estimate of the inverse variance of the model.

Given a power spectrum, this function returns an estimate of the inverse variance of each voxel in the (u, v, eta) model which is used as a prior in the posterior probability calculation.

Parameters:

x (array_like) – Input power spectrum amplitudes per k bin with length nDims.

Returns:

PhiI – Vector with estimates of the inverse variance of each model (u, v, eta) voxel.

Return type:

np.ndarray

calc_SigmaI_dbar(Sigma, dbar, x_for_error_checking=[])

Solves the linear system Sigma * a = dbar.

Solved by calculating the Cholesky decomposition (if self.use_gpu is True) of the matrix Sigma = T_Ninv_T + PhiI. If not using GPUs to perform the matrix inversion, scipy.linalg.inv will be used. This is not desired as the CPU based scipy.linalg.inv function does not always return the “true” matrix inverse for the matrices used here.

Parameters:
  • Sigma (np.ndarray) – Complex matrix Sigma = T_Ninv_T + PhiI.

  • dbar (np.ndarray) – Noise weighted representation of the data (signal + noise) vector of visibilities in model (u, v, eta) space.

  • x_for_error_checking (array_like) – Input power spectrum amplitudes per k bin with length nDims used for error checking of the matrix inversion. Defaults to an empty list (no error checking).

Returns:

  • SigmaI_dbar (np.ndarray) – Complex array of maximum a posteriori (u, v, eta) and Large Spectral Scale Model (LSSM) amplitudes. Used to compute the model data vector via m = T * SigmaI_dbar.

  • logdet_Magma_Sigma (np.ndarray) – Natural logarith of the determinant of Sigma. Only returned if self.use_gpu is True.

calc_SigmaI_dbar_wrapper(x, T_Ninv_T, dbar, block_T_Ninv_T=[])

Wrapper for calc_SigmaI_dbar.

Constructs Sigma and calculates SigmaI_dbar and other quantities derived from SigmaI_dbar. The actual solve step to obtain SigmaI_dbar is performed in calc_SigmaI_sbar.

Parameters:
  • x (array_like) – Input power spectrum amplitudes per k bin with length nDims.

  • T_Ninv_T (np.ndarray) – Complex matrix product T.conjugate().T * Ninv * T.

  • dbar (np.ndarray) – Noise weighted representation of the data (signal + noise) vector of visibilities in model (u, v, eta) space.

  • block_T_Ninv_T (list) – Block diagonal representation of T_Ninv_T. Only used if ignoring instrumental effects. Defaults to an empty list.

Returns:

  • SigmaI_dbar (np.ndarray) – Complex array of maximum a posteriori (u, v, eta) and Large Spectral Scale Model (LSSM) amplitudes. Used to compute the model data vector via m = T * SigmaI_dbar.

  • dbarSigmaIdbar (np.ndarray) – Complex array product dbar * SigmaI_dbar.

  • PhiI (np.ndarray) – Vector with estimates of the inverse variance of each model (u, v, eta) voxel.

  • logSigmaDet (np.ndarray) – Natural logarithm of the determinant of Sigma = T_Ninv_T + PhiI.

calc_Sigma_block_diagonals(T_Ninv_T, PhiI)

Constructs Sigma using block diagonal components like block_T_Ninv_T.

Used only if T_Ninv_T has been constructed as a block-diagonal matrix, i.e. if ignoring instrumental effects.

Parameters:
  • T_Ninv_T (np.ndarray) – Complex matrix product T.conjugate().T * Ninv * T.

  • PhiI (np.ndarray) – Vector with estimates of the inverse variance of each model (u, v, eta) voxel.

Returns:

Sigma_block_diagonals – Array containing a block diagonal representation of Sigma = T_Ninv_T + PhiI. Each block is an entry along the zeroth axis of Sigma_block_diagonals. This allows Sigma to be inverted numerically block by block as opposed to all at once.

Return type:

np.ndarray

calc_physical_dimensionless_power_spectral_normalisation(i_bin)

Dimensionless power spectrum normalization in physical units.

This normalization will return PowerI, an estimate for one over the variance of a, in units of 1 / (mK^2 sr^2 Hz^2).

Parameters:

i_bin (int) – Spherically averaged k bin index.

Returns:

dmps_norm – Dimensionless power spectrum normalization with units of 1 / (sr**2 Hz**2).

Return type:

float

posterior_probability(x, block_T_Ninv_T=[])

Computes the posterior probability for a given power spectrum sample.

Parameters:
  • x (array_like) – Input power spectrum amplitudes per k bin with length nDims.

  • block_T_Ninv_T (list) – Block diagonal representation of T_Ninv_T. Only used if ignoring instrumental effects. Defaults to an empty list.

Returns:

  • MargLogL (float) – Posterior probability of x.

  • phi – Only used if sampling with PolyChord.