calibration_utils module

General SKA-LOW calibration functions.

aiv_utils.calibration_utils.apply_cal_from_array(station_name, gain_solns_array, *, is_channels_first=True, gain_solns_start_channel=64, total_nof_channels=384)

Use MccsStation to apply the provided calibration solution, given as a numpy array.

Parameters:
  • station_name (str) – Name of the station to apply solutions to.

  • gain_solns_array (ndarray) – A numpy array containing the full gain solutions. The expected shape is [channels, antennas, polarisations].

  • is_channels_first (bool) – Whether axis 0 is channels. If false, then it is assumed that axis 0 is antennas instead.

  • gain_solns_start_channel (int) – Coarse channel that the gain solutions start at

  • total_nof_channels (int) – Total number of channels that the beamformer supports.

Raises:

ValueError – If any tango device commands fail.

Return type:

None

aiv_utils.calibration_utils.apply_cal_from_file(station_name, gain_solns_path, *, is_channels_first=True, gain_solns_start_channel=64, total_nof_channels=384)

Use MccsStation to apply the provided calibration solution in .npy format.

Parameters:
  • station_name (str) – Name of the station to apply solutions to.

  • gain_solns_path (str | PathLike) – Path to a .npy file containing the full gain solutions. The expected shape is [channels, antennas, polarisations] or [antennas, channels, polarisations] if is_channels_first is False.

  • is_channels_first (bool) – Whether axis 0 is channels. If false, then it is assumed that axis 0 is antennas instead.

  • gain_solns_start_channel (int) – Coarse channel that the gain solutions start at

  • total_nof_channels (int) – Total number of channels that the beamformer supports.

Return type:

None

aiv_utils.calibration_utils.apply_unity_cal(station_name, *, total_nof_channels=384)

Apply unity calibration [1,0,0,1] to all antennas, ignoring the beamformer table.

This function is primarily for testing as well as returning the calibration coefficients to a known state.

Parameters:
  • station_name (str) – Name of the station to apply solutions to.

  • total_nof_channels (int) – Total number of channels that the beamformer supports.

Return type:

None

aiv_utils.calibration_utils.apply_zeroed_cal(station_name, *, total_nof_channels=384)

Apply zeroed calibration to all antennas, ignoring the beamformer table.

This function is primarily for testing as well as returning the calibration coefficients to a known state.

Parameters:
  • station_name (str) – Name of the station to apply solutions to.

  • total_nof_channels (int) – Total number of channels that the beamformer supports.

aiv_utils.calibration_utils.assess_phase_fit_quality(mean_phase_err, flagged_antenna_names, phase_err_thresh=5.74398001037828)

Assess the quality of a set of calibration solutions.

Parameters:
  • mean_phase_err (float) – Mean error in phase fit across frequency, antennas and polarisations (in degrees).

  • flagged_antenna_names (Iterable[str]) – List of names of flagged antennas.

  • phase_err_thresh (float) – Threshold for mean_phase_err to make solution set Faulty. Default is np.rad2deg(np.sqrt(-1*np.log(0.99))) for 1% sensitivity loss.

Returns:

Quality status from (“Healthy”, “Degraded 1”, “Degraded 2”, “Faulty”).

Return type:

str

aiv_utils.calibration_utils.configure_station(station_name, mccs_beamformer_table)

Configure the station which sets up the beamformer table and applies calibration.

The calibration solution from the store are applied according to the beamformer

table and the calibration store selection policy.

Parameters:
  • station_name (str) – Name of the station to configure.

  • mccs_beamformer_table (list[int]) – Beamformer table to use for determining how to apply calibration solutions. Use set_up_single_beam or create_mccs_beamformer_table to create this table as needed.

Raises:

ValueError – If any tango device commands fail.

Return type:

None

aiv_utils.calibration_utils.create_visibility(observation_data, config_data, freq_mhz)

Loads correlation data into an SDP visibility dataset.

Parameters:
  • observation_data (dict) – Observation data from load_correlation_burst_data.

  • config_data (dict) – Station config data from load_config_data.

  • freq_mhz (float) – The frequency of the data in MHz.

Returns:

The SDP visibility dataset.

aiv_utils.calibration_utils.estimate_sensitivity_loss(mean_phase_err, n_flagged_ants, max_n_ants=256)

Estimate the sensitivity loss due to errors in phase fits and flagged antennas.

Parameters:
  • mean_phase_err (float) – Mean of errors in phase fit at across antennas and polarisations (in degrees).

  • n_flagged_ants (int) – Number of flagged antennas.

  • max_n_ants (int, optional) – Maximum number of available antennas (default: 256)

Returns:

Sensitivity loss as a fraction.

Return type:

float

