ska_sdp_wflow_pointing_offset.utils module
Util functions for:
Constructing katpoint antenna information
Constructing Measurement Sets names based on ScanIDs
Determining observing frequency band
Storing errors and traceback in the config db when running the pipeline in SDP
Extracts the values from the dictionary of the fitted parameters and outputs them as a numpy array in degrees.
Extracting the index of antenna under test in a two-dish mode scenario
Merging the output offsets from a two-dish mode scenario
Computing the weighted average of the output offsets for the parallel hands gain or visibility amplitudes
Computing a weighted-average of the fitted parameters and their standard deviations from beams fitted to the Stokes I amplitudes or parallel-hands gain amplitudes
Converting the dictionary of fitted parameters to a numpy array and to a structured numpy array
Generating some parameters required for plotting the Gaussian fits in the two-dish mode scenario
Splitting array into chunks and discards the first and last chunks if the number of chunks is greater than 1
Extracting the cross-correlation Visibility object of the parallel-hands polarisations
Selecting frequency ranges for input data and splitting into chunks
- ska_sdp_wflow_pointing_offset.utils.antenna_and_offsets_reorder(offsets)[source]
Re-orders the antenna names and their corresponding fitted parameters in the two-dish scenario to match those in the output HDF5 file
- Parameters:
offsets – A dictionary of the weighted-average pointing offsets output by
array_data_func.weighted_average()- Returns:
A dictionary of the input offsets with the right antenna names and fitted offsets ordering
- ska_sdp_wflow_pointing_offset.utils.average_output_offsets(output_offsets_list)[source]
Computes a weighted average of the output offsets for the parallel hands gain or visibility amplitudes output by
array_data_func.fitted_offsets_weighted_average().- Parameters:
output_offsets_list – A list of output offsets.
- Returns:
A dictionary of the weighted-average output offsets.
- ska_sdp_wflow_pointing_offset.utils.construct_antennas(xyz, diameter, station)[source]
Construct list of katpoint Antenna objects based on telescope configuration information.
- Parameters:
xyz – xyz coordinates of antenna positions in [nants, 3]
diameter – Diameter of dishes in [nants]
station – List of the antenna names [nants]
- Returns:
a set of katpoint Antenna objects
- ska_sdp_wflow_pointing_offset.utils.construct_ms_file_name(data_dir, scan_ids=None)[source]
Construct filenames based on scanID. Assumes one MS per scan ID.
- Parameters:
data_dir – Given directory name containing Measurement Sets
scan_ids – A list of scan IDs
- Returns:
A list of Measurement Sets filenames
- ska_sdp_wflow_pointing_offset.utils.convert_dict_to_numpy_array(offsets)[source]
Extracts the values from the dictionary of the fitted parameters and outputs them as a numpy array.
- Parameters:
offsets – A dictionary of the weighted-average pointing offsets output by
array_data_func.weighted_average()- Returns:
A numpy array of the input offsets
- ska_sdp_wflow_pointing_offset.utils.convert_offsets_to_degrees_for_kafka(offsets)[source]
Extracts the values from the dictionary of the fitted parameters and outputs them as a numpy array in degrees.
- Parameters:
offsets – A dictionary of the weighted-average pointing offsets output by
array_data_func.weighted_average()- Returns:
A converted numpy array where all the input offsets are now in degrees except the fitted heights and its uncertainty are in arbitrary units
- ska_sdp_wflow_pointing_offset.utils.convert_to_structured(poffset_data, last_scan_index)[source]
Convert pointing offset data from a numpy structure of 13 elements (antenna_name plus 12 floats representing fitting values) to a numpy structured array. The names of the fields are taken to match those in array_data_func.weighted_average() Include the last scan index as the second element in this structured data
- Parameters:
poffset_data – Offsets as numpy column_data
last_scan_index – Index of last scan
- Returns:
Offsets and last_scan_index as structured numpy data
- ska_sdp_wflow_pointing_offset.utils.create_dict_for_output_offsets(nants)[source]
Creates a dictionary of the fitted parameters and populates them with NaNs
- Parameters:
nants – The number of antennas
- Returns:
A dictionary of the fitted parameters populated with NaNs
- ska_sdp_wflow_pointing_offset.utils.create_empty_array(antennas)[source]
Create an empty array with 13 columns and as many rows as there are receptors to send to kafka if there is an exception while processing scans
- Parameters:
antennas – list of antenna names
- Returns:
empty array to send to kafka
- ska_sdp_wflow_pointing_offset.utils.get_crosscorrelations(vis)[source]
Extracts the cross-correlation visibilities and their weights from visibilities containing both auto and cross-correlations
- Parameters:
vis – Visibility object containing both auto and cross- correlations
- Returns:
Cross-correlation Visibility object for the parallel-hands polarisations
- ska_sdp_wflow_pointing_offset.utils.get_off_source_antenna_index(on_sky_offsets)[source]
Extracts the index of the antenna under test i.e the antenna performing the five-point scan or similar from the on-sky offsets in a two-dish mode reference pointing observation
- Parameters:
on_sky_offsets – The commanded pointings relative to the target in the reference pointing observation in xEl-El coordinates with dimensions (nscans, nants, 2)
- Returns:
A list of the index of the antenna performing the five-point or similar scan
- ska_sdp_wflow_pointing_offset.utils.get_parameters_for_gaussian_fits_plot(x_per_scan_list, y_per_scan_list, fitted_beams_list)[source]
Generate some parameters required for plotting the Gaussian fits in the two-dish mode scenario i.e, when the beams are fitted to the visibility amplitudes by merging the parameters from the two sets of observations
- Parameters:
x_per_scan_list – List of on-sky offsets from the two sets of observations
y_per_scan_list – List of visibility amplitudes from the two sets of observations
fitted_beams_list – The list of fitted beams from the two sets of observations
- Returns:
The on-sky offsets with dimension (nscans, nants, 2), the vis amplitudes with dimensions (nants, nscans) when num_chunks=1 or (nants, num_chunks, nscans) when num_chunks > 1. Note that nants is always 2 because only two antennas are used in the observation when the beams are fitted to the visibility amplitudes
- ska_sdp_wflow_pointing_offset.utils.handle_exception(err, traceback_frames, scan_ids)[source]
When an exception occurs store the error and traceback in the config db
- Parameters:
err – Exception thrown
traceback_frames – Exception traceback object
scan_ids – list of processed scan IDs
- Returns:
dict of error information
- ska_sdp_wflow_pointing_offset.utils.merge_output_offsets(output_offsets_list)[source]
Merges the output offsets from a two-dish scenario observation into a single dictionary of the output offsets
- Parameters:
output_offsets_list – A list of output offsets
- Returns:
A dictionary of the merged output offsets
- ska_sdp_wflow_pointing_offset.utils.observing_band(frequency_per_chunk)[source]
Compares the frequency per chunk to the dedicated frequency bands for the SKA and returns which observing band was used.
The observing frequency bands were obtained from https://www.skao.int/en/science-users/118/ska-telescope-specifications#__otpm4
- Parameters:
frequency_per_chunk – 1D array of the averaged-frequency in each chunk in Hz [num_chunks]
- Returns:
The frequency band within which an observation falls
- ska_sdp_wflow_pointing_offset.utils.select_channels(freqs, channels, start_freq, end_freq)[source]
Select the desired frequencies and corresponding channels of interest, by inputting the start and end frequency. The function will select the channels between these two frequencies.
- Parameters:
freqs – 1D frequency array in MHz [nchan]
channels – 1D frequency channel numbers
start_freq – Start frequency in MHz (float)
end_freq – End frequency in MHz (float)
- Returns:
selected array of (frequencies in MHz, channel numbers)
- ska_sdp_wflow_pointing_offset.utils.select_channels_and_split(freqs, channels, start_freq, end_freq, num_chunks)[source]
Selects frequencies and corresponding channels and split them into chunks
- Parameters:
freqs – Frequency array in MHz
channels – Channel array with same length as freqs
start_freq – Start frequency in MHz
end_freq – End frequency in MHz
- Returns:
Optionally selected frequencies and channels split into chunks
- ska_sdp_wflow_pointing_offset.utils.split_array_into_chunks(array, num_chunks)[source]
Split an array into chunks of num_chunks elements. When num_chunks > 1, the first and last chunks are discarded
- Parameters:
array – Array to be split (equally or unequally) into chunks
num_chunks – Number of chunks
- Returns:
Array with chunks of size num_chunks
- ska_sdp_wflow_pointing_offset.utils.weighted_avg_and_std(data, axis, weights, std_error=False)[source]
Compute weighted-average and standard deviation (or error).
- Parameters:
data – Data to be averaged (masked entries are ignored).
weights – Array of weights with same shape as data along the specified axes.
axis – Axis or axes along which to average data.
std_error – If set then return standard error instead of standard deviation (default=False)
- Returns:
weighted average and weighted standard deviation (or error).