Skip to content

Commit

Permalink
Add wrapper script for bayestar
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Aug 15, 2023
1 parent e9e274f commit 2912a20
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 9 deletions.
61 changes: 61 additions & 0 deletions bin/all_sky_search/pycbc_make_bayestar_skymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env python

"""
Simple wraper around bayestar-localize-coincs to get sky localization for a
specific compact binary merger event.
Uses an XML containing SNR timeseries and PSD and calls BAYESTAR to produce a
sky localization.
"""

import argparse
import subprocess
import shutil
import logging
import pycbc.version
from pycbc import init_logging

parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--version', action="version",
version=pycbc.version.git_verbose_msg)
parser.add_argument('--verbose', action='count',
help="Make the logging increasingly more verbose")
parser.add_argument('--bayestar-executable',
help="The bayestar-localize-coinc executable to be run. "
"If not given, will use whatever is available in "
"the current environment.")
parser.add_argument('--event-xml', required=True,
help="XML file containing event information, SNR "
"timeseries and PSD to pass to bayestar")
parser.add_argument('--waveform', default='TaylorF2',
help="Waveform used in the matched-filtering "
"to generate the SNR timeseries.")
parser.add_argument('--low-frequency-cutoff', type=float, default=20,
help="Low-frequency cutoff used in the matched-filtering "
"to generate the SNR timeseries")
parser.add_argument('--seed',
help="Seed to pass to bayestar-localize-coincs")
parser.add_argument('--output-file', required=True,
help="Filename to output the fits file to."
args = parser.parse_args()

init_logging(args.verbose)
logging.info("Starting")


bayestar_exe = args.bayestar_executable if args.bayestar_executable \
else 'bayestar-localize-coincs'

cmd = [bayestar_exe,
args.event_xml,
'--waveform', args.waveform,
'--f_low', str(args.low_frequency_cutoff),
'-o', tmpdir]

logging.info("Running %s", ' '.join(cmd))
subprocess.call(cmd)

logging.info("Moving output to %s", args.output_file)
shutil.move(os.path.join(tmpdir, '0.fits'), args.output_file)

logging.info("Done")
2 changes: 1 addition & 1 deletion examples/search/executables.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[executables]
average_psd = ${which:pycbc_average_psd}
bank2hdf = ${which:pycbc_coinc_bank2hdf}
bayestar = ${which:bayestar-localize-coincs}
bayestar = ${which:pycbc_make_bayestar_skymap}
calculate_psd = ${which:pycbc_calculate_psd}
coinc = ${which:pycbc_coinc_findtrigs}
combine_statmap = ${which:pycbc_add_statmap}
Expand Down
6 changes: 2 additions & 4 deletions examples/search/gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ set -e

pycbc_make_offline_search_workflow \
--workflow-name gw \
--output-dir output_3 \
--output-dir output \
--config-files analysis.ini plotting.ini executables.ini injections_minimal.ini \
--config-overrides results_page:output-path:$(pwd)/html \
--submit-now \
--cache-file reuse.cache
--config-overrides results_page:output-path:$(pwd)/html
2 changes: 1 addition & 1 deletion examples/search/plotting.ini
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ num-to-write = 2
[page_versioning]

[bayestar]
f-low = ${inspiral|low-frequency-cutoff}
low-frequency-cutoff = ${inspiral|low-frequency-cutoff}

[skymap_plot]
contour = 50 90
Expand Down
5 changes: 2 additions & 3 deletions pycbc/workflow/minifollowups.py
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ def make_upload_files(workflow, psd_files, snr_timeseries, xml_all,
tags=tags
)

bayestar_node.add_input_opt('--event-xml', xml_out)
bayestar_node = bayestar_exe.create_node()
fits_out = bayestar_node.new_output_file_opt(
workflow.analysis_time,
Expand All @@ -1007,16 +1008,14 @@ def make_upload_files(workflow, psd_files, snr_timeseries, xml_all,
approximant = b'TaylorF2'
bayestar_node.add_opt('--waveform', str(approximant))

bayestar_node.add_input_opt('', xml_out)

workflow += bayestar_node

skymap_plot_exe = Executable(
workflow.cp,
'skymap_plot',
ifos=workflow.ifos,
out_dir=out_dir,
tags=['skymap']
tags=tags
)

skymap_plot_node = skymap_plot_exe.create_node()
Expand Down

0 comments on commit 2912a20

Please sign in to comment.