Commit c40cbacd authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

add new subcommand: events

parent 2ffed940
......@@ -24,6 +24,7 @@ def d2u(d):
subcommand_descriptions = {
'init': 'print example configuration',
'events': 'print available event names for given configuration',
'check': 'check data and configuration',
'go': 'run Grond optimization',
'forward': 'run forward modelling',
......@@ -34,6 +35,7 @@ subcommand_descriptions = {
subcommand_usages = {
'init': 'init [options]',
'events': 'events <configfile>',
'check': 'check <configfile> <eventnames> ... [options]',
'go': 'go <configfile> <eventnames> ... [options]',
'forward': (
......@@ -56,6 +58,7 @@ usage = '''%(program_name)s <subcommand> [options] [--] <arguments> ...
Subcommands:
init %(init)s
events %(events)s
check %(check)s
go %(go)s
forward %(forward)s
......@@ -173,6 +176,21 @@ def command_init(args):
print config
def command_events(args):
def setup(parser):
pass
parser, options, args = cl_parse('events', args, setup)
if len(args) != 1:
help_and_die(parser, 'missing arguments')
config_path = args[0]
config = grond.read_config(config_path)
for event_name in grond.get_event_names(config):
print event_name
def command_check(args):
def setup(parser):
parser.add_option(
......
......@@ -5,6 +5,7 @@ import logging
import time
import copy
import shutil
import glob
import os.path as op
from string import Template
......@@ -760,6 +761,21 @@ class DatasetConfig(HasPaths):
HasPaths.__init__(self, *args, **kwargs)
self._ds = {}
def get_event_names(self):
def extra(path):
return expand_template(path, dict(
event_name='*'))
def fp(path):
return self.expand_path(path, extra=extra)
events = []
for fn in glob.glob(fp(self.events_path)):
events.extend(model.load_events(filename=fn))
event_names = [ev.name for ev in events]
return event_names
def get_dataset(self, event_name):
if event_name not in self._ds:
def extra(path):
......@@ -960,6 +976,9 @@ class Config(HasPaths):
def __init__(self, *args, **kwargs):
HasPaths.__init__(self, *args, **kwargs)
def get_event_names(self):
return self.dataset_config.get_event_names()
def get_dataset(self, event_name):
return self.dataset_config.get_dataset(event_name)
......@@ -1549,6 +1568,10 @@ def harvest(rundir, problem=None, nbest=10, force=False, weed=0):
problem.dump_problem_data(dumpdir, x, ms, ns)
def get_event_names(config):
return config.get_event_names()
def check_problem(problem):
if len(problem.targets) == 0:
raise GrondError('no targets available')
......@@ -1944,6 +1967,7 @@ __all__ = '''
forward
harvest
go
get_event_names
check
export
'''.split()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment