Sediment Analysis Tools
SedimentSourceAnalysis.SedimentTools
— ModuleImport, store, and visualize sediment data.
Types
SedimentSourceAnalysis.SedimentTools.Grain
— TypeGrain(v::AbstractVector{T}, measurement_names::AbstractVector{String})
Struct to hold grain level data
SedimentSourceAnalysis.SedimentTools.DensityTensor
— TypeDensityTensor(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).
SedimentSourceAnalysis.SedimentTools.Rock
— TypeAlias for Sink
SedimentSourceAnalysis.SedimentTools.Sink
— TypeSink(grain1, grain2, ...)
Sink([grain1, grain2, ...])
Collects a list of Grain
s
into a Rock
/Sink
.
Ensures all Grain
s
have the same names and are in the same order. Struct to hold sink level data
SedimentSourceAnalysis.SedimentTools.Source
— TypeAlias for Sink
Method Extentions
Base.getindex
— MethodBase.getindex(s::Sink, k::String)
Base.getindex(s::Sink, ks::AbstractVector{String})
Gets all values of the measurement k
in the Sink
.
Base.names
— Methodnames(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.
Plots.heatmap
— MethodPlots.heatmap(M::NamedMatrix; kwargs...)
Automatically grabs the names in axis to label the x and y plot axis
MatrixTensorFactor.make_densities
— Methodmake_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}
MatrixTensorFactor.make_densities2d
— Methodmake_densities2d(s::Sink; kwargs...)
make_densities2d(s::Sink, domains::AbstractVector{<:AbstractVector}; kwargs...)
Similar to make_densities
but performs the KDE on 2 measurements jointly.
Functions
Importers
SedimentSourceAnalysis.SedimentTools.read_raw_data
— Functionread_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.
Getters
SedimentSourceAnalysis.SedimentTools.array
— FunctionTurn a DensityTensor or NamedArray into a plain Array type.
SedimentSourceAnalysis.SedimentTools.getdomain
— Functiongetdomain(D::DensityTensor, measurement::String)
getdomain(D::DensityTensor, j::Integer)
Gets the domain for the measurement
density, the locations where the density was sampled. See getdomains
.
SedimentSourceAnalysis.SedimentTools.getdomains
— Functiongetdomains(D::DensityTensor{T})::Vector{Vector{T}}
Gets the domain for every measurement's density, the locations where each density was sampled. See getdomains
.
SedimentSourceAnalysis.SedimentTools.getmeasurements
— Functiongetmeasurements(g::Grain)
getmeasurements(s::Sink)
getmeasurements(D::DensityTensor)
Getter for the measurement names.
getmeasurements(s::Sink)
Gets the names of measurements from a Sink
SedimentSourceAnalysis.SedimentTools.getsourcename
— Functiongetsourcename(D::DensityTensor)
Gets the name for the grouping of measurements. Usually "Sink"
or "Source"
. See getsourcename
.
SedimentSourceAnalysis.SedimentTools.getsourcenames
— Functiongetsourcenames(D::DensityTensor)
Gets the list of all sources' names. For example, ["Sink 1", "Sink 2", ...]
. See getsourcenames
.
SedimentSourceAnalysis.SedimentTools.getstepsizes
— Functiongetstepsizes(D::DensityTensor)
Gets the step sizes used for each domain. See getdomains
.
SedimentSourceAnalysis.SedimentTools.namedarray
— FunctionTurn a DensityTensor into a NamedArray type.
SedimentSourceAnalysis.SedimentTools.getsink
— FunctionAlias for getsource
SedimentSourceAnalysis.SedimentTools.getsource
— Functiongetsource(D::DensityTensor, i::Integer)
getsink(D::DensityTensor, i::Integer)
Gets source/sink i from D
. See eachsource
.
Setters and Manipulators
SedimentSourceAnalysis.SedimentTools.normalize_density_sums!
— Functionnormalize_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.
SedimentSourceAnalysis.SedimentTools.normalize_density_sums
— FunctionSedimentSourceAnalysis.SedimentTools.setsourcename!
— Functionsetsourcename!(D::DensityTensor, name::String)
Sets the name of the source used by getsourcename
and getsourcenames
.
SedimentSourceAnalysis.SedimentTools.match_sources!
— Functionmatch_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.
Grain Labeling
SedimentSourceAnalysis.SedimentTools.confidence_score
— Functionconfidence_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.
SedimentSourceAnalysis.SedimentTools.estimate_which_source
— Functionestimate_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)
SedimentSourceAnalysis.SedimentTools.estimate_which_2d_source
— Functionestimate_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.
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)
SedimentSourceAnalysis.SedimentTools.estimate_which_nd_source
— Functionestimate_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)
SedimentSourceAnalysis.SedimentTools.label_accuracy
— Functionlabel_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}}
orTuple{Tuple}
)true_amounts
: Number of grains from each source for every sink
Outputs
n_correct_eachsink::Integer
n_total_labels::Integer
accuracy::Real
Iterators
SedimentSourceAnalysis.SedimentTools.eachdensity
— Functioneachdensity(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.
SedimentSourceAnalysis.SedimentTools.eachmeasurement
— Functioneachmeasurement(s::Sink)
Iterator for a list of values of each measurement
eachmeasurement(D::DensityTensor)
Iterates D
over each measurement slice. These are the lateral slices.
SedimentSourceAnalysis.SedimentTools.eachsink
— FunctionAlias for eachsource
.
SedimentSourceAnalysis.SedimentTools.eachsource
— Functioneachsource(D::DensityTensor)
eachsink(D::DensityTensor)
Iterates D
over each source/sink slice. These are the horizontal slices. See getsource
.
Visualizers
SedimentSourceAnalysis.SedimentTools.measurement_heatmaps
— Functionmeasurement_heatmaps(D::DensityTensor; kw...)
Returns heatmaps for each measurement (lateral slices) of D
.
SedimentSourceAnalysis.SedimentTools.plot_densities
— Functiondistributions_plot(D::DensityTensor, measurement::String; kw...)
Returns one plot will all distributions for a given measurement (lateral slice) of D
.
SedimentSourceAnalysis.SedimentTools.source_heatmaps
— Functionsource_heatmaps(D::DensityTensor; title="", kw...)
Returns heatmaps for each source (horizontal slices) of D
.
The source name/index for each source will be appended to title.
SedimentSourceAnalysis.SedimentTools.plot_convergence
— Functionplot_convergence(rel_errors, norm_grad, dist_Ncone)
Returns 3 separate plots for the three convergence metrics on a log10-y scale.
plot_convergence((rel_errors, norm_grad, dist_Ncone))
SedimentSourceAnalysis.SedimentTools.plot_source_index
— Functionplot_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.
Index
SedimentSourceAnalysis.SedimentTools
SedimentSourceAnalysis.SedimentTools.DensityTensor
SedimentSourceAnalysis.SedimentTools.Grain
SedimentSourceAnalysis.SedimentTools.Rock
SedimentSourceAnalysis.SedimentTools.Sink
SedimentSourceAnalysis.SedimentTools.Source
Base.getindex
Base.names
MatrixTensorFactor.make_densities
MatrixTensorFactor.make_densities2d
Plots.heatmap
SedimentSourceAnalysis.SedimentTools.array
SedimentSourceAnalysis.SedimentTools.confidence_score
SedimentSourceAnalysis.SedimentTools.eachdensity
SedimentSourceAnalysis.SedimentTools.eachmeasurement
SedimentSourceAnalysis.SedimentTools.eachsink
SedimentSourceAnalysis.SedimentTools.eachsource
SedimentSourceAnalysis.SedimentTools.estimate_which_2d_source
SedimentSourceAnalysis.SedimentTools.estimate_which_nd_source
SedimentSourceAnalysis.SedimentTools.estimate_which_source
SedimentSourceAnalysis.SedimentTools.getdomain
SedimentSourceAnalysis.SedimentTools.getdomains
SedimentSourceAnalysis.SedimentTools.getmeasurements
SedimentSourceAnalysis.SedimentTools.getsink
SedimentSourceAnalysis.SedimentTools.getsource
SedimentSourceAnalysis.SedimentTools.getsourcename
SedimentSourceAnalysis.SedimentTools.getsourcenames
SedimentSourceAnalysis.SedimentTools.getstepsizes
SedimentSourceAnalysis.SedimentTools.label_accuracy
SedimentSourceAnalysis.SedimentTools.match_sources!
SedimentSourceAnalysis.SedimentTools.measurement_heatmaps
SedimentSourceAnalysis.SedimentTools.namedarray
SedimentSourceAnalysis.SedimentTools.normalize_density_sums
SedimentSourceAnalysis.SedimentTools.normalize_density_sums!
SedimentSourceAnalysis.SedimentTools.plot_convergence
SedimentSourceAnalysis.SedimentTools.plot_densities
SedimentSourceAnalysis.SedimentTools.plot_source_index
SedimentSourceAnalysis.SedimentTools.read_raw_data
SedimentSourceAnalysis.SedimentTools.setsourcename!
SedimentSourceAnalysis.SedimentTools.source_heatmaps