From 8e71d44e024d81f4e7ae6a5445ecda8848c9858f Mon Sep 17 00:00:00 2001 From: Juan Escudero Date: Wed, 13 Dec 2023 18:19:10 +0100 Subject: [PATCH] Fix tests, bump python version to 3.11 (#29) * fix tests * bump python version to 3.11 * fix ci * add tests for bayesian blocks --- .github/workflows/ci.yml | 58 ++++++++++++++++++++++------ docs/recipes/stochastics_tests.ipynb | 4 +- mutis/flares/bayblocks.py | 2 +- mutis/lib/correlation.py | 4 +- mutis/signal.py | 9 ++--- mutis/tests/test_bayblocks.py | 16 ++++++++ setup.py | 2 +- 7 files changed, 72 insertions(+), 23 deletions(-) create mode 100644 mutis/tests/test_bayblocks.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 57fe1f3..afbfe74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,20 +1,42 @@ name: CI -on: [push, pull_request] + +on: + push: + branches: + - main + tags: + - '**' + pull_request: + jobs: + tests: + name: test coverage + + strategy: + matrix: + include: + - python-version: "3.11" + os: ubuntu-latest + + runs-on: ${{ matrix.os }} + defaults: run: shell: bash -l {0} - name: test coverage - runs-on: ubuntu-latest + steps: - - name: checkout repo - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} - name: create and activate env - uses: conda-incubator/setup-miniconda@v2 + uses: conda-incubator/setup-miniconda@v3 with: activate-environment: mutis environment-file: environment.yml + auto-update-conda: true + python-version: ${{ matrix.python-version }} - name: install mutis run: | pip install -e . @@ -22,20 +44,34 @@ jobs: run: | make test-cov codecov -X gcov + docs: + name: docs building + + strategy: + matrix: + include: + - python-version: "3.11" + os: ubuntu-latest + + runs-on: ${{ matrix.os }} + defaults: run: shell: bash -l {0} - name: docs building - runs-on: ubuntu-latest + steps: - - name: checkout repo - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + ref: ${{ github.event.pull_request.head.sha }} - name: create and activate env - uses: conda-incubator/setup-miniconda@v2 + uses: conda-incubator/setup-miniconda@v3 with: activate-environment: mutis environment-file: environment.yml + auto-update-conda: true + python-version: ${{ matrix.python-version }} - name: install mutis run: | pip install -e . diff --git a/docs/recipes/stochastics_tests.ipynb b/docs/recipes/stochastics_tests.ipynb index f5312e8..3d83441 100644 --- a/docs/recipes/stochastics_tests.ipynb +++ b/docs/recipes/stochastics_tests.ipynb @@ -313,9 +313,7 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "fit[0]*sigma_est**2/2" - ] + "source": [] }, { "cell_type": "markdown", diff --git a/mutis/flares/bayblocks.py b/mutis/flares/bayblocks.py index 33e6a6d..95ec956 100644 --- a/mutis/flares/bayblocks.py +++ b/mutis/flares/bayblocks.py @@ -213,7 +213,7 @@ def get_flare_list(self): np.where((np.abs(np.diff(np.asarray(self.inflare, dtype=int))) == 1))[0]+1) # (groups contains the groups of indices of self.inflare/self.values - # that corresond to flares or no flares) + # that correspond to flares or no flares) #print(self.inflare) #print([list(grp) for grp in groups]) diff --git a/mutis/lib/correlation.py b/mutis/lib/correlation.py index f8fad50..ec5a6ce 100644 --- a/mutis/lib/correlation.py +++ b/mutis/lib/correlation.py @@ -267,8 +267,8 @@ def nindcf(t1, s1, t2, s2): """Computes the normalised correlation of two discrete signals (interpolating them).""" dt = np.max([(t1.max() - t1.min()) / t1.size, (t2.max() - t2.min()) / t2.size]) - n1 = np.int(np.ptp(t1) / dt * 10.0) - n2 = np.int(np.ptp(t1) / dt * 10.0) + n1 = int(np.ptp(t1) / dt * 10.0) + n2 = int(np.ptp(t1) / dt * 10.0) s1i = np.interp(np.linspace(t1.min(), t1.max(), n1), t1, s1) s2i = np.interp(np.linspace(t2.min(), t2.max(), n2), t2, s2) return ndcf(s1i, s2i) diff --git a/mutis/signal.py b/mutis/signal.py index 46d8f46..5a3b0d3 100644 --- a/mutis/signal.py +++ b/mutis/signal.py @@ -47,7 +47,6 @@ class Signal: (For OU method) Parameter mu of the OU process. OU_sigma : :class:`float` (For OU method) Parameter sigma of the OU process. - """ def __init__(self, times, values, dvalues=None, fgen=None): @@ -123,7 +122,7 @@ def OU_fit(self, bins=None, rang=None, a=1e-5, b=100): # plot histogram if bins is None: - bins = np.int(y.size ** 0.5 / 1.5) # bins='auto' + bins = int(y.size ** 0.5 / 1.5) # bins='auto' if rang is None: rang = (np.percentile(y, 0), np.percentile(y, 99)) @@ -138,7 +137,7 @@ def OU_fit(self, bins=None, rang=None, a=1e-5, b=100): anchored_text = AnchoredText( f"mean {np.mean(y):.2g} \n " f"median {np.median(y):.2g} \n " - f"mode {scipy_stats.mode(y)[0][0]:.2g} \n " + f"mode {scipy_stats.mode(y)[0]:.2g} \n " f"std {np.std(y):.2g} \n " f"var {np.var(y):.2g}", loc="upper right", @@ -242,12 +241,12 @@ def check_gen(self, fgen=None, fgen_params=None, fpsd="lombscargle", **axes): axes["ax1"].set_title("light curves") # plot their histogram - bins = "auto" # bins = np.int(y.size**0.5/1.5) # + bins = "auto" # bins = int(y.size**0.5/1.5) # rang = (np.percentile(y, 0), np.percentile(y, 99)) axes["ax2"].hist(y, density=True, color="b", alpha=0.4, bins=bins, range=rang) # ax2p = ax2.twinx() - bins = "auto" # bins = np.int(y.size**0.5/1.5) # + bins = "auto" # bins = int(y.size**0.5/1.5) # rang = (np.percentile(y2, 0), np.percentile(y2, 99)) axes["ax2"].hist(y2, density=True, color="r", alpha=0.4, bins=bins, range=rang) diff --git a/mutis/tests/test_bayblocks.py b/mutis/tests/test_bayblocks.py new file mode 100644 index 0000000..f96c4c1 --- /dev/null +++ b/mutis/tests/test_bayblocks.py @@ -0,0 +1,16 @@ +import unittest +import numpy as np +from mutis.flares.bayblocks import BayesianBlocks +from mutis import Signal + +def test_bayblocks(): + # test the bayblock algorithm with a signal that corresponds to 3 gaussian pulses in a row + t = np.linspace(0, 6, 50) + y = np.exp(-(t-1)**2/0.1) + np.exp(-(t-3)**2/0.1) + np.exp(-(t-5)**2/0.1) + dy = 0.1 * np.abs(y) + signal = Signal(t, y, dy) + bayblocks = BayesianBlocks(signal, p=1e-1) + bayblocks.get_flares() + bayblocks.signal.plot() + bayblocks.plot() + assert len(bayblocks.get_flare_list()) == 3 \ No newline at end of file diff --git a/setup.py b/setup.py index 2d00dbd..f173a33 100644 --- a/setup.py +++ b/setup.py @@ -18,5 +18,5 @@ "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", ], - python_requires='>=3.7', + python_requires='>=3.11', ) \ No newline at end of file