Skip to content

Commit

Permalink
Add GeneralAgeData struct
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Jun 27, 2024
1 parent 9eb871e commit 13348ba
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 20 deletions.
5 changes: 4 additions & 1 deletion src/Chron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module Chron
include("Fitplot.jl")

# Structs
export ChronAgeData, HiatusData, StratAgeModelConfiguration, StratAgeModel
export ChronAgeData, GeneralAgeData, HiatusData
export SystematicUncertainty, StratAgeModelConfiguration, StratAgeModel

# High-level functions
export StratMetropolis, StratMetropolisDist, StratMetropolis14C,
Expand All @@ -67,4 +68,6 @@ module Chron
# (mostly already exported by reexporting Isoplot.jl)
export TruncatedNormalDistribution, EllisDistribution, ArClosureDistribution

include("Deprecations.jl")

end # module
22 changes: 22 additions & 0 deletions src/Deprecations.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# For backwards compatibility with old scripts and publications
function NewChronAgeData(nSamples::Integer)
@warn "`NewChronAgeData` is deprecated, use `ChronAgeData` instead"
ChronAgeData(nSamples)
end
export NewChronAgeData
function StratAgeData(nSamples::Integer)
@warn "`StratAgeData` is deprecated, use `ChronAgeData` instead"
ChronAgeData(nSamples)
end
export StratAgeData
function NewStratAgeData(nSamples::Integer)
@warn "`NewStratAgeData` is deprecated, use `ChronAgeData` instead"
ChronAgeData(nSamples)
end
export NewStratAgeData


function NewHiatusData(nHiatuses::Integer)
@warn "`NewHiatusData` is deprecated, use `HiatusData` instead"
HiatusData(nHiatuses)
end
44 changes: 28 additions & 16 deletions src/Objects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Define a type of struct object to hold data about geochron samples from
# a region or stratigraphic section of interest
mutable struct ChronAgeData{N}
@kwdef mutable struct ChronAgeData{N}
Name::NTuple{N, String}
Height::Vector{Float64}
Height_sigma::Vector{Float64}
Expand All @@ -24,7 +24,7 @@
end

function ChronAgeData(nSamples::Integer)
smpl = ChronAgeData{nSamples}(
ChronAgeData{nSamples}(
ntuple(i->"Sample name", nSamples),
collect(1.0:nSamples), # Sample Height
zeros(nSamples), # Sample Height_sigma
Expand All @@ -44,23 +44,38 @@
"Ma",
"m",
)
return smpl
end
# For backwards compatibility
const NewChronAgeData = ChronAgeData
export NewChronAgeData
const NewStratAgeData = ChronAgeData
export NewStratAgeData
const StratAgeData = ChronAgeData
export StratAgeData

@kwdef mutable struct GeneralAgeData{N}
Name::NTuple{N, String}
Height::Vector{Float64}
Height_sigma::Vector{Float64}
Age::Vector{Distribution{Univariate, Continuous}}
Age_Sidedness::Vector{Float64}
Chronometer::NTuple{N, Symbol}
Age_Unit::String
Height_Unit::String
end

function GeneralAgeData(nSamples::Integer)
GeneralAgeData{nSamples}(
ntuple(i->"Sample name", nSamples),
collect(1.0:nSamples), # Sample Height
zeros(nSamples), # Sample Height_sigma
fill(Uniform(0,4567),nSamples), # Sample ages
zeros(nSamples), # Sidedness (zeros by default, geochron constraints are two-sided). Use -1 for a maximum age and +1 for a minimum age, 0 for two-sided
ntuple(i->:Chronometer, nSamples), # Age Types (e.g., :UPb or :ArAr)
"Ma",
"m",
)
end

# One-sigma systematic uncertainty
mutable struct SystematicUncertainty
UPb::Float64
ArAr::Float64
end
SystematicUncertainty() = SystematicUncertainty(NaN, NaN)
export SystematicUncertainty

# A type of object to hold data about hiatuses
mutable struct HiatusData
Expand All @@ -73,18 +88,15 @@
end

function HiatusData(nHiatuses::Integer)
hiatus = HiatusData(
HiatusData(
fill(NaN,nHiatuses), # Height
fill(NaN,nHiatuses), # Height_sigma
fill(NaN,nHiatuses), # Duration
fill(NaN,nHiatuses), # Duration_sigma
"Ma",
"m",
)
return hiatus
end
const NewHiatusData = HiatusData
export NewHiatusData

# A type of object to specify the configuration of the stratigraphic model
mutable struct StratAgeModelConfiguration
Expand All @@ -96,7 +108,7 @@
end

function StratAgeModelConfiguration()
return StratAgeModelConfiguration(NaN, 0, 0, 0, NaN)
StratAgeModelConfiguration(NaN, 0, 0, 0, NaN)
end
const NewStratAgeModelConfiguration = StratAgeModelConfiguration
export NewStratAgeModelConfiguration
Expand Down
10 changes: 9 additions & 1 deletion test/testStratOnly.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Make an instance of a ChronAgeData object for nSamples
nSamples = 4
smpl = ChronAgeData(nSamples)
@test smpl isa ChronAgeData
smpl.Name = ("Sample 1", "Sample 2", "Sample 3", "Sample 4") # Et cetera
smpl.Age .= [ 699.1, 708.8, 723.0, 754.0,] # Measured ages
smpl.Age_sigma .= [ 3.0, 7.0, 5.0, 5.0,] # Measured 1-σ uncertainties
Expand Down Expand Up @@ -56,4 +57,11 @@ hiatus.Duration_sigma = [ 3.1, 2.0 ]
@test all(!isnan, agedist)
@test size(hiatusdist) == (nHiatuses, config.nsteps)
@test mean(hiatusdist, dims=2) [10.580012942504894; 18.96167245288326;;] atol=2
@test -Inf < mean(lldist) < 0
@test -Inf < mean(lldist) < 0

## --- Strat only, general Distributions-based case

# Make an instance of a ChronAgeData object for nSamples
nSamples = 4
smpl = GeneralAgeData(nSamples)
@test smpl isa GeneralAgeData
4 changes: 2 additions & 2 deletions test/testUtilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@test d isa BilinearExponential{Float64}
@test pdf(d, 66.02) 0.00010243952455548608
@test logpdf(d, 66.02) (-3.251727600957773 -5.9345103368858085)
@test pdf(d, [66.02, 66.08, 66.15]) [0.00010243952455548608, 1.0372066408907184e-13, 1.0569878258022094e-28]
@test pdf.(d, [66.02, 66.08, 66.15]) [0.00010243952455548608, 1.0372066408907184e-13, 1.0569878258022094e-28]

@test eltype(d) === partype(d) === Float64
@test params(d) == (-5.9345103368858085, 66.00606672179812, 0.17739474265630253, 70.57882331291309, 0.6017142541555505)
Expand All @@ -21,7 +21,7 @@
@test d isa Radiocarbon{Float64}
@test pdf(d, 950) 0.0036210273644940918
@test logpdf(d, 950) -3.4446721311475414
@test pdf(d, [900, 950, 1000]) [3.372067127114498e-7, 0.0036210273644940918, 1.5582187464154278e-12]
@test pdf.(d, [900, 950, 1000]) [3.372067127114498e-7, 0.0036210273644940918, 1.5582187464154278e-12]

@test eltype(d) === partype(d) === Float64
@test location(d) 926.3094740428785 atol=0.1
Expand Down

0 comments on commit 13348ba

Please sign in to comment.