Skip to content

Commit

Permalink
multi-file
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Feb 15, 2024
1 parent efe7c05 commit dca9606
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 71 deletions.
1 change: 1 addition & 0 deletions src/ZarrDatasets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Base:

import CommonDataModel:
CFVariable,
MFDataset,
SymbolOrString,
attrib,
attribnames,
Expand Down
4 changes: 2 additions & 2 deletions src/dataset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ function ZarrDataset(url::AbstractString,mode = "r";
end


ZarrDataset(keys::AbstractArray{<:AbstractString,N}, args...; kwargs...) where N =
ZarrDataset(ZarrDataset,fnames, args...; kwargs...)
ZarrDataset(fnames::AbstractArray{<:AbstractString,N}, args...; kwargs...) where N =
MFDataset(ZarrDataset,fnames, args...; kwargs...)


function ZarrDataset(f::Function,args...; kwargs...)
Expand Down
71 changes: 2 additions & 69 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,74 +1,7 @@
using CommonDataModel: iswritable, attribnames, parentdataset, load!, dataset
using Dates
using DiskArrays
using NCDatasets
using Test
using ZarrDatasets

@testset "ZarrDatasets.jl" begin
fname = tempname()
mkpath(fname)

nczarr_name = "file://" * fname * "#mode=zarr"
@debug "filenames " nczarr_name fname
v = randn(2,3)
ds = NCDataset(nczarr_name,"c")
defVar(ds,"var",v,("lon","lat"),attrib = Dict(
"foo" => "bar",
"int_attribute" => 1,
"float_attribute" => 1.,
"scale_factor" => 1.23))
ds.attrib["title"] = "test file"
close(ds)

ds = NCDataset(nczarr_name)
dsz = ZarrDataset(fname)

@test Set(dimnames(dsz)) == Set(dimnames(ds))

for (name,len) in ds.dim
@test dsz.dim[name] == len
end

for (varname,v) in ds
@test haskey(dsz,varname)

v2 = dsz[varname]
@test Array(v2) == Array(v)

for (attribname,attribval) in v.attrib
@test v2.attrib[attribname] == attribval
end
end

for (attribname,attribval) in ds.attrib
@test dsz.attrib[attribname] == attribval
end

io = IOBuffer()
show(io,dsz)
str = String(take!(io))
@test occursin("title",str)

@test !iswritable(dsz)
@test "title" in attribnames(dsz)
@test isnothing(parentdataset(dsz))

zvar = ZarrDataset(fname) do ds3
Array(ds3["var"])
end

@test DiskArrays.haschunks(dsz["var"]) == DiskArrays.Chunked()
@test length(DiskArrays.eachchunk(dsz["var"])) 1
@test zvar == Array(ds["var"])

v = dsz["var"].var
buffer = zeros(eltype(v),size(v))
load!(v,buffer,:,:)

@test buffer == Array(ds["var"].var)

@test dataset(dsz["var"]) == dsz
close(ds)
close(dsz)
include("test_cdm.jl")
include("test_multifile.jl")
end

0 comments on commit dca9606

Please sign in to comment.