Skip to content

Commit

Permalink
core-loss
Browse files Browse the repository at this point in the history
  • Loading branch information
gduscher committed May 15, 2024
1 parent f9c6b90 commit 64ba906
Show file tree
Hide file tree
Showing 5 changed files with 824 additions and 192 deletions.
66 changes: 41 additions & 25 deletions notebooks/Spectroscopy/Analyse_Low_Loss.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"start_time": "2024-01-15T14:40:42.347318700Z"
Expand All @@ -129,8 +129,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n",
"You don't have igor2 installed. If you wish to open igor files, you will need to install it (pip install igor2) before attempting.\n",
"You don't have gwyfile installed. If you wish to open .gwy files, you will need to install it (pip install gwyfile) before attempting.\n",
"Symmetry functions of spglib enabled\n",
"Using kinematic_scattering library version {_version_ } by G.Duscher\n",
"pyTEM version: 0.2024.05.0\n"
]
}
Expand Down Expand Up @@ -181,14 +183,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 33,
"metadata": {
"hideCode": false,
"hidePrompt": false,
Expand All @@ -198,7 +193,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4b0c8ab2efb34478b8efded845dafbfc",
"model_id": "398ee7476e5b446bb9b6ac1dd4b57d0a",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -220,24 +215,45 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b6fe6f4d3c3849c2af8efb7264ff2074",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AppLayout(children=(GridspecLayout(children=(ToggleButton(value=False, button_style='info', description='Fit A…"
]
},
"metadata": {},
"output_type": "display_data"
"ename": "ValueError",
"evalue": "operands could not be broadcast together with shapes (0,) (1973,) ",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[35], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m infoWidget\u001b[38;5;241m.\u001b[39mcore_loss\u001b[38;5;241m.\u001b[39mdo_fit(\u001b[38;5;241m1\u001b[39m)\n",
"File \u001b[1;32m~\\Documents\\Github\\pyTEMlib\\notebooks\\Spectroscopy\\../..\\pyTEMlib\\core_loss_widget.py:441\u001b[0m, in \u001b[0;36mCoreLoss.do_fit\u001b[1;34m(self, value)\u001b[0m\n\u001b[0;32m 439\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 440\u001b[0m spectrum \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mdataset\n\u001b[1;32m--> 441\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39medges \u001b[38;5;241m=\u001b[39m eels\u001b[38;5;241m.\u001b[39mfit_edges2(spectrum, \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mparent\u001b[38;5;241m.\u001b[39menergy_scale, edges)\n\u001b[0;32m 442\u001b[0m areal_density \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m 443\u001b[0m elements \u001b[38;5;241m=\u001b[39m []\n",
"File \u001b[1;32m~\\Documents\\Github\\pyTEMlib\\notebooks\\Spectroscopy\\../..\\pyTEMlib\\eels_tools.py:1432\u001b[0m, in \u001b[0;36mfit_edges2\u001b[1;34m(spectrum, energy_scale, edges)\u001b[0m\n\u001b[0;32m 1428\u001b[0m \u001b[38;5;66;03m########################\u001b[39;00m\n\u001b[0;32m 1429\u001b[0m \u001b[38;5;66;03m# Background Fit\u001b[39;00m\n\u001b[0;32m 1430\u001b[0m \u001b[38;5;66;03m########################\u001b[39;00m\n\u001b[0;32m 1431\u001b[0m bgd_fit_area \u001b[38;5;241m=\u001b[39m [background_fit_start, background_fit_end]\n\u001b[1;32m-> 1432\u001b[0m background, [A, r] \u001b[38;5;241m=\u001b[39m power_law_background(spectrum, energy_scale, bgd_fit_area, verbose\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[0;32m 1434\u001b[0m \u001b[38;5;66;03m#######################\u001b[39;00m\n\u001b[0;32m 1435\u001b[0m \u001b[38;5;66;03m# Edge Fit\u001b[39;00m\n\u001b[0;32m 1436\u001b[0m \u001b[38;5;66;03m#######################\u001b[39;00m\n\u001b[0;32m 1437\u001b[0m x \u001b[38;5;241m=\u001b[39m energy_scale\n",
"File \u001b[1;32m~\\Documents\\Github\\pyTEMlib\\notebooks\\Spectroscopy\\../..\\pyTEMlib\\eels_tools.py:1376\u001b[0m, in \u001b[0;36mpower_law_background\u001b[1;34m(spectrum, energy_scale, fit_area, verbose)\u001b[0m\n\u001b[0;32m 1373\u001b[0m err \u001b[38;5;241m=\u001b[39m yy \u001b[38;5;241m-\u001b[39m power_law(xx, pp[\u001b[38;5;241m0\u001b[39m], pp[\u001b[38;5;241m1\u001b[39m])\n\u001b[0;32m 1374\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m err\n\u001b[1;32m-> 1376\u001b[0m [p, _] \u001b[38;5;241m=\u001b[39m leastsq(bgdfit, p0, args\u001b[38;5;241m=\u001b[39m(y, x), maxfev\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2000\u001b[39m)\n\u001b[0;32m 1378\u001b[0m background_difference \u001b[38;5;241m=\u001b[39m y \u001b[38;5;241m-\u001b[39m power_law(x, p[\u001b[38;5;241m0\u001b[39m], p[\u001b[38;5;241m1\u001b[39m])\n\u001b[0;32m 1379\u001b[0m background_noise_level \u001b[38;5;241m=\u001b[39m std_dev \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mstd(background_difference)\n",
"File \u001b[1;32m~\\AppData\\Local\\anaconda3\\Lib\\site-packages\\scipy\\optimize\\_minpack_py.py:420\u001b[0m, in \u001b[0;36mleastsq\u001b[1;34m(func, x0, args, Dfun, full_output, col_deriv, ftol, xtol, gtol, maxfev, epsfcn, factor, diag)\u001b[0m\n\u001b[0;32m 418\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(args, \u001b[38;5;28mtuple\u001b[39m):\n\u001b[0;32m 419\u001b[0m args \u001b[38;5;241m=\u001b[39m (args,)\n\u001b[1;32m--> 420\u001b[0m shape, dtype \u001b[38;5;241m=\u001b[39m _check_func(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mleastsq\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfunc\u001b[39m\u001b[38;5;124m'\u001b[39m, func, x0, args, n)\n\u001b[0;32m 421\u001b[0m m \u001b[38;5;241m=\u001b[39m shape[\u001b[38;5;241m0\u001b[39m]\n\u001b[0;32m 423\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m n \u001b[38;5;241m>\u001b[39m m:\n",
"File \u001b[1;32m~\\AppData\\Local\\anaconda3\\Lib\\site-packages\\scipy\\optimize\\_minpack_py.py:29\u001b[0m, in \u001b[0;36m_check_func\u001b[1;34m(checker, argname, thefunc, x0, args, numinputs, output_shape)\u001b[0m\n\u001b[0;32m 27\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_check_func\u001b[39m(checker, argname, thefunc, x0, args, numinputs,\n\u001b[0;32m 28\u001b[0m output_shape\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m):\n\u001b[1;32m---> 29\u001b[0m res \u001b[38;5;241m=\u001b[39m atleast_1d(thefunc(\u001b[38;5;241m*\u001b[39m((x0[:numinputs],) \u001b[38;5;241m+\u001b[39m args)))\n\u001b[0;32m 30\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (output_shape \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;129;01mand\u001b[39;00m (shape(res) \u001b[38;5;241m!=\u001b[39m output_shape):\n\u001b[0;32m 31\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m (output_shape[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m):\n",
"File \u001b[1;32m~\\Documents\\Github\\pyTEMlib\\notebooks\\Spectroscopy\\../..\\pyTEMlib\\eels_tools.py:1373\u001b[0m, in \u001b[0;36mpower_law_background.<locals>.bgdfit\u001b[1;34m(pp, yy, xx)\u001b[0m\n\u001b[0;32m 1372\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mbgdfit\u001b[39m(pp, yy, xx):\n\u001b[1;32m-> 1373\u001b[0m err \u001b[38;5;241m=\u001b[39m yy \u001b[38;5;241m-\u001b[39m power_law(xx, pp[\u001b[38;5;241m0\u001b[39m], pp[\u001b[38;5;241m1\u001b[39m])\n\u001b[0;32m 1374\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m err\n",
"\u001b[1;31mValueError\u001b[0m: operands could not be broadcast together with shapes (0,) (1973,) "
]
}
],
"source": [
"infoWidget.core_loss.do_fit(1)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"del infoWidget.core_loss.edges"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"\n",
"datasets = {'Channel_000': infoWidget.datasets['Channel_000']}\n",
Expand Down
Loading

0 comments on commit 64ba906

Please sign in to comment.