In [1]:
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import os
import glob
import sys

Import a list of filenames¶

In [2]:
path = os.getcwd()
path
Out[2]:
'C:\\Users\\Kosuke Sato\\OneDrive - 学校法人トヨタ学園豊田工業大学\\ドキュメント\\research_data\\Aichi-SR'
In [3]:
def import_list_of_filenames(keyword):
    l = glob.glob("%s\\*%s-?.txt"%(path,keyword))
    l.extend(glob.glob("%s\\*%s-??.txt"%(path,keyword)))
    return l
In [4]:
def exp_XRD(filename):
    df = pd.read_csv(filename,sep="\t",usecols=[0,1])
    #print(df)
    l_ang = np.array(df.iloc[:,0])
    l_int = np.array(df.iloc[:,1])
    l_int = np.array([float(d) for d in l_int])
    #print(l_int)
    #print(min(l_int))
    l_int = l_int - min(l_int)
    #print(l_int)
    k = max(l_int)
    l_int = l_int/k
    return [l_ang, l_int]
In [5]:
def exp_XRD_raw(filename):
    df = pd.read_csv(filename,sep="\t",usecols=[0,1])
    #print(df)
    l_ang = np.array(df.iloc[:,0])
    l_int = np.array(df.iloc[:,1])
    l_int = np.array([float(d) for d in l_int])
    return l_ang, l_int
In [6]:
def get_ang_int(l):
    return [ exp_XRD(c) for i, c in enumerate(l)]        
In [7]:
def get_ang_int_raw(l):
    l_a, l_i = [], []
    for i, c in enumerate(l):
        l1, l2 = exp_XRD_raw(c)
        #print(len(l2))
        l_a.append(l1); l_i.append(l2)
    #l_i = np.array(l_i)
    return l_a, l_i
In [8]:
def reshape_intensity_array(amin,amax,la,li):
    lii = []
    for i,lt in enumerate(li):
        lll = [v for j, v in enumerate(lt) if la[i][j] > amin-0.0001 and amax-0.0001 > la[i][j]]
        #print(len(lll))
        lii.append(lll)
    return lii
In [9]:
def find_peak_root(l,ran):
    l_iamo = []
    for i, ll in enumerate(l):
        amax = np.argmax(ll[1])
        angmax = ll[0][amax]
        #print(imax,ll[0][imax],ll[1][imax])
        amin = np.argmin(ll[1][amax-ran:amax+ran])
        angmin = ll[0][amin+amax-ran]
        imin = ll[1][amin+amax-ran]
        #print(amax,angmax,amin,angmin,imin)
        l_iamo.append(imin)
    return l_iamo
In [10]:
# Ag2S0.7Te0.3 No.2 continuous
l2 = import_list_of_filenames("ag2s0.7te0.3")
l_2 = get_ang_int(l2)
l_2r_a,  l_2r_i= get_ang_int_raw(l2)
In [11]:
l_2r_i2 = reshape_intensity_array(1,90,l_2r_a,l_2r_i)
In [12]:
l2_iamo = find_peak_root(l_2,100)
l2_iamo[0]
Out[12]:
0.4056784648472016
In [13]:
# Ag2S0.7Te0.3 No.3 stable
l3_ = ["20220628144117-no.3_ag2s0.7te0.3-27-001.txt","20220628152204-no.3_ag2s0.7te0.3-110-002.txt","20220628154559-no.3_ag2s0.7te0.3-120-003.txt",\
    "20220628160959-no.3_ag2s0.7te0.3-130-004.txt","20220628163353-no.3_ag2s0.7te0.3-140-005.txt","20220628170230-no.3_ag2s0.7te0.3-170-006.txt",\
      "20220628174315-no.3_ag2s0.7te0.3-27-007.txt"]
In [14]:
l_3 = get_ang_int(l3_)
l_3r_a,  l_3r_i= get_ang_int_raw(l3_)
In [15]:
# Ag1.97Cu0.03S0.7Te0.3 No.34 continuous
l34 = import_list_of_filenames("ag1.97cu0.03s0.7te0.3")
l_34 = get_ang_int(l34)
l_34r_a,  l_34r_i= get_ang_int_raw(l34)
In [16]:
l_34r_i2 = reshape_intensity_array(1,90,l_34r_a,l_34r_i)
In [17]:
l_ag453s3 = exp_XRD("20220628180733-Ag453Te3-1.txt")

