Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpretation of '.seq' files is not matching with sequence designed on PyPulseq #320

Closed
ZemaTimoteo opened this issue Mar 11, 2024 · 6 comments · Fixed by #321
Closed
Assignees
Labels
bug Something isn't working

Comments

@ZemaTimoteo
Copy link

What happened?

First, thank you for your nice repository, I found it very useful.

However, I am struggling with an issue regarding the interpretation of '.seq' files. Apparently, KomaMRI interpretates each block of gradient built in PyPulseq, with the need to start and finish at 0.

Here are the full concatenated blocks I want to perform in the simulations. However, as you can see they have unexpected behavior of going to zero between each block of gradients design in the Pypulseq.

Slide1

Here are an example of block 1 and 2 for Gz:
Block 1 - Koma
Block1_Koma
Block 1 - Pulseq
Block1_Pulseq
Block 2 - Koma
Block2_Koma

Block 1:2 - Koma
Block1to2_Koma
Block 1:2 - Pulseq
Block1to2_Pulseq

I feel like this shouldn't be the case, as I need to simulate the '.seq' and don't want to edit it in the Koma environment as it would make it a different sequence from the one I will design for further scanning.

Should I do something different, or is this something that needs to be update?

Best
ZemaTimoteo

Environment

OS x86_64-w64-mingw32
Julia 1.9.4
KomaMRIPlots 0.7.8
KomaMRI 0.7.5
KomaMRICore 0.7.6
@ZemaTimoteo ZemaTimoteo added the bug Something isn't working label Mar 11, 2024
@cncastillo
Copy link
Member

cncastillo commented Mar 11, 2024

Hi!

Thanks for using Koma 😄!

This issue is related to #205. While it looks weird, it is more of a plotting bug, as it has no impact on the simulations. The worst thing that it could do is to add a sample with amplitud 0 and duration 0 to the simulation, which has no effect.

Having said that, I don't think it is a hard one to solve. Could you provide this pulseq file to do some tests? 

In the meantime, we have tools to check what is actually being simulated. Take a look at the results of  plot_seqd(seq) (see it in the docs). It would be good to update Koma anyway, as we recently fixed a bug #315 which could have an impact on the simulation.

Cheers!

@cncastillo
Copy link
Member

I believe we found a case where this could affect the simulation, opened #321 to fix it.

@ZemaTimoteo
Copy link
Author

Having said that, I don't think it is a hard one to solve. Could you provide this pulseq file to do some tests?

  • I attatch the seq file that is give me this trouble. It is a simple MSE sequence.

MSE_test_KomaMRI.zip

  • I tried to run the code plot_seqd(seq) but i got the following error message:

`ERROR: MethodError: no method matching discretize(::Sequence; sim_params::Dict{String, Any})

Closest candidates are:
discretize(::Sequence; simParams) got unsupported keyword argument "sim_params"
@ KomaMRICore C:\Users\filia.julia\packages\KomaMRICore\wY77R\src\datatypes\simulation\DiscreteSequence.jl:53`

@beorostica
Copy link
Contributor

beorostica commented Mar 12, 2024

Hi @ZemaTimoteo!
Thank you for your MSE sequence. We are going to perform some tests with it 😃.

Can you please update your KomaMRI version? That is why you see ERROR: MethodError: no method matching discretize .... To do this, just type ] up in the REPL.

@cncastillo
Copy link
Member

Hi, to give an update on this. What we were doing differently. We hadn't added the heuristic that Pulseq uses for the first and last samples (more info here #321 (comment)). It is an easy fix and should be solved this week.

@cncastillo
Copy link
Member

cncastillo commented Apr 8, 2024

This has been solved in the current dev version of Koma (master). In some cases, the first sample is not exactly the same, but the difference is very small and only happens when the sample duration dt=0, so it had no effect in the simulation. We added tests to confirm this in

@testitem "Pulseq compat" tags=[:files, :pulseq] begin
using MAT, KomaMRIBase, Suppressor
# Aux functions
inside(x) = x[2:end-1]
namedtuple(x) = x[:]
namedtuple(d::Dict) = (; (Symbol(k == "df" ? "Δf" : k) => namedtuple(v) for (k,v) in d)...)
not_empty = ((ek, ep),) -> !isempty(ep.t)
# Reading files
path = joinpath(@__DIR__, "test_files/pulseq_read_comparison")
pulseq_files = filter(endswith(".seq"), readdir(path)) .|> x -> splitext(x)[1]
for pulseq_file in pulseq_files
#@show pulseq_file
seq_koma = @suppress read_seq("$path/$pulseq_file.seq")
seq_pulseq = matread("$path/$pulseq_file.mat")["sequence"] .|> namedtuple
@testset "$pulseq_file" begin
for i in 1:length(seq_koma)
blk_koma = get_samples(seq_koma, i)
blk_pulseq = NamedTuple{keys(blk_koma)}(seq_pulseq[i]) # Reorder keys
for (ev_koma, ev_pulseq) in Iterators.filter(not_empty, zip(blk_koma, blk_pulseq))
@test ev_koma.t ev_pulseq.t
@test inside(ev_koma.A) inside(ev_pulseq.A)
@test first(ev_koma.A) first(ev_pulseq.A) || ev_koma.t[2] ev_koma.t[1]
@test last(ev_koma.A) last(ev_pulseq.A)
end
end
end
end
end

plot_seq
seq

plot_seqd
seqd

Please let us know if you encounter any other issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants