diff --git a/gwinc/__main__.py b/gwinc/__main__.py index 0ea5aa1a40f0a8969093676b253db225cbdf9951..48569879f37b0d96fb24dd1d4609a46308702953 100644 --- a/gwinc/__main__.py +++ b/gwinc/__main__.py @@ -62,8 +62,8 @@ group.add_argument('--interactive', '-i', action='store_true', help="open interactive shell when plotting") group.add_argument('--no-plot', '-np', action='store_false', dest='plot', help="supress plotting") -parser.add_argument('IFO', nargs='?', default=IFO, - help="IFO name or description file path (.yaml or .mat)") +parser.add_argument('IFO', default=IFO, + help="IFO name or description file path (.yaml, .mat, .m)") def main(): diff --git a/gwinc/ifo/__init__.py b/gwinc/ifo/__init__.py index 71e6ce1cb7f9fb444b88ade4bec8eacbb19b86b2..7ea1c794bf7ae0d296e7ab38edc89d930fe6b6b0 100644 --- a/gwinc/ifo/__init__.py +++ b/gwinc/ifo/__init__.py @@ -2,6 +2,8 @@ import os import fnmatch from ..struct import Struct +from ..gwinc_matlab import Matlab + def available_ifos(): """List available included IFO files""" @@ -15,10 +17,15 @@ def available_ifos(): def load_ifo(name_or_path): """Load IFO by name or from file. - IFO names will correspond to basename of included .yaml IFO - definition file. + Named IFOs should correspond to the basename of .yaml IFO + definition files included with pygwinc (see available_ifos() + above). - When specifying path may be either .yaml or .mat. + When specifying by path files may be either .yaml, .mat or .m. + For .m files, the file is expected to include either an object or + function that corresponds to the basename of the file. The MATLAB + engine will be invoked to execute the .m code and extract the + resultant IFO data. """ if os.path.exists(name_or_path): @@ -26,5 +33,16 @@ def load_ifo(name_or_path): else: path = os.path.join(os.path.dirname(__file__), name_or_path+'.yaml') - s = Struct.from_file(path) - return s + + (root, ext) = os.path.splitext(path) + + if ext == '.m': + matlab = Matlab() + matlab.addpath(os.path.dirname(path)) + func_name = os.path.basename(root) + matlab.eval("ifo = {};".format(func_name), nargout=0) + ifo = matlab.extract('ifo') + return Struct.from_matstruct(ifo) + + else: + return Struct.from_file(path)