Reference XRD (Ag2S)¶

In [18]:
l_ag2s_l = exp_XRD("20210827100945-Ag2S_No.1_stoichi-1.txt")
l_ag2s_l
Out[18]:
[array([ 0.1 ,  0.11,  0.12, ..., 95.01, 95.02, 95.03]),
 array([0.        , 0.00029807, 0.        , ..., 0.01730043, 0.01492125,
        0.01709218])]

Experimental XRD from structure of ICSD.¶

In [19]:
def xrd_spectra(l_ang,l_int,theta_min,theta_max,dtheta,width):
    theta_range = theta_max - theta_min
    N = int(theta_range/dtheta)
    l_int_sme, l_ang_sme = [], []
    for i in range(N):
        theta = theta_min + i*dtheta
        I_theta = 0.0
        for j, intensity in enumerate(l_int):
            fact = ((theta-l_ang[j])/width)**2
            I_theta += intensity*np.exp(-fact)
        l_ang_sme.append(theta)
        l_int_sme.append(I_theta)
    l_int_sme = l_int_sme/max(l_int_sme)
    return l_ang_sme,l_int_sme
In [20]:
def xrd_to_lists(filename):
    f = open(filename,"r")
    l_ = f.readlines()
    f.close()
    l_ang, l_int = [], []
    for i in range(2,len(l_)):
        sp = l_[i].split()
        l_ang.append(float(sp[0]))
        l_int.append(float(sp[1]))
    l_int1 = np.array(l_int)
    l_int2 = l_int1/max(l_int1)
    l_ang2 = np.array(l_ang)
    return [l_ang2, l_int2]
In [21]:
def pks_to_lists(filename):
    f = open(filename,"r")
    l_ = f.readlines()
    f.close()
    l_ang, l_int = [], []
    for i in range(13,len(l_)):
        #print(l_[i])
        sp = l_[i].split()
        l_ang.append(float(sp[1]))
        l_int.append(float(sp[4]))
    l_int1 = np.array(l_int)
    l_int2 = l_int1/max(l_int1)
    l_ang2 = np.array(l_ang)
    return l_ang2, l_int2
In [22]:
l_ag = xrd_to_lists("Ag_crystal.gpd") 
In [23]:
l_ag2te_l = xrd_to_lists("ag2te_low_temp.gpd")
l_ag2te_l
Out[23]:
[array([  3.01,   3.02,   3.03, ..., 119.98, 119.99, 120.  ]),
 array([0.      , 0.      , 0.      , ..., 0.001836, 0.001868, 0.001912])]
In [24]:
#l_ang_ag2s_l, l_int_ag2s_l = xrd_to_lists("ag2s_low_temp.int") 
In [25]:
l_ag2s_h = xrd_to_lists("ag2s_high_temp_match.gpd") 
In [26]:
l_ag2te_l = xrd_to_lists("ag2te_low_temp.gpd") 
In [27]:
l_ag2te_h = xrd_to_lists("ag2te_high_temp.gpd") 
In [28]:
l_ag3cus2 = xrd_to_lists("ag3cus2.gpd") 
In [29]:
l_cu2s_l = xrd_to_lists("cu2s_low_temp.gpd") 
In [30]:
l_al2o3 = xrd_to_lists("Al2O3.gpd") 
In [31]:
def XRD_picture_raw(l_ang,l_int,l_colors,l_labs,l_mrks,xmin,xmax,ymax,filename):
    plt.clf() # initialization
    plt.figure(figsize=(8, 6))
    plt.axis([xmin,xmax,0,ymax])
    plt.tick_params(direction="in")
    plt.rcParams["font.family"] = "times new roman"
    plt.rcParams['mathtext.fontset'] = 'cm'
    plt.rcParams["axes.linewidth"] = 1.5
    plt.tick_params(direction="in")
    plt.rcParams["xtick.major.size"] = 10
    plt.rcParams["xtick.major.width"] = 1.5
    plt.rcParams["ytick.major.size"] = 10
    plt.rcParams["ytick.major.width"] = 1.5
    plt.rcParams["font.size"] = 30
    plt.ylabel("Intensity (arb. unit)")
    plt.xlabel(r"2$\theta$ (degrees)")
    l_line = ["-"]*len(l_ang)
    for i in range(len(l_ang)):
        #plt.scatter(l_ang[i], l_int[i],color=l_color[i],marker=l_mrks[i],label=l_lab[i])
        plt.plot(l_ang[i], l_int[i],color=l_color[i],marker="None",label=l_labs[i],linestyle=l_line[i]) 
    #plt.legend(loc='upper right')
    plt.savefig(filename,bbox_inches="tight")
    plt.show()
In [37]:
def XRD_picture_shifted(l_,l_colors,l_mrks,xmin,xmax,xfig,yfig,filename):
    Nang = len(l_)
    plt.clf() # initialization
    plt.figure(figsize=(xfig, yfig))
    plt.axis([xmin,xmax,-Nang+1,max(l_[0][1])])
    plt.tick_params(direction="in")
    plt.rcParams["font.family"] = "times new roman"
    plt.rcParams['mathtext.fontset'] = 'cm'
    plt.rcParams["axes.linewidth"] = 1.5
    plt.tick_params(direction="in")
    plt.rcParams["xtick.major.size"] = 10
    plt.rcParams["xtick.major.width"] = 1.5
    plt.rcParams["ytick.major.size"] = 10
    plt.rcParams["ytick.major.width"] = 1.5
    plt.rcParams["font.size"] = 30
    plt.ylabel("Intensity (arb. unit)")
    plt.xlabel(r"2$\theta$ (degrees)")
    plt.tick_params(labelleft=False)
    l_line = ["-","-","-","-","-","-"]
    for i in range(len(l_)):
        #plt.scatter(l_ang[i], l_int[i],color=l_color[i],marker=l_mrks[i],label=l_lab[i])
        plt.hlines([-i],0,100,linestyle="--")
        plt.plot(l_[i][0], l_[i][1]-i,color=l_color[i],marker="None",linestyle="-") 
    #plt.legend(loc='upper right')
    plt.savefig(filename,bbox_inches="tight")
    plt.show()
In [33]:
l_color = ["black","red", "blue","green","cyan","purple","orange","brown","gray","pink"]
l_mrks = ["o","^", "*","d",">","<","o"]

exp XRD comparison¶

