imr-framework / pypulseq

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

Indexing mistake in seq read helper function #28

Closed tonggehua closed 4 years ago

tonggehua commented 4 years ago

Describe the bug Around line 200 in sequence.py, in the function rf_from_lib_data(), there has been a change between version 1.2.1 and 1.2.0 that seems to fix the error message but reads the sequence incorrectly.

# 1.2.1 (gives error message in cases that lib_data has length less than or equal to 6)
        rf.delay = lib_data[3]
        rf.freq_offset = lib_data[4]
        rf.phase_offset = lib_data[5]

        if max(lib_data.shape) < 6:
            lib_data = np.append(lib_data, 0)
        rf.dead_time = lib_data[6]

        if max(lib_data.shape) < 7:
            lib_data = np.append(lib_data, 0)
        rf.ringdown_time = lib_data[7]

        if max(lib_data.shape) < 8:
            lib_data = np.append(lib_data, 0)

        use_cases = {1: 'excitation', 2: 'refocusing', 3: 'inversion'}
        if lib_data[8] in use_cases:
            rf.use = use_cases[lib_data[8]]
# 1.2.0 (current version; reads the data incorrectly)
        rf.delay = lib_data[3]
        rf.freq_offset = lib_data[4]
        rf.phase_offset = lib_data[5] ## <<< note this 

        if max(lib_data.shape) < 6:
            lib_data = np.append(lib_data, 0)
        rf.dead_time = lib_data[5] ## <<< and note this

        if max(lib_data.shape) < 7:
            lib_data = np.append(lib_data, 0)
        rf.ringdown_time = lib_data[6]

        if max(lib_data.shape) < 8:
            lib_data = np.append(lib_data, 0)

        use_cases = {1: 'excitation', 2: 'refocusing', 3: 'inversion'}
        if lib_data[7] in use_cases:
            rf.use = use_cases[lib_data[7]]

For reference, the fields contained in lib_data in the case of an RF pulse are: lib_data[0] : RF amplitude lib_data[1] : RF magnitude waveform ID lib_data[2] : RF phase waveform ID lib_data[3] : RF delay lib_data[4] : RF frequency offset lib_data[5] : RF phase offset

Right now (1.2.0), the code is reading the phase offset as the dead time.

Desktop (please complete the following information):

sravan953 commented 4 years ago

@tonggehua Thanks for reporting this bug. Please let me know if commit 2e8d28c4f69348e29bafb06d9bf57e9e0150ee52 fixes this issue for you. As always, you can pip install the latest commit by doing so: pip install git+git://github.com/imr-framework/pypulseq.git@2e8d28c4f69348e29bafb06d9bf57e9e0150ee52

sravan953 commented 4 years ago

@tonggehua Is your issue fixed?