Developer Docs

Documentation for all the under-the-hood classes and functions that most users won’t need to interact with.

Base Classes

These classes are the under-the-hood classes that provide much of the infrastructure for pyuvdata’s user classes.

UVParameter is the base class for the attributes on pyuvdata’s user classes, allowing the attributes to carry information like expected type and shape, acceptable values or ranges and tolerances. We also have some type specific parameter objects (e.g. for angles and earth locations) with extra functionality.

UVBase is the base class for pyuvdata’s user classes which has the common infrastructure to turn the UVParameter attributes into properties and check the attribute shapes and values.

class pyuvdata.parameter.UVParameter(name, required=True, value=None, spoof_val=None, form=(), description='', expected_type=<class 'int'>, acceptable_vals=None, acceptable_range=None, tols=(1e-05, 1e-08), strict_type_check=False)[source]

Data and metadata objects for interferometric data sets.

name

The name of the attribute. Used as the associated property name in classes based on UVBase.

Type

str

required

Flag indicating whether this is required metadata for the class with this UVParameter as an attribute. Default is True.

Type

bool

value

The value of the data or metadata.

spoof_val

A fake value that can be assigned to a non-required UVParameter if the metadata is required for a particular file-type. This is not an attribute of required UVParameters.

form

Either ‘str’ or a tuple giving information about the expected shape of the value. Elements of the tuple may be the name of other UVParameters that indicate data shapes.

Form examples:
  • ‘str’: a string value

  • (‘Nblts’, 3): the value should be an array of shape:

    Nblts (another UVParameter name), 3

Type

‘str’ or tuple

description

Description of the data or metadata in the object.

Type

str

expected_type

The type that the data or metadata should be. Default is int or str if form is ‘str’.

acceptable_vals

List giving allowed values for elements of value.

Type

list, optional

acceptable_range

Tuple giving a range of allowed magnitudes for elements of value.

Type

2-tuple, optional

tols

Tolerances for testing the equality of UVParameters. Either a single absolute value or a tuple of relative and absolute values to be used by np.isclose()

Type

float or 2-tuple of float

strict_type_check

When True, the input expected_type is used exactly, otherwise a more generic type is found to allow changes in precicions or to/from numpy dtypes to not break checks.

Type

bool

apply_spoof()[source]

Set value to spoof_val for non-required UVParameters.

expected_shape(uvbase)[source]

Get the expected shape of the value based on the form.

Parameters

uvbase (object) – Object with this UVParameter as an attribute. Needed because the form can refer to other UVParameters on this object.

Returns

tuple – The expected shape of the value.

check_acceptability()[source]

Check that values are acceptable.

class pyuvdata.parameter.AngleParameter(name, required=True, value=None, spoof_val=None, form=(), description='', expected_type=<class 'int'>, acceptable_vals=None, acceptable_range=None, tols=(1e-05, 1e-08), strict_type_check=False)[source]

Subclass of UVParameter for Angle type parameters.

Adds extra methods for conversion to & from degrees (used by UVBase objects for _degrees properties associated with these parameters).

degrees()[source]

Get value in degrees.

set_degrees(degree_val)[source]

Set value in degrees.

Parameters

degree_val (float) – Value in degrees to use to set the value attribute.

class pyuvdata.parameter.LocationParameter(name, required=True, value=None, spoof_val=None, description='', acceptable_range=(6350000.0, 6390000.0), tols=0.001)[source]

Subclass of UVParameter for Earth location type parameters.

Adds extra methods for conversion to & from lat/lon/alt in radians or degrees (used by UVBase objects for _lat_lon_alt and _lat_lon_alt_degrees properties associated with these parameters).

lat_lon_alt()[source]

Get value in (latitude, longitude, altitude) tuple in radians.

set_lat_lon_alt(lat_lon_alt)[source]

Set value from (latitude, longitude, altitude) tuple in radians.

Parameters

lat_lon_alt (3-tuple of float) – Tuple with the latitude (radians), longitude (radians) and altitude (meters) to use to set the value attribute.

lat_lon_alt_degrees()[source]

Get value in (latitude, longitude, altitude) tuple in degrees.

set_lat_lon_alt_degrees(lat_lon_alt_degree)[source]

Set value from (latitude, longitude, altitude) tuple in degrees.

Parameters

lat_lon_alt (3-tuple of float) – Tuple with the latitude (degrees), longitude (degrees) and altitude (meters) to use to set the value attribute.

check_acceptability()[source]

Check that vector magnitudes are in range.

class pyuvdata.uvbase.UVBase[source]

Base class for objects with UVParameter attributes.

This class is intended to be subclassed and its init method should be called in the subclass init after all associated UVParameter attributes are defined. The init method of this base class creates properties (named using UVParameter.name) from all the UVParameter attributes on the subclass. AngleParameter and LocationParameter attributes also have extra convenience properties defined:

AngleParameter:

UVParameter.name+’_degrees’

LocationParameter:

UVParameter.name+’_lat_lon_alt’ UVParameter.name+’_lat_lon_alt_degrees’

prop_fget(param_name)[source]

Getter method for UVParameter properties.

prop_fset(param_name)[source]

Setter method for UVParameter properties.

degree_prop_fget(param_name)[source]

Degree getter method for AngleParameter properties.

degree_prop_fset(param_name)[source]

Degree setter method for AngleParameter properties.

lat_lon_alt_prop_fget(param_name)[source]

Lat/lon/alt getter method for LocationParameter properties.

lat_lon_alt_prop_fset(param_name)[source]

Lat/lon/alt setter method for LocationParameter properties.

lat_lon_alt_degrees_prop_fget(param_name)[source]

Lat/lon/alt degree getter method for LocationParameter properties.

lat_lon_alt_degrees_prop_fset(param_name)[source]

Lat/lon/alt degree setter method for LocationParameter properties.

required()[source]

Iterate over all required UVParameter attributes.

extra()[source]

Iterate over all non-required UVParameter attributes.

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

Check that required parameters exist and have the correct shapes.

Optionally, check that the values are acceptable.

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

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

  • ignore_requirements (bool) – Do not error if a required parameter isn’t set. This allows the user to run the shape/acceptability checks on parameters in a partially-defined UVData object.

copy()[source]

Make and return a copy of the object.

File Type Specific Classes

These classes inherit from pyuvdata’s user classes and hold the file type specific code. The read and write methods on the user classes convert between the user classes and the file-specific classes automatically as needed, so users generally do not need to interact with these classes, but developers may need to.

class pyuvdata.uvdata.fhd.FHD[source]

Defines a FHD-specific subclass of UVData for reading FHD save files.

This class should not be interacted with directly, instead use the read_fhd method on the UVData class.

read_fhd(filelist, use_model=False, background_lsts=True, read_data=True, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, check_autos=True, fix_autos=True)[source]

Read in data from a list of FHD files.

Parameters
  • filelist (array_like of str) – The list/array of FHD save files to read from. Must include at least one polarization file, a params file, a layout file and a flag file. An obs file is also required if read_data is False.

  • use_model (bool) – Option to read in the model visibilities rather than the dirty visibilities (the default is False, meaning the dirty visibilities will be read).

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • read_data (bool) – Read in the visibility, nsample and flag data. If set to False, only the metadata will be read in. Setting read_data to False results in a metadata only object. If read_data is False, an obs file must be included in the filelist. Note that if read_data is False, Npols is derived from the obs file and reflects the number of polarizations used in the FHD run. If read_data is True, Npols is given by the number of visibility data files provided in filelist.

  • 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).

  • 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 reading in the file (the default is True, meaning the acceptable range check will be done).

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is False.

Raises
  • IOError – If root file directory doesn’t exist.

  • ValueError – If required files are missing or multiple files for any polarization are included in filelist. If there is no recognized key for visibility weights in the flags_file.

class pyuvdata.uvdata.mir.Mir[source]

A class for Mir file objects.

This class defines an Mir-specific subclass of UVData for reading and writing Mir files. This class should not be interacted with directly, instead use the read_mir and write_mir methods on the UVData class.

read_mir(filepath, isource=None, irec=None, isb=None, corrchunk=None, pseudo_cont=False, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, allow_flex_pol=True, check_autos=True, fix_autos=False)[source]

Read in data from an SMA MIR file, and map to the UVData model.

Note that with the exception of filename, the rest of the parameters are used to sub-select a range of data that matches the limitations of the current instantiation of pyuvdata – namely 1 source. This could be dropped in the future, as pyuvdata capabilities grow.

