Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arguments of Scipy special functions #870

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changes/870.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix problem with data types fed to scipy special functions
5 changes: 3 additions & 2 deletions stingray/bexvar.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
log_src_crs_grid : iterable, `:class:numpy.array` of floats
An array of log(source count rates).
"""

src_counts = np.asanyarray(src_counts, dtype=float)
bkg_counts = np.asanyarray(bkg_counts, dtype=float)

Check warning on line 62 in stingray/bexvar.py

View check run for this annotation

Codecov / codecov/patch

stingray/bexvar.py#L61-L62

Added lines #L61 - L62 were not covered by tests
# lowest count rate
a = scipy.special.gammaincinv(src_counts + 1, 0.001) / rate_conversion
# highest background count rate
Expand Down Expand Up @@ -113,9 +114,9 @@
# background counts give background count rates deterministically
N = 1000
u = np.linspace(0, 1, N)[1:-1]
bkg_cr = scipy.special.gammaincinv(bkg_counts + 1, u) / bkg_area
bkg_cr = scipy.special.gammaincinv(float(bkg_counts) + 1, u) / bkg_area

def prob(log_src_cr):

Check warning on line 119 in stingray/bexvar.py

View check run for this annotation

Codecov / codecov/patch

stingray/bexvar.py#L117-L119

Added lines #L117 - L119 were not covered by tests
src_cr = 10**log_src_cr * rate_conversion
like = scipy.stats.poisson.pmf(src_counts, src_cr + bkg_cr).mean()
return like
Expand Down
4 changes: 2 additions & 2 deletions stingray/pulse/accelsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ def _create_responses(range_z):
Yks = sign * np.sqrt(2 / absz) * q_ks
Zks = sign * np.sqrt(2 / absz) * (q_ks + z)
# print(Yks, Zks)
[SZs, CZs] = special.fresnel(Zks)
[SYs, CYs] = special.fresnel(Yks)
[SZs, CZs] = special.fresnel(Zks.astype(float))
[SYs, CYs] = special.fresnel(Yks.astype(float))
weights = SZs - SYs + 1j * (CYs - CZs)
responses.append(weights * exponentials * factor)
return responses
Expand Down
12 changes: 11 additions & 1 deletion stingray/pulse/tests/test_accelsearch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import pytest
from stingray.pulse.accelsearch import accelsearch
from stingray.pulse.accelsearch import accelsearch, _create_responses
from stingray.utils import HAS_NUMBA

pytestmark = pytest.mark.slow
Expand Down Expand Up @@ -46,6 +46,16 @@ def setup_class(cls):
def test_prepare(self):
pass

@pytest.mark.parametrize("kind", [float, np.longdouble])
def test_create_response_types(self, kind):
z = np.array([-1, 0, 1], dtype=kind)
zint = np.array([-1, 0, 1], dtype=int)

rs = _create_responses(z)
rints = _create_responses(zint)
for r, rint in zip(rs, rints):
assert np.allclose(r, rint)

def test_signal(self):
candidate_table = accelsearch(
self.times,
Expand Down
Loading