SKA-Low MCCS Calibration Package

High-level Setup and Calibration Functions.

ska_low_mccs_calibration.calibration.adjust_gsm(vis, modelvis, gal_data, sun_data)

Fit for a brightness scale difference between the galaxy and the sun.

The change may be polarised, but would need to peel the sun away for that.

Parameters:
  • vis (Dataset) – Calibrated Visibility xarray

  • modelvis (Dataset) – Model Visibility xarray to update

  • gal_data (ndarray[Any, dtype[Union[complex64, complex128]]]) – 2D NumPy ndarray containing galactic contribution to model vis

  • sun_data (ndarray[Any, dtype[Union[complex64, complex128]]]) – 2D NumPy ndarray containing solar contribution to model vis

Return type:

tuple[Dataset, float]

Returns:

(updated modelvis, adjustment factor)

ska_low_mccs_calibration.calibration.calibrate_mccs_visibility(vis, skymodel='gsm', masked_antennas=array([], dtype=int64), min_uv=0, adjust_solar_model=True, jones_solve=False, back_rotation=False, refant=1, nside=32, dtype=<class 'numpy.complex64'>, ignore_eeps=False, eep_path='.', eep_filebase='FEKO_AAVS3_vogel_256_elem_50ohm_', eep_rotation_deg=0.0, eep_suffix='.npy', niter=200, gain_threshold=0.25, qa_plots=None)

Calibrate MCCS visibilities against a Global Sky Model.

Parameters:
  • vis (Dataset) – Visibility xarray to calibrate. Flags will be updated if any additional antenna flags are set.

  • skymodel (Union[Dataset, str]) – Either a model visibility xarray to calibrate against or the name of a sky model type to generate. Supported sky models are “gsm” and “sun”. The “gsm” model combines components of the PyGDSM GlobalSkyModel16 Galactic sky model that are above the horizon with a point-source solar model, while sun uses only the point-source solar model.

  • masked_antennas (ndarray, list) – list of antennas that have been flagged as bad and should be excluded. The default is to include all antennas.

  • min_uv (float) – Minimum baseline length used in calibration (in metres). The default value is zero.

  • adjust_solar_model (bool) – Adjust sky model after initial calibration to limit differences between the galactic and solar flux scales.

  • jones_solve (bool) – Call polarised solver after initial calibration.

  • back_rotation (bool) – Rotate the gain solution polarisation frame about zenith to local cardinal directions with X=East and Y=North. Default is False.

  • refant (int) – Antenna to use for phase referencing. Should be one of the zero-based indices used in the visibility dataset. Default is 1. Both polarisations are phase referenced against the X polarisation of refant, as a non-zero XY-phase is expected and solved for.

  • nside (int) – Healpix nside at which to generate sky model. Default is 32, which corresponds to approximately 110 arcminutes. This is okay at low frequencies but may need to be increased at higher frequencies.

  • dtype (dtype) – The NumPy data-type to use for complex EEPs and sky models. The default is numpy.complex64.

  • ignore_eeps (bool) – If True, EEP files will not be imported and station beam patterns and rotations will be ignored when modelling visibilities. Sky model components will be added with equal amplitude in XX and YY and zeros amplitude in XY and YX. Default is False.

  • eep_path (str) – Directory path to EEP image files. Default is the current dir.

  • eep_filebase (str) – Start of filenames, before frequency specification. Files are assumed to have a specific form, which for polarisation combination X/phi is: eep_path/eep_filebase<freq>MHz_Xpol_phi.npy. Default is filebase=”FEKO_AAVS3_vogel_256_elem_50ohm_”.

  • eep_rotation_deg (float) – Azimuthal rotation of station (and therefore the patterns) in degrees. Default is zero degress (no rotation).

  • eep_suffix (str) – The suffix to use when loading EEP image files. Default is .npy.

  • niter (int) – Number of iterations for solver. Default 200.

  • gain_threshold (float) – Fractional threshold used to reject antennas with low gains. Any antenna with either an X or Y gain amplitude less than the median is flagged as bad. The default values is 0.25.

  • qa_plots (Optional[dict[str, bool]]) – Dictionary of QA plots to generate (or not to generate). Any plotting functions from qa() can be listed with a True or False value, and any set to true will be called with PNG output. Use print(ska_low_mccs_calibration.qa.__all__) for a list. For example qa_plots = {“generate_closure_comparison_plots”: True}. Default is not to generate any PNG files.

