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)

Return the intensity centroid [x, y] in pixel indices from pixel (0, 0).

change_directory(directory)

clean_image_for_strehl(img[, ...])

compute_fwhm_dark_subtracted_image(image)

cosine_similarity(v1, v2)

decrease_nice(*_ignored)

Deprecated: use raise_thread_priority().

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)

Return Gaussian weights on a grid_size square grid around cell (i, j).

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[, unique_str])

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[, num_iters])

Measure repeated execution-time statistics for a callable.

next_power_of_two(n)

power_law_og(num_modes, k)

precise_delay(microseconds)

pyplot()

Import and return matplotlib.pyplot on first use.

raise_thread_priority([realtime_priority])

Raise the calling thread's scheduling priority (Linux only).

read_input_with_timeout(timeout)

read_yaml_file(file_path)

Load a YAML file and return the parsed Python object.

require_optional(module, extra, feature)

Import an optional dependency, or raise ImportError naming its extra.

robust_variance(data)

set_affinity(affinity)

Pin the calling thread to the given CPU core(s).

set_affinity_and_priority(thread_id, cpu_cores)

Pin the calling thread and raise its priority, logging what applied.

set_from_config(conf, name, default)

Return a config value or a typed default.

signal_2d(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.