astrohack.utils.algorithms

Functions

tokenize_version_number(version_number)

Tokenize a version number into an array of integers

data_from_version_needs_patch(version_to_check, ...)

Check if data from a version needs to be patched according to a reference patch version

calc_coords(image_size, cell_size)

Calculate the center pixel of the image given a cell and image size

find_nearest(array, value)

Find the nearest entry in array to that of value.

chunked_average(data, weight, avg_map, avg_freq)

Average visibilities in chunks with close enough frequencies

find_peak_beam_value(data[, height, scaling])

Search algorithm to determine the maximal signal peak in the beam pattern.

gauss_elimination(system, vector)

Gauss elimination solving of a system using numpy

least_squares(system, vector[, return_sigma])

Least squares fitting of a system of linear equations

least_squares_jit(system, vector)

Least squares fitting of a system of linear equations

calculate_optimal_grid_parameters(pnt_map_dict, ...)

compute_average_stokes_visibilities(vis, stokes)

compute_stokes(data, weight, pol_axis)

compute_antenna_relative_off(antenna, tel_lon, ...[, ...])

Computes an antenna offset to the array center

rotate_to_gmt(positions, errors, longitude)

Rotate geometrical delays from antenna reference frame to GMT reference frame

data_statistics(data_array)

phase_wrapping(phase)

Wraps phase to the -pi to pi interval

create_coordinate_images(x_axis, y_axis[, ...])

Takes two axes and creates 2D representation of the image coordinates

arm_shadow_masking(inmask, x_mesh, y_mesh, ...)

are_axes_equal(axis_a, axis_b)

create_2d_array_reconstruction_array(x_axis, y_axis, mask)

regrid_data_onto_2d_grid(x_axis, y_axis, linear_array, ...)

Use index information to get 1D data back onto a 2D grid.

compute_antenna_baseline_distance_matrix_dict(ant_pos, ...)

Compute a matrix of antenna position distances from antenna positions

Module Contents

tokenize_version_number(version_number)[source]

Tokenize a version number into an array of integers :param version_number: The astrohack number version to be tokenized

Returns:

Tokenized version number in 3 element numpy array of integers

data_from_version_needs_patch(version_to_check, patched_version)[source]

Check if data from a version needs to be patched according to a reference patch version :param version_to_check: The version that is being tested :param patched_version: Reference version at which the patch is no longer needed

Returns:

True if the checked version is from before the patch False elsewise

calc_coords(image_size, cell_size)[source]

Calculate the center pixel of the image given a cell and image size

Parameters:
  • image_size (np.ndarray) – image size

  • cell_size (np.ndarray) – cell size

Returns:

center pixel location in coordinates x, y

Return type:

float, float

find_nearest(array, value)[source]

Find the nearest entry in array to that of value.

Parameters:
  • array (numpy.array) – _description_

  • value (float) – _description_

Returns:

index, array value

Return type:

int, float

chunked_average(data, weight, avg_map, avg_freq)[source]

Average visibilities in chunks with close enough frequencies :param data: Visibility data :param weight: Visibility weights :param avg_map: mapping of channels to average :param avg_freq: new frequency ranges

Returns: Chunked average of visibilities and weights

find_peak_beam_value(data, height=0.5, scaling=0.5)[source]

Search algorithm to determine the maximal signal peak in the beam pattern.

Parameters:
  • data (numpy.ndarray) – beam data grid

  • height (float, optional) – Peak threshold. Looks for the maximum peak in data and uses a percentage of this peak to determine a threshold for other peaks. Defaults to 0.5.

  • scaling (float, optional) – scaling factor for beam data cropping. Defaults to 0.5.

Returns:

peak maximum value

Return type:

float

gauss_elimination(system, vector)[source]

Gauss elimination solving of a system using numpy :param system: System matrix to be solved :param vector: Vector that represents the right hand side of the system

Returns: The solved system

least_squares(system, vector, return_sigma=False)[source]

Least squares fitting of a system of linear equations The variances are simplified as the diagonal of the covariances :param system: System matrix to be solved :param vector: Vector that represents the right hand side of the system :param return_sigma: Return sigma value

Returns: The solved system, the variances of the system solution and the sum of the residuals

least_squares_jit(system, vector)[source]

Least squares fitting of a system of linear equations The variances are simplified as the diagonal of the covariances :param system: System matrix to be solved :param vector: Vector that represents the right hand side of the system

Returns: The solved system, the variances of the system solution and the sum of the residuals

calculate_optimal_grid_parameters(pnt_map_dict, antenna_name, telescope_diameter, chan_freq, ddi)[source]
compute_average_stokes_visibilities(vis, stokes)[source]
compute_stokes(data, weight, pol_axis)[source]
compute_antenna_relative_off(antenna, tel_lon, tel_lat, tel_rad, scaling=1.0)[source]

Computes an antenna offset to the array center :param antenna: Antenna information dictionary :param tel_lon: array center longitude :param tel_lat: array center latitude :param tel_rad: array center’s distance to the center of the earth :param scaling: scale factor

Returns: Offset to the east, Offset to the North, elevation offset and distance to array center

rotate_to_gmt(positions, errors, longitude)[source]

Rotate geometrical delays from antenna reference frame to GMT reference frame :param positions: geometrical delays :param errors: geometrical delay errors :param longitude: Antenna longitude

Returns: Rotated geometrical delays and associated errors

data_statistics(data_array)[source]
phase_wrapping(phase)[source]

Wraps phase to the -pi to pi interval :param phase: phase to be wrapped

Returns: Phase wrapped to the -pi to pi interval

create_coordinate_images(x_axis, y_axis, create_polar_coordinates=False)[source]

Takes two axes and creates 2D representation of the image coordinates :param x_axis: X axis :param y_axis: Y axis :param create_polar_coordinates: Also create polar coordinates images?

Returns:

x_mesh and y_mesh, plus radius_mesh and polar_angle_mesh if create_polar_coordinates

arm_shadow_masking(inmask, x_mesh, y_mesh, radius_mesh, minradius, maxradius, width, angle)[source]
are_axes_equal(axis_a, axis_b)[source]
create_2d_array_reconstruction_array(x_axis, y_axis, mask)[source]
regrid_data_onto_2d_grid(x_axis, y_axis, linear_array, grid_idx)[source]

Use index information to get 1D data back onto a 2D grid. :param x_axis: X axis of the data on the 2 D grid :param y_axis: Y axis of the data on the 2 D grid :param linear_array: Linearized masked array :param grid_idx: Linearized 2 D indexes onto the original grid

Returns: Data regridded onto a 2D array

compute_antenna_baseline_distance_matrix_dict(ant_pos, ant_names)[source]

Compute a matrix of antenna position distances from antenna positions :param ant_pos: antenna position array :param ant_names: antenna names array :return: dict with antenna distance matrix