Skip to content

Commit

Permalink
tests for harmonics calc+plot
Browse files Browse the repository at this point in the history
  • Loading branch information
hfmark committed May 9, 2024
1 parent 680eddf commit 7b3e31a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions rf/tests/test_harmonics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2013-2016 Tom Eulenfeld, MIT license
"""
Tests for harmonics module.
"""
import unittest

from rf.rfstream import read_rf, rfstats
from rf.harmonics import harmonics
import warnings

class HarmonicsTestCase(unittest.TestCase):
def test_harmonics_RT(self):
stream = read_rf()
rfstats(stream)
stream.filter('bandpass',freqmin=0.33,freqmax=1)
stream.trim2(-5,15)
stream.rf(deconvolve='multitaper',rotate='NE->RT',\
gauss=0.5,K=3,tband=4,T=10,olap=0.75,normalize=0)
with warnings.catch_warnings(): # warns for sparse data; generally bad but ok for test
warnings.simplefilter("ignore")
harm = harmonics(stream,components='RT',scalars=(1,1),method='time')
trtest = harm.select(location='mod',channel='0')[0]
self.assertEqual(trtest.data.argmax(),100)
self.assertEqual(trtest.data.max().round(4),1.1839)

def test_harmonics_R(self):
stream = read_rf()
rfstats(stream)
stream.filter('bandpass',freqmin=0.33,freqmax=1)
stream.trim2(-5,15)
stream.rf(deconvolve='multitaper',rotate='NE->RT',\
gauss=0.5,K=3,tband=4,T=10,olap=0.75,normalize=0)
with warnings.catch_warnings(): # warns for sparse data; generally bad but ok for test
warnings.simplefilter("ignore")
harm = harmonics(stream,components='R',method='time')
trtest = harm.select(location='mod',channel='0')[0]
self.assertEqual(trtest.data.argmax(),100)
self.assertEqual(trtest.data.max().round(4),1.7725)

def suite():
return unittest.makeSuite(HarmonicsTestCase, 'test')

if __name__ == '__main__':
unittest.main(defaultTest='suite')

9 changes: 9 additions & 0 deletions rf/tests/test_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ def test_plot_ppoints(self):
stream = minimal_example_rf()
plot_ppoints(stream.ppoints(50), inventory=stream)

def test_plot_harmonics(self):
from rf.imaging import plot_harmonics
from rf.harmonics import harmonics
stream = minimal_example_rf()
with warnings.catch_warnings():
warnings.simplefilter("ignore")
harm = harmonics(stream,components='QT',scalars=(1,1))
plot_harmonics(harm)


def suite():
return unittest.makeSuite(ImagingTestCase, 'test')
Expand Down

0 comments on commit 7b3e31a

Please sign in to comment.