(mri_dir, flash_echos, angle)
| 1918 | |
| 1919 | |
| 1920 | def _write_echos(mri_dir, flash_echos, angle): |
| 1921 | nib = _import_nibabel("write echoes") |
| 1922 | from nibabel.spatialimages import SpatialImage |
| 1923 | |
| 1924 | if _path_like(flash_echos): |
| 1925 | flash_echos = nib.load(flash_echos) |
| 1926 | if isinstance(flash_echos, SpatialImage): |
| 1927 | flash_echo_imgs = [] |
| 1928 | data = np.asanyarray(flash_echos.dataobj) |
| 1929 | affine = flash_echos.affine |
| 1930 | if data.ndim == 3: |
| 1931 | data = data[..., np.newaxis] |
| 1932 | for echo_idx in range(data.shape[3]): |
| 1933 | this_echo_img = flash_echos.__class__( |
| 1934 | data[..., echo_idx], affine=affine, header=deepcopy(flash_echos.header) |
| 1935 | ) |
| 1936 | flash_echo_imgs.append(this_echo_img) |
| 1937 | flash_echos = flash_echo_imgs |
| 1938 | del flash_echo_imgs |
| 1939 | for idx, flash_echo in enumerate(flash_echos, 1): |
| 1940 | if _path_like(flash_echo): |
| 1941 | flash_echo = nib.load(flash_echo) |
| 1942 | nib.save(flash_echo, op.join(mri_dir, "flash", f"mef{angle}_{idx:03d}.mgz")) |
| 1943 | |
| 1944 | |
| 1945 | @verbose |
no test coverage detected