Skip to content

Commit

Permalink
test case with 3d data was added in testAcqData.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
atsanda committed Dec 19, 2024
1 parent 4bf4019 commit 7bb3541
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 5 deletions.
50 changes: 49 additions & 1 deletion MRIBase/test/Utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using MRIBase

export get_default_cartesian_raw_acq_data

function get_default_cartesian_raw_acq_data(n_profiles, n_samples_per_profile, data = nothing)
function get_default_cartesian_raw_acq_data_2d(n_profiles, n_samples_per_profile, data = nothing)
params = Dict{String, Any}()
params["trajectory"] = "Cartesian"
params["encodedSize"] = [n_samples_per_profile, n_profiles]
Expand Down Expand Up @@ -31,4 +31,52 @@ function get_default_cartesian_raw_acq_data(n_profiles, n_samples_per_profile, d
)
return f
end


function get_default_cartesian_raw_acq_data_3d(n_slices, n_profiles, n_samples_per_profile, data = nothing, mask=nothing)
params = Dict{String, Any}()
params["trajectory"] = "Cartesian"
params["encodedSize"] = [n_samples_per_profile, n_profiles, n_slices]
params["encodedFOV"] = [n_samples_per_profile, n_profiles, n_slices]

traj_nodes = kspaceNodes(trajectory(Float32, "Cartesian3D", n_profiles, n_samples_per_profile, numSlices=n_slices))
traj_nodes = reshape(traj_nodes, 3, n_samples_per_profile, n_profiles, n_slices)
if data == nothing
data = rand(ComplexF32, n_samples_per_profile, n_profiles, n_slices)
end

n_elemens = mask == nothing ? n_profiles*n_slices : sum(mask)
profiles = Vector{Profile}(undef, n_elemens)
i = 1
for i_profile in 1:n_profiles
for i_slice in 1:n_slices
if mask != nothing && !mask[1, i_profile, i_slice]
continue
end

profile_head = AcquisitionHeader(
idx = EncodingCounters(
kspace_encode_step_1 = i_profile - 1,
kspace_encode_step_2 = i_slice - 1,
),
center_sample = div(n_samples_per_profile, 2),
trajectory_dimensions=3,
)
# profiles[(i_slice-1)*n_profiles+i_profile] = Profile(
profiles[i] = Profile(
profile_head,
traj_nodes[:, :, i_profile, i_slice],
reshape(data[:, i_profile, i_slice], n_samples_per_profile, 1),
)
i += 1
end
end

f = RawAcquisitionData(
params,
profiles,
)
return f
end

end
25 changes: 23 additions & 2 deletions MRIBase/test/testAcqData.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
using .Utils: get_default_cartesian_raw_acq_data
using .Utils: get_default_cartesian_raw_acq_data_2d, get_default_cartesian_raw_acq_data_3d


@testset "kDataCart restores the order when profiles are shuffled" begin
n_profiles = 10
n_samples_per_profile = 12
data = rand(ComplexF32, n_samples_per_profile, n_profiles)
f = get_default_cartesian_raw_acq_data(n_profiles, n_samples_per_profile, data)
f = get_default_cartesian_raw_acq_data_2d(n_profiles, n_samples_per_profile, data)
f.profiles = shuffle(f.profiles)
acq = AcquisitionData(f)
kdata = kDataCart(acq)[:, :, 1, 1, 1, 1]
@test isapprox(kdata, data)
end


@testset "kDataCart restores the order when profiles are shuffled for 3D data" begin
n_profiles = 10
n_samples_per_profile = 12
n_slices = 3
data = rand(ComplexF32, n_samples_per_profile, n_profiles, n_slices)
elipsoid_mask = zeros(Bool, 1, n_profiles, n_slices)
for i in 1:n_profiles
for j in 1:n_slices
elipsoid_mask[1, i, j] = (i-5)^2/25 + (j-2)^2/4 < 0.5
end
end
data .*= elipsoid_mask
f = get_default_cartesian_raw_acq_data_3d(n_slices, n_profiles, n_samples_per_profile, data, elipsoid_mask)
f.profiles = shuffle(f.profiles)
acq = AcquisitionData(f)
kdata = kDataCart(acq)[:, :, :, 1, 1, 1]

@test isapprox(kdata, data)
end
16 changes: 14 additions & 2 deletions MRIBase/test/testRawAcqData.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
using Random
using MRIBase
using .Utils: get_default_cartesian_raw_acq_data
using .Utils: get_default_cartesian_raw_acq_data_2d


@testset "MRIBase.rawdata with dense 2D cartesian data" begin
n_profiles = 10
n_samples_per_profile = 12
data = rand(ComplexF32, n_samples_per_profile, n_profiles)
f = get_default_cartesian_raw_acq_data(n_profiles, n_samples_per_profile, data)
f = get_default_cartesian_raw_acq_data_2d(n_profiles, n_samples_per_profile, data)
kdata = MRIBase.rawdata(f)
kdata = reshape(kdata, n_samples_per_profile, n_profiles)
@test isapprox(kdata, data)
end


@testset "MRIBase.rawdata is not supposed to handle shuffles profiles" begin
n_profiles = 10
n_samples_per_profile = 12
data = rand(ComplexF32, n_samples_per_profile, n_profiles)
f = get_default_cartesian_raw_acq_data_2d(n_profiles, n_samples_per_profile, data)
shuffle!(f.profiles)
kdata = MRIBase.rawdata(f)
kdata = reshape(kdata, n_samples_per_profile, n_profiles)
@test !isapprox(kdata, data)
end

0 comments on commit 7bb3541

Please sign in to comment.