πŸ…Ό oscfar.gaussian_fit

Functions

  1. πŸ…Ό oscfar.gaussian_fit
    1. πŸ…΅ oscfar.gaussian_fit.sum_of_gaussians
    2. πŸ…΅ oscfar.gaussian_fit.sum_of_scattered_gaussians
    3. πŸ…΅ oscfar.gaussian_fit.find_best_multi_gaussian_fit
    4. πŸ…΅ oscfar.gaussian_fit.find_best_multi_gaussian_fit_combinatorial
  2. πŸ…Ό oscfar.generate_docs
    1. Constants
    2. πŸ†… oscfar.generate_docs.MODULE_ORDER
    3. πŸ†… oscfar.generate_docs.DOC_TARGETS
    4. Functions
    5. πŸ…΅ oscfar.generate_docs.parse_args
    6. πŸ…΅ oscfar.generate_docs.find_anchor_block
    7. πŸ…΅ oscfar.generate_docs.normalize_module_block
    8. πŸ…΅ oscfar.generate_docs.get_existing_front_matter
    9. πŸ…΅ oscfar.generate_docs.default_front_matter
    10. πŸ…΅ oscfar.generate_docs.write_module_docs
    11. πŸ…΅ oscfar.generate_docs.main

πŸ…΅ oscfar.gaussian_fit.sum_of_gaussians

def sum_of_gaussians(x, *params):

Calculates the sum of multiple Gaussian functions.

Each Gaussian is defined by its amplitude, mean, and standard deviation. The parameters for the Gaussians are provided in a flat list: [amp1, mean1, stddev1, amp2, mean2, stddev2, ..., ampN, meanN, stddevN]

Parameters:

  • x (np.array): The independent variable where the functions are calculated.
  • *params (list or np.array): A variable number of arguments representing the parameters. The total number of parameters must be a multiple of 3.
  • amp: Amplitude of the Gaussian.
  • mean: Mean (center) of the Gaussian.
  • stddev: Standard deviation (width) of the Gaussian.

Returns:

  • y (np.ndarray): The sum of the Gaussian functions evaluated at x.

Raises:

  • ValueError: If the number of parameters in `params` is not a multiple of 3.

    πŸ…΅ oscfar.gaussian_fit.sum_of_scattered_gaussians

def sum_of_scattered_gaussians(x, *params):

Calculates the sum of multiple scattered Gaussian functions.

Each scattered Gaussian is defined by its amplitude, mean, standard deviation, and scattering timescale. The parameters for the scattered Gaussians are provided in a flat list: [amp1, mean1, sigma1, tau1, amp2, mean2, sigma2, tau2, ..., ampN, meanN, sigmaN, tauN]

Parameters:

  • x (np.array): The independent variable where the functions are calculated.
  • *params (list or np.array): A variable number of arguments representing the parameters. The total number of parameters must be a multiple of 4.
  • amp: Amplitude of the scattered Gaussian.
  • mean: Mean (center) of the scattered Gaussian.
  • sigma: Standard deviation (width) of the Gaussian before scattering.
  • tau: Scattering timescale.

Returns:

  • y (np.ndarray): The sum of the scattered Gaussian functions evaluated at x.

Raises:

  • ValueError: If the number of parameters in `params` is not a multiple of 4.

    πŸ…΅ oscfar.gaussian_fit.find_best_multi_gaussian_fit

def find_best_multi_gaussian_fit(x_data, y_data, initial_flat_params, max_n_gaussians = None, y_err = None):

Finds the best fit to the data using a sum of Gaussian functions.

This function attempts to fit the data with a varying number of Gaussian components, up to a specified maximum. The best fit is determined by comparing the Bayesian Information Criterion (BIC) for each fit.

