imr-framework / pypulseq

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

Cast times and amplitude inputs to np array in case they are supplied as list. #88

Closed btasdelen closed 1 year ago

btasdelen commented 1 year ago

Sometimes it is more convenient to supply times and amplitudes as Python list instead of np.array to avoid boilerplate. In fact, it is what is done in "Tong et al. A framework for validating open-source pulse sequences. MRM. 2022. (https://doi.org/10.1016/j.mri.2021.11.014)", so IRSE and TSE sequences are currently failing in PyPulseq 1.4. This PR aims to introduce this convenience, and make this branch more "backwards compatible".

Usage of np.asarray is almost free in this context, because:

  1. It does nothing if the input is already numpy array, so no funny business or slowdown.
  2. If the input is a list, it automatically does what the user would do manually for average use case: ie. np.array([1, 2, 3 .....]).

PS: IMHO, every function that gets an ArrayLike, should have asarray casts for their respective inputs.