Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
from filePath import *
import cmd #cmd in small letters is the name of the module. do cmd.Cmd.any_function() to run a function from the class from the module
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import glob
from plotRaman import *
import os
import numpy as np
from material import *
import re
from scipy.optimize import curve_fit
from scipy.interpolate import interp1d
import pyperclip3
def ramanMapCleanAndAvg():
newpath=os.getcwd()+"\\corrected_raman_map"+"\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
files=glob.glob("*.txt")
f_list=fileExtensionRemover(glob.glob("*.txt"))
flag=0
a=float(input("How much data point do you have in the map?: "))
for i,fp in enumerate(files):
print("Working on \"",files[i],"\"")
with open(fp) as file:
for line in file:
if(line[0]!='#'):
if(flag==1):
y_temp=np.zeros(len(line.split()))
y_temp=line.split()
y_temp2=y_temp[2:]
for k in range(len(y_temp2)):
y[k]=y[k]+float(y_temp2[k])
else:
x=np.zeros(len(line.split()))
y=np.zeros(len(line.split()))
x=line.split()
flag=1
y=y/a
with open (newpath+f_list[i]+"_corrected_map.txt",'w') as file:
for j in range(len(x)):
file.write(str(x[j])+" "+str(y[j])+"\n")
print('\n---------------------------------------------------------------\n')
pyperclip3.copy("path "+newpath)
print("\nOperation successful! Created path and path command copied to clipboard. Paste to move DesCar to the created directory\n")
def ramanSiliconPressure():
newpath=os.getcwd()+"\\raman_peak_shift"+"\\"
if not os.path.exists(newpath):
os.makedirs(newpath)
files=glob.glob("*.txt")
x_pressure=[]
y_1peak_pos=[]
y_2peak_pos1=[]
y_2peak_pos2=[]
error=[]
for i,fp in enumerate(files):
with open(fp) as file:
print("Working on ","\"",files[i],"\"")
x_temp = []
y_temp = []
for line in file:
values = line.split()
x_temp.append(float(values[0]))
y_temp.append(float(values[1]))
try:
y_1peak_pos.append(find_1peak(x_temp,y_temp)) #LO
y_2peak_pos1.append(find_2peaks(x_temp,y_temp)[0]) #TO
y_2peak_pos2.append(find_2peaks(x_temp,y_temp)[1]) #LO
x_pressure.append(float(re.findall(r'\d+',files[i])[0]))
except:
print("\n!!Fit error!!",files[i],"was skipped\n")
sort=np.argsort(x_pressure)
x=[]
y=[]
for k in range(len(sort)):
x.append(x_pressure[sort[k]])
y.append(y_1peak_pos[sort[k]])
with open (newpath+"raman_peak_lorentzian1.txt",'w') as file:
for j in range(len(x)):
file.write(str(x[j])+" "+str(y[j])+"\n")
with open (newpath+"LO_Ferran_Urena_and_all_uniAxial.txt",'w') as file:
for j in range(len(x)):
file.write(str(x[j])+" "+str((520.7-y[j])/(343))+"\n")
with open (newpath+"LO_Nicolas_Roisin_and_all_uniAxial.txt",'w') as file:
for j in range(len(x)):
file.write(str(x[j])+" "+str((520.7-y[j])/(175.77))+"\n")
x1=[]
y1=[]
for k in range(len(sort)):
x1.append(x_pressure[sort[k]])
y1.append(y_2peak_pos1[sort[k]])
with open (newpath+"raman_peak1_lorentzian2.txt",'w') as file:
for j in range(len(x1)):
file.write(str(x1[j])+" "+str(y1[j])+"\n")
# with open (newpath+"LO_Ferran_Urena_and_all(TP).txt",'w') as file:
# for j in range(len(x1)):
# file.write(str(x1[j])+" "+str((520.7-y1[j])/(485))+"\n")
# with open (newpath+"LO_Nicolas_Roisin_and_all(TP).txt",'w') as file:
# for j in range(len(x1)):
# file.write(str(x1[j])+" "+str((520.7-y1[j])/(400))+"\n")
x2=[]
y2=[]
for k in range(len(sort)):
x2.append(x_pressure[sort[k]])
y2.append(y_2peak_pos2[sort[k]])
# with open (newpath+"TO_Ferran_Urena_and_all(TP).txt",'w') as file:
# for j in range(len(x2)):
# file.write(str(x2[j])+" "+str((520.7-y2[j])/(485))+"\n")
# with open (newpath+"TO_Nicolas_Roisin_and_all(TP).txt",'w') as file:
# for j in range(len(x2)):
# file.write(str(x2[j])+" "+str((520.7-y2[j])/(400))+"\n")
with open (newpath+"raman_peak2_lorentzian2.txt",'w') as file:
for j in range(len(x2)):
file.write(str(x2[j])+" "+str(y2[j])+"\n")
print('\n---------------------------------------------------------------\n')
pyperclip3.copy("path "+newpath)
print("\nOperation successful! Created path and path command copied to clipboard. Paste to move DesCar to the created directory\n")
#Code bellow from Nicolas Roisin. PhD student uclouvain 2023
def lorentzian( x, a,b,c ):
return b * c**2 / ( c**2 + ( x - a )**2)
def lorentzian2( x, a1,b1,c1,a2,b2,c2 ):
return b1 * c1**2 / ( c1**2 + ( x - a1 )**2)+b2 * c2**2 / ( c2**2 + ( x - a2 )**2)
#We here try to detect a single peak. A single peak would be mainly the LO (LL 20231212)
#We do a quadratic interpolation of the Raman spectrum then we detect the max. The >450 is to take the median and remove the baseline.
# Taking >450 removes some weird effect that can appear bellow 450
def find_1peak(x,y):
x=np.array(x)
y=np.array(y)
x_interp=np.linspace(x[0],x[-1],10000)
# y=y-np.median(y[(x<500) & (x>480)])
y=y-np.median(y[(x>450)])
y=y/np.max(y)
f = interp1d(x, y,kind='quadratic')
x0=x_interp[f(x_interp)==np.max(f(x_interp[x_interp>450]))][0]
p1=curve_fit(lorentzian,x_interp,f(x_interp),p0=[x0,0.7,1],bounds=[(515,0,0.5),(525,1,3)],maxfev=10000)[0]
return p1[0] #returns the position only
# return p1 #returns the position, height and width
#We here try to find two peaks: LO and TO. The LO is the one that moves the less compared to the 520.7 original position of the peak. The TO moves away to
# the left of this position. Not always possible to find it. Under high levels of strain the two peaks do separate. Not so much with smaller levels of deformation
# p2[0] => TO and p2[3] => LO (LL 20231212)
#We do a quadratic interpolation of the Raman spectrum then we detect the max. The >450 is to take the median and remove the baseline.
# Taking >450 removes some weird effect that can appear bellow 450
def find_2peaks(x,y):
x=np.array(x)
y=np.array(y)
x_interp=np.linspace(x[0],x[-1],10000)
y=y-np.median(y[x<450])
y=y/np.max(y)
f = interp1d(x, y,kind='quadratic')
x0=x_interp[f(x_interp)==np.max(f(x_interp[x_interp>450]))][0]
p2=curve_fit(lorentzian2,x_interp,f(x_interp),p0=[x0-0.1,0.7,1,x0+0.1,0.7,1],bounds=[(515,0,0.5,515,0,0.5),(525,1,3,525,1,3)],maxfev=10000)[0]
return p2[0],p2[3]
#We do a quadratic interpolation of the Raman spectrum then we detect the max. The >450 is to take the median and remove the baseline.
# Taking >450 removes some weird effect that can appear bellow 450
def find_peak_max(x,y):
x=np.array(x)
y=np.array(y)
x_interp=np.linspace(x[0],x[-1],10000)
# y=y-np.median(y[(x<500) & (x>480)])
y=y-np.median(y[(x>450)])
y=y/np.max(y)
f = interp1d(x, y,kind='quadratic')
x0=x_interp[f(x_interp)==np.max(f(x_interp[x_interp>450]))][0]
return x0