From 52c35066b038b94bae29c1ab810a3d8a8f6a51b5 Mon Sep 17 00:00:00 2001 From: eliascarv Date: Mon, 15 May 2023 15:57:39 +0000 Subject: [PATCH] :robot: Format .jl files --- src/durations.jl | 4 ++-- src/environment.jl | 15 +++++++------- src/geostats.jl | 7 +++---- src/processes.jl | 3 +-- src/processes/geostats.jl | 4 ++-- src/processes/sequential.jl | 2 +- src/processes/smoothing.jl | 3 +-- src/strata.jl | 40 ++++++++++++++++++------------------- test/runtests.jl | 25 ++++++++++++----------- 9 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/durations.jl b/src/durations.jl index f8bfd50..82947f0 100644 --- a/src/durations.jl +++ b/src/durations.jl @@ -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 @@ -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)) diff --git a/src/environment.jl b/src/environment.jl index d1642f5..5b2781f 100644 --- a/src/environment.jl +++ b/src/environment.jl @@ -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) @@ -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 @@ -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) diff --git a/src/geostats.jl b/src/geostats.jl index d68e1be..07da0cd 100644 --- a/src/geostats.jl +++ b/src/geostats.jl @@ -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 diff --git a/src/processes.jl b/src/processes.jl index 165c390..0051149 100644 --- a/src/processes.jl +++ b/src/processes.jl @@ -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 diff --git a/src/processes/geostats.jl b/src/processes/geostats.jl index 7b204c6..e858fe3 100644 --- a/src/processes/geostats.jl +++ b/src/processes/geostats.jl @@ -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 diff --git a/src/processes/sequential.jl b/src/processes/sequential.jl index 286301a..2f01547 100644 --- a/src/processes/sequential.jl +++ b/src/processes/sequential.jl @@ -15,4 +15,4 @@ end function evolve!(land::Matrix, proc::SequentialTimelessProcess) evolve!(land, proc.first) evolve!(land, proc.second) -end \ No newline at end of file +end diff --git a/src/processes/smoothing.jl b/src/processes/smoothing.jl index df58885..cdad54b 100644 --- a/src/processes/smoothing.jl +++ b/src/processes/smoothing.jl @@ -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") diff --git a/src/strata.jl b/src/strata.jl index 0480d91..3a128c4 100644 --- a/src/strata.jl +++ b/src/strata.jl @@ -17,9 +17,9 @@ 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 @@ -27,9 +27,9 @@ function Strata(record::Record{LandState}, stack=:erosional) 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 @@ -43,7 +43,7 @@ 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) @@ -51,37 +51,37 @@ function voxelize(strata::Strata, nz::Int; fillbase=NaN, filltop=NaN) 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 @@ -89,9 +89,9 @@ function voxelize(strata::Strata, nz::Int; fillbase=NaN, filltop=NaN) # 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 diff --git a/test/runtests.jl b/test/runtests.jl index 7fbc0e0..af49520 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 @@ -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