In [34]:
l_a = [l_2r_a[i] for i in [0,9,17]]
l_i = [l_2r_i[i] for i in [0,9,17]]
l_color = ["black","red","blue","green"]
l_lab = ["300 K","407 K","498 K","520 K"]
XRD_picture_raw(l_a,l_i,l_color,l_lab,l_mrks,9,23,150,"test.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [35]:
l_a = [l_2r_a[i] for i in [19]]
l_i = [l_2r_i[i] for i in [19]]
l_color = ["black"]
l_lab = ["520 K"]
XRD_picture_raw(l_a,l_i,l_color,l_lab,l_mrks,9,23,50,"test.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [39]:
l_ = [l_2[17],l_2[9],l_2[0]]
l_color = ["black"]*3
XRD_picture_shifted(l_,l_color,l_mrks,9,23,8,6,"XRD_analysis_AichiSR_20221221_Ag2S0.7Te0.3_No.2_paper_heating_cooling.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [37]:
l_ = [l_2[20],l_2[25],l_2[30],l_2[35],l_2[39]]
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221212_Ag2S0.7Te0.3_No.2_paper_cooling.jpg")
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-37-a36bb999f00e> in <module>
      1 l_ = [l_2[20],l_2[25],l_2[30],l_2[35],l_2[39]]
----> 2 XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221212_Ag2S0.7Te0.3_No.2_paper_cooling.jpg")

<ipython-input-32-1a53a8f4106a> in XRD_picture_shifted(l_, l_colors, l_mrks, xmin, xmax, filename)
     21         #plt.scatter(l_ang[i], l_int[i],color=l_color[i],marker=l_mrks[i],label=l_lab[i])
     22         plt.hlines([-i],0,100,linestyle="--")
---> 23         plt.plot(l_[i][0], l_[i][1]-i,color=l_color[i],marker="None",linestyle="-")
     24     #plt.legend(loc='upper right')
     25     plt.savefig(filename,bbox_inches="tight")

IndexError: list index out of range
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [38]:
l_ = [l_2[0],l_2[19], l_2[-1]]
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221212_Ag2S0.7Te0.3_No.2_paper_heating_cooling.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [37]:
l_ = [l_2[30],l_2[19], l_2[-1]]
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221215_Ag2S0.7Te0.3_No.2_paper_test.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [38]:
l_ = [l_2[i] for i in range(19,-1,-1)]
l_color = ["black"]*len(l_)
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221011_Ag2S0.7Te0.3_#2_step0-19.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [39]:
l_ = [l_2[i] for i in [0,7,8]]
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20230220_Ag2S0.7Te0.3_#2_step0-8.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [40]:
l_ = [l_2[i] for i in range(20,40)]
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221011_Ag2S0.7Te0.3_#2_step20-end.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [41]:
l_ = [l_2[i] for i in range(20,30)]
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221011_Ag2S0.7Te0.3_#2_step20-30.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [42]:
l_ = [l_2[i] for i in range(30,40)]
XRD_picture_shifted(l_,l_color,l_mrks,9,23,"XRD_analysis_AichiSR_20221011_Ag2S0.7Te0.3_#2_step30-40.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [43]:
l_ = [l_2[29],l_2[30],l_2[31],l_2[-1]]
XRD_picture_shifted(l_,l_color,l_mrks,12,14,"XRD_analysis_AichiSR_20221214_Ag2S0.7Te0.3_No.2_chosen.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [44]:
l_ = [l_ag2s_l,l_ag2s_h,l_ag2te_l,l_ag2te_h,l_cu2s_l,l_ag453s3]
XRD_picture_shifted(l_,l_color,l_mrks,5,25,"XRD_analysis_AichiSR_20220712_reference.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [45]:
l_ = [l_2[0],l_2[7],l_2[20],l_2[29],l_2[39],l_ag2s_l,l_ag2s_h]
XRD_picture_shifted(l_,l_color,l_mrks,5,25,"XRD_analysis_AichiSR_20220701_Ag2S0.7Te0.3_No.2.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [45]:
l_ = [l_34[0],l_34[7],l_34[20],l_34[29],l_34[39],l_ag2s_l,l_ag2s_h,l_ag2te_l,l_ag]
XRD_picture_shifted(l_,l_color,l_mrks,5,25,"XRD_analysis_AichiSR_20220701_Ag1.97Cu0.03S0.7Te0.3_No.34.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [46]:
l_ = l_3+[l_ag2s_l,l_ag2s_h,l_ag]
XRD_picture_shifted(l_,l_color,l_mrks,5,25,"XRD_analysis_AichiSR_20220701_Ag2S0.7Te0.3_No.3_stable.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [47]:
l_ = [l_2[0],l_ag2s_l,l_ag2s_h,l_ag]
XRD_picture_shifted(l_,l_color,l_mrks,5,25,"XRD_analysis_AichiSR_20220701_Ag2S0.7Te0.3_No.2_sole.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [48]:
def XRD_picture_2Dmap(l_temp,l_step,l_i,xmin,xmax,ymin,ymax,zmin,zmax,filename):
    plt.clf() # initialization
    plt.figure(figsize=(10, 6))
    plt.axis([xmin,xmax,ymin,ymax])
    plt.tick_params(direction="in")
    plt.rcParams["font.family"] = "serif"
    plt.rcParams["axes.linewidth"] = 1.5
    plt.tick_params(direction="in")
    plt.rcParams["xtick.major.size"] = 10
    plt.rcParams["xtick.major.width"] = 1.5
    plt.rcParams["ytick.major.size"] = 10
    plt.rcParams["ytick.major.width"] = 1.5
    plt.rcParams["font.size"] = 30
    plt.ylabel("Measurement steps")
    plt.xlabel(r"2$\theta$, degree")
    
    plt.contourf(l_temp,l_step,l_i,cmap=plt.cm.binary,vmin=zmin, vmax=zmax)
    plt.colorbar(label='Intensity')
    plt.savefig(filename,bbox_inches="tight")
    plt.show()
In [49]:
l_step = np.arange(len(l_2))
l_temp, l_step = np.meshgrid(np.arange(1,90,0.01), l_step)
XRD_picture_2Dmap(l_temp,l_step,l_2r_i2,10,25,0,39,0,250,"XRD_analysis_AichiSR_20220629_Ag2S0.7Te0.3_No.2_2D.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [50]:
l_step = np.arange(21)
l_temp, l_step = np.meshgrid(np.arange(1,90,0.01), l_step)
XRD_picture_2Dmap(l_temp,l_step,l_2r_i2[:21],10,25,0,20,0,160,"XRD_analysis_AichiSR_20221201_Ag2S0.7Te0.3_No.2_2D_heating.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [51]:
l_step = np.arange(len(l_2[21:]))
l_temp, l_step = np.meshgrid(np.arange(1,90,0.01), l_step)
XRD_picture_2Dmap(l_temp,l_step,l_2r_i2[21:],10,25,0,18,0,200,"XRD_analysis_AichiSR_20221201_Ag2S0.7Te0.3_No.2_2D_cooling.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [52]:
l_step = np.arange(len(l_34))
l_temp, l_step = np.meshgrid(np.arange(1,90,0.01), l_step)
XRD_picture_2Dmap(l_temp,l_step,l_34r_i2,10,25,0,39,0,250,"XRD_analysis_AichiSR_20220701_Ag1.97Cu0.03S0.7Te0.3_No.34_2D.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [53]:
def peak_ratio_cry_amo(flag,l_x,l_,xmin,xmax,ymin,ymax,filename):
    plt.clf() # initialization
    plt.figure(figsize=(8, 6))
    plt.axis([xmin,xmax,ymin,ymax])
    plt.tick_params(direction="in")
    plt.rcParams["font.family"] = "serif"
    plt.rcParams["axes.linewidth"] = 1.5
    plt.tick_params(direction="in")
    plt.rcParams["xtick.major.size"] = 10
    plt.rcParams["xtick.major.width"] = 1.5
    plt.rcParams["ytick.major.size"] = 10
    plt.rcParams["ytick.major.width"] = 1.5
    plt.rcParams["font.size"] = 20
    plt.ylabel(r"$I_{back}(I_{total})^{-1}$")
    xlabel = "Time Steps"
    if flag == 1:
        xlabel = "Temperature, K"
    plt.xlabel(xlabel)
    #plt.tick_params(labelleft=False)
    plt.plot(l_x, l_,marker="o",linestyle="-") 
    #plt.legend(loc='upper right')
    plt.savefig(filename,bbox_inches="tight")
    plt.show()
In [54]:
l_step = np.arange(len(l2_iamo))
Nstep = len(l_step)
peak_ratio_cry_amo(0,l_step,l2_iamo,0,Nstep,0,0.6,"XRD_analysis_AichiSR_20220629_Ag2S0.7Te0.3_No.2_peak_ratio.jpg")
#peak_ratio_cry_amo(0,l_step,l2_ratio,0,Nstep,0,1,"XRD_analysis_AichiSR_20220909_Ag2S0.5Te0.5_No.43_peak_ratio_vs_time-step.jpg")
<Figure size 432x288 with 0 Axes>
No description has been provided for this image
In [55]:
peak_ratio_cry_amo(0,l_step,l2_ratio,0,Nstep,0,1,"XRD_analysis_AichiSR_20220909_Ag2S0.5Te0.5_No.43_peak_ratio_vs_time-step.jpg")
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-55-a706ffe6a2ab> in <module>
----> 1 peak_ratio_cry_amo(0,l_step,l2_ratio,0,Nstep,0,1,"XRD_analysis_AichiSR_20220909_Ag2S0.5Te0.5_No.43_peak_ratio_vs_time-step.jpg")

NameError: name 'l2_ratio' is not defined
In [ ]:
l_step = np.arange(len(l_34))
peak_ratio_cry_amo(l_step,l34_iamo,0,0.6,"XRD_analysis_AichiSR_20220701_Ag1.97Cu0.03S0.7Te0.3_No.34_peak_ratio.jpg")

Temperature dependent¶

In [51]:
def read_averaged_temperature(Iini,Nstep,Nskip,fname):
    f = open(fname,"r")
    l = f.readlines()
    f.close()
    
    l_temp = []
    for i in range(Nstep):
        sp = l[Iini+i*Nskip].split()
        l_temp.append(float(sp[-1]))
    return np.array(l_temp)
In [ ]: