221 lines
6.6 KiBLFS
Plaintext
221 lines
6.6 KiBLFS
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 29,
|
|
"id": "22bc2a27",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"'/home/chn/repo/SiC-2nd-paper'"
|
|
]
|
|
},
|
|
"execution_count": 29,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import numpy as np\n",
|
|
"from scipy.optimize import curve_fit\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import plotly.graph_objects as go\n",
|
|
"import matplotlib\n",
|
|
"\n",
|
|
"def lorentzian(x, A, x0, gamma, k, b):\n",
|
|
" return A / (1 + ((x - x0) / gamma)**2) + k * x + b\n",
|
|
"def double_lorentzian(x, A1, x1, gamma1, A2, x2, gamma2, k, b):\n",
|
|
" return lorentzian(x, A1, x1, gamma1, k, b) + lorentzian(x, A2, x2, gamma2, 0, 0)\n",
|
|
"\n",
|
|
"%pwd"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 30,
|
|
"id": "f4aba80e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def fitting_peek(x, y, x_range, function, guess, bound):\n",
|
|
" mask = (x > x_range[0]) & (x < x_range[1])\n",
|
|
" x = x[mask]\n",
|
|
" y = y[mask]\n",
|
|
" popt, pcov = curve_fit(function, x, y, p0=guess, maxfev=10000, bounds=bound)\n",
|
|
" return popt\n",
|
|
"\n",
|
|
"def fitting_line_xzyx(x, y):\n",
|
|
" integration = []\n",
|
|
" result = fitting_peek(x, y, fitting_range[1], lorentzian, fitting_init_parameter[1], fitting_bound[1])\n",
|
|
" integration.append(result[0] * result[2] * np.pi)\n",
|
|
" return integration\n",
|
|
"def fitting_line_xzzx(x, y):\n",
|
|
" integration = []\n",
|
|
" result = fitting_peek(x, y, fitting_range[2], lorentzian, fitting_init_parameter[2], fitting_bound[2])\n",
|
|
" integration.append(result[0] * result[2] * np.pi)\n",
|
|
" result = fitting_peek(x, y, [830, 847], lorentzian, [1e3, 838, 2, 0, 100], (-np.inf, np.inf))\n",
|
|
" integration.append(result[0] * result[2] * np.pi)\n",
|
|
" return integration"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 31,
|
|
"id": "591e7dc9",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"fitting_init_parameter = [\n",
|
|
" [300, 196, 1, 2e3, 204, 0.8, 0, 900],\n",
|
|
" [1000, 266, 1, 0, 100],\n",
|
|
" [1e3, 611, 5, 0, 100],\n",
|
|
" [1e4, 776, 1, 1e3, 797, 1, 1, 100]\n",
|
|
"]\n",
|
|
"fitting_range = [\n",
|
|
" [180, 220],\n",
|
|
" [250, 280],\n",
|
|
" [600, 617],\n",
|
|
" [700, 850]\n",
|
|
"]\n",
|
|
"fitting_bound = [\n",
|
|
" ([0, 192, 0, 0, 200, 0, -np.inf, -np.inf], [np.inf, 198, np.inf, np.inf, 206, np.inf, np.inf, np.inf]),\n",
|
|
" ([0, 260, 0, -np.inf, -np.inf], [np.inf, 270, np.inf, np.inf, np.inf]),\n",
|
|
" ([0, 605, 0, -np.inf, -np.inf], [np.inf, 617, np.inf, np.inf, np.inf]),\n",
|
|
" (-np.inf, np.inf)\n",
|
|
"]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 32,
|
|
"id": "ad979c50",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"xzyx_x = np.loadtxt('画图/拉曼结果拟合/251008/2/xzyx_x.txt')\n",
|
|
"xzyx_y = np.loadtxt('画图/拉曼结果拟合/251008/2/xzyx_y.txt')\n",
|
|
"xzzx_x = np.loadtxt('画图/拉曼结果拟合/251008/2/xzzx_x.txt')\n",
|
|
"xzzx_y = np.loadtxt('画图/拉曼结果拟合/251008/2/xzzx_y.txt')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 33,
|
|
"id": "ea7b0b57",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0\n",
|
|
"[ 6.20863446e+02 8.38299773e+02 9.88636310e-01 -2.75421651e-01\n",
|
|
" 4.37847606e+02]\n",
|
|
"1\n",
|
|
"[ 5.70835585e+02 8.38290687e+02 1.06223999e+00 -4.20011037e-01\n",
|
|
" 5.54691452e+02]\n",
|
|
"2\n",
|
|
"[ 5.67699634e+02 8.38310484e+02 1.09375996e+00 -1.91829315e-01\n",
|
|
" 3.63015294e+02]\n",
|
|
"3\n",
|
|
"[ 5.71587243e+02 8.38312536e+02 1.10515225e+00 -2.35440551e-01\n",
|
|
" 4.04026894e+02]\n",
|
|
"4\n",
|
|
"[ 5.63526465e+02 8.38321133e+02 1.11857378e+00 -1.57440689e-01\n",
|
|
" 3.35431720e+02]\n",
|
|
"5\n",
|
|
"[ 5.58936304e+02 8.38298057e+02 1.11846058e+00 -4.78122075e-01\n",
|
|
" 5.97983191e+02]\n",
|
|
"6\n",
|
|
"[ 5.94881490e+02 8.38293742e+02 1.03933855e+00 -2.20381683e-01\n",
|
|
" 3.93859587e+02]\n",
|
|
"7\n",
|
|
"[ 5.89327016e+02 8.38306592e+02 1.06489366e+00 -3.99797321e-01\n",
|
|
" 5.43370844e+02]\n",
|
|
"8\n",
|
|
"[ 6.07322341e+02 8.38311130e+02 1.05443289e+00 -3.31104222e-01\n",
|
|
" 4.87033118e+02]\n",
|
|
"9\n",
|
|
"[ 6.03524138e+02 8.38298730e+02 1.01543786e+00 -1.65621189e-01\n",
|
|
" 3.44437001e+02]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# 检查拟合结果\n",
|
|
"for site in range(10):\n",
|
|
" print(site)\n",
|
|
" result = fitting_peek(xzzx_x[site], xzzx_y[site], [830, 847], lorentzian, [1e3, 838, 2, 0, 100], (-np.inf, np.inf))\n",
|
|
" fig = go.Figure()\n",
|
|
" fig.add_trace(go.Scatter(x=xzzx_x[site], y=np.log10(xzzx_y[site]), mode='lines', name='data'))\n",
|
|
" fig.add_trace(go.Scatter(x=xzzx_x[site], y=np.log10(lorentzian(xzzx_x[site], *result)), mode='lines', name='fit'))\n",
|
|
" fig.update_yaxes(range=[1, 4])\n",
|
|
" # fig.show()\n",
|
|
" print(result)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 34,
|
|
"id": "e3526b25",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# 收集拟合结果\n",
|
|
"integration_all = []\n",
|
|
"for site in range(10):\n",
|
|
" integration_xzyx = fitting_line_xzyx(xzyx_x[site], xzyx_y[site])\n",
|
|
" integration_xzzx = fitting_line_xzzx(xzzx_x[site], xzzx_y[site])\n",
|
|
" integration_all.append([integration_xzyx[0], integration_xzzx[0], integration_xzzx[1]])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 35,
|
|
"id": "c49bc98d",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"mean: [2195.66402216 3117.93160487 1956.38300586]\n",
|
|
"std: [55.69099914 55.3995643 30.57802302]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# 计算峰面积的平均和标准差\n",
|
|
"integration_all = np.array(integration_all)\n",
|
|
"mean = np.mean(integration_all, axis=0)\n",
|
|
"std = np.std(integration_all, axis=0)\n",
|
|
"print(\"mean:\", mean)\n",
|
|
"print(\"std:\", std)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.13.7"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|