Skip to content

Commit

Permalink
Merge pull request #158 from timwahoo/main
Browse files Browse the repository at this point in the history
Adding brkrecon CLI and minor updates
  • Loading branch information
dvm-shlee authored Mar 27, 2024
2 parents 6483ce1 + 6bfd95f commit c7f654a
Show file tree
Hide file tree
Showing 12 changed files with 881 additions and 103 deletions.
16 changes: 7 additions & 9 deletions brkraw/lib/recoFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def reco_phase_rotate(frame, Reco, actual_framenumber):

# import variables
RECO_rotate_all = get_value(Reco,'RECO_rotate')


if RECO_rotate_all.shape[1] > actual_framenumber:
RECO_rotate = get_value(Reco,'RECO_rotate')[:, actual_framenumber]
Expand All @@ -89,13 +88,12 @@ def reco_phase_rotate(frame, Reco, actual_framenumber):
phase_matrix = np.ones_like(frame)
for index in range(len(RECO_rotate)):
f = np.arange(dims[index])
#print(f)

if RECO_ft_mode in ['COMPLEX_FT', 'COMPLEX_FFT']:
phase_vector = np.exp(1j*2*np.pi*RECO_rotate[index]*f)
elif RECO_ft_mode in ['NO_FT', 'NO_FFT']:
phase_vector = np.ones_like(f)
elif RECO_ft_mode in ['COMPLEX_IFT', 'COMPLEX_IFFT']:
#print(RECO_rotate[index])
phase_vector = np.exp(1j*2*np.pi*(1-RECO_rotate[index])*f)
else:
raise ValueError('Your RECO_ft_mode is not supported')
Expand Down Expand Up @@ -192,7 +190,7 @@ def reco_FT(frame, Reco, actual_framenumber):
elif RECO_ft_mode in ['NO_FT', 'NO_FFT']:
pass
elif RECO_ft_mode in ['COMPLEX_IFT', 'COMPLEX_IFFT']:
frame = np.fft.fftn(frame)
frame = np.fft.ifftn(frame)
#frame = sp.ifft(frame, axes=[0,1,2], center=False)
else:
raise ValueError('Your RECO_ft_mode is not supported')
Expand Down Expand Up @@ -236,20 +234,20 @@ def reco_cutoff(frame, Reco, actual_framenumber):
# Use function only if Reco.RECO_size is not equal to size(frame)
dim_equal = True
for i,j in zip(get_value(Reco,'RECO_size'), frame.shape):
dim_equal = (i==j)

if not dim_equal:

if i!=j:
dim_equal = False

if not dim_equal:
# Import variables
RECO_offset = get_value(Reco,'RECO_offset')[:, actual_framenumber]
RECO_size = get_value(Reco, 'RECO_size')

# Cut the new part with RECO_size and RECO_offset
pos_ges = []
for i in range(len(RECO_size)):

pos_ges.append(slice(RECO_offset[i], RECO_offset[i] + RECO_size[i]))
newframe = frame[tuple(pos_ges)]

else:
newframe = frame

Expand Down
52 changes: 52 additions & 0 deletions brkraw/lib/recoSigpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
Created on Sat Feb 08 2024
DEVELOPED FOR BRUKER PARAVISION 360 datasets
Below code will work for 3D cartesian sequence
undersampled in the y-z phase view
Reconstructions are completed with SIGPY
THIS IS A WORK IN PROGRESS due to a lack of CS
datasets from PV360.3.3 or higher
@author: Tim Ho (UVA)
"""

import sigpy as sp
import sigpy.mri as mr
import numpy as np

from .utils import get_value

def compressed_sensing_recon(data, acqp, meth, reco, lamda=0.01, method=None):
# Meta Variables
ky = get_value(meth,'PVM_EncGenSteps1')
kz = get_value(meth,'PVM_EncGenSteps2')
PVM_EncGenTotalSteps = get_value(meth, 'PVM_EncGenTotalSteps')

kspaceShape = [1 for _ in range(7)]
RECO_ft_size = get_value(reco, 'RECO_ft_size')
NI = get_value(acqp, 'NI')
NR = get_value(acqp, 'NR')
kspaceShape[1:len(RECO_ft_size)+1] = RECO_ft_size
kspaceShape[0] = data.shape[1]
kspaceShape[5] = NI
kspaceShape[6] = NR

# Resort Raw Sorted to K-SPACE
frame_sort = data.reshape((NR, PVM_EncGenTotalSteps, NI, kspaceShape[0], RECO_ft_size[0]))

k_space = np.zeros(shape=kspaceShape, dtype=complex)
for index, (i,j) in enumerate(zip(ky,kz)):
k_space[:,:,int(i+max(ky)), j+max(kz)+1,0,:,:]= frame_sort[:,index,:,:,:].transpose(2,3,1,0)


N1, N2, N3, N4, N5, N6, N7 = k_space.shape
output = np.zeros(shape=(N2,N3,N4,N6,N7), dtype=complex)
for NR in range(N7):
for NI in range(N6):
k_space = np.squeeze(k_space[:,:,:,:,:,NI,NR])
# Compressed Sensing
sens = mr.app.EspiritCalib(k_space).run()
output[:,:,:,NI,NR] = mr.app.L1WaveletRecon(k_space, sens, lamda=lamda).run()

return output
Loading

0 comments on commit c7f654a

Please sign in to comment.