Merge plot notebooks for both Olympus/Sciaps
parent
032f8f5a49
commit
0e92e91d0e
|
@ -1,129 +0,0 @@
|
||||||
{
|
|
||||||
"cells": [
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {
|
|
||||||
"tags": []
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"# witzit-plot-x555 --- What In The Zap Is That? AI categorization of spectra from LIBS/XRF analyzers.\n",
|
|
||||||
"#\n",
|
|
||||||
"# Copyright (C) 2019-2022, Jeff Moe\n",
|
|
||||||
"#\n",
|
|
||||||
"# This program is free software: you can redistribute it and/or modify\n",
|
|
||||||
"# it under the terms of the GNU General Public License as published by\n",
|
|
||||||
"# the Free Software Foundation, either version 3 of the License, or\n",
|
|
||||||
"# (at your option) any later version.\n",
|
|
||||||
"#\n",
|
|
||||||
"# This program is distributed in the hope that it will be useful,\n",
|
|
||||||
"# but WITHOUT ANY WARRANTY; without even the implied warranty of\n",
|
|
||||||
"# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n",
|
|
||||||
"# GNU General Public License for more details.\n",
|
|
||||||
"#\n",
|
|
||||||
"# You should have received a copy of the GNU General Public License\n",
|
|
||||||
"# along with this program. If not, see <http://www.gnu.org/licenses/>.\n",
|
|
||||||
"#\n",
|
|
||||||
"# Plotting Application.\n",
|
|
||||||
"# https://spacecruft.org/spacecruft/witzit\n",
|
|
||||||
"#\n",
|
|
||||||
"# Based on wut?\n",
|
|
||||||
"# https://spacecruft.org/spacecruft/satnogs-wut"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"import pandas as pd\n",
|
|
||||||
"import matplotlib.pyplot as plt\n",
|
|
||||||
"import seaborn as sns\n",
|
|
||||||
"import locale"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"locale.setlocale(locale.LC_ALL, \"en_US.utf8\")\n",
|
|
||||||
"plt.rcParams['axes.formatter.use_locale'] = True"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"template = pd.read_csv('template/sciaps-x555.csv')\n",
|
|
||||||
"mca = pd.read_csv('examples/golden_buffalo.mca', skiprows=21)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"df=template.join(mca)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"print(df)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"sns.set_theme()\n",
|
|
||||||
"plt.figure(facecolor='xkcd:off white', figsize=(15, 8))\n",
|
|
||||||
"g=sns.lineplot(x=\"energy (eV)\", y=\"2048\", data=df, linestyle='-', linewidth=1, color='xkcd:pale orange')\n",
|
|
||||||
"g.set_title('XRF Spectrum'.format('seaborn'), color='xkcd:cornflower blue', fontsize='large', fontweight='bold')\n",
|
|
||||||
"g.set_xlabel('energy (eV)', color='xkcd:goldenrod', fontsize='large', fontweight='bold')\n",
|
|
||||||
"g.set_ylabel('Counts', color='xkcd:cerulean', fontsize='large', fontweight='bold')\n",
|
|
||||||
"g.patch.set_alpha(1.0)\n",
|
|
||||||
"g.set_facecolor('xkcd:powder blue')\n",
|
|
||||||
"plt.xlim(0,50000)\n",
|
|
||||||
"plt.ylim(0,100000)\n",
|
|
||||||
"plt.tight_layout()\n",
|
|
||||||
"plt.savefig(\"xrf-spectrum.png\", dpi=72, transparent=False, facecolor='xkcd:off white', edgecolor=g.get_facecolor())\n",
|
|
||||||
"plt.show()\n",
|
|
||||||
"plt.close()"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"kernelspec": {
|
|
||||||
"display_name": "Python 3 (ipykernel)",
|
|
||||||
"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.10.4"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"nbformat": 4,
|
|
||||||
"nbformat_minor": 4
|
|
||||||
}
|
|
|
@ -8,7 +8,7 @@
|
||||||
},
|
},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"# witzit-plot-vanta --- What In The Zap Is That? AI categorization of spectra from LIBS/XRF analyzers.\n",
|
"# witzit-plot --- What In The Zap Is That? AI categorization of spectra from LIBS/XRF analyzers.\n",
|
||||||
"#\n",
|
"#\n",
|
||||||
"# Copyright (C) 2019-2022, Jeff Moe\n",
|
"# Copyright (C) 2019-2022, Jeff Moe\n",
|
||||||
"#\n",
|
"#\n",
|
||||||
|
@ -41,7 +41,24 @@
|
||||||
"import pandas as pd\n",
|
"import pandas as pd\n",
|
||||||
"import matplotlib.pyplot as plt\n",
|
"import matplotlib.pyplot as plt\n",
|
||||||
"import seaborn as sns\n",
|
"import seaborn as sns\n",
|
||||||
"import locale"
|
"import locale\n",
|
||||||
|
"import sys\n",
|
||||||
|
"import re"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# Olympus Vanta-M XRF Example\n",
|
||||||
|
"#datafile=('examples/olympus-vanta.csv')\n",
|
||||||
|
"# SciAps X-555 XRF Example\n",
|
||||||
|
"#datafile=('examples/sciaps-x555.mca')\n",
|
||||||
|
"# Fail examples\n",
|
||||||
|
"#datafile=('examples/foo.csv')\n",
|
||||||
|
"#datafile=('examples/sciaps-x555.csv')"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -60,21 +77,31 @@
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"df = pd.read_csv('examples/olympus-vanta.csv', header = 0,\n",
|
"with open(datafile) as f:\n",
|
||||||
" skiprows=39,\n",
|
" firstline = f.readline().rstrip()\n",
|
||||||
" names=('eV', 'Counts'),\n",
|
|
||||||
" usecols = [0, 1])\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
"df['eV'] = df['eV'] * 1000"
|
"if firstline == 'File Version = 2':\n",
|
||||||
]
|
" print('SciAps X-555 XRF MCA')\n",
|
||||||
},
|
" template = pd.read_csv('template/sciaps-x555-ev.csv', header=0,\n",
|
||||||
{
|
" skiprows=0,\n",
|
||||||
"cell_type": "code",
|
" usecols = [0])\n",
|
||||||
"execution_count": null,
|
" mca = pd.read_csv(datafile, skiprows=21, header=0,\n",
|
||||||
"metadata": {},
|
" usecols = [0])\n",
|
||||||
"outputs": [],
|
" df=template.join(mca)\n",
|
||||||
"source": [
|
" df.rename(columns = {'2048':'Counts'}, inplace = True)\n",
|
||||||
"print(df)"
|
"\n",
|
||||||
|
"elif re.match(re.compile('Date,*'), firstline):\n",
|
||||||
|
" print('Olympus Vanta-M XRF')\n",
|
||||||
|
" df = pd.read_csv(datafile, header=0,\n",
|
||||||
|
" skiprows=39,\n",
|
||||||
|
" names=('energy (eV)', 'Counts'),\n",
|
||||||
|
" usecols = [0, 1])\n",
|
||||||
|
" df['energy (eV)'] = df['energy (eV)'] * 1000\n",
|
||||||
|
"\n",
|
||||||
|
"elif re.match(re.compile('\"Date\",*'), firstline):\n",
|
||||||
|
" print('Possibly SciAps X-555 XRF CSV, not processed. Use .mca file instead of .csv.')\n",
|
||||||
|
"else:\n",
|
||||||
|
" print('Unknown file type.')\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -85,7 +112,7 @@
|
||||||
"source": [
|
"source": [
|
||||||
"sns.set_theme()\n",
|
"sns.set_theme()\n",
|
||||||
"plt.figure(facecolor='xkcd:off white', figsize=(15, 8))\n",
|
"plt.figure(facecolor='xkcd:off white', figsize=(15, 8))\n",
|
||||||
"g=sns.lineplot(x=\"eV\", y=\"Counts\", data=df, linestyle='-', linewidth=1, color='xkcd:pale orange', legend=False)\n",
|
"g=sns.lineplot(x=\"energy (eV)\", y=\"Counts\", data=df, linestyle='-', linewidth=1, color='xkcd:pale orange', legend=False)\n",
|
||||||
"g.set_title('XRF Spectrum'.format('seaborn'), color='xkcd:cornflower blue', fontsize='large', fontweight='bold')\n",
|
"g.set_title('XRF Spectrum'.format('seaborn'), color='xkcd:cornflower blue', fontsize='large', fontweight='bold')\n",
|
||||||
"g.set_xlabel('energy (eV)', color='xkcd:goldenrod', fontsize='large', fontweight='bold')\n",
|
"g.set_xlabel('energy (eV)', color='xkcd:goldenrod', fontsize='large', fontweight='bold')\n",
|
||||||
"g.set_ylabel('Counts', color='xkcd:cerulean', fontsize='large', fontweight='bold')\n",
|
"g.set_ylabel('Counts', color='xkcd:cerulean', fontsize='large', fontweight='bold')\n",
|
||||||
|
@ -94,7 +121,7 @@
|
||||||
"plt.xlim(0,50000)\n",
|
"plt.xlim(0,50000)\n",
|
||||||
"plt.ylim(0,100000)\n",
|
"plt.ylim(0,100000)\n",
|
||||||
"plt.tight_layout()\n",
|
"plt.tight_layout()\n",
|
||||||
"plt.savefig(\"xrf-spectrum-vanta.png\", dpi=72, transparent=False, facecolor='xkcd:off white', edgecolor=g.get_facecolor())\n",
|
"plt.savefig(\"tmp/xrf-spectrum.png\", dpi=72, transparent=False, facecolor='xkcd:off white', edgecolor=g.get_facecolor())\n",
|
||||||
"plt.show()\n",
|
"plt.show()\n",
|
||||||
"plt.close()"
|
"plt.close()"
|
||||||
]
|
]
|
|
@ -24,7 +24,7 @@
|
||||||
# witzit-load [filename]
|
# witzit-load [filename]
|
||||||
# Examples:
|
# Examples:
|
||||||
# witzit-load ./examples/olympus-vanta.csv
|
# witzit-load ./examples/olympus-vanta.csv
|
||||||
# witzit-load ./examples/golden_buffalo.mca
|
# witzit-load ./examples/sciaps-x555.mca
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import sys
|
import sys
|
||||||
|
|
Loading…
Reference in New Issue