Skip to content

Commit

Permalink
Use ASCCONV from Phoenix header (#5)
Browse files Browse the repository at this point in the history
* Overwrite metadata from Phoenix' ASCCONV (previously only extract MeasYaps) if same key found since MeasYaps is sometimes inconsistent with others section, especially in frequency.

* Log the difference in warning.
  • Loading branch information
darrencl authored Dec 1, 2020
1 parent 1d81be2 commit f2a9d1c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
21 changes: 20 additions & 1 deletion src/io_twix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,32 @@ function load_twix(io::IO; header_only=false, acquisition_filter=(acq)->true,
@debug "Header section names" keys(header_sections)
metadata = Dict{String,Any}()
try
phoenix_ascconv = match(r"(### ASCCONV BEGIN.*### ASCCONV END ###)"s,
header_sections["Phoenix"]).captures[1]
yaps_meta = parse_header_yaps(header_sections["MeasYaps"])
phoenix_ascconv_meta = parse_header_yaps(phoenix_ascconv)

# Check if the same key has different value in yaps and phoenix to warn user
differences = Dict()
for k in intersect(Set(keys(yaps_meta)), Set(keys(phoenix_ascconv_meta)))
if yaps_meta[k] != phoenix_ascconv_meta[k]
differences[k] = (MeasYapsASCCONV=yaps_meta[k],
PhoenixASCCONV=phoenix_ascconv_meta[k])
end
end
if length(differences) > 0
@warn """
Different values found in MeasYaps and Phoenix ASCCONV section. As per
our testing in getting the correct frequency, MeasYaps sometimes is not
consistent with other sections, so this metadata is extracted from Phoenix.
""" differences
end
dicom_meta = match_xprot_header(header_sections["Dicom"], "Dicom.",
["SoftwareVersions", "DeviceSerialNumber", "InstitutionName", "Manufacturer", "ManufacturersModelName"])
meas_meta = match_xprot_header(header_sections["Meas"], "Meas.",
["tReferenceImage0", "tReferenceImage1", "tReferenceImage2",
"tFrameOfReference"])
metadata = merge(metadata, yaps_meta, dicom_meta, meas_meta)
metadata = merge(metadata, yaps_meta, phoenix_ascconv_meta, dicom_meta, meas_meta)
catch exc
@error "Could not parse header metadata" exception=(exc,catch_backtrace())
end
Expand Down
2 changes: 2 additions & 0 deletions test/io_twix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ end

@testset "twix quality control" begin
twix = @test_logs (Logging.Warn,r"Unexpected empty meas packet") #=
=# (Logging.Warn,r"Different values found in MeasYaps") #=
=# load_twix("twix/sub-SiemensBrainPhantom_seq-svslcosy_incomplete.twix")
@test MagneticResonanceSignals.AcquisitionsIncomplete in twix.quality_control

Expand All @@ -99,6 +100,7 @@ end
truncated_twix = copy(valid_twix_bytes)
truncated_twix = truncated_twix[1:900_000]
twix = @test_logs (Logging.Warn,r"Twix acquisition truncated at position 900000") #=
=# (Logging.Warn,r"Different values found in MeasYaps") #=
=# load_twix(IOBuffer(truncated_twix))
@test MagneticResonanceSignals.AcquisitionsIncomplete in twix.quality_control
end
Expand Down
3 changes: 2 additions & 1 deletion test/mr_load.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ using Logging

@testset "mr_load integration test" begin
# TODO: This is far too trivial! should get / generate some better test data.
cosy = @test_logs (:warn,r"Sequence.*is not one of the versions I recognize"s) #=
cosy = @test_logs (:warn,r"Different values found in MeasYaps") #=
=# (:warn,r"Sequence.*is not one of the versions I recognize"s) #=
=# mr_load("twix/sub-SiemensBrainPhantom_seq-svslcosy_inc-1.twix")

@test size(cosy.lcosy_scans) == (1,1)
Expand Down
2 changes: 1 addition & 1 deletion test/processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ end
end

@testset "lcosy" begin
lcosy = @test_logs (:warn,) mr_load("twix/sub-SiemensBrainPhantom_seq-svslcosy_inc-1.twix")
lcosy = @test_logs (:warn,) (:warn,) mr_load("twix/sub-SiemensBrainPhantom_seq-svslcosy_inc-1.twix")

signal = simple_averaging(lcosy)
@test size(signal) == (2048,1)
Expand Down

0 comments on commit f2a9d1c

Please sign in to comment.