2022-04-20 12:08:38 +00:00
|
|
|
from copy import copy
|
|
|
|
import pytest
|
|
|
|
import numpy as np
|
|
|
|
|
|
|
|
from mdevaluate import utils
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def logdata(request):
|
|
|
|
xdata = np.logspace(-1, 3, 50)
|
2023-12-18 13:47:22 +00:00
|
|
|
ydata = np.exp(-((xdata) ** 0.7))
|
2022-04-20 12:08:38 +00:00
|
|
|
return xdata, ydata
|
|
|
|
|
|
|
|
|
|
|
|
def test_filon_fourier_transformation(logdata):
|
|
|
|
xdata, ydata = logdata
|
|
|
|
|
|
|
|
xdata_zero = copy(xdata)
|
|
|
|
xdata_zero[0] = 0
|
|
|
|
_, filon = utils.filon_fourier_transformation(xdata_zero, ydata)
|
2023-12-18 13:47:22 +00:00
|
|
|
assert not np.isnan(filon).any(), "There are NaN values in the filon result!"
|
2022-04-20 12:08:38 +00:00
|
|
|
|
|
|
|
freqs = np.logspace(-4, 1)
|
|
|
|
filon_freqs, filon_imag = utils.filon_fourier_transformation(
|
2023-12-18 13:47:22 +00:00
|
|
|
xdata, xdata, frequencies=freqs, derivative="linear", imag=True
|
|
|
|
)
|
2022-04-20 12:08:38 +00:00
|
|
|
|
|
|
|
assert (freqs == filon_freqs).all()
|
|
|
|
|
|
|
|
freqs, filon_real = utils.filon_fourier_transformation(
|
2023-12-18 13:47:22 +00:00
|
|
|
xdata, xdata, frequencies=freqs, derivative="linear", imag=False
|
|
|
|
)
|
2022-04-20 12:08:38 +00:00
|
|
|
assert np.isclose(filon_imag.real, filon_real).all()
|