Return type:

tuple[Dataset, Dataset, Dataset, ndarray[Any, dtype[int64]], NamedTuple]

Returns:

  • gains: GainTable Dataset containing the calibration solutions

  • model vis: Visibility Dataset containing model visibilities used in calibration. This dataset will retain any flags or weights used in calibration.

  • calibrated vis: Visibility Dataset containing calibrated visibilities. This dataset will retain any flags or weights used in calibration.

  • updated antenna flags: list of antenna flags used in final calibration step.

  • calibration info: namedtuple of return variables. See generate_calibration_info() for details.

ska_low_mccs_calibration.calibration.rotate_gaintable(gaintable, eep_rotation_deg=0.0)

Rotate the X and Y polarisation axes from the nominal X=East, Y=North.

The station being calibrated will in general have an azimuthal orientation that is different from other stations. As both the observed and model visibilities have polarisation axes in the rotated frame, the calibration solutions generated will be as well. This function rotates the gain solution matrices relative to the standard X=East, Y=North frame. When the solution matrices are inverted and applied to the observed data, the resulting calibrated visibilities will be back-rotated to the standard frame.

The direction-independent calibration matrices dealt with in this package are solved on the left-hand side of the beam matrices, as the effects are assumed to occur in the system after passing through the antennas. As such, the rotation matrix should be applied on the right-hand side of the calibration matrices.

Parameters:
  • gaintable (Dataset) – ska-sdp-datamodels GainTable xarray containing gain solutions.

  • eep_rotation_deg (float) – rotation of the station in degrees. Default is 0.

Return type:

Dataset

Returns:

update gaintable.

ska_low_mccs_calibration.calibration.xy_phase_estimate(vis, modelvis)

Estimate uncalibrated xy-phase by comparing calibrated and model visibilities.

Parameters:
  • vis (Dataset) – Calibrated Visibility xarray

  • modelvis (Dataset) – Model Visibility xarray to update

Return type:

float

Returns:

xy-phase estimate (radians)

Embedded Element Pattern Support.

ska_low_mccs_calibration.eep.azel_to_eep_indices(eep_shape, eep_rotation_deg, azimuth_deg, elevation_deg)

Return nearest EEP pixels for a set of azimuths and elevations.

All elevations should be greater than or equal to 0. If the station is rotated in azimuth, the EEP pixel coordaintes are rotated accordingly.

Parameters:
  • eep_shape (ndarray, list) – shape of EEP azimuth and zenith angle axes, [Naz,Nza]

  • eep_rotation_deg (float) – rotation of the station (and therefore EEPs) in degrees

  • azimuth_deg (ndarray, list) – azimuth of pixels in degrees

  • elevation_deg (ndarray, list) – elevation of pixels in degrees

Return type:

list[ndarray[Any, dtype[int64]]]

Returns:

[azimuth indices, zenith angle indices]

ska_low_mccs_calibration.eep.convert_eep2npy(eep_filename, npy_dir='.', dtype=<class 'numpy.complex64'>)

Convert MATLAB EEP files to NumPy format and write them to disk.

EEPs are split into separate files for the phi and theta polarisations.

Parameters:
  • eep_filename (str) – MATLAB filename or list of names to load.

  • npy_dir (str) – Output directory for npy files. Default is the current working directory.

  • dtype (dtype) – The NumPy data-type to use for the output arrays. MATLAB files have dtype=complex128, but by default they will be reduced on output to dtype=complex64.

Return type:

None

ska_low_mccs_calibration.eep.eep_pa_rotation(jones_array, location, time, right_ascension_deg, declination_deg)

Apply a parallactic angle correction to one or more Jones matrices.

Parameters:
  • jones_array (ndarray[Any, dtype[Union[complex64, complex128]]]) – numpy array contain EEPs in Jones format with at least two dimensions: [2, 2] or [ntimes, 2, 2].

  • location (Quantity) – Astropy coordinates of the observation location.

  • time (Union[Quantity, list[Quantity]]) – Astropy time/times of the observation, length ntimes.

  • right_ascension_deg (float) – right ascension of beam in degrees

  • declination_deg (float) – declination of beam in degrees

  • pa_correction – whether to generate matrices that include the PA rotation from IAU coordinates aligned with declination and right ascension. False by default.

Return type:

ndarray[Any, dtype[Union[complex64, complex128]]]

Returns:

average beam Jones matrix

ska_low_mccs_calibration.eep.get_nearest_file(filename_pattern, frequency_mhz, maximum_offset_mhz=3)

Find the closest frequency of the available EEP files.

This method is very basic at this point and requires the filenames to contain the substring “<freq>MHz”.

Parameters:
  • filename_pattern (str) – Filename pattern with standard glob wildcards to search for closest frequency match. Filenames must contain sub-string “<freq>MHz”.

  • frequency_mhz (float) – Frequency of data being processed, in MHz.

  • maximum_offset_mhz (float) – The maximum allowed separation of the closest frequency match from the desired frequency, in MHz. Default is 3.

Return type:

str

Returns:

Frequency of the nearest file.

ska_low_mccs_calibration.eep.load_eeps(frequency_mhz, path, filebase='FEKO_AAVS3_vogel_256_elem_50ohm_', dtype=<class 'numpy.complex64'>, conjugate=True, suffix='.npy', maximum_offset_mhz=3)

Load EEP NumPy files into beam ndarrays of shape [az, za, nant].

Antennas are reordered to match the visibility data order, as specified by antenna_order. EEPs are stored in separate arrays for the four polarisation combinations: X,Y instrument polarisations and phi,theta sky polarisations.

Antenna-averaged EEPs can also be used, with shape = [az, za, 1] or [az, za].

Note: if EEP images are in MATLAB format, then before calling this function one should first call convert_eep2npy() to convert to NumPy format.

Parameters:
  • frequency_mhz (float) – Frequency of data being processed, in MHz.

  • path (str) – Directory path to EEP image files

  • filebase (str) – Start of filenames, before frequency specification. Files are assumed to have a specific form, which depends on the suffix. Default is filebase=”FEKO_AAVS3_vogel_256_elem_50ohm_”.

  • antenna_order – The antenna order for these models in the visibility data. The first EEP image corresponds to antenna antenna_order[0] in the visibilities, for example. Default is antenna_order=None.

  • dtype (dtype) – The NumPy data-type to use to store the arrays. MATLAB files have dtype=complex128, but by default convert_eep2npy() reduces the npy output to dtype=complex64. Default here is dtype=complex64.

  • conjugate (bool) – Whether to conjugate the data. Default is True.

  • suffix (str) – The file extension to use. Default is “.npy”. Different suffixes correspond to different file types which need to be handled differently.

  • maximum_offset_mhz (float) – The maximum allowed separation of the closest frequency match from the desired frequency, in MHz. Default is 3.

Return type:

list[ndarray[Any, dtype[Union[complex64, complex128]]]]

Returns:

[eep_x_phi, eep_x_theta, eep_y_phi, eep_y_theta]. One ndarray for each of the four polarisation combinations. Dimensions are [azimuth, zenith angle, antenna (in data order)].

ska_low_mccs_calibration.eep.normalise_eeps(eeps)

Normalise EEPs for operations with the local sky model.

When calling resample_eeps for the all-sky diffuse sky model, re-sampling may change the beam solid angle integral. This function re-normalises the EEPs by the power integral over the re-sampled pixels.

The shape of the each EEP should be [antenna, pixel].

Parameters:

eeps (list[ndarray[Any, dtype[Union[complex64, complex128]]]]) – list of four EEPs: [Xphi, Xtheta, Yphi, Ytheta]

Return type:

list[ndarray[Any, dtype[Union[complex64, complex128]]]]

Returns:

updated beam arrays

ska_low_mccs_calibration.eep.reconfigure_eeps(eeps, eep_rotation_deg=0, azimuth_deg=array([], dtype=float64), elevation_deg=array([], dtype=float64), normalise=True)

Reconfigure EEPs for operations with the local sky model. Deprecated.

This amounts to a change of axis ordering and a normalisation with respect to pixel centres of the sky model. At present this is a simple nearest-pixel resampling.

On input the shape of each EEP is [azimuth, zenith angle, antenna]. On output the shape of each EEP is [antenna, zenith angle, azimuth].

Parameters:
  • eeps (list[ndarray[Any, dtype[Union[complex64, complex128]]]]) – list of four EEPs: [Xphi, Xtheta, Yphi, Ytheta]

  • eep_rotation_deg (float) – rotation of the station (and therefore EEPs) in degrees. Only required if normalise = true.

  • azimuth_deg (ndarray, list) – azimuth of new pixels in degrees. Only required if normalise = true.

  • elevation_deg (ndarray, list) – elevation of new pixels in degrees. Only required if normalise = true.

  • normalise (bool) – if true, normalise EEPs by the power integral over a set of pixels. Default is true.

Return type:

list[ndarray[Any, dtype[Union[complex64, complex128]]]]

Returns:

updated beam arrays

ska_low_mccs_calibration.eep.resample_eeps(eeps, eep_rotation_deg, azimuth_deg, elevation_deg)

Resample beam models at the LSM pixel centres.

At present this is a simple nearest-pixel resampling.

On input the shape of each EEP is [azimuth, zenith angle, antenna]. On output the shape of each EEP is [antenna, pixel]

Parameters:
  • eeps (list[ndarray[Any, dtype[Union[complex64, complex128]]]]) – list of four EEPs: [Xphi, Xtheta, Yphi, Ytheta]

  • eep_rotation_deg (float) – rotation of the station (and therefore EEPs) in degrees

  • azimuth_deg (ndarray, list) – azimuth of new pixels in degrees

  • elevation_deg (ndarray, list) – elevation of new pixels in degrees

Return type:

list[ndarray[Any, dtype[Union[complex64, complex128]]]]

Returns:

updated beam arrays

ska_low_mccs_calibration.eep.station_beam_matrix(eeps, eep_rotation_deg, location, time, right_ascension_deg, declination_deg, keepdims=False, pa_correction=False)

Return the station-averaged EEP Jones matrix/matrices for given sky coordinates.

eeps is a list of four beam arrays with shape [azimuth, zenith angle, antenna]. On output the sampled beam is averaged across stations to form a 2x2 Jones matrix for each time step.

Parameters:
  • eeps (list[ndarray[Any, dtype[Union[complex64, complex128]]]]) – list of four EEP sets: [Xphi, Xtheta, Yphi, Ytheta].

  • eep_rotation_deg (float) – rotation of the station (and therefore EEPs) in degrees.

  • location (Quantity) – Astropy coordinates of the observation location.

  • time (Union[Quantity, list[Quantity]]) – Astropy time of the observation.

  • right_ascension_deg (float) – right ascension of beam in degrees.

  • keepdims (bool) – if there is a single time sample the axis is retained with size one.

  • declination_deg (float) – declination of beam in degrees

  • pa_correction (bool) – whether to generate matrices that include the PA rotation from IAU coordinates aligned with declination and right ascension. False by default.

Return type:

ndarray[Any, dtype[Union[complex64, complex128]]]

Returns:

average beam Jones matrix

ska_low_mccs_calibration.eep.station_rotation_matrix(eep_rotation_deg, reverse=False)

Return the rotation matrix for station polarisations relative to X=EW, Y=NS.

Parameters:
  • eep_rotation_deg (float) – rotation of the station (and therefore EEPs) in degrees

  • reverse (bool) – whether to transpose the matrix for back-rotation. True by default.

Return type:

ndarray[Any, dtype[Union[complex64, complex128]]]

Returns:

polarisation rotation matrix

Functions for gathering or generating quality assurance information.

ska_low_mccs_calibration.qa.generate_calibration_info(vis, modelvis, masked_antennas_init, masked_antennas_final, location, time, xy_phase, sun_adjustment_factor)

Collect calibration QA metadata and return as a namedtuple.

Parameters:
  • vis (Dataset) – Calibrated Visibility xarray

  • modelvis (Dataset) – Model Visibility xarray to update

  • masked_antennas_init (ndarray[Any, dtype[int64]]) – initial list of flagged antenna

  • masked_antennas_final (ndarray[Any, dtype[int64]]) – final list of flagged antenna

  • location (Quantity) – Astropy coordinates of the observation location.

  • time (Quantity) – Astropy time of the observation.

  • xy_phase (float) – Any excess XY-phase determined after calibration.

  • sun_adjustment_factor (float) – Amplitude factor determined for the sun temperature.

Return type:

NamedTuple

Returns:

  • corrcoeff: List of Pearson product-moment correlation coefficients for each polarisation of the calibrated visibilities and the model.

  • residual_std: List of residual visibility standard deviation per polarisation (K).

  • residual_max: List of residual visibility maximum absolution deviation per polarisation (K).

  • xy_phase: Estimated xy-phase (degrees) if solved for separately.

  • n_masked_initial: Initial number of masked antennas.

  • n_masked_final: Final number of masked antennas.

  • lst: Apparent sidereal time at station (degrees).

  • galactic_centre_elevation: Elevation of the galactic centre (degrees).

  • sun_elevation: Elevation of the sun (degrees).

  • sun_adjustment_factor: Solar adjustment factor (if adjust_solar_model=True, “1” otherwise).

ska_low_mccs_calibration.qa.generate_closure_comparison_plots(vis, modelvis, masked_antennas, min_uv=0.0, decimate=1, ctype=None)

Plot visibility closure relation comparisons against model visibilities.

Talk about there being too many cross products and it being advisable to generate and display products for sub-arrays at a time.

Parameters:
  • vis (Dataset) – Visibility xarray dataset containing calibrated data. Assumes a single time and frequency.

  • modelvis (Dataset) – Visibility xarray dataset containing model data

  • masked_antennas (ndarray[Any, dtype[int64]]) – 1D numpy array of flagged antenna indices

  • min_uv (float) – Minimum baseline length allowed in triplets, in metres. Default = 0.

  • decimate (int) – Use a sub-array formed from every _decimate_ antennas to speed up plotting. Default is 1 (no decimation).

  • ctype (Optional[str]) – What to use for colouring. Allowed options are “uvmin”, which will set colours based on the minimum baseline length in each triplet, “uvmax”, which will set colours based on the maximum baseline length in each triplet, and “uvdiff”, which will set colours based on uvmax - uvmin. Default is none, which will use a single colour for all points.

Return type:

Figure

Returns:

matplotlib figure of visibility comparisons.

ska_low_mccs_calibration.qa.generate_gaintable_plots(gain_table, masked_antennas)

Plot the amplitude and phase of the Jones matrix elements versus antenna.

Parameters:
  • gain_table (Dataset) – GainTable xarray dataset containing calibration solutions. Assumes a single time and frequency.

  • masked_antennas (ndarray[Any, dtype[int64]]) – 1D numpy array of flagged antenna indices.

Return type:

Figure

Returns:

matplotlib figure of Jones matrix amp and phase versus antenna number.

ska_low_mccs_calibration.qa.generate_gaintable_scatter_plots(gain_table, masked_antennas, enu, refant=None)

Plot the amplitude and phase of the Jones matrix elements versus position.

Parameters:
  • gain_table (Dataset) – GainTable xarray dataset containing calibration solutions. Assumes a single time and frequency.

  • masked_antennas (ndarray[Any, dtype[int64]]) – 1D numpy array of flagged antenna indices.

  • enu (ndarray,) – Array of antenna East,North,Up coordinates.

  • refant (Optional[int]) – Index of reference antenna to use in phase plots. None by default.

Return type:

Figure

Returns:

matplotlib figure of Jones matrix amp and phase versus antenna position.

