Skip to content

Commit dc99c0c

Browse files
author
IvanARashid
committed
Merge branch 'main' into wrapper_dev
2 parents 563205f + 5c217fc commit dc99c0c

File tree

12 files changed

+2019
-1413
lines changed

12 files changed

+2019
-1413
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Build and Run Docker
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
types: [opened, synchronize, edited]
8+
branches:
9+
- main
10+
- "docker/**"
11+
jobs:
12+
build-and-run-docker:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.x'
22+
23+
- name: Install Python dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install -r requirements.txt
27+
28+
- name: Generate input files
29+
run: |
30+
python -m Docker.generate_signal_docker_test
31+
32+
- name: Verify input files
33+
run: |
34+
for file in ivim_simulation.nii.gz ivim_simulation.bval ivim_simulation.bvec; do
35+
if [ ! -f "$file" ]; then
36+
echo "Error: $file not found"
37+
exit 1
38+
fi
39+
done
40+
echo "All input files generated successfully"
41+
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
45+
- name: Build Docker image
46+
run: |
47+
docker build -t tf2.4_ivim-mri_codecollection -f Docker/Dockerfile .
48+
49+
- name: Run Docker container
50+
run: |
51+
docker run --rm --name TF2.4_IVIM-MRI_CodeCollection \
52+
-v ${{ github.workspace }}:/usr/src/app \
53+
-v ${{ github.workspace }}:/usr/app/output \
54+
tf2.4_ivim-mri_codecollection ivim_simulation.nii.gz ivim_simulation.bvec ivim_simulation.bval
55+
56+
- name: Verify output files
57+
run: |
58+
for file in f.nii.gz dp.nii.gz d.nii.gz; do
59+
if [ ! -f "$file" ]; then
60+
echo "Error: $file not found"
61+
exit 1
62+
fi
63+
done
64+
echo "All output files generated successfully"
65+
66+
- name: Clean up artifacts and Docker image
67+
run: |
68+
docker rmi tf2.4_ivim-mri_codecollection || true
69+
rm -f tf2.4_ivim-mri_codecollection.tar.gz
70+
rm -f ${{ github.workspace }}/f.nii.gz
71+
rm -f ${{ github.workspace }}/dp.nii.gz
72+
rm -f ${{ github.workspace }}/d.nii.gz
73+
rm -f ${{ github.workspace }}/ivim_simulation.nii.gz
74+
rm -f ${{ github.workspace }}/ivim_simulation.bval
75+
rm -f ${{ github.workspace }}/ivim_simulation.bvec
76+
- name: Cleanup Docker
77+
run: |
78+
docker system prune -a --force

.github/workflows/website.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,20 @@ jobs:
4646
with:
4747
name: 'Data'
4848

49+
- name: Run the test that generates the plots report.
50+
run: |
51+
pytest tests/IVIMmodels/unit_tests/test_ivim_fit.py --json-report
52+
mv .report.json utilities/
53+
python utilities/report-summary.py .report.json report-summary.json
54+
4955
- name: 'Filter and compress results file.'
5056
run: python utilities/reduce_output_size.py test_output.csv test_output.csv.gz
5157

5258
- name: move data to the dashboard folder
5359
run: |
5460
mv test_output.csv.gz website/dashboard
61+
mv report-summary.json website/dashboard
62+
5563
5664
- name: Build documentation
5765
run: |

Docker/generate_signal_docker_test.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import numpy as np
2+
import nibabel as nib
3+
from utilities.data_simulation.GenerateData import GenerateData
4+
from WrapImage.nifti_wrapper import save_nifti_file
5+
6+
7+
def save_bval_bvec(filename, values):
8+
if filename.endswith('.bval'):
9+
# Convert list to a space-separated string for bval
10+
values_string = ' '.join(map(str, values))
11+
elif filename.endswith('.bvec'):
12+
# Convert 2D list to a line-separated, space-separated string for bvec
13+
values_string = '\n'.join(' '.join(map(str, row)) for row in values)
14+
else:
15+
raise ValueError("Unsupported file extension. Use '.bval' or '.bvec'.")
16+
17+
with open(filename, 'w') as file:
18+
file.write(values_string)
19+
20+
# Set random seed for reproducibility
21+
np.random.seed(42)
22+
# Create GenerateData instance
23+
gd = GenerateData()
24+
25+
# Generate random input data
26+
shape = (10, 10, 5)
27+
f_in = np.random.uniform(low=0, high=1, size=shape)
28+
D_in = np.random.uniform(low=0, high=1e-3, size=shape)
29+
Dp_in = np.random.uniform(low=0, high=1e-1, size=shape)
30+
S0 = 1000 # Setting a constant S0 for simplicity
31+
bvals = np.array([0, 50, 100, 500, 1000])
32+
bvals_reshaped = np.broadcast_to(bvals, shape)
33+
34+
# Generate IVIM signal
35+
signals = gd.ivim_signal(D_in, Dp_in, f_in, S0, bvals_reshaped)
36+
37+
# Save the generated image as a NIfTI file
38+
save_nifti_file(signals, "ivim_simulation.nii.gz")
39+
# Save the bval in a file
40+
save_bval_bvec("ivim_simulation.bval", [0, 50, 100, 500, 1000])
41+
# Save the bvec value
42+
save_bval_bvec("ivim_simulation.bvec", [[1, 0, 0], [0, 1, 0], [0, 0, 1]])

WrapImage/nifti_wrapper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def save_nifti_file(data, output_file, affine=None, **kwargs):
5656
For saving the 3d nifti images of the output of the algorithm
5757
"""
5858
if affine is None:
59-
affine = np.eye(data.ndim + 1)
59+
affine = np.eye(4)
60+
else:
61+
affine = np.array(affine.reshape(4, 4))
6062
output_img = nib.nifti1.Nifti1Image(data, affine , **kwargs)
6163
nib.save(output_img, output_file)
6264

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
numpy<2
2+
nibabel
23
scipy
34
torchio
45
torch
@@ -13,3 +14,4 @@ tqdm
1314
pandas
1415
sphinx
1516
sphinx_rtd_theme
17+
pytest-json-report

tests/IVIMmodels/unit_tests/compare.r

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
#Run like this:
44
#Rscript --vanilla tests/IVIMmodels/unit_tests/compare.r test_output.csv test_reference.csv reference_output.csv test_results.csv
55

6+
# If this script fails:
7+
# 1. Save the "Comparison" file from the run on Github, OR run this file directly
8+
# 2. Find the file producted "test_reference.csv" on Github, or whatever the "reference_file" variable was called
9+
# 3. This replaces "tests/IVIMmodels/unit_tests/reference_output.csv" in the repository
10+
# 4. For the algorithm "IAR_LU_modified_mix", replace the "f_f_alpha, Dp_f_alpha, D_f_alpha, f_t_alpha, Dp_t_alpha, D_t_alpha" columns with "0.01,0.01,0.01,0.0,0.0,0.0"
11+
612
args = commandArgs(trailingOnly=TRUE)
713
# Define file paths
814
test_file <- "test_output.csv"

0 commit comments

Comments
 (0)