Skip to content

Commit 7294bde

Browse files
committed
Generated the testing images during docker building and added confirmation to ensure files are being generated
1 parent 1fa952c commit 7294bde

File tree

8 files changed

+11232
-241826
lines changed

8 files changed

+11232
-241826
lines changed

.github/workflows/docker-build-and-run.yml

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name: Build and Run Docker
2-
32
on:
43
push:
54
branches:
@@ -9,15 +8,37 @@ on:
98
branches:
109
- main
1110
- "docker/**"
12-
1311
jobs:
1412
build-and-run-docker:
1513
runs-on: ubuntu-latest
16-
1714
steps:
1815
- name: Checkout code
1916
uses: actions/checkout@v4
2017

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 numpy nibabel
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+
2142
- name: Set up Docker Buildx
2243
uses: docker/setup-buildx-action@v3
2344

@@ -40,7 +61,17 @@ jobs:
4061
docker run --rm --name TF2.4_IVIM-MRI_CodeCollection \
4162
-v ${{ github.workspace }}:/usr/src/app \
4263
-v ${{ github.workspace }}:/usr/app/output \
43-
tf2.4_ivim-mri_codecollection Docker/ivim_simulation.nii.gz Docker/ivim_simulation.bvec Docker/ivim_simulation.bval
64+
tf2.4_ivim-mri_codecollection ivim_simulation.nii.gz ivim_simulation.bvec ivim_simulation.bval
65+
66+
- name: Verify output files
67+
run: |
68+
for file in f.nii.gz dp.nii.gz d.nii.gz; do
69+
if [ ! -f "$file" ]; then
70+
echo "Error: $file not found"
71+
exit 1
72+
fi
73+
done
74+
echo "All output files generated successfully"
4475
4576
- name: Clean up artifacts and Docker image
4677
run: |
@@ -49,3 +80,6 @@ jobs:
4980
rm -f ${{ github.workspace }}/f.nii.gz
5081
rm -f ${{ github.workspace }}/dp.nii.gz
5182
rm -f ${{ github.workspace }}/d.nii.gz
83+
rm -f ${{ github.workspace }}/ivim_simulation.nii.gz
84+
rm -f ${{ github.workspace }}/ivim_simulation.bval
85+
rm -f ${{ github.workspace }}/ivim_simulation.bvec

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ md5sums.txt
2121
.cache
2222
nosetests.xml
2323
coverage.xml
24-
*.pyc
24+
*.pyc

Docker/generate_signal_docker_test.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
import numpy as np
22
import nibabel as nib
33
from utilities.data_simulation.GenerateData import GenerateData
4+
from WrapImage.nifti_wrapper import save_nifti_file
45

5-
def save_nii(data, filename='ivim_image.nii.gz'):
6-
"""
7-
Save the data as a NIfTI file (.nii.gz)
8-
"""
9-
nii_img = nib.Nifti1Image(data, affine=np.eye(4))
10-
nib.save(nii_img, filename)
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)
1119

1220
# Set random seed for reproducibility
1321
np.random.seed(42)
14-
1522
# Create GenerateData instance
1623
gd = GenerateData()
1724

@@ -25,7 +32,11 @@ def save_nii(data, filename='ivim_image.nii.gz'):
2532
bvals_reshaped = np.broadcast_to(bvals, shape)
2633

2734
# Generate IVIM signal
28-
images = gd.ivim_signal(D_in, Dp_in, f_in, S0, bvals_reshaped)
35+
signals = gd.ivim_signal(D_in, Dp_in, f_in, S0, bvals_reshaped)
2936

3037
# Save the generated image as a NIfTI file
31-
save_nii(images)
38+
save_nifti_file(signals, "ivim_image.nii.gz")
39+
# Save the bval in a file
40+
save_bval_bvec("ivim_image.bval", [0, 50, 100, 500, 1000])
41+
# Save the bvec value
42+
save_bval_bvec("ivim_signal.bvec", [[1, 0, 0], [0, 1, 0], [0, 0, 1]])

Docker/ivim_simulation.bval

Lines changed: 0 additions & 1 deletion
This file was deleted.

Docker/ivim_simulation.bvec

Lines changed: 0 additions & 3 deletions
This file was deleted.

Docker/ivim_simulation.nii.gz

-3.12 KB
Binary file not shown.

test_output.csv

Lines changed: 11173 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)