Skip to content

Commit

Permalink
Also add backend_kw to FieldDataset
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-ramadhan committed Sep 9, 2024
1 parent 7fbe454 commit 7e9f66e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/OutputReaders/field_dataset.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
struct FieldDataset{F, M, P}
struct FieldDataset{F, M, P, KW}
fields :: F
metadata :: M
filepath :: P
backend_kw :: KW
end

"""
Expand All @@ -22,17 +23,24 @@ linearly.
`file["metadata"]`.
- `grid`: May be specified to override the grid used in the JLD2 file.
- `backend_kw`: A dictionary of keyword arguments to pass to the backend (currently only JLD2)
to be used when opening files.
"""
function FieldDataset(filepath;
architecture=CPU(), grid=nothing, backend=InMemory(), metadata_paths=["metadata"])
architecture = CPU(),
grid = nothing,
backend = InMemory(),
metadata_paths = ["metadata"],
backend_kw = Dict{Symbol, Any}())

file = jldopen(filepath)
file = jldopen(filepath; backend_kw...)

field_names = keys(file["timeseries"])
filter!(k -> k != "t", field_names) # Time is not a field.

ds = Dict{String, FieldTimeSeries}(
name => FieldTimeSeries(filepath, name; architecture, backend, grid)
name => FieldTimeSeries(filepath, name; architecture, backend, grid, backend_kw)
for name in field_names
)

Expand All @@ -44,7 +52,7 @@ function FieldDataset(filepath;

close(file)

return FieldDataset(ds, metadata, abspath(filepath))
return FieldDataset(ds, metadata, abspath(filepath), backend_kw)
end

Base.getindex(fds::FieldDataset, inds...) = Base.getindex(fds.fields, inds...)
Expand Down

0 comments on commit 7e9f66e

Please sign in to comment.