num_theta = 250
dtheta = 2*np.pi/num_theta

scale = [200, 400, 330]
means = [40, 140, 200]
stds = [5, 10, 7]

np.random.normal(0,1,num_theta)

noise = np.random.normal(0,1,num_theta)
signal = np.zeros(num_theta)

for i in range(3):
    signal += scale[i]*EM.gaussian_basis_wrap(num_theta,
                                           dtheta,
                                           means[i],
                                           (stds[i]*dtheta)**2)

#%% Create Dictionary
num_var = 15

# Local maxima
maxima = argrelmax(signal)[0]

# Variances
test_vars = np.linspace((dtheta),(np.pi/16),num_var)**2
variances = test_vars

B = np.empty([num_theta,0])
B0 = np.empty([num_theta,0])
B0_tran = np.zeros([num_theta,num_var])
#%% Generate Data

num_theta = 250
dtheta = 2*np.pi/num_theta

scale = [200, 400, 330]
means = [40, 140, 200]


np.random.normal(0,1,num_theta)

noise = np.random.normal(0,1,num_theta)
signal = 0

i = 1
signal += EM.gaussian_basis_wrap(num_theta,dtheta,0,(10*dtheta)**2)

coefs = np.zeros((num_theta))

for i in range(3):
    coefs[means[i]] = scale[i]



import cython_test as ct

a_fft = np.fft.fft(signal)    
b_fft = np.fft.fft(coefs)

# Convolution via cython and blas
t = time.time()
#%% Plot fit but try to remove DC component

plt.figure(1)
plt.ylabel('Intensity')
plt.xlabel('Angle (Radians)')

plt.plot(rsf_ex.theta, rsf_ex.f, 'bo-')

# Construct B
dom = np.arange(len(rsf_ex.coefs))
keep = dom[np.abs(rsf_ex.coefs) > 0]
full_fit = np.zeros(len(rsf_ex.theta))

for i in keep:
    if (rsf_ex.coefs[i] < 10):
        basis = EM.gaussian_basis_wrap(len(rsf_ex.f), dtheta, rsf_ex.means[i],
                                       rsf_ex.variances[i])
        plt.figure(1)
        plt.plot(rsf_ex.theta, rsf_ex.coefs[i] * basis, 'r-')

        full_fit += rsf_ex.coefs[i] * basis
plt.plot(rsf_ex.theta, full_fit, 'g-')

#%% View an individual histogram and fit plots
num_theta = 2400
dtheta = 2 * np.pi / num_theta
num_bins = 30

img_num = 13
load_steps = [0, 4]
bar_colors = ['r', 'b', 'g', 'm', 'k']
Пример #4
0
#%% Lasso fitting for each ring
num_var = 15

# Extract local maxima
maxima = argrelmax(b)[0]

# Create Gaussian basis function fitting matrix
test_vars = np.linspace((dtheta), (np.pi / 16), num_var)**2
variances = test_vars

B = np.empty([num_theta, 0])
B0 = np.empty([num_theta, 0])
B0_tran = np.zeros([num_theta, num_var])

for i, var in enumerate(variances):
    basis_vec = EM.gaussian_basis_wrap(num_theta, dtheta, 0, var)
    B0 = np.hstack([B0, basis_vec[:, None]])
    for shift in maxima:
        B_shift = np.concatenate([basis_vec[-shift:], basis_vec[0:-shift]])
        B = np.hstack([B, B_shift[:, None]])

B_tran = np.transpose(B)

for i, var in enumerate(variances):
    B0_tran[0, i] = B0[0, i]
    B0_tran[1::, i] = np.flipud(B0[1::, i])

B = np.array(B, order='F', copy=True)
B_tran = np.array(B_tran, order='F', copy=True)
B0 = np.array(B0, order='F', copy=True)
B0_tran = np.array(B0_tran, order='F', copy=True)