Skip to content

Commit

Permalink
Merge pull request #3 from myokit/imaxabs
Browse files Browse the repository at this point in the history
Added iabs_max_on
  • Loading branch information
MichaelClerx authored Dec 6, 2024
2 parents 0cf75bc + 4e8fd9e commit b3d0d06
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions datkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

from ._points import ( # noqa
abs_max_on,
iabs_max_on,
imax_on,
imin_on,
index,
Expand Down
12 changes: 12 additions & 0 deletions datkit/_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ def abs_max_on(times, values, t0=None, t1=None, include_left=True,
return times[i], values[i]


def iabs_max_on(times, values, t0=None, t1=None, include_left=True,
include_right=False):
"""
Returns the index ``i`` corresponding to the maximum of ``abs(values)`` on
the interval from ``t0`` to ``t1``.
See also :meth:`index_on`.
"""
i, j = index_on(times, t0, t1, include_left, include_right)
return i + np.argmax(np.abs(values[i:j]))


def imax_on(times, values, t0=None, t1=None, include_left=True,
include_right=False):
"""
Expand Down
10 changes: 10 additions & 0 deletions datkit/tests/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ def test_abs_max_on(self):
self.assertEqual(d.abs_max_on(t, v, 1.5, 2), (t[99], v[99]))
self.assertEqual(d.abs_max_on(t, v, 1.5, 2, False, True), (2, 1))

def test_iabs_max_on(self):
t = np.linspace(0, 2, 101)
v = np.cos(t * np.pi)
self.assertEqual(d.iabs_max_on(t, v, 0, 1), 0)
self.assertEqual(d.iabs_max_on(t, v, 0.5, 1), 49)
self.assertEqual(d.iabs_max_on(t, v, 0.5, 1, True, True), 50)
self.assertEqual(d.iabs_max_on(t, v, 0.6, 1.5), 50)
self.assertEqual(d.iabs_max_on(t, v, 1.5, 2), 99)
self.assertEqual(d.iabs_max_on(t, v, 1.5, 2, False, True), 100)

def test_imax_on(self):
t = np.linspace(0, 2, 101)
v = np.cos(t * np.pi)
Expand Down
2 changes: 2 additions & 0 deletions docs/source/finding_points.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Finding points

.. autofunction:: imin_on

.. autofunction:: iabs_max_on

0 comments on commit b3d0d06

Please sign in to comment.