Skip to content

Commit

Permalink
Merge pull request #129 from albert-de-montserrat/adm/sea_level
Browse files Browse the repository at this point in the history
Sea level curves
  • Loading branch information
albert-de-montserrat authored Jul 3, 2024
2 parents f946bf4 + 2d425a0 commit 7bde28e
Show file tree
Hide file tree
Showing 16 changed files with 67,621 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/GeophysicalModelGenerator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ include("IO.jl")
include("event_counts.jl")
include("surface_functions.jl")
include("movies_from_pics.jl")
include("sea_lvl.jl")

# Add optional routines (only activated when the packages are loaded)

Expand Down
48 changes: 48 additions & 0 deletions src/sea_level.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
export sea_level_files, SeaLevel, load_sea_level, curve_name

const sea_level_path = "sea_level_data"

const sea_level_files = Dict(
:Spratt_800ka => "Spratt2016-800ka.txt",
:Spratt_450ka => "Spratt2016-450ka.txt",
:Bintanja_3Ma => "Bintanja-3Ma.txt",
:Grant_153ka => "Grant2012_153ka.txt",
:Rohl_Bint_3Ma => "Rohl-Bint-3Ma.txt",
:Rohling2009_516ka => "Rohling2009-516ka.txt",
:Siddall2003_379ka => "Siddall2003-379ka.txt",
:Waelbroeck2002 => "Waelbroeck2002.txt",
)

struct SeaLevel{T}
elevation::Vector{T}
age::Vector{T}
name::Symbol

function SeaLevel(name::Symbol; flip_elevation = false, flip_age = false)
age, elevation = load_sea_level(
name;
flip_age = flip_age,
flip_elevation = flip_elevation
)
new{eltype(age)}(age, elevation, name)
end
end

Base.getindex(x::SeaLevel, i::Int64) = x.elevation[i]
Base.getindex(x::SeaLevel, i::Int64, j::Int64) = x.elevation[i], x.age[j]
Base.getindex(x::SeaLevel, i::Tuple{Int64}) = x.elevation[i...], x.age[i...]
Base.size(x::SeaLevel) = size(x.elevation)
Base.eachindex(x::SeaLevel) = eachindex(x.elevation)
Base.axes(x::SeaLevel) = axes(x.elevation)
Base.length(x::SeaLevel) = length(x.elevation)
curve_name(x::SeaLevel) = x.name

function load_sea_level(name::Symbol; flip_elevation = false, flip_age = false)
fname = sea_level_files[name]
data = readdlm(joinpath(sea_level_path, fname))
h = data[:, 1]
age = data[:, 2]
flip_elevation && reverse!(h)
flip_age && reverse!(age)
return h, age
end
Loading

0 comments on commit 7bde28e

Please sign in to comment.