Skip to content

Commit

Permalink
Add fastmri, HDF5
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffFessler committed Jul 24, 2019
1 parent 5588e20 commit d7b240c
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 3 deletions.
115 changes: 115 additions & 0 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,146 @@
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[BinDeps]]
deps = ["Compat", "Libdl", "SHA", "URIParser"]
git-tree-sha1 = "12093ca6cdd0ee547c39b1870e0c9c3f154d9ca9"
uuid = "9e28174c-4ba2-5203-b857-d8d62c4213ee"
version = "0.8.10"

[[BinaryProvider]]
deps = ["Libdl", "Logging", "SHA"]
git-tree-sha1 = "c7361ce8a2129f20b0e05a89f7070820cfed6648"
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
version = "0.5.6"

[[Blosc]]
deps = ["BinaryProvider", "CMakeWrapper", "Compat", "Libdl"]
git-tree-sha1 = "71fb23581e1f0b0ae7be8ccf0ebfb3600e23ca41"
uuid = "a74b3585-a348-5f62-a45c-50e91977d574"
version = "0.5.1"

[[CMake]]
deps = ["BinDeps"]
git-tree-sha1 = "c67a8689dc5444adc5eb2be7d837100340ecba11"
uuid = "631607c0-34d2-5d66-819e-eb0f9aa2061a"
version = "1.1.2"

[[CMakeWrapper]]
deps = ["BinDeps", "CMake", "Libdl", "Parameters", "Test"]
git-tree-sha1 = "16d4acb3d37dc05b714977ffefa8890843dc8985"
uuid = "d5fb7624-851a-54ee-a528-d3f3bac0b4a0"
version = "0.2.3"

[[Compat]]
deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"]
git-tree-sha1 = "84aa74986c5b9b898b0d1acaf3258741ee64754f"
uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
version = "2.1.0"

[[Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[DelimitedFiles]]
deps = ["Mmap"]
uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab"

[[Distributed]]
deps = ["Random", "Serialization", "Sockets"]
uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[[HDF5]]
deps = ["BinaryProvider", "Blosc", "Libdl", "Mmap"]
git-tree-sha1 = "635ae44613c8c8dcf5d5b0084bfa00abea498e1f"
uuid = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
version = "0.12.0"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"

[[LibGit2]]
uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"

[[Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"

[[LinearAlgebra]]
deps = ["Libdl"]
uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[[Logging]]
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[Markdown]]
deps = ["Base64"]
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"

[[Mmap]]
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[OrderedCollections]]
deps = ["Random", "Serialization", "Test"]
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.1.0"

[[Parameters]]
deps = ["OrderedCollections"]
git-tree-sha1 = "1dfd7cd50a8eb06ef693a4c2bbe945943cd000c5"
uuid = "d96e819e-fc66-5662-9728-84c9c7592b0a"
version = "0.11.0"

[[Pkg]]
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[[Printf]]
deps = ["Unicode"]
uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"

[[REPL]]
deps = ["InteractiveUtils", "Markdown", "Sockets"]
uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"

[[Random]]
deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"

[[Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"

[[SharedArrays]]
deps = ["Distributed", "Mmap", "Random", "Serialization"]
uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"

[[Sockets]]
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"

[[SparseArrays]]
deps = ["LinearAlgebra", "Random"]
uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[[Statistics]]
deps = ["LinearAlgebra", "SparseArrays"]
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[[Test]]
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[[URIParser]]
deps = ["Test", "Unicode"]
git-tree-sha1 = "6ddf8244220dfda2f17539fa8c9de20d6c575b69"
uuid = "30578b45-9adc-5946-b283-645ec420af67"
version = "0.4.0"

[[UUIDs]]
deps = ["Random", "SHA"]
uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[[Unicode]]
uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ uuid = "274281c4-ae57-11e9-2014-65d3d5d9358c"
authors = ["[email protected] <[email protected]>"]
version = "0.1.0"

[compat]
julia = "1.1"

[deps]
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
julia = "1.1"
2 changes: 2 additions & 0 deletions src/MIRTio.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module MIRTio

include("fastmri/hdf5utils.jl")

include("ge-mri/pfile.jl")
#include("ge-mri/rdb-26_002.jl") # not
include("ge-mri/read_rdb_hdr.jl")
Expand Down
107 changes: 107 additions & 0 deletions src/fastmri/hdf5utils.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#=
hdf5utils.jl
Utilities for reading HDF5 data files for the 2019 fastMRI challenge.
Code by Steven Whitaker
Documentation by Jeff Fessler
=#

export h5_get_keys, h5_get_attributes, h5_get_ismrmrd
export h5_get_ESC, h5_get_RSS, h5_get_kspace

using HDF5


"""
`h5_getkeys(filename::String)`
Get `names` from file. Returns a `?`
"""
function h5_get_keys(filename::String)

return h5open(filename, "r") do file
names(file)
end

end


"""
`h5_get_attributes(filename::String)`
Get `attrs` from file. Returns a `Dict`
"""
function h5_get_attributes(filename::String)

return h5open(filename, "r") do file
a = attrs(file)
attr = Dict{String,Any}()
for s in names(a)
attr[s] = read(a[s])
end
attr
end

end

"""
`h5_get_ismrmrd(filename::String)`
Get ISMRM header data from file. Returns a `?`
"""
function h5_get_ismrmrd(filename::String)

return h5read(filename, "ismrmrd_header")

end


"""
`h5_get_ESC(filename::String; T::DataType = ComplexF32)`
Return `Array` of ESC (emulated single coil) data from file.
HDF5.jl reads the data differently than Python's h5py.
This is significant because the fastMRI paper
says that the datasets have certain dimensionality,
but the dimensions are permuted in Julia compared to Python,
hence the calls to `permutedims` in the following functions.
"""
function h5_get_ESC(filename::String; T::DataType = ComplexF32)

data = T.(h5read(filename, "reconstruction_esc"))
return permutedims(data, ndims(data):-1:1)

end


"""
`h5_get_RSS(filename::String; T::DataType = ComplexF32)`
Return `Array` of RSS (root sum of squares) data from file.
"""
function h5_get_RSS(filename::String; T::DataType = ComplexF32)

data = T.(h5read(filename, "reconstruction_rss"))
return permutedims(data, ndims(data):-1:1)

end


"""
`h5_get_kspace(filename::String; T::DataType = ComplexF32))`
Return `Array` of kspace data from file.
"""
function h5_get_kspace(filename::String; T::DataType = ComplexF32)

data = h5open(filename, "r") do file
readmmap(file["kspace"], Array{getcomplextype(file["kspace"])})
end
return permutedims(T.(data), ndims(data):-1:1)

end


#=
Copied (basically) from
https://github.com/MagneticParticleImaging/MPIFiles.jl/blob/79711bf7af389f9e2dd4b0370e64040e5da1e193/src/Utils.jl#L33
=#
function getcomplextype(dataset)
T = HDF5.hdf5_to_julia_eltype(
HDF5Datatype(HDF5.h5t_get_member_type(datatype(dataset).id, 0)))
return Complex{T}
end

0 comments on commit d7b240c

Please sign in to comment.