Skip to content

Commit

Permalink
Reverting non-functional changes in stat.py
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtrevor committed Jan 11, 2024
1 parent 2a26fa5 commit a19b497
Showing 1 changed file with 53 additions and 53 deletions.
106 changes: 53 additions & 53 deletions pycbc/events/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def get_sngl_ranking(self, trigs):
**self.sngl_ranking_kwargs
)

def single(self, trigs): # pylint:disable=unused-argument
def single(self, trigs): # pylint:disable=unused-argument
"""
Calculate the necessary single detector information
Expand All @@ -122,7 +122,7 @@ def single(self, trigs): # pylint:disable=unused-argument
raise NotImplementedError(err_msg)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for a single detector candidate
Expand All @@ -142,7 +142,7 @@ def rank_stat_single(self, single_info,
raise NotImplementedError(err_msg)

def rank_stat_coinc(self, s, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic.
"""
Expand Down Expand Up @@ -172,7 +172,7 @@ def _check_coinc_lim_subclass(self, allowed_names):
raise NotImplementedError(err_msg)

def coinc_lim_for_thresh(self, s, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest
Expand Down Expand Up @@ -207,7 +207,7 @@ def single(self, trigs):
return self.get_sngl_ranking(trigs)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for a single detector candidate
Expand All @@ -228,7 +228,7 @@ def rank_stat_single(self, single_info,
return single_info[1]

def rank_stat_coinc(self, sngls_list, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic.
Expand All @@ -254,7 +254,7 @@ def rank_stat_coinc(self, sngls_list, slide, step, to_shift,
return cstat

def coinc_lim_for_thresh(self, s, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest
Expand Down Expand Up @@ -423,7 +423,8 @@ def get_hist(self, ifos=None):
if param[ifo].dtype == numpy.int8:
# Older style, incorrectly sorted histogram file
ncol = param[ifo].shape[1]
self.pdtype = [('c%s' % i, param[ifo].dtype) for i in range(ncol)]
self.pdtype = [('c%s' % i, param[ifo].dtype)
for i in range(ncol)]
self.param_bin[ifo] = numpy.zeros(len(self.weights[ifo]),
dtype=self.pdtype)
for i in range(ncol):
Expand Down Expand Up @@ -662,7 +663,7 @@ def single(self, trigs):
return numpy.array(singles, ndmin=1)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for a single detector candidate
Expand All @@ -683,7 +684,7 @@ def rank_stat_single(self, single_info,
return single_info[1]

def rank_stat_coinc(self, sngls_list, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic, defined in Eq 2 of
[Nitz et al, 2017](https://doi.org/10.3847/1538-4357/aa8f50).
Expand All @@ -696,7 +697,7 @@ def rank_stat_coinc(self, sngls_list, slide, step, to_shift,
return cstat ** 0.5

def coinc_lim_for_thresh(self, sngls_list, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest.
Calculate the required single detector statistic to exceed the
Expand Down Expand Up @@ -749,7 +750,7 @@ def __init__(self, sngl_ranking, files=None, ifos=None, **kwargs):
# the stat file attributes are hard-coded as '%{ifo}-fit_coeffs'
parsed_attrs = [f.split('-') for f in self.files.keys()]
self.bg_ifos = [at[0] for at in parsed_attrs if
(len(at) == 2 and at[1] == 'fit_coeffs')]
(len(at) == 2 and at[1] == 'fit_coeffs')]
if not len(self.bg_ifos):
raise RuntimeError("None of the statistic files has the required "
"attribute called {ifo}-fit_coeffs !")
Expand Down Expand Up @@ -843,15 +844,13 @@ def find_fits(self, trigs):
The thresh fit value(s)
"""
try:
tnum = trigs.template_num
except AttributeError:
tnum = trigs['template_id']

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

# fits_by_tid is a dictionary of dictionaries of arrays
# indexed by ifo / coefficient name / template_id
Expand Down Expand Up @@ -885,7 +884,7 @@ def lognoiserate(self, trigs):
# ratei is rate of trigs in given template compared to average
# thresh is stat threshold used in given ifo
lognoisel = - alphai * (sngl_stat - thresh) + numpy.log(alphai) + \
numpy.log(ratei)
numpy.log(ratei)
return numpy.array(lognoisel, ndmin=1, dtype=numpy.float32)

def single(self, trigs):
Expand All @@ -908,7 +907,7 @@ def single(self, trigs):
return self.lognoiserate(trigs)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for a single detector candidate
Expand All @@ -927,23 +926,23 @@ def rank_stat_single(self, single_info,
raise NotImplementedError(err_msg)

def rank_stat_coinc(self, s, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic.
"""
err_msg = "Sorry! No-one has implemented this method yet! "
raise NotImplementedError(err_msg)

def coinc_lim_for_thresh(self, s, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest
"""
err_msg = "Sorry! No-one has implemented this method yet! "
raise NotImplementedError(err_msg)

# Keeping this here to help write the new coinc method.
def coinc_OLD(self, s0, s1, slide, step): # pylint:disable=unused-argument
def coinc_OLD(self, s0, s1, slide, step): # pylint:disable=unused-argument
"""Calculate the final coinc ranking statistic"""

# Approximate log likelihood ratio by summing single-ifo negative
Expand Down Expand Up @@ -1043,7 +1042,7 @@ def single(self, trigs):
return numpy.array(stat, ndmin=1, dtype=numpy.float32)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for single detector candidates
Expand All @@ -1065,7 +1064,7 @@ def rank_stat_single(self, single_info,
return sngl_multiifo

def rank_stat_coinc(self, s, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic.
Expand All @@ -1088,7 +1087,7 @@ def rank_stat_coinc(self, s, slide, step, to_shift,
return sum(sngl[1] for sngl in s) / (len(s) ** 0.5)

def coinc_lim_for_thresh(self, s, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest
Expand Down Expand Up @@ -1172,7 +1171,7 @@ def single(self, trigs):
return numpy.array(singles, ndmin=1)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for a single detector candidate
Expand All @@ -1191,15 +1190,15 @@ def rank_stat_single(self, single_info,
raise NotImplementedError(err_msg)

def rank_stat_coinc(self, s, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic.
"""
err_msg = "Sorry! No-one has implemented this method yet! "
raise NotImplementedError(err_msg)

def coinc_lim_for_thresh(self, s, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest
Calculate the required single detector statistic to exceed
Expand Down Expand Up @@ -1293,7 +1292,7 @@ def reassign_rate(self, ifo):
self.fits_by_tid[ifo]['fit_by_rate_in_template'] /= analysis_time

def rank_stat_coinc(self, s, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic.
Expand Down Expand Up @@ -1444,9 +1443,9 @@ def lognoiserate(self, trigs, alphabelow=6):
# below threshold use specified alphabelow
bt = newsnr < thresh
lognoisel = - alphai * (newsnr - thresh) + numpy.log(alphai) + \
numpy.log(ratei)
numpy.log(ratei)
lognoiselbt = - alphabelow * (newsnr - thresh) + \
numpy.log(alphabelow) + numpy.log(ratei)
numpy.log(alphabelow) + numpy.log(ratei)
lognoisel[bt] = lognoiselbt[bt]
return numpy.array(lognoisel, ndmin=1, dtype=numpy.float32)

Expand Down Expand Up @@ -1482,16 +1481,18 @@ def single(self, trigs):
# exists if accessed via coinc_findtrigs
self.curr_tnum = trigs.template_num
except AttributeError:
# exists for SingleDetTriggers & pycbc_live get_coinc
# exists for SingleDetTriggers
self.curr_tnum = trigs['template_id']
# Should only be one ifo fit file provided
assert len(self.ifos) == 1

# 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]
return numpy.array(singles, ndmin=1)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for single detector candidates
Expand Down Expand Up @@ -1521,7 +1522,7 @@ def rank_stat_single(self, single_info,
return loglr

def rank_stat_coinc(self, s, slide, step, to_shift,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the coincident detection statistic.
Expand Down Expand Up @@ -1591,7 +1592,7 @@ def rank_stat_coinc(self, s, slide, step, to_shift,
return loglr

def coinc_lim_for_thresh(self, s, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest
Expand Down Expand Up @@ -1630,7 +1631,8 @@ def coinc_lim_for_thresh(self, s, thresh, limifo,
if thresh <= -30.:
return numpy.ones(len(s[0][1]['snglstat'])) * numpy.inf
sngl_rates = {sngl[0]: sngl[1]['snglstat'] for sngl in s}
# Add limifo to singles dict so that overlap time is calculated correctly
# Add limifo to singles dict so that overlap
# time is calculated correctly
sngl_rates[limifo] = numpy.zeros(len(s[0][1]))
ln_noise_rate = coinc_rate.combination_noise_lograte(
sngl_rates, kwargs['time_addition'])
Expand Down Expand Up @@ -1742,7 +1744,7 @@ def logsignalrate(self, stats, shift, to_shift):
return logr_s

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for a single detector candidate
Expand Down Expand Up @@ -1787,21 +1789,16 @@ def single(self, trigs):
The array of single detector values
"""
from pycbc.conversions import mchirp_from_mass1_mass2
try:
mass1 = trigs.param['mass1']
mass2 = trigs.param['mass2']
except AttributeError:
mass1 = trigs['mass1']
mass2 = trigs['mass2']
self.curr_mchirp = mchirp_from_mass1_mass2(mass1, mass2)
self.curr_mchirp = mchirp_from_mass1_mass2(trigs.param['mass1'],
trigs.param['mass2'])

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))
return ExpFitFgBgNormStatistic.single(self, trigs)

def coinc_lim_for_thresh(self, s, thresh, limifo,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Optimization function to identify coincs too quiet to be of interest
Expand Down Expand Up @@ -1870,7 +1867,7 @@ def find_kdes(self):
# and 'template-kde_file'
parsed_attrs = [f.split('-') for f in self.files.keys()]
self.kde_names = [at[0] for at in parsed_attrs if
(len(at) == 2 and at[1] == 'kde_file')]
(len(at) == 2 and at[1] == 'kde_file')]
assert sorted(self.kde_names) == ['signal', 'template'], \
"Two stat files are required, they should have stat attr " \
"'signal-kde_file' and 'template-kde_file' respectively"
Expand Down Expand Up @@ -1925,7 +1922,7 @@ def logsignalrate(self, stats, shift, to_shift):
return logr_s

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Calculate the statistic for a single detector candidate
Expand Down Expand Up @@ -2090,8 +2087,10 @@ def setup_segments(self, key):
dq_state_segs_dict = {}
for k in ifo_grp['dq_segments'].keys():
seg_dict = {}
seg_dict['start'] = ifo_grp[f'dq_segments/{k}/segment_starts'][:]
seg_dict['end'] = ifo_grp[f'dq_segments/{k}/segment_ends'][:]
seg_dict['start'] = \
ifo_grp[f'dq_segments/{k}/segment_starts'][:]
seg_dict['end'] = \
ifo_grp[f'dq_segments/{k}/segment_ends'][:]
dq_state_segs_dict[k] = seg_dict

if self.dq_state_segments is None:
Expand All @@ -2102,7 +2101,8 @@ def setup_segments(self, key):
self.dq_state_segments[ifo] = dq_state_segs_dict
else:
# we must be in LL, shouldn't have segments
assert not self.dq_state_segments, 'Should not have segments in LL'
assert not self.dq_state_segments, \
'Should not have segments in LL'
self.low_latency = True

def find_dq_noise_rate(self, trigs, dq_state):
Expand Down Expand Up @@ -2232,7 +2232,7 @@ def logsignalrate(self, stats, shift, to_shift):
to_shift)

def rank_stat_single(self, single_info,
**kwargs): # pylint:disable=unused-argument
**kwargs): # pylint:disable=unused-argument
"""
Inherited, see docstring for ExpFitFgBgKDEStatistic.rank_stat_single
"""
Expand Down

0 comments on commit a19b497

Please sign in to comment.