In [1]:
%pylab inline
import numpy as np

import sys
sys.path.append('../src')

import PatternEvaluator as pe
import SamplingPattern as sp


Populating the interactive namespace from numpy and matplotlib

In [2]:
# instance PatternEvaluator
mype = pe.PatternEvaluator()

#load numpy array of coil sensitivities. (nchannels x nx x ny)
mype.load_sens('../data/sens_6ch_128x128.npz')
#mype.load_sens('../data/sens_31ch_128x128.npz')

In [9]:
# make sampling pat
mypat = sp.SamplingPattern()

# set up vectors for r= 2x2
mypat.yvec[::2,:]=0
mypat.xvec[:,::2]=0

#tell sampling pattern to calculate its 'sampling' parameter by taking outer product of x and y sampling vectors
mypat.calc_pattern()

#alternativley, you can set mypat.sampling to an array of 1/0 of the correct k-space size


Out[9]:
array([[ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  1.,  0., ...,  1.,  0.,  1.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       ..., 
       [ 0.,  1.,  0., ...,  1.,  0.,  1.],
       [ 0.,  0.,  0., ...,  0.,  0.,  0.],
       [ 0.,  1.,  0., ...,  1.,  0.,  1.]])

In [4]:
pat = np.random.sample((128,128))>0.75
sum(pat)
mypat.sampling = pat

In [5]:
#evaluate pattern
mype.eval_pattern(mypat)


Using normfac of 6
Elapased: 1.51298999786s
Elapased: 3.15601205826s
[ 0.78477078]
[ 0.00186844]

In [5]:
#can change simulation params in mypat
mypat.hitol=1e-2
mypat.tol=1e-5

In [6]:
mype.eval_pattern(mypat)


Using normfac of 6
Elapased: 1.52117180824s
Elapased: 3.0257589817s
[ 0.81433894]
[ 0.00251387]

In [8]:
# We can opt to use a single coil, in which case the system is not solvable
#mype.set_single_coil()
#mype.eval_pattern(mypat)


Using normfac of 1
Elapased: 1.28519105911s
Elapased: 0.637102127075s
[ 1.]
[  1.58052540e-21]

Demonstration: fill in centre block of sampling pattern and re-evaluate. Note the change in the maximum eigenvalue.


In [7]:
mypat.sampling[61:67, 61:67]=1

In [8]:
mype.eval_pattern(mypat)


Using normfac of 6
Elapased: 1.48094511032s
Elapased: 2.99401712418s
[ 0.99191374]
[ 0.00252401]

In [10]:
mypat.sampling[61:68,122:127]=1
mype.eval_pattern(mypat)


Using normfac of 6
Elapased: 1.46254396439s
Elapased: 1.44049692154s
[ 0.98609627]
[ 0.0734144]