Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ac86658
Rewrite the README from the top down and link to the documentation
micahgallen Nov 4, 2026
9146fac
Describe each task's strengths and limits rather than recommending one
micahgallen Nov 4, 2026
549829a
Move the documentation pages into getting-started, tasks and referenc…
micahgallen Nov 4, 2026
080f3f6
Split the theory page between the tasks overview and the HRD
micahgallen Nov 4, 2026
b60ba74
Add a changelog page that includes CHANGELOG.md
micahgallen Nov 4, 2026
6b353f9
Dissolve the user guide into task and getting-started pages
micahgallen Nov 4, 2026
285eb11
Point the PAT hardware list to Recording devices for the PLUX hub
micahgallen Nov 4, 2026
5670460
Add placeholder pages for the Whitehead method and the method of cons…
micahgallen Nov 4, 2026
15b83cd
Cut the home page down to a landing page
micahgallen Nov 4, 2026
d4d8bb4
Call the PAT and HSD beta rather than experimental
micahgallen Nov 4, 2026
fc90da2
Correct stimulus ranges, the HSD ceiling and setup="test" against the…
micahgallen Nov 4, 2026
ac15d95
Write the Phase Adjustment Task as a proper name throughout the docs
micahgallen Nov 4, 2026
93a9e92
Use US -yze and -ize spelling in the theory text and the tutorials index
micahgallen Nov 4, 2026
544b63c
Redirect the old page URLs to their new locations
micahgallen Nov 4, 2026
a09b2c8
Point the README, changelog and workshop links at the new page locations
micahgallen Nov 4, 2026
6340e33
Correct the citation year, copyright line, report notebooks, unused-t…
micahgallen Nov 4, 2026
83085b6
Add trial-sequence figures for the PAT and HSD, made from screenshots…
micahgallen Nov 5, 2026
4da7feb
Make the HRD page a single page that describes the task and how to ru…
micahgallen Nov 5, 2026
fff9459
Make the HSD page a single page that describes the task and how to ru…
micahgallen Nov 5, 2026
b2719aa
Fill out the Heartbeat Counting page with the trial, the settings, th…
micahgallen Nov 5, 2026
72cef1e
Reorder the Phase Adjustment Task page to the shared task layout and …
micahgallen Nov 5, 2026
4b770fb
Reduce the tasks overview to the comparison, the strengths and limita…
micahgallen Nov 5, 2026
7f1cda2
Redirect the removed Running the HRD and Running the HSD pages to the…
micahgallen Nov 5, 2026
033c4ae
Rewrite the home page around the all-in-one toolbox framing
micahgallen Nov 5, 2026
1461921
Shorten the installation guide and move the device material to Record…
micahgallen Nov 5, 2026
86d1a83
Rewrite Recording devices as the one home for the oximeter, LSL and P…
micahgallen Nov 5, 2026
11a233b
Give Running a session the material shared by every task
micahgallen Nov 5, 2026
7b305e4
List the task pages in the sidebar and use one task order
micahgallen Nov 5, 2026
f989a07
Rejoin the theory into one page, Measuring cardiac interoception
micahgallen Nov 5, 2026
381bdc5
Correct three HSD statements and give the design page its own title
micahgallen Nov 5, 2026
dd1886d
Move the neutral PAT and HSD comparison to the tasks overview
micahgallen Nov 5, 2026
66c01d3
Fill the gaps on the HRD page and add its test-retest reliability
micahgallen Nov 5, 2026
b7b1dfb
Correct typos, defaults and types in the HRD getParameters docstring
micahgallen Nov 5, 2026
cb836d0
Name and cite the tutorials' example data
micahgallen Nov 5, 2026
10a374c
Make the first installation success hardware-free and state the legac…
micahgallen Nov 5, 2026
0848093
List all five device-check verdicts and add two device notes
micahgallen Nov 5, 2026
2c25ebc
Link the wrapper files and add a pre-session checklist to Running a s…
micahgallen Nov 5, 2026
268f23f
Complete the cite page
micahgallen Nov 5, 2026
e6a8331
Tidy the API page and keep its generated entries out of the sidebar
micahgallen Nov 5, 2026
35fb671
Make the PAT autopilot example self-contained
micahgallen Nov 5, 2026
62124dd
Say that the legacy reports do not read 1.0 run folders, and list wha…
micahgallen Nov 5, 2026
cdf59a5
Point the tasks overview to Running a session for the output layout
micahgallen Nov 5, 2026
eedbb7c
Describe Running a session in the README as it now is
micahgallen Nov 5, 2026
c16be63
Bring the stale lines of AGENTS.md up to date
micahgallen Nov 5, 2026
3961111
Add a contributing guide and link it from the README
micahgallen Nov 5, 2026
614c6aa
Point the documentation's repository links at main
micahgallen Nov 5, 2026
cbb8e9d
Give the catch-trial differences in the getParameters docstring as th…
micahgallen Nov 5, 2026
f30ca71
Replace the HRD paper figure with one drawn from the task's own scree…
micahgallen Nov 5, 2026
05212f8
Add psiPreset to the HRD config, with the original paper's settings a…
micahgallen Nov 5, 2026
6b159a0
Deploy the released docs from main and the development docs from dev …
micahgallen Nov 5, 2026
b67a8a8
Point the tutorials link at main and spell PLUX consistently
micahgallen Nov 5, 2026
5d7a1ee
Describe the four tasks of 1.0 in the citation and Zenodo metadata
micahgallen Nov 5, 2026
89acdaa
Fix the bibliography's malformed DOI and arXiv links and update redir…
micahgallen Nov 5, 2026
2482e0a
Say on the dev branch and in the dev docs that 1.0 is not on PyPI yet…
micahgallen Nov 5, 2026
56cab9c
Format repository settings
micahgallen Nov 5, 2026
dff50a2
Read the installation page from its new location in the install check
micahgallen Nov 5, 2026
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
10 changes: 5 additions & 5 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"attribution": {
"commit": "",
"pr": "",
"sessionUrl": false
}
"attribution": {
"commit": "",
"pr": "",
"sessionUrl": false
}
}
62 changes: 45 additions & 17 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
name: Build and Deploy

# Two sites from one gh-pages branch:
#
# main -> https://www.the-ecg.org/Cardioception/ the released version
# dev -> https://www.the-ecg.org/Cardioception/dev/ the development version
#
# Pull requests build but never deploy, so no PR can replace live documentation
# before review. master holds 0.7.2 and no longer deploys: a push there would
# replace the released 1.0 docs with 0.7 ones.

on:
push:
branches:
- master
- main
- dev
pull_request:
branches:
- master
- main
- dev
permissions:
contents: write

# A push to main and a push to dev both write to gh-pages. Run deploys one at a
# time so the second does not fail on a stale branch head; never cancel one
# halfway through.
concurrency:
group: docs-deploy
cancel-in-progress: false

jobs:
build-and-deploy:
runs-on: ubuntu-latest
env:
# Read by conf.py: "dev" adds the development banner, marks every page
# noindex and points canonical URLs at /dev/.
DOCS_CHANNEL: ${{ (github.ref == 'refs/heads/dev' || github.base_ref == 'dev') && 'dev' || 'stable' }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip
Expand All @@ -35,20 +53,30 @@ jobs:
pip install --no-deps -e .
pip install -r requirements-docs.txt

# -W turns warnings into errors, so a broken cross-reference or a missing
# page fails the build instead of shipping. --keep-going reports all of
# them in one run.
- name: Build documentation
run: |
sphinx-build -b html docs/source docs/build/html

# Build on every push and pull request to master or dev, publish only
# from a push to master. Without this guard a pull request deployed
# straight to gh-pages, so any PR could replace the live documentation
# before anyone reviewed it, and a push to dev would publish unreleased
# documentation. `main` exists and is built, but the site still deploys
# from master until the 1.0.0 release: on release day, change the ref
# below to refs/heads/main.
- name: Deploy 🚀
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
sphinx-build -W --keep-going -b html docs/source docs/build/html

# The root deploy cleans out files the new build no longer has, which
# would include the whole dev/ folder. clean-exclude keeps it, and the
# CNAME that serves the site at www.the-ecg.org.
- name: Deploy the released docs
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs/build/html
branch: gh-pages
clean-exclude: |
dev
CNAME

- name: Deploy the development docs
if: github.event_name == 'push' && github.ref == 'refs/heads/dev'
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: docs/build/html
BRANCH: gh-pages
branch: gh-pages
target-folder: dev
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
# `dev` matches none of "dev/**" -- that pattern wants a slash -- so when
# dev became the working branch the suite silently stopped running on the
# only branch doing any work. Named explicitly.
branches: [master, main, dev, "dev/**", "phase*/**"]
branches: [main, dev, "dev/**", "phase*/**"]
pull_request:
workflow_dispatch:

Expand Down
7 changes: 5 additions & 2 deletions .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"upload_type": "software",
"title": "Cardioception Toolbox: measuring cardiac interoception in PsychoPy",
"description": "<p>Cardioception measures cardiac interoception in PsychoPy. It implements the Heart Rate Discrimination task, a psychophysical method that separates the bias in what people believe their heart rate to be from the precision with which they can discriminate it, together with the older Heartbeat Counting task.</p><p>The tasks run with minimal equipment, a computer and a device that reads the participant's pulse, and slot into richer setups (ECG, M/EEG, fMRI). This is the official release from the Embodied Computation Group at Aarhus University.</p>",
"description": "<p>Cardioception is an open-source Python toolbox for studying how people perceive their own heartbeat. Built on PsychoPy, it brings the most widely used methods for measuring cardiac interoception together under one installation and one output layout: the Heart Rate Discrimination task, the Heartbeat Counting task, the Phase Adjustment Task and the Heartbeat Synchrony Discrimination task. The pulse is recorded from a USB pulse oximeter, or from ECG and PPG devices over Lab Streaming Layer.</p><p>This is the official release from the Embodied Computation Group at Aarhus University.</p>",
"license": "apache-2.0",
"access_right": "open",
"creators": [
Expand All @@ -23,7 +23,10 @@
"heartbeat counting",
"psychophysics",
"metacognition",
"psychopy"
"psychopy",
"heartbeat synchrony",
"phase adjustment task",
"lab streaming layer"
],
"related_identifiers": [
{
Expand Down
38 changes: 25 additions & 13 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,44 @@ it useful too, but the audience is agents.

## What this project is

Cardioception is a Python package that runs two psychophysical tasks in PsychoPy:
Cardioception is a Python package that runs four psychophysical tasks in PsychoPy:

- **Heart Rate Discrimination task (HRD)** — the primary task. Participants judge
- **Heart Rate Discrimination task (HRD)**, established. Participants judge
whether tones are faster or slower than their own heart, under an adaptive staircase.
- **Heartbeat Counting task (HBC)** — the classic counting task, kept because the
literature rests on it. Not recommended for new studies.
- **Heartbeat Counting task (HBC)**, established. The classic counting task, kept
because the literature rests on it.
- **Phase Adjustment Task (PAT)**, beta. Participants turn a dial until tones
timed from each R-wave feel synchronous with their heartbeat. Needs an ECG over LSL.
- **Heartbeat Synchrony Discrimination task (HSD)**, beta. Participants judge
whether tones at a delay chosen by Bayesian adaptive placement are synchronous
with their heartbeat. Needs an ECG over LSL.

The docs describe each task's strengths and limits and do not tell readers which
task to use; keep it that way.

The package **collects** data. It does not analyse it. Modelling happens in R with the
[Hierarchical Interoception toolbox](https://github.com/embodied-computation-group/Hierarchical-Interoception).

## Naming, and a trap
## Naming

| Thing | Value |
|---|---|
| PyPI distribution | `cardioception-toolbox` |
| Python import name | `cardioception` |

These differ deliberately. `pip install cardioception` installs a **different,
third-party package**. Any instruction, script, environment file or doc that says
`pip install cardioception` is a bug. Never "fix" `cardioception-toolbox` back to
`cardioception` in an install command.
These differ deliberately. The install name is `cardioception-toolbox`. An
install command, script, environment file or doc that installs under any other
name is a bug. Never change `cardioception-toolbox` in an install command.

## Layout

```
cardioception/
HRD/ the Heart Rate Discrimination task (parameters.py, task.py)
HBC/ the Heartbeat Counting task
PAT/ the Phase Adjustment Task (beta)
HSD/ the Heartbeat Synchrony Discrimination task (beta)
devices/ recorders, and the beat source and tone player the PAT and HSD share
notebooks/ report templates executed by reports.report()
reports.py preprocessing and HTML reports (legacy, due to be rebuilt)
_resources.py locates bundled images and sounds
Expand All @@ -52,8 +62,8 @@ tests/
- Python is formatted with black, imports sorted with isort, and checked with flake8
and mypy, on **Python 3.11**. The package supports **3.10 and 3.11**: the upper
bound is `pywinhook`, which ships wheels only to cp311, not PsychoPy, which
allows 3.12. Note that CI runs `black` and `isort` *before* `flake8`, so
formatting findings are reformatted away rather than reported.
allows 3.12. CI runs `black --check` and `isort --check` before `flake8`, so
a formatting finding fails the build.
- Use `cardioception._resources.resource_filename` rather than
`importlib.resources.files` for shipped data files. Not for version reasons any
more, just so there is one way of doing it.
Expand Down Expand Up @@ -93,8 +103,10 @@ Two rules worth stating here because they are the most common errors:

## Before you commit

- Docs changes: the build runs on every push to `master` and deploys to
<https://www.the-ecg.org/Cardioception/>. It takes about a minute. Check the run.
- Docs changes: the build runs with `-W`, so a warning fails it. A push to `main`
deploys to <https://www.the-ecg.org/Cardioception/>, a push to `dev` to
<https://www.the-ecg.org/Cardioception/dev/> (with a development banner and
`noindex`). It takes about a minute. Check the run.
- Do not commit large fitted model objects. Cache them locally with brms `file =`.
- Participant-level data with demographics is sensitive. Do not move it from a private
repository into this public one without an explicit instruction that acknowledges the
Expand Down
33 changes: 22 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

1.0.0 is the first release of the rewritten package. It runs four tasks under
one output layout: the Heart Rate Discrimination and Heartbeat Counting tasks,
and the experimental Heartbeat Synchrony Discrimination and Phase Adjustment
tasks. It changes the output schema and the output layout, so analysis scripts
and the Heartbeat Synchrony Discrimination and Phase Adjustment tasks, both
in beta. It changes the output schema and the output layout, so analysis scripts
written against 0.7.x need the migration notes under Breaking below. The 0.7
line stays installable from the `legacy/0.7` branch and the `v0.7.2` tag.

Expand Down Expand Up @@ -56,6 +56,15 @@ varies. Set `onMissedTrial="skip"` for a fixed number of presentations.

### Added

- `TaskConfig(psiPreset=...)` for the Heart Rate Discrimination task.
- `"legacy"`, the default, keeps the Psi settings of the original paper.
- `"courtin"` uses the per-condition threshold and slope ranges and the
0.01 lapse rate from the hierarchical refit of the Visceral Mind Project
data (Courtin et al., 2026).
- `intensRange`, `alphaRange`, `betaRange` and `delta` still override the
preset, in both conditions.
- The settings each staircase used are written to `manifest.json` under
`config.psi`.
- German instructions for the Heart Rate Discrimination task, `language="german"`,
addressing the participant formally. The texts shipped in 0.7.2 as a Python
function and move here to `HRD/texts/german.yaml`, checked against that
Expand Down Expand Up @@ -99,14 +108,14 @@ varies. Set `onMissedTrial="skip"` for a fixed number of presentations.
they are `HBC/texts/english.yaml` and `german.yaml`, checked against those
functions by a snapshot test, and an unknown language fails before a window
opens. The German confidence scale reads "Geraten" to "Sicher".
- `cardioception.HSD.psi.SynchronyPsi`, the estimation engine for an
experimental Heartbeat Synchrony Discrimination task: an adaptive Bayesian
- `cardioception.HSD.psi.SynchronyPsi`, the estimation engine for the
Heartbeat Synchrony Discrimination task: an adaptive Bayesian
version of the Brener, Liu and Ring method of constant stimuli that chooses
each R-wave-to-tone delay by expected information gain and estimates where
in the cardiac cycle the heartbeat is felt, and how sharply. Plain NumPy, no
PsychoPy or device. The design is documented
in `docs/source/hsd_design.md`.
- The Heartbeat Synchrony Discrimination task runner, experimental:
in `docs/source/tasks/hsd/design.md`.
- The Heartbeat Synchrony Discrimination task runner, in beta:
`cardioception.HSD.parameters.getParameters` and `cardioception.HSD.task.run`,
with English instructions, a tutorial with three practice trials, both
stimulus axes (ms after the R-wave, or a fraction of the interbeat
Expand All @@ -117,11 +126,13 @@ varies. Set `onMissedTrial="skip"` for a fixed number of presentations.
`setup="behavioral"` uses the shared `LSLBeatSource` and `TonePlayer` in
`cardioception.devices`. Every tone is scheduled a 50 ms latency bias early
(`TaskConfig.latencyBias`), for the transport and speaker delays the
recordings cannot see, so the shortest delay played is 130 ms. One hardware
recordings cannot see, so no delay below 130 ms is played and the
shortest on the default grid is 140 ms. One hardware
dry run, 60 trials on a PLUX ECG over Bluetooth, is recorded in the design
document, with a simulation rerun at the 130 ms floor. The user guide has a
how-to for running a session and reading its results.
- The Phase Adjustment Task, experimental: `cardioception.PAT`, after the
document, with a simulation rerun at the 130 ms floor. Running the HSD
(`docs/source/tasks/hsd/index.md`) is a how-to for running a session and
reading its results.
- The Phase Adjustment Task, in beta: `cardioception.PAT`, after the
PAT-ECG variant of Hodgetts et al. (2026, *Psychophysiology* 63:e70415).
One tone per heartbeat, timed from the R-waves of an LSL ECG stream, at a
delay the participant moves with the mouse wheel until tones and heartbeats
Expand All @@ -131,7 +142,7 @@ varies. Set `onMissedTrial="skip"` for a fixed number of presentations.
and `wrappers/pat_lsl.py`. A session writes `final`, `tones` and
`parameters`; `cardioception.PAT.scoring` gives the paper's 2 x 2 x 2 grid
of phase-consistency scores with Monte Carlo chance thresholds. See
`docs/source/pat.md`.
`docs/source/tasks/pat.md`.
- The ECG channel is a required field in `wrappers/pat_lsl.py` and
`wrappers/hsd_lsl.py`, with no default: its label is not the same on every
hub (`ECG1` on one, `ECG2` on another), so it has to be typed in, and the
Expand Down
15 changes: 10 additions & 5 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ identifiers:
repository-code: 'https://github.com/embodied-computation-group/Cardioception'
url: 'https://www.the-ecg.org/Cardioception/'
abstract: >-
Cardioception measures cardiac interoception in PsychoPy. It implements the
Heart Rate Discrimination task, a psychophysical method that separates the
bias in what people believe their heart rate to be from the precision with
which they can discriminate it, together with the older Heartbeat Counting
task.
Cardioception is an open-source Python toolbox for studying how people
perceive their own heartbeat. Built on PsychoPy, it brings the most widely
used methods for measuring cardiac interoception together under one
installation and one output layout: the Heart Rate Discrimination task, the
Heartbeat Counting task, the Phase Adjustment Task and the Heartbeat
Synchrony Discrimination task. The pulse is recorded from a USB pulse
oximeter, or from ECG and PPG devices over Lab Streaming Layer.
keywords:
- interoception
- heart rate discrimination
Expand All @@ -44,6 +46,9 @@ keywords:
- metacognition
- cardiac
- psychopy
- heartbeat synchrony
- phase adjustment task
- lab streaming layer
license: Apache-2.0
version: 1.0.0
# Set on the day of the release.
Expand Down
74 changes: 74 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributing to Cardioception

Bug reports and questions go in the [issue tracker](https://github.com/embodied-computation-group/Cardioception/issues). Code and documentation changes come as pull requests.

## Branches

Branch from `dev` and open the pull request against `dev`. `main` holds the released version.

## A development install

Cardioception needs Python 3.10 or 3.11. In a fresh virtual environment, from a clone of the repository:

```bash
pip install -e ".[lsl]" pytest pytest-timeout
```

## Running the tests

> **Warning: the session tests play tones at full volume.** `tests/test_hrd.py`, `tests/test_hbc.py`, `tests/test_headless.py` and `tests/test_tone_player.py` play sound through PsychoPy's audio backend, which ignores the system volume. Unplug the headphones or mute the output device before you run them.

These run without a window or sound, and are the quick check:

```bash
pytest tests/test_rng.py tests/test_stimuli.py tests/test_hsd_psi.py
```

The whole suite, as CI runs it:

```bash
pytest tests/ --ignore=tests/test_reports.py --timeout=180 --timeout-method=thread
```

CI also checks types, formatting and lint on Python 3.11:

```bash
mypy ./cardioception/ --ignore-missing-imports
black --check --diff ./cardioception/ ./tests/
isort --check --diff ./cardioception/ ./tests/
flake8 ./cardioception/ --extend-ignore=E501
```

## Building the documentation

The documentation builds on Python 3.10 with Sphinx 5.3. In a separate environment:

```bash
pip install --no-deps -e .
pip install -r requirements-docs.txt
sphinx-build -b html docs/source docs/build/html
```

The pages are MyST markdown in `docs/source/`. Every push to `dev` or `main` builds them.

## Adding a language

Each task reads its instructions from `cardioception/<task>/texts/<language>.yaml`. To add one:

1. Copy `english.yaml` to `<language>.yaml` in the same folder and translate the values, not the keys or the `{placeholders}`.
2. Add the language to the tests that list `available()` exactly: `tests/test_languages.py` (HRD), `tests/test_hbc_languages.py` and `tests/test_pat_languages.py`.
3. Add it to the language tables in the documentation: Languages in `docs/source/getting-started/running-a-session.md`, and the `language` row of the task page.

## Copyright and licence

Cardioception is released under the [Apache 2.0 licence](LICENSE). Every Python file starts with the copyright header:

```python
# Copyright (C) 2020-2026 Micah G Allen and the Embodied Computation Group, Aarhus University
```

By opening a pull request you agree that your contribution is licensed under Apache 2.0.

## Review

The maintainers review every pull request before it is merged. Say what the change does and why, and how you checked it.
Loading
Loading