71 lines
2.1 KiB
Python
Executable File
71 lines
2.1 KiB
Python
Executable File
#!/usr/bin/python3
|
|
#
|
|
# witzit-load
|
|
#
|
|
# 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-load
|
|
# Load a sample from a Olympus Vanta XRF
|
|
#
|
|
# Usage:
|
|
# witzit-load [filename]
|
|
# Examples:
|
|
# witzit-load ./examples/olympus-vanta.csv
|
|
# witzit-load ./examples/sciaps-x555.mca
|
|
|
|
import pandas as pd
|
|
import sys
|
|
import re
|
|
|
|
# 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.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()
|
|
|
|
# Print the Dataframe
|
|
with pd.option_context('display.max_rows', None,
|
|
'display.max_columns', None
|
|
):
|
|
print(df)
|
|
|