Commit 72ce21bb authored by Sebastian Heimann's avatar Sebastian Heimann
Browse files

synthetic tests: new option to add white noise

parent 2f76860c
......@@ -683,12 +683,11 @@ class SyntheticWaveformNotAvailable(Exception):
class SyntheticTest(Object):
inject_solution = Bool.T(default=False)
respect_data_availability = Bool.T(default=False)
add_real_noise = Bool.T(default=False)
add_white_noise = Bool.T(default=False)
amplitude_white_noise = Float.T(default=1.0e-6)
random_seed = Int.T(optional=True)
real_noise_scale = Float.T(default=0.0)
white_noise_scale = Float.T(default=0.0)
random_response_scale = Float.T(default=0.0)
toffset_real_noise = Float.T(default=-3600.)
real_noise_toffset = Float.T(default=-3600.)
random_seed = Int.T(optional=True)
x = Dict.T(String.T(), Float.T())
def __init__(self, **kwargs):
......@@ -733,15 +732,18 @@ class SyntheticTest(Object):
if self.random_response_scale != 0:
tf = RandomResponse(scale=self.random_response_scale)
rstate = num.random.RandomState(iresult)
rstate = num.random.RandomState(
(self.random_seed or 0) + iresult)
tf.set_random_state(rstate)
tr = tr.transfer(
tfade=tfade,
transfer_function=tf)
if self.add_white_noise:
u = num.random.normal(
scale=self.amplitude_white_noise,
if self.white_noise_scale != 0.0:
rstate = num.random.RandomState(
(self.random_seed or 0) + iresult)
u = rstate.normal(
scale=self.white_noise_scale,
size=tr.data_len())
tr.ydata += u
......
......@@ -519,10 +519,10 @@ class Dataset(object):
toffset_noise_extract = 0.0
if syn_test:
if not syn_test.respect_data_availability:
if syn_test.add_real_noise:
if syn_test.real_noise_scale != 0.0:
raise DatasetError(
'respect_data_availability=False and '
'add_real_noise=True cannot be combined.')
'addition of real noise cannot be combined.')
tr = syn_test.get_waveform(
nslc, tmin, tmax,
......@@ -534,7 +534,7 @@ class Dataset(object):
return tr
if syn_test.add_real_noise:
if syn_test.real_noise_scale != 0.0:
toffset_noise_extract = syn_test.toffset_real_noise
abs_delays = []
......@@ -589,9 +589,14 @@ class Dataset(object):
tfade=tfade, freqlimits=freqlimits)
if tr_syn:
if syn_test.add_real_noise:
if syn_test.real_noise_scale != 0.0:
tr_syn = tr_syn.copy()
tr_syn.add(tr)
tr_noise = tr.copy()
tr_noise.set_ydata(
tr_noise.get_ydata()
* syn_test.real_noise_scale)
tr_syn.add(tr_noise)
trs_projected_synthetic.append(tr_syn)
......
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