Commit 92c236c6 authored by Sebastian Heimann's avatar Sebastian Heimann

Merge branch 'exercise_dahm' into refactor

Conflicts:
	src/apps/__main__.py
	src/core.py
	src/dataset.py
	src/plot.py
parents 2d5ba359 ba89f37c
......@@ -512,6 +512,7 @@ def command_plot(args):
'hudson',
'fits',
'fits_statics',
'fits_ensemble',
'solution',
'location']
......@@ -630,12 +631,19 @@ def command_qc_polarization(args):
def setup(parser):
parser.add_option(
'--time-factor', dest='time_factor', type=float,
'--time-factor-pre', dest='time_factor_pre', type=float,
metavar='NUMBER',
default=0.5,
help='set duration to extract before and after synthetic P phase '
'arrival, relative to 1/fmin. fmin is taken from the '
'selected target group in the config file (default=%default)')
help='set duration to extract before synthetic P phase arrival, '
'relative to 1/fmin. fmin is taken from the selected target '
'group in the config file (default=%default)')
parser.add_option(
'--time-factor-post', dest='time_factor_post', type=float,
metavar='NUMBER',
default=0.5,
help='set duration to extract after synthetic P phase arrival, '
'relative to 1/fmin. fmin is taken from the selected target '
'group in the config file (default=%default)')
parser.add_option(
'--distance-min', dest='distance_min', type=float,
metavar='NUMBER',
......@@ -715,7 +723,8 @@ def command_qc_polarization(args):
grond.qc.polarization(
ds, store, timing, fmin=fmin, fmax=fmax, ffactor=ffactor,
time_factor=options.time_factor,
time_factor_pre=options.time_factor_pre,
time_factor_post=options.time_factor_post,
distance_min=options.distance_min,
distance_max=options.distance_max,
depth_min=options.depth_min,
......
......@@ -348,13 +348,18 @@ class Dataset(object):
return scene
raise NotFound('No kite scene with id %s defined' % scene_id)
def get_response(self, obj):
def get_response(self, obj, quantity='displacement'):
if (self.responses is None or len(self.responses) == 0) \
and (self.responses_stationxml is None
or len(self.responses_stationxml) == 0):
raise NotFound('no response information available')
quantity_to_unit = {
'displacement': 'M',
'velocity': 'M/S',
'acceleration': 'M/S**2'}
if self.is_blacklisted(obj):
raise NotFound('response is blacklisted', self.get_nslc(obj))
......@@ -377,7 +382,18 @@ class Dataset(object):
if k in self.responses:
for x in self.responses[k]:
if x.tmin < tmin and (x.tmax is None or tmax < x.tmax):
candidates.append(x.response)
if quantity == 'displacement':
candidates.append(x.response)
elif quantity == 'velocity':
candidates.append(trace.MultiplyResponse([
x.response,
tarce.DifferentiationResponse()]))
elif quantity == 'acceleration':
candidates.append(trace.MultiplyResponse([
x.response,
tarce.DifferentiationResponse(2)]))
else:
assert False
for sx in self.responses_stationxml:
try:
......@@ -385,7 +401,7 @@ class Dataset(object):
sx.get_pyrocko_response(
(net, sta, loc, cha),
timespan=(tmin, tmax),
fake_input_units='M'))
fake_input_units=quantity_to_unit[quantity]))
except (fs.NoResponseInformation, fs.MultipleResponseInformation):
pass
......@@ -468,8 +484,6 @@ class Dataset(object):
want_incomplete=False,
extend_incomplete=False):
assert quantity == 'displacement' # others not yet implemented
trs_raw = self.get_waveform_raw(
obj, tmin=tmin, tmax=tmax, tpad=tpad+tfade,
toffset_noise_extract=toffset_noise_extract,
......@@ -482,7 +496,7 @@ class Dataset(object):
tr.downsample_to(deltat, snap=True, allow_upsample_max=5)
tr.deltat = deltat
resp = self.get_response(tr)
resp = self.get_response(tr, quantity=quantity)
trs_restituted.append(
tr.transfer(
tfade=tfade, freqlimits=freqlimits,
......@@ -537,7 +551,6 @@ class Dataset(object):
debug=False):
assert not debug or (debug and cache is None)
assert quantity == 'displacement' # others not yet implemented
if cache is True:
cache = self._cache
......@@ -622,6 +635,7 @@ class Dataset(object):
trs_restituted_this, trs_raw_this = \
self.get_waveform_restituted(
station.nsl() + (cha,),
quantity=quantity,
tmin=tmin, tmax=tmax, tpad=tpad+abs_delay_max,
toffset_noise_extract=toffset_noise_extract,
tfade=tfade,
......
This diff is collapsed.
......@@ -452,7 +452,6 @@ class ModelHistory(object):
self.nmodels_capacity = self.nmodels_capacity_min
self.listeners = []
self.mode = mode
self.optimizer = load_optimizer_info(path)
if mode == 'r':
self.verify_rundir(self.path)
......@@ -461,7 +460,7 @@ class ModelHistory(object):
@staticmethod
def verify_rundir(rundir):
_rundir_files = ['config.yaml', 'optimizer.yaml', 'misfits', 'models']
_rundir_files = ['misfits', 'models']
if not op.exists(rundir):
raise OSError('Rundir %s does not exist!' % rundir)
......
......@@ -6,7 +6,7 @@ import numpy as num
from matplotlib import pyplot as plt
from mpl_toolkits.axes_grid1 import ImageGrid
from pyrocko import gf, orthodrome as od, plot
from pyrocko import gf, orthodrome as od, plot, model, trace
from grond import dataset
km = 1000.
......@@ -34,7 +34,8 @@ def plot_color_line(axes, x, y, t, color, tmin, tmax):
def polarization(
ds, store, timing, fmin, fmax, ffactor,
time_factor=2.,
time_factor_pre=2.,
time_factor_post=2.,
distance_min=None,
distance_max=None,
depth_min=None,
......@@ -48,9 +49,6 @@ def polarization(
event = ds.get_event()
stations = ds.get_stations()
nsl_to_station = dict(
(s.nsl(), s) for s in stations)
source = gf.Source.from_pyrocko_event(event)
trs = []
......@@ -83,8 +81,8 @@ def polarization(
for component in 'ZNE':
tmin = tp - time_factor / fmin
tmax = tp + time_factor / fmin
tmin = tp - time_factor_pre / fmin
tmax = tp + time_factor_post / fmin
nslc = nsl + (component,)
......@@ -106,17 +104,48 @@ def polarization(
freqlimits=freqlimits,
debug=True)
for tr in trs_projected:
tr.shift(-tp)
trs.extend(trs_projected)
except dataset.NotFound as e:
logger.warn(str(e))
continue
d_trs = defaultdict(dict)
trace.snuffle(trs, stations=stations)
plot_polarizations(
stations, trs,
event=event,
size_factor=size_factor,
output_filename=output_filename,
output_format=output_format,
output_dpi=output_dpi)
def plot_polarizations(
stations, trs,
event=None,
size_factor=0.05,
fontsize=10.,
output_filename=None,
output_format=None,
output_dpi=None):
if event is None:
slats = num.array([s.lat for s in stations], dtype=num.float)
slons = num.array([s.lon for s in stations], dtype=num.float)
clat, clon = od.geographic_midpoint(slats, slons)
event = od.Loc(clat, clon)
nsl_c_to_trs = defaultdict(dict)
for tr in trs:
d_trs[tr.nslc_id[:3]][tr.nslc_id[3]] = tr
nsl_c_to_trs[tr.nslc_id[:3]][tr.nslc_id[3]] = tr
nsl_to_station = dict(
(s.nsl(), s) for s in stations)
fontsize = 10.
plot.mpl_init(fontsize=fontsize)
fig = plt.figure(figsize=plot.mpl_papersize('a4', 'landscape'))
plot.mpl_margins(fig, w=7., h=6., units=fontsize)
......@@ -140,14 +169,15 @@ def polarization(
axes_ed.set_ylabel('Depth [km]')
axes_ed.set_xlabel('Easting [km]')
axes_en.plot(0., 0., '*')
axes_dn.plot(event.depth/km, 0., '*')
axes_ed.plot(0., event.depth/km, '*')
if isinstance(event, model.Event):
axes_en.plot(0., 0., '*')
axes_dn.plot(event.depth/km, 0., '*')
axes_ed.plot(0., event.depth/km, '*')
grid[3].set_axis_off()
locations = []
for nsl in sorted(d_trs.keys()):
for nsl in sorted(nsl_c_to_trs.keys()):
station = nsl_to_station[nsl]
n, e = od.latlon_to_ne(
event.lat, event.lon, station.lat, station.lon)
......@@ -166,14 +196,14 @@ def polarization(
fontsize_annot = fontsize * 0.7
data = {}
for insl, nsl in enumerate(sorted(d_trs.keys())):
for insl, nsl in enumerate(sorted(nsl_c_to_trs.keys())):
color = plot.mpl_graph_color(insl)
try:
tr_e = d_trs[nsl]['E']
tr_n = d_trs[nsl]['N']
tr_z = d_trs[nsl]['Z']
tr_e = nsl_c_to_trs[nsl]['E']
tr_n = nsl_c_to_trs[nsl]['N']
tr_z = nsl_c_to_trs[nsl]['Z']
except KeyError:
continue
......
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