Skip to content
Snippets Groups Projects
Commit 30491470 authored by Jameson Rollins's avatar Jameson Rollins
Browse files

cli: better range handling

All ranges are calculated automatically if the inspiral_range package
is provided, and the resultant metrics are printed to stdout.  Just
the "range" is added as plot subtitle.
parent c1d60e95
No related branches found
No related tags found
1 merge request!117simplified range handling
...@@ -47,20 +47,21 @@ file (without display) (various file formats are supported, indicated ...@@ -47,20 +47,21 @@ file (without display) (various file formats are supported, indicated
by file extension). If the requested extension is 'hdf5' or 'h5' then by file extension). If the requested extension is 'hdf5' or 'h5' then
the noise traces and IFO parameters will be saved to an HDF5 file. the noise traces and IFO parameters will be saved to an HDF5 file.
If the inspiral_range package is available, various figures of merit If the inspiral_range package is available, various BNS (m1=m2=1.4
can be calculated for the resultant spectrum with the --fom option, M_solar) range figures of merit will be calculated for the resultant
e.g.: spectrum. The range parameters can be overriden with the --range
option, e.g.:
gwinc --fom horizon ... gwinc --range m1=20,m2=20 ...
gwinc --fom range:m1=20,m2=20 ...
See the inspiral_range package documentation for details. Specify "none" to bypass calculating the inspiral ranges. See the
NOTE: The range will be calculated with the supplied frequency array, inspiral_range package documentation for details.
and may therefore be inaccurate if a restricted array is specified.
""" """
IFO = 'aLIGO' IFO = 'aLIGO'
FOM = 'range:m1=1.4,m2=1.4' FREQ = '5:3000:6000'
RANGE_PARAMS = 'm1=1.4,m2=1.4'
DATA_SAVE_FORMATS = ['.hdf5', '.h5']
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='gwinc', prog='gwinc',
...@@ -80,8 +81,8 @@ parser.add_argument( ...@@ -80,8 +81,8 @@ parser.add_argument(
'--title', '-t', '--title', '-t',
help="plot title") help="plot title")
parser.add_argument( parser.add_argument(
'--fom', metavar='FUNC[:PARAM=VAL,...]', default=FOM, '--range', metavar='PARAM=VAL[,...]', default=RANGE_PARAMS,
help="use inspiral_range.FUNC to calculate range figure-of-merit on resultant spectrum") help="specify inspiral_range parameters, or 'none' to not calculate range")
group = parser.add_mutually_exclusive_group() group = parser.add_mutually_exclusive_group()
group.add_argument( group.add_argument(
'--interactive', '-i', action='store_true', '--interactive', '-i', action='store_true',
...@@ -194,25 +195,22 @@ def main(): ...@@ -194,25 +195,22 @@ def main():
logger.warning("no display, plotting disabled.") logger.warning("no display, plotting disabled.")
args.plot = False args.plot = False
try: if args.range.lower() in ['none', 'no', 'false']:
import inspiral_range args.range = None
logger_ir = logging.getLogger('inspiral_range') else:
logger_ir.setLevel(logger.getEffectiveLevel())
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(name)s: %(message)s'))
logger_ir.addHandler(handler)
except ModuleNotFoundError:
logger.warning("WARNING: inspiral_range package not available, figure of merit will not be calculated.")
args.fom = None
if args.fom:
try: try:
range_func, range_func_args = args.fom.split(':') import inspiral_range
except ValueError: logger_ir = logging.getLogger('inspiral_range')
range_func = args.fom logger_ir.setLevel(logger.getEffectiveLevel())
range_func_args = '' handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(name)s: %(message)s'))
logger_ir.addHandler(handler)
except ModuleNotFoundError:
logger.warning("WARNING: inspiral_range package not available, figure of merit will not be calculated.")
args.range = None
if args.range:
range_params = {} range_params = {}
for param in range_func_args.split(','): for param in args.range.split(','):
if not param: if not param:
continue continue
p, v = param.split('=') p, v = param.split('=')
...@@ -234,21 +232,23 @@ def main(): ...@@ -234,21 +232,23 @@ def main():
if args.title: if args.title:
plot_style['title'] = args.title plot_style['title'] = args.title
else: else:
plot_style['title'] = plot_style.get( plot_style['title'] = "GWINC Noise Budget: {}".format(args.IFO)
'title',
"GWINC Noise Budget: {}".format(args.IFO), if args.range:
) logger.info("calculating inspiral ranges...")
if args.fom: metrics, H = inspiral_range.all_ranges(freq, trace.psd, **range_params)
logger.info("calculating inspiral {}...".format(range_func)) print(f"{H.params['approximant']} {H.params['m1']}/{H.params['m2']} M_solar:")
H = inspiral_range.CBCWaveform(freq, **range_params) for metric, (value, unit) in metrics.items():
logger.debug("waveform params: {}".format(H.params)) if unit is None:
fom = eval('inspiral_range.{}'.format(range_func))(freq, trace.psd, H=H) unit = ''
logger.info("{}({}) = {:.2f} Mpc".format(range_func, range_func_args, fom)) print(f" {metric}: {value:0.1f} {unit}")
subtitle = 'inspiral {func} {m1}/{m2} $\mathrm{{M}}_\odot$: {fom:.0f} Mpc'.format( range_func = 'range'
subtitle = 'inspiral {func} {m1}/{m2} $\mathrm{{M}}_\odot$: {fom:.0f} {unit}'.format(
func=range_func, func=range_func,
m1=H.params['m1'], m1=H.params['m1'],
m2=H.params['m2'], m2=H.params['m2'],
fom=fom, fom=metrics[range_func][0],
unit=metrics[range_func][1] or '',
) )
else: else:
subtitle = None subtitle = None
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment