From 2bd2bd0c9b8b1eddd56e8c37b925819ed964d1b0 Mon Sep 17 00:00:00 2001 From: Jameson Graef Rollins <jrollins@finestructure.net> Date: Wed, 12 Feb 2020 15:03:57 -0800 Subject: [PATCH] drop dynamic included IFO discovery in favor fixed list This allows for specifying an order that makes sense without too much loss of ease of expandability (just need to add an entry to a list). --- gwinc/__init__.py | 12 ++++++------ gwinc/__main__.py | 4 ++-- gwinc/ifo/__init__.py | 20 ++++++++------------ gwinc/plot.py | 1 + gwinc/test/__main__.py | 2 +- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/gwinc/__init__.py b/gwinc/__init__.py index efa72a1c..d528c5a4 100644 --- a/gwinc/__init__.py +++ b/gwinc/__init__.py @@ -4,7 +4,7 @@ import logging import importlib import numpy as np -from .ifo import available_ifos +from .ifo import IFOS from .struct import Struct from .plot import plot_noise from .io import load_hdf5, save_hdf5 @@ -37,9 +37,9 @@ def load_budget(name_or_path): """Load GWINC IFO Budget by name or from path. Named IFOs should correspond to one of the IFOs available in the - gwinc package (see gwinc.available_ifos()). If a path is provided - it should either be a budget package (directory) or module (ending - in .py), or an IFO struct definition (see gwinc.Struct). + gwinc package (see gwinc.IFOS). If a path is provided it should + either be a budget package (directory) or module (ending in .py), + or an IFO struct definition (see gwinc.Struct). If a budget package path is provided, and the package includes an 'ifo.yaml' file, that file will be loaded into a Struct and @@ -71,10 +71,10 @@ def load_budget(name_or_path): logging.info("loading module path {}...".format(modname)) else: - if name_or_path not in available_ifos(): + if name_or_path not in IFOS: raise RuntimeError("Unknonw IFO '{}' (available IFOs: {}).".format( name_or_path, - available_ifos(), + IFOS, )) bname = name_or_path modname = 'gwinc.ifo.'+name_or_path diff --git a/gwinc/__main__.py b/gwinc/__main__.py index beb810e5..72573767 100644 --- a/gwinc/__main__.py +++ b/gwinc/__main__.py @@ -9,7 +9,7 @@ import logging logging.basicConfig(format='%(message)s', level=os.getenv('LOG_LEVEL', logging.INFO)) -from . import available_ifos, load_budget, plot_noise +from . import IFOS, load_budget, plot_noise from . import io ################################################## @@ -18,7 +18,7 @@ description = """Plot GWINC noise budget for specified IFO. Available included IFOs: {} -""".format(', '.join(["'{}'".format(ifo) for ifo in available_ifos()])) +""".format(', '.join(["'{}'".format(ifo) for ifo in IFOS])) # for ifo in available_ifos(): # description += " '{}'\n".format(ifo) description += """ diff --git a/gwinc/ifo/__init__.py b/gwinc/ifo/__init__.py index 0c5b6ff1..281a5a05 100644 --- a/gwinc/ifo/__init__.py +++ b/gwinc/ifo/__init__.py @@ -1,6 +1,14 @@ import os +IFOS = [ + 'aLIGO', + 'Aplus', + 'Voyager', + 'CE1', + 'CE2', +] + PLOT_STYLE = dict( ylabel=u"Strain [1/\u221AHz]", ) @@ -18,15 +26,3 @@ def lpath(file0, file1): """ return os.path.abspath(os.path.join(os.path.dirname(file0), file1)) - - -def available_ifos(): - """List available included pre-defined IFOs - - """ - ifos = [] - root = os.path.dirname(__file__) - for f in os.listdir(root): - if os.path.isdir(os.path.join(root, f)) and f[0] != '_': - ifos.append(f) - return sorted(ifos) diff --git a/gwinc/plot.py b/gwinc/plot.py index 1b70bdce..a22abe00 100644 --- a/gwinc/plot.py +++ b/gwinc/plot.py @@ -1,6 +1,7 @@ from numpy import sqrt from collections import OrderedDict + def plot_noise( freq, traces, diff --git a/gwinc/test/__main__.py b/gwinc/test/__main__.py index 41c684f4..83fc338f 100644 --- a/gwinc/test/__main__.py +++ b/gwinc/test/__main__.py @@ -14,7 +14,7 @@ from PyPDF2 import PdfFileReader, PdfFileWriter logging.basicConfig(format='%(message)s', level=os.getenv('LOG_LEVEL', logging.INFO)) -from .. import available_ifos, load_budget +from .. import IFOS, load_budget from .. import load_hdf5, save_hdf5 try: -- GitLab