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

support loading ifo from IFOModel .m script

Assumes the IFOModel is given as function in .m script, and use Matlab
engine interface to execute and load.
parent c29d04c9
No related branches found
No related tags found
No related merge requests found
......@@ -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():
......
......@@ -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)
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