Skip to content

Commit 2694331

Browse files
committed
Added type hints and updating contributing.md
1 parent 78e1916 commit 2694331

9 files changed

Lines changed: 148 additions & 16 deletions

File tree

.flake8

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ exclude=
1414
.git,
1515
venv,
1616
test_data,
17+
pcp1,

.github/workflows/tests.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
if: github.event.pull_request.draft == false
1515

1616
env:
17-
python-latest: 3.14
17+
python-latest: '3.14'
1818
strategy:
1919
matrix:
20-
python-version: ['3.10', 3.11, 3.12, 3.13, 3.14]
20+
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
2121

2222
steps:
2323
- name: Checkout repository
@@ -31,12 +31,17 @@ jobs:
3131
- name: Install dependencies
3232
run: |
3333
python -m pip install --upgrade pip
34-
python -m pip install -e .[test]
34+
python -m pip install -e .[dev]
3535
3636
- name: Check code style with flake8
3737
if: ${{ matrix.python-version == env.python-latest }}
3838
run: |
39-
python -m flake8 pcpostprocess
39+
python -m flake8 -j4
40+
41+
- name: Check typing with mypy
42+
if: ${{ matrix.python-version == env.python-latest }}
43+
run: |
44+
python -m mypy
4045
4146
- name: Extract test data
4247
run: |

