diffbank.bank.Bank#

class diffbank.bank.Bank(amp, Psi, fs, Sn, m_star, eta, sample_base, density_fun_base=<function Bank.<lambda>>, name='test')[source]#

Bases: object

Class representing a template bank.

calc_bank_effectualness(key, n, show_progress=True)[source]#

Computes effectualness of bank at points sampled from the metric density. See diffbank.utils.get_bank_effectualness().

Raises

RuntimeError – if the bank does not contain templates

computed_vars: Set[str] = {'_dim', '_eff_pad_high', '_eff_pad_low', 'effectualness_points', 'effectualnesses', 'eta_est', 'eta_est_err', 'n_templates', 'ratio_max', 'templates'}[source]#

The names of attributes that are computed in the course of working with a bank. For example, this includes "templates".

density_fun(theta)[source]#

Computes the determinant of the metric over the intrinsic of the binary, maximized over the time and phase at coalescence. See diffbank.metric.get_density().

Return type

ndarray

property dim: int[source]#

The dimensionality of the bank’s parameter space.

Return type

int

est_ratio_max(key, n_iter=1000, n_init=200, show_progress=True)[source]#

Estimate maximum of the ratio of target to base density using empirical supremum rejection sampling. See diffbank.utils.est_ratio_max().

Return type

Tuple[ndarray, ndarray]

fill_bank(key, method='random', n_eff=1000, show_progress=True)[source]#

Fills the bank with the required number of templates using the random or stochastic sampling methods from Coogan et al 2022. Updates the templates and n_templates attributes. See diffbank.utils.gen_bank_random() and diffbank.utils.gen_bank_stochastic().

Raises

RuntimeError – if ratio_max is not set

g_fun(theta)[source]#

Computes the metric for the intrinsic binary parameters of the binary, maximized over the time and phase at coalescence. See diffbank.metric.get_density().

Return type

ndarray

gam_fun(theta)[source]#

Computes the metric for the time of coalescence and intrinsic parameters of the binary. See diffbank.metric.get_gam().

Return type

ndarray

gen_template_rejection(key)[source]#

Generates a single template using rejection sampling. See diffbank.utils.gen_template_rejection().

Raises

RuntimeError – if ratio_max is not set

Return type

ndarray

gen_templates_rejection(key, n_templates)[source]#

Generates multiple templates using rejection sampling. See diffbank.utils.gen_template_rejection().

Raises

RuntimeError – if ratio_max is not set

Return type

ndarray

get_top_matches_templates(theta2s, amp2=None, Psi2=None, n_top=1, show_progress=True)[source]#

Finds best-matching templates for a set of points for a waveform model distinct from the bank’s. See diffbank.utils.get_top_matches_templates().

Raises

RuntimeError – if the bank does not contain templates

Return type

Tuple[ndarray, ndarray]

classmethod load(path, amp, Psi, Sn, sample_base, ignore_key_errors=False)[source]#

Loads template bank’s non-function attributes from a npz file. The other required attributes must be provided as arguments to this function.

Parameters
  • path (str) – path to npz file generated with Bank.save

  • amp (Callable[[ndarray, ndarray], ndarray]) – function returning the amplitude of the Fourier-domain waveform as a function of frequency and parameters

  • Psi (Callable[[ndarray, ndarray], ndarray]) – function returning the phase of the Fourier-domain waveform as a function of frequency and parameters

  • Sn (Callable[[ndarray], ndarray]) – power spectral density of the detector noise

  • sample_base (Callable[[PRNGKeyArray, int], ndarray]) – jit-able base sampler for rejection sampling from the metric density. Takes a key and number of samples as arguments.

  • ignore_key_errors (bool) – if True, will try to load the bank even if there are extra or missing keys in the npz file.

Raises

ValueError – if the bank being loaded is missing or contains extra keys, and ignore_key_errors is False. This should only happen when trying to load old banks after diffbank goes through major updates.

Returns

A new Bank

match_fun(theta1, theta2, amp2=None, Psi2=None)[source]#

Gets the match between a point from the bank’s waveform model and a different point, potentially with a distinct waveform model. See diffbank.utils.get_match().

Parameters
  • theta1 (ndarray) – the point from the same waveform model as the bank

  • theta2 (ndarray) – the other point

  • amp2 (Optional[Callable[[ndarray, ndarray], ndarray]]) – amplitude function for the theta2. If not provided, it is assumed theta2 has the same waveform model as the bank.

  • Psi2 (Optional[Callable[[ndarray, ndarray], ndarray]]) – phase function for the theta2. If not provided, it is assumed theta2 has the same waveform model as the bank.

Return type

ndarray

Returns

The match between the waveforms for the two points.

provided_vars: Set[str] = {'eta', 'fs', 'm_star', 'name'}[source]#

The names of attributes containing data the user provides when initialing a bank

save(path='')[source]#

Saves template bank non-function attributes to a npz file. The file name is the bank’s name plus the .npz extension.

Parameters

path (str) – directory in which to save bank