Skip to content

Commit

Permalink
fixes to pycbc_page_snglinfo
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Nov 28, 2023
1 parent a2ab781 commit 9f7b522
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions bin/minifollowups/pycbc_page_snglinfo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ matplotlib.use('Agg')
import lal
import pycbc.version, pycbc.events, pycbc.results, pycbc.pnutils
from pycbc.results import followup
from pycbc.events import stat
from pycbc.events import stat as pystat
from pycbc.io import hdf


Expand Down Expand Up @@ -62,42 +62,53 @@ parser.add_argument('--include-gracedb-link', action='store_true',
parser.add_argument('--significance-file',
help="If given, will search for this trigger's id in the file to see if "
"stat and p_astro values exists for this trigger.")
stat.insert_statistic_option_group(parser,
pystat.insert_statistic_option_group(parser,
default_ranking_statistic='single_ranking_only')


args = parser.parse_args()

pycbc.init_logging(args.verbose)

if args.trigger_id is not None:
# Make a mask which is just the trigger of interest
mask = numpy.array([args.trigger_id])
else:
mask = None

# Get the single-ifo triggers
sngl_file = hdf.SingleDetTriggers(
args.single_trigger_file,
args.instrument,
bank_file=args.bank_file,
veto_file=args.veto_file,
segment_name=args.veto_segment_name,
premask=mask,
)

rank_method = pystat.get_statistic_from_opts(args, [args.instrument])

if args.trigger_id is not None:
# Apply a mask which is just the trigger of interest
sngl_file.apply_mask(numpy.array([args.trigger_id]))
# Mask already applied
pass
elif args.n_loudest is not None:
# Cluster by a ranking statistic and retain only the loudest n clustered
# triggers
rank_method = stat.get_statistic_from_opts(args, [args.instrument])
sngl_file.mask_to_n_loudest_clustered_events(
rank_method,
n_loudest=args.n_loudest+1
)
else:
raise ValueError("Must give --n-loudest or --trigger-id.")

sds = rank_method.single(sngl_file.trig_dict())
stat = rank_method.rank_stat_single((sngl_file.ifo, sds))
if args.n_loudest is not None:
# Restrict to only the nth loudest, instead of all triggers up to nth
# loudest
stat = sngl_file.stat
l = stat.argsort()
stat = stat[l[0]]
sngl_file.apply_mask(l[0])
else:
raise ValueError("Must give --n-loudest or --trigger-id.")

# make a table for the single detector information ############################
time = sngl_file.end_time
Expand Down Expand Up @@ -147,7 +158,8 @@ if args.ranking_statistic in ["quadsum", "single_ranking_only"]:
else:
# Name would be too long - just call it ranking statistic
stat_name = 'Ranking Statistic'
stat_name_long = ' with '.join([args.ranking_statistic, args.sngl_ranking])
stat_name_long = ' with '.join(
[args.ranking_statistic, args.sngl_ranking])

headers.append(stat_name)

Expand Down
2 changes: 1 addition & 1 deletion pycbc/io/hdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ def and_masks(self, logic_mask):
Parameters
----------
logic_mask : boolean array or numpy array of indices
logic_mask : boolean array or numpy array/list of indices
"""
if self.mask is None:
# No mask exists, just update to use the given mask
Expand Down

0 comments on commit 9f7b522

Please sign in to comment.