Skip to content

utils

Utility functions for the argus package.

load_config

load_config(config_path)

Load configuration from file.

Parameters

config_path : str Path to the configuration file

Returns

configparser.ConfigParser Configuration object containing all settings

Raises

FileNotFoundError If the configuration file does not exist

resolve_config_paths

resolve_config_paths(config, config_path)

Resolve relative paths in configuration relative to config file location.

This function modifies the config object in-place, converting any relative paths to absolute paths based on the directory containing the config file. Absolute paths are left unchanged.

Parameters

config : configparser.ConfigParser Configuration object to modify config_path : str Path to the configuration file (used as base for relative paths)

Returns

configparser.ConfigParser The same config object with resolved paths (modified in-place)

get_noise_parameters

get_noise_parameters(config)

Get injected noise parameters from configuration and data files.

Parameters:

  • config

    Configuration object

Returns

tuple: (efac_array, equad_array, sigma_p_array, gamma_p_array)

setup_logging

setup_logging(output_dir, config)

Set up logging configuration.

DEPRECATED: Use io_manager.setup_single_logger() instead for centralized logging. This function is kept for backward compatibility.

Parameters

output_dir : str Directory where log files will be stored config : configparser.ConfigParser Configuration object containing logging settings

Returns

logging.Logger Configured logger instance

check_gpu_availability

check_gpu_availability()

Check for GPU availability and configure JAX accordingly.

Returns

bool True if GPU is available, False otherwise

get_efac_equad_injections

get_efac_equad_injections(noise_params_path, excluded_psrs=[])

Load EFAC and EQUAD values from noise parameters file.

Parameters

noise_params_path : str Path to the noise parameters JSON file excluded_psrs : list of str, optional List of pulsar names to exclude from the analysis. Default is an empty list.

Returns

tuple Two JAX arrays containing EFAC and EQUAD values for the included pulsars.

get_psr_noise_injections

get_psr_noise_injections(spin_injections_path, excluded_psrs=[])

Load pulsar noise parameters from pickle file.

Parameters

spin_injections_path : str Path to the spin injections pickle file excluded_psrs : list of str, optional List of pulsar names to exclude from the analysis. Default is an empty list.

Returns

tuple Two JAX arrays containing sigma_p and gamma_p values for the included pulsars.

corner_plot

corner_plot(results, output_dir=None)

Create a corner plot for log10_ha parameter from inference results.

Parameters

results : str or object Either a file path (string) to results file, or a results object. For NumPyro: path to NetCDF file or arviz.InferenceData object output_dir : str, optional Directory to save the plot. If None, plot is shown but not saved.

Returns

str or None Path to saved plot file, or None if not saved

diagnostics

diagnostics(fname, output_dir=None)

Run MCMC diagnostics on NumPyro results.

Parameters:

  • fname (str) –

    Path to NumPyro results NetCDF file

  • output_dir (str, default: None ) –

    Directory to save diagnostics outputs

find_results_file

find_results_file(output_dir, file_pattern)

Find results file in output directory matching pattern.

Parameters

output_dir : str Directory to search for results files file_pattern : str Glob pattern to match files (e.g., 'inference_results_*.json')

Returns

str or None Path to the first matching results file, or None if not found

load_numpyro_results

load_numpyro_results(results_file)

Load NumPyro results from NetCDF file.

Parameters

results_file : str Path to NumPyro results NetCDF file

Returns

arviz.InferenceData ArviZ InferenceData object

extract_log_evidence

extract_log_evidence(results, method)

Extract log evidence from results object.

Parameters

results : object Results object (ArviZ only) method : str Inference method ('numpyro' only)

Returns

tuple (log_evidence, log_evidence_uncertainty)

load_jaxns_results

load_jaxns_results(results_file)

Load JAXNS results - DEPRECATED.

Parameters

results_file : str Path to results file

Raises

ValueError Always raised as JAXNS is no longer supported

get_inference_method_from_files

get_inference_method_from_files(output_dir)

Determine inference method used based on result files in directory.

Parameters

output_dir : str Output directory to check

Returns

str or None 'numpyro' if NumPyro results found, None if not found