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 tests, bump python version to 3.11 #29

Merged
merged 13 commits into from
Dec 13, 2023
Merged
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
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 @@ -113,7 +112,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 @@ -128,7 +127,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 @@ -232,12 +231,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',
)