Parameters:

  • x_data (np.array): The independent variable where the data is measured.
  • y_data (np.array): The dependent data to be fitted.
  • initial_flat_params (list or np.array): A flat list of initial parameters for Gaussian components, ordered as [amp1, mean1, sigma1, amp2, mean2, sigma2, ...]. Amplitudes can be positive or negative.
  • max_n_gaussians (int): The maximum number of Gaussian components to try. If None, it defaults to the number of components implied by `initial_flat_params`.
  • y_err (list or np.array): Error on y_data. If provided, it’s used in `curve_fit` for weighted least squares.

Returns:

  • fit_results (dict): Fitting results with keys:
  • β€˜best_fit’: Results for the best model (lowest BIC), including β€˜n_components’, β€˜popt’, β€˜pcov’, β€˜bic’, and β€˜rss’.
  • β€˜all_fits’: Results for all attempted component counts.

Raises:

  • ValueError: If `initial_flat_params` is invalid (empty or not a multiple of 3), if `x_data` and `y_data` are empty or have different lengths.

    πŸ…΅ oscfar.gaussian_fit.find_best_multi_gaussian_fit_combinatorial

def find_best_multi_gaussian_fit_combinatorial(x_data, y_data, initial_flat_params, max_n_gaussians = None, y_err = None, max_initial_components_for_pool = None, model_to_test = 'gaussian', default_initial_tau = 0.0001, max_tau_bound_factor = 1.0, use_multiprocessing = True, num_processes = None):

Performs a grid search to find the best multi-component fit by trying

different numbers of components, different combinations of initial peak guesses, and optionally different model types (Gaussian or Scattered Gaussian).

This version supports multiprocessing to speed up the fitting process.

Args: (Same as the single-process version, plus the following:) use_multiprocessing (bool, optional): Whether to use multiprocessing. Defaults to True. num_processes (int, optional): The number of processes to use. If None, uses the number of CPU cores.

Returns: fit_results (dict): Same structure as `_process_model_fit`, containing best-fit and all-fit results for the selected model(s).

Raises: (Same as the single-process version)

πŸ…Ό oscfar.generate_docs

Constants

πŸ†… oscfar.generate_docs.MODULE_ORDER

MODULE_ORDER = ['oscfar', 'oscfar-cfar', 'oscfar-cluster', 'oscfar-filters', 'oscfar-gaussian_fit', 'oscfar-reload', 'oscfar-setup', 'oscfar-utils']

πŸ†… oscfar.generate_docs.DOC_TARGETS

DOC_TARGETS = {'oscfar': {'file': 'oscfar.md', 'title': 'General functions', 'nav_order': 1}, 'oscfar-cfar': {'file': 'oscfar-cfar.md', 'title': 'CFAR Algorithms', 'nav_order': 2}, 'oscfar-filters': {'file': 'oscfar-filters.md', 'title': 'Filtering', 'nav_order': 3}, 'oscfar-cluster': {'file': 'oscfar-cluster.md', 'title': 'Clustering', 'nav_order': 4}, 'oscfar-gaussian_fit': {'file': 'oscfar-gaussian.md', 'title': 'Fitting', 'nav_order': 5}, 'oscfar-utils': {'file': 'oscfar-utils.md', 'title': 'Utilities', 'nav_order': 6}}

Functions

πŸ…΅ oscfar.generate_docs.parse_args

def parse_args() -> argparse.Namespace:

πŸ…΅ oscfar.generate_docs.find_anchor_block

def find_anchor_block(content: str, anchor: str, anchor_positions: dict[str, int]) -> str:

πŸ…΅ oscfar.generate_docs.normalize_module_block

def normalize_module_block(block: str) -> str:

πŸ…΅ oscfar.generate_docs.get_existing_front_matter

def get_existing_front_matter(path: Path) -> str | None:

πŸ…΅ oscfar.generate_docs.default_front_matter

def default_front_matter(title: str, nav_order: int) -> str:

πŸ…΅ oscfar.generate_docs.write_module_docs

def write_module_docs(content: str, docs_dir: Path) -> None:

πŸ…΅ oscfar.generate_docs.main

def main() -> None: