Skip to content
Open
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
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GRIB = "b16dfd50-4035-11e9-28d4-9dfe17e6779b"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
AxisArrays = "v0.4.0"
Expand All @@ -21,7 +22,7 @@ FileIO = "1.3.0"
GRIB = "0.1, 0.2"
JSON = "0.21.0"
PyCall = "1.91.0"
julia = "1.2"
Requires = "1.0"

[extras]
AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9"
Expand Down
51 changes: 21 additions & 30 deletions src/backends.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module Backends

using FileIO
using Requires
using CfGRIB

# Goal is for the backends to be optional, so only include the files if the
Expand All @@ -7,42 +10,28 @@ BACKEND_PROVIDERS = [:AxisArrays, :DimensionalData]
AVAILABLE_BACKENDS = []
DEFAULT_BACKEND = DataSet

try
using DimensionalData
include("./backends/dimensionaldata.jl")
global DEFAULT_BACKEND = DimensionalArrayWrapper
append!(AVAILABLE_BACKENDS, [:DimensionalArray])
catch e
if !(e isa ArgumentError)
throw(e)
function __init__()
@require AxisArrays = "39de3d68-74b9-583c-8d2d-e117c070f3a9" begin
include("./backends/dimensionaldata.jl")
println("Weee")
global DEFAULT_BACKEND = AxisArrayWrapper
append!(AVAILABLE_BACKENDS, [:AxisArray])
end
end

try
using AxisArrays
include("./backends/axisarrays.jl")
global DEFAULT_BACKEND = AxisArrayWrapper
append!(AVAILABLE_BACKENDS, [:AxisArray])
catch e
if !(e isa ArgumentError)
throw(e)
@require DimensionalData="0703355e-b756-11e9-17c0-8b28908087d0" begin
include("./backends/axisarrays.jl")
println("Weee")
global DEFAULT_BACKEND = DimensionalArrayWrapper
append!(AVAILABLE_BACKENDS, [:DimensionalArray])
end
end#

# If no backends could be loaded print a warning
if DEFAULT_BACKEND == DataSet
@warn """No backends could be loaded, setting default to bare `DataSet`.
Please include one of: $BACKEND_PROVIDERS.
Run `import Pkg; Pkg.add("BACKEND")` to install one of the array backends"""
if DEFAULT_BACKEND == DataSet
@warn """No backends could be loaded, setting default to bare `DataSet`.
Please include one of: $BACKEND_PROVIDERS.
Run `import Pkg; Pkg.add("BACKEND")` to install one of the array backends"""
end
end


# function load(f::String; backend=DEFAULT_BACKEND, kwargs...)
# ds = DataSet(f, kwargs...)

# return convert(backend, ds)
# end

function fileio_load(f::File{format"GRIB"}; backend=DEFAULT_BACKEND, kwargs...)
""" Load command for FileIO integration. Following line must be in the
FileIO Registry for this to function properly:
Expand All @@ -52,3 +41,5 @@ function fileio_load(f::File{format"GRIB"}; backend=DEFAULT_BACKEND, kwargs...)
ds = DataSet(f.filename, kwargs...)
return convert(backend, ds)
end

end # module