88 lines
2.7 KiB
Plaintext
88 lines
2.7 KiB
Plaintext
|
#!/usr/bin/python3
|
||
|
#
|
||
|
# witzit-plot
|
||
|
#
|
||
|
# Copyright (C) 2022, Jeff Moe
|
||
|
#
|
||
|
# This program is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
#
|
||
|
# witzit-plot
|
||
|
# Plot a sample from a SciAps X-555 or Olympus Vanta-M.
|
||
|
#
|
||
|
# Usage:
|
||
|
# witzit-plot [data filename]
|
||
|
#
|
||
|
# Examples:
|
||
|
# witzit-plot examples/olympus-vanta.csv
|
||
|
# witzit-plot examples/sciaps-x555.mca
|
||
|
|
||
|
import numpy as np
|
||
|
import pandas as pd
|
||
|
import seaborn as sns
|
||
|
import matplotlib.pyplot as plt
|
||
|
import locale
|
||
|
import sys
|
||
|
import re
|
||
|
|
||
|
locale.setlocale(locale.LC_ALL, "en_US.utf8")
|
||
|
plt.rcParams['axes.formatter.use_locale'] = True
|
||
|
|
||
|
# Determine what type of file to load to dataframe
|
||
|
datafile=(sys.argv[1])
|
||
|
|
||
|
with open(datafile) as f:
|
||
|
firstline = f.readline().rstrip()
|
||
|
|
||
|
if firstline == 'File Version = 2':
|
||
|
print('SciAps X-555 XRF MCA')
|
||
|
template = pd.read_csv('template/sciaps-x555-ev.csv', header=0,
|
||
|
skiprows=0,
|
||
|
usecols = [0])
|
||
|
mca = pd.read_csv(datafile, skiprows=21, header=0,
|
||
|
usecols = [0])
|
||
|
df=template.join(mca)
|
||
|
df.rename(columns = {'2048':'Counts'}, inplace = True)
|
||
|
|
||
|
elif re.match(re.compile('Date,*'), firstline):
|
||
|
print('Olympus Vanta-M XRF')
|
||
|
df = pd.read_csv(datafile, header=0,
|
||
|
skiprows=39,
|
||
|
names=('energy (eV)', 'Counts'),
|
||
|
usecols = [0, 1])
|
||
|
df['energy (eV)'] = df['energy (eV)'] * 1000
|
||
|
|
||
|
elif re.match(re.compile('"Date",*'), firstline):
|
||
|
print('Possibly SciAps X-555 XRF CSV, not processed. Use .mca file instead of .csv.')
|
||
|
exit()
|
||
|
|
||
|
else:
|
||
|
print('Unknown file type.')
|
||
|
exit()
|
||
|
|
||
|
# Plot
|
||
|
sns.set_theme()
|
||
|
plt.figure(facecolor='xkcd:off white', figsize=(15, 8))
|
||
|
g=sns.lineplot(x="energy (eV)", y="Counts", data=df, linestyle='-', linewidth=1, color='xkcd:pale orange')
|
||
|
g.set_title('XRF Spectrum'.format('seaborn'), color='xkcd:cornflower blue', fontsize='large', fontweight='bold')
|
||
|
g.set_xlabel('energy (eV)', color='xkcd:goldenrod', fontsize='large', fontweight='bold')
|
||
|
g.set_ylabel('Counts', color='xkcd:cerulean', fontsize='large', fontweight='bold')
|
||
|
g.patch.set_alpha(1.0)
|
||
|
g.set_facecolor('xkcd:powder blue')
|
||
|
plt.xlim(0,50000)
|
||
|
plt.ylim(0,100000)
|
||
|
plt.tight_layout()
|
||
|
plt.show()
|
||
|
plt.close()
|
||
|
|