Skip to content

Commit 2ce1948

Browse files
authored
Hacky fix for waveforms_and_times rf append floating point issue. (#114)
* Hacky fix for waveforms_and_times rf append floating point issue. * Use rf raster instead of eps
1 parent 145557b commit 2ce1948

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pypulseq/Sequence/sequence.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ def waveforms_and_times(
14571457
[curr_dur + t, block.rf.freq_offset, block.rf.phase_offset]
14581458
)
14591459
if append_RF:
1460+
14601461
rf_piece = np.array(
14611462
[
14621463
curr_dur + rf.delay + rf.t,
@@ -1470,12 +1471,12 @@ def waveforms_and_times(
14701471
out_len[-1] += len(rf.t)
14711472

14721473
if np.abs(rf.signal[0]) > 0:
1473-
pre = np.array([[curr_dur + rf.delay + rf.t[0] - eps], [0]])
1474+
pre = np.array([[rf_piece[0, 0] - 0.1*self.system.rf_raster_time], [0]])
14741475
rf_piece = np.hstack((pre, rf_piece))
14751476
out_len[-1] += pre.shape[1]
14761477

14771478
if np.abs(rf.signal[-1]) > 0:
1478-
post = np.array([[curr_dur + rf.delay + rf.t[-1] + eps], [0]])
1479+
post = np.array([[rf_piece[0, -1] + 0.1*self.system.rf_raster_time], [0]])
14791480
rf_piece = np.hstack((rf_piece, post))
14801481
out_len[-1] += post.shape[1]
14811482

@@ -1519,11 +1520,15 @@ def waveforms_and_times(
15191520
:, wave_cnt[j] + np.arange(length - 1)
15201521
] = wave_data_local[:, 1:]
15211522
wave_cnt[j] += length - 1
1522-
if wave_cnt[j] != len(np.unique(wave_data[j][0, : wave_cnt[j]])):
1523+
1524+
rftdiff = np.diff(wave_data[j][0, : wave_cnt[j]])
1525+
if np.any(rftdiff < eps):
15231526
raise Warning(
1524-
"Not all elements of the generated time vector are unique."
1527+
"Time vector elements are not monotonically increasing."
15251528
)
15261529

1530+
1531+
15271532
# Trim output data
15281533
for j in range(shape_channels):
15291534
if wave_cnt[j] < wave_data[j].shape[1]:

0 commit comments

Comments
 (0)