Skip to content

Commit

Permalink
Fix tests, bump python version to 3.11 (#29)
Browse files Browse the repository at this point in the history
* fix tests 

* bump python version to 3.11

* fix ci

* add tests for bayesian blocks
  • Loading branch information
juanep97 authored Dec 13, 2023
1 parent bb43d64 commit 8e71d44
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 23 deletions.
58 changes: 47 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,77 @@
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 .
- name: test coverage
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 .
Expand Down
4 changes: 1 addition & 3 deletions docs/recipes/stochastics_tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fit[0]*sigma_est**2/2"
]
"source": []
},
{
"cell_type": "markdown",
Expand Down
2 changes: 1 addition & 1 deletion mutis/flares/bayblocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions mutis/lib/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions mutis/signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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))

Expand All @@ -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",
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions mutis/tests/test_bayblocks.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
"License :: OSI Approved :: BSD License",
"Operating System :: OS Independent",
],
python_requires='>=3.7',
python_requires='>=3.11',
)

0 comments on commit 8e71d44

Please sign in to comment.