Skip to content

Commit

Permalink
Make plotting work, and other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtrevor committed Sep 5, 2024
1 parent a0b845b commit 29c12f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
15 changes: 12 additions & 3 deletions bin/live/pycbc_live_daily_dq_trigger_rates
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ from gwpy.segments import Segment, DataQualityFlag
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--trigger-file", required=True)
parser.add_argument("--ifo", required=True)
parser.add_argument("--day-str", required=True)
parser.add_argument("--gps-start-time", required=True, type=int)
parser.add_argument("--gps-end-time", required=True, type=int)
parser.add_argument("--template-bin-file", required=True)
Expand All @@ -53,7 +52,7 @@ day_seg = Segment(args.gps_start_time, args.gps_end_time)
observing_flag = DataQualityFlag.query(ar_flag_name, day_seg)
observing_segs = observing_flag.active
daily_livetime = observing_flag.livetime
logging.info(f'{args.day_str} has {daily_livetime} seconds of observing time.')
logging.info(f'Found {daily_livetime} seconds of observing time at {args.ifo}.')

# for each segment, check how much time was dq flagged
flagged_time = 0
Expand All @@ -76,7 +75,10 @@ for seg in observing_segs:
dq_ok_flag = (tsdict[dq_ok_channel] == 1).to_dqflag()
dq_flag = (tsdict[dq_channel] <= args.dq_thresh).to_dqflag()
flagged_time += (dq_flag & dq_ok_flag).livetime
logging.info(f'{args.day_str} has {flagged_time} seconds of dq flagged time.')
logging.info(f'Found {flagged_time} seconds of dq flagged time at {args.ifo}.')

bg_livetime = daily_livetime - flagged_time
state_time = np.array([bg_livetime, flagged_time])

# read in template bins
template_bins = {}
Expand Down Expand Up @@ -125,6 +127,13 @@ with h5.File(args.output, 'w') as f:
bgrp.create_dataset('total_triggers', data=bin_total_triggers[bin_num])
bgrp.create_dataset('dq_triggers', data=bin_dq_triggers[bin_num])

bg_triggers = bin_total_triggers[bin_num] - bin_dq_triggers[bin_num]
num_trigs = np.array([bg_triggers, bin_dq_triggers[bin_num]])
trig_rates = num_trigs / state_time
mean_rate = bin_total_triggers[bin_num] / daily_livetime
normalized_rates = trig_rates / mean_rate
bgrp.create_dataset('dq_rates', data=normalized_rates)

f.attrs['dq_thresh'] = args.dq_thresh
f.attrs['dq_channel'] = dq_channel
f.attrs['dq_ok_channel'] = dq_ok_channel
Expand Down
33 changes: 14 additions & 19 deletions bin/live/pycbc_live_supervise_collated_trigger_fits
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ def fit_over_multiparam(
fit_over_controls,
fit_over_options,
ifo,
day_str,
output_dir,
controls
):
Expand All @@ -229,11 +228,6 @@ def fit_over_multiparam(
"specified parameters",
len(daily_files)
)
logging.info(
"Smoothing fits using fit_over_multiparam with %d files and "
"specified parameters",
len(daily_files)
)
file_id_str = f'{first_date}-{end_date}'
out_fname = fit_over_controls['fit-over-format'].format(
dates=file_id_str,
Expand Down Expand Up @@ -482,8 +476,8 @@ def daily_dq_trigger_rates(
in each dq bin, total triggers in each dq bin, the amount
of time flagged by idq and the total observing time.
"""
logging.info("Calculating daily dq trigger rates")
fname_format = daily_dq_controls['daily-dq-trigger-rates-format']
logging.info(f"Calculating daily dq trigger rates for {ifo}")
fname_format = daily_dq_controls['daily-dq-format']
ddtr_out_fname = fname_format.format(date=day_str, ifo=ifo)

if 'replay-start-time' in daily_dq_controls:
Expand All @@ -496,7 +490,8 @@ def daily_dq_trigger_rates(
ddtr_out_full = os.path.join(output_dir, ddtr_out_fname)
daily_dq_args = ['pycbc_live_daily_dq_trigger_rates']
daily_dq_args += ['--trigger-file', trigger_merge_file]
daily_dq_args += ['--output', ddtr_out_full, '--ifo', ifo]
daily_dq_args += ['--output', ddtr_out_full]
daily_dq_args += ['--ifo', ifo]

daily_dq_options['gps-start-time'] = f'{gps_start_time:d}'
daily_dq_options['gps-end-time'] = f'{gps_end_time:d}'
Expand All @@ -511,7 +506,6 @@ def combine_dq_trigger_rates(
combined_dq_controls,
combined_dq_options,
ifo,
day_str,
output_dir,
controls
):
Expand All @@ -524,16 +518,18 @@ def combine_dq_trigger_rates(
controls['output-directory'],
ifo
)
logging.info(
"Combining dq trigger rates over %d files",
len(daily_files)
)

date_range = f'{first_date}-{end_date}'
outfile_name = combined_dq_controls['outfile-format'].format(
date=day_str,
date_range=date_range,
outfile_name = combined_dq_controls['combined-dq-format'].format(
ifo=ifo,
dates=date_range,
)

logging.info(
f"Combining {ifo} dq trigger rates over {len(daily_files)} files "
f"from {date_range}"
)

combined_dq_options['output'] = os.path.join(output_dir, outfile_name)
combined_dq_options['daily-dq-files'] = ' '.join(daily_files)
combined_dq_options['ifo'] = ifo
Expand Down Expand Up @@ -673,6 +669,7 @@ def supervise_collation_fits_dq(args, day_dt, day_str):
ddtr_file = daily_dq_trigger_rates(
merged_triggers,
day_str,
day_dt,
daily_dq_control_options,
daily_dq_options,
output_dir,
Expand All @@ -694,7 +691,6 @@ def supervise_collation_fits_dq(args, day_dt, day_str):
fit_over_control_options,
fit_over_options,
ifo,
day_str,
output_dir,
controls
)
Expand All @@ -714,7 +710,6 @@ def supervise_collation_fits_dq(args, day_dt, day_str):
combined_dq_control_options,
combined_dq_options,
ifo,
day_str,
output_dir,
controls
)
Expand Down
4 changes: 1 addition & 3 deletions bin/plotting/pycbc_plot_dq_flag_likelihood
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ ifo = args.ifo
f = HFile(args.dq_file, 'r')
ifo_grp = f[ifo]

dq_states = ifo_grp['dq_segments'].keys()
bin_names = ifo_grp['bins'].keys()

num_bins = len(bin_names)
x = numpy.arange(num_bins)
x = numpy.arange(len(bin_names))

if args.low_latency:
dq_states = {
Expand Down

0 comments on commit 29c12f3

Please sign in to comment.