ska_low_mccs_calibration.qa.generate_visibility_comparison_plots(vis, modelvis, masked_antennas)

Plot calibrated and model visibility comparisons.

Parameters:
  • vis (Dataset) – Visibility xarray dataset containing calibrated data. Assumes a single time and frequency.

  • modelvis (Dataset) – Visibility xarray dataset containing model data

  • masked_antennas (ndarray[Any, dtype[int64]]) – 1D numpy array of flagged antenna indices

Return type:

Figure

Returns:

matplotlib figure of visibility comparisons.

ska_low_mccs_calibration.qa.generate_visibility_plots(vis, modelvis, masked_antennas)

Plot calibrated and model visibilities.

Parameters:
  • vis (Dataset) – Visibility xarray dataset containing calibrated data. Assumes a single time and frequency.

  • modelvis (Dataset) – Visibility xarray dataset containing model data

  • masked_antennas (ndarray[Any, dtype[int64]]) – 1D numpy array of flagged antenna indices

Return type:

Figure

Returns:

matplotlib figure of visibility amplitude and phase.

Sky Model Support.

ska_low_mccs_calibration.sky_model.dft_sky_to_vis(eeps, index_array, ft_phasor, lsm)

Evaluate the DFT of the sky model for each baseline.

Evaluation can be done without EEPs, with a single set of EEPs for all antennas, or with a separate set of EEPs for each antenna.

Parameters:
  • eeps (Optional[list[ndarray[Any, dtype[Union[complex64, complex128]]]]]) – list of four EEP sets: [Xphi, Xtheta, Yphi, Ytheta]. Set to None to ignore beams in the DFT. The first dimension of each array is the antenna index, which has a length of one when a single beam model is used for all antennas.

  • index_array (ndarray, list) – first and second antenna indices for each baseline

  • ft_phasor (ndarray, list) – array of DFT phase terms between pixels and baselines

  • lsm (ndarray, list) – list of pixel values

Return type:

list[ndarray[Any, dtype[Union[complex64, complex128]]]]

Returns:

complex model visibilities [XX, XY, YX, YY]

ska_low_mccs_calibration.sky_model.generate_ft_phasor(delay_ns, frequency_mhz, azimuth_deg, elevation_deg)

Generate Fourier phase shifts for the LSM.

Generate a complex array of phase shifts for the DFT from sky model pixels to sky model visibilities.

In keeping with standard references and real-to-complex Fourier transforms from standard packages like FFTW and CUFFT, this is a forward transform and the sign of the Fourier exponent is negative.

Parameters:
  • delay_ns (ndarray, list) – array of shape (3,nbaselines) containing the relative baseline delays in nanoseconds.

  • frequency_mhz (float) – observing frequency in MHz

  • azimuth_deg (ndarray, list) – array of shape (nskypixels) containing pixel azimuths.

  • elevation_deg (ndarray, list) – array of shape (nskypixels) containing zenith angles.

Return type:

ndarray[Any, dtype[Union[complex64, complex128]]]

Returns:

complex array of DFT phase terms, shape (nbaselines,nskypixels).

ska_low_mccs_calibration.sky_model.gsmap_lsm(gsmap, location, time, elevation_min=0.0)

Extract relevant pixels from the GSM.

Return the azimuth, elevation and temperature values of all pixels in the Healpix map above elevation_min degrees.

Parameters:
  • gsmap (ndarray, list) – Healpix map.

  • location (Quantity) – Astropy coordinates of the observation location.

  • time (Quantity) – Astropy time of the observation.

  • elevation_min (float) – min elevation cutoff in degrees (default is 0 deg)

Return type:

list[ndarray[Any, dtype[Union[float32, float64]]]]

Returns:

[azimuth_deg, elevation_deg, temperature]

ska_low_mccs_calibration.sky_model.gsmodel(frequency_mhz, nside, include_cmb=True, model_name='GlobalSkyModel16')

Call PyGDSM to evaluate the diffuse galactic sky model.

PyGDSM model GlobalSkyModel16 is used.

Parameters:
Return type:

ndarray[Any, dtype[Union[float32, float64]]]

Returns:

List containing the Healpix map at each frequency

ska_low_mccs_calibration.sky_model.predict_vis(eeps, eep_rotation_deg, index_array, delay_ns, frequency_mhz, azimuth_deg, elevation_deg, lsm, normalise_beam=False)

Evaluate the DFT of the sky model for each baseline.

Parameters:
  • eeps (Optional[list[ndarray[Any, dtype[Union[complex64, complex128]]]]]) – list of four EEP sets: [Xphi, Xtheta, Yphi, Ytheta]. Set to None to ignore beams in prediction.

  • eep_rotation_deg (float) – rotation of the station (and therefore EEPs) in degrees. Not used if eeps = None.

  • index_array (ndarray, list) – first and second antenna indices for each baseline

  • delay_ns (ndarray, list) – array of shape (3,nbaselines) containing the relative baseline delays in nanoseconds

  • frequency_mhz (float) – observing frequency in MHz

  • azimuth_deg (ndarray, list) – array of shape (nskypixels) containing pixel azimuths.

  • elevation_deg (ndarray, list) – array of shape (nskypixels) containing zenith angles.

  • lsm (ndarray, list) – list of pixel values

  • normalise_beam (bool) – if true, normalise EEPs by the power integral over the set of pixels. Default is false.

Return type:

list[ndarray[Any, dtype[Union[complex64, complex128]]]]

Returns:

complex model visibilities [XX, XY, YX, YY]

ska_low_mccs_calibration.sky_model.solar_lsm(frequency_mhz, location, time)

Get the position of the sun and estimate the temperature.

Temperature is based on the analytical expression for the quiet Sun in the range 30 - 350 MHz from Benz A. O. (2009) “Radio emission of the quiet sun.” Landolt Börnstein, 4B (103). This will be an underestimate when the sun is active.

Parameters:
  • frequency_mhz (ndarray, list, float) – Frequency or list of frequencies to evaluate (MHz).

  • location (Quantity) – Astropy coordinates of the observation location.

  • time (Quantity) – Astropy time of the observation.

Return type:

list[ndarray[Any, dtype[Union[float32, float64]]]]

Returns:

[azimuth_deg, elevation_deg, temperature]

Extra Utility Functions.

ska_low_mccs_calibration.utils.apply_gaintable(vis, gt, inverse=False)

Apply a GainTable to a Visibility.

This is a temporary local version of ska-sdp-func-python.operations.apply_gaintable that avoid a bug in the original. Will remove once the ska-sdp-func-python version is fixed. The bug is that the function does not transpose the rightmost matrix. This may not always be the desired action, for instance if calibration was done separately for each polarised visibility type, but is required when the solutions are Jones matrices.

Note: this is a temporary function and has not been made to robustly handle all situations. For instance, it ignores flags and does not properly handle sub-bands and partial solution intervals. It also assumes that the matrices being applied are Jones matrices and the general ska-sdp-datamodels xarrays are used.

Parameters:
  • vis (Dataset) – ska-sdp-datamodels Visibility xarray containing visibilities.

  • gt (Dataset) – ska-sdp-datamodels GainTable xarray containing gain solutions.

  • inverse (bool) – Apply the inverse of the gain. This requires the gain matrices to be square. (default=False)

Return type:

Dataset

Returns:

ska-sdp-datamodels Visibility xarray containing calibrated visibilities.

ska_low_mccs_calibration.utils.enu_to_geocentric(antpos_enu, location)

Convert East,North,Up antenna coordinates to geocentric.

Convert antenna coordinates from the local frame to geocentric.

Parameters:
  • antpos_enu (ndarray, list) – array of East,North,Up coordinates. This array must have shape […, 3], with East,North,Up coordinates along the last axis.

  • location (Quantity) – Astropy coordinates of the observation location.

Return type:

ndarray[Any, dtype[Union[float32, float64]]]

Returns:

ndarray with the same shape as antpos_enu and X,Y,Z coordinates along the last axis.