Parameters
  • filepath (str) – The file path to the MIR folder to read from.

  • isource (list of int) – Source code(s) for MIR dataset

  • irec (array-like of int) – Receiver code for MIR dataset

  • isb (array-like of int) – Sideband codes for MIR dataset (0 = LSB, 1 = USB). Default is both sb.

  • corrchunk (array-like of int) – Correlator chunk codes for MIR dataset

  • pseudo_cont (boolean) – Read in only pseudo-continuuum values. Default is false.

  • flex_spw (boolean) – Allow for support of multiple spectral windows. Default is true.

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

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

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

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • allow_flex_pol (bool) – If only one polarization per spectral window is read (and the polarization differs from window to window), allow for the UVData object to use “flexible polarization”, which compresses the polarization-axis of various attributes to be of length 1, sets the flex_spw_polarization_array attribute to define the polarization per spectral window. Default is True.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is False.

write_mir(filename)[source]

Write out the SMA MIR files.

Parameters

filename (str) – The path to the folder on disk to write data to.

class pyuvdata.uvdata.miriad.Miriad[source]

Defines a Miriad-specific subclass of UVData for reading and writing Miriad files.

This class should not be interacted with directly, instead use the read and write_miriad methods on the UVData class.

read_miriad(filepath, antenna_nums=None, ant_str=None, bls=None, polarizations=None, time_range=None, read_data=True, phase_type=None, correct_lat_lon=True, background_lsts=True, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, calc_lst=True, fix_old_proj=False, fix_use_ant_pos=True, check_autos=True, fix_autos=True)[source]

Read in data from a miriad file.

Parameters
  • filepath (str) – The miriad root directory to read from.

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

  • bls (list of tuple, optional) – A list of antenna number tuples (e.g. [(0, 1), (3, 2)]) or a list of baseline 3-tuples (e.g. [(0, 1, ‘xx’), (2, 3, ‘yy’)]) specifying baselines to include when reading data into the object. For length-2 tuples, the ordering of the numbers within the tuple does not matter. For length-3 tuples, the polarization string is in the order of the two antennas. If length-3 tuples are provided, polarizations must be None.

  • ant_str (str, optional) – A string containing information about what antenna numbers and polarizations to include when reading data into the object. Can be ‘auto’, ‘cross’, ‘all’, or combinations of antenna numbers and polarizations (e.g. ‘1’, ‘1_2’, ‘1x_2y’). See tutorial for more examples of valid strings and the behavior of different forms for ant_str. If ‘1x_2y,2y_3y’ is passed, both polarizations ‘xy’ and ‘yy’ will be kept for both baselines (1, 2) and (2, 3) to return a valid pyuvdata object. An ant_str cannot be passed in addition to any of antenna_nums, bls or polarizations parameters, if it is a ValueError will be raised.

  • polarizations (array_like of int or str, optional) – List of polarization integers or strings to read-in. e.g. [‘xx’, ‘yy’, …]

  • time_range (list of float, optional) – len-2 list containing min and max range of times in Julian Date to include when reading data into the object. e.g. [2458115.20, 2458115.40]

  • read_data (bool) – Read in the uvws, times, visibility and flag data. If set to False, only the metadata that can be read quickly (without reading the data) will be read in. For Miriad, some of the normally required metadata are not fast to read in (e.g. uvws, times) so will not be read in if this keyword is False. Therefore, setting read_data to False results in an incompletely defined object (check will not pass).

  • phase_type (str, optional) – Option to specify the phasing status of the data. Options are ‘drift’, ‘phased’ or None. ‘drift’ means the data are zenith drift data, ‘phased’ means the data are phased to a single RA/Dec. Default is None meaning it will be guessed at based on the file contents.

  • correct_lat_lon (bool) – Option to update the latitude and longitude from the known_telescopes list if the altitude is missing.

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • 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.

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • calc_lst (bool) – Recalculate the LST values that are present within the file, useful in cases where the “online” calculate values have precision or value errors. Default is True.

  • fix_old_proj (bool) – Applies a fix to uvw-coordinates and phasing, assuming that the old phase method was used prior to writing the data, which had errors of the order of one part in 1e4 - 1e5. See the phasing memo for more details.

  • fix_use_ant_pos (bool) – If setting fix_old_proj to True, use the antenna positions to derive the correct uvw-coordinates rather than using the baseline vectors. Default is True.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is False.

Raises
  • IOError – If root file directory doesn’t exist.

  • ValueError – If incompatible select keywords are set (e.g. ant_str with other antenna selectors, times and time_range) or select keywords exclude all data or if keywords are set to the wrong type. If the data are multi source or have multiple spectral windows. If the metadata are not internally consistent.

write_miriad(filepath, clobber=False, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, no_antnums=False, calc_lst=False, check_autos=True, fix_autos=False)[source]

Write the data to a miriad file.

Parameters
  • filename (str) – The miriad root directory to write to.

  • clobber (bool) – Option to overwrite the filename if the file already exists.

  • run_check (bool) – Option to check for the existence and proper shapes of parameters after before writing the file (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 before writing the file (the default is True, meaning the acceptable range check will be done).

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • no_antnums (bool) – Option to not write the antnums variable to the file. Should only be used for testing purposes.

  • calc_lst (bool) – Recalculate the LST values upon writing the file. This is done to perform higher-precision accounting for the difference in MIRAD timestamps vs pyuvdata (the former marks the beginning of an integration, the latter marks the midpoint). Default is False, which instead uses a simple formula for correcting the LSTs, expected to be accurate to approximately 0.1 µsec precision.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is False.

Raises
  • ValueError – If the frequencies are not evenly spaced or are separated by more than their channel width.

  • TypeError – If any entry in extra_keywords is not a single string or number.

class pyuvdata.uvdata.ms.MS[source]

Defines a class for reading and writing casa measurement sets.

This class should not be interacted with directly, instead use the read_ms method on the UVData class.

ms_required_extra

Names of optional UVParameters that are required for MS

Type

list of str

write_ms(filepath, force_phase=False, clobber=False, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, check_autos=True, fix_autos=False)[source]

Write a CASA measurement set (MS).

Parameters
  • filepath (str) – The MS file path to write to.

  • force_phase (bool) – Option to automatically phase drift scan data to zenith of the first timestamp.

  • clobber (bool) – Option to overwrite the file if it already exists.

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

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

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

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is False.

read_ms(filepath, data_column='DATA', pol_order='AIPS', background_lsts=True, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, ignore_single_chan=True, raise_error=True, read_weights=True, allow_flex_pol=False, check_autos=True, fix_autos=True)[source]

Read in a casa measurement set.

Parameters
  • filepath (str) – The measurement set root directory to read from.

  • data_column (str) – name of CASA data column to read into data_array. Options are: ‘DATA’, ‘MODEL’, or ‘CORRECTED_DATA’

  • pol_order (str) – Option to specify polarizations order convention, options are ‘CASA’ or ‘AIPS’.

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • 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).

  • 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 reading in the file (the default is True, meaning the acceptable range check will be done).

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • ignore_single_chan (bool) – Some measurement sets (e.g., those from ALMA) use single channel spectral windows for recording pseudo-continuum channels or storing other metadata in the track when the telescopes are not on source. Because of the way the object is strutured (where all spectral windows are assumed to be simultaneously recorded), this can significantly inflate the size and memory footprint of UVData objects. By default, single channel windows are ignored to avoid this issue, although they can be included if setting this parameter equal to True.

  • raise_error (bool) – The measurement set format allows for different spectral windows and polarizations to have different metdata for the same time-baseline combination, but UVData objects do not. If detected, by default the reader will throw an error. However, if set to False, the reader will simply give a warning, and will use the first value read in the file as the “correct” metadata in the UVData object.

  • read_weights (bool) – Read in the weights from the MS file, default is True. If false, the method will set the nsamples_array to the same uniform value (namely 1.0).

  • allow_flex_pol (bool) – If only one polarization per spectral window is read (and the polarization differs from window to window), allow for the UVData object to use “flexible polarization”, which compresses the polarization-axis of various attributes to be of length 1, sets the flex_spw_polarization_array attribute to define the polarization per spectral window. Default is True.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is True.

Raises
  • IOError – If root file directory doesn’t exist.

  • ValueError – If the data_column is not set to an allowed value. If the data are have multiple subarrays or are multi source or have multiple spectral windows. If the data have multiple data description ID values.

class pyuvdata.uvdata.mwa_corr_fits.MWACorrFITS[source]

UVData subclass for reading MWA correlator fits files.

This class should not be interacted with directly; instead use the read_mwa_corr_fits method on the UVData class.

correct_cable_length(cable_lens, ant_1_inds, ant_2_inds)[source]

Apply a cable length correction to the data array.

Parameters
  • cable_lens (list of strings) – A list of strings containing the cable lengths for each antenna.

  • ant_1_inds (array) – An array of indices for antenna 1

  • ant_2_inds (array) – An array of indices for antenna 2

flag_init(num_fine_chan, edge_width=80000.0, start_flag=2.0, end_flag=0.0, flag_dc_offset=True)[source]

Apply routine flagging to the MWA Correlator FITS file data.

Includes options to flag the coarse channel edges, beginning and end of obs, as well as the center fine channel of each coarse channel.

Parameters
  • edge_width (float) – The width to flag on the edge of each coarse channel, in hz. Set to 0 for no edge flagging.

  • start_flag (float) – The number of seconds to flag at the beginning of the observation. Set to 0 for no flagging.

  • end_flag (floats) – The number of seconds to flag at the end of the observation. Set to 0 for no flagging.

  • flag_dc_offset (bool) – Set to True to flag the center fine channel of each coarse channel.

Raises

ValueError – If edge_width is not an integer multiple of the channel_width of the data (0 also acceptable). If start_flag is not an integer multiple of the integration time (0 also acceptable). If end_flag is not an integer multiple of the integration time (0 also acceptable).

van_vleck_correction(ant_1_inds, ant_2_inds, flagged_ant_inds, cheby_approx, data_array_dtype)[source]

Apply a van vleck correction to the data array.

For an explanation of the Van Vleck corrections used and their implementation in this code, see the memos at https://github.com/EoRImaging/Memos/blob/master/PDFs/007_Van_Vleck_A.pdf and https://github.com/EoRImaging/Memos/blob/master/PDFs/008_Van_Vleck_B.pdf

Parameters
  • ant_1_inds (array) – An array of indices for antenna 1.

  • ant_2_inds (array) – An array of indices for antenna 2.

  • flagged_ant_inds (numpy array of type int) – List of indices of flagged antennas.

  • cheby_approx (bool) – Option to implement the van vleck correction with a chebyshev polynomial. approximation.

  • data_array_dtype (numpy dtype) – Datatype to store the output data_array as.

read_mwa_corr_fits(filelist, use_aoflagger_flags=None, remove_dig_gains=True, remove_coarse_band=True, correct_cable_len=None, correct_van_vleck=False, cheby_approx=True, flag_small_auto_ants=True, phase_to_pointing_center=False, propagate_coarse_flags=True, flag_init=True, edge_width=80000.0, start_flag='goodtime', end_flag=0.0, flag_dc_offset=True, remove_flagged_ants=True, background_lsts=True, read_data=True, data_array_dtype=<class 'numpy.complex64'>, nsample_array_dtype=<class 'numpy.float32'>, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, check_autos=True, fix_autos=True)[source]

Read in MWA correlator gpu box files.

The default settings remove some of the instrumental effects in the bandpass by dividing out the coarse band shape (for legacy data only) and the digital gains, and applying a cable length correction. If the desired output is raw correlator data, set remove_dig_gains=False, remove_coarse_band=False, correct_cable_len=False, and phase_to_pointing_center=False.

Parameters
  • filelist (list of str) – The list of MWA correlator files to read from. Must include at least one fits file and only one metafits file per data set. Can also be a list of lists to read multiple data sets.

  • axis (str) – Axis to concatenate files along. This enables fast concatenation along the specified axis without the normal checking that all other metadata agrees. This method does not guarantee correct resulting objects. Please see the docstring for fast_concat for details. Allowed values are: ‘blt’, ‘freq’, ‘polarization’. Only used if multiple files are passed.

  • use_aoflagger_flags (bool) – Option to use aoflagger mwaf flag files. Defaults to true if aoflagger flag files are submitted.

  • remove_dig_gains (bool) – Option to divide out digital gains.

  • remove_coarse_band (bool) – Option to divide out coarse band shape.

  • correct_cable_len (bool) – Option to apply a cable delay correction.

  • correct_van_vleck (bool) – Option to apply a van vleck correction.

  • cheby_approx (bool) – Only used if correct_van_vleck is True. Option to implement the van vleck correction with a chebyshev polynomial approximation.

  • flag_small_auto_ants (bool) – Only used if correct_van_vleck is True. Option to completely flag any antenna for which the autocorrelation falls below a threshold found by the Van Vleck correction to indicate bad data. Specifically, the threshold used is 0.5 * integration_time * channel_width. If set to False, only the times and frequencies at which the auto is below the threshold will be flagged for the antenna.

  • phase_to_pointing_center (bool) – Option to phase to the observation pointing center.

  • propagate_coarse_flags (bool) – Option to propagate flags for missing coarse channel integrations across frequency.

  • flag_init (bool) – Set to True in order to do routine flagging of coarse channel edges, start or end integrations, or the center fine channel of each coarse channel. See associated keywords.

  • edge_width (float) – Only used if flag_init is True. The width to flag on the edge of each coarse channel, in hz. Errors if not equal to integer multiple of channel_width. Set to 0 for no edge flagging.

  • start_flag (float or str) – Only used if flag_init is True. The number of seconds to flag at the beginning of the observation. Set to 0 for no flagging. Default is ‘goodtime’, which uses information in the metafits file to determine the length of time that should be flagged. Errors if input is not a float or ‘goodtime’. Errors if float input is not equal to an integer multiple of the integration time.

  • end_flag (floats) – Only used if flag_init is True. The number of seconds to flag at the end of the observation. Set to 0 for no flagging. Errors if not equal to an integer multiple of the integration time.

  • flag_dc_offset (bool) – Only used if flag_init is True. Set to True to flag the center fine channel of each coarse channel.

  • remove_flagged_ants (bool) – Option to perform a select to remove antennas flagged in the metafits file. If correct_van_vleck and flag_small_auto_ants are both True then antennas flagged by the Van Vleck correction are also removed.

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • read_data (bool) – Read in the visibility, nsample and flag data. If set to False, only the metadata will be read in. Setting read_data to False results in a metadata only object.

  • data_array_dtype (numpy dtype) – Datatype to store the output data_array as. Must be either np.complex64 (single-precision real and imaginary) or np.complex128 (double-precision real and imaginary).

  • nsample_array_dtype (numpy dtype) – Datatype to store the output nsample_array as. Must be either np.float64 (double-precision), np.float32 (single-precision), or np.float16 (half-precision). Half-precision is only recommended for cases where no sampling or averaging of baselines will occur, because round-off errors can be quite large (~1e-3).

  • 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).

  • 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 reading in the file (the default is True, meaning the acceptable range check will be done).

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is True.

Raises

ValueError – If required files are missing or multiple files metafits files are included in filelist. If files from different observations are included in filelist. If files in fileslist have different fine channel widths If file types other than fits, metafits, and mwaf files are included in filelist.

class pyuvdata.uvdata.uvfits.UVFITS[source]

Defines a uvfits-specific subclass of UVData for reading and writing uvfits.

This class should not be interacted with directly, instead use the read_uvfits and write_uvfits methods on the UVData class.

read_uvfits(filename, antenna_nums=None, antenna_names=None, ant_str=None, bls=None, frequencies=None, freq_chans=None, times=None, time_range=None, lsts=None, lst_range=None, polarizations=None, blt_inds=None, keep_all_metadata=True, read_data=True, background_lsts=True, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, fix_old_proj=False, fix_use_ant_pos=True, check_autos=True, fix_autos=True)[source]

Read in header, metadata and data from a uvfits file.

Supports reading only selected portions of the data.

