Skip to content

Commit

Permalink
Don't allow missings in Zarr anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
meggart committed Jul 20, 2022
1 parent da329c1 commit 08a352e
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/datasets/zarr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@ to_zarrtype, zopen, Compressor
struct ZarrDataset
g::ZGroup
end
ZarrDataset(g::String;mode="r") = ZarrDataset(zopen(g,mode,fill_as_missing=true))
ZarrDataset(g::String;mode="r") = ZarrDataset(zopen(g,mode,fill_as_missing=false))

get_var_dims(ds::ZarrDataset,name) = reverse(ds[name].attrs["_ARRAY_DIMENSIONS"])
get_varnames(ds::ZarrDataset) = collect(keys(ds.g.arrays))
get_var_attrs(ds::ZarrDataset, name) = ds[name].attrs
function get_var_attrs(ds::ZarrDataset, name)
#We add the fill value to the attributes to be consistent with NetCDF
a = ds[name]
if a.metadata.fill_value !== nothing
merge(ds[name].attrs,Dict("_FillValue"=>a.metadata.fill_value))
else
ds[name].attrs
end
end
get_global_attrs(ds::ZarrDataset) = ds.g.attrs
Base.getindex(ds::ZarrDataset, i) = ds.g[i]
Base.haskey(ds::ZarrDataset,k) = haskey(ds.g,k)

function add_var(p::ZarrDataset, T::Type{>:Missing}, varname, s, dimnames, attr; kwargs...)
S = Base.nonmissingtype(T)
add_var(p,S, varname, s, dimnames, attr; fill_value = defaultfillval(S), kwargs...)
end
# function add_var(p::ZarrDataset, T::Type{>:Missing}, varname, s, dimnames, attr; kwargs...)
# S = Base.nonmissingtype(T)
# add_var(p,S, varname, s, dimnames, attr; fill_value = defaultfillval(S), fill_as_missing=true, kwargs...)
# end

function add_var(p::ZarrDataset, T::Type, varname, s, dimnames, attr;
chunksize=s, kwargs...)
chunksize=s, fill_as_missing=false, kwargs...)
attr2 = merge(attr,Dict("_ARRAY_DIMENSIONS"=>reverse(collect(dimnames))))
za = zcreate(T, p.g, varname,s...;fill_as_missing=true,attrs=attr2,chunks=chunksize,kwargs...)
fv = get(attr,"_FillValue",get(attr,"missing_value",default_fillvalue(T)))
za = zcreate(T, p.g, varname,s...;fill_as_missing,attrs=attr2,chunks=chunksize,kwargs...)
za
end

Expand All @@ -40,6 +49,6 @@ backendlist[:zarr] = ZarrDataset
push!(backendregex, r"(.zarr$)|(.zarr/$)"=>ZarrDataset)

allow_parallel_write(::ZarrDataset) = true
allow_missings(::ZarrDataset) = true
allow_missings(::ZarrDataset) = false
to_dataset(g::ZGroup; kwargs...) = ZarrDataset(g)
iscompressed(a::ZArray{<:Any,<:Any,<:Compressor}) = true

0 comments on commit 08a352e

Please sign in to comment.