From 241b36a10842e11c1ebdabd9614df09e2cd63093 Mon Sep 17 00:00:00 2001 From: meggart Date: Mon, 29 Nov 2021 14:07:14 +0100 Subject: [PATCH] Make compression of netcdf and zarr discoverable in interface --- Project.toml | 2 +- src/datasets/netcdf.jl | 1 + src/datasets/zarr.jl | 3 ++- test/datasets.jl | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index d616c58..1f141f9 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "YAXArrayBase" uuid = "90b8fcef-0c2d-428d-9c56-5f86629e9d14" authors = ["Fabian Gans "] -version = "0.3.0" +version = "0.3.1" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" diff --git a/src/datasets/netcdf.jl b/src/datasets/netcdf.jl index 332149c..92476c5 100644 --- a/src/datasets/netcdf.jl +++ b/src/datasets/netcdf.jl @@ -32,6 +32,7 @@ end end writeblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...) = NetCDF.open(a->writeblock!(a,aout,r...), v.filename, v.varname, mode=NC_WRITE) readblock!(v::NetCDFVariable, aout, r::AbstractUnitRange...) = NetCDF.open(a->readblock!(a,aout,r...), v.filename, v.varname) +iscompressed(v::NetCDFVariable) = NetCDF.open(v->v.compress > 0, v.filename, v.varname) Base.size(v::NetCDFVariable) = v.size diff --git a/src/datasets/zarr.jl b/src/datasets/zarr.jl index 5dec705..2a36933 100644 --- a/src/datasets/zarr.jl +++ b/src/datasets/zarr.jl @@ -1,5 +1,5 @@ using .Zarr: ZArray, ZGroup, zgroup, zcreate, -to_zarrtype, zopen +to_zarrtype, zopen, Compressor struct ZarrDataset g::ZGroup @@ -42,3 +42,4 @@ push!(backendregex, r"(.zarr$)|(.zarr/$)"=>ZarrDataset) allow_parallel_write(::ZarrDataset) = true allow_missings(::ZarrDataset) = true to_dataset(g::ZGroup; kwargs...) = ZarrDataset(g) +iscompressed(a::ZArray{<:Any,<:Any,<:Compressor}) = true \ No newline at end of file diff --git a/test/datasets.jl b/test/datasets.jl index 9de076f..741a468 100644 --- a/test/datasets.jl +++ b/test/datasets.jl @@ -16,6 +16,7 @@ vn = get_varnames(ds_nc) @test get_var_dims(ds_nc, "time_bnds") == ["bnds", "time"] @test get_var_attrs(ds_nc,"tas")["long_name"] == "air_temperature" h = get_var_handle(ds_nc, "tas") +@test !YAXArrayBase.iscompressed(h) @test all(isapprox.(h[1:2,1:2], [215.893 217.168; 215.805 217.03])) @test allow_parallel_write(ds_nc) == false @test allow_missings(ds_nc) == false @@ -31,6 +32,7 @@ vn = get_varnames(ds_zarr) @test get_var_dims(ds_zarr, "time_bnds") == ["bnds", "time"] @test get_var_attrs(ds_zarr,"psl")["long_name"] == "Sea Level Pressure" h = get_var_handle(ds_zarr, "psl") +@test YAXArrayBase.iscompressed(h) @test all(isapprox.(h[1:2,1:2,1], [99360.8 99334.9; 99360.8 99335.4])) @test allow_parallel_write(ds_zarr) == true @test allow_missings(ds_zarr) == true