Skip to content

Commit

Permalink
calculate_psd: support for time-dependent options and stop infinite l…
Browse files Browse the repository at this point in the history
…oop (gwastro#4508)

* calculate_psd: support for TD options and stop infinite loop

* Don't resolve if option not given

* Rework try/except bit

* Update bin/all_sky_search/pycbc_calculate_psd

Co-authored-by: Tito Dal Canton <tito.dalcanton@ijclab.in2p3.fr>

* Remove rerun_count

---------

Co-authored-by: Tito Dal Canton <tito.dalcanton@ijclab.in2p3.fr>
  • Loading branch information
spxiwh and titodalcanton authored Sep 28, 2023
1 parent 3170f44 commit 7fd8c02
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions bin/all_sky_search/pycbc_calculate_psd
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ parser.add_argument("--analysis-segment-file", required=True,
parser.add_argument("--segment-name", help="Name of segment list to use")
parser.add_argument("--cores", default=1, type=int)
parser.add_argument("--output-file", required=True)
parser.add_argument("--num-data-retries", default=10, type=int)

pycbc.psd.insert_psd_option_group(parser, output=False)
pycbc.strain.insert_strain_option_group(parser, gps_times=False)
Expand Down Expand Up @@ -48,15 +49,26 @@ def get_psd(input_tuple):
argstmp.gps_start_time = int(seg[0]) + args.pad_data
argstmp.gps_end_time = int(seg[1]) - args.pad_data
tmp_segment = segment([argstmp.gps_start_time, argstmp.gps_end_time])
argstmp.channel_name = resolve_td_option(args.channel_name, tmp_segment)

# This helps when the filesystem is unreliable, and gives extra retries.
# python has an internal limit of ~100 (it is not infinite)
try:
gwstrain = pycbc.strain.from_cli(argstmp, pycbc.DYN_RANGE_FAC)
except RuntimeError:
time.sleep(10)
return get_psd((seg, i))
# There may be cases where channel name or frame type change within an
# analysis (noting that this could be an issue with significance
# computation). If so, resolve them for each PSD block. This still
# assumes that the channel and frame type are constant during a lock stretch.
if args.channel_name:
# Option may not have been given at all
argstmp.channel_name = resolve_td_option(args.channel_name, tmp_segment)
if args.frame_type:
# Option is often not given.
argstmp.frame_type = resolve_td_option(args.frame_type, tmp_segment)

# This helps when the filesystem is unreliable
for i in range(args.num_data_retries):
try:
gwstrain = pycbc.strain.from_cli(argstmp, pycbc.DYN_RANGE_FAC)
break
except RuntimeError:
time.sleep(10)
if i == (args.num_data_retries-1):
raise

logging.info('%d: determining strain segmentation', i)
strain_segments = pycbc.strain.StrainSegments.from_cli(args, gwstrain)
Expand Down

0 comments on commit 7fd8c02

Please sign in to comment.