Parameters
  • filename (str) – The uvfits file to read from.

  • antenna_nums (array_like of int, optional) – The antennas numbers to include when reading data into the object (antenna positions and names for the removed antennas will be retained unless keep_all_metadata is False). This cannot be provided if antenna_names is also provided. Ignored if read_data is False.

  • antenna_names (array_like of str, optional) – The antennas names to include when reading data into the object (antenna positions and names for the removed antennas will be retained unless keep_all_metadata is False). This cannot be provided if antenna_nums is also provided. Ignored if read_data is False.

  • bls (list of tuple, optional) – A list of antenna number tuples (e.g. [(0, 1), (3, 2)]) or a list of baseline 3-tuples (e.g. [(0, 1, ‘xx’), (2, 3, ‘yy’)]) specifying baselines to include when reading data into the object. For length-2 tuples, the ordering of the numbers within the tuple does not matter. For length-3 tuples, the polarization string is in the order of the two antennas. If length-3 tuples are provided, polarizations must be None. Ignored if read_data is False.

  • ant_str (str, optional) – A string containing information about what antenna numbers and polarizations to include when reading data into the object. Can be ‘auto’, ‘cross’, ‘all’, or combinations of antenna numbers and polarizations (e.g. ‘1’, ‘1_2’, ‘1x_2y’). See tutorial for more examples of valid strings and the behavior of different forms for ant_str. If ‘1x_2y,2y_3y’ is passed, both polarizations ‘xy’ and ‘yy’ will be kept for both baselines (1, 2) and (2, 3) to return a valid pyuvdata object. An ant_str cannot be passed in addition to any of antenna_nums, antenna_names, bls args or the polarizations parameters, if it is a ValueError will be raised. Ignored if read_data is False.

  • frequencies (array_like of float, optional) – The frequencies to include when reading data into the object, each value passed here should exist in the freq_array. Ignored if read_data is False.

  • freq_chans (array_like of int, optional) – The frequency channel numbers to include when reading data into the object. Ignored if read_data is False.

  • times (array_like of float, optional) – The times to include when reading data into the object, each value passed here should exist in the time_array.

  • time_range (array_like of float, optional) – The time range in Julian Date to keep in the object, must be length 2. Some of the times in the object should fall between the first and last elements. Cannot be used with times.

  • lsts (array_like of float, optional) – The local sidereal times (LSTs) to keep in the object, each value passed here should exist in the lst_array. Cannot be used with times, time_range, or lst_range.

  • lst_range (array_like of float, optional) – The local sidereal time (LST) range in radians to keep in the object, must be of length 2. Some of the LSTs in the object should fall between the first and last elements. If the second value is smaller than the first, the LSTs are treated as having phase-wrapped around LST = 2*pi = 0, and the LSTs kept on the object will run from the larger value, through 0, and end at the smaller value.

  • polarizations (array_like of int, optional) – The polarizations numbers to include when reading data into the object, each value passed here should exist in the polarization_array. Ignored if read_data is False.

  • blt_inds (array_like of int, optional) – The baseline-time indices to include when reading data into the object. This is not commonly used. Ignored if read_data is False.

  • keep_all_metadata (bool) – Option to keep all the metadata associated with antennas, even those that do not have data associated with them after the select option.

  • read_data (bool) – Read in the visibility, nsample and flag data. If set to False, only the metadata will be read in. Setting read_data to False results in a metadata only object.

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • 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.

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • fix_old_proj (bool) – Applies a fix to uvw-coordinates and phasing, assuming that the old phase method was used prior to writing the data, which had errors of the order of one part in 1e4 - 1e5. See the phasing memo for more details. Default is False.

  • fix_use_ant_pos (bool) – If setting fix_old_proj to True, use the antenna positions to derive the correct uvw-coordinates rather than using the baseline vectors. Default is True.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is True.

Raises
  • IOError – If filename doesn’t exist.

  • ValueError – If incompatible select keywords are set (e.g. ant_str with other antenna selectors, times and time_range) or select keywords exclude all data or if keywords are set to the wrong type. If the data have multi spw with different channel widths. If the metadata are not internally consistent or missing.

write_uvfits(filename, spoof_nonessential=False, write_lst=True, force_phase=False, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, check_autos=True, fix_autos=False)[source]

Write the data to a uvfits file.

If using this method to write out a data set for import into CASA, users should be aware that the importuvifts task does not currently support reading in data sets where the number of antennas is > 255. If writing out such a data set for use in CASA, we suggest using the measurement set writer (UVData.write_ms) instead.

Parameters
  • filename (str) – The uvfits file to write to.

  • spoof_nonessential (bool) – Option to spoof the values of optional UVParameters that are not set but are required for uvfits files. This keyword is now deprecated, as values are automatically set to their best known values if not previously set.

  • write_lst (bool) – Option to write the LSTs to the metadata (random group parameters).

  • force_phase (bool) – Option to automatically phase drift scan data to zenith of the first timestamp.

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

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

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

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is False.

Raises
  • ValueError – The phase_type of the object is “drift” and the force_phase keyword is not set. If the frequencies are not evenly spaced or are separated by more than their channel width. The polarization values are not evenly spaced. If the timesys parameter is set to anything other than “UTC” or None.

  • TypeError – If any entry in extra_keywords is not a single string or number.

class pyuvdata.uvdata.uvh5.UVH5[source]

A class for UVH5 file objects.

This class defines an HDF5-specific subclass of UVData for reading and writing UVH5 files. This class should not be interacted with directly, instead use the read_uvh5 and write_uvh5 methods on the UVData class.

read_uvh5(filename, antenna_nums=None, antenna_names=None, ant_str=None, bls=None, frequencies=None, freq_chans=None, times=None, time_range=None, lsts=None, lst_range=None, polarizations=None, blt_inds=None, keep_all_metadata=True, read_data=True, data_array_dtype=<class 'numpy.complex128'>, multidim_index=False, background_lsts=True, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, fix_old_proj=None, fix_use_ant_pos=True, check_autos=True, fix_autos=True)[source]

Read in data from a UVH5 file.

Parameters
  • filename (str) – The UVH5 file to read from.

  • antenna_nums (array_like of int, optional) – The antennas numbers to include when reading data into the object (antenna positions and names for the removed antennas will be retained unless keep_all_metadata is False). This cannot be provided if antenna_names is also provided. Ignored if read_data is False.

  • antenna_names (array_like of str, optional) – The antennas names to include when reading data into the object (antenna positions and names for the removed antennas will be retained unless keep_all_metadata is False). This cannot be provided if antenna_nums is also provided. Ignored if read_data is False.

  • bls (list of tuple, optional) – A list of antenna number tuples (e.g. [(0, 1), (3, 2)]) or a list of baseline 3-tuples (e.g. [(0, 1, ‘xx’), (2, 3, ‘yy’)]) specifying baselines to include when reading data into the object. For length-2 tuples, the ordering of the numbers within the tuple does not matter. For length-3 tuples, the polarization string is in the order of the two antennas. If length-3 tuples are provided, polarizations must be None. Ignored if read_data is False.

  • ant_str (str, optional) – A string containing information about what antenna numbers and polarizations to include when reading data into the object. Can be ‘auto’, ‘cross’, ‘all’, or combinations of antenna numbers and polarizations (e.g. ‘1’, ‘1_2’, ‘1x_2y’). See tutorial for more examples of valid strings and the behavior of different forms for ant_str. If ‘1x_2y,2y_3y’ is passed, both polarizations ‘xy’ and ‘yy’ will be kept for both baselines (1, 2) and (2, 3) to return a valid pyuvdata object. An ant_str cannot be passed in addition to any of antenna_nums, antenna_names, bls args or the polarizations parameters, if it is a ValueError will be raised. Ignored if read_data is False.

  • frequencies (array_like of float, optional) – The frequencies to include when reading data into the object, each value passed here should exist in the freq_array. Ignored if read_data is False.

  • freq_chans (array_like of int, optional) – The frequency channel numbers to include when reading data into the object. Ignored if read_data is False.

  • times (array_like of float, optional) – The times to include when reading data into the object, each value passed here should exist in the time_array. Cannot be used with time_range.

  • time_range (array_like of float, optional) – The time range in Julian Date to keep in the object, must be length 2. Some of the times in the object should fall between the first and last elements. Cannot be used with times.

  • lsts (array_like of float, optional) – The local sidereal times (LSTs) to keep in the object, each value passed here should exist in the lst_array. Cannot be used with times, time_range, or lst_range.

  • lst_range (array_like of float, optional) – The local sidereal time (LST) range in radians to keep in the object, must be of length 2. Some of the LSTs in the object should fall between the first and last elements. If the second value is smaller than the first, the LSTs are treated as having phase-wrapped around LST = 2*pi = 0, and the LSTs kept on the object will run from the larger value, through 0, and end at the smaller value.

  • polarizations (array_like of int, optional) – The polarizations numbers to include when reading data into the object, each value passed here should exist in the polarization_array. Ignored if read_data is False.

  • blt_inds (array_like of int, optional) – The baseline-time indices to include when reading data into the object. This is not commonly used. Ignored if read_data is False.

  • keep_all_metadata (bool) – Option to keep all the metadata associated with antennas, even those that do not have data associated with them after the select option.

  • read_data (bool) – Read in the visibility, nsample and flag data. If set to False, only the metadata will be read in. Setting read_data to False results in a metadata only object.

  • data_array_dtype (numpy dtype) – Datatype to store the output data_array as. Must be either np.complex64 (single-precision real and imaginary) or np.complex128 (double- precision real and imaginary). Only used if the datatype of the visibility data on-disk is not ‘c8’ or ‘c16’.

  • multidim_index (bool) – If True, attempt to index the HDF5 dataset simultaneously along all data axes. Otherwise index one axis at-a-time. This only works if data selection is sliceable along all but one axis. If indices are not well-matched to data chunks, this can be slow.

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • 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.

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • fix_old_proj (bool) – Applies a fix to uvw-coordinates and phasing, assuming that the old phase method was used prior to writing the data, which had errors of the order of one part in 1e4 - 1e5. See the phasing memo for more details. Default is to apply the correction if the attributes phase_center_app_ra and phase_center_app_dec are missing (as they were introduced alongside the new phasing method).

  • fix_use_ant_pos (bool) – If setting fix_old_proj to True, use the antenna positions to derive the correct uvw-coordinates rather than using the baseline vectors. Default is True.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is True.

