sft_utils module

Commonly used helper functions in the short functional tests.

exception aiv_utils.sft_utils.EarlyTestFailure

Exception to be raised by SFTs for the test to fail without continuing.

Raising any other sort of exception will result in the test being aborted.

aiv_utils.sft_utils.baselines_to_antenna_names(baseline_array, antnum_tpm_to_name)

Converts baselines in antnum_tpm numbering into a string of named baselines.

Parameters:
  • baseline_array – List of lists of baselines in antnum_tpm numbering. It should have shape (2,N) or (N,2).

  • antnum_tpm_to_name – Array of antenna names in antnum_tpm ordering.

Return type:

str

Returns:

A string containing the baseline names.

Raises:

ValueError – if baseline_array cannot be converted into a usable shape.

aiv_utils.sft_utils.flat_correlation_to_upper_triangular(correlation_data, n_ant, n_pol=1)

Convert a flat correlation matrix into an upper triangular correlation matrix.

Parameters:
  • correlation_data – Flattened triangular correlation matrix. Usually has shape (32896, 4). otherwise should have shape (n_ant*(n_ant+1)/2, n_pol).

  • n_ant – Number of antennas.

  • n_pol – Number of polarisations present.

Returns:

An (n_ant,n_ant,n_pol) correlation matrix with the upper triangle filled.

Raises:

ValueError – If the shape of correlation_data is invalid.

aiv_utils.sft_utils.generate_sky_model_correlation_matrix(station_name, channel_id, obs_time, eep_path, eep_file_name, *, eep_f3='pol.npz', nside=64, elevation_min=0)

Generate a model correlation matrix for a channel for a station at a specific time. Code taken from ska-low-mccs-calibration.

Parameters:
  • station_name (str) – The name of the station, like “s9-2”.

  • channel_id (int) – The coarse channel to generate.

  • obs_time – The time of the observation.

  • eep_path – Path to the EEPs.

  • eep_file_name – The EEP base file name.

  • eep_f3 (str) – The EEP suffix.

  • nside (int) – The NSIDE to use when generating the sky model.

  • elevation_min – Ignore sky model contributions from below this elevation.

Returns:

A tuple containing correlation matrices for the sky and the sun.

aiv_utils.sft_utils.get_lst(station_name, obs_time)

Returns the LST for a station at a given time.

Parameters:
  • station_name – The station_name.

  • obs_time – The time of the observation.

Returns:

The LST.

aiv_utils.sft_utils.get_smartbox_colors()

Returns a list of distinct colour hex codes for colouring smartboxes in plots. Generated by https://mokole.com/palette.html.

Return type:

list[str]

Returns:

A list of colour hex codes.

aiv_utils.sft_utils.get_sun_elevation(station_name, obs_time)

Returns the sun elevation for a station at a given time.

Parameters:
  • station_name – The station_name.

  • obs_time – The time of the observation.

Returns:

The elevation of the sun.

aiv_utils.sft_utils.get_tpm_colors()

Returns a list of distinct colour hex codes for colouring TPMs in plots. Generated by https://mokole.com/palette.html.

Return type:

list[str]

Returns:

A list of colour hex codes.

aiv_utils.sft_utils.legend_without_duplicate_labels(axes, bbox_to_anchor=(1, 1))

Create a legend for a matplotlib without duplicate labels.

Taken from https://stackoverflow.com/a/56253636.

Params ax:

The matplotlib Axes object to add the legend to.

Params bbox_to_anchor:

The anchor for the legend. The default is top left.

aiv_utils.sft_utils.simulate_polarisation_swap(vis, antennas_to_swap, *, xx_pol=0, xy_pol=1, yx_pol=2, yy_pol=3)

Simulates a polarisation swap on the correlation matrix for specified antennas.

The process for one antenna is: * XY pol -> XX pol for correlations to this antenna * YX pol -> YY pol for correlations to this antenna * YX pol -> XX pol for correlations from this antenna * XY pol -> YY pol for correlations from this antenna Once these steps are done for all antennas, we then do the special case where there are muliple polarisation swaps, which is a simple case of swapping XX and YY polarisations for baselines between two polswaps.

Parameters:
  • vis – A correlation matrix.

  • antennas_to_swap – A list of antennas to swap polarisations of.

  • xx_pol – The index of the XX polarisation. Should be 0.

  • xx_pol – The index of the XX polarisation. Should be 1.

  • xx_pol – The index of the XX polarisation. Should be 2.

  • xx_pol – The index of the XX polarisation. Should be 3.

Returns:

The correlation matrix with the polarisation swaps.