-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add plotting and enhance performance and add docstrings
- Loading branch information
1 parent
8740440
commit 5e18f5e
Showing
27 changed files
with
472 additions
and
2,635 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,23 @@ name = "wonkyconn" | |
description = "Evaluating the residual motion in fMRI connectome and visualise reports." | ||
readme = "README.md" | ||
requires-python = ">=3.11" | ||
license = { file="LICENSE" } | ||
authors = [ | ||
{ name="Hao-Ting Wang", email="[email protected]" }, | ||
] | ||
license = { file = "LICENSE" } | ||
authors = [{ name = "Hao-Ting Wang", email = "[email protected]" }] | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3.11", | ||
"Programming Language :: Python :: 3.12", | ||
] | ||
dependencies = [ | ||
"nilearn[plotting] >=0.10.3", | ||
"pybids >=0.15.0, <0.16.0", | ||
"templateflow < 23.0.0", | ||
"setuptools", | ||
"jinja2 >= 2.0", | ||
"numpy", | ||
"scipy", | ||
"patsy", | ||
"pandas", | ||
"rich", | ||
"numba", | ||
"seaborn", | ||
"matplotlib", | ||
] | ||
dynamic = ["version"] | ||
|
||
|
@@ -35,22 +36,14 @@ dev = [ | |
"flake8", | ||
"pre-commit", | ||
"wonkyconn[test]", | ||
'tox', | ||
'mypy', | ||
'types-all', | ||
'pandas-stubs', | ||
'types-tqdm' | ||
] | ||
test = [ | ||
"pytest", | ||
"pytest-cov", | ||
] | ||
docs = [ | ||
"sphinx", | ||
"sphinx_rtd_theme", | ||
"myst-parser", | ||
"sphinx-argparse" | ||
"tox", | ||
"mypy", | ||
"types-all", | ||
"pandas-stubs", | ||
"types-tqdm", | ||
] | ||
test = ["nibabel", "nilearn", "pytest", "pytest-cov", "templateflow < 23.0.0"] | ||
docs = ["sphinx", "sphinx_rtd_theme", "myst-parser", "sphinx-argparse"] | ||
# Aliases | ||
tests = ["wonkyconn[test]"] | ||
|
||
|
@@ -69,13 +62,10 @@ exclude = [".git_archival.txt"] | |
|
||
[tool.hatch.build.targets.wheel] | ||
packages = ["wonkyconn"] | ||
exclude = [ | ||
".github", | ||
"wonkyconn/data/test_data" | ||
] | ||
exclude = [".github", "wonkyconn/data/test_data"] | ||
|
||
[tool.black] | ||
target-version = ['py311'] | ||
target-version = ["py311"] | ||
exclude = "wonkyconn/_version.py" | ||
line-length = 79 | ||
|
||
|
@@ -84,7 +74,7 @@ check_untyped_defs = true | |
disallow_any_generics = true | ||
disallow_incomplete_defs = true | ||
disallow_untyped_defs = true | ||
enable_error_code = ["ignore-without-code", "redundant-expr"] # "truthy-bool" | ||
enable_error_code = ["ignore-without-code", "redundant-expr"] # "truthy-bool" | ||
no_implicit_optional = true | ||
show_error_codes = true | ||
# strict = true | ||
|
@@ -95,36 +85,34 @@ warn_unused_ignores = true | |
[[tool.mypy.overrides]] | ||
ignore_missing_imports = true | ||
module = [ | ||
"bids.*", | ||
"h5py.*", | ||
"nibabel.*", | ||
"nilearn.*", | ||
"nilearn.connectome.*", | ||
"nilearn.image.*", | ||
"nilearn.interfaces.*", | ||
"nilearn.maskers.*", | ||
"nilearn.masking.*", | ||
"patsy.*", | ||
"rich.*", | ||
"scipy.*", | ||
"statsmodels.*", | ||
"templateflow.*", | ||
"bids.*", | ||
"matplotlib.*", | ||
"numba.*", | ||
"patsy.*", | ||
"rich.*", | ||
"scipy.*", | ||
"seaborn.*", | ||
"statsmodels.*", | ||
"templateflow.*", | ||
] | ||
|
||
[[tool.mypy.overrides]] | ||
ignore_errors = true | ||
module = [ | ||
'wonkyconn.tests.*', | ||
'conf', | ||
] | ||
module = ["wonkyconn.tests.*", "conf"] | ||
|
||
[tool.pytest.ini_options] | ||
markers = [ | ||
"smoke: smoke tests that will run on a simulated dataset (deselect with '-m \"not smoke\"')", | ||
] | ||
# filterwarnings = ["error"] | ||
minversion = "7" | ||
log_cli_level = "INFO" | ||
xfail_strict = true | ||
testpaths = ["wonkyconn/tests"] | ||
addopts = ["-ra", "--strict-config", "--strict-markers", "--doctest-modules", "-v"] | ||
markers = [ | ||
"smoke: smoke tests that will run on a downsampled real dataset (deselect with '-m \"not smoke\"')", | ||
addopts = [ | ||
"-ra", | ||
"--strict-config", | ||
"--strict-markers", | ||
"--doctest-modules", | ||
"-v", | ||
] | ||
# filterwarnings = ["error"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import numpy as np | ||
import scipy | ||
from numba import guvectorize | ||
from numpy import typing as npt | ||
|
||
|
||
def correlation_p_value(r: npt.NDArray[np.float64], m: int) -> npt.NDArray[np.float64]: | ||
ab = m / 2 - 1 | ||
distribution = scipy.stats.beta(ab, ab, loc=-1, scale=2) | ||
pvalue = 2 * (distribution.sf(np.abs(r))) | ||
return pvalue | ||
|
||
|
||
@guvectorize( | ||
["void(float64[:], float64[:], float64[:, :], float64[:])"], | ||
"(n),(n),(n,m)->()", | ||
nopython=True, | ||
) | ||
def partial_correlation( | ||
x: npt.NDArray[np.float64], | ||
y: npt.NDArray[np.float64], | ||
cov: npt.NDArray[np.float64], | ||
out: npt.NDArray[np.float64], | ||
) -> None: | ||
"""A minimal implementation of partial correlation. | ||
Parameters | ||
---------- | ||
x, y : np.ndarray | ||
Variable of interest. | ||
cov : np.ndarray | ||
Variable to be removed from variable of interest. | ||
Returns | ||
------- | ||
dict | ||
Correlation and p-value. | ||
""" | ||
beta_cov_x, _, _, _ = np.linalg.lstsq(cov, x) | ||
beta_cov_y, _, _, _ = np.linalg.lstsq(cov, y) | ||
resid_x = x - cov @ beta_cov_x | ||
resid_y = y - cov @ beta_cov_y | ||
out[0] = np.corrcoef(resid_x, resid_y)[0, 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from dataclasses import dataclass | ||
from typing import Self | ||
|
||
import numpy as np | ||
|
||
|
||
@dataclass | ||
class MeanAndSEMResult: | ||
mean: float | ||
sem: float | ||
|
||
@classmethod | ||
def empty(cls) -> Self: | ||
return cls(mean=np.nan, sem=np.nan) |
Oops, something went wrong.