Skip to content

Commit

Permalink
Rename Age_Distribution field of GeneraAgeData to just Age
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Jul 9, 2024
1 parent 0680917 commit ec4e16e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Chron"
uuid = "68885b1f-77b5-52a7-b2e7-6a8014c56b98"
authors = ["C. Brenhin Keller <[email protected]>"]
version = "0.6.1"
version = "0.6.2"

[deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Expand Down
20 changes: 10 additions & 10 deletions examples/Chron1.0StratOnlyGeneral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
nsamples = 5
# Make an instance of a GeneralAgeData object for n samples
smpl = GeneralAgeData(nsamples)
smpl.Name = ( "Sample 1", "Sample 2", "Sample 3", "Sample 4", "Sample 5",) # Et cetera
smpl.Age_Distribution = [Normal(39.5,0.1), Uniform(37, 38), Normal(36.3, 0.1), Uniform(33.5,34), Normal(32.1, 0.1),] # Measured ages
smpl.Height = [ 100, 200, 300, 400, 500,] # Depths below surface should be negative
smpl.Age_Sidedness = 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
smpl.Name = ( "Sample 1", "Sample 2", "Sample 3", "Sample 4", "Sample 5",) # Et cetera
smpl.Age = [Normal(39.5,0.1), Uniform(37, 38), Normal(36.3, 0.1), Uniform(33.5,34), Normal(32.1, 0.1),] # Measured ages
smpl.Height = [ 100, 200, 300, 400, 500,] # Depths below surface should be negative
smpl.Age_Sidedness = 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
smpl.Age_Unit = "Ma" # Unit of measurement for ages
smpl.Height_Unit = "m" # Unit of measurement for Height and Height_sigma

Expand Down Expand Up @@ -60,13 +60,13 @@
plot!(hdl, [mdl.Age_025CI; reverse(mdl.Age_975CI)],[mdl.Height; reverse(mdl.Height)], fill=(round(Int,minimum(mdl.Height)),0.5,:blue), label="model")
plot!(hdl, mdl.Age, mdl.Height, linecolor=:blue, label="") # Center line
t = smpl.Age_Sidedness .== 0 # Two-sided constraints (plot in black)
any(t) && plot!(hdl, mean.(smpl.Age_Distribution[t]), smpl.Height[t], xerror=2*std.(smpl.Age_Distribution[t]),label="data",seriestype=:scatter,color=:black)
any(t) && plot!(hdl, mean.(smpl.Age[t]), smpl.Height[t], xerror=2*std.(smpl.Age[t]),label="data",seriestype=:scatter,color=:black)
t = smpl.Age_Sidedness .== 1 # Minimum ages (plot in cyan)
any(t) && plot!(hdl, mean.(smpl.Age_Distribution[t]), smpl.Height[t], xerror=(2*std.(smpl.Age_Distribution[t]),zeros(count(t))),label="",seriestype=:scatter,color=:cyan,msc=:cyan)
any(t) && zip(mean.(smpl.Age_Distribution[t]), mean.(smpl.Age_Distribution[t]).+nanmean(std.(smpl.Age_Distribution[t]))*4, smpl.Height[t]) .|> x-> plot!([x[1],x[2]],[x[3],x[3]], arrow=true, label="", color=:cyan)
any(t) && plot!(hdl, mean.(smpl.Age[t]), smpl.Height[t], xerror=(2*std.(smpl.Age[t]),zeros(count(t))),label="",seriestype=:scatter,color=:cyan,msc=:cyan)
any(t) && zip(mean.(smpl.Age[t]), mean.(smpl.Age[t]).+nanmean(std.(smpl.Age[t]))*4, smpl.Height[t]) .|> x-> plot!([x[1],x[2]],[x[3],x[3]], arrow=true, label="", color=:cyan)
t = smpl.Age_Sidedness .== -1 # Maximum ages (plot in orange)
any(t) && plot!(hdl, mean.(smpl.Age_Distribution[t]), smpl.Height[t], xerror=(zeros(count(t)),2*std.(smpl.Age_Distribution[t])),label="",seriestype=:scatter,color=:orange,msc=:orange)
any(t) && zip(mean.(smpl.Age_Distribution[t]), mean.(smpl.Age_Distribution[t]).-nanmean(std.(smpl.Age_Distribution[t]))*4, smpl.Height[t]) .|> x-> plot!([x[1],x[2]],[x[3],x[3]], arrow=true, label="", color=:orange)
any(t) && plot!(hdl, mean.(smpl.Age[t]), smpl.Height[t], xerror=(zeros(count(t)),2*std.(smpl.Age[t])),label="",seriestype=:scatter,color=:orange,msc=:orange)
any(t) && zip(mean.(smpl.Age[t]), mean.(smpl.Age[t]).-nanmean(std.(smpl.Age[t]))*4, smpl.Height[t]) .|> x-> plot!([x[1],x[2]],[x[3],x[3]], arrow=true, label="", color=:orange)
savefig(hdl,"AgeDepthModel.pdf")
display(hdl)

Expand Down Expand Up @@ -147,7 +147,7 @@
# Plot results (mean and 95% confidence interval for both model and data)
hdl = plot([mdl.Age_025CI; reverse(mdl.Age_975CI)],[mdl.Height; reverse(mdl.Height)], fill=(minimum(mdl.Height),0.5,:blue), label="model")
plot!(hdl, mdl.Age, mdl.Height, linecolor=:blue, label="", fg_color_legend=:white)
plot!(hdl, mean.(smpl.Age_Distribution), smpl.Height, xerror=std.(smpl.Age_Distribution)*2,label="data",seriestype=:scatter,color=:black)
plot!(hdl, mean.(smpl.Age), smpl.Height, xerror=std.(smpl.Age)*2,label="data",seriestype=:scatter,color=:black)
plot!(hdl, xlabel="Age ($(smpl.Age_Unit))", ylabel="Height ($(smpl.Height_Unit))")
savefig(hdl, "Interpolated age distribution.pdf")
display(hdl)
Expand Down
60 changes: 30 additions & 30 deletions src/Objects.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@
Sidedness_Method::Symbol
end

function ChronAgeData(nSamples::Integer)
ChronAgeData{nSamples}(
ntuple(i->"Sample name", nSamples),
collect(1.0:nSamples), # Sample Height
zeros(nSamples), # Sample Height_sigma
fill(NaN,nSamples), # Sample ages
fill(NaN,nSamples), # Sample age uncertainty
fill(NaN,nSamples), # Sample age 2.5% CI
fill(NaN,nSamples), # Sample age 97.5% CI
fill(NaN,nSamples), # Sample 14C ages
fill(NaN,nSamples), # Sample 14C uncertainties
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
zeros(nSamples), # DistType (for Distribution-fitting only: 0=distribution to be fit, 1=single Gaussian)
Vector{Vector{Float64}}(undef,nSamples), # Stationary distribution of eruption age
ntuple(i->:Chronometer, nSamples), # Age Types (e.g., :UPb or :ArAr)
fill(NaN,5,nSamples), # Sample age distribution parameters
function ChronAgeData(nsamples::Integer)
ChronAgeData{nsamples}(
ntuple(i->"Sample name", nsamples),
collect(1.0:nsamples), # Sample Height
zeros(nsamples), # Sample Height_sigma
fill(NaN,nsamples), # Sample ages
fill(NaN,nsamples), # Sample age uncertainty
fill(NaN,nsamples), # Sample age 2.5% CI
fill(NaN,nsamples), # Sample age 97.5% CI
fill(NaN,nsamples), # Sample 14C ages
fill(NaN,nsamples), # Sample 14C uncertainties
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
zeros(nsamples), # DistType (for Distribution-fitting only: 0=distribution to be fit, 1=single Gaussian)
Vector{Vector{Float64}}(undef,nsamples), # Stationary distribution of eruption age
ntuple(i->:Chronometer, nsamples), # Age Types (e.g., :UPb or :ArAr)
fill(NaN,5,nsamples), # Sample age distribution parameters
"./", # Relative path where we can find .csv data files
2, # i.e., are the data files 1-sigma or 2-sigma
"Ma",
Expand All @@ -52,22 +52,22 @@
Name::NTuple{N, String}
Height::Vector{Float64}
Height_sigma::Vector{Float64}
Age_Distribution::Vector{<:Union{<:Distribution{Univariate, Continuous}}}
Age::Vector{<:Union{<:Distribution{Univariate, Continuous}}}
Age_Sidedness::Vector{Float64}
Chronometer::NTuple{N, Symbol}
Age_Unit::String
Height_Unit::String
Sidedness_Method::Symbol
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)
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",
:cdf,
Expand All @@ -85,12 +85,12 @@
Height_Unit::String
end

function HiatusData(nHiatuses::Integer)
function HiatusData(nhiatuses::Integer)
HiatusData(
fill(NaN,nHiatuses), # Height
fill(NaN,nHiatuses), # Height_sigma
fill(NaN,nHiatuses), # Duration
fill(NaN,nHiatuses), # Duration_sigma
fill(NaN, nhiatuses), # Height
fill(NaN, nhiatuses), # Height_sigma
fill(NaN, nhiatuses), # Duration
fill(NaN, nhiatuses), # Duration_sigma
"Ma",
"m",
)
Expand Down
4 changes: 2 additions & 2 deletions src/StratMetropolis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
bounding = config.bounding

# Stratigraphic age constraints
ages = unionize(smpl.Age_Distribution)::Vector{<:Union{<:Distribution{Univariate, Continuous}}}
ages = unionize(smpl.Age)::Vector{<:Union{<:Distribution{Univariate, Continuous}}}
Height = copy(smpl.Height)::Vector{Float64}
Height_sigma = smpl.Height_sigma::Vector{Float64} .+ 1E-9 # Avoid divide-by-zero issues
Age_Sidedness = copy(smpl.Age_Sidedness)::Vector{Float64} # Bottom is a maximum age and top is a minimum age
Expand Down Expand Up @@ -227,7 +227,7 @@
bounding = config.bounding

# Stratigraphic age constraints
ages = unionize(smpl.Age_Distribution)::Vector{<:Union{<:Distribution{Univariate, Continuous}}}
ages = unionize(smpl.Age)::Vector{<:Union{<:Distribution{Univariate, Continuous}}}
Height = copy(smpl.Height)::Vector{Float64}
Height_sigma = smpl.Height_sigma::Vector{Float64} .+ 1E-9 # Avoid divide-by-zero issues
Age_Sidedness = copy(smpl.Age_Sidedness)::Vector{Float64} # Bottom is a maximum age and top is a minimum age
Expand Down
8 changes: 4 additions & 4 deletions test/testStratOnlyGeneral.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
nsamples = 5
# Make an instance of a GeneralAgeData object for n samples
smpl = GeneralAgeData(nsamples)
smpl.Name = ( "Sample 1", "Sample 2", "Sample 3", "Sample 4", "Sample 5",) # Et cetera
smpl.Age_Distribution = [Normal(39.5,0.1), Uniform(37, 38), Normal(36.3, 0.1), Uniform(33.5,34), Normal(32.1, 0.1),] # Measured ages
smpl.Height = [ 100, 200, 300, 400, 500,] # Depths below surface should be negative
smpl.Age_Sidedness = 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
smpl.Name = ( "Sample 1", "Sample 2", "Sample 3", "Sample 4", "Sample 5",) # Et cetera
smpl.Age = [Normal(39.5,0.1), Uniform(37, 38), Normal(36.3, 0.1), Uniform(33.5,34), Normal(32.1, 0.1),] # Measured ages
smpl.Height = [ 100, 200, 300, 400, 500,] # Depths below surface should be negative
smpl.Age_Sidedness = 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
smpl.Age_Unit = "Ma" # Unit of measurement for ages
smpl.Height_Unit = "m" # Unit of measurement for Height and Height_sigma
@test smpl isa GeneralAgeData
Expand Down

2 comments on commit ec4e16e

@brenhinkeller
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register
Release notes:

  • Rename Age_Distribution field of GeneraAgeData struct to just Age

@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/110773

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.6.2 -m "<description of version>" ec4e16e684622aba8f2fcc18a3df472636727622
git push origin v0.6.2

Please sign in to comment.