In [1]:
import pandas as pd
import numpy as np
import latools as la
from comparison_tools import helpers, stats_zircon, plots_zircon
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
dataformat = {'genfromtext_args': {'delimiter': ',',
'skip_header': 4,
'skip_footer': 3},
'column_id': {'name_row': 3,
'delimiter': ',',
'timecolumn': 0,
'pattern': '([A-z]{1,2}[0-9]{1,3})'},
'meta_regex': {2: (['date', 'method'],
'([0-9/]+ [0-9:]+ [AMP]+) using (.*?),')}
}
In [3]:
dat = la.analyse('raw_data/zircon/', dataformat=dataformat,
srm_identifier='NIST', internal_standard='Si29')
In [4]:
sample = '119'
_ = dat.data[sample].tplot()
In [5]:
dat.despike()
In [6]:
_ = dat.data[sample].tplot()
In [7]:
dat.autorange(on_mult=(1.5, 1), off_mult=(1., 3.))
In [8]:
_ = dat.data[sample].tplot(ranges=True)
In [9]:
dat.bkg_calc_weightedmean(weight_fwhm=800)
In [10]:
dat.bkg_plot()
Out[10]:
In [11]:
dat.bkg_subtract()
In [12]:
_ = dat.data[sample].tplot(ranges=True)
In [13]:
dat.ratio()
In [14]:
_ = dat.data[sample].tplot(ranges=True)
In [15]:
dat.calibrate(srms_used='NIST610')
In [16]:
_ = dat.calibration_plot(ncol=4)
In [17]:
_ = dat.data[sample].tplot(ranges=True)
In [18]:
dat.analytes
Out[18]:
In [19]:
# subsets of a few contaminant-related elements, and a few elements of interest
contam = ['La139', 'Ti49', 'Mg24', 'Al27']
interest = ['Pb206', 'Hf177', 'Nd146']
In [20]:
_ = dat.data[sample].tplot(contam, ranges=True)
In [21]:
_ = dat.data[sample].tplot(interest, ranges=True)
This shows us that some of the elements we're interested in (e.g. Nd) are influence by contamination
In [22]:
fig, axs = dat.crossplot(contam + interest, mode='scatter', filt=False)
In [23]:
from latools.helpers.chemistry import to_molar_ratio
In [24]:
# calculate molar ratio thresholds
La_thresh = to_molar_ratio(320e-9, 16e-2, 138.9, 28.09) * 10
Ti_thresh = to_molar_ratio(12e-6, 16e-2, 47.9, 28.09) * 5
In [25]:
dat.filter_clear()
dat.filter_threshold('La139', La_thresh)
In [26]:
# dat.filter_clear()
dat.filter_threshold('Ti49', Ti_thresh)
In [27]:
dat.filter_on('Ti49_thresh_below', show_status=False)
dat.filter_on('La139_thresh_below', show_status=True)
In [28]:
_ = dat.filter_nremoved()
In [29]:
fig, axs = dat.crossplot(contam + interest, mode='scatter', filt=True)
In [30]:
_ = dat.data[sample].tplot(contam, filt=True)
This has done a pretty good job of removing the bad data at the end, but the contamination at the start is still included.
In [31]:
dat.filter_defragment(4, 'exclude')
In [32]:
dat.filter_off()
dat.filter_on('defrag')
In [33]:
dat.optimise_signal(['Ti49', 'La139', 'Al27'], threshold_mode='kde_first_max', x_bias=0.2)
In [34]:
dat.optimisation_plots(filt=True)
In [35]:
dat.filter_off()
dat.filter_on('optim', show_status=True)
In [36]:
_ = dat.data[sample].tplot(contam, filt=True)
Done a pretty good job!
In [37]:
# trim filter edges, to be conservative
dat.filter_trim(start=1, end=1)
In [38]:
dat.filter_off()
dat.filter_on('trim')
In [39]:
fig, axs = dat.crossplot(contam, mode='scatter', filt=True)
In [40]:
# f, a = dat.gradient_crossplot(contam, mode='scatter', win=5, filt=True)
In [41]:
dat.minimal_export(path='raw_data/zircon_export/minimal_export.zip')
In [42]:
import re
import numpy as np
import pandas as pd
from latools.helpers.chemistry import elements, calc_M, to_mass_fraction
In [43]:
rd = helpers.load_reference_data('zircon_reference')
In [44]:
rd.index = rd.index.droplevel('rep')
In [45]:
# 'H15' stats are Huber 'robust' statistics, which recursively remove outliers
dat.sample_stats(stats=['H15_mean', 'H15_se'])
In [46]:
las = dat.getstats()
In [47]:
# remove 'replicate' from index
las.index = las.index.droplevel('rep')
In [48]:
# convert lead 206 to total lead
els = elements().set_index('isotope')
las.loc[:,'Pb206'] /= (100 / els.loc[206, 'percent'])
In [49]:
# rename columns to element names
ename = re.compile('[A-z]+')
las.columns = [ename.match(c).group() for c in las.columns]
In [50]:
# load mass list
els = elements(all_isotopes=False)
In [51]:
els['Si']
Out[51]:
In [52]:
# calculate wt% Si from wt% SiO2
rd.loc[:, 'wtpcSi'] = rd.loc[:, 'SiO2'] * els['Si'] / calc_M('SiO2')
In [53]:
# transfer wt% Si to latools data
la_ppm = las.join(rd.loc[:, 'wtpcSi'], how='inner')
In [54]:
# calculate mass fractions
for c in las.columns:
la_ppm.loc[:, c] = to_mass_fraction(las.loc[:, c], la_ppm.loc[:, 'wtpcSi'] * 1e-2,
els[ename.match(c).group()], els['Si'])
In [55]:
# convert Al to wt% Al2
la_ppm.loc[:, 'Al'] *= (2 * 1e-4)
In [56]:
# isolate means
lad = la_ppm.loc['H15_mean',:].join(la_ppm.loc['H15_se', :], rsuffix='_err') * 1e6 # convert to ppm
In [57]:
# combine data
comp = lad.join(rd, lsuffix='_la', rsuffix='_rd')
In [58]:
from comparison_tools.plots import get_panel_bounds
In [59]:
fig, axs = plots_zircon.bland_altman_plots(comp)
In [60]:
fig.savefig('Figures/zircon_comparison.pdf')
fig.savefig('Figures/zircon_comparison.png', dpi=200)
In [61]:
stat = stats_zircon.comparison_stats(comp)
In [62]:
stat.to_csv('Stats/zircon_stats.csv')