Skip to content

Commit db3f01b

Browse files
author
IvanARashid
authored
Merge pull request #24 from OSIPI/analysis/workflow
Analysis/workflow
2 parents b8a769a + 18daf57 commit db3f01b

File tree

5 files changed

+80
-7
lines changed

5 files changed

+80
-7
lines changed

.github/workflows/analysis.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Algorithm Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'analysis/**'
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
continue-on-error: false
14+
strategy:
15+
fail-fast: false
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: "3.11"
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
- name: Set up R
27+
uses: r-lib/actions/setup-r@v2
28+
with:
29+
use-public-rspm: true
30+
- name: Install R dependencies
31+
uses: r-lib/actions/setup-r-dependencies@v2
32+
with:
33+
packages: |
34+
any::plyr
35+
any::dplyr
36+
any::tidyverse
37+
any::data.table
38+
any::ggplot2
39+
- name: Generate fitting data
40+
run: |
41+
pip install pytest
42+
python -m pytest -m slow --saveFileName test_output.csv --SNR 10 30 50 100 200 --fitCount 300 --saveDurationFileName test_duration.csv
43+
- name: Generate figures
44+
run: Rscript --vanilla tests/IVIMmodels/unit_tests/analyze.r test_output.csv test_duration.csv
45+
- name: Upload raw data
46+
uses: actions/upload-artifact@v3
47+
with:
48+
name: Raw data
49+
path: |
50+
test_output.csv
51+
test_duration.csv
52+
- name: Upload figures
53+
uses: actions/upload-artifact@v3
54+
with:
55+
name: Fit figures
56+
path: |
57+
D.pdf
58+
f.pdf
59+
Dp.pdf
60+
D_limited.pdf
61+
f_limited.pdf
62+
Dp_limited.pdf
63+
durations.pdf

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ The **test** folder contains the test files corresponding to the contributed cod
3030
The **utils** folder contains various helpful tools.
3131

3232
## View Testing Reports
33-
*to be added*
33+
[![Unit tests](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/unit_test.yml/badge.svg?branch=main)](https://github.com/OSIPI/TF2.4_IVIM-MRI_CodeCollection/actions/workflows/unit_test.yml)

conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ def pytest_addoption(parser):
1919
type=bool,
2020
help="Use Rician noise, non-rician is gaussian",
2121
)
22+
parser.addoption(
23+
"--usePrior",
24+
default=False,
25+
type=bool,
26+
help="Use a prior where accepted",
27+
)
2228
parser.addoption(
2329
"--algorithmFile",
2430
default="tests/IVIMmodels/unit_tests/algorithms.json",
@@ -110,6 +116,10 @@ def fit_count(request):
110116
def rician_noise(request):
111117
return request.config.getoption("--ricianNoise")
112118

119+
@pytest.fixture(scope="session")
120+
def use_prior(request):
121+
return request.config.getoption("--usePrior")
122+
113123

114124
def pytest_generate_tests(metafunc):
115125
if "SNR" in metafunc.fixturenames:

tests/IVIMmodels/unit_tests/analyze.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ plot_ivim <- function(data, fileExtension) {
2525
f_plot <- ggplot(data, aes(x=Algorithm)) + geom_boxplot(aes(y=f_fitted)) + geom_boxplot(color="red", aes(y=f)) + facet_grid(SNR ~ Region) + scale_x_discrete(guide = guide_axis(angle = 90)) + ylim(0, 1) + ggtitle("Perfusion fraction grid") + ylab("Perfusion fraction")
2626
print(f_plot)
2727
ggsave(paste("f", fileExtension, sep=""), plot=f_plot, width = 50, height = 50, units = "cm")
28-
D_plot <- ggplot(data, aes(x=Algorithm)) + geom_boxplot(aes(y=D_fitted)) + geom_boxplot(color="red", aes(y=D)) + facet_grid(SNR ~ Region) + scale_x_discrete(guide = guide_axis(angle = 90)) + ggtitle("Diffusion grid") + ylab("Diffusion")
28+
D_plot <- ggplot(data, aes(x=Algorithm)) + geom_boxplot(aes(y=D_fitted)) + geom_boxplot(color="red", aes(y=D)) + facet_grid(SNR ~ Region) + scale_x_discrete(guide = guide_axis(angle = 90)) + ylim(0, 0.005) + ggtitle("Diffusion grid") + ylab("Diffusion")
2929
print(D_plot)
3030
ggsave(paste("D", fileExtension, sep=""), plot=D_plot, width = 50, height = 50, units = "cm")
3131
Dp_plot <- ggplot(data, aes(x=Algorithm)) + geom_boxplot(aes(y=Dp_fitted)) + geom_boxplot(color="red", aes(y=Dp)) + facet_grid(SNR ~ Region) + scale_x_discrete(guide = guide_axis(angle = 90)) + ylim(0, 0.25) + ggtitle("Perfusion grid") + ylab("Perfusion")
@@ -43,8 +43,8 @@ plot_ivim(data_restricted, "_limited.pdf")
4343
data_duration <- read.csv(duration_name)
4444
data_duration <- data_duration %>% mutate_if(is.character, as.factor)
4545
data_duration$ms <- data_duration$Duration..us./data_duration$Count/1000
46-
ggplot(data_duration, aes(x=Algorithm, y=ms)) + geom_boxplot() + scale_x_discrete(guide = guide_axis(angle = 90)) + ggtitle("Fit Duration") + ylab("Time (ms)")
47-
ggsave("durations.pdf", width = 20, height = 20, units = "cm")
46+
duration_plot <- ggplot(data_duration, aes(x=Algorithm, y=ms)) + geom_boxplot() + scale_x_discrete(guide = guide_axis(angle = 90)) + ggtitle("Fit Duration") + ylab("Time (ms)")
47+
ggsave("durations.pdf", plot=duration_plot, width = 20, height = 20, units = "cm")
4848

4949

5050
if (runPrediction) {

tests/IVIMmodels/unit_tests/test_ivim_synthetic.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#run using pytest <path_to_this_file> --saveFileName test_output.txt --SNR 50 100 200
1515
#e.g. pytest -m slow tests/IVIMmodels/unit_tests/test_ivim_synthetic.py --saveFileName test_output.csv --SNR 10 50 100 200 --fitCount 20
1616
@pytest.mark.slow
17-
def test_generated(ivim_algorithm, ivim_data, SNR, rtol, atol, fit_count, rician_noise, save_file, save_duration_file):
17+
def test_generated(ivim_algorithm, ivim_data, SNR, rtol, atol, fit_count, rician_noise, save_file, save_duration_file, use_prior):
1818
# assert save_file == "test"
1919
random.seed(42)
2020
S0 = 1
@@ -24,8 +24,8 @@ def test_generated(ivim_algorithm, ivim_data, SNR, rtol, atol, fit_count, rician
2424
f = data["f"]
2525
Dp = data["Dp"]
2626
fit = OsipiBase(algorithm=ivim_algorithm)
27-
# here try a prior, but it's not seeing it, why?
28-
if hasattr(fit, "accepts_priors") and fit.accepts_priors:
27+
# here is a prior
28+
if use_prior and hasattr(fit, "accepts_priors") and fit.accepts_priors:
2929
prior = [np.random.normal(D, D/3, 10), np.random.normal(f, f/3, 10), np.random.normal(Dp, Dp/3, 10), np.random.normal(1, 1/3, 10)]
3030
# prior = [np.repeat(D, 10)+np.random.normal(0,D/3,np.shape(np.repeat(D, 10))), np.repeat(f, 10)+np.random.normal(0,f/3,np.shape(np.repeat(D, 10))), np.repeat(Dp, 10)+np.random.normal(0,Dp/3,np.shape(np.repeat(D, 10))),np.repeat(np.ones_like(Dp), 10)+np.random.normal(0,1/3,np.shape(np.repeat(D, 10)))] # D, f, D*
3131
fit.initialize(prior_in=prior)

0 commit comments

Comments
 (0)