Issue adding new shape
tblazey opened this issue · 4 comments
Hi,
I've been having a problem adding rf blocks with different phase modulation to my sequence. I can add the first couple of pulses, but after that I see repeated shapes when I plot the sequence. After a bit of searching, I think I have narrowed it down to the find_or_insert function in event_lib.py. With my shapes, find_or_insert was reporting there was an identical shape in the dictionary even when that shape wasn't present.
I believe the issue is that because my shapes are longer than numpy.get_printoptions()['threshold'], array2string is returning a shortened string with just the the first and last few elements separated by a '...'. In my case, many of the shapes I wanted to add had the same beginning and ending values. If set the threshold parameter in array2string to np.inf, I can add the additional shapes.
Thanks,
-Tyler
pypulseq/pypulseq/event_lib.py
Lines 109 to 111 in c246ff9
Hello! Thanks for reporting the bug and also identifying a workaround. Could you please share code to reproduce the bug? If you're also interested in submitting a PR to fix this bug, I'd much appreciate it!
Hi,
An example is below. I actually had a bit of trouble reproducing the bug with generic pulses, so I have attached my pulse as well. I suspect that this issue interacts with shape compression in some way, but I'm not sure how.
import pypulseq as pp
import numpy as np
#Create sequence object
seq = pp.Sequence()
#Load in rf pulse
rf_data = np.loadtxt('siemens_pyr_plateau_slab_rf.csv', delimiter=',')
rf_pulse = rf_data[0, :] * np.exp(1j * rf_data[1, :])
#Loop through phases
n = 8
for i in range(n):
#Add new RF pulse to sequence
rf_ev = pp.make_arbitrary_rf(rf_pulse * np.exp(1j * np.pi / n * i), np.pi / 2, system=seq.system)
seq.add_block(rf_ev)
#Print RF ID
print(seq.block_events[i + 1][1])
By default, I only see one shape and the code prints '1, 1, 1, 1, 1, 1, 1, 1'. With the change in #108, it prints '1, 2, 3, 4, 5, 6, 7, 8'.
Thanks!
-Tyler
Thanks for catching this, and also submitting a PR to fix this!