Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
aTrotier committed Nov 15, 2024
1 parent d84012a commit b7c88bb
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ MRICoilSensitivities = "c57eb701-aafc-44a2-a53c-128049758959"
MRIFiles = "5a6f062f-bf45-497d-b654-ad17aae2a530"
MRIReco = "bdf86e05-2d2b-5731-a332-f3fe1f9e047f"
NIfTI = "a3a9e032-41b5-5fc4-967a-a6b7a19844d3"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
QuantitativeMRI = "659767e3-31a7-4dc1-8563-6e03f484b231"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[compat]
JSON = "0.21"
MRICoilSensitivities = "0.1.3"
MRIFiles = "0.3.2"
MRIReco = "0.9.0"
NIfTI = "0.6.0"
Pkg = "1.10"
QuantitativeMRI = "0.1.3"
Statistics = "1.10"
julia = "1.10"

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

[targets]
test = ["Test"]
test = ["Test","LazyArtifacts"]
14 changes: 14 additions & 0 deletions src/BIDS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ function write_bids_MP2RAGE(d::Dict,subname::AbstractString,folder="")
p_MP2 = d["params_MP2RAGE"]

# define JSON dict
proj = Pkg.project()
gen_dict = Dict{Any,Any}()
gen_dict["Name"] = proj.name
gen_dict["Version"] = string(proj.version)

JSON_dict = Dict{Any,Any}()
JSON_dict["InversonTime"]= [p_MP2.TI₁,p_MP2.TI₂] #s
JSON_dict["RepetitionTimeExcitation"]= p_MP2.TR
Expand All @@ -82,10 +87,19 @@ function write_bids_MP2RAGE(d::Dict,subname::AbstractString,folder="")
JSON_dict["FlipAngle"]= [p_MP2.α₁,p_MP2.α₂]
JSON_dict["MagneticFieldStrength"] = MagneticField
JSON_dict["Units"] = "arbitrary"
JSON_dict["GeneratedBy"]=gen_dict


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

# Write dataset description


JSON_dict = Dict{Any,Any}()
JSON_dict["generatedBy"] = proj.name
JSON_dict["version"] = proj.version

end
2 changes: 2 additions & 0 deletions src/SEQ_BRUKER_a_MP2RAGE_CS_360.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ using QuantitativeMRI
using Statistics
using JSON
using NIfTI
using Pkg

# Write your package code here.
include("bruker_sequence.jl")
include("reconstruction.jl")
include("BIDS.jl")

end
1 change: 1 addition & 0 deletions src/reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function reconstruction_MP2RAGE(path_bruker;mean_NR::Bool = false,paramsCS=Dict(
params = merge(params,paramsCS)

x_approx = reconstruction(acq, params).data

if mean_NR
x_approx = mean(x_approx,dims=6) # average accross repetition
end
Expand Down
6 changes: 6 additions & 0 deletions test/Artifacts.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[MP2RAGE_data]
git-tree-sha1 = "04cd4c29bb9e2aeb5384fbc70a9af0e1a37ca369"

[[MP2RAGE_data.download]]
sha256 = "1f1b703c79db66ba6ef620651eca431cb0319d87f1eafa53826cb11a93afe4a8"
url = "https://zenodo.org/records/14051522/files/data.tar.gz"
20 changes: 19 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
using SEQ_BRUKER_a_MP2RAGE_CS_360
using Test
using LazyArtifacts
using SEQ_BRUKER_a_MP2RAGE_CS_360.NIfTI
using SEQ_BRUKER_a_MP2RAGE_CS_360.JSON

@testset "SEQ_BRUKER_a_MP2RAGE_CS_360.jl" begin
# Write your tests here.
datadir = artifact"MP2RAGE_data"
@info "The test data is located at $datadir."

path_bruker = joinpath(datadir, "MP2RAGE_FULLY")
d = reconstruction_MP2RAGE(path_bruker; mean_NR=true)

@test size(d["im_reco"]) == (128,128,96,1,2)
@test size(d["T1map"]) == (128,128,96,1)

write_bids_MP2RAGE(d,"sub","")

ni = niread(joinpath("sub","anat","sub_T1map.nii.gz")).raw
@test d["T1map"] == ni

JSON_dict = JSON.parsefile(joinpath("sub","MP2RAGE.json"))
@test JSON_dict["RepetitionTimePreparation"] == 5000
end

0 comments on commit b7c88bb

Please sign in to comment.