Skip to content

Commit

Permalink
Merge pull request #25 from JuliaEarth/auto-juliaformatter-pr
Browse files Browse the repository at this point in the history
[AUTO] JuliaFormatter.jl run
  • Loading branch information
juliohm committed May 15, 2023
2 parents 61e40c8 + 52c3506 commit b7d4657
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 53 deletions.
4 changes: 2 additions & 2 deletions src/durations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ end

ExponentialDuration(λ) = ExponentialDuration(Random.GLOBAL_RNG, λ)

(p::ExponentialDuration)(t) = rand(p.rng, Exponential(1/p.λ))
(p::ExponentialDuration)(t) = rand(p.rng, Exponential(1 / p.λ))

struct UniformDuration{RNG}
rng::RNG
Expand All @@ -19,4 +19,4 @@ end

UniformDuration(a, b) = UniformDuration(Random.GLOBAL_RNG, a, b)

(p::UniformDuration)(t) = rand(p.rng, Uniform(p.a,p.b))
(p::UniformDuration)(t) = rand(p.rng, Uniform(p.a, p.b))
15 changes: 7 additions & 8 deletions src/environment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ struct Environment{RNG}
rng::RNG
processes::Vector
transitions::Matrix{Float64}
durations
durations::Any
end

Environment(processes, transitions, durations) =
Environment(Random.GLOBAL_RNG, processes, transitions, durations)
Environment(processes, transitions, durations) = Environment(Random.GLOBAL_RNG, processes, transitions, durations)

"""
iterate(env, state=nothing)
Expand All @@ -25,9 +24,9 @@ Iterate the environment `env` producing processes and durations.
function Base.iterate(env::Environment, state=nothing)
# environment settings
ps = env.processes
P = env.transitions
Δ = env.durations
n = length(ps)
P = env.transitions
Δ = env.durations
n = length(ps)

# current state and time
if state === nothing
Expand All @@ -38,10 +37,10 @@ function Base.iterate(env::Environment, state=nothing)

# process and duration
proc = ps[s]
Δt = Δ(t)
Δt = Δ(t)

# transition to a new state
ss = wsample(env.rng, 1:n, view(P,s,:))
ss = wsample(env.rng, 1:n, view(P, s, :))
tt = t + 1

(proc, Δt), (ss, tt)
Expand Down
7 changes: 3 additions & 4 deletions src/geostats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,11 @@ function preprocess(problem::SimulationProblem, solver::StratSim)

# determine fill values
fillbase = varparams.fillbase
filltop = varparams.filltop
filltop = varparams.filltop

# save preprocessed input
preproc[var] = (environment=environment, state=state,
stack=stack, nepochs=nepochs,
fillbase=fillbase, filltop=filltop)
preproc[var] =
(environment=environment, state=state, stack=stack, nepochs=nepochs, fillbase=fillbase, filltop=filltop)
end
end

Expand Down
3 changes: 1 addition & 2 deletions src/processes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ end
Evolve the landscape `state` with timeless process `proc` for a time period `Δt`.
"""
evolve!(state::LandState, proc::TimelessProcess, Δt::Float64) =
evolve!(state.land, proc, Δt)
evolve!(state::LandState, proc::TimelessProcess, Δt::Float64) = evolve!(state.land, proc, Δt)

#------------------
# IMPLEMENTATIONS
Expand Down
4 changes: 2 additions & 2 deletions src/processes/geostats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct GeoStatsProcess{S} <: TimelessProcess
end

function evolve!(land::Matrix, proc::GeoStatsProcess)
domain = CartesianGrid(size(land))
problem = SimulationProblem(domain, :land => Float64, 1)
domain = CartesianGrid(size(land))
problem = SimulationProblem(domain, :land => Float64, 1)
solution = solve(problem, proc.solver)
land[:] .= solution[:land][1]
nothing
Expand Down
2 changes: 1 addition & 1 deletion src/processes/sequential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ end
function evolve!(land::Matrix, proc::SequentialTimelessProcess)
evolve!(land, proc.first)
evolve!(land, proc.second)
end
end
3 changes: 1 addition & 2 deletions src/processes/smoothing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,4 @@ end

SmoothingProcess() = SmoothingProcess(3.0)

evolve!(land::Matrix, proc::SmoothingProcess) =
imfilter!(land, land, centered(Kernel.gaussian(proc.σ)), "replicate")
evolve!(land::Matrix, proc::SmoothingProcess) = imfilter!(land, land, centered(Kernel.gaussian(proc.σ)), "replicate")
40 changes: 20 additions & 20 deletions src/strata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ function Strata(record::Record{LandState}, stack=:erosional)

if stack == :erosional
# erode land maps backward in time
for t=length(horizons):-1:2
for t in length(horizons):-1:2
Lt = horizons[t]
Lp = horizons[t-1]
Lp = horizons[t - 1]
erosion = Lp .> Lt
Lp[erosion] = Lt[erosion]
end
end

