Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate SNR/FAR for live pastro calcs #4278

Merged
merged 5 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion pycbc/population/live_pastro.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ def check_template_param_bin_data(spec_json):
return spec_json


def check_template_param_bin_farlim_data(spec_json):
"""
Parameters
----------
spec_json: JSON dictionary-like object
Result of parsing json file containing static data

Returns
-------
spec_json: dictionary
"""
# Standard template param bin checks
check_template_param_bin_data(spec_json)

# In addition, need limiting FAR and SNR values
assert 'limit_far' in spec_json
assert 'limit_snr' in spec_json

return spec_json


def read_template_bank_param(spec_d, bankf):
"""
Parameters
Expand Down Expand Up @@ -206,7 +227,7 @@ def template_param_bin_types_pa(padata, trdata, horizons):
else:
expfac = padata.spec['bg_fac']

# Ifos over trigger threshold
# List of ifos over trigger threshold
tr_ifos = trdata['triggered']

# FAR is in Hz, therefore convert to rate per year (per SNR)
Expand Down Expand Up @@ -238,6 +259,29 @@ def template_param_bin_types_pa(padata, trdata, horizons):
return p_astro, 1 - p_astro


def template_param_bin_types_farlim_pa(padata, trdata, horizons):
"""
Parameters
----------
padata: PAstroData instance
Static information on p astro calculation
trdata: dictionary
Trigger properties
horizons: dictionary
BNS horizon distances keyed on ifo

Returns
-------
p_astro, p_terr: tuple of floats
"""
# If the network SNR and FAR indicate saturation of the FAR estimate,
# set them to specified fixed values
trdata = padata.apply_significance_limits(trdata)

# Now perform standard calculation with event types
return template_param_bin_types_pa(padata, trdata, horizons)


__all__ = [
"check_template_param_bin_data",
"read_template_bank_param",
Expand All @@ -247,4 +291,5 @@ def template_param_bin_types_pa(padata, trdata, horizons):
"signal_rate_trig_type",
"template_param_bin_pa",
"template_param_bin_types_pa",
"template_param_bin_types_farlim_pa",
]
43 changes: 37 additions & 6 deletions pycbc/population/live_pastro_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@ def insert_live_pastro_option_group(parser):

# Choices of p astro calc method
_check_spec = {
'template_param_bins': livepa.check_template_param_bin_data,
'template_param_bins_types': livepa.check_template_param_bin_data
'template_param_bins': livepa.check_template_param_bin_data,
'template_param_bins_types': livepa.check_template_param_bin_data,
'template_param_bins_types_farlim':
livepa.check_template_param_bin_farlim_data
}

_read_bank = {
'template_param_bins': livepa.read_template_bank_param,
'template_param_bins_types': livepa.read_template_bank_param
'template_param_bins': livepa.read_template_bank_param,
'template_param_bins_types': livepa.read_template_bank_param,
'template_param_bins_types_farlim': livepa.read_template_bank_param
}

_do_calc = {
'template_param_bins': livepa.template_param_bin_pa,
'template_param_bins_types': livepa.template_param_bin_types_pa
'template_param_bins': livepa.template_param_bin_pa,
'template_param_bins_types': livepa.template_param_bin_types_pa,
'template_param_bins_types_farlim':
livepa.template_param_bin_types_farlim_pa
}


Expand Down Expand Up @@ -71,6 +76,32 @@ def __init__(self, specfile, bank):
self.spec = _check_spec[self.method](self.spec_json)
self.bank = _read_bank[self.method](self.spec, bank)

def apply_significance_limits(self, trigger_data):
"""
If the network SNR and FAR indicate saturation of the FAR estimate,
set them to the fixed values given in the specification.
"""
# This only happens for double or triple events
if len(trigger_data['triggered']) == 1:
return trigger_data

if len(trigger_data['triggered']) > 1:
farlim = self.spec['limit_far']
snrlim = self.spec['limit_snr']
# Only do anything if FAR and SNR are beyond given limits
if trigger_data['far'] > farlim or \
trigger_data['network_snr'] < snrlim:
return trigger_data

logging.debug('Truncating FAR and SNR from %f, %f to %f, %f',
trigger_data['far'], trigger_data['network_snr'],
farlim, snrlim)
trigger_data['network_snr'] = snrlim
trigger_data['far'] = farlim
return trigger_data

raise RuntimeError('Number of triggered ifos must be >0 !')
tdent marked this conversation as resolved.
Show resolved Hide resolved

def do_pastro_calc(self, trigger_data, horizons):
""" No-op, or call the despatch dictionary to evaluate p_astro """
if not self.do:
Expand Down