Exemplo n.º 1
0
def surface_check():
    func = double_diamond
    cube = cube_lattice(lattice_num=70, flambda=func)
    delt = 0.1
    cube_d = (np.abs(cube)<delt).astype(float)
    plt.imshow(cube_d[:,:,-1])
    plt.colorbar()
    plt.show()
    qsvec, intens_str = straight_intensity(cube_d, peakmax=5)
    lenqs = qsvec_to_lenqs(qsvec)
    intens_str /= (intens_str*lenqs*lenqs).sum()
    intens_mod = np.load("../data/dd_model_surf.npy")
    intens_paper = np.load("../data/dd_paper_surf.npy")
    plt.title("DD")
    plt.plot(lenqs,intens_mod,'bo',label="surface appr")
    plt.plot(lenqs, intens_str,'^g', label="direct surface")
    plt.plot(lenqs, intens_paper,'r+',label="paper data")

    #for x in range(len(qsvec)):
     #   print x, qsvec[x]

    cube_b = ((cube)<0).astype(float)
    qsvec, intens_bulk = straight_intensity(cube_b, peakmax=5)
    intens_bulk /= (intens_bulk*lenqs*lenqs).sum()
    plt.plot(lenqs, intens_bulk,'xk', label="direct bulk")
    plt.legend()
    plt.show()

    plt.imshow(cube_b[:,:,-1])
    plt.colorbar()
    plt.show()
Exemplo n.º 2
0
def test_by_sin(npoints=100):
    s = lambda x, y, z: np.sin(2*np.pi*4*r(x,y,z))
    sizelat = 4
    l = sizelat/2
    r = lambda x, y, z: np.sqrt((x-l)**2 + (y-l)**2 + (z-l)**2)

    cube = cube_lattice(lattice_num=npoints, flambda=s, sizelat=sizelat)
    plt.imshow(cube[npoints/2, :,:])
    plt.colorbar()
    plt.show()
    cube -= np.average(cube)

    peakmax = 10.
    lenqs2, intens_mod = straight_intensity(cube, peakmax=peakmax, sizelat=sizelat)
    intens_mod /= lenqs2**2
    plt.plot(lenqs2, intens_mod,'--b')
    plt.plot(lenqs2, intens_mod,'bo')

    plt.title("ФП в точках, ячеек:{}".format(sizelat))
    plt.ylabel("I, a.u.")
    plt.xlabel("q, a.u.")
    plt.show()
    output(name="test3", pic_path=".", lenqs=lenqs2, intens_exp=intens_mod,
           intens_mod=intens_mod, error=0., xaxis=np.array([0.,9.]))

    from Fourier import fourier_base
    lenqs_f, intens_f = fourier_base(cube)
    lenqs_f /= sizelat
    plt.plot(lenqs_f, intens_f/np.max(intens_f),'-r')
    plt.title("Полное ФП, ячеек:{}".format(sizelat))

    plt.ylabel("I, a.u.")
    plt.xlabel("q, a.u.")
    plt.show()
Exemplo n.º 3
0
def diamond_symmetry(con):
    N = 100
    pm = 4
    tr = 0.05
    sizelat = 1
    func = double_diamond
    cubezero = double_sign_lattice(lattice_num=N, func=func, con=con, sizelat=sizelat)
    print round(cubezero.sum()/N**3,3)

    cubezero /= cubezero.sum()
    qsvec, intens_zero = straight_intensity(cubezero, peakmax=pm, sizelat=sizelat)
    _, lenqs = generate_qvecs_lenqs_deprecated(peakmax=pm)

    plt.plot(lenqs, intens_zero, 'bo')
    plt.plot(lenqs, intens_zero, '--g')
    for num, x in enumerate(qsvec):
        if intens_zero[num]>tr:
            print x, round(lenqs[num],3)
    plt.title(con)
    plt.show()
    slice = cubezero[0, :, :]
    plt.imshow(slice)
    plt.colorbar()
    plt.show()
