From 05622bd32becbe6fd6f370054d3f3c30653d9877 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 30 Jun 2021 11:14:05 -0700 Subject: [PATCH] point path to noise_module for stretching test. --- test/test_routines/test_stretching.py | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/test/test_routines/test_stretching.py b/test/test_routines/test_stretching.py index f36e2057..7d0fe380 100644 --- a/test/test_routines/test_stretching.py +++ b/test/test_routines/test_stretching.py @@ -1,11 +1,18 @@ import numpy as np -from src.noise_module import stretching_vect, stretching +import sys +import os +sys.path.append(os.getcwd()) +from noise_module import stretching_vect, stretching from obspy.signal.invsim import cosine_taper import pytest +import time # This short script is intended as a test for the stretching routine # it takes a generic sine curve with known stretching factor and ensures # that the stretching routines in noise_module always recover this factor +# Note: The script has to be called from src/ directory, like +# (in directory noisepy/src:) +# python ../test/test_routines/test_stretching.py def test_stretching(): t = np.linspace(0., 9.95, 2500) # 0.5 % perturbation @@ -46,13 +53,14 @@ def test_stretching_vect(): assert dvv + 0.5 < para["dt"] # assert result is -0.5% if __name__ == "__main__": - import sys - if sys.argv[1] == "normal": - for i in range(300): - test_stretching() - elif sys.argv[1] == "vect": - for i in range(300): - test_stretching_vect() - else: - raise ValueError("call with python test_stretching.py ,\ -where choice of stretching is \"normal\" or \"vect\".") + print("Running stretching...") + t = time.time() + for i in range(300): + test_stretching() + print("Done stretching, no errors, %4.2fs." %(time.time()-t)) + + print("Running stretching using numpy...") + t = time.time() + for i in range(300): + test_stretching_vect() + print("Done stretching, no errors, %4.2fs." %(time.time()-t))