Skip to content

Commit b7c88bb

Browse files
committed
add test
1 parent d84012a commit b7c88bb

6 files changed

+53
-2
lines changed

Project.toml

+11-1
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,24 @@ MRICoilSensitivities = "c57eb701-aafc-44a2-a53c-128049758959"
99
MRIFiles = "5a6f062f-bf45-497d-b654-ad17aae2a530"
1010
MRIReco = "bdf86e05-2d2b-5731-a332-f3fe1f9e047f"
1111
NIfTI = "a3a9e032-41b5-5fc4-967a-a6b7a19844d3"
12+
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1213
QuantitativeMRI = "659767e3-31a7-4dc1-8563-6e03f484b231"
1314
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1415

1516
[compat]
17+
JSON = "0.21"
18+
MRICoilSensitivities = "0.1.3"
19+
MRIFiles = "0.3.2"
20+
MRIReco = "0.9.0"
21+
NIfTI = "0.6.0"
22+
Pkg = "1.10"
23+
QuantitativeMRI = "0.1.3"
24+
Statistics = "1.10"
1625
julia = "1.10"
1726

1827
[extras]
1928
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
29+
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
2030

2131
[targets]
22-
test = ["Test"]
32+
test = ["Test","LazyArtifacts"]

src/BIDS.jl

+14
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ function write_bids_MP2RAGE(d::Dict,subname::AbstractString,folder="")
7474
p_MP2 = d["params_MP2RAGE"]
7575

7676
# define JSON dict
77+
proj = Pkg.project()
78+
gen_dict = Dict{Any,Any}()
79+
gen_dict["Name"] = proj.name
80+
gen_dict["Version"] = string(proj.version)
81+
7782
JSON_dict = Dict{Any,Any}()
7883
JSON_dict["InversonTime"]= [p_MP2.TI₁,p_MP2.TI₂] #s
7984
JSON_dict["RepetitionTimeExcitation"]= p_MP2.TR
@@ -82,10 +87,19 @@ function write_bids_MP2RAGE(d::Dict,subname::AbstractString,folder="")
8287
JSON_dict["FlipAngle"]= [p_MP2.α₁,p_MP2.α₂]
8388
JSON_dict["MagneticFieldStrength"] = MagneticField
8489
JSON_dict["Units"] = "arbitrary"
90+
JSON_dict["GeneratedBy"]=gen_dict
91+
8592

8693
# Write the dictionary to a JSON file
8794
open(joinpath(folder,subname,"MP2RAGE.json"), "w") do f
8895
JSON.print(f, JSON_dict, 4) # Indent 4 spaces for readability
8996
end
9097

98+
# Write dataset description
99+
100+
101+
JSON_dict = Dict{Any,Any}()
102+
JSON_dict["generatedBy"] = proj.name
103+
JSON_dict["version"] = proj.version
104+
91105
end

src/SEQ_BRUKER_a_MP2RAGE_CS_360.jl

+2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ using QuantitativeMRI
88
using Statistics
99
using JSON
1010
using NIfTI
11+
using Pkg
1112

1213
# Write your package code here.
1314
include("bruker_sequence.jl")
1415
include("reconstruction.jl")
1516
include("BIDS.jl")
17+
1618
end

src/reconstruction.jl

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ function reconstruction_MP2RAGE(path_bruker;mean_NR::Bool = false,paramsCS=Dict(
5858
params = merge(params,paramsCS)
5959

6060
x_approx = reconstruction(acq, params).data
61+
6162
if mean_NR
6263
x_approx = mean(x_approx,dims=6) # average accross repetition
6364
end

test/Artifacts.toml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[MP2RAGE_data]
2+
git-tree-sha1 = "04cd4c29bb9e2aeb5384fbc70a9af0e1a37ca369"
3+
4+
[[MP2RAGE_data.download]]
5+
sha256 = "1f1b703c79db66ba6ef620651eca431cb0319d87f1eafa53826cb11a93afe4a8"
6+
url = "https://zenodo.org/records/14051522/files/data.tar.gz"

test/runtests.jl

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
using SEQ_BRUKER_a_MP2RAGE_CS_360
22
using Test
3+
using LazyArtifacts
4+
using SEQ_BRUKER_a_MP2RAGE_CS_360.NIfTI
5+
using SEQ_BRUKER_a_MP2RAGE_CS_360.JSON
36

47
@testset "SEQ_BRUKER_a_MP2RAGE_CS_360.jl" begin
5-
# Write your tests here.
8+
datadir = artifact"MP2RAGE_data"
9+
@info "The test data is located at $datadir."
10+
11+
path_bruker = joinpath(datadir, "MP2RAGE_FULLY")
12+
d = reconstruction_MP2RAGE(path_bruker; mean_NR=true)
13+
14+
@test size(d["im_reco"]) == (128,128,96,1,2)
15+
@test size(d["T1map"]) == (128,128,96,1)
16+
17+
write_bids_MP2RAGE(d,"sub","")
18+
19+
ni = niread(joinpath("sub","anat","sub_T1map.nii.gz")).raw
20+
@test d["T1map"] == ni
21+
22+
JSON_dict = JSON.parsefile(joinpath("sub","MP2RAGE.json"))
23+
@test JSON_dict["RepetitionTimePreparation"] == 5000
624
end

0 commit comments

Comments
 (0)