StatGeochemBase
Documentation for StatGeochemBase.
StatGeochemBase.DictDatasetStatGeochemBase.TupleDatasetStatGeochemBase.arcdistanceStatGeochemBase.cntrStatGeochemBase.concatenatedatasetsStatGeochemBase.containsiStatGeochemBase.copyat!StatGeochemBase.count_unique!StatGeochemBase.delim_string_functionStatGeochemBase.delim_string_parseStatGeochemBase.delim_string_parse!StatGeochemBase.draw_from_distributionStatGeochemBase.draw_from_distribution!StatGeochemBase.elementifyStatGeochemBase.exportdatasetStatGeochemBase.fast_inv_sqrtStatGeochemBase.find_grid_inpolygonStatGeochemBase.findclosestStatGeochemBase.findclosestaboveStatGeochemBase.findclosestbelowStatGeochemBase.findclosestunequalStatGeochemBase.findmatchesStatGeochemBase.findnthStatGeochemBase.floatifyStatGeochemBase.hashdatasetStatGeochemBase.image_from_pathsStatGeochemBase.image_from_paths!StatGeochemBase.importdatasetStatGeochemBase.imscStatGeochemBase.imsciStatGeochemBase.inpolygonStatGeochemBase.isnumericStatGeochemBase.leastsigfigStatGeochemBase.linregStatGeochemBase.linterp1StatGeochemBase.linterp1!StatGeochemBase.linterp1sStatGeochemBase.linterp1s!StatGeochemBase.linterp2StatGeochemBase.mcmc_surfaceStatGeochemBase.midpointquadratureStatGeochemBase.minarcdistanceStatGeochemBase.nearestStatGeochemBase.nonnumericStatGeochemBase.norm_quantileStatGeochemBase.norm_widthStatGeochemBase.normcdfStatGeochemBase.normcdf!StatGeochemBase.normcdf_llStatGeochemBase.normcdf_ll!StatGeochemBase.normlogpdfStatGeochemBase.normlogproductStatGeochemBase.normpdfStatGeochemBase.normpdf_llStatGeochemBase.normproductStatGeochemBase.normproduct_llStatGeochemBase.parsedlmStatGeochemBase.renormalize!StatGeochemBase.renormalize!StatGeochemBase.rescaleStatGeochemBase.reversecopyat!StatGeochemBase.sanitizevarnameStatGeochemBase.sigdigitsStatGeochemBase.stepifyStatGeochemBase.stepifyedgesStatGeochemBase.trapezoidalquadratureStatGeochemBase.unelementifyStatGeochemBase.unionize
StatGeochemBase.DictDataset — Function
DictDataset(t::NamedTuple, elements=keys(t))Convert a tuple-based dataset to a dict-based dataset.
See also TupleDataset
Examples
julia> t
NamedTuple with 2 elements:
La = Vector{Float64}(100,) [0.6809734028326375 ... 0.30665937715972313]
Yb = Vector{Float64}(100,) [0.8851029525168138 ... 0.866246147690925]
julia> d = DictDataset(t)
Dict{String, Vector{Float64}} with 2 entries:
"Yb" => [0.885103, 0.284384, 0.351527, 0.643542, 0.631274, 0.653966, 0.968414, 0.00204819, 0.0655173, 0.5343…
"La" => [0.680973, 0.35098, 0.0198742, 0.139642, 0.0703337, 0.0328973, 0.639431, 0.245205, 0.424142, 0.48889… StatGeochemBase.TupleDataset — Function
TupleDataset(d::Dict, elements=keys(d))Convert a dict-based dataset to a tuple-based dataset.
See also DictDataset
Examples
julia> d
Dict{String, Vector{Float64}} with 2 entries:
"Yb" => [0.823733, 0.0531003, 0.47996, 0.560998, 0.001816, 0.455064, 0.694017, 0.737816, 0.0755015, 0.46098 …
"La" => [0.440947, 0.937551, 0.464318, 0.694184, 0.253974, 0.521292, 0.857979, 0.0545946, 0.716639, 0.597616…
julia> t = TupleDataset(d)
NamedTuple with 2 elements:
Yb = Vector{Float64}(100,) [0.8237334494155881 ... 0.012863893327602627]
La = Vector{Float64}(100,) [0.44094669199955616 ... 0.5371416189174069]StatGeochemBase.arcdistance — Method
arcdistance(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
StatGeochemBase.cntr — Method
cntr(edges::Collection)Given an array of bin edges, return a corresponding vector of bin centers
Examples
julia> cntr(1:10)
1.5:1.0:9.5StatGeochemBase.concatenatedatasets — Method
concatenatedatasets(d1::NamedTuple, d2::NamedTuple,... ;[elements::Vector{Symbol}])
concatenatedatasets(d1::AbstractDict, d2::AbstractDict,... ;[elements::Vector{String}])Vertically concatenate two or more Dict- or Tuple-based datasets, variable-by-variable. Optionally, a list of variables to include may be specified in elements
Examples
julia> d1 = Dict("La" => rand(5), "Yb" => rand(5))
Dict{String, Vector{Float64}} with 2 entries:
"Yb" => [0.221085, 0.203369, 0.0657271, 0.124606, 0.0975556]
"La" => [0.298578, 0.481674, 0.888624, 0.632234, 0.564491]
julia> d2 = Dict("La" => rand(5), "Ce" => rand(5))
Dict{String, Vector{Float64}} with 2 entries:
"Ce" => [0.0979752, 0.108585, 0.718315, 0.771128, 0.698499]
"La" => [0.538215, 0.633298, 0.981322, 0.908532, 0.77754]
julia> concatenatedatasets(d1,d2)
Dict{String, Vector{Float64}} with 3 entries:
"Ce" => [NaN, NaN, NaN, NaN, NaN, 0.0979752, 0.108585, 0.718315, 0.771128, 0.698499]
"Yb" => [0.221085, 0.203369, 0.0657271, 0.124606, 0.0975556, NaN, NaN, NaN, NaN, NaN]
"La" => [0.298578, 0.481674, 0.888624, 0.632234, 0.564491, 0.538215, 0.633298, 0.981322, 0.908532, 0.77754]StatGeochemBase.containsi — Method
containsi(haystack, needle)Converts both haystack and needle to strings and checks whether string(haystack) contains string(needle), ignoring case.
Examples
julia> containsi("QuickBrownFox", "brown")
trueStatGeochemBase.copyat! — Method
copyat!(dest, src, tₛ::AbstractVector{Bool})Copy from src to dest when tₛ is true. Equivalent to dest .= src[tₛ], but without inducing allocations.
See also reversecopyat!
StatGeochemBase.count_unique! — Method
n = count_unique!(A)Sort the array A in-place (if not already sorted), 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)
Examples
julia> A = rand(1:5, 10)
10-element Vector{Int64}:
4
4
2
3
3
4
1
5
1
2
julia> A = rand(1:5, 7)
7-element Vector{Int64}:
1
1
4
3
1
1
4
julia> n = count_unique!(A)
3
julia> A
7-element Vector{Int64}:
1
3
4
1
3
4
4
julia> A[1:n]
3-element Vector{Int64}:
1
3
4StatGeochemBase.delim_string_function — Method
delim_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.
Examples
julia> delim_string_function(x -> delim_string_parse(x, ',', Int32, undefval=0), "1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16", '
', Array{Int32,1})
4-element Vector{Vector{Int32}}:
[1, 2, 3, 4]
[5, 6, 7, 8]
[9, 10, 11, 12]
[13, 14, 15, 16]StatGeochemBase.delim_string_parse — Function
delim_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
Optional keyword arguments and defaults:
merge::Bool=falseMerge repeated delimiters?
undefval=NaNA value to subsitute for any value that cannot be parsed to type T.
See also delim_string_parse! for an in-place version.
Examples
julia> delim_string_parse("1,2,3,4,5", ',', Float64)
5-element Vector{Float64}:
1.0
2.0
3.0
4.0
5.0StatGeochemBase.delim_string_parse! — Function
delim_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 explicitly, the eltype of the result array will be used by default.
Optional keyword arguments and defaults:
offset::Integer=0Start writing the parsed results into result at index 1+offset
merge::Bool=falseMerge repeated delimiters?
undefval=NaNA value to subsitute for any value that cannot be parsed to type T.
See also delim_string_parse for a non-in-place version that will automatically allocate a result array.
Examples
julia> A = zeros(100);
julia> n = delim_string_parse!(A, "1,2,3,4,5", ',', Float64)
5
julia> A[1:n]
5-element Vector{Float64}:
1.0
2.0
3.0
4.0
5.0StatGeochemBase.draw_from_distribution! — Method
draw_from_distribution!(x::DenseArray{<:AbstractFloat}, dist::Collection{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.
StatGeochemBase.draw_from_distribution — Method
draw_from_distribution(dist::Collection{AbstractFloat}, [dims...])Draw n random floating point numbers from a continuous probability distribution specified by a collection dist defining the PDF curve thereof.
Examples
julia> draw_from_distribution([0,1,2,1,0.], 7)
7-element Vector{Float64}:
0.5271744125470383
0.6624591724796276
0.7737643383545575
0.9603780726501608
0.7772477857811155
0.8307248435614027
0.6351766227803024 StatGeochemBase.elementify — Method
elementify(data::AbstractArray, [elements=data[1,:]];
importas=:Dict,
standardize::Bool=true,
floattype=Float64,
skipstart::Integer=1,
skipnameless::Bool=true
)Convert a flat array data into a Named Tuple (importas=:Tuple) or Dictionary (importas=:Dict) with each column as a variable. Tuples are substantially more efficient, so should be favored where possible.
Examples
julia> A = ["La" "Ce" "Pr"; 1.5 1.1 1.0; 3.7 2.9 2.5]
3×3 Matrix{Any}:
"La" "Ce" "Pr"
1.5 1.1 1.0
3.7 2.9 2.5
julia> elementify(A, importas=:Tuple)
NamedTuple with 3 elements:
La = Vector{Float64}(2,) [1.5 ... 3.7]
Ce = Vector{Float64}(2,) [1.1 ... 2.9]
Pr = Vector{Float64}(2,) [1.0 ... 2.5]
julia> elementify(A, importas=:Dict)
Dict{String, Union{Vector{Float64}, Vector{String}}} with 4 entries:
"Ce" => [1.1, 2.9]
"Pr" => [1.0, 2.5]
"elements" => ["La", "Ce", "Pr"]
"La" => [1.5, 3.7]StatGeochemBase.exportdataset — Function
exportdataset(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
sigdigitsSpecify a number of absolute or significant digits to which to round the printed output. Default is no rounding.
skipnanLeave NaNs as empty cells in the delimited output file. Boolean; true by default.
floatoutForce all output to be represented as a floating-point number, or else NaN. Boolean; false by default.
findnumericExport only numeric columns. Boolean; false by default.
rowsspecify which rows of the dataset to export. Default : exports all rows.
StatGeochemBase.fast_inv_sqrt — Method
fast_inv_sqrt(x)The infamous 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 nontrivial loss of precision. The implementations here are good to about 4 ppm.
StatGeochemBase.find_grid_inpolygon — Method
(columns, rows) = 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
Examples
```julia julia> grid_x = -1.5:1/3:1.5;
julia> grid_y = -1.5:1/3:1.5;
julia> cols,rows = findgridinpolygon(gridx, gridy, [-.4,.4,.4,-.4],[.4,.4,-.4,-.4]) ([5, 5, 6, 6], [5, 6, 5, 6])
julia> grid_x[cols] 4-element Vector{Float64}: -0.16666666666666666 -0.16666666666666666 0.16666666666666666 0.16666666666666666
julia> grid_y[rows] 4-element Vector{Float64}: -0.16666666666666666 0.16666666666666666 -0.16666666666666666 0.16666666666666666
StatGeochemBase.findclosest — Method
findclosest(needles, haystack)Return the index of the numerically closest value in the indexable collection haystack for each value in needles. If muliple values are equally close, the first one is used
Examples
julia> findclosest(3.4, 1:10)
3
julia> findclosest(3:4, 1:10)
2-element Vector{Int64}:
3
4StatGeochemBase.findclosestabove — Method
findclosestabove(needles, haystack)Return the index of the nearest value of the indexable collection haystack that is greater than (i.e., "above") each value in needles. If no such values exist, returns lastindex(haystack)+1.
Examples
julia> findclosestabove(3.5, 1:10)
4
julia> findclosestabove(3:4, 1:10)
2-element Vector{Int64}:
4
5StatGeochemBase.findclosestbelow — Method
findclosestbelow(needles, haystack)Return the index of the nearest value of the indexable collection haystack that is less than (i.e., "below") each value in needles. If no such haystack values exist, returns firstindex(haystack)-1.
Examples
julia> findclosestbelow(3.5, 1:10)
3
julia> findclosestbelow(3:4, 1:10)
2-element Vector{Int64}:
2
3 StatGeochemBase.findclosestunequal — Method
findclosestunequal(x::Collection, i::Integer)Return the index of the closest index n to i for which x[n] != x[i], or i if no unequal values of x are found.
Examples
julia> x = [1, 2, 2, 3, 4]
5-element Vector{Int64}:
1
2
2
3
4
julia> findclosestunequal(x, 2)
1
julia> findclosestunequal(x, 3)
4 StatGeochemBase.findmatches — Method
findmatches(needles, haystack)Return the linear index of the first value in haystack (if any) that is equal to a given value in needles for each value in needles; else 0.
Examples
julia> findmatches([3,5],1:10)
2-element Vector{Int64}:
3
5StatGeochemBase.findnth — Method
findnth(t::Collection{Bool}, n::Integer)Return the index of the nth true value of t, else length(t)
Examples
julia> t = rand(Bool,5)
5-element Vector{Bool}:
1
1
0
1
1
julia> findnth(t, 3)
4StatGeochemBase.floatify — Function
floatify(x, T::Type=Float64)Convert x to a floating-point number (default Float64) by any means necessary
Examples
julia> StatGeochem.floatify(5)
5.0
julia> StatGeochem.floatify("5")
5.0
julia> StatGeochem.floatify("0x05")
5.0
julia> StatGeochem.floatify("0.5e1")
5.0StatGeochemBase.hashdataset — Method
hashdataset(ds::Union{Dict, NamedTuple}; digits::Number=3, elements=keys(ds))Calculate a hash value for each row of a dataset. By default, this considers only the first 3 digits of each number, regardless of scale.
Examples
julia> ds = (La=rand(5), Yb=rand(5)/10)
NamedTuple with 2 elements:
La = Vector{Float64}(5,) [0.580683620945775 ... 0.23810020661332487]
Yb = Vector{Float64}(5,) [0.014069255862588826 ... 0.067367584177675]
julia> hashdataset(ds)
5-element Vector{UInt64}:
0x89a02fa88348e07c
0x181e78f0ad2af144
0xa3811bd05cca4743
0xfcfe1b6edf0c81cf
0x647868efa9352972StatGeochemBase.image_from_paths! — Method
image_from_paths!([imgcounts::AbstractMatrix], xpoints::AbstractMatrix, ypoints::AbstractMatrix;
xresolution::Int=1800,
yresolution::Int=1200,
xrange=nanextrema(xpoints),
yrange=nanextrema(ypoints),
method=:nearest,
)As image_from_paths, but may sort xpoints (as required for interpolation) in-place rather than making a copy.
Optionally, a result matrix imgcounts may be supplied for fully in-place operation, in which case yresolution, xresolution = size(imgcounts)
Available line-drawing methods include :interpolate, which interpolates the independent variable (y) as a function of the dependent variable (x) :closest, which attempts to find the
StatGeochemBase.image_from_paths — Method
image_from_paths(xpoints::AbstractMatrix, ypoints::AbstractMatrix;
xresolution::Int=1800,
yresolution::Int=1200,
xrange=nanextrema(xpoints),
yrange=nanextrema(ypoints),
)Produce a 2d image (histogram) of path densities given a set of x-y points stored column-wise in separate matrices xpoints and ypoints. x is assumed to be the independent variable (i.e., the x-y points are plotted in order of increasing x).
See also image_from_paths!
Examples
julia> nsims = 1000
1000
julia> xdist = rand(10, nsims);
julia> ydist = rand(10, nsims);
julia> imgcounts, xbincenters, ybincenters = image_from_paths(xpaths, ypaths; xresolution=50, yresolution=50)
([8 15 … 9 11; 12 4 … 14 11; … ; 9 15 … 9 9; 10 17 … 10 14], -3.715247394908744:0.1523101612461508:3.747950506152645, -3.86556932981587:0.1497772964483582:3.4735181961536803)StatGeochemBase.importdataset — Function
function importdataset(filepath, [delim];
importas=:Dict,
elements=nothing,
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:
importasSpecify the format of the imported dataset. Options include :Dict and :Tuple
elementsSpecify the names to be used for each element (i.e., column) of the dataset. Default value (nothing) will cause elements to be read from the first row of the file
standardizeConvert columns to uniform type wherever possible. Boolean; true by default.
floattypePreferred floating-point type for numerical data. Float64 by default.
skipstartIgnore 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.
skipnamelessSkip columns with no column name. Boolean; true by default
mindefinedcolumnsSkip rows with fewer than this number of delimiters. 0 by default.
StatGeochemBase.imsc — Function
imsc(A::AbstractArray, colormap::AbstractVector=viridis, cmin=nanminimum(A), cmax=nanmaximum(A))Convert a matrix A to an image (an array of Colors.jl colors) using the specified colormap (default viridis), optionally scaled between cmin and cmax.
Examples
julia> A = rand(3,3)
3×3 Matrix{Float64}:
0.39147 0.553489 0.351628
0.331786 0.343836 0.824674
0.639233 0.558113 0.965627
julia> img = imsc(A) # N.B. will display as image if `using ImageInTerminal`
3×3 Array{RGB{N0f8},2} with eltype ColorTypes.RGB{FixedPointNumbers.N0f8}:
RGB{N0f8}(0.282,0.137,0.455) … RGB{N0f8}(0.278,0.051,0.376)
RGB{N0f8}(0.267,0.004,0.329) RGB{N0f8}(0.431,0.808,0.345)
RGB{N0f8}(0.133,0.553,0.553) RGB{N0f8}(0.992,0.906,0.145)
julia> using Images; save("img.png", img) # Save to file as PNG
julia> using Plots; plot(0:3, 0:3, img) # Plot with specified x and y axesStatGeochemBase.imsci — Function
imsci(A::AbstractArray, colormap::AbstractVector=viridis, cmin=nanminimum(A), cmax=nanmaximum(A))Convert a matrix A to an indirect array image (an IndirectArray of Colors.jl colors) using the specified colormap (default viridis), optionally scaled between cmin and cmax.
As imsc, but returns an IndirectArray; slightly more space efficient for small colormaps, but with computational cost.
Examples
julia> A = rand(3,3)
3×3 Matrix{Float64}:
0.39147 0.553489 0.351628
0.331786 0.343836 0.824674
0.639233 0.558113 0.965627
julia> img = imsci(A)
3×3 IndirectArrays.IndirectArray{RGB{N0f8}, 2, UInt64, Matrix{UInt64}, Vector{RGB{N0f8}}}:
RGB{N0f8}(0.282,0.137,0.455) … RGB{N0f8}(0.278,0.051,0.376)
RGB{N0f8}(0.267,0.004,0.329) RGB{N0f8}(0.431,0.808,0.345)
RGB{N0f8}(0.133,0.553,0.553) RGB{N0f8}(0.992,0.906,0.145)
julia> using Images; save("img.png", img) # Save to file as PNG
julia> using Plots; plot(0:3, 0:3, img) # Plot with specified x and y axesStatGeochemBase.inpolygon — Method
inpolygon(x,y,point)Check if a 2D polygon defined by the arrays x, y contains a given point. Returns boolean (true or false)
Examples
julia> x = [0, 1, 1, 0];
julia> y = [0, 0, 1, 1];
julia> inpolygon(x, y, (0.5,0.5))
true
julia> inpolygon(x, y, (0.5,1.5))
falseStatGeochemBase.isnumeric — Method
isnumeric(x)Return true if x can be parsed as a number, else false
Examples
julia> StatGeochem.isnumeric(1)
true
julia> StatGeochem.isnumeric("1")
true
julia> StatGeochem.isnumeric("0.5e9")
true
julia> StatGeochem.isnumeric("foo")
falseStatGeochemBase.leastsigfig — Method
leastsigfig(d)Return the order of magnitude of the least significant decimal digit of a number d.
Examples
julia> leastsigfig(1000)
1000.0
julia> leastsigfig(1001)
1.0
julia> leastsigfig(1001.1234)
0.0001StatGeochemBase.linreg — Method
(a,b) = linreg(x::AbstractVector, y::AbstractVector)Returns the coefficients for a simple linear least-squares regression of the form y = a + bx
Examples
julia> a, b = linreg(1:10, 1:10)
2-element Vector{Float64}:
-1.19542133983862e-15
1.0
julia> isapprox(a, 0, atol = 1e-12)
true
julia> isapprox(b, 1, atol = 1e-12)
trueStatGeochemBase.linterp1! — Method
linterp1!(yq::AbstractArray, [knot_index], x, y, xq; interpolate=static(:linear), extrapolate=interpolate)In-place variant of linterp1.
An optional temporary working array knot_index = similar(xq, Int) may be provided if desired for performance.
StatGeochemBase.linterp1 — Method
yq = linterp1(x, y, xq; interpolate=static(:linear), extrapolate=interpolate)Simple linear interpolation in one dimension. Given a vector of knots x and values y, find the corresponding y values at position(s) xq.
Knots x must be sorted in increasing order.
If the optional keyword argument extrapolate is set to :linear (default), xq values outside the range of x will be extrapolated using a linear extrapolation of the closest two x-y pairs. Otherwise, if extrapolate is set to a Number (e.g., 0, or NaN), that number will be used instead.
Examples
julia> linterp1(1:10, 1:10, 5.5)
5.5
julia> linterp1(1:10, 1:10, 0.5:10.5)
11-element Vector{Float64}:
0.5
1.5
2.5
3.5
4.5
5.5
6.5
7.5
8.5
9.5
10.5StatGeochemBase.linterp1s! — Method
linterp1s!(yq, [knot_index], x, y, xq; interpolate=static(:linear), extrapolate=interpolate)In-place variant of linterp1s. Will sort x and permute y to match, before interpolating at xq and storing the result in yq.
An optional temporary working array knot_index = similar(xq, Int) may be provided if desired for performance.
StatGeochemBase.linterp1s — Method
yq = linterp1s(x::AbstractArray, y::AbstractArray, xq; interpolate=static(:linear), extrapolate=interpolate)As as linterp1 (simple linear interpolation in one dimension), but will sort the knots x and values y pairwise if x is not already sorted in increasing order.
Examples
julia> linterp1s(10:-1:1, 1:10, 5.5)
5.5
julia> linterp1s(10:-1:1, 1:10, 0.5:10.5)
11-element Vector{Float64}:
10.5
9.5
8.5
7.5
6.5
5.5
4.5
3.5
2.5
1.5
0.5StatGeochemBase.linterp2 — Method
zq = linterp2(x, y, z::AbstractMatrix, xq, yq; interpolate=:bilinear, extrapolate=interpolate)Simple linear interpolation in one dimension. Given vectors of knots x and y and a matrix of values z, find the corresponding z values at position xq,yq.
Knot vectors x and y must be sorted in increasing order, and must match z in dimension, such that eachindex(x) == axes(z,2) and eachindex(y) == axes(z,1)
Available methods currently include :bilinear (default), and :nearest (nearest-neighbor). In the :bilinear method, xq,yq pairs will be interpolated (or extrapolated) linearly in x and then linearly in y (yielding a quadratic result as a whole), based on the closest four z values. In the nearest-neighbor method, the single closest z value will be chosen.
If not otherwise specified, the same method will be used for extrapolation as for interpolation. Alternatively, if extrapolate is set to a Number (e.g., 0, or NaN), that number will be used instead.
Examples
julia> x = 1:3
1:3
julia> y = 1:4
1:4
julia> z = y*x'
4×3 Matrix{Int64}:
1 2 3
2 4 6
3 6 9
4 8 12
julia> linterp2(x,y,z,1.5,1.5)
2.25
julia> linterp2(x,y,z,2.5,3.5)
8.75
julia> linterp2(x,y,z,1,-10)
-10.0
julia> linterp2(x,y,z,2,-10)
-20.0
julia> linterp2(x,y,z,2,-10, extrapolate=NaN)
NaNStatGeochemBase.mcmc_surface — Method
mcmc_surface(xaxis::AbstractRange, yaxis::AbstractRange, llmatrix::AbstractMatrix;
nsteps::Int=100000,
burnin::Int=10000,
)Explore a precomputed log likelihood surface llmatrix with dimensions xaxis (horizontal, columns) and yaxis (vertical, rows) using a Markov chain Monte Carlo approach (the Metropolis algorithm) to calculate posterior distributions for x and y.
Examples
julia> xaxis = yaxis = -5:0.01:5
-5.0:0.01:5.0
julia> llmatrix = [-((x+1)^2/0.5^2 + (y-1)^2/0.5^2) for y in yaxis, x in xaxis];
julia> xdist, ydist, lldist, acceptancedist = mcmc_surface(xaxis,yaxis,llmatrix);
julia> mean(xdist), std(xdist)
(-0.9888633375860412, 0.41023499283715603)
julia> mean(ydist), std(ydist)
(1.0110703489524537, 0.4182564675721746)StatGeochemBase.midpointquadrature — Method
midpointquadrature(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.
Examples
julia> midpointquadrature(0:0.1:10, 0:0.1:10)
50.5StatGeochemBase.minarcdistance — Method
minarcdistance(latᵢ,lonᵢ,lat,lon)Return the smallest non-NaN arcdistance (i.e. distance on a sphere in arc degrees) between a given point (latᵢ[i],lonᵢ[i]) and any point in (lat,lon) for each i in eachindex(latᵢ, lonᵢ).
Latitude and Longitude should be specified in decimal degrees
StatGeochemBase.nearest — Method
nearest(T, x)Convert x to the nearest representable value in type T, rounding if inexact
Examples
```julia julia> nearest(Int, 1234.56) 1235
julia> nearest(Int, Inf) 9223372036854775807
julia> nearest(Int, -Inf) -9223372036854775808 ````
StatGeochemBase.nonnumeric — Method
nonnumeric(x)Return true for if x is not missing but cannot be parsed as a number
Examples
julia> StatGeochem.nonnumeric(1)
false
julia> StatGeochem.nonnumeric("1")
false
julia> StatGeochem.nonnumeric("0.5e9")
false
julia> StatGeochem.nonnumeric("foo")
trueStatGeochemBase.norm_quantile — Method
norm_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
StatGeochemBase.norm_width — Method
norm_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?
StatGeochemBase.normcdf! — Method
normcdf!(result,mu,sigma,x)In-place version of normcdf
StatGeochemBase.normcdf — Method
normcdf(mu,sigma,x)Cumulative distribution function of the Normal (Gaussian) distribution
$1/2 + erf(rac{x-μ}{σ√2})/2$
with mean mu and standard deviation sigma, evaluated at x.
StatGeochemBase.normcdf_ll! — Method
normcdf_ll!(mu, sigma, x)Fast log likelihood proportional to the natural logarithm of the cumulative distribution function of a Normal (Gaussian) distribution with mean mu and standard deviation sigma, evaluated at x.
As normcdf_ll, but in-place (using x as a buffer).
StatGeochemBase.normcdf_ll — Method
normcdf_ll(mu, sigma, x)Fast log likelihood proportional to the natural logarithm of the cumulative distribution function of 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 normcdf
StatGeochemBase.normlogpdf — Method
normlogpdf(mu, sigma, x)The natural logarithm of the probability density function of 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 probability density over all x will be returned.
See also normpdf, normlogpdf
StatGeochemBase.normlogproduct — Method
normlogproduct(μ1, σ1, μ2, σ2)The logarithm of the integral of N[μ1,σ1] * N[μ2,σ2]
StatGeochemBase.normpdf — Method
normpdf(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
StatGeochemBase.normpdf_ll — Method
normpdf_ll(mu, sigma, x)Fast log likelihood proportional to the natural logarithm of the probability density function of 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, normlogpdf
StatGeochemBase.normproduct — Method
normproduct(μ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
StatGeochemBase.normproduct_ll — Method
normproduct_ll(μ1, σ1, μ2, σ2)Fast log likelihood proportional to the integral of N[μ1,σ1] * N[μ2,σ2] As normlogproduct, but using the fast log likelihood of a Normal distribution (i.e., without the preexponential terms).
StatGeochemBase.parsedlm — Method
parsedlm(str::AbstractString, delimiter::Char, T::Type=Float64; rowdelimiter::Char='\n', merge::Bool=false)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.
Examples
julia> parsedlm("1,2,3
4,5,6
7,8,9
", ',', Float64)
3×3 Matrix{Float64}:
1.0 2.0 3.0
4.0 5.0 6.0
7.0 8.0 9.0
julia> parsedlm("1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16", ',', Int64)
4×4 Matrix{Int64}:
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16StatGeochemBase.renormalize! — Function
renormalize!(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
StatGeochemBase.renormalize! — Method
renormalize!(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.
StatGeochemBase.rescale — Function
rescale(y, min::Number=0, max::Number=1)Rescale a collection of numbers y between a new minimum min and new maximum max
Examples
julia> rescale(1:5)
5-element Vector{Float64}:
0.0
0.25
0.5
0.75
1.0
julia> rescale(1:5, -1, 0)
5-element Vector{Float64}:
-1.0
-0.75
-0.5
-0.25
0.0StatGeochemBase.reversecopyat! — Method
reversecopyat!(dest, src, tₛ::AbstractVector{Bool})As copyat!, but also reverse the order of stored elements.
Equivalent to dest .= reverse(src[tₛ]), but without inducing allocations.
StatGeochemBase.sanitizevarname — Method
sanitizevarname(s::AbstractString)Modify an input string s to transform it into an acceptable variable name.
Examples
julia> StatGeochemBase.sanitizevarname("foo")
"foo"
julia> StatGeochemBase.sanitizevarname("523foo")
"_523foo"
julia> StatGeochemBase.sanitizevarname("Length (μm)")
"Length_μm"StatGeochemBase.sigdigits — Method
sigdigits(d)Determine the number of decimal significant figures of a number d.
Examples
julia> sigdigits(1000)
1
julia> sigdigits(1001)
4
julia> sigdigits(1001.1245)
8StatGeochemBase.stepify — Method
stepify(x::AbstractVector)Duplicate every element of an array.
Together with stepifyedges, allows for convenient plotting of a histogram of bin counts and bin edges as a stepped line.
Examples
julia> stepify([1,3,2])
6-element Vector{Int64}:
1
1
3
3
2
2
julia> plot(stepifyedges(binedges), stepify(bincounts))
# Returns a stepped line plot of a histogramStatGeochemBase.stepifyedges — Method
stepifyedges(x::AbstractVector)Duplicate every element of an array except for the first and last.
Together with stepify, allows for convenient plotting of a histogram of bin counts and bin edges as a stepped line.
Examples
julia> stepifyedges([1,2,3,4])
6-element Vector{Int64}:
1
2
2
3
3
4
julia> plot(stepifyedges(binedges), stepify(bincounts))
# Returns a stepped line plot of a histogramStatGeochemBase.trapezoidalquadrature — Method
trapezoidalquadrature(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 (integration will be faster if edges are specified as an AbstractRange).
Examples
julia> trapezoidalquadrature(0:0.1:10, 0:0.1:10)
50.0StatGeochemBase.unelementify — Function
unelementify(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
Examples
julia> D
NamedTuple with 3 elements:
La = Vector{Float64}(2,) [1.5 ... 3.7]
Ce = Vector{Float64}(2,) [1.1 ... 2.9]
Pr = Vector{Float64}(2,) [1.0 ... 2.5]
julia> unelementify(D)
3×3 Matrix{Any}:
"La" "Ce" "Pr"
1.5 1.1 1.0
3.7 2.9 2.5StatGeochemBase.unionize — Method
unionize(x::AbstractVector)Turn an array with possibly abstract element type into one with eltype equal to a Union of all types of elements in the array.
Always returns a copy, even if x is already unionized.
Examples
julia> a = Any[false, 0, 1.0]
3-element Vector{Any}:
false
0
1.0
julia> unionize(a)
3-element Vector{Union{Bool, Float64, Int64}}:
false
0
1.0