Skip to content
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
Binary file modified .DS_Store
Binary file not shown.
25 changes: 18 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@ concurrency:
cancel-in-progress: true

env:
# circStudio requires Python 3.12 (pyproject: requires-python = ">=3.12").
PYTHON_VERSION: "3.12"
# Keep every test headless; conftest.py also sets this, belt and braces.
MPLBACKEND: Agg

jobs:
unit:
name: library tests
runs-on: ubuntu-latest
timeout-minutes: 20
name: library tests (${{ matrix.os }}, Python ${{ matrix.python-version }})
runs-on: ${{ matrix.os }}
timeout-minutes: 30
strategy:
# Run every combination even if one fails, so a platform-specific
# failure does not hide the others.
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
# circStudio requires Python 3.12 or later (pyproject: requires-python = ">=3.12").
python-version: ["3.12", "3.13", "3.14"]
defaults:
run:
# Use bash on every runner, including Windows, so the multi-line
# commands below behave the same everywhere.
shell: bash

steps:
- uses: actions/checkout@v4
Expand All @@ -31,11 +42,11 @@ jobs:
cache-dependency-glob: pyproject.toml

- name: Set up Python
run: uv python install ${{ env.PYTHON_VERSION }}
run: uv python install ${{ matrix.python-version }}

- name: Create the environment
run: |
uv venv --python ${{ env.PYTHON_VERSION }}
uv venv --python ${{ matrix.python-version }}
# Library runtime dependencies, pinned to the ranges in pyproject.
uv pip install \
'pandas>=2.3.3,<3' 'numpy>=2.4.1,<3' 'scipy>=1.17.0,<2' \
Expand Down
26 changes: 26 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
cff-version: 1.2.0
message: "If you use circStudio, please cite it using the metadata below."
title: "circStudio: a Python package for actigraphy data analysis and mathematical models of circadian rhythms"
type: software
authors:
- family-names: Marques
given-names: Daniel
email: daniel.marques@gimm.pt
affiliation: "GIMM - Gulbenkian Institute for Molecular Medicine, Lisbon, Portugal"
# TODO: add orcid: "https://orcid.org/0000-0000-0000-0000"
- family-names: Morais
given-names: Nuno
affiliation: "GIMM - Gulbenkian Institute for Molecular Medicine, Lisbon, Portugal"
- family-names: Reis
given-names: Cátia
affiliation: "Faculdade de Medicina, Universidade de Lisboa, Lisbon, Portugal"
version: 1.1.3
license: GPL-3.0-only
repository-code: "https://github.com/DiseaseTranscriptomicsLab/circStudio"
url: "https://DiseaseTranscriptomicsLab.github.io/circStudio/"
keywords:
- actigraphy
- circadian rhythms
- sleep
- mathematical modeling
- chronobiology
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ representative at an online or offline event.

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
[INSERT CONTACT METHOD].
daniel.marques@gimm.pt.
All complaints will be reviewed and investigated promptly and fairly.

All community leaders are obligated to respect the privacy and security of the
Expand Down
58 changes: 58 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Contributing to circStudio

Thank you for your interest in circStudio. This page explains how to ask for
help, report a problem and propose a change. Everyone taking part is expected to
follow the [Code of Conduct](CODE_OF_CONDUCT.md).

## Getting help