aiv_utils.calibration_utils.fault_due_to_sb_flagged(flagged_antenna_names)

Check if any smartboxes are entirely/almost entirely flagged.

If so, the current calibration solution set should be immediately determined to be faulty. This is because a clustered group of flagged antennas creates a “hole” in the station aperture, resulting in an unmodelled beam shape.

Parameters:

flagged_antenna_names (Iterable[str]) – List of names of flagged antennas.

Returns:

True if any smartbox has at least ten antennas flagged, False otherwise.

Return type:

bool

aiv_utils.calibration_utils.gain_solns_to_cal_table(beamformer_table, gain_solns_array, *, n_ant=256, gain_solns_start_channel=64, total_nof_channels=384)

Create a table of gain solutions based on the channels we will beamform.

Parameters:
  • beamformer_table (ndarray) – Beamformer table to use for applying calibration solutions. It should be in the same format as what sps_station.beamformertable returns.

  • gain_solns_array (ndarray) – A numpy array containing the full gain solutions. The expected shape is [channels, antennas, polarisations].

  • n_ant (int) – The number of antennas in this station.

  • gain_solns_start_channel (int) – The coarse channel that the gain solutions start at

  • total_nof_channels (int) – Total number of channels that the beamformer supports.

Return type:

ndarray[complex]

Returns:

A 2D complex valued numpy array containing the gain solutions for each beamformer channel that we will calibrate on with shape [channel, antenna].

Raises:

ValueError – If beamformer table is illegal or inconsistent.

aiv_utils.calibration_utils.generate_sky_model_for_itf(vis)

Generate and return a sky-model for ITF with a point source at zenith for given frequency.

Parameters:

vis (Dataset) – Visibility dataset for generating the sky-model.

Return type:

Dataset

Returns:

Skymodel Dataset

aiv_utils.calibration_utils.load_config_data(station_name)

Helper function to load data from the config file and returns it as a dictionary.

Parameters:

station_name – The name of the station (e.g. s9-2).

Return type:

dict

Returns:

A dictionary containing config data.

aiv_utils.calibration_utils.mask_antennas_by_name(station_name, antenna_names)

Zero out specific antennas in the calibration coefficients by name (e.g. sb01-01).

Parameters:
  • station_name (str) – Name of the station to apply solutions to.

  • antenna_names (Iterable[str]) – Antennas to mask by name.

Return type:

None

aiv_utils.calibration_utils.mask_antennas_by_number(station_name, antennas_tpm_numbering, *, total_nof_channels=384)

Zero out specific antennas in the calibration coefficients by tpm numbering.

Parameters:
  • station_name (str) – Name of the station to apply solutions to.

  • antennas_tpm_numbering (Iterable[int]) – Antennas to mask in zero-based tpm ordering.

  • total_nof_channels (int) – Total number of channels that the beamformer supports.

Raises:

ValueError – If any tango device commands fail.

Return type:

None

aiv_utils.calibration_utils.mask_known_bad_antennas(station_name, *, num_ants_in_tpm=16)

Apply zero calibration to antennas masked or undefined in the telmodel.

Return type:

None

aiv_utils.calibration_utils.reduce_correlations_based_on_antennas(obs_data)

Reduce the correlations in the observation data based on the antenna present in the Telmodel.

E.g. If the station s10-3 has 254 antennas instead of all 256 and this is recorded in Telmodel. This function will modify the obseravtion data to reflect this, changing the number of antennas, number of baselines and correlations to reflect the correct amount of antennas.

Parameters:

obs_data (dict[str, Union[str, int, float, ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]]]) – Observation data dictionary

Return type:

dict[str, Union[str, int, float, ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]]]

Returns:

Reduced observation data dictionary

aiv_utils.calibration_utils.reset_selection_policy(station_name)

Reset the selection policy so that the most recent stored solution will be used.

Parameters:

station_name (str) – Name of the station to apply solutions to.

Raises:

ValueError – If any tango device commands fail.

Return type:

None

aiv_utils.calibration_utils.set_impossible_selection_policy(cal_store)

Set an impossible selection policy so that no calibrations solutions can be found.

The calibration store returns a unity calibration when no solutions are found.

Parameters:

station_name – Name of the station to apply solutions to.

Raises:

ValueError – If any tango device commands fail.

Return type:

None

aiv_utils.calibration_utils.sig_phi(freq, sig_m, sig_c, sig_mc)

Calculate uncertainty in phase angle as a function of frequency.

Parameters:
  • freq (float) – Frequency to evaluate uncertainty at

  • sig_m (float) – Uncertainty in phase gradient

  • sig_c (float) – Uncertainty in phase offset

  • sig_mc (float) – Covariance between phase gradient and offset

Returns:

Uncertainty in phi(f)