Skip to content

Data

get_vis_data loads a visibility file or preprocessed vector and returns the data vector, noise information and observation axes in the analysis convention. The instrument enters through its baselines, InstrumentModel, and its primary beam, Beam_Model.

See the Data guide for the supported inputs and settings.

Visibilities

bayeseor_jax.data.vis.get_vis_data

get_vis_data(*, data_path: Path | str, inst_model: Path | str | None = None, noise_data_path: Path | str | None = None, sigma: float | None = None, noise_seed: int = 742123, calc_noise: bool = False, antenna_selection: str = 'cross', bl_cutoff: float | None = None, freq_idx_min: int | None = None, freq_min: float | None = None, freq_center: float | None = None, n_freqs_select: int | None = None, jd_idx_min: int | None = None, jd_min: float | None = None, jd_center: float | None = None, n_times_select: int | None = None, form_pi: bool = True, pi_norm: float = 1.0, pol: str = 'xx', redundant_avg: bool = False, uniform_redundancy: bool = False, n_freq: int | None = None, f0_mhz: float | None = None, df_mhz: float | None = None, n_t: int | None = None, d_t: float | None = None, save_vis: bool = False, save_model: bool = False, save_dir: Path | str = './', clobber: bool = False) -> dict[str, Any]

Load a visibility vector, its noise realisation and aligned observation metadata.

Parameters:

Name Type Description Default
data_path Path or str

A calibrated .uvh5 or .uvfits file, a .ms directory, or a preprocessed .npy array. These lowercase suffixes select the reader. Raw inputs must be in Jy or K sr; NumPy inputs must already be in mK sr, flattened in time/frequency/baseline order with conjugate copies.

required
inst_model Path or str

Required for NumPy inputs. Directory containing uvw_model.npy and redundancy_model.npy with optional antpairs.npy, or a combined instrument_model.npy dictionary. See InstrumentModel.

None
noise_data_path Path or str

Trusted NumPy noise vector in the same units and order as the data. Takes precedence over estimated noise. It is returned, not added: the input visibilities are assumed to contain noise already.

None
sigma float

Complex noise RMS in mK sr before redundancy scaling. Required when neither supplied nor estimated noise is available; the input is then treated as noiseless and a synthetic realisation is added.

None
noise_seed int

Seed passed to generate_gaussian_noise; defaults to 742123.

742123
calc_noise bool

Request the legacy even/odd time-difference noise estimate for raw inputs. Does not estimate noise from preprocessed NumPy inputs.

False
antenna_selection str

pyuvdata antenna-selection string for raw inputs; default 'cross'.

'cross'
bl_cutoff float or Quantity

Raw-input cutoff on sqrt(u2 + v2), in metres if unitless.

None
freq_idx_min int

First raw frequency-channel index, starting from zero.

None
freq_min float or Quantity

Raw-input frequency lower bound or window centre, in Hz if unitless.

None
freq_center float or Quantity

Raw-input frequency lower bound or window centre, in Hz if unitless.

None
n_freqs_select int

Raw channel-window width. Supply a starting index, lower bound or centre to activate selection; a centre requires this width.

None
jd_idx_min int

First raw integration index, starting from zero.

None
jd_min float

Time-window lower bound or centre as Julian date. For NumPy inputs, one is required to construct the time axis; jd_min takes priority. Raw preprocessing also accepts astropy Time values.

None
jd_center float

Time-window lower bound or centre as Julian date. For NumPy inputs, one is required to construct the time axis; jd_min takes priority. Raw preprocessing also accepts astropy Time values.

None
n_times_select int

Raw time-window width, paired with an index, lower bound or centre.

None
form_pi bool

Form pseudo-Stokes I from raw XX and YY, or retain existing pI. Defaults to True; otherwise select pol.

True
pi_norm float

Scale in pI = pi_norm * (XX + YY); defaults to 1, not 1/2.

1.0
pol str

Raw polarisation selected when form_pi=False; defaults to 'xx'.

'xx'
redundant_avg bool

Average redundant raw baselines; defaults to False.

False
uniform_redundancy bool

Use unit redundancy weights even after averaging; defaults to False.

False
n_freq (int, float, float)

Required NumPy frequency-axis length, first frequency and spacing in MHz. For a single raw channel, df_mhz supplies its spacing.

None
f0_mhz (int, float, float)

