cogwheel.utilsΒΆ

Utility functions.

Functions

clear_caches

Clear caches of functions decorated with lru_cache.

exp_normalize

Return normalized probabilities from unnormalized log probabilities.

get_eventdir

Return pathlib.Path object for a directory of the form parentdir/prior_name/eventname/.

get_priordir

Return pathlib.Path object for a directory of the form parentdir/prior_name.

get_rundir

Return path to a directory where a new inference run can take place.

handle_scalars

Return a function that outputs a scalar instead of 0-d array.

import_lal

Import lal, disabling stdout/stderr redirection if in ipython.

lru_cache

Cache function results and register it for easy cache clearing.

merge_dictionaries_safely

Merge multiple dictionaries into one.

mkdirs

Create directory and its parents if needed.

mod

Modulus operation, but allows to specify the domain of the output.

n_effective

Calculate the effective sample size from a set of weights.

quantile

Compute the q-th quantile of the data.

read_json

Return a class instance that was saved to json.

real_matmul

Return real part of complex matrix multiplication.

replace

Replace specified elements in a sequence with new values.

resample_equal

Resample a weighted DataFrame to produce equal-weight samples.

rundir_number

Return first strech of numbers in rundir as int.

sorted_rundirs

Return rundirs sorted by number (i.e. 'run_2' before 'run_10').

submit_condor

Generic function to submit a job using HTCondor.

submit_lsf

Generic function to submit a job using IBM Spectrum LSF.

submit_slurm

Generic function to submit a job using slurm.

temporarily_change_attributes

Change attributes of an object temporarily in a context manager.

update_dataframe

Modify a dataframe in-place by adding the columns from another.

weighted_avg_and_std

Return average and standard deviation of values with weights.

Classes

ClassProperty

Like @property but for class attributes instead of instance attributes.

CogwheelDecoder

Decoder for subclasses of JSONMixin.

CogwheelEncoder

Encoder for subclasses of JSONMixin.

InitDictMixin

Provide methods get_init_dict and reinstantiate.

JSONMixin

Provide JSON output to subclasses.

NumpyEncoder

Encoder for numpy data types.