CONTRIBUTING.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ When making changes, we try to follow the procedure below.
4242
**TODO: Once there is a "user" way to install, move the git clone etc. information here [#105](https://github.com/CardiacModelling/pcpostprocess/issues/105).**
4343

4444
```
45-
pip install -e .[test]
45+
pip install -e .[dev]
4646
```
4747

4848
## Style guidelines
@@ -62,6 +62,17 @@ In addition to the rules checked by flake8, we try to use single quotes (`'`) fo
6262

6363
Class, method, and argument names are in UK english.
6464

65+
### Type hints
66+
67+
We'll try to use [type hints](https://docs.python.org/3/library/typing.html), checked with [mypy](https://www.mypy-lang.org/).
68+
69+
To run locally, use
70+
```
71+
$ mypy
72+
```
73+
74+
Mypy is configured in `pyproject.toml`.
75+
6576
## Documentation
6677

6778
Every method and every class should have a [docstring](https://www.python.org/dev/peps/pep-0257/) that describes in plain terms what it does, and what the expected input and output is.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ This repository contains a python package and scripts for handling time-series d
55
The package has been tested with data from a SyncroPatch 384, but may be adapted to work with data in other formats.
66
It can also be used to perform quality control (QC) as described in [Lei et al. (2019)](https://doi.org/10.1016%2Fj.bpj.2019.07.029).
77

8-
This package is tested on Ubuntu with Python 3.10, 3.11, 3.12, 3.13 and 3.14.
8+
This package is tested on Ubuntu with Python 3.10 to 3.14.
99

1010
## Getting Started
1111

@@ -27,7 +27,7 @@ Then install the package with `pip`.
2727

2828
```sh
2929
python3 -m pip install --upgrade pip
30-
python3 -m pip install -e .'[test]'
30+
python3 -m pip install -e .'[dev]'
3131
```
3232

3333
To run the tests you must first download some test data.

pcpostprocess/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# This file is part of pcpostprocess.
3+
# See https://github.com/CardiacModelling/pcpostprocess for copyright, sharing,
4+
# and licensing details.
5+
#
6+
7+
from ._trace import (
8+
Trace,
9+
)
10+
11+
from ._leak import (
12+
estimate_gE_leak_ramp,
13+
estimate_gE_leak_step,
14+
)

pcpostprocess/_leak.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Leak estimation and correction
3+
#
4+
# This file is part of pcpostprocess.
5+
# See https://github.com/CardiacModelling/pcpostprocess for copyright, sharing,
6+
# and licensing details.
7+
#
8+
from . import Trace
9+
10+
11+
def estimate_gE_leak_ramp(
12+
trace : Trace, ramp: int | None = None, step: int | None = None):
13+
"""
14+
Estimates ``g * (V - E)`` leak using a "leak ramp" in the voltage protocol.
15+
16+
Parameters
17+
----------
18+
trace : Trace
19+
20+
ramp : int, optional
21+
The index of the ramp in the voltage protocol: 0 for the first segment
22+
that's a ramp, 1 for the second segment that's a ramp, etc. If neither
23+
``ramp_index`` or ``step_index`` is given, the first ramp will be used.
24+
step : int, optional
25+
An alternative way to specify the
26+
27+
Returns
28+
-------
29+
30+
"""
31+
return 0
32+
33+
34+
def estimate_gE_leak_step(trace : Trace, step_1: int, step_2: int):
35+
"""
36+
Estimates ``g * (V - E)`` leak using a "leak ramp" in the voltage protocol.
37+
38+
39+
40+
41+
42+
43+
"""
44+
return 0
45+
46+
47+
def correct_gE_leak(trace : Trace, g : float, E : float):
48+
"""
49+
"""
50+
pass
51+
52+
53+
# Alternative:
54+
class gELeak:
55+
56+
def __init__(self, g, E):
57+
pass
58+
59+
@classmethod
60+
def from_ramp(trace, ramp_index=None, step_index=None):
61+
pass
62+
63+
def from_steps(trace, step_1, step_2):
64+
pass
65+

pcpostprocess/_protocol.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#
2+
# Voltage protocol
3+
#
4+
# This file is part of pcpostprocess.
5+
# See https://github.com/CardiacModelling/pcpostprocess for copyright, sharing,
6+
# and licensing details.
7+
#
8+
#import numpy as np
9+
10+
11+
class VoltageProtocol:
12+
"""
13+
Represents a voltage protocol consisting of a sequence of steps and/or
14+
ramps.
15+
"""
16+
# Internal format: Sequence of (duration, v_start, v_end) objects.
17+

pcpostprocess/_trace.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#
2+
# Trace class and implementations
3+
#
4+
# This file is part of pcpostprocess.
5+
# See https://github.com/CardiacModelling/pcpostprocess for copyright, sharing,
6+
# and licensing details.
7+
#
8+
#import numpy as np
9+
10+
11+
class Trace:
12+
13+
def __init__(self, time, current):
14+
pass

pyproject.toml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
[build-system]
2+
build-backend = 'setuptools.build_meta'
23
requires = [
34
'setuptools>=80',
45
'setuptools_scm>=8.0',
5-
'wheel',
6+
#'wheel',
67
]
78

8-
build-backend = 'setuptools.build_meta'
9-
109
[tool.setuptools_scm]
1110
local_scheme = 'dirty-tag'
1211
write_to = 'pcpostprocess/_version.py'
@@ -42,27 +41,33 @@ dependencies = [
4241
]
4342

4443
[project.optional-dependencies]
45-
test = [
44+
dev = [
4645
'coverage', # For coverage testing
4746
'codecov>=2.1.3', # To upload coverage reports
4847
'flake8>=3', # For code style checking
48+
'mypy>=1', #
4949
]
5050

51-
[tools.setuptools.package-data]
52-
include_package_data = true
53-
5451
[project.urls]
5552
Homepage = 'https://github.com/CardiacModelling/pcpostprocess'
5653
Source = 'https://github.com/CardiacModelling/pcpostprocess'
5754

58-
[project.scripts]
59-
pcpostprocess = 'pcpostprocess.scripts.__main__:main'
55+
#[project.scripts]
56+
#pcpostprocess = 'pcpostprocess.scripts.__main__:main'
57+
58+
[tools.setuptools.package-data]
59+
include_package_data = true
6060

6161
[tool.setuptools.packages.find]
6262
include = [
6363
'pcpostprocess',
6464
]
6565

66+
[tool.mypy]
67+
modules = [
68+
'pcpostprocess',
69+
]
70+
6671
[tool.coverage.run]
6772
source = [
6873
'pcpostprocess',

0 commit comments

Comments
 (0)