Returns

None

Raises
  • IOError – If filename doesn’t exist.

  • ValueError – If the data_array_dtype is not a complex dtype. If incompatible select keywords are set (e.g. ant_str with other antenna selectors, times and time_range) or select keywords exclude all data or if keywords are set to the wrong type.

write_uvh5(filename, clobber=False, chunks=True, data_compression=None, flags_compression='lzf', nsample_compression='lzf', data_write_dtype=None, add_to_history=None, run_check=True, check_extra=True, run_check_acceptability=True, strict_uvw_antpos_check=False, check_autos=True, fix_autos=False)[source]

Write an in-memory UVData object to a UVH5 file.

Parameters
  • filename (str) – The UVH5 file to write to.

  • clobber (bool) – Option to overwrite the file if it already exists.

  • chunks (tuple or bool) – h5py.create_dataset chunks keyword. Tuple for chunk shape, True for auto-chunking, None for no chunking. Default is True.

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

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

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

  • data_write_dtype (numpy dtype) – The datatype of output visibility data. If ‘None’, then the same datatype as data_array will be used. The user may specify ‘c8’ for single-precision floats or ‘c16’ for double-presicion. Otherwise, a numpy dtype object must be specified with an ‘r’ field and an ‘i’ field for real and imaginary parts, respectively. See uvh5.py for an example of defining such a datatype.

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

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

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

  • strict_uvw_antpos_check (bool) – Option to raise an error rather than a warning if the check that uvws match antenna positions does not pass.

  • check_autos (bool) – Check whether any auto-correlations have non-zero imaginary values in data_array (which should not mathematically exist). Default is True.

  • fix_autos (bool) – If auto-correlations with imaginary values are found, fix those values so that they are real-only in data_array. Default is False.

Returns

None

Raises

IOError – If the file located at filename already exists and clobber=False, an IOError is raised.

Notes

The HDF5 library allows for the application of “filters” when writing data, which can provide moderate to significant levels of compression for the datasets in question. Testing has shown that for some typical cases of UVData objects (empty/sparse flag_array objects, and/or uniform nsample_arrays), the built-in LZF filter provides significant compression for minimal computational overhead.

Note that for typical HERA data files written after mid-2020, the bitshuffle filter was applied to the data_array. Because of the lack of portability, it is not included as an option here; in the future, it may be added. Note that as long as bitshuffle is installed on the system in a way that h5py can find it, no action needs to be taken to _read_ a data_array encoded with bitshuffle (or an error will be raised).

initialize_uvh5_file(filename, clobber=False, chunks=True, data_compression=None, flags_compression='lzf', nsample_compression='lzf', data_write_dtype=None)[source]

Initialize a UVH5 file on disk to be written to in parts.

Parameters
  • filename (str) – The UVH5 file to write to.

  • clobber (bool) – Option to overwrite the file if it already exists.

  • chunks (tuple or bool) – h5py.create_dataset chunks keyword. Tuple for chunk shape, True for auto-chunking, None for no chunking. Default is True.

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

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

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

  • data_write_dtype (str or numpy dtype) – The datatype of output visibility data. If ‘None’, then double- precision floats will be used. The user may specify ‘c8’ for single-precision floats or ‘c16’ for double-presicion. Otherwise, a numpy dtype object must be specified with an ‘r’ field and an ‘i’ field for real and imaginary parts, respectively. See uvh5.py for an example of defining such a datatype.

Returns

None

Raises

IOError – If the file located at filename already exists and clobber=False, an IOError is raised.

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_uvh5_part method, with the same filename as the one specified in this function. See the tutorial for a worked example.

The HDF5 library allows for the application of “filters” when writing data, which can provide moderate to significant levels of compression for the datasets in question. Testing has shown that for some typical cases of UVData objects (empty/sparse flag_array objects, and/or uniform nsample_arrays), the built-in LZF filter provides significant compression for minimal computational overhead.

Note that for typical HERA data files written after mid-2018, the bitshuffle filter was applied to the data_array. Because of the lack of portability, it is not included as an option here; in the future, it may be added. Note that as long as bitshuffle is installed on the system in a way that h5py can find it, no action needs to be taken to _read_ a data_array encoded with bitshuffle (or an error will be raised).

write_uvh5_part(filename, data_array, flag_array, nsample_array, check_header=True, antenna_nums=None, antenna_names=None, ant_str=None, bls=None, frequencies=None, freq_chans=None, times=None, time_range=None, lsts=None, lst_range=None, polarizations=None, blt_inds=None, run_check_acceptability=True, add_to_history=None)[source]

Write out a part of a UVH5 file that has been previously initialized.

Parameters
  • filename (str) – The file on disk to write data to. It must already exist, and is assumed to have been initialized with initialize_uvh5_file.

  • data_array (array of float) – The data to write to disk. A check is done to ensure that the dimensions of the data passed in conform to the ones specified by the “selection” arguments.

  • flag_array (array of bool) – The flags array to write to disk. A check is done to ensure that the dimensions of the data passed in conform to the ones specified by the “selection” arguments.

  • nsample_array (array of float) – The nsample array to write to disk. A check is done to ensure that the dimensions fo the data passed in conform to the ones specified by the “selection” arguments.

  • check_header (bool) – Option to check that the metadata present in the header on disk matches that in the object.

  • run_check_acceptability (bool) – If check_header, additional option to check acceptable range of the values of parameters after reading in the file.

  • antenna_nums (array_like of int, optional) – The antennas numbers to include when writing data into the object (antenna positions and names for the excluded antennas will be retained). This cannot be provided if antenna_names is also provided.

  • antenna_names (array_like of str, optional) – The antennas names to include when writing data into the object (antenna positions and names for the excluded antennas will be retained). This cannot be provided if antenna_nums is also provided.

  • bls (list of tuples, optional) – A list of antenna number tuples (e.g. [(0, 1), (3, 2)]) or a list of baseline 3-tuples (e.g. [(0, 1, ‘xx’), (2, 3, ‘yy’)]) specifying baselines to write to the file. For length-2 tuples, the ordering of the numbers within the tuple does not matter. For length-3 tuples, the polarization string is in the order of the two antennas. If length-3 tuples are provided, the polarizations argument below must be None.

  • ant_str (str, optional) – A string containing information about what antenna numbers and polarizations to include when writing data into the object. Can be ‘auto’, ‘cross’, ‘all’, or combinations of antenna numbers and polarizations (e.g. ‘1’, ‘1_2’, ‘1x_2y’). See tutorial for more examples of valid strings and the behavior of different forms for ant_str. If ‘1x_2y,2y_3y’ is passed, both polarizations ‘xy’ and ‘yy’ will be written for both baselines (1, 2) and (2, 3) to reflect a valid pyuvdata object. An ant_str cannot be passed in addition to any of the above antenna args or the polarizations arg.

  • frequencies (array_like of float, optional) – The frequencies to include when writing data to the file.

  • freq_chans (array_like of int, optional) – The frequency channel numbers to include when writing data to the file.

  • times (array_like of float, optional) – The times in Julian Day to include when writing data to the file.

  • time_range (array_like of float, optional) – The time range in Julian Date to include when writing data to the file, must be length 2. Some of the times in the object should fall between the first and last elements. Cannot be used with times.

  • lsts (array_like of float, optional) – The local sidereal times (LSTs) to keep in the object, each value passed here should exist in the lst_array. Cannot be used with times, time_range, or lst_range.

  • lst_range (array_like of float, optional) – The local sidereal time (LST) range in radians to keep in the object, must be of length 2. Some of the LSTs in the object should fall between the first and last elements. If the second value is smaller than the first, the LSTs are treated as having phase-wrapped around LST = 2*pi = 0, and the LSTs kept on the object will run from the larger value, through 0, and end at the smaller value.

  • polarizations (array_like of int, optional) – The polarizations to include when writing data to the file.

  • blt_inds (array_like of int, optional) – The baseline-time indices to include when writing data to the file. This is not commonly used.

  • add_to_history (str) – String to append to history before write out. Default is no appending.

