From 0e92e91d0ec65d5ef4a4b253529b71c1c80b0384 Mon Sep 17 00:00:00 2001 From: Jeff Moe Date: Fri, 27 May 2022 16:51:00 -0600 Subject: [PATCH] Merge plot notebooks for both Olympus/Sciaps --- .../{golden_buffalo.csv => sciaps-x555.csv} | 0 .../{golden_buffalo.mca => sciaps-x555.mca} | 0 .../{golden_buffalo.csv => sciaps-x555.csv} | 0 .../{golden_buffalo.mca => sciaps-x555.mca} | 0 notebooks/witzit-plot-x555.ipynb | 129 ------------------ ...zit-plot-vanta.ipynb => witzit-plot.ipynb} | 63 ++++++--- witzit-load | 2 +- 7 files changed, 46 insertions(+), 148 deletions(-) rename examples/{golden_buffalo.csv => sciaps-x555.csv} (100%) rename examples/{golden_buffalo.mca => sciaps-x555.mca} (100%) rename notebooks/examples/{golden_buffalo.csv => sciaps-x555.csv} (100%) rename notebooks/examples/{golden_buffalo.mca => sciaps-x555.mca} (100%) delete mode 100644 notebooks/witzit-plot-x555.ipynb rename notebooks/{witzit-plot-vanta.ipynb => witzit-plot.ipynb} (61%) diff --git a/examples/golden_buffalo.csv b/examples/sciaps-x555.csv similarity index 100% rename from examples/golden_buffalo.csv rename to examples/sciaps-x555.csv diff --git a/examples/golden_buffalo.mca b/examples/sciaps-x555.mca similarity index 100% rename from examples/golden_buffalo.mca rename to examples/sciaps-x555.mca diff --git a/notebooks/examples/golden_buffalo.csv b/notebooks/examples/sciaps-x555.csv similarity index 100% rename from notebooks/examples/golden_buffalo.csv rename to notebooks/examples/sciaps-x555.csv diff --git a/notebooks/examples/golden_buffalo.mca b/notebooks/examples/sciaps-x555.mca similarity index 100% rename from notebooks/examples/golden_buffalo.mca rename to notebooks/examples/sciaps-x555.mca diff --git a/notebooks/witzit-plot-x555.ipynb b/notebooks/witzit-plot-x555.ipynb deleted file mode 100644 index 3463faa..0000000 --- a/notebooks/witzit-plot-x555.ipynb +++ /dev/null @@ -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 .\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 -} diff --git a/notebooks/witzit-plot-vanta.ipynb b/notebooks/witzit-plot.ipynb similarity index 61% rename from notebooks/witzit-plot-vanta.ipynb rename to notebooks/witzit-plot.ipynb index 90b4cd6..b15112d 100644 --- a/notebooks/witzit-plot-vanta.ipynb +++ b/notebooks/witzit-plot.ipynb @@ -8,7 +8,7 @@ }, "outputs": [], "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", "# Copyright (C) 2019-2022, Jeff Moe\n", "#\n", @@ -41,7 +41,24 @@ "import pandas as pd\n", "import matplotlib.pyplot as plt\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": {}, "outputs": [], "source": [ - "df = pd.read_csv('examples/olympus-vanta.csv', header = 0,\n", - " skiprows=39,\n", - " names=('eV', 'Counts'),\n", - " usecols = [0, 1])\n", + "with open(datafile) as f:\n", + " firstline = f.readline().rstrip()\n", "\n", - "df['eV'] = df['eV'] * 1000" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(df)" + "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", + " usecols = [0])\n", + " mca = pd.read_csv(datafile, skiprows=21, header=0,\n", + " usecols = [0])\n", + " df=template.join(mca)\n", + " df.rename(columns = {'2048':'Counts'}, inplace = True)\n", + "\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": [ "sns.set_theme()\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_xlabel('energy (eV)', color='xkcd:goldenrod', 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.ylim(0,100000)\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.close()" ] diff --git a/witzit-load b/witzit-load index 944b0ed..88f7b42 100755 --- a/witzit-load +++ b/witzit-load @@ -24,7 +24,7 @@ # witzit-load [filename] # Examples: # witzit-load ./examples/olympus-vanta.csv -# witzit-load ./examples/golden_buffalo.mca +# witzit-load ./examples/sciaps-x555.mca import pandas as pd import sys