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

[pycbc live] Allowing the use of template fits in the pycbc live ranking statistic #4527

Merged
merged 34 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
379da30
Adding all template_fit changes to this branch
ArthurTolley Oct 4, 2023
84f28a7
Merge branch 'gwastro:master' into template_fits
ArthurTolley Oct 12, 2023
e2b157d
Updating errors to print errors
ArthurTolley Oct 16, 2023
211eb61
removing assertion and comment
ArthurTolley Oct 17, 2023
0a39883
updating comment
ArthurTolley Oct 17, 2023
ffc484c
Adding coinc_threshold to test case
ArthurTolley Oct 19, 2023
4c63d57
Reworking error handling and vectorizing mchirp calc
ArthurTolley Oct 24, 2023
bdb8060
Merge branch 'gwastro:master' into template_fits
ArthurTolley Dec 6, 2023
e6d264f
Merge branch 'gwastro:master' into template_fits
ArthurTolley Dec 13, 2023
47c91bd
adding try except for code also used by coinc_findtrigs
ArthurTolley Dec 15, 2023
d6d020c
forgot the pass in the except
ArthurTolley Dec 15, 2023
c95d19a
Merge branch 'gwastro:master' into template_fits
ArthurTolley Feb 1, 2024
357742b
Add mass1 and mass2 parameters to triggers for test
ArthurTolley Feb 1, 2024
73a73c3
Moving curr_mchirp to correct stat
ArthurTolley Feb 1, 2024
4add7a9
Revert "Moving curr_mchirp to correct stat"
ArthurTolley Feb 1, 2024
6715e2f
adding changes properly
ArthurTolley Feb 1, 2024
120f8d9
if mchirp change
ArthurTolley Feb 2, 2024
ceea096
removing len(i1) check
ArthurTolley Feb 2, 2024
7f6166f
Merge branch 'gwastro:master' into template_fits
ArthurTolley Feb 2, 2024
5136b97
Changing coinc-threshold to coinc-window-pad
ArthurTolley Feb 5, 2024
0e747d6
Checking ifo from class instance not triggers
ArthurTolley Feb 5, 2024
402a449
removing erroneous string
ArthurTolley Feb 5, 2024
631dc22
Merge branch 'gwastro:master' into template_fits
ArthurTolley Feb 8, 2024
21ce202
Merge branch 'gwastro:master' into template_fits
ArthurTolley Feb 11, 2024
84c63b0
only create Detector objects once!
ArthurTolley Mar 1, 2024
d00efc3
Merge branch 'gwastro:master' into template_fits
ArthurTolley Mar 1, 2024
c367a6c
check if dets is given in kwargs, it isn't given in offline
ArthurTolley Mar 8, 2024
befd1c4
Merge branch 'gwastro:master' into template_fits
ArthurTolley Mar 10, 2024
fa5abe5
missed a dets reference
ArthurTolley Mar 10, 2024
861ce2b
removing whitespace
ArthurTolley Mar 11, 2024
640a68b
codeclimate, line length fix
ArthurTolley Mar 11, 2024
173835d
Apply suggestions from code review
GarethCabournDavies Apr 5, 2024
7a0a0b0
Apply GCD suggestions
GarethCabournDavies Apr 5, 2024
7169170
specify an older branch of BBHx in tox.ini (#4672)
WuShichao Mar 25, 2024
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
3 changes: 3 additions & 0 deletions bin/pycbc_live
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ parser.add_argument('--gracedb-labels', metavar='LABEL', nargs='+',
parser.add_argument('--ifar-upload-threshold', type=float, required=True,
help='Inverse-FAR threshold for uploading candidate '
'triggers to GraceDB, in years.')
parser.add_argument('--coinc-threshold', type=float,
help="The time window allowed between coincident triggers",
default=0.002)
ArthurTolley marked this conversation as resolved.
Show resolved Hide resolved
parser.add_argument('--file-prefix', default='Live')

parser.add_argument('--round-start-time', type=int, metavar='X',
Expand Down
26 changes: 20 additions & 6 deletions pycbc/events/coinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import numpy, logging, pycbc.pnutils, pycbc.conversions, copy, lal
from pycbc.detector import Detector, ppdets
from pycbc.conversions import mchirp_from_mass1_mass2
from .eventmgr_cython import coincbuffer_expireelements
from .eventmgr_cython import coincbuffer_numgreater
from .eventmgr_cython import timecoincidence_constructidxs
Expand Down Expand Up @@ -877,6 +878,7 @@ def __init__(self, num_templates, analysis_block, background_statistic,

self.timeslide_interval = timeslide_interval
self.return_background = return_background
self.coinc_threshold = coinc_threshold

self.ifos = ifos
if len(self.ifos) != 2:
Expand Down Expand Up @@ -971,6 +973,7 @@ def from_cli(cls, args, num_templates, analysis_chunk, ifos):
ifar_limit=args.background_ifar_limit,
timeslide_interval=args.timeslide_interval,
ifos=ifos,
coinc_threshold=args.coinc_threshold,
**kwargs)

@staticmethod
Expand Down Expand Up @@ -1097,9 +1100,11 @@ def _add_singles_to_buffer(self, results, ifos):

if len(trigs['snr'] > 0):
trigsc = copy.copy(trigs)
trigsc['ifo'] = ifo
trigsc['chisq'] = trigs['chisq'] * trigs['chisq_dof']
trigsc['chisq_dof'] = (trigs['chisq_dof'] + 2) / 2
single_stat = self.stat_calculator.single(trigsc)
del trigsc['ifo']
else:
single_stat = numpy.array([], ndmin=1,
dtype=self.stat_calculator.single_dtype)
Expand Down Expand Up @@ -1170,6 +1175,9 @@ def _find_coincs(self, results, valid_ifos):
trig_stat = trigs['stat'][i]
trig_time = trigs['end_time'][i]
template = trigs['template_id'][i]
mass1 = trigs['mass1'][i]
mass2 = trigs['mass2'][i]
mchirp = mchirp_from_mass1_mass2(mass1, mass2)
ArthurTolley marked this conversation as resolved.
Show resolved Hide resolved

# Get current shift_ifo triggers in the same template
times = self.singles[shift_ifo].data(template)['end_time']
Expand Down Expand Up @@ -1206,12 +1214,18 @@ def _find_coincs(self, results, valid_ifos):
# ranking statistic values.
sngls_list = [[fixed_ifo, self.trig_stat_memory[:len(i1)]],
[shift_ifo, stats[i1]]]
c = self.stat_calculator.rank_stat_coinc(
sngls_list,
slide,
self.timeslide_interval,
shift_vec
)

if len(i1):
c = self.stat_calculator.rank_stat_coinc(
sngls_list,
slide,
self.timeslide_interval,
shift_vec,
time_addition=self.coinc_threshold,
mchirp=mchirp
)
else:
c = numpy.array([])
ArthurTolley marked this conversation as resolved.
Show resolved Hide resolved

# Store data about new triggers: slide index, stat value and
# times.
Expand Down
36 changes: 26 additions & 10 deletions pycbc/events/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,13 +837,16 @@ def find_fits(self, trigs):
The thresh fit value(s)
"""
try:
tnum = trigs.template_num # exists if accessed via coinc_findtrigs
tnum = trigs.template_num
except AttributeError:
tnum = trigs['template_id']
GarethCabournDavies marked this conversation as resolved.
Show resolved Hide resolved

try:
ifo = trigs.ifo
except AttributeError:
tnum = trigs['template_id'] # exists for SingleDetTriggers
assert len(self.ifos) == 1
# Should be exactly one ifo provided
ifo = self.ifos[0]
ifo = trigs['ifo']
assert ifo in self.ifos

# fits_by_tid is a dictionary of dictionaries of arrays
# indexed by ifo / coefficient name / template_id
alphai = self.fits_by_tid[ifo]['smoothed_fit_coeff'][tnum]
Expand Down Expand Up @@ -1473,10 +1476,9 @@ def single(self, trigs):
# exists if accessed via coinc_findtrigs
self.curr_tnum = trigs.template_num
except AttributeError:
# exists for SingleDetTriggers
# exists for SingleDetTriggers & pycbc_live get_coinc
self.curr_tnum = trigs['template_id']
# Should only be one ifo fit file provided
assert len(self.ifos) == 1
GarethCabournDavies marked this conversation as resolved.
Show resolved Hide resolved

# Store benchmark log volume as single-ifo information since the coinc
# method does not have access to template id
singles['benchmark_logvol'] = self.benchmark_logvol[self.curr_tnum]
Expand Down Expand Up @@ -1555,6 +1557,12 @@ def rank_stat_coinc(self, s, slide, step, to_shift,

# First get signal PDF logr_s
stat = {ifo: st for ifo, st in s}

try:
self.curr_mchirp = kwargs['mchirp']
except KeyError as e:
print(e)
ArthurTolley marked this conversation as resolved.
Show resolved Hide resolved

logr_s = self.logsignalrate(stat, slide * step, to_shift)

# Find total volume of phase-time-amplitude space occupied by noise
Expand Down Expand Up @@ -1779,8 +1787,16 @@ def single(self, trigs):
The array of single detector values
"""
from pycbc.conversions import mchirp_from_mass1_mass2
self.curr_mchirp = mchirp_from_mass1_mass2(trigs.param['mass1'],
trigs.param['mass2'])
try:
self.curr_mchirp = mchirp_from_mass1_mass2(trigs.param['mass1'],
trigs.param['mass2'])
except AttributeError:
try:
self.curr_mchirp = mchirp_from_mass1_mass2(trigs['mass1'],
trigs['mass2'])
except KeyError as e:
print(e)
titodalcanton marked this conversation as resolved.
Show resolved Hide resolved

if self.mcm is not None:
# Careful - input might be a str, so cast to float
self.curr_mchirp = min(self.curr_mchirp, float(self.mcm))
Expand Down
3 changes: 2 additions & 1 deletion test/test_live_coinc_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def setUp(self, *args):
statistic_keywords=None,
timeslide_interval=0.1,
background_ifar_limit=100,
store_background=True
store_background=True,
coinc_threshold=0.002
)

# number of templates in the bank
Expand Down
Loading