pyRTC.utils

General utility helpers shared across pyRTC.

The utilities in this module cover several small but widely used concerns: configuration validation, file-path helpers, timing helpers, dtype encoding, basic numerical helpers, and lightweight socket/process convenience functions.

They are kept here because they are broadly reusable across components and do not belong to a single subsystem.

Functions

add_to_buffer(buffer, vec)

add_to_path(directory)

adjusted_cosine_similarity(a, b)

angle_between_vectors(v1, v2)

append_to_file(filename, data[, dtype])

Append a numpy array to a binary file on disk.

bind_socket(host, start_port[, max_attempts])

Bind a TCP socket, retrying across a short range of ports.

centroid(array)

change_directory(directory)

clean_image_for_strehl(img[, ...])

compute_fwhm_dark_subtracted_image(image)

cosine_similarity(v1, v2)

decrease_nice()

dtype_to_float(dtype)

Convert a NumPy dtype to a unique float.

float_to_dtype(dtype_float)

Convert a unique float back to the original NumPy dtype.

gaussian_2d_grid(i, j, sigma, grid_size)

generate_circular_aperture_mask(N, R, ratio)

Generates a binary mask of size NxN with a circular aperture of radius R and a central obscuration of radius r.

generate_filepath([base_dir, prefix, extension])

Generate a file path based on the current date and time.

get_tmp_filepath(file_path[, uniqueStr])

Append '_tmp' to the filename part of the given file path, before the file extension.

is_numeric(s)

load_data(filename[, dtype])

measure_execution_time(f, args[, numIters])

Measure repeated execution-time statistics for a callable.

next_power_of_two(n)

powerLawOG(numModes, k)

precise_delay(microseconds)

read_input_with_timeout(timeout)

read_yaml_file(file_path)

Load a YAML file and return the parsed Python object.

robust_variance(data)

setFromConfig(conf, name, default)

Return a config value or a typed default.

set_affinity(affinity)

set_affinity_and_priority(thread_id, cpu_cores)

signal2D(signal, layout)

validate_component_config(conf, mro_names)

Dispatch configuration validation based on the component class hierarchy.

validate_loop_config(conf)

validate_wfc_config(conf)

validate_wfs_config(conf)

Exceptions

ConfigValidationError

Raised when a component configuration does not meet pyRTC expectations.