Exemplo n.º 4
0
def diamond_paper_res():
    peakmax = 6
    qsvec, lenqs = generate_qvecs_lenqs_deprecated(peakmax)
    func_p = lambda x, y, z: double_diamond(x, y, z, const=0)
    gart_list = np.array([0.]*len(qsvec))#len(qsvec))

    """
    #gyr
    gart_list[5] = 0.65
    gart_list[6] = 0.43
    gart_list[12] = 0.097
    gart_list[13] = 0.34
    gart_list[17] = 0.33
    gart_list[19] = 0.47
    gart_list[20] = 0.27
    gart_list[22] = 0.189
    gart_list[30] = 0.41
    """
    for num, q in enumerate(qsvec):
        print num, q
    #dd

    gart_list[6] = 0.958
    gart_list[10] = 0.97
    gart_list[13] = 0.523
    gart_list[20] = 0.424
    gart_list[26] = 0.516
    #gart_list[30] = 0.56
    qsvec_new, intens_paper = calc_model_set_fstruct(gart_list, 0.05, ddens=1., peakmax=peakmax)
    intens_paper /= (intens_paper*lenqs*lenqs).sum()

    sizelat = 1.

    intenses = []
    Ns = [30, 110]
    for N in Ns:
        #print N
        cube_p = cube_lattice(N, func_p, sizelat=sizelat)
        qsvec, lenqs = generate_qvecs_lenqs_deprecated(peakmax)

        factor_struct = factor_calc_structural(qsvec, cube_p)
        #print factor_struct

        qsvec_new, intens_mod = calc_model_set_fstruct(factor_struct, layer=0.05, ddens=1., peakmax=peakmax)
        print max(intens_mod)
        intens_mod /= (intens_mod*lenqs*lenqs).sum()
        print max(intens_mod)
        print
        intenses.append(intens_mod)
        #plt.plot(lenqs, intens_mod,'o',label='m surface %d'%(N))

    plt.plot(lenqs, intens_paper, '^', label='external data')
    plt.title("DD")



    cube_n = cube_lattice(80, func_p, sizelat=sizelat)

    for err in [0.20]:
        cube_p = (cube_n<0)#err
        qsvec, intens_dir = straight_intensity(lattice=cube_p, peakmax=peakmax,sizelat=sizelat)
        intens_dir /= (intens_dir*lenqs*lenqs).sum()
        print ((intens_dir - intens_paper)**2).sum()
        plt.plot(lenqs, intens_dir,"s", label="m direct {:1.3f}".format((cube_p>0).astype(float).sum()/80**3))

        cube_p = (np.abs(cube_n)<err)
        qsvec, intens_dir = straight_intensity(lattice=cube_p, peakmax=peakmax, sizelat=sizelat)
        intens_dir /= (intens_dir*lenqs*lenqs).sum()
        print ((intens_dir - intens_paper)**2).sum()
        plt.plot(lenqs, intens_dir,"s", label="m direct surf {:1.3f}, {:1.3f}".format((cube_p>0).astype(float).sum()/80**3, err))


    plt.legend(bbox_to_anchor=(0.8, 1.1))


        #up = np.sqrt(((intens_paper-intens_mod)**2).sum())
        #down1 = np.sqrt((intens_paper**2).sum())
        #down2 = np.sqrt((intens_mod**2).sum())
        #print down1, down2
        #print up/down1, up/down2

        #plt.show()

        #diff = intens_paper/intens_mod
        #diff = diff[np.nonzero(diff)]



    plt.show()
    plt.imshow(cube_p[0,:,:])
    plt.show()
    np.save("../data/dd_model_surf.npy", intenses[0])
Exemplo n.º 5
0
def single_point(*args):
    try:
        mkdir(addr)
    except:
        pass

    if args is not ():
        phi1 = args[0]
        phi2 = args[1]
        rho_abs_h20, rho_abs_pol, rho_abs_alk = args[2]
        val_debye = args[3]
    else:
        global phi1, phi2, rho_abs_h20
        global rho_abs_pol, rho_abs_alk, val_debye
    print(phi1, phi2, (rho_abs_h20,rho_abs_pol, rho_abs_alk), val_debye)
    qsvec, lenqs = generate_qvecs_lenqs(peakmax=lenqsmax)

    #experimental data correction
    lenqs_exp_grand, intens_exp_grand = read_exp_data(scat_exp_file, intens_exp_file)

    peaks_indices = find_peaks_ind_in_smooth_profile(intens_exp_grand, cond='>')
    lenqs_exp = lenqs_exp_grand[peaks_indices]
    intens_exp = intens_exp_grand[peaks_indices]

    lattice_parameter = get_lattice_parameter(lenqs_exp_abs=lenqs_exp, peaks_file=peaks_file)
    print("lattice parameter: {:1.3f}".format(1./lattice_parameter))
    lenqs_exp /= lattice_parameter
    lenqs_exp_grand /= lattice_parameter

    lenqs_exp = peaks_file_to_lenqs(peaks_file)

    exp_ind_in_model = find_exp_indices(lenqs_exp_short=lenqs_exp, lenqs_model=lenqs, corr_file=peaks_file) #corrction of model
    intens_exp = insert_exp_peaks(intensity_exp=intens_exp, indices_exp=exp_ind_in_model, lenqs_model=lenqs)

    #for model correction
    ind_forbid = []
    peak_max = exp_ind_in_model[-1]

    print("inices higher than {} ({}) are forbidden".format(peak_max, qsvec[peak_max]))
    if qsvec_forbid is not None:
        ind_forbid = find_indices(qsvec_forbid, lenqs)
        print("hkl forbid: {}, ind forbid{}:".format(str(qsvec_forbid), ind_forbid))

    #for output xaxis
    ind_exp = np.nonzero(intens_exp)[0]
    xaxis = [round(lenqs[ind_exp[0]])-1, round(lenqs[ind_exp[-1]])+1]
    #init
    lenqs = qsvec_to_lenqs(qsvec)
    #brute force
    con1 = phi_to_const(phi1)
    cube_in = build_lattice_function(lattice_num=lattice_num, func=model_function, con=con1, warn=global_warn, sizelat=sizelat)

    con2 = phi_to_const(phi2+phi1)
    cube_out = build_lattice_function(lattice_num=lattice_num, func=model_function, con=con2, warn=global_warn, sizelat=sizelat)

    cube = (1.-cube_out)*rho_abs_alk
    cube += (cube_out - cube_in)*rho_abs_pol
    cube += cube_in*rho_abs_h20
    print(rho_abs_alk, rho_abs_pol, rho_abs_h20)
    plt.title(u"Электронная плотность в срезе")
    plt.imshow(cube[0], extent=[0,1,0,1])
    plt.colorbar()
    plt.show()
    cube -= cube.sum()/lattice_num**3

    lenqs2, intens_mod = straight_intensity(cube, peakmax=lenqsmax, sizelat=sizelat)
    assert lenqs.all()==lenqs2.all(),'trouble!'

    debye_factor = np.exp(-(lenqs*val_debye)**2)
    intens_mod *= debye_factor

    intens_mod[peak_max+1::] = 0.0
    intens_mod[ind_forbid] = 0.0

    err = calculate_error(lenqs, intens_mod, lenqs, intens_exp, norm='area')

    name_cur = "$\phi={}; $\phi2={}, rho=({},{},{}), d={}$".format(phi1, phi2,
                                                                          rho_abs_h20,rho_abs_pol,rho_abs_alk, val_debye)
    output(name=name_cur,pic_path=addr, lenqs=lenqs, intens_exp=intens_exp, intens_mod=intens_mod,
                               error=err, lenqs_exp_grand=lenqs_exp_grand, intens_exp_grand=intens_exp_grand, xaxis=xaxis)