Returns

None

Raises

AssertionError – An AsserionError is raised if: (1) the location specified by filename does not exist; (2) the data_array, flag_array, and nsample_array do not all have the same shape; (3) the shape of the data arrays do not correspond to the sizes specified by the properties to write out.

Notes

When partially writing out data, this function should be called after calling initialize_uvh5_file. The same filename is passed in, with an optional check to ensure that the object’s metadata in-memory matches the header on-disk. See the tutorial for a worked example.

class pyuvdata.uvcal.calfits.CALFITS[source]

Defines a calfits-specific class for reading and writing calfits files.

This class should not be interacted with directly, instead use the read_calfits and write_calfits methods on the UVCal class.

write_calfits(filename, run_check=True, check_extra=True, run_check_acceptability=True, clobber=False)[source]

Write the data to a calfits file.

Parameters
  • filename (str) – The calfits file to write to.

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

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

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

  • clobber (bool) – Option to overwrite the filename if the file already exists.

read_calfits(filename, read_data=True, background_lsts=True, run_check=True, check_extra=True, run_check_acceptability=True)[source]

Read data from a calfits file.

Parameters
  • filename (str) – The calfits file to read from.

  • read_data (bool) – Read in the gains or delays, quality arrays and flag arrays. If set to False, only the metadata will be read in. Setting read_data to False results in a metadata only object.

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • run_check (bool) – Option to check for the existence and proper shapes of parameters after reading in the file.

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

  • run_check_acceptability (bool) – Option to check acceptable range of the values of parameters after reading in the file.

class pyuvdata.uvcal.fhd_cal.FHDCal[source]

Defines a FHD-specific subclass of UVCal for reading FHD calibration save files.

This class should not be interacted with directly, instead use the read_fhd_cal method on the UVCal class.

read_fhd_cal(cal_file, obs_file, layout_file=None, settings_file=None, raw=True, read_data=True, background_lsts=True, extra_history=None, run_check=True, check_extra=True, run_check_acceptability=True)[source]

Read data from an FHD cal.sav file.

Parameters
  • cal_file (str) – The cal.sav file to read from.

  • obs_file (str) – The obs.sav file to read from.

  • layout_file (str) – The FHD layout file. Required for antenna_positions to be set.

  • settings_file (str, optional) – The settings_file to read from. Optional, but very useful for provenance.

  • raw (bool) – Option to use the raw (per antenna, per frequency) solution or to use the fitted (polynomial over phase/amplitude) solution. Default is True (meaning use the raw solutions).

  • read_data (bool) – Read in the gains, quality array and flag data. If set to False, only the metadata will be read in. Setting read_data to False results in a metadata only object. If read_data is False, a settings file must be provided.

  • background_lsts (bool) – When set to True, the lst_array is calculated in a background thread.

  • extra_history (str or list of str, optional) – String(s) to add to the object’s history parameter.

  • run_check (bool) – Option to check for the existence and proper shapes of parameters after reading in the file.

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

  • run_check_acceptability (bool) – Option to check acceptable range of the values of parameters after reading in the file.

class pyuvdata.uvbeam.beamfits.BeamFITS[source]

Defines a fits-specific subclass of UVBeam for reading and writing beamfits files.

This class should not be interacted with directly, instead use the read_beamfits and write_beamfits methods on the UVBeam class.

The beamfits format supports regularly gridded or healpix beam files. The format defined here for healpix beams is not compatible with true healpix formats because it needs to support multiple dimensions (e.g. polarization, frequency, efield vectors).

read_beamfits(filename, run_check=True, check_extra=True, run_check_acceptability=True, check_auto_power=True, fix_auto_power=True)[source]

Read the data from a beamfits file.

Parameters
  • filename (str) – The beamfits file to read from.

  • run_check (bool) – Option to check for the existence and proper shapes of required parameters after reading in the file.

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

  • run_check_acceptabilit (bool) – Option to check acceptable range of the values of required parameters after reading in the file.

  • check_auto_power (bool) – For power beams, check whether the auto polarization beams have non-zero imaginary values in the data_array (which should not mathematically exist).

  • fix_auto_power (bool) – For power beams, if auto polarization beams with imaginary values are found, fix those values so that they are real-only in data_array.

write_beamfits(filename, run_check=True, check_extra=True, run_check_acceptability=True, check_auto_power=True, fix_auto_power=False, clobber=False)[source]

Write the data to a beamfits file.

Parameters
  • filename (str) – The beamfits file to write to.

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

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

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

  • check_auto_power (bool) – For power beams, check whether the auto polarization beams have non-zero imaginary values in the data_array (which should not mathematically exist).

  • fix_auto_power (bool) – For power beams, if auto polarization beams with imaginary values are found, fix those values so that they are real-only in data_array.

  • clobber (bool) – Option to overwrite the filename if the file already exists.

class pyuvdata.uvbeam.cst_beam.CSTBeam[source]

Defines a CST-specific subclass of UVBeam for reading CST text files.

This class should not be interacted with directly, instead use the read_cst_beam method on the UVBeam class.

name2freq(fname)[source]

Extract frequency from the filename.

Assumes the file name contains a substring with the frequency channel in MHz that the data represents. e.g. “HERA_Sim_120.87MHz.txt” should yield 120.87e6

Parameters

fname (str) – Filename to parse.

Returns

float – Frequency extracted from filename in Hz.

read_cst_beam(filename, beam_type='power', feed_pol='x', rotate_pol=True, frequency=None, telescope_name=None, feed_name=None, feed_version=None, model_name=None, model_version=None, history='', x_orientation=None, reference_impedance=None, extra_keywords=None, run_check=True, check_extra=True, run_check_acceptability=True, check_auto_power=True, fix_auto_power=True)[source]

Read in data from a cst file.

Parameters
  • filename (str) – The cst file to read from.

  • beam_type (str) – What beam_type to read in (‘power’ or ‘efield’).

  • feed_pol (str) – The feed or polarization or list of feeds or polarizations the files correspond to. Defaults to ‘x’ (meaning x for efield or xx for power beams).

  • rotate_pol (bool) – If True, assume the structure in the simulation is symmetric under 90 degree rotations about the z-axis (so that the y polarization can be constructed by rotating the x polarization or vice versa). Default: True if feed_pol is a single value or a list with all the same values in it, False if it is a list with varying values.

  • frequency (float or list of float) – The frequency or list of frequencies corresponding to the filename(s). This is assumed to be in the same order as the files. If not passed, the code attempts to parse it from the filenames.

  • telescope_name (str) – The name of the telescope corresponding to the filename(s).

  • feed_name (str) – The name of the feed corresponding to the filename(s).

  • feed_version (str) – The version of the feed corresponding to the filename(s).

  • model_name (str) – The name of the model corresponding to the filename(s).

  • model_version (str) – The version of the model corresponding to the filename(s).

  • history (str) – A string detailing the history of the filename(s).

  • x_orientation (str, optional) – Orientation of the physical dipole corresponding to what is labelled as the x polarization. Options are “east” (indicating east/west orientation) and “north” (indicating north/south orientation)

  • reference_impedance (float, optional) – The reference impedance of the model(s).

  • extra_keywords (dict, optional) – A dictionary containing any extra_keywords.

  • run_check (bool) – Option to check for the existence and proper shapes of required parameters after reading in the file.

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

  • run_check_acceptability (bool) – Option to check acceptable range of the values of required parameters after reading in the file.

  • check_auto_power (bool) – For power beams, check whether the auto polarization beams have non-zero imaginary values in the data_array (which should not mathematically exist).

  • fix_auto_power (bool) – For power beams, if auto polarization beams with imaginary values are found, fix those values so that they are real-only in data_array.

class pyuvdata.uvbeam.mwa_beam.MWABeam[source]

Defines an MWA-specific subclass of UVBeam for representing MWA beams.

This class should not be interacted with directly, instead use the read_mwa_beam method on the UVBeam class.

This is based on https://github.com/MWATelescope/mwa_pb/ but we don’t import that module because it’s not python 3 compatible.

Note that the azimuth convention in for the UVBeam object is different than the azimuth convention in the mwa_pb repo. In that repo, the azimuth convention is changed from the native FEKO convention (the FEKO convention is the same as the UVBeam convention). The convention in the mwa_pb repo has a different zero point and a different direction (so it is in a left handed coordinate system).

