del g_sym
    euler_sym[sym, ...] = tmp
    del tmp

# make sure all of the euler angles within the appropriate
# ranges (eg. not negative)
print "initial: euler angles less than zero: %s" % np.sum(euler_sym < 0)
lt = euler_sym < 0.0
euler_sym += 2 * np.pi * lt
print "final: euler angles less than zero: %s" % np.sum(euler_sym < 0)
"""Calculate the GSH coefficients for each symmetric zone"""

st = time.time()

X = gsh.gsh_eval(euler_sym, np.arange(1, N_L))

print "basis evaluation complete: %ss" % np.round(time.time() - st, 3)
print "size of X: %sgb" % str(X.nbytes / (1E9))
print "X shape: %s" % str(X.shape)
"""Error check the GSH coefficients in terms of symmetry"""

error = np.zeros((n_sym - 1, n_tot, N_L - 1))

for sym in xrange(n_sym - 1):
    error[sym, ...] = np.abs(np.real(X[0, ...]) - np.real(X[sym, ...]))

print "maximum error: %s" % error.max()

print "coefficient magnitude closest to zero: %s" % str(np.abs(X).min())
Example #2
0
phi1max = 2*np.pi
phimax = np.pi/2.
phi2max = np.pi/2.

# n_tot = 72000
# euler = euler_rand(n_tot, phi1max, phimax, phi2max)

inc = 15.
euler, n_tot = euler_grid_center(inc, phi1max, phimax, phi2max)

""" Calculate X """

st = time.time()

X = gsh.gsh_eval(euler, np.arange(N_L))

print "basis evaluation complete: %ss" % np.round(time.time()-st, 3)
print "size of X: %sgb" % np.str(X.nbytes/(1E9))

""" Generate Y """

bvec = [0,  10, 20, 60, 140, 280]
bval = [40., 20., -10., 6., -4., 1.]

Y = np.dot(bval, X[:, bvec].T)

""" Perform the regression """

coeff = np.zeros(N_L, dtype='complex128')
Example #3
0
f = h5py.File(C['XcalcGSH_output'] % str(tnum).zfill(5), 'w')

for p in xrange(ii_stt, ii_end):

    st = time.time()

    vec = np.zeros(N_par, dtype='complex128')

    # for jj in xrange(C['XcalcGSH_nchunks']):
    #     jj_stt = jj*ch_len  # start index
    #     jj_end = jj_stt + ch_len
    #     if jj_end > N_par:
    #         jj_end = N_par

    #     tmp = gsh.gsh_eval(X[ii_stt:ii_end, :], [p])
    #     vec[ii_stt:ii_end] = np.squeeze(tmp)

    vec = np.squeeze(gsh.gsh_eval(X, [p]))

    set_id = 'p_%s' % str(p).zfill(5)
    f.create_dataset(set_id, data=vec)
    fn.WP(set_id, filename)

    msg = "GSH eval time: %ss" % np.round(time.time()-st, 3)
    fn.WP(msg, filename)

f.close()

f_flag = open("flag%s" % str(tnum).zfill(5), 'w')
f_flag.close()
Example #4
0
ch_len = np.int64(np.ceil(np.float(N_par)/C['XcalcGSH_nchunks']))

f = h5py.File(C['XcalcGSH_output'] % str(tnum).zfill(5), 'w')

for p in xrange(ii_stt, ii_end):

    st = time.time()

    vec = np.zeros(N_par, dtype='complex128')

    for jj in xrange(C['XcalcGSH_nchunks']):
        jj_stt = jj*ch_len  # start index
        jj_end = jj_stt + ch_len
        if jj_end > N_par:
            jj_end = N_par

        tmp = gsh.gsh_eval(g[ii_stt:ii_end, :], [p])
        vec[ii_stt:ii_end] = np.squeeze(tmp)

    set_id = 'p_%s' % str(p).zfill(5)
    f.create_dataset(set_id, data=vec)
    fn.WP(set_id, filename)

    msg = "GSH eval time: %ss" % np.round(time.time()-st, 3)
    fn.WP(msg, filename)

f.close()

f_flag = open("flag%s" % str(tnum).zfill(5), 'w')
f_flag.close()
Example #5
0
emat[:, 0] = np.random.rand(n_tot) * np.pi / 2.
emat[:, 1] = np.random.rand(n_tot) * np.pi / 2.
emat[:, 2] = np.random.rand(n_tot) * np.pi / 2.

print emat.shape
""" calculate XhX """

lmax = 10

XhX = np.zeros((lmax, lmax), dtype='complex128')

for ii in xrange(lmax):
    print ii
    for jj in xrange(lmax):

        xii = gsh.gsh_eval(emat, [ii])[:, 0]
        xjj = gsh.gsh_eval(emat, [jj])[:, 0]

        XhX[ii, jj] = np.sum(xii.conj() * xjj * np.sin(emat[:, 1]))
        # XhX[ii, jj] = np.dot(xii.conj(), xjj)
""" plot the XhX matrix """

plt.figure(1)

plt.subplot(121)

ax = plt.imshow(np.real(XhX), origin='lower', interpolation='none', cmap='jet')
plt.title("real(XhX): GSH")
plt.colorbar(ax)

plt.subplot(122)
Example #6
0
def gen():

    C = constants.const()

    filename = 'log_gen_test_data.txt'

    inc2rad = C['inc'] * np.pi / 180.
    """get the test euler angle set"""

    thetavec = (np.arange(C['n_th']) + 0.5) * inc2rad
    phi1vec = (np.arange(C['n_p1']) + 0.5) * inc2rad
    phivec = (np.arange(C['n_P']) + 0.5) * inc2rad
    phi2vec = (np.arange(C['n_p2']) + 0.5) * inc2rad

    phi1, phi, phi2 = np.meshgrid(phi1vec, phivec, phi2vec)

    phi1 = phi1.reshape(phi1.size)
    phi = phi.reshape(phi.size)
    phi2 = phi2.reshape(phi2.size)

    angles = np.zeros([C['n_tot'], 4], dtype='float64')

    for ii in xrange(C['n_th']):
        ii_stt = ii * C['n_eul']
        ii_end = ii_stt + C['n_eul']
        angles[ii_stt:ii_end, 0] = thetavec[ii]
        angles[ii_stt:ii_end, 1] = phi1
        angles[ii_stt:ii_end, 2] = phi
        angles[ii_stt:ii_end, 3] = phi2
    """Generate test Y"""

    bvec = np.random.randint(low=0, high=C['cmax'], size=(5))
    bvec[0] = 0
    bvec = np.unique(bvec)

    bval = np.random.randint(low=1, high=10, size=bvec.size)

    msg = "bvec: %s" % str(bvec)
    fn.WP(msg, filename)
    msg = "bval: %s" % str(bval)
    fn.WP(msg, filename)

    cmat = np.unravel_index(np.arange(C['cmax']), C['N_tuple'])
    cmat = np.array(cmat).T

    Y = np.zeros((C['n_tot']), dtype='complex128')

    for ii in xrange(bvec.size):
        p, q = cmat[bvec[ii], :]

        tmpgsh = gsh.gsh_eval(angles[:, 1:4], [p])
        tmpcos = np.cos(q * np.pi * angles[:, 0] / C['L_th'])

        Y += bval[ii] * np.squeeze(tmpgsh) * tmpcos

    alldata = np.zeros((C['n_tot'], 14), dtype='complex128')
    alldata[:, :4] = angles
    alldata[:, 4] = Y

    f1 = h5py.File(C['combineread_output'], 'w')
    f1.create_dataset("var_set", data=alldata)
    f1.close()