Required NumPy frequency-axis length, first frequency and spacing in MHz. For a single raw channel, df_mhz supplies its spacing.

None
df_mhz (int, float, float)

Required NumPy frequency-axis length, first frequency and spacing in MHz. For a single raw channel, df_mhz supplies its spacing.

None
n_t (int, float)

Required NumPy time-axis length and cadence in seconds. d_t also supplies raw single-integration cadence (otherwise returned as zero).

None
d_t (int, float)

Required NumPy time-axis length and cadence in seconds. d_t also supplies raw single-integration cadence (otherwise returned as zero).

None
save_vis bool

Save raw preprocessing products: visibility/noise vectors and/or baseline, redundancy and antenna-pair arrays. Defaults to False. These hooks do not save subsequently generated synthetic noise.

False
save_model bool

Save raw preprocessing products: visibility/noise vectors and/or baseline, redundancy and antenna-pair arrays. Defaults to False. These hooks do not save subsequently generated synthetic noise.

False
save_dir Path or str

Directory for requested raw preprocessing products; defaults to './'.

'./'
clobber bool

Allow replacement of those saved products; defaults to False.

False

Returns:

Type Description
dict

vis is the loaded complex128 vector in mK sr; vis_noisy is either that vector or vis + noise. noise is the supplied, estimated or generated vector in matching order. bl_conj_pairs_map records synthetic-noise baseline pairing, otherwise it is empty. uvws contains metre coordinates, shape (n_t, n_baseline, 3), and redundancy contains aligned baseline weights. antpairs holds baseline labels if available. freqs_hz and jds are the frequency and Julian-date axes; df_hz and dt are their spacings in Hz and seconds. uvd is the processed raw UVData object, or None for NumPy.

Notes

Raw selection and conversion are delegated to preprocess_uvdata. NumPy inputs bypass these steps and must already match the model's row ordering and Hermitian augmentation; stored metadata are not used to infer the axes. NumPy dictionary inputs are unpickled: load trusted files only. This loader does not turn partial flags into per-visibility noise weights.

bayeseor_jax.data.vis.preprocess_uvdata

preprocess_uvdata(filepath, antenna_selection='cross', bl_cutoff=None, freq_idx_min=None, freq_min=None, freq_center=None, n_freqs_select=None, jd_idx_min=None, jd_min=None, jd_center=None, n_times_select=None, form_pi=True, pi_norm=1.0, pol='xx', redundant_avg=False, uniform_redundancy=False, calc_noise=False, return_uvd=False, save_vis=False, save_model=False, save_dir='./', clobber=False)

Read visibility data from disk and form a one-dimensional data vector.

This function loads a pyuvdata-compatible file containing visibilities for a set of baselines (Nbls), times (Ntimes), and frequencies (Nfreqs) and forms a one-dimensional data vector with shape (2*Nbls * Ntimes * Nfreqs,) and an accompanying instrument model of baseline coordinates in metres and a redundancy model (when averaging redundant baselines). The factor of two comes from appending conjugate visibilities at reversed baselines (u, v, w) -> (-u, -v, -w). These are redundant copies of the measurements, not independent observations. Time is the slowest axis, frequency next, and baseline fastest.

Optionally, if calc_noise is True, a noise vector is also produced. The noise is estimated by differencing visibilities at even and odd time steps per baseline and frequency.

Parameters:

Name Type Description Default
filepath Path or str

Path read by pyuvdata (normally UVH5, UVFITS or a Measurement Set). Unlike get_vis_data, this lower-level function delegates format detection directly to UVData.read. Input units must be Jy or K sr.

required
antenna_selection str

Antenna downselect string. This determines what baselines to keep in the data vector. Please see pyuvdata.UVData.select for more details. Defaults to 'cross' (cross-correlation baselines only).

'cross'
bl_cutoff Quantity or float

Cutoff on sqrt(u2 + v2), in metres if not a Quantity. Defaults to None (keep all baselines).

None
freq_idx_min int

Minimum frequency channel index to keep in the data vector. Defaults to None (keep all frequencies).

None
freq_min Quantity or float

Minimum frequency to keep in the data vector in Hertz if not a Quantity. All frequencies greater than or equal to freq_min will be kept, unless n_freqs_select is specified. Defaults to None (keep all frequencies).

None
freq_center Quantity or float