read_mwa_beam(h5filepath, delays=None, amplitudes=None, pixels_per_deg=5, freq_range=None, run_check=True, check_extra=True, run_check_acceptability=True, check_auto_power=True, fix_auto_power=True)[source]

Read in the full embedded element MWA beam.

Parameters
  • h5filepath (str) – path to input h5 file containing the MWA full embedded element spherical harmonic modes. Download via wget http://cerberus.mwa128t.org/mwa_full_embedded_element_pattern.h5

  • delays (array of ints) – Array of MWA beamformer delay steps. Should be shape (n_pols, n_dipoles).

  • amplitudes (array of floats) – Array of dipole amplitudes, these are absolute values (i.e. relatable to physical units). Should be shape (n_pols, n_dipoles).

  • pixels_per_deg (float) – Number of theta/phi pixels per degree. Sets the resolution of the beam.

  • freq_range (array_like of float) – Range of frequencies to include in Hz, defaults to all available frequencies. Must be length 2.

  • run_check (bool) – Option to check for the existence and proper shapes of required parameters after reading in the file.

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

  • run_check_acceptability (bool) – Option to check acceptable range of the values of required parameters after reading in the file.

  • check_auto_power (bool) – For power beams, check whether the auto polarization beams have non-zero imaginary values in the data_array (which should not mathematically exist).

  • fix_auto_power (bool) – For power beams, if auto polarization beams with imaginary values are found, fix those values so that they are real-only in data_array.

Returns

None

Raises

ValueError – If the amplitudes or delays are the wrong shape or there are delays greater than 32 or delays are not integer types. If the frequency range doesn’t include any available frequencies.

Mir Parser

Module for low-level interface to MIR files.

This module extracts data types associated with MIR files.

class pyuvdata.uvdata.mir_parser.MirParser(filepath=None, has_auto=False, load_vis=False, load_raw=False, load_auto=False)[source]

General class for reading Mir datasets.

Does lots of cool things! There are static functions that allow you low level access to mir files without needing to create an object. You can also instantiate a MirParser object with the constructor of this class which will only read the metadata into memory by default. Read in the raw data through the use of the load_vis, load_raw, load_auto flags, or by using the load_data() function once the object is created. This allows for the flexible case of quickly loading metadata first to check whether or not to load additional data into memory.

copy()[source]

Make and return a copy of the MirParser object.

Returns

MirParser – Copy of self.

static read_in_data(filepath)[source]