- Read the [documentation](https://DiseaseTranscriptomicsLab.github.io/circStudio/),
which includes four tutorial notebooks and a full reference for every function.
- If your question is not answered there, open an issue on the
[GitHub issue tracker](https://github.com/DiseaseTranscriptomicsLab/circStudio/issues)
and label it `question`. Questions asked in public help the next user too.

## Reporting a bug

Open an issue on the [issue tracker](https://github.com/DiseaseTranscriptomicsLab/circStudio/issues)
and include:

1. the circStudio version (`python -c "import importlib.metadata as m; print(m.version('circStudio'))"`),
your Python version and your operating system;
2. the smallest piece of code that shows the problem, ideally using one of the
example recordings in `src/circstudio/data` so that others can run it;
3. what you expected to happen and what happened instead, including the full
error message.

If the problem only occurs with your own recordings and you cannot share them,
say which device and file format they come from.

## Proposing a change

Small fixes (typos, documentation, clearly scoped bugs) are welcome as pull
requests directly. For a new feature or a change in behavior, please open an
issue first so the change can be discussed before you invest time in it.

1. Fork the repository and create a branch from `main`.
2. Install the package in editable mode with the test dependencies:

```bash
python -m venv .venv && source .venv/bin/activate
pip install -e . pytest pytest-mock pyexcel-ods
```

3. Make your change and add or update tests in `tests/`. New analysis functions
should be tested against values that can be derived independently (for
example, on synthetic signals with known properties), and new algorithms
should cite the publication that defines them in their docstring.
4. Run the test suite and make sure it passes:

```bash
pytest tests -q
```

5. Open a pull request describing what the change does and why. The test suite
runs automatically on Linux, macOS and Windows for every pull request.

By contributing, you agree that your contribution is released under the
project's license, the [GNU General Public License v3.0](LICENSE.md).
7 changes: 7 additions & 0 deletions paper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Intermediate files written by the pyActigraphy reference scripts
scripts/pyact_metrics.json
scripts/pyact_sleep.pkl
scripts/pyact_profile_dfa.pkl
# Local virtual environments
.venv/
.venv-pyact/
126 changes: 126 additions & 0 deletions paper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Reproducing the circStudio manuscript

This folder contains the code that produces every figure and every agreement
analysis reported in the GigaByte Technical Release describing circStudio
(version 1.1.3).

```
paper/
├── scripts/ code for the figures and the agreement analyses
├── figures/ the figures, as PDF (for the manuscript) and PNG (for viewing)
└── results/ expected outputs of the agreement analyses, as CSV
```

All commands below are run from this `paper/` folder. The scripts import
circStudio from `../src` and read the example recordings bundled with the
package in `../src/circstudio/data`.

## 1. Environment

```bash
python -m venv .venv && source .venv/bin/activate
pip install -e .. # circStudio 1.1.3 and its dependencies
pip install circadian==1.0.3 # only for the model comparison (section 4)
```

## 2. Figures

```bash
python scripts/figure1_architecture.py # Figure 1, architecture of circStudio
python scripts/figure2_analysis.py # Figure 2, descriptive analysis
python scripts/figure_pacemaker_schematic.py # Figure 3, structure of the pacemaker models
python scripts/figure3_models.py # Figure 4, circadian models
```

Each script writes a PDF and a 220 dpi PNG into `figures/`. Figure 1 and the
schematic part of Figure 3 take no input data. Figure 2 reads `example_01.AWD`.
Figure 4 builds two synthetic light schedules with the `Light` container and,
in panel (d), reads the ActTrust recording `test_sample_atr.txt`, whose light
channel drives the Forger model.

`Light.create` draws its light-on intensities from an unseeded random
generator, so `figure3_models.py` pins the generator for the two calls that
build the schedules. Without this, the predicted onsets in panels (b) and (c)
could move by one sampling bin (10 minutes) between runs.

## 3. Agreement with pyActigraphy (Table 3)

circStudio requires NumPy 2 and pandas 2, while pyActigraphy 1.2.2 requires
NumPy 1 and pandas 1. They cannot be installed in the same environment, so each
comparison runs in two steps: a pyActigraphy script writes its results to a file
next to itself, and the matching circStudio script reads that file.

```bash
# Step 1: reference values, in a separate pyActigraphy environment (Python 3.10)
python3.10 -m venv .venv-pyact
./.venv-pyact/bin/pip install pyActigraphy==1.2.2 'numpy==1.23.5'
./.venv-pyact/bin/python scripts/compare_metrics_pyactigraphy.py # -> scripts/pyact_metrics.json
./.venv-pyact/bin/python scripts/compare_sleep_pyactigraphy.py # -> scripts/pyact_sleep.pkl
./.venv-pyact/bin/python scripts/compare_profile_dfa_pyactigraphy.py # -> scripts/pyact_profile_dfa.pkl

# Step 2: circStudio values and the comparison, in the circStudio environment
python scripts/compare_metrics_circstudio.py # -> results/agreement_metrics.csv
python scripts/compare_sleep_circstudio.py # -> results/agreement_sleep_scoring.csv
python scripts/compare_profile_dfa_circstudio.py # -> results/agreement_profile_midpoint_dfa.csv
```

pyActigraphy 1.2.2 pins NumPy 1.21, which its own dependency numba rejects;
installing NumPy 1.23.5 afterwards resolves this (pip reports the pin as a
conflict, which can be ignored for these scripts).

The intermediate files written in step 1 are not tracked in the repository;
the CSV files in `results/` contain both packages' values side by side and are
the expected outputs.

| Comparison | Recordings | Result |
|---|---|---|
| Interdaily stability, intradaily variability, L5, M10, relative amplitude, average daily total activity | 5 | identical (30 of 30 values) |
| Cole-Kripke, Sadeh, Scripps, Oakley, Roenneberg | 5 | identical on all 111,272 epochs |
| Crespo | 5 | identical after inverting the rest/activity label |
| Sleep propensity profile | 5 | maximum absolute difference 0 |
| Sleep midpoint | 5 | identical |
| Detrended fluctuation analysis, F(n) and scaling exponent | 5 | maximum relative difference 3.1 × 10⁻¹⁵ (F(n)); maximum absolute difference 5.6 × 10⁻¹⁶ (exponent) |

## 4. Agreement with the `circadian` package

```bash
python scripts/compare_models_circadian.py # -> results/models_vs_circadian.csv
```

The Forger, Jewett, both Hannay and the Breslow models are driven with
identical light, time grid and initial state in circStudio and in `circadian`
1.0.3, using a regular schedule (16 h at 1000 lux, 8 h dark, 30 days) and the
light channel of the ActTrust example recording. All predicted dim-light
melatonin onsets fall on the same sample in both packages, and the oscillator
states differ by at most 10⁻³. The two packages integrate differently (SciPy's
`odeint` in circStudio, fixed-step fourth-order Runge-Kutta in `circadian`),
which accounts for the small differences in state.

For the Breslow model, the melatonin compartments differ by up to 0.68. After
bright light, `circadian`'s fixed-step scheme lets pineal melatonin overshoot
below zero (to -0.68 on the regular schedule), which the model's guard against
negative production is meant to prevent; circStudio keeps it at zero or above.
On the real recording, `circadian` also reports extra, closely spaced
temperature minima for this model because it imposes no minimum spacing
between them; each circStudio onset is matched to the nearest one.

The St Hilaire and Skeldon models, which include sleep-wake dynamics, are not
part of this comparison.

## 5. Test suite

```bash
pip install pytest pytest-mock pyexcel-ods
pytest ../tests -q
```

The suite runs automatically through GitHub Actions on Linux, macOS and Windows
with Python 3.12, 3.13 and 3.14.

## Versions used for the results reported in the manuscript

| Environment | Versions |
|---|---|
| circStudio | circStudio 1.1.3, Python 3.13.18, NumPy 2.5.5, pandas 2.3.3, SciPy 1.18.1, matplotlib 3.11.2 |
| circadian comparison | as above, plus circadian 1.0.3 |
| pyActigraphy reference | pyActigraphy 1.2.2, Python 3.10.12, NumPy 1.23.5, pandas 1.3.5 |
Binary file added paper/figures/fig1_architecture.pdf
Binary file not shown.
Binary file added paper/figures/fig1_architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paper/figures/fig2_analysis.pdf
Binary file not shown.
Binary file added paper/figures/fig2_analysis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paper/figures/fig3_models.pdf
Binary file not shown.
Binary file added paper/figures/fig3_models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paper/figures/fig_pacemaker_schematic.pdf
Binary file not shown.
Binary file added paper/figures/fig_pacemaker_schematic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions paper/results/agreement_metrics.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
recording,metric,circstudio,pyactigraphy,identical,relative_difference
example_01,IS,0.527656245354158,0.527656245354158,True,0.0
example_01,IV,0.32913524895082263,0.32913524895082263,True,0.0
example_01,L5,0.10512820512820513,0.10512820512820513,True,0.0
example_01,M10,0.7624465811965813,0.7624465811965813,True,0.0
example_01,RA,0.7576503909857768,0.7576503909857768,True,0.0
example_01,ADAT,656.4007409927273,656.4007409927273,True,0.0
example_02,IS,0.5237758757150337,0.5237758757150337,True,0.0
example_02,IV,0.28892307810751544,0.28892307810751544,True,0.0
example_02,L5,0.08897435897435897,0.08897435897435897,True,0.0
example_02,M10,0.8044764957264957,0.8044764957264957,True,0.0
example_02,RA,0.8008298755186721,0.8008298755186721,True,0.0
example_02,ADAT,685.2122448979592,685.2122448979592,True,0.0
example_03,IS,0.3720781873681576,0.3720781873681576,True,0.0
example_03,IV,0.22572327571081752,0.22572327571081752,True,0.0
example_03,L5,0.11755555555555555,0.11755555555555555,True,0.0
example_03,M10,0.7228174603174603,0.7228174603174603,True,0.0
example_03,RA,0.7202300565697395,0.7202300565697395,True,0.0
example_03,ADAT,686.0828336963789,686.0828336963789,True,0.0
example_04,IS,0.2551624866267735,0.2551624866267735,True,0.0
example_04,IV,0.21317483858015063,0.21317483858015063,True,0.0
example_04,L5,0.043181818181818175,0.043181818181818175,True,0.0
example_04,M10,0.5207683982683982,0.5207683982683982,True,0.0
example_04,RA,0.84685946765434,0.84685946765434,True,0.0
example_04,ADAT,497.0130621384587,497.0130621384587,True,0.0
example_05,IS,0.6595438549841431,0.6595438549841431,True,0.0
example_05,IV,0.38058912302569026,0.38058912302569026,True,0.0
example_05,L5,0.06888888888888889,0.06888888888888889,True,0.0
example_05,M10,0.7826319444444444,0.7826319444444444,True,0.0
example_05,RA,0.8381979954166973,0.8381979954166973,True,0.0
example_05,ADAT,662.3063473461364,662.3063473461364,True,0.0
6 changes: 6 additions & 0 deletions paper/results/agreement_profile_midpoint_dfa.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
recording,profile_bins_compared,profile_max_abs_difference,midpoint_circstudio_min,midpoint_pyactigraphy_min,midpoint_abs_difference_ns,alpha_circstudio,alpha_pyactigraphy,alpha_abs_difference,F_n_max_relative_difference
example_01,96,0.0,183.3690115438114,183.3690115438114,0.0,0.9760250750347922,0.9760250750347927,5.551115123125783e-16,1.400644198333589e-15
example_02,96,0.0,173.34283674156742,173.34283674156742,0.0,1.0418290088953666,1.0418290088953668,2.220446049250313e-16,2.4621839871324174e-15
example_03,96,0.0,222.13144128232918,222.13144128232918,0.0,1.0232943774893948,1.023294377489395,2.220446049250313e-16,2.7018568377068637e-15
example_04,96,0.0,199.65630140947243,199.65630140947243,0.0,0.9997831779844136,0.9997831779844142,5.551115123125783e-16,3.1178145745398125e-15
example_05,96,0.0,246.00890843207017,246.00890843207017,0.0,1.004375856738435,1.0043758567384355,4.440892098500626e-16,1.08300124038312e-15
31 changes: 31 additions & 0 deletions paper/results/agreement_sleep_scoring.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
recording,algorithm,epochs,agreement_direct,agreement_inverted
example_01,CK,18401,1.0,0.0
example_01,Sadeh,18401,1.0,0.0
example_01,Scripps,18401,1.0,0.0
example_01,Oakley,18401,1.0,0.0
example_01,Roenneberg,18401,1.0,0.0
example_01,Crespo,18401,0.0,1.0
example_02,CK,18413,1.0,0.0
example_02,Sadeh,18413,1.0,0.0
example_02,Scripps,18413,1.0,0.0
example_02,Oakley,18413,1.0,0.0
example_02,Roenneberg,18413,1.0,0.0
example_02,Crespo,18413,0.0,1.0
example_03,CK,21456,1.0,0.0
example_03,Sadeh,21456,1.0,0.0
example_03,Scripps,21456,1.0,0.0
example_03,Oakley,21456,1.0,0.0
example_03,Roenneberg,21456,1.0,0.0
example_03,Crespo,21456,0.0,1.0
example_04,CK,31299,1.0,0.0
example_04,Sadeh,31299,1.0,0.0
example_04,Scripps,31299,1.0,0.0
example_04,Oakley,31299,1.0,0.0
example_04,Roenneberg,31299,1.0,0.0
example_04,Crespo,31299,0.0,1.0
example_05,CK,21703,1.0,0.0
example_05,Sadeh,21703,1.0,0.0
example_05,Scripps,21703,1.0,0.0
example_05,Oakley,21703,1.0,0.0
example_05,Roenneberg,21703,1.0,0.0
example_05,Crespo,21703,0.0,1.0
11 changes: 11 additions & 0 deletions paper/results/models_vs_circadian.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
input,model,dlmo_circstudio,dlmo_circadian,max_abs_dlmo_difference_min,sampling_interval_min,max_abs_difference_oscillator_states,max_abs_difference_melatonin,min_pineal_melatonin_circadian
"regular 16 h light : 8 h dark, 30 days",Forger (1999),30,30,0.0,6.000000000000512,9.667881538666379e-07,,
"regular 16 h light : 8 h dark, 30 days",Jewett (1999),30,30,0.0,6.000000000000512,3.487367374266359e-05,,
"regular 16 h light : 8 h dark, 30 days",Hannay single population (2019),30,30,0.0,6.000000000000512,1.8524140418696433e-05,,
"regular 16 h light : 8 h dark, 30 days",Hannay two populations (2019),30,30,0.0,6.000000000000512,1.8524140418696433e-05,,
"regular 16 h light : 8 h dark, 30 days",Breslow (2013),30,30,0.0,6.000000000000512,6.569857560534409e-06,0.6828722952434629,-0.6822102462220864
"ActTrust example recording, 4 days",Forger (1999),4,4,0.0,0.9999999999999432,0.00033173120059148964,,
"ActTrust example recording, 4 days",Jewett (1999),4,4,0.0,0.9999999999999432,0.000980505659026798,,
"ActTrust example recording, 4 days",Hannay single population (2019),4,4,0.0,0.9999999999999432,2.9947960060942858e-05,,
"ActTrust example recording, 4 days",Hannay two populations (2019),4,4,0.0,0.9999999999999432,0.00013677107390046989,,
"ActTrust example recording, 4 days",Breslow (2013),4,17,0.0,0.9999999999999432,2.863085776938501e-05,0.06426242752543876,-0.06331185555655094
Loading
Loading