Commit 30d9d792 authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

can now use ${config_name} in paths; add title to figures

parent dd08690b
import os.path as op
from string import Template
from collections import defaultdict
from pyrocko.guts import Object, String
from pyrocko.gf import Earthmodel1D
......@@ -103,6 +105,17 @@ class HasPaths(Object):
for p in path]
def expand_template(template, d):
try:
return Template(template).substitute(d)
except KeyError as e:
raise LassieError(
'invalid placeholder "%s" in template: "%s"' % (str(e), template))
except ValueError:
raise LassieError(
'malformed placeholder in template: "%s"' % template)
__all__ = [
'LassieError',
'Earthmodel',
......
......@@ -7,7 +7,8 @@ from pyrocko.fdsn import station as fs
from pyrocko.gf import TPDef
from lassie import receiver, ifc, grid, geo
from lassie.common import Earthmodel, HasPaths, Path, LassieError
from lassie.common import Earthmodel, HasPaths, Path, LassieError, \
expand_template
guts_prefix = 'lassie'
......@@ -116,6 +117,17 @@ class Config(HasPaths):
self._receivers = None
self._grid = None
self._events = None
self._config_name = 'untitled'
def set_config_name(self, config_name):
self._config_name = config_name
def expand_path(self, path):
def extra(path):
return expand_template(path, dict(
config_name=self._config_name))
return HasPaths.expand_path(self, path, extra=extra)
def get_events_path(self):
run_path = self.expand_path(self.run_path)
......@@ -226,6 +238,8 @@ def read_config(path):
raise LassieError('invalid Lassie configuration in file "%s"' % path)
config.set_basepath(op.dirname(path) or '.')
config.set_config_name(op.splitext(op.basename(path))[0])
return config
......
import os
import numpy as num
from pyrocko import automap, plot
from pyrocko import automap, plot, util
from lassie import grid as gridmod, geo
km = 1000.
......@@ -126,6 +126,7 @@ def plot_detection(
fig = plt.figure(figsize=plot.mpl_papersize('a4', 'landscape'))
axes = plt.subplot2grid((2, 3), (0, 2), aspect=1.0)
plot.mpl_labelspace(axes)
......@@ -334,6 +335,9 @@ def plot_detection(
mec='black',
mfc='white'))
static_artists.append(fig.suptitle(
'%06i - %s' % (idetection, util.time_to_str(t0))))
frame_artists = []
progress_artists = []
......
Markdown is supported
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