Central frequency, in Hertz if not a Quantity, around which n_freqs_select frequencies will be kept in the data vector. n_freqs_select must also be passed, otherwise an error is raised. Defaults to None (keep all frequencies).

None
n_freqs_select int

Number of frequencies to keep starting from freq_idx_min, the channel corresponding to freq_min, or around freq_center. Defaults to None (keep all frequencies).

None
jd_idx_min int

Minimum time index to keep in the data vector. Defaults to None (keep all times).

None
jd_min Time or float

Minimum time to keep in the data vector as a Julian date if not a Time. Defaults to None (keep all times).

None
jd_center Time or float

Central time, as a Julian date if not a Time, around which n_times_select times will be kept in the data vector. n_times_select must also be passed, otherwise an error is raised. Defaults to None (keep all times).

None
n_times_select int

Number of times to keep starting from jd_idx_min, the time corresponding to jd_min or around jd_center. Defaults to None (keep all times).

None
form_pi bool

Form pseudo-Stokes I visibilities. Otherwise, use the polarization specified by pol. Defaults to True.

True
pi_norm float

Normalization, N, used in forming pseudo-Stokes I from XX and YY via pI = N * (XX + YY). Defaults to 1.0.

1.0
pol str

Case-insensitive polarization string. Used only if form_pi is False. Defaults to 'xx'.

'xx'
redundant_avg bool

Redundantly average the data. Defaults to False.

False
uniform_redundancy bool

Force the redundancy model to be uniform. Defaults to False.

False
calc_noise bool

Calculate a noise estimate from the visibilities via differencing adjacent times per baseline and frequency. Defaults to False.

False
return_uvd bool

Return the preprocessed UVData object. Defaults to False.

False
save_vis bool

Write visibility vector to disk in save_dir. If calc_noise is True, also save the noise vector. Defaults to False.

False
save_model bool

Write instrument model (antenna pairs, (u, v, w) sampling, and redundancy model) to disk in save_dir. Defaults to False.

False
save_dir Path or str

Output directory if save_vis or save_model is True. Defaults to './'.

'./'
clobber bool

Clobber files on disk if they exist. Defaults to False.

False

Returns:

Name Type Description
vis ndarray

Complex visibility vector in mK sr, shape (2NblsNfreqs*Ntimes,).

antpairs list of tuple

List of antenna pair tuples corresponding to the (u, v, w) coordinates in uvws, in identical order, with length (2*Nbls).

uvws ndarray

Baseline coordinates in metres, shape (Ntimes, 2*Nbls, 3). The ordering of the Nbls axis matches the ordering of the baselines in vis.

redundancy ndarray

Redundancy model containing the number of baselines averaged within a redundant baseline group, shape (Ntimes, 2*Nbls, 1).

noise ndarray or None

Estimated noise vector with shape (2NblsNfreqs*Ntimes,). Returned as None when calc_noise is False.

uvd UVData or None

Preprocessed UVData object. Returned only if return_uvd is True.

Notes

This path assumes a common set of baselines at every selected time and unprojected drift-scan geometry. Fully flagged baselines are removed, but individual flagged samples are not masked or assigned zero weight here. The returned UVData data array has been converted to mK sr; its original vis_units label is not updated. Use the returned vector for inference.

Instrument

bayeseor_jax.model.instrument.baselines.InstrumentModel

Load a BayesEoR instrument model.

The instrument model consists of: - (u, v, w) array with shape (nt, nbls, 3) where nt is the number of times and nbls is the number of baselines - Number of redundantly-averaged baselines per (u, v, w) with shape (nt, nbls) or (nt, nbls, 1) - (optional) a list of antenna pair tuples with length nbls matching the order of baselines in the (u, v, w) array

This class first looks for an instrument_model.npy pickled dictionary in inst_model_dir. If not found, it then loads the individual numpy arrays specified by uvw_file, red_file, and antpairs_file.

Parameters:

Name Type Description Default
inst_model_dir Path or str

Path to the instrument model directory.

required
uvw_file str

File containing instrumentally sampled (u, v, w) coords. Defaults to 'uvw_model.npy'.

'uvw_model.npy'
red_file str

File containing baseline redundancy info. Defaults to 'redundancy_model.npy'.

'redundancy_model.npy'
antpairs_file str

File containing baseline antenna pairs for each sampled (u, v, w). Defaults to 'antpairs.npy'.

'antpairs.npy'

Attributes:

Name Type Description
uvw_array_m Array

Sampled (u, v, w) coordinates in meters with shape (nt, nbls, 3).

bl_red_array Array

Number of redundantly-averaged baselines per (u, v, w) with shape (nt, nbls).

antpairs array - like or None

Baseline antenna pair tuples if antpairs_file is found in inst_model_dir, otherwise None.

n_t property

n_t: int

Return the number of time integrations in the loaded baseline array.

Returns:

Type Description
int

Length of the time axis of uvw_array_m.

n_bls property

n_bls: int

Return the number of sampled baselines per integration.

Returns:

Type Description
int

Length of the baseline axis of uvw_array_m.

__init__

__init__(inst_model_dir: Path | str, uvw_file: str = 'uvw_model.npy', red_file: str = 'redundancy_model.npy', antpairs_file: str = 'antpairs.npy') -> None

Load sampled baselines and redundancy weights from saved NumPy arrays.

Parameters:

Name Type Description Default
inst_model_dir Path or str

Directory containing an instrument_model.npy dictionary or separate coordinate, redundancy, and optional antenna-pair files.

required
uvw_file str

Coordinate file relative to the directory; defaults to uvw_model.npy. Coordinates are in metres, not wavelengths.

'uvw_model.npy'
red_file str

Redundancy file; defaults to redundancy_model.npy.

'redundancy_model.npy'
antpairs_file str

Optional antenna-pair file; defaults to antpairs.npy.

'antpairs.npy'

Returns:

Type Description
None

Populates the instance with validated baseline arrays.

Notes

A combined dictionary takes precedence over separate files. The time and baseline axes are preserved so visibility rows, noise weights, and forward-operator rows refer to the same measurements.

bayeseor_jax.model.instrument.beam.Beam_Model

Supply the beam weights multiplying image-domain sky brightness.

Parameters:

Name Type Description Default
beam_type str

Supported beam types are:

  • uniform: unit power response above the horizon (the default).
  • gaussian: Gaussian profile with a specified angular width or an aperture-derived, frequency-dependent width.
  • airy: Airy power pattern for a circular aperture.
  • gausscosine: Gaussian profile modulated by a cosine-squared response.
  • taperairy: Airy power pattern multiplied by a Gaussian taper.
  • tanhairy: Airy power pattern multiplied by a hyperbolic-tangent taper.
  • A beamfits file path: an arbitrary tabulated beam loaded through pyuvdata.UVBeam and interpolated onto the sky-pixel directions and observing frequencies. Both HEALPix and azimuth/zenith-angle beam grids are supported; pol selects the polarisation and freq_interp_kind selects the frequency interpolation method (cubic by default).
None
peak_amp float

Peak power-response amplitude for Gaussian-based profiles. Defaults to 1.0; the uniform and untapered Airy profiles have unit peak.

1.0
fwhm_deg float

Full width at half maximum in degrees. Gaussian-based profiles use this width when supplied, otherwise deriving a width from diam.

None
diam float

Antenna (aperture) diameter in meters. Used if beam_type is 'airy'.

None
cosfreq float

Cosine frequency in inverse radians. Used if beam_type is 'gausscosine'.

None
tanh_freq float

Exponential frequency (rate parameter) in inverse radians. Used if beam_type is 'tanhairy'.

None
tanh_sl_red float

Fractional suppression of the Airy power response far from zenith. Used if beam_type is 'tanhairy'.

None
pol str

Polarization string. Used only if beam_type is a UVBeam file path. Defaults to 'xx'.

'xx'
freq_interp_kind str

Frequency interpolation kind from scipy.interpolate.interp1d. Defaults to 'cubic'.

'cubic'
Notes

Analytic profiles or an interpolated UVBeam power model are evaluated at each pixel's topocentric direction and observing frequency. get_beam_vals returns the diagonal entries of the primary-beam operator; it does not allocate a dense diagonal matrix.

__init__

__init__(beam_type: str | None = None, peak_amp: float = 1.0, fwhm_deg: float | None = None, diam: float | None = None, cosfreq: float | None = None, tanh_freq: float | None = None, tanh_sl_red: float | None = None, pol: str = 'xx', freq_interp_kind: str = 'cubic') -> None

Configure an analytic profile or load the selected UVBeam polarisation.

Parameters:

Name Type Description Default
beam_type str or None

