bahamas.method

bahamas.method.gaps

This module generates observation gaps based on scheduled and unscheduled constraints. It provides a function to create gaps in observation data, considering scheduled periods, unscheduled events, and merging close gaps.

bahamas.method.gaps.generate_gaps(T_obs, scheduled_gap=25200, scheduled_period=1209600, unscheduled_gap=259200, exp_scale=864000, merge_threshold=86400, duty_cycle=0.75)

Generate observation gaps based on scheduled and unscheduled constraints. :param T_obs: Total observation time in seconds. :type T_obs: int :param scheduled_gap: Duration of scheduled gaps in seconds. :type scheduled_gap: int :param scheduled_period: Duration of scheduled periods in seconds. :type scheduled_period: int :param unscheduled_gap: Duration of unscheduled gaps in seconds. :type unscheduled_gap: int :param exp_scale: Scale for the exponential distribution for unscheduled gaps. :type exp_scale: int :param merge_threshold: Threshold for merging close gaps in seconds. :type merge_threshold: int :param duty_cycle: Desired duty cycle for observing time. :type duty_cycle: float

Returns:

Start and end times of data segments as numpy arrays.

Return type:

tuple

bahamas.method.setting_hmc

This module contains functions for sampling and likelihood computation in a Bayesian analysis framework. It includes functions for sampling parameters from prior distributions and computing likelihoods using the Whittle and Gamma methods. It is designed to work with the BAHAMAS framework for analyzing gravitational wave signals.

Functions:

prior_sample(sources): Samples parameters from prior distributions for multiple sources. whittle_lik(data, freqs, response, sources, …): Computes the Whittle likelihood. gamma_lik(data, freqs, response, sources, …): Computes the Gamma likelihood. beta_scaled_log_likelihood(log_like_fn, beta): Scales a log-likelihood by a beta factor.

Dependencies:
  • JAX

  • NumPyro

  • psd_function (custom module)

bahamas.method.setting_hmc.beta_scaled_log_likelihood(log_like_fn, beta)

Scale a log-likelihood function by a beta factor.

Parameters: - log_like_fn (callable): Log-likelihood function. - beta (float): scaling factor.

Returns: - callable: Scaled log-likelihood function.

bahamas.method.setting_hmc.gamma_lik(data, freqs, response, sources, dt, t1, t2, dof, gen2)

Compute the Gamma likelihood.

Parameters: - data (list): Observed data segments. - freqs (list): Frequency grids for each segment. - response (list): Response functions for each segment. - sources (dict): Source parameters. - dt (float): Time step. - t1, t2 (list): Start and end times for each segment. - dof (list): Degrees of freedom for each segment.

Returns: - None: Adds the log-likelihood factor to the NumPyro model.

bahamas.method.setting_hmc.prior_sample(sources)

Sample parameters from prior distributions for multiple sources.

Parameters: - sources (dict): Dictionary of sources and their parameter configurations.

Returns: - dict: Dictionary of sampled parameters for each source.

bahamas.method.setting_hmc.whittle_lik(data, freqs, response, sources, dt, t1, t2, dof, gen2)

Compute the Whittle likelihood.

Parameters: - data (list): Observed data segments. - freqs (list): Frequency grids for each segment. - response (list): Response functions for each segment. - sources (dict): Source parameters. - dt (float): Time step. - t1, t2 (list): Start and end times for each segment. - dof (list): Degrees of freedom for each segment.

Returns: - None: Adds the log-likelihood factor to the NumPyro model.

bahamas.method.setting_inference

This module provides utilities for setting up Bayesian inference, including reading data, selecting likelihood methods, and initializing matrices for EGP modeling.

Functions:

read_data(config): Reads HDF5 data and applies frequency masking if specified. set_inference(config, sources): Sets up the inference process, including likelihood and EGP matrix initialization.

Classes:

InferenceMethod: Handles the selection of likelihood methods and related configurations. EGPMatrix: Initializes the EGP matrix for Gaussian Process modeling.

Dependencies:
  • egp (custom module)

  • method (custom module)

  • NumPy

  • h5py

class bahamas.method.setting_inference.InferenceMethod(config, t1, t2, count)

Bases: object

Handles the selection of likelihood methods and related configurations.

select_method()

Select the likelihood method and configure it based on the sampler and mode.

Returns:

A tuple containing:
  • log_like (callable): The selected likelihood function.

  • t1 (array): Start times for each segment.

  • t2 (array): End times for each segment.

  • dof (array): Degrees of freedom for each segment.

Return type:

tuple

bahamas.method.setting_inference.get_first_part(path: str) str

Extract the first part of a file path.

Parameters: - path (str): The file path.

Returns: - str: The first part of the file path.

bahamas.method.setting_inference.read_data(config)

Reads HDF5 data from the specified file and applies frequency masking if specified.

Parameters:

config (dict) – Configuration containing the file path and optional frequency masking parameters (‘f1’, ‘f2’).

Returns:

A tuple containing:
  • data_list (list): List of data arrays for each segment.

  • response_list (list): List of response arrays for each segment.

  • freq_list (list): List of frequency arrays for each segment.

  • count (list): List of count arrays for each segment.

Return type:

tuple

bahamas.method.setting_inference.set(config, sources)

Set up the inference process, including likelihood and EGP matrix initialization.

Parameters:
  • config (dict) – Configuration dictionary.

  • sources (dict) – Source parameters.

Returns:

A tuple containing:
  • log_like (callable): The selected likelihood function.

  • data (list): Observed data segments.

  • freqs (list): Frequency grids for each segment.

  • response (list): Response functions for each segment.

  • dt (float): Time step.

  • t1 (array): Start times for each segment.

  • t2 (array): End times for each segment.

  • dof (array): Degrees of freedom for each segment.

  • matrix_egp (np.ndarray or None): The initialized EGP matrix.

Return type:

tuple