Skip to content

Commit

Permalink
fix usage of parse_statistic_feature_options in test
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Jan 26, 2024
1 parent e4efc98 commit 89b10bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pycbc/events/coinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,12 +948,16 @@ def from_cli(cls, args, num_templates, analysis_chunk, ifos):

# Allow None inputs
stat_files = args.statistic_files or []
stat_features = args.statistic_features or []
stat_keywords = args.statistic_keywords or []

# flatten the list of lists of filenames to a single list (may be empty)
stat_files = sum(stat_files, [])

kwargs = stat.parse_statistic_feature_options(stat_keywords)
kwargs = stat.parse_statistic_feature_options(
stat_features,
stat_keywords,
)

return cls(num_templates, analysis_chunk,
args.ranking_statistic,
Expand Down
29 changes: 16 additions & 13 deletions pycbc/events/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ def insert_statistic_option_group(parser, default_ranking_statistic=None):
return statistic_opt_group


def parse_statistic_feature_options(opts):
def parse_statistic_feature_options(stat_features, stat_kwarg_list):
"""
Parse the list of statistic keywords into an appropriate dictionary.
Expand All @@ -1586,7 +1586,17 @@ def parse_statistic_feature_options(opts):
Statistic keywords in dict format
"""
stat_kwarg_dict = {}
stat_kwarg_list = opts.statistic_keywords

# Check that the statistic keywords are allowed
for feature in stat_features:
if feature not in _allowed_statistic_features:
err_msg = f"--statistic-feature {feature} not recognised"
raise NotImplementedError(err_msg)

# Set values for each feature key to a boolean of whether we want them
for feature in _allowed_statistic_features:
stat_kwarg_dict[feature] = feature in stat_features

for inputstr in stat_kwarg_list:
try:
key, value = inputstr.split(':')
Expand All @@ -1597,16 +1607,6 @@ def parse_statistic_feature_options(opts):
"Received {}".format(' '.join(stat_kwarg_list))
raise ValueError(err_txt)

# Check that the statistic keywords are allowed
for feature in opts.statistic_features:
if feature not in _allowed_statistic_features:
err_msg = f"--statistic-feature {feature} not recognised"
raise NotImplementedError(err_msg)

# Set values for each feature key to a boolean of whether we want them
for feature in _allowed_statistic_features:
stat_kwarg_dict[feature] = feature in opts.statistic_features

return stat_kwarg_dict


Expand Down Expand Up @@ -1639,7 +1639,10 @@ def get_statistic_from_opts(opts, ifos):
# flatten the list of lists of filenames to a single list (may be empty)
opts.statistic_files = sum(opts.statistic_files, [])

extra_kwargs = parse_statistic_feature_options(opts)
extra_kwargs = parse_statistic_feature_options(
opts.statistic_features,
opts.statistic_keywords,
)

stat_class = get_statistic(opts.ranking_statistic)(
opts.sngl_ranking,
Expand Down
1 change: 1 addition & 0 deletions test/test_live_coinc_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def setUp(self, *args):
ranking_statistic="phasetd",
statistic_files=[stat_file_paths],
statistic_keywords=None,
statistic_features=None,
timeslide_interval=0.1,
background_ifar_limit=100,
store_background=True
Expand Down

0 comments on commit 89b10bc

Please sign in to comment.