Example #1
0
def straight_intensity(lattice, peakmax=5, sizelat=1):
    qsvec, lenqs = generate_qvecs_lenqs_full(peakmax, uniquelenq=False)
    lattice_num = len(lattice)
    x, y, z = np.mgrid[:sizelat:lattice_num * 1j, :sizelat:lattice_num * 1j, :sizelat:lattice_num * 1j]
    intensity = []
    for m in range(len(qsvec)):
        qvec = qsvec[m]
        qC = x*qvec[0] + y*qvec[1] + z*qvec[2]
        expqC = np.exp(2*np.pi*1j*qC)
        amplitude = np.abs((expqC*lattice).sum()).astype(float)
        #print(lenqs[m], np.abs(amplitude))
        intensity.append((amplitude*lenqs[m])**2)
    intensity = np.array(intensity)
    intensity *= factor_calc_multiplicity_intens(qsvec)
    lenqs, intensity = filter_unique(np.round(lenqs,4), intensity, concat=True)
    intensity /= max(intensity)
    return lenqs, intensity
Example #2
0
def sphere_integrate(cube_space, cube_func, **kwargs):
    """
    executes averaging by sphere of func
    :param cube_space: numpy array, values of variables
    :param cube_func: numpy array, values of function
    :return: func(var)
    """
    new_variant_flag=kwargs.get("new_variant", False)

    N = len(cube_space)
    if not (cube_space.shape == cube_func.shape):
        raise TypeError("Wrong dimensions: func:{}, space:{}".format(cube_space.shape, cube_func.shape))
    if not np.all(np.array(cube_space.shape)==N):
        raise TypeError("Wrong dimensions: func:{}, space:{} != {}".format(cube_space.shape, cube_func.shape, N))

    if N//2 == N/2:
        N += 1
        cube_space_n = extend_symmetrically(cube_space)
        cube_func_n = extend_symmetrically(cube_func)
    else:
        cube_space_n = cube_space
        cube_func_n = cube_func
    if cube_space_n[N//2, N//2, N//2]!=0.:
        print("warning: non centr-symmety in {}:{}".format(N//2+1,cube_space_n[N//2+1, N//2+1, N//2+1]))

    freq_flat = cube_space_n.reshape(N**3)#*1/cube_sample_rate

    int_flat = cube_func_n.reshape(N**3)
    ind_sort = np.argsort(freq_flat)
    freq_flat = freq_flat[ind_sort]
    int_flat = int_flat[ind_sort]

    #filtering  from high freqs that are higher than half-side of cube
    freqmax = N//2
    ind_max = freq_flat<freqmax
    freq_flat = freq_flat[ind_max]
    int_flat = int_flat[ind_max]
    int_flat /= np.max(int_flat)

    #concatenate all similiear freqs
    if new_variant_flag:

        divider = np.linspace(0., np.max(freq_flat), 2*N)
        div_ind = np.searchsorted(freq_flat, divider)[:-1]
        space_intervals = np.array(np.split(freq_flat, div_ind))
        func_intervals = np.array(np.split(int_flat, div_ind))
        r_aver = np.zeros(space_intervals.shape)
        f_aver = np.zeros(func_intervals.shape)
        for num, f in enumerate(func_intervals):
            #r_aver[num] = np.average(space_intervals[num])
            #f_aver[num] = np.average(f) * r_aver[num]**2

            r_aver[num] = np.average(space_intervals[num])
            f_aver[num] = np.sum(f)

        r_aver = np.nan_to_num(r_aver)
        f_aver = np.nan_to_num(f_aver)

        return r_aver, f_aver

    x, fx = filter_unique(freq_flat, int_flat, func=np.average, concat=True)
    fx *= x**2
    x_n = np.linspace(0., np.max(x), len(cube_space_n))
    fx_n = np.interp(x_n, xp=x, fp=fx)

    return x_n, fx_n