Skip to content

Commit

Permalink
Improve read_phantom and write_phantom
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillacorta committed Apr 1, 2024
1 parent 7568c2d commit 8fe9f0c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions KomaMRIBase/src/KomaMRIBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ export brain_phantom2D, brain_phantom3D, pelvis_phantom2D
export get_dims
# Motion
export MotionModel
export SimpleMotion, NoMotion, ArbitraryMotion
export SimpleMotionType
export NoMotion, SimpleMotion, ArbitraryMotion
export SimpleMotionType, SimpleMotionTypes
export Translation, Rotation, PeriodicTranslation, PeriodicRotation
export get_spin_coords, get_times
export LinearInterpolator
Expand Down
7 changes: 6 additions & 1 deletion KomaMRIBase/src/datatypes/phantom/motion/SimpleMotion.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# ------ SimpleMotionType
# ------ SimpleMotionTypes
global SimpleMotionTypes = ["Translation",
"Rotation",
"PeriodicTranslation",
"PeriodicRotation"]

abstract type SimpleMotionType{T<:Real} end

"""
Expand Down
10 changes: 5 additions & 5 deletions KomaMRIFiles/src/Phantom/Phantom.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ function import_motion(Ns::Int, motion_group::HDF5.Group, precision::Type)
for key in keys(types_group)
type_group = types_group[key]
type_str = match(r"^\d+_(\w+)", key).captures[1]
type = type_str == "Translation" ? Translation :
type_str == "Rotation" ? Rotation :
nothing
if type_str in SimpleMotionTypes
type = eval(Meta.parse(type_str)) # Use of eval is controlled
end
args = []
for key in fieldnames(type)
push!(args, read_attribute(type_group, string(key)))
Expand Down Expand Up @@ -178,10 +178,10 @@ function export_motion(motion_group::HDF5.Group, motion::SimpleMotion)
types_group = create_group(motion_group, "types")
counter = 1
for type in motion.types
type_group = create_group(types_group, string(counter)*"_"*match(r"^\w+", string(typeof(type))).match)
type_group = create_group(types_group, string(counter)*"_"*match(r"(?<=\.)[^\{\}]+", string(typeof(type))).match)
fields = fieldnames(typeof(type))
for field in fields
HDF5.attributes(type_group)[string(field)] = getfield(type, fieldcount)
HDF5.attributes(type_group)[string(field)] = getfield(type, field)
end
counter += 1
end
Expand Down

0 comments on commit 8fe9f0c

Please sign in to comment.