Skip to content

Commit

Permalink
* Added function get_n_cyc_array to compute number of cycles series…
Browse files Browse the repository at this point in the history
… from a loading series
  • Loading branch information
millen1m committed Oct 22, 2019
1 parent 2b21bdc commit 723db15
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ History

* Fixed issue in `get_zero_crossings_array_indices` where it would fail if array did not contain any zeros.
* Added calculation of equivalent number of cycles and equivalent uniform amplitude using power law relationship as intensity measures
* Added function `get_n_cyc_array` to compute number of cycles series from a loading series


1.1.0 (2019-10-08)
Expand Down
32 changes: 32 additions & 0 deletions eqsig/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,38 @@ def get_peak_array_indices(values, ptype='all'):
return peak_full_indices


def get_n_cyc_array(values, opt='all', start='origin'):
"""
Given an array, create an array of the same length that numbers the peaks
Parameters
----------
values
opt
Returns
-------
"""
if opt == 'all':
indys = get_peak_array_indices(values)
elif opt == 'switched':
indys = get_switched_peak_array_indices(values)
else:
raise ValueError('opt must be either "all" or "switched"')
# each indy corresponds to half a cycle
if start == 'origin':
svalue = -0.25
elif start == 'peak':
svalue = 0.0
else:
raise ValueError('start must be either "origin" or "peak"')
if indys[0] != 0:
indys = np.insert(indys, 0, 0)
n_cycs = 0.5 * np.arange(len(indys))
n_cycs[1:] += svalue
return np.interp(np.arange(len(values)), indys, n_cycs)


def get_peak_indices(asig):
return get_peak_array_indices(asig.values)

Expand Down
13 changes: 12 additions & 1 deletion tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ def test_get_peak_indices():
expected = np.array([0, 1, 2, 3, 4, 5, 8, 10, 11])
assert np.sum(abs(peak_indices - expected)) == 0

values = np.array([2, 1, -1, 1])
peak_indices = fns.get_peak_array_indices(values)
expected = np.array([0, 2, 3])
assert np.sum(abs(peak_indices - expected)) == 0

values = np.array([1, 2, -1, 1])
peak_indices = fns.get_peak_array_indices(values)
expected = np.array([0, 1, 2, 3])
assert np.sum(abs(peak_indices - expected)) == 0



def test_get_zero_crossings_array_indices():
vs = np.array([0, 2, 1, 2, -1, 1, 0, 0, 1, 0.3, 0, -1, 0.2, 1, 0.2])
Expand Down Expand Up @@ -272,7 +283,7 @@ def test_roll_av_vals():

if __name__ == '__main__':

test_get_zero_crossings_array_indices2()
test_get_peak_indices()
# test_put_array_in_2d_array()
# test_fa_spectrum_conversion()
# test_determine_peaks_only_series_with_sine_wave()
Expand Down

0 comments on commit 723db15

Please sign in to comment.