In [1]:
import re
import pandas as pd
In [2]:
gd = pd.read_csv('rawdata/GeoRem_Preferred_170622.csv', comment='#')
In [3]:
els = pd.read_pickle('resources/elements.pkl')
In [ ]:
In [4]:
def calc_M(molecule):
"""
Returns molecular mass of molecule.
Where molecule is in standard chemical notation,
e.g. 'CO2' or 'HCO3'
NOTE: Brackets not supported - i.e. B(OH)4 must be
written as BO4H4
"""
# break the molecule up into a list of (Element, N) pairs
comp = re.findall('([A-Z][a-z]{0,})([0-9]{0,})',
molecule)
# Calculate their mass
M = 0
for el, n in comp:
if n == '':
n = 1
else:
n = float(n)
m = els[el]
M += m * n
return M
In [5]:
# calculate molecular weight for all compounds
gd.loc[:,'M'] = gd.Item.apply(calc_M)
In [6]:
udict = {'%m/m': 100,
'ug/g': 1e6}
In [7]:
gd.loc[:,'g/g'] = gd.Value / [udict[u] for u in gd.Unit]
gd.loc[:,'g/g_err'] = gd.Uncertainty / [udict[u] for u in gd.Unit]
In [8]:
gd.loc[:,'mol/g'] = gd.loc[:,'g/g'] / gd.loc[:,'M']
gd.loc[:,'mol/g_err'] = gd.loc[:,'g/g_err'] / gd.loc[:,'M']
In [9]:
gd.to_csv('GeoRem_Preferred_170622.csv', index=False)
In [153]:
srmdat = gd.copy()
In [154]:
internal_standard = 'Si29'
In [155]:
internal_el = re.match('([A-Z][a-z]{0,})',internal_standard).groups()[0]
In [157]:
denom
Out[157]:
In [161]:
for srm in srmdat.SRM.unique():
ind = srmdat.SRM == srm
# find denominator
denom = srmdat.loc[srmdat.Item.str.contains(internal_el) & ind]
# calculate denominator composition
comp = re.findall('([A-Z][a-z]{0,})([0-9]{0,})',
denom.Item.values[0])
# determine stoichiometric multiplier
N = [n for el, n in comp if el == internal_el][0]
if N == '':
N = 1
else:
N = float(N)
srmdat.loc[ind, 'mol_ratio'] = srmdat.loc[ind, 'mol/g'] / (denom['mol/g'].values * N)
srmdat.loc[ind, 'mol_ratio_err'] = ((srmdat.loc[ind, 'mol/g_err'] / srmdat.loc[ind, 'mol/g'])**2 +
(denom['mol/g_err'].values / denom['mol/g'].values))**0.5 * srmdat.loc[ind, 'mol_ratio']
# srmdat.loc[ind]
In [162]:
srmdat
Out[162]:
In [134]:
N
Out[134]:
In [128]:
re.findall('([A-Z][a-z]{0,})([0-9]{0,})',
denom.Item.values[0])
Out[128]:
In [127]:
Out[127]:
In [107]:
denom =
In [108]:
denom
Out[108]:
In [105]:
denom
Out[105]: