base.py 1.0 KB

12345678910111213141516171819202122232425262728
  1. from pathlib import Path
  2. import numpy as np
  3. def main(script: callable, matlab_seq_filename: str, pypulseq_seq_filename: str):
  4. path_here = Path(__file__) # Path of this file
  5. pypulseq_seq_filename = (
  6. path_here.parent / pypulseq_seq_filename
  7. ) # Path to PyPulseq seq
  8. matlab_seq_filename = (
  9. path_here.parent / "matlab_seqs" / matlab_seq_filename
  10. ) # Path to MATLAB seq
  11. # Run PyPulseq script and write seq file
  12. script.main(plot=False, write_seq=True, seq_filename=str(pypulseq_seq_filename))
  13. # Read MATLAB and PyPulseq seq files, discard header and signature
  14. seq_matlab = matlab_seq_filename.read_text().splitlines()[4:-7]
  15. seq_pypulseq = pypulseq_seq_filename.read_text().splitlines()[4:-7]
  16. pypulseq_seq_filename.unlink() # Delete PyPulseq seq
  17. diff_lines = np.setdiff1d(seq_matlab, seq_pypulseq) # Mismatching lines
  18. percentage_diff = len(diff_lines) / len(
  19. seq_matlab
  20. ) # % of lines that are mismatching; we tolerate upto 0.1%
  21. assert percentage_diff < 1e-3 # Unit test