Sediment Analysis Tools

Types

SedimentAnalysis.SedimentTools.DensityTensorType
DensityTensor(KDEs, domains, sinks)
DensityTensor(array, domains, measurement_names; kw...)

An order 3 array to hold the density distributions for multiple sinks.

KDEs is a Vector{Vector{Vector{T}}} like type whereas array is an Array{T,3} like type.

Call setsourcename! to set the source name (name of first dimention).

source

Method Extentions

Base.getindexMethod
Base.getindex(s::Sink, k::String)
Base.getindex(s::Sink, ks::AbstractVector{String})

Gets all values of the measurement k in the Sink.

source
Base.namesMethod
names(n::NamedArray, dimname::Union{String,Symbol})

Extend the names function from NamedArray to get the names given the axis name rather than the axis number.

source
Plots.heatmapMethod
Plots.heatmap(M::NamedMatrix; kwargs...)

Automatically grabs the names in axis to label the x and y plot axis

source
MatrixTensorFactor.make_densitiesMethod
make_densities(s::Sink; kwargs...)
make_densities(s::Sink, domains::AbstractVector{<:AbstractVector}; kwargs...)

Estimates the densities for each measurement in a Sink.

When given domains, a list where each entry is a domain for a different measurement, resample the kernel on this domain.

Parameters

  • bandwidths::AbstractVector{<:Real}: list of bandwidths used for each measurement's

density estimation

  • inner_percentile::Integer=100: value between 0 and 100 that filters out each measurement

by using the inner percentile range. This can help remove outliers and focus in on where the bulk of the data is.

Returns

  • density_estimates::Vector{UnivariateKDE}
source

Functions

Importers

SedimentAnalysis.SedimentTools.read_raw_dataFunction
read_raw_data(filename)
read_raw_data(filename; skip_sheets)

Imports excel data to a Vector{Sink}.

Excel file must have one element per page where different columns correspond to different sinks. Each sink can have a different number of grains (length of the column), but a sink must have a consistant length across different measurements (sheets).

Optionaly provide a collection skip_sheets to blacklist sheet names from the excel file.

source

Getters

Setters and Manipulators

SedimentAnalysis.SedimentTools.normalize_density_sums!Function
normalize_density_sums!(D::DensityTensor)

Rescales the densities so that the sum of the density samples is 1.

This is in constrast to the usualy normalization for density functions where the area of the density curve is 1. In the case of an evenly sampled density, this area is sum(density_samples)*step_size.

Use normalize_density_sums to avoid mutation.

source
SedimentAnalysis.SedimentTools.match_sources!Function
match_sources!(C, F, C_true, F_true)

Permute sources in C and F to match the ground truth C_true and F_true.

Similarity is checked by finding the source that minimizes norm(c - c_true) where c is the column of C.

Parameters

  • double_check::Bool: When true, repeat for F and F_true with their horizontal slices, and assert the ordering is the same as before.
source

Grain Labeling

SedimentAnalysis.SedimentTools.confidence_scoreFunction
confidence_score(source_likelihoods; sorted=false)

Scores each grain between [0, 1] on how confident it came from the most likely source.

The likelihoods should be sorted in desending order. If they are presorted, use the keyword sorted=true.

Input

source_likelihoods: A list-of-lists or NTuple of Vectors of the likelihood each grain came from each source.

source
SedimentAnalysis.SedimentTools.estimate_which_sourceFunction
estimate_which_source(grain::Grain, F::DensityTensor; kwargs...)

Returns the likelihood and source index of the mostly likely factor the grain vector came from.

Returns

  • (Default) source_index::Integer: The index of the most likely source
  • (when max_likelihoods==true) (maxlikelihood, source_index): The most likely source and its likelihood
  • (when all_likelihoods==true) likelihoods::Vector{Real}: Likelihood grain came from each source
  • (when both are true) ((maxlikelihood, source_index), likelihoods)
source
SedimentAnalysis.SedimentTools.estimate_which_2d_sourceFunction
estimate_which_2d_source(grain::Grain, F; kwargs...)

Returns the likelihood and source index of the mostly likely factor the grain vector came from.

Works on densities F where each horizontal slice is a discretized 2D KDE.

See estimate_which_source.

Returns

  • (Default) source_index::Integer: The index of the most likely source
  • (when max_likelihoods==true) (maxlikelihood, source_index): The most likely source and its likelihood
  • (when all_likelihoods==true) likelihoods::Vector{Real}: Likelihood grain came from each source
  • (when both are true) ((maxlikelihood, source_index), likelihoods)
source
SedimentAnalysis.SedimentTools.estimate_which_nd_sourceFunction
estimate_which_nd_source(grain::Grain, F; kwargs...)

Returns the likelihood and source index of the mostly likely factor the grain vector came from.

Works on densities F where each first order slice is a discretized n-Dimentional KDE.

See estimate_which_source and estimate_which_2d_source.

Returns

  • (Default) source_index::Integer: The index of the most likely source
  • (when max_likelihoods==true) (maxlikelihood, source_index): The most likely source and its likelihood
  • (when all_likelihoods==true) likelihoods::Vector{Real}: Likelihood grain came from each source
  • (when both are true) ((maxlikelihood, source_index), likelihoods)
source
SedimentAnalysis.SedimentTools.label_accuracyFunction
label_accuracy(labels, true_amounts::AbstractArray{T,3})

Calculates the number of correctly labeled grains and percentage of correct labels

Arguments

  • labels: Iterable of iterables with the labels for each grain (Vector{Vector{T}} or Tuple{Tuple})
  • true_amounts: Number of grains from each source for every sink

Outputs

  • n_correct_eachsink::Integer
  • n_total_labels::Integer
  • accuracy::Real
source

Iterators

SedimentAnalysis.SedimentTools.eachdensityFunction
eachdensity(D::DensityTensor)
eachdensity(D::DensityTensor, measurement::String)
eachdensity(...; sink::Integer)

Iterates D over each density vector. These are the 3 fibers of D. If a measurement is given, iterates over the densities for that measurement. If the keyword sink is given, only show densities from that sink.

source

Visualizers

SedimentAnalysis.SedimentTools.plot_source_indexFunction
plot_source_index(
indexes::AbstractVector{<:Integer},
loglikelihood_ratios::AbstractVector{<:Real};
kwargs...
)

Returns one scatter plot of dots (eachindex(indexes), indexes) with brighter colours corresponding to higher loglikelihood_ratios.

source

Index