Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sea level curves #129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(

Check warning on line 22 in src/sea_level.jl

View check run for this annotation

Codecov / codecov/patch

src/sea_level.jl#L21-L22

Added lines #L21 - L22 were not covered by tests
name;
flip_age = flip_age,
flip_elevation = flip_elevation
)
new{eltype(age)}(age, elevation, name)

Check warning on line 27 in src/sea_level.jl

View check run for this annotation

Codecov / codecov/patch

src/sea_level.jl#L27

Added line #L27 was not covered by tests
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

Check warning on line 38 in src/sea_level.jl

View check run for this annotation

Codecov / codecov/patch

src/sea_level.jl#L31-L38

Added lines #L31 - L38 were not covered by tests

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

Check warning on line 47 in src/sea_level.jl

View check run for this annotation

Codecov / codecov/patch

src/sea_level.jl#L40-L47

Added lines #L40 - L47 were not covered by tests
end
Loading
Loading