Skip to content

Commit

Permalink
Merge pull request #10 from jpvantassel/dev
Browse files Browse the repository at this point in the history
For v0.5.0
  • Loading branch information
jpvantassel authored Dec 28, 2020
2 parents 59aa9ab + 24bc245 commit 4c21452
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
sys.path.insert(0, os.path.abspath('../hvsrpy'))

meta = {}
with open("meta.py") as f:
with open("../hvsrpy/meta.py") as f:
exec(f.read(), meta)

# -- Project information -----------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion examples/azimuthal_hvsrpy_interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Elapsed Time: 2.94 seconds\n",
"Elapsed Time: 1.83 seconds\n",
"\n",
"Statistics after rejection considering azimuth:\n"
]
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_hvsrpy_interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Elapsed Time: 1.86 seconds\n",
"Elapsed Time: 1.19 seconds\n",
"\n",
"Statistics before rejection:\n"
]
Expand Down
8 changes: 4 additions & 4 deletions examples/spatial_hvsrpy_interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,12 @@
" <tbody>\n",
" <tr>\n",
" <th>Fundamental Site Frequency, f0</th>\n",
" <td>0.57</td>\n",
" <td>0.58</td>\n",
" <td>0.15</td>\n",
" </tr>\n",
" <tr>\n",
" <th>Fundamental Site Period, T0</th>\n",
" <td>1.74</td>\n",
" <td>1.73</td>\n",
" <td>0.15</td>\n",
" </tr>\n",
" </tbody>\n",
Expand All @@ -391,8 +391,8 @@
],
"text/plain": [
" Lognormal Median Lognormal Standard Deviation\n",
"Fundamental Site Frequency, f0 0.57 0.15\n",
"Fundamental Site Period, T0 1.74 0.15"
"Fundamental Site Frequency, f0 0.58 0.15\n",
"Fundamental Site Period, T0 1.73 0.15"
]
},
"metadata": {},
Expand Down
11 changes: 6 additions & 5 deletions hvsrpy/hvsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,15 @@ def __init__(self, amplitude, frequency, find_peaks=True,
"""
self.frq = self._check_input("frequency", frequency)
nfrqs = len(self.frq)

self.amp = self._check_input("amplitude", amplitude)
try:
self.amp = self.amp.reshape((self.amp.size//nfrqs, nfrqs))
except ValueError as e:

if len(self.amp.shape) == 1:
self.amp = self.amp.reshape((1, self.amp.size))

if self.frq.size != self.amp.shape[1]:
msg = f"Size of amplitude={self.amp.size} and frequency={self.frq.size} must be compatable."
raise ValueError(msg) from e
raise ValueError(msg)

self.n_windows = self.amp.shape[0]
self.valid_window_indices = np.ones(self.n_windows, dtype=bool)
Expand Down
2 changes: 1 addition & 1 deletion hvsrpy/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@

"""Metadata for hvsrpy."""

__version__ = "0.5.0rc0"
__version__ = "0.5.0"
2 changes: 1 addition & 1 deletion test/data/output/example_output_geopsy.hv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# hvsrpy output version 0.5.0rc0
# hvsrpy output version 0.5.0
# Number of windows = 46
# f0 from average 0.7651
# Number of windows for f0 = 46
Expand Down
2 changes: 1 addition & 1 deletion test/data/output/example_output_hvsrpy.hv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# hvsrpy output version 0.5.0rc0
# hvsrpy output version 0.5.0
# File Name (),UT.STN11.A2_C150.miniseed
# Method (),geometric-mean
# Azimuth (),None
Expand Down
2 changes: 1 addition & 1 deletion test/data/output/example_output_hvsrpy_az.hv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# hvsrpy output version 0.5.0rc0
# hvsrpy output version 0.5.0
# File Name (),UT.STN11.A2_C150.miniseed
# Window Length (s),60.0
# Total Number of Windows per Azimuth (),60
Expand Down
35 changes: 35 additions & 0 deletions test/test_hvsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ def test_init(self):
amp = np.array([1, 2, np.nan])
self.assertRaises(ValueError, hvsrpy.Hvsr, amp, frq)

# incompatible frequency and amplitude
frq = np.array([1, 2, 3])
amp = np.array([1, 2])
self.assertRaises(ValueError, hvsrpy.Hvsr, amp, frq)

# incompatible frequency and amplitude
frq = np.array([1, 2, 3])
amp = np.array([1, 2, 4, 5, 6, 7])
self.assertRaises(ValueError, hvsrpy.Hvsr, amp, frq)

def test_find_peaks(self):
# amp as 1d array - single peak
frq = np.array([1, 2, 3, 4, 5])
Expand Down Expand Up @@ -98,6 +108,31 @@ def test_find_peaks(self):
self.assertNestedListEqual([[1, 3, 5], [2], [2, 4]],
hvsrpy.Hvsr.find_peaks(myhvsr.amp)[0])

def test_peaks_with_limits(self):
# amp as 1d array - two peak
frq = np.array([1, 2, 3, 4, 5, 6, 7, 8])
amp = np.array([[1, 1, 2, 1, 1, 5, 1, 1]])
hvsr = hvsrpy.Hvsr(amp, frq, f_low=None, f_high=4, find_peaks=True)
self.assertArrayEqual(np.array([3.0]), hvsr.peak_frq)

# amp as 1d array - two peak
frq = np.array([1, 2, 3, 4, 5, 6, 7, 8])
amp = np.array([[1, 1, 2, 1, 1, 5, 1, 1]])
hvsr = hvsrpy.Hvsr(amp, frq, f_low=4, f_high=None, find_peaks=True)
self.assertArrayEqual(np.array([6.0]), hvsr.peak_frq)

# amp as 1d array - two peak
frq = np.array([1, 2, 3, 4, 5, 6, 7, 8])
amp = np.array([[1, 1, 2, 1, 1, 5, 1, 1]])
hvsr = hvsrpy.Hvsr(amp, frq, f_low=1, f_high=8, find_peaks=True)
self.assertArrayEqual(np.array([6.0]), hvsr.peak_frq)

# amp as 1d array - two peak
frq = np.array([1, 2, 3, 4, 5, 6, 7, 8])
amp = np.array([[1, 1, 2, 1, 1, 5, 1, 1]])
hvsr = hvsrpy.Hvsr(amp, frq, f_low=None, f_high=None, find_peaks=True)
self.assertArrayEqual(np.array([6.0]), hvsr.peak_frq)

def test_properties(self):
# peak_frq
expected = np.array([2., 3, 3])
Expand Down

0 comments on commit 4c21452

Please sign in to comment.