imr-framework / pypulseq

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

Fix usage of np.max #89

Closed fzimmermann89 closed 1 year ago

fzimmermann89 commented 1 year ago

Before, the three values were interpreted as thee parameters to the max function, i.e. as array, axis and out instead of choosing the maximum of those values. This issue was introduced by #84 Just passing the values as a tuple fixes this

fzimmermann89 commented 1 year ago

old traceback:

 File "lib/python3.8/site-packages/pypulseq/Sequence/sequence.py", line 214, in calculate_kspace
    gw = self.gradient_waveforms()
  File "lib/python3.8/site-packages/pypulseq/Sequence/sequence.py", line 636, in gradient_waveforms
    max_t = np.round(np.max(tx_e, ty_e, tz_e)/dt)*dt
  File "<__array_function__ internals>", line 180, in amax
  File "lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 2793, in amax
    return _wrapreduction(a, np.maximum, 'max', axis, None, out,
  File "lib/python3.8/site-packages/numpy/core/fromnumeric.py", line 84, in _wrapreduction
    return reduction(axis=axis, out=out, **passkwargs)
  File "lib/python3.8/site-packages/numpy/core/_methods.py", line 40, in _amax
    return umr_maximum(a, axis, None, out, keepdims, initial, where)
TypeError: output must be an array
btasdelen commented 1 year ago

Hi @fzimmermann89, thanks for the PR. #87 fixes this, but that PR has been waiting for some time. If it gets merged, this issue will be resolved.

sravan953 commented 1 year ago

@fzimmermann89 Thank you for this PR! I've been caught up with other things, so couldn't work on the pending issues/PRs. Like @bilal-tasdelen mentioned, PR #87 would've fixed this, and it was in the queue, but I just accepted it. Thanks again :)

fzimmermann89 commented 1 year ago

Glad that it got fixed, thanks!

Nikbert commented 1 year ago

Hello, seems like we have a bug with this! I get the following error: " /usr/local/lib/python3.8/dist-packages/pypulseq/Sequence/sequence.py in gradient_waveforms(self) 637 grad_waveforms = np.zeros((3, maxt_i)) 638 --> 639 grad_waveforms[0, gx_i:(gx_i+gx.shape[0])] = gx 640 grad_waveforms[1, gy_i:(gy_i+gy.shape[0])] = gy 641 grad_waveforms[2, gz_i:(gz_i+gz.shape[0])] = gz

ValueError: could not broadcast input array from shape (766316,) into shape (766315,) "

Apparently the error can be resolved by changing line 632 in sequence.py from: maxt_i = int(np.max((tx_e, ty_e, tz_e))/dt) to: maxt_i = int(np.round(np.max((tx_e, ty_e, tz_e))/dt))