if stack == :depositional
# deposit sediments forward in time
for t=1:length(horizons)-1
for t in 1:(length(horizons) - 1)
Lt = horizons[t]
Lf = horizons[t+1]
Lf = horizons[t + 1]
nodeposit = Lf .≤ Lt
Lf[nodeposit] = Lt[nodeposit]
end
Expand All @@ -43,55 +43,55 @@ function voxelize(strata::Strata, nz::Int; fillbase=NaN, filltop=NaN)
horizons = strata.horizons

# initial land map
init = copy(horizons[1])
init = copy(horizons[1])
init .-= minimum(init[.!isnan.(init)])
nx, ny = size(init)

# estimate bulk sediment
thickness = diff(horizons)

# handle NaNs
init[isnan.(init)] .= 0.
for t=1:length(thickness)
init[isnan.(init)] .= 0.0
for t in 1:length(thickness)
thick = thickness[t]
thick[isnan.(thick)] .= 0.
thick[isnan.(thick)] .= 0.0
end

# estimate maximum z coordinate
zmax = maximum(init + sum(thickness))

# current elevation
elevation = floor.(Int, (init/zmax)*nz)
elevation = floor.(Int, (init / zmax) * nz)

# voxel model
model = fill(NaN, nx, ny, nz)

# fill model base
if !isnan(fillbase)
for j=1:ny, i=1:nx
for k=1:elevation[i,j]
model[i,j,k] = fillbase
for j in 1:ny, i in 1:nx
for k in 1:elevation[i, j]
model[i, j, k] = fillbase
end
end
end

# add layers to model
for t=1:length(thickness)
for t in 1:length(thickness)
thick = thickness[t]
sediments = floor.(Int, (thick/zmax)*nz)
for j=1:ny, i=1:nx
for k=1:sediments[i,j]
model[i,j,elevation[i,j]+k] = t
sediments = floor.(Int, (thick / zmax) * nz)
for j in 1:ny, i in 1:nx
for k in 1:sediments[i, j]
model[i, j, elevation[i, j] + k] = t
end
end
elevation .+= sediments
end

# fill model top
if !isnan(filltop)
for j=1:ny, i=1:nx
for k=elevation[i,j]+1:nz
model[i,j,k] = filltop
for j in 1:ny, i in 1:nx
for k in (elevation[i, j] + 1):nz
model[i, j, k] = filltop
end
end
end
Expand Down
25 changes: 13 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using StratiGraphics
using Meshes
using GeoStatsBase
using Plots; gr(size=(600,400))
using Plots;
gr(size=(600, 400));
using GeoStatsPlots # TODO: replace by GeoStatsViz
using ReferenceTests, ImageIO
using Test, Random
Expand All @@ -13,32 +14,32 @@ ENV["GKSwstype"] = "100"
isCI = "CI" keys(ENV)
islinux = Sys.islinux()
visualtests = !isCI || (isCI && islinux)
datadir = joinpath(@__DIR__,"data")
datadir = joinpath(@__DIR__, "data")

include("dummy.jl")

@testset "StratiGraphics.jl" begin
if visualtests
rng = MersenneTwister(2019)
proc = GeoStatsProcess(Dummy())
env = Environment(rng, [proc, proc], [0.5 0.5; 0.5 0.5], ExponentialDuration(rng, 1.0))
record = simulate(env, LandState(zeros(50,50)), 10)
rng = MersenneTwister(2019)
proc = GeoStatsProcess(Dummy())
env = Environment(rng, [proc, proc], [0.5 0.5; 0.5 0.5], ExponentialDuration(rng, 1.0))
record = simulate(env, LandState(zeros(50, 50)), 10)
strata = Strata(record)

@test_reference "data/strata.png" plot(strata)

for (i, fillbase, filltop) in [(1, NaN, NaN), (2, 0, NaN), (3, 0, 0)]
rng = MersenneTwister(2019)
rng = MersenneTwister(2019)
proc = GeoStatsProcess(Dummy())
env = Environment(rng, [proc, proc], [0.5 0.5; 0.5 0.5], ExponentialDuration(rng, 1.0))
prob = SimulationProblem(CartesianGrid(50,50,20), :strata => Float64, 3)
env = Environment(rng, [proc, proc], [0.5 0.5; 0.5 0.5], ExponentialDuration(rng, 1.0))
prob = SimulationProblem(CartesianGrid(50, 50, 20), :strata => Float64, 3)
solv = StratSim(:strata => (environment=env, fillbase=fillbase, filltop=filltop))
sol = solve(prob, solv)
sol = solve(prob, solv)
plts = map(sol) do real
R = asarray(real, :strata)
heatmap(rotr90(R[1,:,:]))
heatmap(rotr90(R[1, :, :]))
end
@test_reference "data/voxel$i.png" plot(plts..., layout=(3,1))
@test_reference "data/voxel$i.png" plot(plts..., layout=(3, 1))
end
end
end

0 comments on commit b7d4657

Please sign in to comment.