Read “in_read” mir file into memory (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

ndarray – Numpy ndarray of custom dtype of in_dtype.

static read_eng_data(filepath)[source]

Read “eng_read” mir file into memory (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

ndarray – Numpy ndarray of custom dtype of eng_dtype.

static read_bl_data(filepath)[source]

Read “bl_read” mir file into memory (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

ndarray – Numpy ndarray of custom dtype of bl_dtype.

static read_sp_data(filepath)[source]

Read “sp_read” mir file into memory (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

ndarray – Numpy ndarray of custom dtype of sp_dtype.

static read_codes_data(filepath)[source]

Read “codes_read” mir file into memory (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

ndarray – Numpy ndarray of custom dtype of codes_dtype.

static read_we_data(filepath)[source]

Read “we_read” mir file into memory (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

ndarray – Numpy ndarray of custom dtype of we_dtype.

static read_antennas(filepath)[source]

Read “antennas” mir file into memory (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

antpos_data (ndarray) – Numpy ndarray of custom dtype of antpos_dtype.

static scan_int_start(filepath)[source]

Read “sch_read” mir file into a python dictionary (@staticmethod).

Parameters

filepath (str) – filepath is the path to the folder containing the mir data set.

Returns

dict – Dictionary containing the indexes from sch_read.

static scan_auto_data(filepath, nchunks=8)[source]

Read “autoCorrelations” mir file into memory (@staticmethod).

Parameters
  • filepath (str) – filepath is the path to the folder containing the mir data set.

  • nchunks (int, optional) – Specify the number of chunks recorded into the autocorrelations (default is 8)

Returns

ac_data (ndarray) – Numpy ndarray of custom type ac_read_dtype.

static parse_vis_data(filepath, in_start_dict, sp_data)[source]

Read “sch_read” mir file into a list of ndarrays. (@staticmethod).

Parameters
  • filepath (str) – Path to the folder containing the mir data set.

  • in_start_dict (dict of tuples) – Dictionary returned from scan_int_start, which records position and record size for each integration

  • sp_data (ndarray of sp_data_type) – Array from “sp_read”, returned by “read_sp_read”.

Returns

vis_list (list of ndarrays) – List of ndarrays (dtype=csingle/complex64), with indices equal to sphid and values being the floating-point visibilities for the spectrum

static parse_raw_data(filepath, in_start_dict, sp_data)[source]

Read “sch_read” mir file into a python dictionary (@staticmethod).

Note that this returns a list rather than a dict to help expedite some processing tasks where order of the arrays matters.

Parameters
  • filepath (str) – Path to the folder containing the mir data set.

  • in_start_dict (dict of tuples) – Dictionary returned from scan_int_start, which records position and record size for each integration

  • sp_data (ndarray of sp_data_type) – Array from “sp_read”, returned by “read_sp_read”.

Returns

  • vis_list (list of ndarray) – List of ndarrays (dtype=int16), each containing the ‘raw’ set of values in “sch_read”, ordered in the same way that as sp_data.

  • scale_fac_list (list of int16) – List of scale factors (in log2 units) for each item in vis_list, also orded identically to sp_data.

static read_auto_data(filepath, ac_data, winsel=None)[source]

Read “autoCorrelations” mir file into memory (@staticmethod).

Note that this returns as an array, since there isn’t any unique index for the autocorrelations file.

Parameters
  • filepath (str) – Path to the folder containing the mir data set.

  • ac_data (arr of dtype ac_read_dtype) – Structure from returned from scan_auto_data.

  • winsel (list of int (optional)) – List of spectral windows to include.

Returns

auto_data (arr of single) – An array of shape (n_ch, n_chunk, n_rec), which containts the auto spectra, where n_ch is number of channels (currently always 16384 per chunk), n_chunk is the number of spectral “chunks” (i.e., Nspws), and n_rec is the number of receivers per antenna recorded (always 2 – 1 per polarization).

static read_vis_data(filepath, in_start_dict)[source]

Read “sch_read” mir file into memory (@staticmethod).

Parameters
  • filepath (str) – filepath is the path to the folder containing the mir data set.

  • in_start_dict (dict) – indexes to the visibility locations within the file.

Returns

in_data_dict (dict) – Dictionary of the data, where the keys are inhid and the values are the ‘raw’ block of values recorded in “sch_read” for that inhid.

load_data(load_vis=True, load_raw=False, load_auto=False, apply_tsys=True)[source]

Load visibility data into MirParser class.

Parameters
  • load_vis (bool) – Load the visibility data (floats) into object (deault is True).

  • load_raw (bool) – Load the raw visibility data (ints) into object (default is False).

  • load_auto (bool) – Load the autos (floats) into object (default is False).

  • apply_tsys (bool) – If load_vis is set to true, applys tsys corrections to the data (default is True).

unload_data()[source]

Unload data from the MirParser object.

from_file(filepath, has_auto=False, load_vis=False, load_raw=False, load_auto=False)[source]

Read in all files from a mir data set into predefined numpy datatypes.

The full dataset can be quite large, as such the default behavior of this function is only to load the metadata. Use the keyword params to load other data into memory.

Parameters
  • filepath (str) – filepath is the path to the folder containing the mir data set.

  • has_auto (bool) – flag to read auto-correlation data, default is False.

  • load_vis (bool) – flag to load visibilities into memory, default is False.

  • load_raw (bool) – flag to load raw data into memory, default is False.

  • load_auto (bool) – flag to load auto-correlations into memory, default is False.

Functions

pyuvdata.uvdata.fhd.get_fhd_history(settings_file, return_user=False)[source]

Small function to get the important history from an FHD settings text file.

Includes information about the command line call, the user, machine name and date

Parameters
  • settings_file (str) – FHD settings file name

  • return_user (bool) – optionally return the username who ran FHD

Returns

  • history (str) – string of history extracted from the settings file

  • user (str) – Only returned if return_user is True

pyuvdata.uvbeam.mwa_beam.P1sin(nmax, theta)[source]

Create the Legendre function flavors for FF expansion using spherical waves.

Note this is not vectorized so is a bit slow, but it handles the special case of theta = 0 and pi. We primarily use the vectorized version (P1sin_array), but call this to handle the special cases.

See: Calculating Far-Field Radiation Based on FEKO Spherical Wave Coefficients, draft 10 June 2015. Available at pyuvdata/docs/references/Far_field_spherical_FEKO_draft2.pdf This memo gives a full description of the equations implemented here, including descriptions of the approximations and numerical approaches used. In line comments below are helpful reminders, but see the memo for the full detail. Also see Sokolowski, M. et al, “Calibration and Stokes Imaging with Full Embedded Element Primary Beam Model for the Murchison Widefield Array”, PASA, 2017 (10.1017/pasa.2017.54) for details specific to the MWA.

Parameters
  • nmax (int) – Maximum n from FEKO Q1mn and Q2mn, n must be >=1

  • theta (float) – The argument of the cosine or sine function used in the associated Legendre functions, in radians.

Returns

  • P_sin (array of float) – P_{n}^{abs(m)}(cos(theta))/sin(theta) with FEKO order M,N. Shape (nmax ** 2 + 2 * nmax).

  • P1 (array of float) – P_{n}^{abs(m)+1}(cos(theta)) with FEKO order M,N. Shape (nmax ** 2 + 2 * nmax).

pyuvdata.uvbeam.mwa_beam.P1sin_array(nmax, theta)[source]

Calculate P^abs(m)_n(cos(theta))/sin(theta) and P^(abs(m)+1)_n(cos(theta)).

Similar to the “P1sin” function, but calculates for all theta in one go. At the end of the function, patches are made using the original P1sin function to solve the 0/0 issue.

Parameters
  • nmax (int) – Maximum n from FEKO Q1mn and Q2mn, n must be >=1

  • theta (array of float) – The argument of the cosine or sine functions used in the associated Legendre functions, in radians.

Returns

  • P_sin (array of float) – P_{n}^{abs(m)}(cos(theta))/sin(theta) with FEKO order M,N. Shape (nmax ** 2 + 2 * nmax, theta.size).

  • P1 (array of float) – P_{n}^{abs(m)+1}(cos(theta)) with FEKO order M,N. Shape (nmax ** 2 + 2 * nmax, theta.size).

pyuvdata.uvflag.uvflag.and_rows_cols(waterfall)[source]

Perform logical and over rows and cols of a waterfall.

For a 2D flag waterfall, flag pixels only if fully flagged along time and/or frequency

Parameters

waterfall (2D boolean array of shape (Ntimes, Nfreqs))

Returns

wf (2D array) – A 2D array (size same as input) where only times/integrations that were fully flagged are flagged.

pyuvdata.uvflag.uvflag.lst_from_uv(uv)[source]

Calculate the lst_array for a UVData or UVCal object.

Parameters

uv (a UVData or UVCal object.) – Object from which lsts are calculated

Returns

lst_array (array of float) – lst_array corresponding to time_array and at telescope location. Units are radian.

pyuvdata.uvflag.uvflag.flags2waterfall(uv, flag_array=None, keep_pol=False)[source]

Convert a flag array to a 2D waterfall of dimensions (Ntimes, Nfreqs).

Averages over baselines and polarizations (in the case of visibility data), or antennas and jones parameters (in case of calibrationd data).

Parameters
  • uv (A UVData or UVCal object) – Object defines the times and frequencies, and supplies the flag_array to convert (if flag_array not specified)

  • flag_array (Optional,) – flag array to convert instead of uv.flag_array. Must have same dimensions as uv.flag_array.

  • keep_pol (bool) – Option to keep the polarization axis intact.

Returns

waterfall (2D array or 3D array) – Waterfall of averaged flags, for example fraction of baselines which are flagged for every time and frequency (in case of UVData input) Size is (Ntimes, Nfreqs) or (Ntimes, Nfreqs, Npols).

aipy extracts

Module for low-level interface to MIRIAD files.

This module extracts some Python code from AIPY used in our MIRIAD I/O routines. It was copied from AIPY commit 6cb5a70876f33dccdd68d4063b076f8d42d9edae, then reformatted. The only items used by pyuvdata are uv_selector and UV.

pyuvdata.uvdata.aipy_extracts.uv_selector(uv, ants=- 1, pol_str=- 1)[source]

Call select on a Miriad object with string arguments for antennas and polarizations.

Parameters
  • uv (UV object) – Miriad data set object

  • ants (str) – string to select antennas or baselines, e.g. ‘all’, ‘auto’, ‘cross’, ‘0,1,2’, or ‘0_1,0_2’

  • pol_str (str) – polarizations to select, e.g. ‘xx’, ‘yy’, ‘xy’, ‘yx’

Returns

None

class pyuvdata.uvdata.aipy_extracts.UV(filename, status='old', corrmode='r')[source]

Top-level interface to a Miriad UV data set.

variables()[source]

Get the list of available variables.

Returns

list of str – list of available variables

items()[source]

Get the list of available header items.

Returns

list of str – list of available header items

select(name, n1, n2, include=True)[source]

Choose which data are returned by read().

Parameters
  • name (str) – This can be: ‘decimate’, ‘time’, ‘antennae’, ‘visibility’, ‘uvrange’, ‘pointing’, ‘amplitude’, ‘window’, ‘or’, ‘dra’, ‘ddec’, ‘uvnrange’, ‘increment’, ‘ra’, ‘dec’, ‘and’, ‘clear’, ‘on’, ‘polarization’, ‘shadow’, ‘auto’, ‘dazim’, ‘delev’

  • n1, n2 (int) – Generally this is the range of values to select. For ‘antennae’, this is the two antennae pair to select (indexed from 0); a -1 indicates ‘all antennae’. For ‘decimate’, n1 is every Nth integration to use, and n2 is which integration within a block of N to use. For ‘shadow’, a zero indicates use ‘antdiam’ variable. For ‘on’, ‘window’, ‘polarization’, ‘increment’, ‘shadow’ only p1 is used. For ‘and’, ‘or’, ‘clear’, ‘auto’ p1 and p2 are ignored.

  • include (bool) – If true, the data is selected. If false, the data is discarded. Ignored for ‘and’, ‘or’, ‘clear’.

read(raw=False)[source]

Return the next data record.

Calling this function causes variables to change to reflect the record which this function returns.

Parameters

raw (bool) – if True data and flags are returned seperately

Returns

  • preamble (tuple) – (uvw, t, (i,j)), where uvw is an array of u,v,w, t is the Julian date, and (i,j) is an antenna pair

  • data (ndarray or masked array) – ndarray if raw is True, otherwise a masked array

  • flags (ndarray) – only returned if raw is True

all_data(raw=False)[source]

Provide an iterator over preamble, data.

Allows constructs like: for preamble, data in uv.all_data(): ....

Parameters

raw (bool) – If True data and flags are returned seperately.

Returns

  • preamble (tuple) – (uvw, t, (i,j)), where uvw is an array of u,v,w, t is the Julian date, and (i,j) is an antenna pair

  • data (ndarray or masked array of complex) – ndarray if raw is True, otherwise a masked array

  • flags (ndarray) – only returned if raw is True

write(preamble, data, flags=None)[source]

Write the next data record.

Parameters
  • preamble (tuple) – (uvw, t, (i,j)), where uvw is an array of u,v,w, t is the Julian date, and (i,j) is an antenna pair

  • data (masked array of complex) – spectra for this record

init_from_uv(uv, override={}, exclude=[])[source]

Initialize header items and variables from another UV.

Those in override will be overwritten by override[k], and tracking will be turned off (meaning they will not be updated in pipe()). Those in exclude are omitted completely.

Parameters
  • uv (UV object) – Miriad data set object to initialize from

  • override (dict) – variables with values to overwrite

  • exclude (list) – list of variable to exclude

pipe(uv, mfunc=<function _uv_pipe_default_action>, append2hist='', raw=False)[source]

Pipe in data from another UV.

Uses the function mfunc(uv, preamble, data), which should return (preamble, data). If mfunc is not provided, the dataset will just be cloned, and if the returned data is None, it will be omitted.

Parameters
  • uv (UV object) – Miriad data set object to pipe from

  • mfunc (function) – function that defines how the data are piped. mfunc(uv, preamble, data) should return (preamble, data). Default is _uv_pipe_default_action which just clones the dataset.

  • append2hist (str) – string to append to history

  • raw (bool) – if True data and flags are piped seperately

add_var(name, var_type)[source]

Add a variable of the specified type to a UV file.

Parameters
  • name (str) – name of header item to add

  • var_type (str) – string indicating the variable type (e.g. ‘a’, ‘i’, ‘d’)