Skip to content

Commit

Permalink
Added tests for with_irf
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Jul 8, 2020
1 parent 2c6fe4e commit 8d76f69
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/time_series/test_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import numpy as np

from skued import biexponential, exponential
from skued import biexponential, exponential, with_irf

seed(23)

Expand Down Expand Up @@ -128,5 +128,44 @@ def test_against_exponential(self):
self.assertTrue(np.allclose(exp, biexp))


class TestWithIrf(unittest.TestCase):
def test_trivial_constant_spacing(self):
""" Test with_irf with a trivial IRF, with constant spacing """
params = (0, 1, 3)
times = np.linspace(-5, 15, 256)
data = exponential(times, *params)

@with_irf(0.00001) # vanishingly small irf
def exponential_with_irf(time, *args, **kwargs):
return exponential(time, *args, **kwargs)

conv = exponential_with_irf(times, *params)

self.assertTrue(np.allclose(data, conv))

def test_trivial_nonconstant_spacing(self):
""" Test with_irf with a trivial IRF, with non-constant spacing """
# Note that the spacing of the steps is important for this test
# If the array `times` is of even length, then the convolution will result
# in one time-step shift
params = (0, 1, 3)
times = np.concatenate(
(
np.arange(-10, -2, step=1),
np.arange(-2, 2, step=0.04),
np.arange(2, 10, step=1),
)
)
data = exponential(times, *params)

@with_irf(0.00001) # vanishingly small irf
def exponential_with_irf(time, *args, **kwargs):
return exponential(time, *args, **kwargs)

conv = exponential_with_irf(times, *params)

self.assertTrue(np.allclose(data, conv))


if __name__ == "__main__":
unittest.main()

0 comments on commit 8d76f69

Please sign in to comment.