diff --git a/src/IO/InputOutput.jl b/src/IO/InputOutput.jl index 84f12cdb00fad8cf5556ee7dfb9e749c62fc688b..47163c69a16ba1b9bbef0108980f736c1d357de5 100644 --- a/src/IO/InputOutput.jl +++ b/src/IO/InputOutput.jl @@ -7,11 +7,13 @@ using JSON3 using Lazy: @>> using Unitful +export loadforcings + include("ioutils.jl") const INPUT_DIR = "input/" -const FORCINGS_DIR = joinpath(INPUT_DIR, "forcings") -const PARA_DIR = joinpath(INPUT_DIR, "para") +const DEFAULT_FORCINGS_DIR = joinpath(INPUT_DIR, "forcings") +const DEFAULT_PARA_DIR = joinpath(INPUT_DIR, "para") struct Resource name::String @@ -42,6 +44,10 @@ struct JsonSpec{Version} <: InputSpec end export InputSpec, JsonSpec """ + loadforcings(filename::String, units...; spec::Type{T}=JsonSpec{1}) + loadforcings(resource::Resource, units...; spec::Type{T}=JsonSpec{1}, outdir=DEFAULT_FORCINGS_DIR) + loadforcings(::Type{JsonSpec{1}}, filename::String, units::Pair{Symbol,<:Unitful.Units}...) + Loads forcing data from the given file according to the format specified by `spec::InputSpec`. Default is JsonSpec{1}. Returns a NamedTuple of the form `(data=(...), timestamps=Array{DateTime,1})` where `data` is a NamedTuple matching the structure of the JSON file. Units can (and should) be supplied as additional pair arguments, e.g: @@ -49,7 +55,7 @@ the structure of the JSON file. Units can (and should) be supplied as additional `loadforcings("example.json", :Tair=>u"°C", :Ptot=>u"mm")` """ loadforcings(filename::String, units...; spec::Type{T}=JsonSpec{1}) where {T <: InputSpec} = loadforcings(T, filename, units...) -loadforcings(resource::Resource, units...; spec::Type{T}=JsonSpec{1}) where {T <: InputSpec} = loadforcings(T, fetch(resource, FORCINGS_DIR), units...) +loadforcings(resource::Resource, units...; spec::Type{T}=JsonSpec{1}, outdir=DEFAULT_FORCINGS_DIR) where {T <: InputSpec} = loadforcings(T, fetch(resource, outdir), units...) function loadforcings(::Type{JsonSpec{1}}, filename::String, units::Pair{Symbol,<:Unitful.Units}...) dict = open(filename, "r") do file; JSON3.read(file) end # convert JSON3 dict for data field to Julia dict @@ -63,6 +69,4 @@ function loadforcings(::Type{JsonSpec{1}}, filename::String, units::Pair{Symbol, (data = NamedTuple{Tuple(keys(data))}(tuple(vals_with_units...)), timestamps = Array(ts)) end -export loadforcings - -end \ No newline at end of file +end diff --git a/src/Setup/Setup.jl b/src/Setup/Setup.jl index 55bb8afc6c88fd8806c6116bc7d3194733da53cc..1cd7be95d5bb3e6290eb3de5d90605fd0214947e 100644 --- a/src/Setup/Setup.jl +++ b/src/Setup/Setup.jl @@ -6,6 +6,7 @@ import Zygote import CryoGrid.Interface: Top, Bottom +using CryoGrid.InputOutput using CryoGrid.Interface using CryoGrid.Layers using CryoGrid.Numerics @@ -28,6 +29,8 @@ using Reexport @reexport using OrdinaryDiffEq @reexport using SimulationLogs +export CryoGridSetup, CryoGridOutput, withaxes, getstate, getvar + include("stratigraphy.jl") include("setup.jl") include("problem.jl") diff --git a/src/Setup/output.jl b/src/Setup/output.jl index bc22c189047f29681f6ede1bf7181f720c50f895..ed63d3bc0cf6b04bf4e770859e5ab0b5b5e505df 100644 --- a/src/Setup/output.jl +++ b/src/Setup/output.jl @@ -98,5 +98,3 @@ function Base.getproperty(out::CryoGridOutput, sym::Symbol) out.vars[sym] end end - -export CryoGridOutput, getvar diff --git a/src/Setup/setup.jl b/src/Setup/setup.jl index 9f18542f0ff39e92de4faa7ab0fbcbaa38648ce6..c4a219059e4f063659dcade4ee064c2c311b4260 100644 --- a/src/Setup/setup.jl +++ b/src/Setup/setup.jl @@ -16,8 +16,6 @@ struct CryoGridSetup{S,G,M,C,U,P} new{S,G,M,C,U,P}(strat,grid,meta,cache,uproto,pproto) end -export CryoGridSetup - """ Constructs a `CryoGridSetup` from the given stratigraphy and grid. `arrayproto` keyword arg should be an array instance (of any arbitrary length, including zero, contents are ignored) that will determine the array type used for all state vectors. @@ -168,8 +166,6 @@ Invokes `unconstrain` on all parameters in `p`. Assumes `p` to be of the same fo """ Numerics.unconstrain(p::ComponentVector, setup::CryoGridSetup) = _apply_or_unapply_constraints(:unapply, p, setup) -export withaxes, getstate, getvar - """ Generated step function (i.e. du/dt) for any arbitrary CryoGridSetup. Specialized code is generated and compiled on the fly via the @generated macro to ensure type stability. The generated code updates each layer in the stratigraphy