ska_low_mccs_calibration.utils.read_station_config(station_dict, namedtuple_output=False)

Extract configuration metadata from a station_dict.

Parameters:
  • station_dict (dict[str, Any]) – a dictionary containing config for a station

  • namedtuple_output (bool) – Set to True to return station configuration parameters as a NamedTuple rather than a standard, fixed tuple. Default is False. Note: tuple output is deprecated. Use namedtuple output instead.

Return type:

Union[tuple[Quantity, ndarray[Any, dtype[bool_]], tuple[ndarray[Any, dtype[int64]], ndarray[Any, dtype[int64]]], tuple[ndarray[Any, dtype[Union[float32, float64]]], ndarray[Any, dtype[Union[float32, float64]]], ndarray[Any, dtype[Union[float32, float64]]]], list[int], float], NamedTuple]

Returns:

tuple or namedtuple of configuration parameters:

  • location: Astropy array location

  • antenna_masks: boolean list of flagged antennas

  • baselines: first and second antenna for each baseline

  • enu: Local [East, North, Up] location of each antenna

  • polid: index of [XX, XY, YX, YY] polarisation in vis dataset

  • rotation: azimuthal rotation of station (bearing clockwise from north)

    in degrees

  • station_name: name of the station (namedtuple output only)

  • antenna_names: antenna names (namedtuple output only)

ska_low_mccs_calibration.utils.read_yaml_config(yaml_file, namedtuple_output=False)

Extract configuration metadata from observation YAML file.

Parameters:
  • yaml_file (str) – YAML file to read

  • namedtuple_output (bool) – Set to True to return station configuration parameters as a NamedTuple rather than a standard, fixed tuple. Default is False.

Return type:

Union[tuple[Quantity, ndarray[Any, dtype[bool_]], tuple[ndarray[Any, dtype[int64]], ndarray[Any, dtype[int64]]], tuple[ndarray[Any, dtype[Union[float32, float64]]], ndarray[Any, dtype[Union[float32, float64]]], ndarray[Any, dtype[Union[float32, float64]]]], list[int], float], NamedTuple]

Returns:

tuple or namedtuple of configuration parameters. See read_station_config() for details. Note: tuple output is deprecated. Use namedtuple output instead.

ska_low_mccs_calibration.utils.sdp_visibility_datamodel(vis, flags, uvw, ant1, ant2, location, antpos_enu, time, int_time, frequency_mhz, channel_bandwidth_mhz=0.78125, station_name='low-station', antenna_names=None)

Package MCCS data in a ska-sdp-datamodels Visibility xarray.

Currently set up for a single time step and frequency channel

Parameters:
  • vis (ndarray[Any, dtype[Union[complex64, complex128]]]) – 2D or 3D array of visibilties, shape [<ntimes>,nbaselines,npol]

  • flags (ndarray[Any, dtype[bool_]]) – 2D or 3D array of bad-data flags, shape [<ntimes>,nbaselines,npol]

  • uvw (ndarray[Any, dtype[Union[float32, float64]]]) – 2D or 3D array of antenna coordinates in metres, shape [<ntimes>,nbaselines,3]

  • ant1 (ndarray, list) – 1D array containing the indices of the first antenna in each baseline

  • ant2 (ndarray, list) – 1D array containing the indices of the second antenna in each baseline

  • location (Quantity) – Astropy coordinates of the observation location.

  • antpos_enu (ndarray, list) – Array of antenna East,North,Up coordinates in metres. This array must have shape [nant, 3], with East,North,Up coordinates along the 2nd axis.

  • time (Quantity) – Astropy time of the observation time step.

  • int_time (float) – Integration time of data samples (seconds).

  • frequency_mhz (float) – Observing frequency of data channel (MHz).

  • channel_bw_MHz – Channel bandwidth (MHz). Default = 400MHz/512 = 0.78125.

  • station_name (str) – name of the station. Default = “low-station”.

  • antenna_names (Optional[list[str]]) – antenna names. Default = “[ant001, ant002, …]”.

Return type:

Dataset

Returns:

ska-sdp-datamodels Visibility xarray containing visibilities and metadata