Skip to content

Commit

Permalink
tests should (could) pass :-)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLecocq committed May 26, 2023
1 parent b079afc commit d74ddd4
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 31 deletions.
2 changes: 1 addition & 1 deletion msnoise/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2182,7 +2182,7 @@ def xr_get_ccf(station1, station2, components, filterid, mov_stack, taxis):

def xr_save_ref(station1, station2, components, filterid, taxis, new, overwrite=False):
path = os.path.join("STACKS2", "%02i" % filterid,
"%REF", "%s" % components)
"REF", "%s" % components)
fn = "%s_%s.nc" % (station1, station2)
fullpath = os.path.join(path, fn)
if overwrite:
Expand Down
35 changes: 17 additions & 18 deletions msnoise/plots/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""

import matplotlib.pyplot as plt
from obspy import read
from obspy import read, Trace
from ..api import *


Expand All @@ -34,7 +34,7 @@ def main(filterid, components, ampli=1, show=True, outfile=None,
maxlag = float(get_config(db, 'maxlag'))
maxlagsamples = get_maxlag_samples(db)
t = np.linspace(-maxlag, maxlag, maxlagsamples)

taxis = get_t_axis(db)
if refilter:
freqmin, freqmax = refilter.split(':')
freqmin = float(freqmin)
Expand All @@ -57,22 +57,21 @@ def main(filterid, components, ampli=1, show=True, outfile=None,
if virtual_source not in [sta1, sta2]:
continue

pair = "%s:%s" % (sta1, sta2)
print(pair, dist)
ref_name = pair.replace(':', '_')
rf = os.path.join("STACKS", "%02i" %
filterid, "REF", components, ref_name + extension)
print(rf)
if os.path.isfile(rf):
ref = read(rf)[0]
if refilter:
ref.detrend("simple")
ref.taper(0.02)
ref.filter("bandpass", freqmin=freqmin, freqmax=freqmax,
zerophase=True)
ref.normalize()
ref = ref.data * ampli
plt.plot(t, ref+dist, c='k', lw=0.4)
try:
ref = xr_get_ref(sta1, sta2, components, filterid, taxis)
ref = Trace(data=ref.CCF.values)
ref.stats.sampling_rate = cc_sampling_rate
except FileNotFoundError:
continue

if refilter:
ref.detrend("simple")
ref.taper(0.02)
ref.filter("bandpass", freqmin=freqmin, freqmax=freqmax,
zerophase=True)
ref.normalize()
ref = ref.data * ampli
plt.plot(t, ref+dist, c='k', lw=0.4)

plt.ylabel("Interstation Distance in km")
plt.xlabel("Lag Time")
Expand Down
4 changes: 3 additions & 1 deletion msnoise/plots/dvv.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
.. image:: ../.static/dvv.png
"""
import traceback

import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
Expand All @@ -25,7 +26,7 @@ def main(mov_stack=None, dttname="M", components='ZZ', filterid=1,
params = get_params(db)
start, end, datelist = build_movstack_datelist(db)

if mov_stack != 0:
if mov_stack and mov_stack != 0:
mov_stacks = [mov_stack, ]
else:
mov_stacks = params.mov_stack
Expand Down Expand Up @@ -54,6 +55,7 @@ def main(mov_stack=None, dttname="M", components='ZZ', filterid=1,
try:
dvv = xr_get_dvv(comps, filterid, mov_stack)
except:
traceback.print_exc()
continue
for _ in ["mean", "50%", "trimmed_mean", "weighted_mean"]:
plt.plot(dvv.index, dvv.loc[:, ("m", _)] * -100, label="%s: %s" % (comps,_ ))
Expand Down
1 change: 1 addition & 0 deletions msnoise/s05compute_mwcs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ def ww(a):
mcoh = np.mean(coh)
MCOH.append(np.real(mcoh))
# Get Weights
coh[coh==1] = 1.0-1e-9
w = 1.0 / (1.0 / (coh ** 2) - 1.0)
w[coh >= 0.99] = 1.0 / (1.0 / 0.9801 - 1.0)
w = np.sqrt(w * np.sqrt(dcs[i][index_range]))
Expand Down
35 changes: 24 additions & 11 deletions msnoise/test/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def test_022_check_content(self):

def test_023_stack(self):
from ..api import connect, update_config, reset_jobs
from ..s04stack import main
from ..s04_stack2 import main
db = connect()
update_config(db, 'ref_begin', '2009-01-01')
update_config(db, 'ref_end', '2011-01-01')
Expand All @@ -320,14 +320,18 @@ def test_023_stack(self):
db.close()

def test_024_mwcs(self):
from ..s05compute_mwcs import main
from ..s05compute_mwcs2 import main
main()

def test_025_dtt(self):
from ..s06compute_dtt import main
from ..s06compute_dtt2 import main
main()

def test_026_build_ref_datelist(self):
def test_026_dvv(self):
from ..s07_compute_dvv import main
main()

def test_027_build_ref_datelist(self):
from ..api import connect, build_ref_datelist
db = connect()
start, end, datelist = build_ref_datelist(db)
Expand All @@ -336,7 +340,7 @@ def test_026_build_ref_datelist(self):
self.failUnlessEqual(len(datelist), 731)
db.close()

def test_027_build_movstack_datelist(self):
def test_028_build_movstack_datelist(self):
from ..api import connect, build_movstack_datelist
db = connect()
start, end, datelist = build_movstack_datelist(db)
Expand All @@ -345,7 +349,7 @@ def test_027_build_movstack_datelist(self):
self.failUnlessEqual(len(datelist), 731)
db.close()

def test_028_stretching(self):
def test_029_stretching(self):
from ..api import connect, update_config, reset_jobs
db = connect()
update_config(db, "export_format", "MSEED")
Expand All @@ -355,7 +359,7 @@ def test_028_stretching(self):
from ..stretch import main
main()

def test_029_create_fake_new_files(self):
def test_030_create_fake_new_files(self):
for f in sorted(glob.glob(os.path.join(self.data_folder, "2010", "*",
"HHZ.D", "*"))):
st = read(f)
Expand All @@ -379,7 +383,7 @@ def test_029_create_fake_new_files(self):
self.failUnlessEqual(jobs[1][0], 3)
self.failUnlessEqual(jobs[1][1], 'T')

def test_030_instrument_response(self):
def test_031_instrument_response(self):
from ..api import connect, update_config
path = os.path.abspath(os.path.dirname(__file__))
resp_folder = os.path.join(path, 'extra')
Expand Down Expand Up @@ -468,6 +472,14 @@ def test_102_plot_distance(self):
self.assertTrue(os.path.isfile(fn),
msg="%s doesn't exist" % fn)

def test_103_plot_dvv(self):
from ..plots.dvv import main
main(filterid=1, components="ZZ", show=False, outfile="?.png")
fn = "dvv ['ZZ']-f1-MM.png"
self.assertTrue(os.path.isfile(fn),
msg="%s doesn't exist" % fn)


# def test_103_plot_mwcs(self):
# from ..plots.mwcs import main
# main("YA.UV05", "YA.UV06", filterid=1, components="ZZ",
Expand Down Expand Up @@ -555,9 +567,10 @@ def test_304_export_rms(self):

def test_400_run_manually(self):
os.system("msnoise reset STACK --all")
os.system("msnoise cc stack2 -m")
os.system("msnoise cc dvv compute_mwcs2")
os.system("msnoise cc dvv compute_dtt2")
os.system("msnoise cc stack -m")
os.system("msnoise cc dvv compute_mwcs")
os.system("msnoise cc dvv compute_dtt")
os.system("msnoise cc dvv compute_dvv")

def test_99210_crondays_positive_float(self):
"""
Expand Down

0 comments on commit d74ddd4

Please sign in to comment.