StatGeochem
Documentation for StatGeochem.
StatGeochem.Ayers_tsphene
StatGeochem.Ayers_tspheneTiO2
StatGeochem.Boehnke_tzirc
StatGeochem.Boehnke_tzircM
StatGeochem.Boehnke_tzircZr
StatGeochem.Harrison_tapatite
StatGeochem.Harrison_tapatiteP
StatGeochem.Harrison_tapatiteP2O5
StatGeochem.LREEmolwt
StatGeochem.LREEt
StatGeochem.MSWD
StatGeochem.Montel_tmonazite
StatGeochem.Montel_tmonaziteREE
StatGeochem.Rusiecka_tmonaziteREE
StatGeochem.Rusiecka_txenotimeY
StatGeochem.Tollari_tapatite
StatGeochem.Tollari_tapatiteP2O5
StatGeochem.arcdistance
StatGeochem.awmean
StatGeochem.bin_bsr
StatGeochem.bin_bsr_ratios
StatGeochem.bincounts
StatGeochem.binmeans
StatGeochem.binmedians
StatGeochem.bsr!
StatGeochem.bsresample
StatGeochem.bsresample
StatGeochem.changepoint
StatGeochem.cntr
StatGeochem.concatenatedatasets
StatGeochem.count_unique!
StatGeochem.delim_string_function
StatGeochem.delim_string_parse
StatGeochem.delim_string_parse!
StatGeochem.digitize_plotline
StatGeochem.digitize_plotmarkers
StatGeochem.draw_from_distribution
StatGeochem.draw_from_distribution!
StatGeochem.elementify
StatGeochem.eustar
StatGeochem.eustar
StatGeochem.exportdataset
StatGeochem.feoconversion
StatGeochem.find_grid_inpolygon
StatGeochem.find_tc1_age
StatGeochem.find_tc1_crust
StatGeochem.find_tc1_lith
StatGeochem.findclosest
StatGeochem.findclosestabove
StatGeochem.findclosestbelow
StatGeochem.findmatches
StatGeochem.findnth
StatGeochem.floatify
StatGeochem.gwmean
StatGeochem.importdataset
StatGeochem.inpctile
StatGeochem.inpolygon
StatGeochem.inv_sqrt
StatGeochem.invweight
StatGeochem.invweight
StatGeochem.invweight_age
StatGeochem.invweight_location
StatGeochem.melts_clean_modes
StatGeochem.melts_configure
StatGeochem.melts_query
StatGeochem.melts_query_liquid
StatGeochem.melts_query_modes
StatGeochem.melts_query_solid
StatGeochem.midpointintegrate
StatGeochem.movmean
StatGeochem.nanaad
StatGeochem.nanadd
StatGeochem.nanadd
StatGeochem.nanadd!
StatGeochem.nanextrema
StatGeochem.nanmad
StatGeochem.nanmask
StatGeochem.nanmask!
StatGeochem.nanmax
StatGeochem.nanmaximum
StatGeochem.nanmean
StatGeochem.nanmean
StatGeochem.nanmean!
StatGeochem.nanmedian
StatGeochem.nanmedian
StatGeochem.nanmedian!
StatGeochem.nanmin
StatGeochem.nanminimum
StatGeochem.nanrange
StatGeochem.nanstd
StatGeochem.nansum
StatGeochem.nearest
StatGeochem.nonnumeric
StatGeochem.norm_quantile
StatGeochem.norm_width
StatGeochem.normcdf
StatGeochem.normcdf!
StatGeochem.normpdf
StatGeochem.normpdf_ll
StatGeochem.normproduct
StatGeochem.normproduct_ll
StatGeochem.oxideconversion
StatGeochem.oxideconversion!
StatGeochem.parsedlm
StatGeochem.pctile
StatGeochem.perplex_configure_geotherm
StatGeochem.perplex_configure_isobar
StatGeochem.perplex_configure_pseudosection
StatGeochem.perplex_query_modes
StatGeochem.perplex_query_modes
StatGeochem.perplex_query_phase
StatGeochem.perplex_query_phase
StatGeochem.perplex_query_point
StatGeochem.perplex_query_point
StatGeochem.perplex_query_seismic
StatGeochem.perplex_query_seismic
StatGeochem.perplex_query_system
StatGeochem.perplex_query_system
StatGeochem.plausiblynumeric
StatGeochem.randsample
StatGeochem.randsample
StatGeochem.renormalize!
StatGeochem.renormalize!
StatGeochem.standardize
StatGeochem.standardize!
StatGeochem.system
StatGeochem.trapz
StatGeochem.unelementify
StatGeochem.yorkfit
StatGeochem.zeronan!
StatGeochem.Ayers_tsphene
— MethodTC = Ayers_tsphene(SiO2, TiO2, Al2O3, FeOT, MnO, MgO, CaO, Na2O, K2O, P2O5)
Calculate sphene saturation temperature in degrees Celsius Following the sphene saturation calibration of Ayers et al., 2018 (doi: 10.1130/abs/2018AM-320568)
StatGeochem.Ayers_tspheneTiO2
— MethodTiO2Sat = Ayers_tspheneTiO2(SiO2, TiO2, Al2O3, FeOT, MnO, MgO, CaO, Na2O, K2O, P2O5, T)
Calculate sphene saturation TiO2 concentration (in wt. %) for a given temperature (in C) following the sphene saturation calibration of Ayers et al., 2018 (doi: 10.1130/abs/2018AM-320568)
StatGeochem.Boehnke_tzirc
— MethodT = Boehnke_tzirc(SiO2, TiO2, Al2O3, FeOT, MnO, MgO, CaO, Na2O, K2O, P2O5, Zr)
Calculate zircon saturation temperature in degrees Celsius Following the zircon saturation calibration of Boehnke, Watson, et al., 2013 (doi: 10.1016/j.chemgeo.2013.05.028)
StatGeochem.Boehnke_tzircM
— MethodM = Boehnke_tzircM(SiO2, TiO2, Al2O3, FeOT, MnO, MgO, CaO, Na2O, K2O, P2O5)
Calculate zircon saturation M-value based on major element concentrations Following the zircon saturation calibration of Boehnke, Watson, et al., 2013 (doi: 10.1016/j.chemgeo.2013.05.028)
StatGeochem.Boehnke_tzircZr
— MethodZrSat = Boehnke_tzircZr(SiO2, TiO2, Al2O3, FeOT, MnO, MgO, CaO, Na2O, K2O, P2O5, T)
Calculate zircon saturation Zr concentration for a given temperature (in C) Following the zircon saturation calibration of Boehnke, Watson, et al., 2013 (doi: 10.1016/j.chemgeo.2013.05.028)
StatGeochem.Harrison_tapatite
— MethodTC = Harrison_tapatite(SiO2, P2O5)
Calculate apatite saturation temperature in degrees Celcius following the apatite saturation model of Harrison and Watson 1984 (doi: 10.1016/0016-7037(84)90403-4)
StatGeochem.Harrison_tapatiteP
— MethodAs Harrison_tapatiteP2O5
, but returns saturation phosphorus concentration in PPM P
StatGeochem.Harrison_tapatiteP2O5
— MethodP2O5 = Harrison_tapatiteP2O5(SiO2, Al2O3, CaO, Na2O, K2O, T)
Calculate P2O5
concentration (in wt.%) required for apatite saturation at a given T
(in C) following the apatite saturation model of Harrison and Watson 1984 (doi: 10.1016/0016-7037(84)90403-4) with the correction of Bea et al. 1992 (doi: 10.1016/0024-4937(92)90033-U) where applicable
StatGeochem.LREEmolwt
— MethodLREEmolwt(La, Ce, Pr, Nd, Sm, Gd)
Returns the average molecular weight of the LREE considered in the REEt value from the monazite saturation model of Montel 1993 (doi: 10.1016/0009-2541(93)90250-M)
StatGeochem.LREEt
— MethodLREEt(La, Ce, Pr, Nd, Sm, Gd)
Returns the sum of the LREE concentrations divided by their respective molar masses. If REE are input in parts per million by weight (ppmw), the result is in units of moles per megagram. This is equivalent to the REEt value from the monazite saturation model of Montel 1993 (doi: 10.1016/0009-2541(93)90250-M)
StatGeochem.MSWD
— MethodMSWD(x, σ)
Return the Mean Square of Weighted Deviates (AKA the reduced chi-squared statistic) of a dataset with values x
and one-sigma uncertainties σ
StatGeochem.Montel_tmonazite
— MethodTC = Montel_tmonazite(SiO2, TiO2, Al2O3, FeOT, MgO, CaO, Na2O, K2O, Li2O, H2O, La, Ce, Pr, Nd, Sm, Gd)
Calculate monazite saturation temperature in degrees Celcius following the monazite saturation model of Montel 1993 (doi: 10.1016/0009-2541(93)90250-M)
StatGeochem.Montel_tmonaziteREE
— MethodREEt = Montel_tmonaziteREE(SiO2, TiO2, Al2O3, FeOT, MgO, CaO, Na2O, K2O, Li2O, H2O, T)
Calculate monazite saturation REEt value (in [ppm/mol.wt.]) for a given temperature (in C) following the monazite saturation model of Montel 1993 (doi: 10.1016/0009-2541(93)90250-M), where:
D = (Na + K + Li + 2Ca) / Al * 1/(Al + Si)) # all as molar cation fractions (not at. %!) ln(REEt) = 9.50 + 2.34D + 0.3879√H2O - 13318/T # H2O as wt.% REEt = Σ REEᵢ(ppm) / at. weight (g/mol)
StatGeochem.Rusiecka_tmonaziteREE
— MethodLREEt = Rusiecka_tmonaziteREE(P_ppm, TC)
Calculate the LREEt (mol/Megagram) value required for monazite saturation at a temperature of TC
degrees celcius and P
ppmw phosphorous present, following the solubility model of Rusiecka & Baker, 2019 (doi: 10.2138/am-2019-6931)
StatGeochem.Rusiecka_txenotimeY
— MethodLREEt = Rusiecka_txenotimeY(P_ppm, TC)
Calculate the Y (ppmw) concentration required for xenotime saturation at a temperature of TC
degrees celcius and P
ppmw phosphorous present, following the solubility model of Rusiecka & Baker, 2019 (doi: 10.2138/am-2019-6931)
StatGeochem.Tollari_tapatite
— MethodTC = Tollari_tapatite(SiO2, TiO2, Al2O3, FeOT, MgO, CaO, Na2O, K2O, P2O5)
Calculate apatite saturation temperature in degrees Celcius following the apatite saturation model of Tollari et al. 2006 (doi: 10.1016/j.gca.2005.11.024)
StatGeochem.Tollari_tapatiteP2O5
— MethodP2O5 = Tollari_tapatiteP2O5(SiO2, CaO, T)
Calculate P2O5
concentration (in wt.%) required for apatite saturation at a given T
(in C) following the apatite saturation model of Tollari et al. 2006 (doi: 10.1016/j.gca.2005.11.024)
StatGeochem.arcdistance
— Methodarcdistance(latᵢ,lonᵢ,lat,lon)
Calculate the distance on a sphere between the point (latᵢ
,lonᵢ
) and any number of points in (lat
,lon
). Latitude and Longitude should be specified in decimal degrees
StatGeochem.awmean
— Method(wx, wσ, mswd) = awmean(x, σ)
Weighted mean, absent the geochonologist's MSWD correction to uncertainty.
StatGeochem.bin_bsr
— Methodbin_bsr([f!::Function], x::Vector, y::VecOrMat, xmin, xmax, nbins, [w];
x_sigma = zeros(size(x)),
y_sigma = zeros(size(y)),
nresamplings = 1000,
sem = :sigma,
p = 0.2
)
Returns the bincenters c
, means or medians m
, and uncertainties of the mean or median for a variable y
binned by independent variable x
into nbins
equal bins between xmin
and xmax
, after nresamplings
boostrap resamplings with acceptance probability p
.
If a 2-d array (matrix) of y
values is provided, each column will be treated as a separate variable, means and uncertainties will be returned column-wise.
Optional keyword arguments and defaults:
x_sigma = zeros(size(x))
A vector representing the uncertainty (standard deviation) of each x value
y_sigma = zeros(size(y))
A vector representing the uncertainty (standard deviation) of each y value
nresamplings = 1000
The number of resamplings to conduct
sem = :sigma
Format of the uncertainty estimate of the distribution of the mean. If :sigma
is chosen, a tuple of three vectors (c, m, e)
will be returned, where e
is the standard error of the mean. If :CI
or :pctile
is chosen, a tuple of four vectors (c, m, el, eu)
will be returned, where el
and eu
are the lower and upper bounds of the 95% confidence interval.
p = 0.2
Resampling probabilities, either as a scalar or a vector of the same length as x
Examples:
(c,m,e) = bin_bsr(nanmedian!, x, y, 0, 4000, 40, x_sigma=0.05x, p=probability, sem=:sigma)
(c,m,el,eu) = bin_bsr(nanmean!, x, y, 0, 4000, 40, x_sigma=0.05x, p=probability, sem=:pctile)
StatGeochem.bin_bsr_ratios
— Method(c, m, el, eu) = bin_bsr_ratios([f!::Function], x::Vector, num::Vector, denom::Vector, xmin, xmax, nbins, [w];
x_sigma = zeros(size(x)),
num_sigma = zeros(size(num)),
denom_sigma = zeros(size(denom)),
nresamplings = 1000,
p::Union{Number,Vector} = 0.2
)
Returns the bincenters c
, means m
, as well as upper (el
) and lower (eu
) 95% CIs of the mean for a ratio num
/den
binned by x
into nbins
equal bins between xmin
and xmax
, after nresamplings
boostrap resamplings with acceptance probability p
.
StatGeochem.bincounts
— Method(bincenters, N) = bincounts(x::AbstractArray, xmin::Number, xmax::Number, nbins::Integer)
Tally the number of samples that fall into each of nbins
equally spaced x
bins between xmin
and xmax
, aligned with bin edges as xmin:(xmax-xmin)/nbins:xmax
StatGeochem.binmeans
— Method(c,m,e) = binmeans(x, y, xmin, xmax, nbins, [weight]; resamplingratio::Number=1)
The means (ignoring NaNs) of y
values binned by x
, into each of nbins
equally spaced x
bins between xmin
and xmax
, returning bincenters, means, and standard errors of the mean.
To calculate binned medians only (without uncertainties), see nanmean
StatGeochem.binmedians
— Method(c,m,e) = binmedians(x, y, xmin, xmax, nbins; resamplingratio::Number=1)
The medians (ignoring NaNs) of y
values binned by x
, into each of nbins
equally spaced x
bins between xmin
and xmax
, returning bincenters, medians, and equivalent standard errors of the mean (1.4828 * median abolute deviation)
To calculate binned medians only (without uncertainties), see nanmedian
StatGeochem.bsr!
— Methodbsr!([f::Function], resampled::Array, index::Vector{Int}, data, sigma, p;
rng::AbstractRNG=MersenneTwister()
)
Fill resampled
with data boostrap resampled from a (sample-per-row / element-per-column) dataset data
with uncertainties sigma
and resampling probabilities p
, optionally using random numbers generated by f
where f
is a function of the form f(rng, data[i], sigma[i])
StatGeochem.bsresample
— Functionresampled = bsresample(data::AbstractArray, sigma, nrows, [p];
kernel = gaussian,
rng = MersenneTwister(),
return_index = false
)
Bootstrap resample a (sample-per-row / element-per-column) array of data
with uncertainties sigma
and resampling probabilities p
StatGeochem.bsresample
— Functionresampled = bsresample(dataset::Dict, nrows, [elements], [p];
kernel = gaussian,
rng = MersenneTwister()
)
Bootstrap resample a dictionary-based dataset
with uncertainties stored either in dataset["err"]
or dataset["[variable]_sigma"]
StatGeochem.changepoint
— Methodchangepoint(data, [sigma], nsteps; np, npmin, npmax)
Given an ordered array of data
points, optionally with uncertainties sigma
, use a Markov chain Monte Carlo approach based on that of Gallagher et al., 2010 (10.1016/j.epsl.2011.09.015) to estimate the position (by index) and optionally number of changepoints that best explain the data
. Will return the results for nsteps
steps of the Markov chain.
Optionally, you may also specify as keyword arguments either np
or npmin
and npmax
to constrain the number of allowed changepoints.
Currently prints results to the terminal (stdout), one line per step of the Markov chain, but a more efficent output format is probably desirable in a future version of this function.
StatGeochem.cntr
— Methodcntr(edges::AbstractArray)
Given an array of bin edges, return a corresponding vector of bin centers
StatGeochem.concatenatedatasets
— Methodconcatenatedatasets(d1::AbstractDict, d2::AbstractDict)
Vertically concatenate two Dict-based datasets, variable-by-variable
StatGeochem.count_unique!
— Methodn = count_unique!(A)
Sort the array A
in-place, move unique elements to the front, and return the number of unique elements found. A[1:count_unique!(A)]
should return an array equivalent to unique(A)
StatGeochem.delim_string_function
— Methoddelim_string_function(f, str, delim, T;
merge::Bool=false,
Parse a delimited string str
with delimiter delim
into substrings that will then be operated upon by function f
. The results of f
will be returned in an array with eltype T
.
StatGeochem.delim_string_parse
— Functiondelim_string_parse(str, delim, T;
merge::Bool=false,
undefval=NaN)
Parse a delimited string str
with delimiter delim
into values of type T
and return the answers as an array with eltype T
StatGeochem.delim_string_parse!
— Functiondelim_string_parse!(result, str, delim, [T];
offset::Integer=0,
merge::Bool=false,
undefval=NaN)
Parse a delimited string str
with delimiter delim
into values of type T
and return the answers in a pre-allocated result
array provided as input.
If T
is not specified, it the eltype
of the result
array will be used by default.
StatGeochem.digitize_plotline
— Method(x,y) = digitize_plotline(img, line_color, xlims, ylims; atol=0.16)
Calculate approximate x and y positions for a colored line in an image
StatGeochem.digitize_plotmarkers
— Method(x,dx,y,dy) = digitize_plotmarkers(img, marker_color, xlims, ylims; atol=0.16)
Calculate approximate x and y positions and uncertainties for colored markers in an image
StatGeochem.draw_from_distribution!
— Methoddraw_from_distribution!(dist::AbstractArray{<:AbstractFloat}, x::Array{<:AbstractFloat})
Fill an existing variable x
with random floating point numbers drawn from a continuous probability distribution specified by a vector dist
defining the PDF curve thereof.
StatGeochem.draw_from_distribution
— Methodx = draw_from_distribution(dist::AbstractArray{<:AbstractFloat}, n::Integer)
Draw n
random floating point numbers from a continuous probability distribution specified by a vector dist
defining the PDF curve thereof.
StatGeochem.elementify
— Functionelementify(data::Array, elements::Array=data[1,:];
importas=:Dict,
standardize::Bool=true,
floattype=Float64,
skipstart::Integer=1,
skipnameless::Bool=true
)
Convert a flat array data
into a dictionary (importas=:Dict
) or named tuple (importas=:Tuple
) with each column as a variable. Tuples are substantially more efficient, so should be favored where possible.
StatGeochem.eustar
— Methodeustar(Nd::Number, Sm::Number, Gd::Number, Tb::Number)
Calculate expected europium concentration, Eu*, based on abundance of adjacent rare earths. Full four-element log-linear interpolation, using ionic radii
StatGeochem.eustar
— Methodeustar(Sm::Number, Gd::Number)
Calculate expected europium concentration, Eu*, based on abundance of adjacent rare earths. Simple geometric mean interpolation from Sm and Gd alone
StatGeochem.exportdataset
— Methodexportdataset(dataset, [elements], filepath, delim;
floatout::Bool=false,
findnumeric::Bool=false,
skipnan::Bool=true,
digits::Integer,
sigdigits::Integer
rows=:
)
Convert a dict or named tuple of vectors into a 2-D array with variables as columns Export a dataset
(in the form of either a Dict
or a NamedTuple
), optionally specifying which elements
to export, as a delimited ASCII text file with the name specified by filepath
and delimiter delim
.
Possible keyword arguments include:
digits
sigdigits
Specify a number of absolute or significant digits to which to round the printed output. Default is no rounding.
skipnan
Leave NaN
s as empty cells in the delimited output file. Boolean; true
by default.
floatout
Force all output to be represented as a floating-point number, or else NaN
. Boolean; false
by default.
findnumeric
Export only numeric columns. Boolean; false
by default.
rows
specify which rows of the dataset to export. Default :
exports all rows.
StatGeochem.feoconversion
— Functionfeoconversion(FeO::Number=NaN, Fe2O3::Number=NaN, FeOT::Number=NaN, Fe2O3T::Number=NaN)
Compiles data from FeO, Fe2O3, FeOT, and Fe2O3T into a single FeOT value.
StatGeochem.find_grid_inpolygon
— Method(rows, columns) = find_grid_inpolygon(grid_x, grid_y, poly_x, poly_y)
Find the indexes of grid points that fall within a polygon for a grid with cell centers given by gridx (j-columns of grid) and gridy (i-rows of grid). Returns a list of rows and columns in the polygon
StatGeochem.find_tc1_age
— Methodfind_tc1_age(lat::Number,lon::Number)
Return a tuple (age, age_min, age_max)
containing the nominal, upper, and lower tc1 age bounds for the 1x1 arc degree grid cell containing lat
and lon
find_tc1_age(lat::AbstractArray,lon::AbstractArray)
Return a tuple (age, age_min, age_max)
where age
, age_min
, and age_max
are arrays containing the nominal, upper and lower tc1 age bounds for each location pair lat[i]
, lon[i]
StatGeochem.find_tc1_crust
— Methodfind_tc1_crust(lat::Number,lon::Number)
Find the depth to the 550C isotherm for the 1x1 arc degree grid cell containing lat
and lon
find_tc1_crust(lat::AbstractArray,lon::AbstractArray)
For each pair of latitudes and longitudes given by lat and lon, find the depth to the 550C isotherm for the 1x1 arc degree grid cell containing lat[i]
and lon[i]
StatGeochem.find_tc1_lith
— Methodfind_tc1_lith(lat::Number,lon::Number)
Find the depth to the 1300C isotherm for the 1x1 arc degree grid cell containing lat
and lon
find_tc1_lith(lat::AbstractArray,lon::AbstractArray)
For each pair of latitudes and longitudes given by lat and lon, find the depth to the 1300C isotherm for the 1x1 arc degree grid cell containing lat[i]
and lon[i]
StatGeochem.findclosest
— Methodfindclosest(source, target)
Return the index of the numerically closest value in the indexable collection target
for each value in source
. If muliple values are equally close, the first one is used
StatGeochem.findclosestabove
— Methodfindclosestabove(source, target)
Return the index of the nearest value of the indexable collection target
that is greater than (i.e., "above") each value in source
. If no such values exist in target
, returns an index of 0.
StatGeochem.findclosestbelow
— Methodfindclosestbelow(source, target)
Return the index of the nearest value of the indexable collection target
that is less than (i.e., "below") each value in source
. If no such target values exist in target
, returns an index of 0.
StatGeochem.findmatches
— Methodfindmatches(source, target)
Return the index of the first value in target
(if any) that is equal to a given value in source
for each value in source
; else 0.
StatGeochem.findnth
— Methodfindnth(t::AbstractArray{Bool}, n::Integer)
Return the index of the n
th true value of t
, else length(t
)
StatGeochem.floatify
— Functionfloatify(x, T::Type=Float64)
Convert x
to a floating-point number (default Float64
) by any means necessary
StatGeochem.gwmean
— Method(wx, wσ, mswd) = gwmean(x, σ)
Geochronologist's weighted mean, with "MSWD correction" to uncertainty, i.e., wσ is increased by a factor of sqrt(mswd)
StatGeochem.importdataset
— Methodfunction importdataset(filepath, delim;
importas=:Dict,
standardize::Bool=true,
floattype=Float64,
skipstart::Integer=0,
skipnameless::Bool=true,
mindefinedcolumns::Integer=0
)
Import a delimited file specified by filepath
with delimiter delim
as a dataset in the form of either a Dict
or a NamedTuple
.
Possible keyword arguments include:
importas
Specify the format of the imported dataset. Options include :Dict
and :Tuple
standardize
Convert columns to uniform type wherever possible. Boolean; true
by default.
floattype
Preferred floating-point type for numerical data. Float64
by default.
skipstart
Ignore this many rows at the start of the input file (useful if input file has a header or other text before the column names). 0
by default.
skipnameless
Skip columns with no column name. Boolean; true
by default
mindefinedcolumns
Skip rows with fewer than this number of delimiters. 0
by default.
StatGeochem.inpctile
— Methodinpctile(A, p::Number; dims)
Return a boolean array that identifies which values of the iterable collection A
fall within the central p
th percentile, optionally along a dimension specified by dims
.
A valid percentile value must satisfy 0 <= p
<= 100.
StatGeochem.inpolygon
— Methodinpolygon(x,y,point)
Check if a 2D polygon defined by the arrays x
, y
contains a given point
. Returns boolean (true or false)
StatGeochem.inv_sqrt
— Methodinv_sqrt(x)
The fast inverse square root of x
, in 32 and 64 bit versions. Can be up to 10x faster than base 1/sqrt(x)
, though with significant loss of precision. The implementations here are good to about 4 ppm.
StatGeochem.invweight
— Methodk = invweight(lat::AbstractArray, lon::AbstractArray, age::AbstractArray;
lp::Number=2,
spatialscale=1.8,
agescale=38.0
)
Find the inverse weights k
(proportional to spatiotemporal sample density) for a set of geological samples with specified latitude (lat
), logitude (lon
), and age
(of crystallization, deposition, etc.).
The default spatialscale
and agescale
are taken from Keller and Schoene 2012. However, alternative scalings can be supplied. If an array is supplied for either spatialscale
, agescale
, or both, a 3-d matrix of k
values will be returned, with dimensions length(spatialscale
)length(agescale
)nrows.
StatGeochem.invweight
— Methodk = invweight(nums::AbstractArray, scale::Number; lp=2)
Find the inverse weights for a single array nums
for a given scale
, and exponent lp
(default lp = 2).
Returns an array k where k[i] is the "inverse weight" for element i of the input array.
StatGeochem.invweight_age
— Methodk = invweight_age(age::AbstractArray; lp::Number=2, agescale::Number=38.0)
Find the inverse weights k
(proportional to temporal sample density) for a set of geological samples with specified age
(of crystallization, deposition, etc.).
StatGeochem.invweight_location
— Methodk = invweight_location(lat::AbstractArray, lon::AbstractArray;
lp::Number=2,
spatialscale::Number=1.8
)
Find the inverse weights k
(proportional to spatial sample density) for a set of geological samples with specified latitude (lat
), and logitude (lon
).
StatGeochem.melts_clean_modes
— Methodmelts_clean_modes(scratchdir::String; index=1)
Read and parse / clean-up modal phase proportions from specified MELTS run directory Returns an elementified dictionary
StatGeochem.melts_configure
— Functionmelts_configure(meltspath::String, scratchdir::String, composition::Array{Float64},
elements::Array,
T_range::Array=[1400, 600],
P_range::Array=[10000,10000];)
Configure and run a MELTS simulation using alphaMELTS. Optional keyword arguments and defaults:
batchstring::String="1 sc.melts 10 1 3 1 liquid 1 1.0 0 10 0 4 0 "
dT = -10
dP = 0
index = 1
version = "pMELTS"
mode = "isobaric"
fo2path = "FMQ"
Oxygen fugacity buffer to follow, e.g., FMQ
or NNO+1
fractionatesolids::Bool = false
Fractionate all solids
suppress::Array{String} = []
Supress individual phases (specify as strings in array, i.e. ["leucite"]
)
verbose::Bool = true
Print verbose MELTS output to terminal (else, write it to melts.log
)
StatGeochem.melts_query
— Methodmelts_query_modes(scratchdir::String; index=1)
Read all phase proportions from Phase_main_tbl.txt
in specified MELTS run directory Returns an elementified dictionary
StatGeochem.melts_query_liquid
— Methodmelts_query_liquid(scratchdir::String; index=1)
Read liquid composition from Liquid_comp_tbl.txt
in specified MELTS run directory Returns an elementified dictionary
StatGeochem.melts_query_modes
— Methodmelts_query_modes(scratchdir::String; index=1)
Read modal phase proportions from Phase_mass_tbl.txt
in specified MELTS run Returns an elementified dictionary
StatGeochem.melts_query_solid
— Methodmelts_query_solid(scratchdir::String; index=1)
Read solid composition from Solid_comp_tbl.txt
in specified MELTS run directory Returns an elementified dictionary
StatGeochem.midpointintegrate
— Methodmidpointintegrate(bincenters, values)
Add up the area under a curve with y positions specified by a vector of values
and x positions specfied by a vector of bincenters
using midpoint integration.
StatGeochem.movmean
— Methodmovmean(x::AbstractVecOrMat, n::Number)
Simple moving average of x
in 1 or 2 dimensions, spanning n
bins (or n*n in 2D)
StatGeochem.nanaad
— Methodnanaad(A; dims)
Mean (average) absolute deviation from the mean, ignoring NaNs, of an indexable collection A
, optionally along a dimension specified by dims
. Note that for a Normal distribution, sigma = 1.253 * AAD
StatGeochem.nanadd!
— Methodnanadd!(A::Array, B)
Add the non-NaN elements of B
to A
, treating NaNs as zeros
StatGeochem.nanadd
— Methodnanadd(a::Number, b::Number)
Add a
to b
, returning NaN only if both are NaN
StatGeochem.nanadd
— Methodnanadd(A::AbstractArray, B::AbstractArray)
Add the non-NaN elements of A and B, treating NaNs as zeros
StatGeochem.nanextrema
— Methodnanextrema(A; dims)
Find the extrema (maximum & minimum) of an indexable collection A
, ignoring NaNs, optionally along a dimension specified by dims
.
StatGeochem.nanmad
— Methodnanmad(A; dims)
Median absolute deviation from the median, ignoring NaNs, of an indexable collection A
, optionally along a dimension specified by dims
. Note that for a Normal distribution, sigma = 1.4826 * MAD
StatGeochem.nanmask!
— Methodnanmask!(mask, A)
Fill a Boolean mask of dimensions size(A)
that is false wherever A
is NaN
StatGeochem.nanmask
— Methodnanmask(A)
Create a Boolean mask of dimensions size(A)
that is false wherever A
is NaN
StatGeochem.nanmax
— Methodnanmax(a,b)
As max(a,b)
, but if either argument is NaN
, return the other one
StatGeochem.nanmaximum
— Methodnanmaximum(A; dims)
Find the largest non-NaN value of an indexable collection A
, optionally along a dimension specified by dims
.
StatGeochem.nanmean!
— Methodnanmean!(MU, [N], x, y, [w], xmin::Number, xmax::Number, nbins::Integer)
Ignoring NaNs, fill the array MU
with the means (and optionally N
with the counts) of non-NAN y
values that fall into each of nbins
equally spaced x
bins between xmin
and xmax
, aligned with bin edges as xmin
:(xmax
-xmin
)/nbins
:xmax
If an optional array of weights [w
] is specified, then N
is required, and will be filled with the sum of weights for each bin.
The array of x
data should given as a one-dimensional array (any subtype of AbstractVector) and y
as either a 1-d or 2-d array (any subtype of AbstractVecOrMat).
The output arrays MU
and N
must be the same size, and must have the same number of columns as y
; if y
is a 2-d array (matrix), then each column of y
will be treated as a separate variable.
StatGeochem.nanmean
— Methodnanmean(x, y, [w], xmin::Number, xmax::Number, nbins::Integer)
Ignoring NaNs, calculate the mean (optionally weighted) of y
values that fall into each of nbins
equally spaced x
bins between xmin
and xmax
, aligned with bin edges as xmin
:(xmax
-xmin
)/nbins
:xmax
The array of x
data should given as a one-dimensional array (any subtype of AbstractVector) and y
as either a 1-d or 2-d array (any subtype of AbstractVecOrMat). If y
is a 2-d array, then each column of y
will be treated as a separate variable.
StatGeochem.nanmean
— Methodnanmean(A, [W]; dims)
Ignoring NaNs, calculate the mean (optionally weighted) of an indexable collection A
, optionally along dimensions specified by dims
.
StatGeochem.nanmedian!
— Methodnanmedian!(M::AbstractVecOrMat, x::AbstractVector, y::AbstractVecOrMat, xmin::Number, xmax::Number, nbins::Integer)
Fill the array M
with the medians of non-NaN y
values that fall into each of nbins
equally spaced x
bins between xmin
and xmax
, aligned with bin edges as xmin
:(xmax
-xmin
)/nbins
:xmax
If y
is a 2-d array (matrix), each column will be treated as a separate variable
StatGeochem.nanmedian
— Methodnanmedian(x::AbstractVector, y::AbstractVecOrMat, xmin::Number, xmax::Number, nbins::Integer)
Calculate the median, ignoring NaNs, of y values that fall into each of nbins
equally spaced x
bins between xmin
and xmax
, aligned with bin edges as xmin
:(xmax
-xmin
)/nbins
:xmax
If y
is a 2-d array (matrix), each column will be treated as a separate variable
StatGeochem.nanmedian
— Methodnanmedian(A; dims)
Calculate the median, ignoring NaNs, of an indexable collection A
, optionally along a dimension specified by dims
.
StatGeochem.nanmin
— Methodnanmin(a,b)
As min(a,b)
, but if either argument is NaN
, return the other one
StatGeochem.nanminimum
— Methodnanminimum(A; dims)
As minimum
but ignoring NaN
s: Find the smallest non-NaN
value of an indexable collection A
, optionally along a dimension specified by dims
.
StatGeochem.nanrange
— Methodnanrange(A; dims)
Calculate the range (maximum - minimum) of an indexable collection A
, ignoring NaNs, optionally along a dimension specified by dims
.
StatGeochem.nanstd
— Methodnanstd(A, [W]; dims)
Calculate the standard deviation (optionaly weighted), ignoring NaNs, of an indexable collection A
, optionally along a dimension specified by dims
.
StatGeochem.nansum
— Methodnansum(A; dims)
Calculate the sum of an indexable collection A
, ignoring NaNs, optionally along dimensions specified by dims
.
StatGeochem.nearest
— Methodnearest(T, x)
Convert x
to the nearest representable value in type T, rounding if inexact
StatGeochem.nonnumeric
— Methodnonnumeric(x)
Return true for if x
is not missing but cannot be parsed as a number
StatGeochem.norm_quantile
— Methodnorm_quantile(F::Number)
How far away from the mean (in units of sigma) should we expect proportion F of the samples to fall in a standard Gaussian (Normal[0,1]) distribution
StatGeochem.norm_width
— Methodnorm_width(N::Number)
How dispersed (in units of sigma) should we expect a sample of N numbers drawn from a standard Gaussian (Normal[0,1]) distribution to be?
StatGeochem.normcdf!
— Methodnormcdf!(result,mu,sigma,x)
In-place version of normcdf
StatGeochem.normcdf
— Methodnormcdf(mu,sigma,x)
Cumulative density function of the Normal (Gaussian) distribution
$1/2 + erf(rac{x-μ}{σ√2})/2$
with mean mu
and standard deviation sigma
, evaluated at x
.
StatGeochem.normpdf
— Methodnormpdf(mu,sigma,x)
Probability density function of the Normal (Gaussian) distribution
$ℯ^{-(x-μ)^2 / (2σ^2)} / σ√2π$
with mean mu
and standard deviation sigma
, evaluated at x
StatGeochem.normpdf_ll
— Methodnormpdf_ll(mu, sigma, x)
Fast log likelihood corresponding to a Normal (Gaussian) distribution with mean mu
and standard deviation sigma
, evaluated at x
.
If x
, [mu
, and sigma
] are given as arrays, the sum of the log likelihood over all x
will be returned.
See also normpdf
StatGeochem.normproduct
— Methodnormproduct(μ1, σ1, μ2, σ2)
The integral of the product of two normal distributions N[μ1,σ1] * N[μ2,σ2]. This is itself just another Normal distribution! Specifically, one with variance σ1^2 + σ2^2, evaluated at distance |μ1-μ2| from the mean
StatGeochem.normproduct_ll
— Methodnormproduct_ll(μ1, σ1, μ2, σ2)
Log likelihood corresponding to the integral of N[μ1,σ1] * N[μ2,σ2] As normproduct
, but using the fast log likelihood of a Normal distribution
StatGeochem.oxideconversion!
— Methoddataset = oxideconversion!(dataset::Dict; unitratio::Number=10000)
Convert major elements (Ti, Al, etc.) into corresponding oxides (TiO2, Al2O3, ...) in place.
If metals are as PPM, set unitratio=10000 (default); if metals are as wt%, set unitratio = 1
StatGeochem.oxideconversion
— Methoddataset = oxideconversion(dataset::Dict; unitratio::Number=10000)
Convert major elements (Ti, Al, etc.) into corresponding oxides (TiO2, Al2O3, ...).
If metals are as PPM, set unitratio=10000 (default); if metals are as wt%, set unitratio = 1
StatGeochem.parsedlm
— Functionparsedlm(str::AbstractString, delimiter::Char, T::Type=Float64; rowdelimiter::Char='\n')
Parse a string delimited by both row and column into a single (2-D) matrix. Default column delimiter is newline. Similar to readdlm
, but operating on a string instead of a file.
StatGeochem.pctile
— Methodpctile(A, p; dims)
Find the p
th percentile of an indexable collection A
, ignoring NaNs, optionally along a dimension specified by dims
.
A valid percentile value must satisfy 0 <= p
<= 100.
StatGeochem.perplex_configure_geotherm
— Functionperplex_configure_geotherm(perplexdir::String, scratchdir::String, composition::Array{<:Number},
elements::String=["SIO2","TIO2","AL2O3","FEO","MGO","CAO","NA2O","K2O","H2O"],
P_range::Array{<:Number}=[280,28000], T_surf::Number=273.15, geotherm::Number=0.1;
dataset::String="hp02ver.dat",
index::Integer=1,
npoints::Integer=100,
solution_phases::String="O(HP)\nOpx(HP)\nOmph(GHP)\nGt(HP)\noAmph(DP)\ncAmph(DP)\nT\nB\nChl(HP)\nBio(TCC)\nMica(CF)\nCtd(HP)\nIlHm(A)\nSp(HP)\nSapp(HP)\nSt(HP)\nfeldspar_B\nDo(HP)\nF\n",
excludes::String="ts\nparg\ngl\nged\nfanth\ng\n",
mode_basis::String="vol", #["vol", "wt", "mol"]
composition_basis::String="wt", #["vol", "wt", "mol"]
fluid_eos::Integer=5)
Set up a PerpleX calculation for a single bulk composition along a specified geothermal gradient and pressure (depth) range. P specified in bar and T_surf in Kelvin, with geothermal gradient in units of Kelvin/bar
StatGeochem.perplex_configure_isobar
— Functionperplex_configure_isobar(perplexdir::String, scratchdir::String, composition::Array{<:Number},
elements::String=["SIO2","TIO2","AL2O3","FEO","MGO","CAO","NA2O","K2O","H2O"]
P::Number=10000, T::Array{<:Number}=[500+273.15, 1500+273.15];
dataset::String="hp11ver.dat",
index::Integer=1,
npoints::Integer=100,
solution_phases::String="O(HP)\nOpx(HP)\nOmph(GHP)\nGt(HP)\noAmph(DP)\ncAmph(DP)\nT\nB\nChl(HP)\nBio(TCC)\nMica(CF)\nCtd(HP)\nIlHm(A)\nSp(HP)\nSapp(HP)\nSt(HP)\nfeldspar_B\nDo(HP)\nF\n",
excludes::String="ts\nparg\ngl\nged\nfanth\ng\n",
mode_basis::String="vol", #["vol", "wt", "mol"]
composition_basis::String="wt", #["vol", "wt", "mol"]
fluid_eos::Integer=5)
Set up a PerpleX calculation for a single bulk composition along a specified isobaric temperature gradient. P specified in bar and T_range in Kelvin
StatGeochem.perplex_configure_pseudosection
— Functionperplex_configure_pseudosection(perplexdir::String, scratchdir::String, composition::Array{<:Number},
elements::Array{String}=["SIO2","TIO2","AL2O3","FEO","MGO","CAO","NA2O","K2O","H2O"],
P::Array{<:Number}=[280, 28000], T::Array{<:Number}=[273.15, 1500+273.15];
dataset::String="hp11ver.dat",
index::Integer=1,
xnodes::Integer=42,
ynodes::Integer=42,
solution_phases::String="O(HP)\nOpx(HP)\nOmph(GHP)\nGt(HP)\noAmph(DP)\ncAmph(DP)\nT\nB\nChl(HP)\nBio(TCC)\nMica(CF)\nCtd(HP)\nIlHm(A)\nSp(HP)\nSapp(HP)\nSt(HP)\nfeldspar_B\nDo(HP)\nF\n",
excludes::String="ts\nparg\ngl\nged\nfanth\ng\n",
mode_basis::String="vol", #["vol", "wt", "mol"]
composition_basis::String="wt", #["wt", "mol"]
fluid_eos::Number=5)
Set up a PerpleX calculation for a single bulk composition across an entire 2d P-T space. P specified in bar and T in Kelvin.
StatGeochem.perplex_query_modes
— Methodperplex_query_modes(perplexdir::String, scratchdir::String, P::Array{<:Number}, T::Array{<:Number};
index::Integer=1, npoints::Integer=200, include_fluid="y")
Query modal mineralogy (mass proportions) along a specified P-T path using a pre-computed pseudosection. Results are returned as a dictionary.
StatGeochem.perplex_query_modes
— Methodperplex_query_modes(perplexdir::String, scratchdir::String;
dof::Integer=1, index::Integer=1, include_fluid="y")
Query modal mineralogy (mass proportions) along a previously configured 1-d path (dof=1, isobar or geotherm) or 2-d grid / pseudosection (dof=2). Results are returned as a dictionary.
Currently returns vol %
StatGeochem.perplex_query_phase
— Methodperplex_query_phase(perplexdir::String, scratchdir::String, phase::String, P::Array{<:Number}, T::Array{<:Number};
index::Integer=1, npoints::Integer=200, include_fluid="y", clean_units::Bool=true)
Query all perplex-calculated properties for a specified phase (e.g. "Melt(G)") along a specified P-T path using a pre-computed pseudosection. Results are returned as a dictionary.
StatGeochem.perplex_query_phase
— Methodperplex_query_phase(perplexdir::String, scratchdir::String, phase::String;
dof::Integer=1, index::Integer=1, include_fluid="y", clean_units::Bool=true)
Query all perplex-calculated properties for a specified phase (e.g. "Melt(G)") along a previously configured 1-d path (dof=1, isobar or geotherm) or 2-d grid / pseudosection (dof=2). Results are returned as a dictionary.
StatGeochem.perplex_query_point
— Methodperplex_query_point(perplexdir::String, scratchdir::String, P::Number, T::Number; index::Integer=1)
Query perplex results at a single P,T point in a pseudosection. Results are returned as a string.
StatGeochem.perplex_query_point
— Methodperplex_query_point(perplexdir::String, scratchdir::String, indvar::Number; index::Integer=1)
Query perplex results at a single temperature on an isobar or single pressure on a geotherm. Results are returned as a string.
StatGeochem.perplex_query_seismic
— Methodperplex_query_seismic(perplexdir::String, scratchdir::String, P::Array{<:Number}, T::Array{<:Number};
index::Integer=1, npoints::Integer=200, include_fluid="n")
Query perplex seismic results along a specified P-T path using a pre-computed pseudosection. Results are returned as a dictionary.
StatGeochem.perplex_query_seismic
— Methodperplex_query_seismic(perplexdir::String, scratchdir::String;
dof::Integer=1, index::Integer=1, include_fluid="n")
Query perplex seismic results along a previously configured 1-d path (dof=1, isobar or geotherm) or 2-d grid / pseudosection (dof=2). Results are returned as a dictionary.
StatGeochem.perplex_query_system
— Methodfunction perplex_query_system(perplexdir::String, scratchdir::String, P::Array{<:Number}, T::Array{<:Number};
index::Integer=1, npoints::Integer=200, include_fluid="y",clean_units::Bool=true)
Query all perplex-calculated properties for the system (with or without fluid) along a specified P-T path using a pre-computed pseudosection. Results are returned as a dictionary. Set include_fluid="n" to return solid+melt only.
StatGeochem.perplex_query_system
— Methodperplex_query_system(perplexdir::String, scratchdir::String;
index::Integer=1, include_fluid="y", clean_units::Bool=true)
?
Query all perplex-calculated properties for the system (with or without fluid) along a previously configured 1-d path (dof=1, isobar or geotherm) or 2-d grid / pseudosection (dof=2). Results are returned as a dictionary. Set include_fluid="n" to return solid+melt only.
StatGeochem.plausiblynumeric
— Methodplausiblynumeric(x)
Return true
if x
can be parsed as a number, else false
StatGeochem.randsample
— Functionrandsample(data::Array, nrows, [p])
Bootstrap resample (without uncertainty) a data
array to length nrows
. Optionally provide weights p
either as a vector (one-weight-per-sample) or scalar.
StatGeochem.randsample
— Functionrandsample(dataset::Dict, nrows, [elements], [p])
Bootstrap resample (without uncertainty) a dataset
dict to length nrows
. Optionally provide weights p
either as a vector (one-weight-per-sample) or scalar.
StatGeochem.renormalize!
— Functionrenormalize!(dataset, [elements]; total=1.0)
Normalize in-place a (i.e., compositional) dataset
defined by a Dict
or NamedTuple
of one-dimensional numerical arrays, such that all the elements
(i.e., variables – by default all keys in the datset) sum to a given total
(by default, 1.0
).
Note that the arrays representing each element or variable are assumed to be of uniform length
StatGeochem.renormalize!
— Methodrenormalize!(A::AbstractArray; dim, total=1.0)
Normalize an array A
in place such that it sums to total
. Optionally may specify a dimension dim
along which to normalize.
StatGeochem.standardize!
— Methodstandardize!(A::Array{<:AbstractFloat}; dims)
Rescale A
to unit variance and zero mean
StatGeochem.standardize
— Methodstandardize(A; dims)
Rescale a copy of A
to unit variance and zero mean
StatGeochem.system
— Methodsystem(cmdstr::AbstractString)
Direct access to the command line through C's system
function – without stripping/sanitizing special characters, in contrast to Julia's safer run()
function. This allows pipelining, etc. in shell commands. Returns 0 on success.
StatGeochem.trapz
— Methodtrapz(edges, values)
Add up the area under a curve with y positions specified by a vector of values
and x positions specfied by a vector of edges
using trapezoidal integration. Bins need not be evenly spaced, though it helps.
StatGeochem.unelementify
— Functionunelementify(dataset, elements;
floatout::Bool=false,
floattype=Float64,
findnumeric::Bool=false,
skipnan::Bool=false,
rows=:
)
Convert a dict or named tuple of vectors into a 2-D array with variables as columns
StatGeochem.yorkfit
— Methodyorkfit(x, σx, y, σy)
Uses the York (1968) least-squares fit to calculate a
, b
, and uncertanties σa
, σb
for the equation y = a + bx
StatGeochem.zeronan!
— Methodzeronan!(A)
Replace all NaN
s in A with zeros of the same type