Closed jweine closed 1 year ago
@jweine Issue #72 was related to this, fixed in PR #84. Please try it out and let me know!
@sravan953 Negative, unit test still fails:
======================================================================
FAIL: test_correct_start_trap (GradWaveformUT.TestGradientWaveform)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/bilal/Insync/tasdelen@usc.edu/GoogleDrive/codebase/pulseq_sequences/bilal_seqs/GradWaveformUT.py", line 16, in test_correct_start_trap
self.assertTrue(np.allclose(wf[:, 0], 0, rtol=1e-10),
AssertionError: False is not true : First gridded sample is not zero
----------------------------------------------------------------------
I feel like the issue arises from the use of interpolation in the points_to_waveform(), as @jweine pointed out. I will take a look at the issue and see if I can come up with a better solution.
Update: Behavior is the same between 'Pulseq' and 'PyPulseq'. 'The issue' comes from the convention Siemens uses, shifting gradient sampling by half raster time, or equivalently, sampling the gradients at the center, not the edges. I believe confusion comes from the fact that, we use shifted gradients for visualization, when in fact, it makes more sense to display non shifted ones.
If we also plot the time-axis, as the first sample will not be at time=0, but time=GRT/2, it all makes sense. So I believe there is no bug here, just a confusing feature.
@bilal-tasdelen Thanks for following up on this. The existence of this shift is mentioned in the pulseq file format definition when using arbitrary gradients and rf-waveforms but not Trapezoidals. But I couldn't find the actual reason for using the shift / center-sampling. I feel it should be documented that this is a Siemens specific feature, as i don't think it is intuitive without more context (especially for non-siemens sites :)). Personally I think, this behaviour should not be presented to user but handled in the Siemens sequence export. But this is more of a design decision to be discussed also with the Pulseq project. Anyway, thanks for the clarification!
Describe the bug When creating a sequence that contains trapezoidal gradient lobes using
make_trapezoid
, the result ofSequence.gradient_waveforms()
shows an incorrectly gridded waveform. When gridded (by calling the functionSequence.gridded_wave_forms()
which in subsequently calls the function `pypulseq.points_to_waveform'), the waveform timing starts at grad_raster_time/2. When defining trapezoids such that the interval border of the piecewise linear function lie exactly on a regular grid with spacing grad_raster_time, this results in 'capped off' corners, a non-zero start value as well as a bend waveform in the last interval.Not sure why the function pypulseq.points_to_waveform performs the time-grid shift of grad_raster_time/2 but for this case it should not be applied.
So, if this is intentional in some cases this conditional needs to be revised to catch the correct case for the trapezoidal gradients.
To Reproduce
Expected behavior
My expectation is, that the reference-points of normalized amplitude [0, 1, 1, 0] at times [0, rise_time, rise_time+flat_time, rise_time+flat_time+fall_time] should be met exactly if all time-points match the grad_raster_time as shown in the figure below.
Desktop (please complete the following information):
pypulseq
version: 1.3.1.post1Additional context To catch errors like this i propose to add a test similar to the following: