imr-framework / pypulseq

Pulseq in Python
https://pypulseq.readthedocs.io
GNU Affero General Public License v3.0
112 stars 58 forks source link

Issue adding new shape #106

Closed tblazey closed 1 year ago

tblazey commented 1 year ago

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

https://github.com/imr-framework/pypulseq/blob/c246ff9ff0018ab9b5a6b4add3850f068f61b034/pypulseq/event_lib.py#L109-L111

sravan953 commented 1 year ago

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!

tblazey commented 1 year ago

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

siemens_pyr_plateau_slab_rf.csv

sravan953 commented 1 year ago

Thanks for catching this, and also submitting a PR to fix this!

btasdelen commented 1 year ago

Fixed in #111.