DelaySpectrum Class

DelaySpectrum is the main user class for power spectrum estimation. It performs linear Four Transforms normalized by the units of the accompanying measurements.

class simpleDS.DelaySpectrum(uv=None, uvb=None, trcvr=None, taper=None)[source]

A Delay Spectrum object to hold relevant data.

If only one UVData Object is specified, data is multiplied by itself.

Parameters
  • uv1 (pyuvdata object, list of no more than 2 pyuvdata objects, optional) – Objects to cross correlate. Assumes all baselines in UVData object will be cross multiplied togeter, required to have only one reduntant group as computed with pyuvdata redundancy functions. input during initialization is optional, but must be set later with add_uvdata()

  • uvb (UVBeam object, optional) – Containts relevent beam info. Currently assumes 1 beam object can describe all baselines Must be power beam in healpix coordinates and peak normalized. input during initialization is optional, but must be set later with add_uvbeam()

  • trcvr (Astropy Quantity, units: Kelvin, optional) – Receiver Temperature of antenna to calculate noise power input during initialization is optional, but must be set later with add_trcvr()

  • taper (function or Callable, optional) – Spectral taper function used during frequency Fourier Transforms Accepts scipy.signal.windows functions or any function whose argument is the len(data) and returns a numpy array. Default: scipy.signal.windows.blackmanharris but can be overwritten later set_taper()

UnitParameter Objects

For a full list of all attributes, types, and expected forms please consult the documentation at (http://simpleds.readthedocs.io/en/latest/dspec_parameters.html).

add_trcvr(trcvr)[source]

Add the receiver temperature used to generate noise simulation.

Parameters

trcvr (astropy Quantity, units: Kelvin) – (Nspws, Nfreqs) array of temperatures if a single temperature, it is assumed to be constant at all frequencies.

Raises

ValueError – If input trcvr is not a single scalar but also not correctly shaped.

add_uvbeam(uvb, no_read_trcvr=False, use_exact=False, bounds_error=False, fill_value='extrapolate', kind='cubic')[source]

Add the beam_area and beam_square_area integrals into memory.

Also adds receiver temperature information if set in UVBeam object. By default will interpolate the beam_area and beam_sq_area value to the frequencies defined in the DelaySpectrum object.

Exact values from the UVBeam object can be used if frequencies match exactly with the DelaySpectrum object by setting the ‘use_exact’ flag.

Parameters
  • uvb (UVBeam object) – Reads beam_area and beam_sq_area from input UVBeam object. Currently assumes 1 beam object can describe all baselines Must be a power beam in healpix coordinates and peak normalized

  • no_read_trcvr ((Bool, default False)) – Flag to Not read trcvr from UVBeam object even if set in UVBeam. This is useful if a trcvr wants to be manually set but a beam read from a file which also contains receiver temperature information.

  • use_exact (Bool) – Use frequencies exactly out of the UVBeam object. If frequencies are not found use the UVBeam’s interp to interpolate along the frequency dimension.

  • bounds_error (Bool) – scipy.interpolate.interp1d bounds_error flag. When set to True, interpolate will error if new frequencies lay outisde of the bounds of the old frequencies

  • fill_value (float or str) – scipy.interpolate.interp1d fill_value flag. If set to a float, will use that float to fill values outside of the bounds when bounds_error is False. If set to ‘extrapolate’ will extrapolate values outside of the original bounds.

  • kind (str) – scipy.interpolate.interp1d kind flag. defines the type of interpolation (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘previous’, ‘next’)

add_uvdata(uv, spectral_windows=None, tol=1.0)[source]

Add the relevant uvdata object data to DelaySpectrum object.

Unloads the data, flags, and nsamples arrays from the input UVData object (or subclass) into local storage.

Parameters
  • uv (UVdata object) – A UVData object or subclass of UVData to add to the existing datasets

  • spectral_windows (tuple of tuples, or tuple of indices, or list of lists, or list of indices; Default selection is (0, Nfreqs)) – spectral windows ranges like (start_index, end_index) where the indices are the frequency channel numbers.

  • tol (float) – Tolerance in meters of the redundancy allowed for pyuvdata.get_redundancies calculation

Raises

ValueError – Input data object must be an instance or subclass of UVData. If input UVData object has more than 1 unique baseline type within tolerance. Input UVData object has parameters inconsistent with any existing data

calculate_delay_spectrum(run_check=True, run_check_acceptability=True, cosmology=None, littleh_units=False)[source]

Perform Delay tranform and cross multiplication of datas.

Take the normalized Fourier transform of the data in objects and cross multiplies baselines. Also generates white noise given the frequency range and trcvr and calculates the expected noise power.

Parameters
  • cosmology (Astropy.Cosmology subclass) – Default: None (uses cosmology object saved in self.cosmology) Input assumed cosmology Setting this value will overwrite the cosmology set on the DelaySpectrum Object.

  • littleh_units (Bool, default:False) – automatically convert to to mK^2 / (littleh / Mpc)^3. Only applies in python 3.

Raises

ValueError – If called before loading a uvdata object

calculate_noise_power()[source]

Use the radiometry equation to generate the expected noise power.

calculate_thermal_sensitivity()[source]

Calculate the Thermal sensitivity for the power spectrum.

Uses the 21cmsense_calc formula:

Tsys**2/(inttime * Nbls * Npols * sqrt(N_lstbins * 2))

Divide by the following factors:
Nbls:

baselines should coherently add together.

Npols:

number of linear polarizations combined (2 if psuedo-Stokes).

sqrt(2):

noise is split between real and imaginary.

sqrt(lst_bins):

noise power spectrum averages incoherently over time.

check(check_extra=True, run_check_acceptability=True)[source]

Add some extra checks on top of checks on UVBase class.

Check that required parameters exist. Check that parameters have appropriate shapes and optionally that the values are acceptable.

Parameters
  • check_extra (bool) – If true, check all parameters, otherwise only check required parameters.

  • run_check_acceptability (bool) – Option to check if values in parameters are acceptable.

Raises

ValueError – If any parameter values are inconsistent with expected types, shapes, or ranges of values.

delay_transform()[source]

Perform a delay transform on the stored data array.

If data is set to frequency domain, fourier transforms to delay space. If data is set to delay domain, inverse fourier transform to frequency space.

generate_noise()[source]

Simulate noise based on meta-data of observation.

initialize_save_file(filename, overwrite=False, run_check=True, check_extra=True, run_check_acceptability=True, data_compression=None, flags_compression='lzf', nsample_compression='lzf')[source]

Initialize the full hdf5 file onto disk to allow for partial writing.

Parameters
  • filename (str) – Name of file to write.

  • overwrite (bool) – If True will overwrite the file if it already exsits.

  • run_check (bool) – Option to check for the existence and proper shapes of parameters before writing the file. Default is True.

  • check_extra (bool) – Option to check optional parameters as well as required ones. Default is True.

  • run_check_acceptability (bool) – Option to check acceptable range of the values of parameters before writing the file. Default is True.

  • data_compression (str) – HDF5 filter to apply when writing the data_array. Default is None (no filter/compression).

  • flags_compression (str) – HDF5 filter to apply when writing the flags_array. Default is the LZF filter.

  • nsample_compression (str) – HDF5 filter to apply when writing the nsample_array. Default is the LZF filter.

Notes

When partially writing out data, this function should be called first to initialize the file on disk. The data is then actually written by calling the write_partial method, with the same filename as the one specified in this function.

property metadata_only

Property that determines whether this is a metadata only object.

An object is metadata only if data_array, nsample_array and flag_array are all None.

normalized_fourier_transform(inverse=False)[source]

Perform a normalized Fourier Transform along frequency dimension.

Local wrapper for function normalized_fourier_transform. Uses astropy quantities to properly normalize an FFT accounting for the Volume factor and units.

Parameters

inverse (bool, default False) – perform the inverse Fourier Transform with np.fft.ifft

property power_like_parameters

Iterate through defined parameters which are power-like (not metadata-like or power-like).

read(filename, cosmology=None, littleh_units=False, antenna_nums=None, bls=None, spws=None, frequencies=None, freq_chans=None, delays=None, delay_chans=None, lsts=None, lst_range=None, polarizations=None, uv_index=None, read_data=True, run_check=True, check_extra=True, run_check_acceptability=True)[source]

Read a saved DelaySpectrum object from hdf5 file.

Parameters
  • filename (str) – Name of file to read

  • cosmology (Astropy Cosmology Object, optional) – Input assumed cosmology. Must be an astropy cosmology object. Cosmology objects cannot be serialized in hdf5 objects. Input cosmology object is used to perform cosmological normalization when data is read. Defaults to Planck15

  • littleh_units (bool, default: False) – automatically convert to to mK^2 / (littleh / Mpc)^3 if power type arrays are present in the data

  • antenna_nums (array_like of int, optional) – The antennas numbers to keep in the object.

  • bls (array_like of tuple or int, optional) – The baselines to keep in the object. Can either be a tuple of antenna numbers (e.g. (0, 1)) the baseline number or a combination of both.

  • spectral_windows (array_like of int) – The spectral windows to keep in the object.

  • frequencies (Astropy Quantity object, optional) – The frequencies to keep in the object. Values must match frequencies which already exist in the object. Only available when in ‘frequency’ mode

  • freq_chans (array_like of int, optional) – The frequency channel numbers to keep in the object. When multiple spectral windows are present, this will apply to all. Only available when in ‘frequency’ mode

  • delays (Astropy Quantity object, optional) – The delays to keep in the object. Values must match delays which already exist in the object. Only available when in ‘delay’ mode.

  • delay_chans (array_like of int, optional) – The delays channel numbers to keep in the object. When multiple spectral windows are present, this will apply to all. Only available when in ‘delay’ mode.

  • lsts (Astropy Quantity object, optional) – The time to keep in the object. Values must match times which already exist in the object.

  • lst_range (list of Astropy Quantity, optional) – A list of length 2 with start and end times to select. All time values which fall in this range will be selected.

  • polarizations (array_like of int, optional) – The polarizations to keep in the object.

  • uv_index (array_like of int, optional) – The index of the UVData objects to keep on the object.

  • read_data (bool, default: True) – Whether to read the data or return a metadata only object.

  • run_check (bool) – Option to check for the existence and proper shapes of parameters after after reading in the file (the default is True, meaning the check will be run). Ignored if read_data is False.

  • check_extra (bool) – Option to check optional parameters as well as required ones (the default is True, meaning the optional parameters will be checked). Ignored if read_data is False.

  • run_check_acceptability (bool) – Option to check acceptable range of the values of parameters after reading in the file (the default is True, meaning the acceptable range check will be done). Ignored if read_data is False.

remove_cosmology()[source]

Remove cosmological conversion from any power spectrum estimates.

select(antenna_nums=None, bls=None, spws=None, frequencies=None, freq_chans=None, delays=None, delay_chans=None, lsts=None, lst_range=None, polarizations=None, uv_index=None, inplace=False, run_check=True, check_extra=True, run_check_acceptability=True)[source]

Downselect data to keep on the object along various axes.

Axes that can be selected along include antenna names or numbers, antenna pairs, frequencies, times and polarizations. Specific baseline-time indices can also be selected, but this is not commonly used. The history attribute on the object will be updated to identify the operations performed.

Parameters
  • antenna_nums (array_like of int, optional) – The antennas numbers to keep in the object.

  • bls (array_like of tuple or int, optional) – The baselines to keep in the object. Can either be a tuple of antenna numbers (e.g. (0, 1)) the baseline number or a combination of both.

  • spws (array_like of int) – The spectral windows to keep in the object.

  • frequencies (Astropy Quantity object, optional) – The frequencies to keep in the object. Values must match frequencies which already exist in the object. Only available when in ‘frequency’ mode

  • freq_chans (array_like of int, optional) – The frequency channel numbers to keep in the object. When multiple spectral windows are present, this will apply to all. Only available when in ‘frequency’ mode

  • delays (Astropy Quantity object, optional) – The delays to kee in the object. Values must match delays which already exist in the object. Only available when in ‘delay’ mode.

  • delay_chans (array_like of int, optional) – The delays channel numbers to keep in the object. When multiple spectral windows are present, this will apply to all. Only available when in ‘delay’ mode.

  • lsts (Astropy Quantity object, optional) – The time to keep in the object. Values must match times which already exist in the object.

  • lst_range (list of Astropy Quantity, optional) – A list of length 2 with start and end times to select. All time values which fall in this range will be selected.

  • polarizations (array_like of int, optional) – The polarizations to keep in the object.

  • uv_index (array_like of int, optional) – The index of the UVData objects to keep on the object.

  • run_check (bool) – Option to check for the existence and proper shapes of parameters after downselecting data on this object (the default is True, meaning the check will be run).

  • check_extra (bool) – Option to check optional parameters as well as required ones (the default is True, meaning the optional parameters will be checked).

  • run_check_acceptability (bool) – Option to check acceptable range of the values of parameters after downselecting data on this object (the default is True, meaning the acceptable range check will be done).

  • inplace (bool) – Option to perform the select directly on self or return a new DelaySpectrum object with just the selected data (the default is True, meaning the select will be done on self).

select_spectral_windows(spectral_windows=None, freqs=None, inplace=True)[source]

Select the spectral windows from loaded data.

Parameters
  • spectral_windows (tuple of tuples, or tuple of indices, or list of lists, or list of indices; Default selection is (0, Nfreqs)) – Spectral windows ranges like (start_index, end_index) where the indices are the frequency channel numbers.

  • freqs (Quantity array of the shape (Nspws, Nfreqs) units equivalent to frequency, optional) – The frequency values to select from the held data set. Input frequencies must match exactly to some subset of frequencies stored in self.freq_array.

  • inplace (Bool; Default True) – choose whether spectral window selection is done inplace on the object, or a new object is returned.

Returns

DelaySpectrum Object – If inplace is False then returns new object with given spectral windows

Return type

Default None

Raises

ValueError – Spectral window tuples must only have two elements (stard_index, end_index) Spectra windows must all have the same size If given frequencies not present in frequency array.

set_delay()[source]

Set the data type to delay.

Raises

UnitConversionError – if data is inconsistent with delay units.

set_frequency()[source]

Set the data type to frequency.

Raises

UnitConversionError – if data is inconsistent with frequency units.

set_taper(taper=None)[source]

Set spectral taper function used during Fourier Transform.

Parameters

taper (function or Callable, Optional) – Spectral taper function used during frequency Fourier Transforms Accepts scipy.signal.windows functions or any function whose argument is the len(data) and returns a numpy array. Default: scipy.signal.windows.blackmanharris

Raises

ValueError – If taper input is not callable.

property thermal_like_parameters

Iterate through the parameters which are themal-like.

update_cosmology(cosmology=None, littleh_units=False)[source]

Update cosmological information with the assumed cosmology.

Parameters
  • cosmology (Astropy Cosmology Object, optional) – input assumed cosmology. Must be an astropy cosmology object. Defaults to Planck15

  • littleh_units (Bool, default:False) – automatically convert to to mK^2 / (littleh / Mpc)^3.

Raises

ValueError – If input cosomolgy is not an astropy cosmology object

property visdata_like_parameters

Iterate through defined parameters which are visdata-like (not metadata-like or power-like).

write(filename, overwrite=False, run_check=True, check_extra=True, run_check_acceptability=True, data_compression=None, flags_compression='lzf', nsample_compression='lzf')[source]

Write the DelaySpectrum object out to an hdf5 file.

Parameters
  • filename (str) – Name of file to write.

  • overwrite (bool) – If True will overwrite the file if it already exsits.

  • run_check (bool) – Option to check for the existence and proper shapes of parameters before writing the file. Default is True.

  • check_extra (bool) – Option to check optional parameters as well as required ones. Default is True.

  • run_check_acceptability (bool) – Option to check acceptable range of the values of parameters before writing the file. Default is True.

  • data_compression (str) – HDF5 filter to apply when writing the data_array. Default is None (no filter/compression).

  • flags_compression (str) – HDF5 filter to apply when writing the flags_array. Default is the LZF filter.

  • nsample_compression (str) – HDF5 filter to apply when writing the nsample_array. Default is the LZF filter.

write_partial(filename)[source]

Write section of data into an alrady initialized hdf5 file.

Parameters

filename (str) – Name of already initializd file to insert delay spetrum data.