Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sebastian Heimann
grond
Commits
511c0533
Commit
511c0533
authored
Oct 17, 2016
by
Sebastian Heimann
Browse files
allow templating in dataset paths
parent
bff01f3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/cmt.py
View file @
511c0533
...
...
@@ -302,7 +302,7 @@ class CMTProblemConfig(core.ProblemConfig):
event_time
=
util
.
time_to_str
(
event
.
time
))
problem
=
CMTProblem
(
name
=
core
.
substitute
_template
(
self
.
name_template
,
subs
),
name
=
core
.
expand
_template
(
self
.
name_template
,
subs
),
apply_balancing_weights
=
self
.
apply_balancing_weights
,
base_source
=
base_source
,
targets
=
targets
,
...
...
src/core.py
View file @
511c0533
...
...
@@ -634,18 +634,24 @@ class HasPaths(Object):
self
.
_basepath
=
new_basepath
def
expand_path
(
self
,
path
):
def
expand_path
(
self
,
path
,
extra
=
None
):
assert
self
.
_basepath
is
not
None
if
extra
is
None
:
def
extra
(
path
):
return
path
path_prefix
=
self
.
path_prefix
or
self
.
_parent_path_prefix
if
path
is
None
:
return
None
elif
isinstance
(
path
,
basestring
):
return
op
.
normpath
(
xjoin
(
self
.
_basepath
,
xjoin
(
path_prefix
,
path
)))
return
extra
(
op
.
normpath
(
xjoin
(
self
.
_basepath
,
xjoin
(
path_prefix
,
path
))))
else
:
return
[
op
.
normpath
(
xjoin
(
self
.
_basepath
,
xjoin
(
path_prefix
,
p
)))
extra
(
op
.
normpath
(
xjoin
(
self
.
_basepath
,
xjoin
(
path_prefix
,
p
))))
for
p
in
path
]
...
...
@@ -757,7 +763,13 @@ class DatasetConfig(HasPaths):
def
get_dataset
(
self
,
event_name
):
if
event_name
not
in
self
.
_ds
:
fp
=
self
.
expand_path
def
extra
(
path
):
return
expand_template
(
path
,
dict
(
event_name
=
event_name
))
def
fp
(
path
):
return
self
.
expand_path
(
path
,
extra
=
extra
)
ds
=
dataset
.
Dataset
(
event_name
)
ds
.
add_stations
(
pyrocko_stations_filename
=
fp
(
self
.
stations_path
),
...
...
@@ -1643,7 +1655,7 @@ def go(config, event_names=None, force=False, nparallel=1, status=('state',)):
pass
def
substitute
_template
(
template
,
d
):
def
expand
_template
(
template
,
d
):
try
:
return
Template
(
template
).
substitute
(
d
)
except
KeyError
as
e
:
...
...
@@ -1679,7 +1691,7 @@ def process_event(ievent, g_data_id):
check_problem
(
problem
)
rundir
=
substitute
_template
(
rundir
=
expand
_template
(
config
.
rundir_template
,
dict
(
problem_name
=
problem
.
name
))
...
...
@@ -1725,6 +1737,9 @@ def process_event(ievent, g_data_id):
logger
.
info
(
'stop %i / %i (%g min)'
%
(
ievent
,
nevents
,
(
tstop
-
tstart
)
/
60.
))
logger
.
info
(
'done with problem %s, rundir is %s'
%
(
problem
.
name
,
rundir
))
class
ParameterStats
(
Object
):
name
=
String
.
T
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment