Spherical data cubes (ps_eor.sphcube)#

Frequency-dependent sky data in HEALPix and spherical harmonics.

This module is the spherical counterpart of ps_eor.datacube. SphImageCube stores HEALPix maps shaped (n_freqs, 12 * nside**2), while SphDataCube stores their complex spherical-harmonic coefficients as (n_freqs, n_modes) with matching (ell, m) coordinates. In a harmonic cube, the transverse spatial coordinate used by the power-spectrum code is u = ell / (2 pi).

A Cartesian visibility cube can be reprojected to HEALPix and transformed to spherical harmonics when a large field of view makes a flat-sky treatment inappropriate:

from ps_eor import sphcube

alm_cube = sphcube.SphDataCube.from_cartcube(
    cart_cube,
    nside=128,
    lmax=600,
)
alm_cube.filter_lm(lmin=20, lmax=500)
alm_cube.save('spherical-visibilities.h5')

The transformation can be reversed for inspection. mask_corrected=True divides by the recorded sky window where its response is sufficiently large:

sky_cube = alm_cube.image(
    mask_corrected=True,
    mask_correction_threshold=.1,
)
sky_cube.plot(fmhz='med')

For multiple observations on the same harmonic grid, SphDataCubeCombiner forms a weighted mean over their common frequency channels. Most filter_* methods modify a spherical cube in place; copy it first when the unfiltered cube must be retained.

class ps_eor.sphcube.SphMetaData(metadata)[source]#

Bases: object

Observation metadata associated with a spherical data cube.

Metadata may describe several accumulated observations. Per-observation pointing, duration, window, and weight fields are stored as lists, while the HEALPix geometry, integration time, coordinate system, and frequency width are shared.

property nside#

HEALPix nside.

property int_time#

Integration time in seconds.

property total_time#

Stored total time, or the sum of observation durations, in seconds.

property freq_width#

Frequency-channel width in Hz.

property win_fct#

Combined SphWindowFunction reconstructed from the metadata.

static new_obs(mjd_obs, radec_obs, time_obs, int_time, nside, win_fct, fwhm, freq_width, coord_sys='ICRS', weight=1)[source]#

Create metadata for one observation.

Parameters:
  • mjd_obs – Observation reference time in MJD.

  • radec_obs – Pointing (RA, Dec) in degrees.

  • time_obs – Observation duration in seconds.

  • int_time – Integration time in seconds.

  • nside – HEALPix resolution.

  • win_fct – Window name, or None for a unit mask.

  • fwhm – Window full-width at half-maximum in radians.

  • freq_width – Frequency-channel width in Hz.

  • coord_sys – Astropy coordinate-system identifier.

  • weight – Relative observation weight.

Returns:

Metadata containing the new observation.

Return type:

SphMetaData

add_obs(mjd_obs, radec_obs, time_obs, win_fct, fwhm, weight=1)[source]#

Append one observation.

Parameters:
  • mjd_obs – Observation reference time in MJD.

  • radec_obs – Pointing (RA, Dec) in degrees.

  • time_obs – Observation duration in seconds.

  • win_fct – Window name, or None.

  • fwhm – Window FWHM in radians.

  • weight – Relative observation weight.

iter_obs(keys)[source]#

Yield the requested fields for each observation.

Parameters:

keys – Ordered metadata keys to return.

Yields:

list – Values corresponding to keys for one observation.

get(key)[source]#

Return metadata field key.

add_weight(weight)[source]#

Multiply every observation weight by weight.

items()[source]#

Return the metadata key-value pairs.

copy()[source]#

Return a deep copy of the metadata.

class ps_eor.sphcube.NoMask[source]#

Bases: Mask

Spherical mask that leaves every pixel unchanged.

generate(meta_data)[source]#

Generate a unit HEALPix mask at meta_data.nside.

class ps_eor.sphcube.NoPrimaryBeam[source]#

Bases: BasePrimaryBeam, NoMask

Spherical primary-beam model with unit response.

class ps_eor.sphcube.SphWindowFunction(name, ra_dec, fwhm, weight=1, primary_beam=None)[source]#

Bases: Mask

Azimuthally symmetric sky window centred on a pointing.

static from_meta(meta, primary_beam=None)[source]#

Reconstruct the combined window recorded in spherical metadata.

Parameters:
  • metaSphMetaData containing observation windows.

  • primary_beam – Optional beam to include in every window.

Returns:

Sum of the per-observation windows.

Return type:

ps_eor.datacube.Mask

generate_window(nside, pb_fwhm=None, oversample=2)[source]#

Generate the HEALPix window map.

Parameters:
  • nside – HEALPix resolution.

  • pb_fwhm – Optional primary-beam FWHM in radians.

  • oversample – Radial window-sampling factor.

Returns:

Window map with 12 * nside**2 pixels.

Return type:

ndarray

generate(meta_data, freq=None)[source]#

Generate the window for the supplied metadata and frequency.

Parameters:
  • meta_data – Spherical metadata defining nside.

  • freq – Frequency in Hz, used for a frequency-dependent primary beam.

Returns:

HEALPix window map.

Return type:

ndarray

class ps_eor.sphcube.SphDataCube(alm_cube, ll, mm, freqs, meta, weights=None)[source]#

Bases: DataCube

Frequency cube of spherical-harmonic coefficients.

The data shape is (n_freqs, n_modes). Each column is identified by the corresponding entries of ll and mm.

get_unique_xy()[source]#

Return per-mode keys used to match (ell, m) between cubes.

static from_cartcube(cube, nside, lmax, reproject_order='bilinear')[source]#

Reproject a Cartesian cube and transform it to spherical harmonics.

The Cartesian cube is imaged, reprojected onto an ICRS HEALPix grid, and transformed independently at every frequency. Pixels outside the Cartesian footprint are set to zero.

Parameters:
  • cubeCartDataCube to transform.

  • nside – Output HEALPix resolution.

  • lmax – Maximum spherical-harmonic degree.

  • reproject_order – Interpolation order accepted by reproject.reproject_to_healpix().

Returns:

Harmonic cube with observation metadata derived from the Cartesian input.

Return type:

SphDataCube

new_with_data(data, weights=None, freqs=None)[source]#

Create a cube on the same harmonic grid with new data.

Parameters:
  • data – Replacement array shaped (n_freqs, n_modes).

  • weights – Optional replacement weights.

  • freqs – Optional replacement frequencies in Hz.

Returns:

The new cube.

Return type:

SphDataCube

filter_outliers(outliers)[source]#

Remove frequency channels selected by outliers in place.

filter_uv_from_index(idx_uv)[source]#

Keep the spatial modes selected by idx_uv in place.

filter_uvrange(umin, umax)[source]#

Keep ell / (2 pi) within [umin, umax] in place.

filter_lm(lmin, lmax)[source]#

Keep modes with ell within [lmin, lmax] in place.

filter_m_theta_max(theta_max)[source]#

Keep azimuthal modes supported within theta_max in place.

Parameters:

theta_max – Maximum angular distance in radians.

static load(filename)[source]#

Load a spherical-harmonic cube from HDF5.

Parameters:

filename – Input HDF5 filename.

Returns:

The restored coefficients and metadata.

Return type:

SphDataCube

save(filename)[source]#

Save the spherical-harmonic cube to HDF5.

Parameters:

filename – Destination HDF5 filename.

plot_lm(fmhz='med', action_fct=None, ax=None, title=None, **kargs)[source]#

Plot real coefficients on the (ell, m) plane.

Parameters:
  • fmhz – Frequency in MHz, or 'med' or 'first'. Ignored when action_fct is supplied.

  • action_fct – Optional reduction called as action_fct(data, axis=0).

  • ax – Matplotlib axes; a new one is created by default.

  • title – Optional axes title.

  • **kargs – Arguments passed to matplotlib.axes.Axes.imshow().

regrid()[source]#

Return this cube; spherical coefficients need no UV regridding.

image(mask_corrected=False, mask_correction_threshold=0.1)[source]#

Transform the coefficients to a HEALPix image cube.

Parameters:
  • mask_corrected – Divide by the recorded window where it is reliable.

  • mask_correction_threshold – Correct pixels above this fraction of the peak window response and set the others to zero.

Returns:

Frequency-dependent HEALPix maps.

Return type:

SphImageCube

class ps_eor.sphcube.SphImageCube(hmaps, freqs, meta)[source]#

Bases: ImageCube

Frequency cube of HEALPix sky maps.

The data shape is (n_freqs, 12 * nside**2).

apply_window_function(win_fct, add_to_meta=True)[source]#

Apply a sky window in place.

Parameters:
  • win_fctSphWindowFunction to multiply into every map.

  • add_to_meta – Record the window as another observation in the metadata.

ft(umin, umax)[source]#

Transform the maps to spherical harmonics over a UV range.

The transform uses lmax = int(2 pi umax) and then retains modes whose ell / (2 pi) lies within the requested interval.

Parameters:
  • umin – Spatial-frequency limits in wavelengths.

  • umax – Spatial-frequency limits in wavelengths.

Returns:

The selected harmonic coefficients.

Return type:

SphDataCube

plot(fmhz='med', action_fct=None, dpar=None, dmer=None, title='', vmax=None, vmin=None, ax=None, auto_scale_quantiles=None, coord='CG', **kargs)[source]#

Plot one frequency map or a reduction over frequency.

Parameters:
  • fmhz – Frequency in MHz, or 'med' or 'first'. Ignored when action_fct is supplied.

  • action_fct – Optional reduction called as action_fct(data, axis=0).

  • dpar – HEALPix graticule spacing.

  • dmer – HEALPix graticule spacing.

  • title – Plot title.

  • vmax – Explicit color limits.

  • vmin – Explicit color limits.

  • ax – Matplotlib axes; a new one is created by default.

  • auto_scale_quantiles – Optional (low, high) quantiles used as color limits.

  • coord – HEALPix coordinate conversion passed to healpy.mollview().

  • **kargs – Additional arguments passed to healpy.mollview().

plot_slice(ax=None, min_dec=-20, npix=1000)[source]#

Plot a declination-frequency slice through the pointing centre.

Parameters:
  • ax – Matplotlib axes; a new one is created by default.

  • min_dec – Lowest declination in degrees.

  • npix – Number of samples along each half of the great-circle slice.

copy()[source]#

Return a deep copy of the map data and metadata.

class ps_eor.sphcube.SphDataCubeCombiner[source]#

Bases: object

Accumulate weighted spherical cubes on their common frequencies.

get_inter_idx(freqs1, freqs2)[source]#

Return masks selecting the common frequencies of two arrays.

add(cube, weight)[source]#

Add a weighted cube to the accumulator.

Only channels common to all cubes accumulated so far are retained. Cubes are expected to share the same (ell, m) grid.

Parameters:
  • cubeSphDataCube to accumulate.

  • weight – Scalar weight applied to the complete observation.

get()[source]#

Return the weighted mean of the accumulated cubes.

Returns:

Combined data on the common frequency and harmonic grid.

Return type:

SphDataCube