From cf5943a3a5882557c780ab4d1a5f56f79fc63f88 Mon Sep 17 00:00:00 2001 From: Sebastian Steinlechner <sebastian.steinlechner@ligo.org> Date: Tue, 30 Mar 2021 00:10:57 +0200 Subject: [PATCH] fixed cmdline ignoring default freq spec --- gwinc/__init__.py | 19 ++++++++++++------- gwinc/__main__.py | 13 +++++-------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gwinc/__init__.py b/gwinc/__init__.py index 7613c93..3cf4e7e 100644 --- a/gwinc/__init__.py +++ b/gwinc/__init__.py @@ -27,6 +27,8 @@ logger = logging.getLogger('gwinc') DEFAULT_FREQ = '5:3000:6000' +class InvalidFrequencySpec(Exception): + pass def freq_from_spec(spec=None): """logarithmicly spaced frequency array, based on specification string @@ -41,13 +43,16 @@ def freq_from_spec(spec=None): elif spec is None: spec = DEFAULT_FREQ fspec = spec.split(':') - if len(fspec) == 2: - fspec = fspec[0], DEFAULT_FREQ.split(':')[1], fspec[1] - return np.logspace( - np.log10(float(fspec[0])), - np.log10(float(fspec[2])), - int(fspec[1]), - ) + try: + if len(fspec) == 2: + fspec = fspec[0], DEFAULT_FREQ.split(':')[1], fspec[1] + return np.logspace( + np.log10(float(fspec[0])), + np.log10(float(fspec[2])), + int(fspec[1]), + ) + except (ValueError, IndexError): + raise InvalidFrequencySpec(f'Improper frequency specification: {spec}') def load_module(name_or_path): diff --git a/gwinc/__main__.py b/gwinc/__main__.py index d70279f..703f616 100644 --- a/gwinc/__main__.py +++ b/gwinc/__main__.py @@ -8,7 +8,7 @@ from . import ( __version__, IFOS, DEFAULT_FREQ, - freq_from_spec, + InvalidFrequencySpec, load_budget, logger, ) @@ -58,7 +58,6 @@ See the inspiral_range package documentation for details. """ IFO = 'aLIGO' -FREQ = '5:3000:6000' RANGE_PARAMS = dict(m1=1.4, m2=1.4) DATA_SAVE_FORMATS = ['.hdf5', '.h5'] @@ -142,11 +141,9 @@ def main(): else: try: - freq = freq_from_spec(args.freq) - except IndexError: - parser.error(f"Improper frequency specification: {args.freq}") - try: - budget = load_budget(args.IFO, freq=freq, bname=args.bname) + budget = load_budget(args.IFO, freq=args.freq, bname=args.bname) + except InvalidFrequencySpec as e: + parser.error(e) except RuntimeError as e: parser.exit(2, f"Error: {e}\n") name = budget.name @@ -258,7 +255,7 @@ def main(): if not trace: logger.info("calculating budget...") - trace = budget.run(freq=freq) + trace = budget.run() if args.range: logger.info("calculating inspiral ranges...") -- GitLab