Analytic beam name or beamfits file path. None selects a uniform beam.

None
peak_amp float

Peak power gain for Gaussian-based beam profiles; defaults to 1.

1.0
fwhm_deg float or None

Configured beam full width at half maximum in degrees, when used instead of an aperture-derived width.

None
diam float or None

Physical or effective aperture diameter in metres for Airy or Gaussian beam profiles.

None
cosfreq float or None

Angular modulation frequency in inverse radians for the gausscosine profile.

None
tanh_freq float or None

Angular taper rate in inverse radians for the tanhairy profile.

None
tanh_sl_red float or None

Fractional far-off-axis power suppression for the tanhairy profile.

None
pol str

Polarisation selected from a file-backed beam, for example xx or pI.

'xx'
freq_interp_kind str

Frequency interpolation method used by UVBeam; defaults to cubic.

'cubic'

Returns:

Type Description
None

Initialises the instance without returning a value.

Notes

Pixel gains are evaluated later by get_beam_vals. File-backed electric-field beams are converted to the requested power or pseudo-Stokes response before interpolation.

get_beam_vals

get_beam_vals(coords: ndarray, freqs: ndarray) -> jnp.ndarray

Weight each HEALPix sky direction by the beam at every frequency.

Parameters:

Name Type Description Default
coords ndarray

Shape (n_t, 2, n_pix) containing [az, za] in radians.

required
freqs ndarray

Shape (n_freq,) in Hz.

required

Returns:

Name Type Description
beam_vals ndarray

Dimensionless power response, shape (n_freq, n_t, n_pix). The forward-operator builder reorders the first two axes before multiplying these gains by the fringe response.

Notes

For each integration, use the pixel's azimuth and zenith angle to evaluate P(nu, t, p). Set the response to zero where the zenith angle is at least pi/2, including pixels that cross the horizon during the observation.

aperture_width_uv

aperture_width_uv(freqs_hz: ndarray, gaussian_nsigma: float = 5.0) -> float

Estimate the transverse Fourier extent added by primary-beam weighting.

Parameters:

Name Type Description Default
freqs_hz array - like

One-dimensional observing-frequency array in Hz.

required
gaussian_nsigma float

Number of Gaussian standard deviations used to define the beam support in uv space. Defaults to 5.

5.0

Returns:

Type Description
float

Approximate beam-support width in uv units. Returns 0.0 for uniform beams and UVBeam file inputs, where no simple analytic aperture-width estimate is available.

Notes

This quantity supplies the buffer around measured baselines when choosing the cosmological uv grid. Airy-like beams contribute an aperture width equal to the effective dish diameter in wavelengths, while Gaussian-like beams contribute Nsigma / (2πσ) using the broadest angular width at the lowest observing frequency.

Simulated noise

bayeseor_jax.data.noise.generate_gaussian_noise

generate_gaussian_noise(sigma: float, s: ndarray, n_freq: int, n_t: int, uvw_array_m: ndarray, bl_red_array: ndarray, random_seed: int | None = None) -> tuple[jnp.ndarray, jnp.ndarray, dict[int, int]]

Generate and add Hermitian complex Gaussian noise to a noiseless vector.

The random draw intentionally follows the old BayesEoR NumPy implementation so the realized noise matches the original pipeline for the same sigma and random_seed:

  • real part seeded with random_seed
  • imaginary part seeded with random_seed * 123 (123 for a seed of 0)

Parameters:

Name Type Description Default
sigma float

RMS amplitude for the complex noise. Real and imaginary components are drawn with standard deviation sigma/sqrt(2).

required
s Array

Noiseless visibility vector with shape (n_t * n_freq * n_bls,).

required
n_freq int

Number of frequency channels.

required
n_t int

Number of time integrations.

required
uvw_array_m Array

UVW coordinates in meters, shape (n_bls, 3) or (n_t, n_bls, 3).

required
bl_red_array Array

Baseline redundancy array with shape (n_t, n_bls), (n_t, n_bls, 1), (n_bls,), or (n_bls, 1).

required
random_seed int or None

Seed for deterministic noise generation.

None

Returns:

Name Type Description
d Array

Noisy visibility vector d = s + n.

complex_noise_hermitian Array

Generated Hermitian noise vector with the same shape as s.

bl_conjugate_pairs_map dict[int, int]

Map from baseline index to its conjugate baseline index.