Skip to content

Commit

Permalink
Add Age and Interval types
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Mar 18, 2024
1 parent 61e5789 commit bf93e22
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Isoplot"
uuid = "5adc30d5-9ddf-423c-bb15-ece697bec3ab"
authors = ["C. Brenhin Keller <[email protected]>"]
version = "0.3.1"
version = "0.3.2"

[deps]
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Expand Down
2 changes: 1 addition & 1 deletion src/Isoplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module Isoplot

# Abstract types which we'll subtype later
include("analysis.jl")
export age, ratio, ellipse, CI
export age, ratio, ellipse, CI, Age, Interval

include("regression.jl")
export wmean, awmean, gwmean, distwmean, mswd
Expand Down
31 changes: 29 additions & 2 deletions src/analysis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ ratio(t::Number, λ::Number) = exp(λ*t) - 1
# Extend Base.isnan to return true if any component of the Analysis is NaN
Base.isnan(a::Analysis) = any(isnan, a.μ) || any(isnan, a.σ) || any(isnan, a.Σ)

# A moment in time
struct Age{T<:AbstractFloat}
mean::T
sigma::T
end
Age(μ, σ) = Age(float(μ), float(σ))
Age(x) = Age(val(x), err(x))

# A duration of time
struct Interval{T<:AbstractFloat}
min::T
min_sigma::T
max::T
max_sigma::T
end
Interval(lμ, lσ, uμ, uσ) = Interval(float(lμ), float(lσ), float(uμ), float(uσ))
Interval(l, u) = Interval(val(l), err(l), val(u), err(u))
Base.min(x::Interval{T}) where {T} = Age{T}(x.min, x.min_sigma)
Base.max(x::Interval{T}) where {T} = Age{T}(x.max, x.max_sigma)

# A confidence or credible interval with 95% bounds
struct CI{T<:AbstractFloat}
mean::T
sigma::T
Expand Down Expand Up @@ -83,6 +104,12 @@ end
# Generic fallback methods for things that don't have uncertainties
val(x) = x
err(x::T) where {T} = zero(T)
# Specialized methods for `CI`s
val(x::CI{T}) where {T} = x.mean::T
err(x::CI{T}) where {T} = x.sigma::T
# Specialized methods for `Age`s
val(x::Age{T}) where {T} = x.mean::T
err(x::Age{T}) where {T} = x.sigma::T
# Specialized methods for `Measurement`s
val(m::Measurement{T}) where {T} = m.val::T
err(m::Measurement{T}) where {T} = m.err::T
val(x::Measurement{T}) where {T} = x.val::T
err(x::Measurement{T}) where {T} = x.err::T
18 changes: 16 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,24 @@ using Measurements
end

@testset "General" begin
@test Isoplot.val(1±1) === 1.0
@test Isoplot.err(1±1) === 1.0
@test Age(0) isa Age{Float64}
@test Age(0, 1) isa Age{Float64}
@test Interval(0, 1) isa Interval{Float64}
@test Interval(0, 1) === Interval(0,0, 1,0)
@test min(Interval(0, 1)) isa Age{Float64}
@test max(Interval(0, 1)) isa Age{Float64}
@test min(Interval(0, 1)) === Age(0,0) === Age(0)
@test max(Interval(0, 1)) === Age(1,0) === Age(1)
@test Isoplot.val(1) === 1
@test Isoplot.err(1) === 0
@test Isoplot.val(1±1) === 1.0
@test Isoplot.err(1±1) === 1.0
ci = CI(1:10)
@test Isoplot.val(ci) 5.5
@test Isoplot.err(ci) 3.0276503540974917
a = Age(ci)
@test Isoplot.val(a) 5.5
@test Isoplot.err(a) 3.0276503540974917
end

@testset "U-Pb" begin
Expand Down

2 comments on commit bf93e22

@brenhinkeller
Copy link
Member Author

@brenhinkeller brenhinkeller commented on bf93e22 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register
Release notes:

  • Add Age and Interval types

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/103111

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.2 -m "<description of version>" bf93e22a132774937865dc2d5ac815c3d9a88efc
git push origin v0.3.2

Please sign in to comment.