Skip to content

Commit

Permalink
Test norm.pdf and update travis for newer python
Browse files Browse the repository at this point in the history
  • Loading branch information
harripd committed Aug 11, 2022
1 parent 7d2975c commit 05a9434
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ dist: xenial
python:
- "3.6"
- "3.7"
- "3.8"
- "3.9"
- "3.10"

services:
- xvfb
Expand All @@ -24,6 +27,7 @@ install:
- conda install --yes phconvert
- pip install pybroom
- python setup.py build
- pip install pybroom
- pip install .
- rm -rf build/

Expand Down
6 changes: 3 additions & 3 deletions fretbursts/burstlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np
import copy
from numpy import zeros, size, r_
import scipy.stats as SS
from scipy.stats import norm

from .utils.misc import pprint, clk_to_s, deprecate
from .poisson_threshold import find_optimal_T_bga
Expand Down Expand Up @@ -2996,7 +2996,7 @@ def fit_E_m(self, E1=-1, E2=2, weights='size', gamma=1.):
np.dot(w, (E[mask] - fit_res[ich, 0])**2)/w.sum())
fit_model_F[ich] = mask.sum()/mask.size

fit_model = lambda x, p: SS.norm.pdf(x, p[0], p[1])
fit_model = lambda x, p: norm.pdf(x, p[0], p[1])
self.add(fit_E_res=fit_res, fit_E_name='Moments',
E_fit=fit_res[:, 0], fit_E_curve=True, fit_E_E1=E1,
fit_E_E2=E2, fit_E_model=fit_model,
Expand Down Expand Up @@ -3091,7 +3091,7 @@ def fit_E_generic(self, E1=-1, E2=2, fit_fun=two_gaussian_fit_hist,
For EM fitting use :meth:`fit_E_two_gauss_EM()`.
"""
if fit_fun.__name__.startswith("gaussian_fit"):
fit_model = lambda x, p: SS.norm.pdf(x, p[0], p[1])
fit_model = lambda x, p: norm.pdf(x, p[0], p[1])
if 'mu0' not in fit_kwargs: fit_kwargs.update(mu0=0.5)
if 'sigma0' not in fit_kwargs: fit_kwargs.update(sigma0=0.3)
iE, nparam = 0, 2
Expand Down
10 changes: 10 additions & 0 deletions fretbursts/tests/test_burstlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from collections import namedtuple
import pytest
import numpy as np
from scipy.stats import norm

try:
import matplotlib
Expand Down Expand Up @@ -78,6 +79,9 @@ def load_fake_pax():
d.burst_search(L=10, m=10, F=6, pax=True)
return d

def normpdf(x, c=0, mu=0.5):
return np.exp(-(x-c)**2/((mu**2)*2))/(mu*np.sqrt(2*np.pi))


@pytest.fixture(scope="module", params=[
load_dataset_1ch,
Expand Down Expand Up @@ -1163,5 +1167,11 @@ def test_collapse(data_8ch):
else:
assert np.allclose(dc1[name][0], dc2[name][0])

def test_norm_pdf():
x = np.arange(0, 1, 0.01)
for c in np.arange(0.1, 1.0, 0.1):
for mu in np.logspace(np.log(5e-2)/np.log(10), np.log(0.5)/np.log(10), 10):
assert np.allclose(normpdf(x, c, mu), norm.pdf(x, loc=c, scale=mu))

if __name__ == '__main__':
pytest.main("-x -v fretbursts/tests/test_burstlib.py")

0 comments on commit 05a9434

Please sign in to comment.