Skip to content

Commit

Permalink
add DiskArrays forwarding to Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Aug 13, 2024
1 parent d952655 commit 346d208
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ mind["name"]
"""
function MessageIndex(message::GRIB.Message; index_keys = ALL_KEYS)
values = read_message.(Ref(message), index_keys)
headers = Dict(k => v for (k,v) in zip(index_keys, values))
headers = Dict{String,Any}(k => v for (k, v) in zip(index_keys, values))

offset = Int(message["offset"])
length = message["totalLength"]
Expand All @@ -280,12 +280,11 @@ function filter_messages(mindexs::Vector{<:MessageIndex}, k::AbstractString, v)
end


function filter_messages(mindexs::Vector{<:MessageIndex}; query...)
ms = deepcopy(mindexs)
function filter_messages(ms::Vector{<:MessageIndex}; query...)
for (k, v) in query
ms = filter_messages(ms, string(k), v)
end
ms
return ms
end

function filter_offsets(mindexs::Vector{<:MessageIndex}, key, val)
Expand Down
2 changes: 1 addition & 1 deletion src/variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Base.parent(var::Variable) = var.values
Base.size(var::Variable) = _size_dims(var.dims)
Base.getindex(var::Variable, I...) = getindex(parent(var), I...)

DA.eachchunk(A::Variable) = DA.eachchunks(parent(A))
DA.eachchunk(A::Variable) = DA.eachchunk(parent(A))
DA.haschunks(A::Variable) = DA.haschunks(parent(A))
DA.readblock!(A::Variable, aout, i::AbstractUnitRange...) =
DA.readblock!(parent(A), aout, i...)
Expand Down
11 changes: 11 additions & 0 deletions test/dataset.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using GRIBDatasets
using Dates
using DiskArrays
using Test
using GRIBDatasets: getone
using GRIBDatasets: Variable
Expand Down Expand Up @@ -30,6 +31,16 @@ using GRIBDatasets: CDM
@test CDM.name(ds[:t]) == CDM.name(ds["t"])
end

@testset "DiskArrays on Variable" begin
var = ds[:z].var
size(var)
@test DiskArrays.eachchunk(var) == DiskArrays.eachchunk(parent(var))
@test DiskArrays.haschunks(var) == DiskArrays.haschunks(parent(var))
block = zeros(10, 10, 1, 1, 1)
DiskArrays.readblock!(var, block, 1:10, 1:10, 1:1, 1:1, 1:1)
@test all(block .== var[1:10, 1:10, 1, 1, 1])
end

@testset "dataset indexing" begin
vars = keys(ds)
@test vars[1] == "lon"
Expand Down

0 comments on commit 346d208

Please sign in to comment.