Skip to content

Commit 863e7f7

Browse files
committed
Added sample data for running the docker image, also added the script for generating the sample data. Zipped the docker image generated. Make changes to nifit_wrapper to use 4, 4
1 parent c2149da commit 863e7f7

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,27 @@ jobs:
2525
run: |
2626
docker build -t tf2.4_ivim-mri_codecollection -f Docker/Dockerfile .
2727
28-
- name: Save Docker image to a tarball
28+
- name: Save and compress Docker image
2929
run: |
30-
docker save -o tf2.4_ivim-mri_codecollection.tar tf2.4_ivim-mri_codecollection
30+
docker save tf2.4_ivim-mri_codecollection | gzip > tf2.4_ivim-mri_codecollection.tar.gz
3131
3232
- name: Upload Docker image artifact
3333
uses: actions/upload-artifact@v4
3434
with:
3535
name: docker-image
36-
path: tf2.4_ivim-mri_codecollection.tar
36+
path: tf2.4_ivim-mri_codecollection.tar.gz
3737

3838
- name: Run Docker container
3939
run: |
4040
docker run --rm --name TF2.4_IVIM-MRI_CodeCollection \
4141
-v ${{ github.workspace }}:/usr/src/app \
4242
-v ${{ github.workspace }}:/usr/app/output \
43-
tf2.4_ivim-mri_codecollection brain.nii.gz brain.bvec brain.bval
43+
tf2.4_ivim-mri_codecollection Docker/ivim_simulation.nii.gz Docker/ivim_simulation.bvec Docker/ivim_simulation.bval
4444
45-
- name: Clean up
45+
- name: Clean up artifacts and Docker image
4646
run: |
47-
docker rmi tf2.4_ivim-mri_codecollection
48-
rm tf2.4_ivim-mri_codecollection.tar
47+
docker rmi tf2.4_ivim-mri_codecollection || true
48+
rm -f tf2.4_ivim-mri_codecollection.tar.gz
49+
rm -f ${{ github.workspace }}/f.nii.gz
50+
rm -f ${{ github.workspace }}/dp.nii.gz
51+
rm -f ${{ github.workspace }}/d.nii.gz

Docker/generate_signal_docker_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import numpy as np
2+
import nibabel as nib
3+
from utilities.data_simulation.GenerateData import GenerateData
4+
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)
11+
12+
# Set random seed for reproducibility
13+
np.random.seed(42)
14+
15+
# Create GenerateData instance
16+
gd = GenerateData()
17+
18+
# Generate random input data
19+
shape = (10, 10, 5)
20+
f_in = np.random.uniform(low=0, high=1, size=shape)
21+
D_in = np.random.uniform(low=0, high=1e-3, size=shape)
22+
Dp_in = np.random.uniform(low=0, high=1e-1, size=shape)
23+
S0 = 1000 # Setting a constant S0 for simplicity
24+
bvals = np.array([0, 50, 100, 500, 1000])
25+
bvals_reshaped = np.broadcast_to(bvals, shape)
26+
27+
# Generate IVIM signal
28+
images = gd.ivim_signal(D_in, Dp_in, f_in, S0, bvals_reshaped)
29+
30+
# Save the generated image as a NIfTI file
31+
save_nii(images)

Docker/ivim_simulation.bval

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 50 100 500 1000

Docker/ivim_simulation.bvec

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1 0 0
2+
0 1 0
3+
0 0 1

Docker/ivim_simulation.nii.gz

3.12 KB
Binary file not shown.

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

utilities/data_simulation/GenerateData.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def exponential_signal(self, D, bvalues):
5353
bvalues : list or array of float
5454
The diffusion (b-values)
5555
"""
56-
assert D >= 0, 'D must be >= 0'
56+
assert np.all(D >= 0), 'all values in D must be >= 0'
5757
return self._op.exp(-self._op.asarray(bvalues, dtype='float64') * D)
5858

5959
def multiexponential_signal(self, D, F, S0, bvalues):
@@ -75,7 +75,7 @@ def multiexponential_signal(self, D, F, S0, bvalues):
7575
assert len(D) == len(F), 'D and F must be the same length'
7676
signal = self._op.zeros_like(bvalues)
7777
for [d, f] in zip(D, F):
78-
signal += f * self.exponential_signal(d, bvalues)
78+
signal += f * self.exponential_signal(d[0], bvalues)
7979
signal *= S0
8080
return signal
8181

@@ -116,7 +116,7 @@ def linear_signal(self, D, bvalues, offset=0):
116116
offset : float
117117
The signal offset
118118
"""
119-
assert D >= 0, 'D must be >= 0'
119+
assert np.all(D >= 0), 'every value in D must be >= 0'
120120
data = -D * np.asarray(bvalues)
121121
return data + offset
122122

@@ -144,4 +144,4 @@ def multilinear_signal(self, D, F, S0, bvalues, offset=0):
144144
signal += f * self.linear_signal(d, bvalues)
145145
signal *= S0
146146
signal += offset
147-
return signal
147+
return signal

0 commit comments

Comments
 (0)