From 15657934716f0a4b623fcea5b564366d3496eb35 Mon Sep 17 00:00:00 2001 From: Fabian Gans Date: Thu, 26 Mar 2026 17:32:15 +0100 Subject: [PATCH 1/5] Fix newly introduced bug when opening Zarr arrays --- Project.toml | 2 +- ext/ZarrExt.jl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 7a5ee9c..86dff51 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "YAXArrayBase" uuid = "90b8fcef-0c2d-428d-9c56-5f86629e9d14" authors = ["Fabian Gans "] -version = "0.7.9" +version = "0.7.10" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" diff --git a/ext/ZarrExt.jl b/ext/ZarrExt.jl index 6dd8c35..79b2ae3 100644 --- a/ext/ZarrExt.jl +++ b/ext/ZarrExt.jl @@ -15,7 +15,10 @@ end struct ZarrDataset g::ZGroup end -function ZarrDataset(g::String; mode="r", path="", kwargs...) +function ZarrDataset(g::Union{String,ZGroup}; mode="r", path="", kwargs...) + if g isa ZGroup + return ZarrDataset(g) + end store = if endswith(g, "zip") ZipStore(ZipReader(SimpleFileDiskArray(g))) else From c3879d6673ce6c87913a429c6b72b96213035fdb Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Fri, 27 Mar 2026 15:09:29 +0100 Subject: [PATCH 2/5] Fix tests for zarr data and add test on to_dataset for Zgroup --- test/datasets.jl | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/datasets.jl b/test/datasets.jl index 4b19c9a..fd83470 100644 --- a/test/datasets.jl +++ b/test/datasets.jl @@ -64,17 +64,19 @@ end end @testset "Reading Zarr" begin -p = "gs://cmip6/CMIP6/HighResMIP/CMCC/CMCC-CM2-HR4/highresSST-present/r1i1p1f1/6hrPlev/psl/gn/v20170706/" +p = "https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr" +z = zopen(p) +ds_zopen = to_dataset(z) ds_zarr = to_dataset(p,driver=:zarr) +@test ds_zopen == ds_zarr vn = get_varnames(ds_zarr) -@test sort(vn) == ["lat", "lat_bnds", "lon", "lon_bnds", "psl", "time", "time_bnds"] -@test get_var_dims(ds_zarr, "psl") == ["lon", "lat", "time"] +@test sort(vn) == ["aerosol_optical_thickness_550", "air_temperature_2m", "bare_soil_evaporation", "burnt_area", "cot", "cth", "ctt", "evaporation", "evaporation_era5", "evaporative_stress", "gross_primary_productivity", "interception_loss", "kndvi", "lat", "latent_energy", "lon", "max_air_temperature_2m", "min_air_temperature_2m", "nbar_blue", "nbar_green", "nbar_nir", "nbar_red", "nbar_swir1", "nbar_swir2", "nbar_swir3", "ndvi", "net_ecosystem_exchange", "net_radiation", "nirv", "open_water_evaporation", "potential_evaporation", "precipitation_era5", "radiation_era5", "root_moisture", "sensible_heat", "sif_gome2_jj", "sif_gome2_pk", "sif_gosif", "sif_rtsif", "sm", "snow_sublimation", "surface_moisture", "terrestrial_ecosystem_respiration", "time", "transpiration"] +@test get_var_dims(ds_zarr, "sm") == ["lon", "lat", "time"] @test get_var_dims(ds_zarr, "time") == ["time"] -@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 get_var_attrs(ds_zarr,"sm")["long_name"] == "Volumetric Soil Moisture" +h = get_var_handle(ds_zarr, "air_temperature_2m") @test YAXArrayBase.iscompressed(h) -@test all(isapprox.(h[1:2,1:2,1], [99360.8 99334.9; 99360.8 99335.4])) +@test all(isapprox.(h[1:2,1:2,1], [-28.8662 -23.4534; -28.8041 -23.1681])) @test allow_parallel_write(ds_zarr) == true @test allow_missings(ds_zarr) == false end From 7e527f9caca63b6b368c23862c404bd9faf28c96 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Fri, 27 Mar 2026 15:18:57 +0100 Subject: [PATCH 3/5] Fix tests --- test/datasets.jl | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/test/datasets.jl b/test/datasets.jl index fd83470..66a3bd7 100644 --- a/test/datasets.jl +++ b/test/datasets.jl @@ -64,21 +64,19 @@ end end @testset "Reading Zarr" begin -p = "https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr" -z = zopen(p) -ds_zopen = to_dataset(z) -ds_zarr = to_dataset(p,driver=:zarr) -@test ds_zopen == ds_zarr -vn = get_varnames(ds_zarr) -@test sort(vn) == ["aerosol_optical_thickness_550", "air_temperature_2m", "bare_soil_evaporation", "burnt_area", "cot", "cth", "ctt", "evaporation", "evaporation_era5", "evaporative_stress", "gross_primary_productivity", "interception_loss", "kndvi", "lat", "latent_energy", "lon", "max_air_temperature_2m", "min_air_temperature_2m", "nbar_blue", "nbar_green", "nbar_nir", "nbar_red", "nbar_swir1", "nbar_swir2", "nbar_swir3", "ndvi", "net_ecosystem_exchange", "net_radiation", "nirv", "open_water_evaporation", "potential_evaporation", "precipitation_era5", "radiation_era5", "root_moisture", "sensible_heat", "sif_gome2_jj", "sif_gome2_pk", "sif_gosif", "sif_rtsif", "sm", "snow_sublimation", "surface_moisture", "terrestrial_ecosystem_respiration", "time", "transpiration"] -@test get_var_dims(ds_zarr, "sm") == ["lon", "lat", "time"] -@test get_var_dims(ds_zarr, "time") == ["time"] -@test get_var_attrs(ds_zarr,"sm")["long_name"] == "Volumetric Soil Moisture" -h = get_var_handle(ds_zarr, "air_temperature_2m") -@test YAXArrayBase.iscompressed(h) -@test all(isapprox.(h[1:2,1:2,1], [-28.8662 -23.4534; -28.8041 -23.1681])) -@test allow_parallel_write(ds_zarr) == true -@test allow_missings(ds_zarr) == false + p = "https://s3.bgc-jena.mpg.de:9000/esdl-esdc-v3.0.2/esdc-16d-2.5deg-46x72x1440-3.0.2.zarr" + for ds_zarr in [to_dataset(p,driver=:zarr), to_dataset(zopen(p))] + vn = get_varnames(ds_zarr) + @test sort(vn) == ["aerosol_optical_thickness_550", "air_temperature_2m", "bare_soil_evaporation", "burnt_area", "cot", "cth", "ctt", "evaporation", "evaporation_era5", "evaporative_stress", "gross_primary_productivity", "interception_loss", "kndvi", "lat", "latent_energy", "lon", "max_air_temperature_2m", "min_air_temperature_2m", "nbar_blue", "nbar_green", "nbar_nir", "nbar_red", "nbar_swir1", "nbar_swir2", "nbar_swir3", "ndvi", "net_ecosystem_exchange", "net_radiation", "nirv", "open_water_evaporation", "potential_evaporation", "precipitation_era5", "radiation_era5", "root_moisture", "sensible_heat", "sif_gome2_jj", "sif_gome2_pk", "sif_gosif", "sif_rtsif", "sm", "snow_sublimation", "surface_moisture", "terrestrial_ecosystem_respiration", "time", "transpiration"] + @test get_var_dims(ds_zarr, "sm") == ["lon", "lat", "time"] + @test get_var_dims(ds_zarr, "time") == ["time"] + @test get_var_attrs(ds_zarr,"sm")["long_name"] == "Volumetric Soil Moisture" + h = get_var_handle(ds_zarr, "air_temperature_2m") + @test YAXArrayBase.iscompressed(h) + @test all(isapprox.(h[1:2,1:2,1], [-28.8662 -23.4534; -28.8041 -23.1681])) + @test allow_parallel_write(ds_zarr) == true + @test allow_missings(ds_zarr) == false + end end @testset "Reading ArchGDAL" begin using ArchGDAL From 0562453c606bf381825afc84b86f9482d81a10a7 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Mon, 30 Mar 2026 16:46:44 +0200 Subject: [PATCH 4/5] Test rational writing only for zarr --- Project.toml | 2 +- test/datasets.jl | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 86dff51..b86aa38 100644 --- a/Project.toml +++ b/Project.toml @@ -14,7 +14,7 @@ julia = "1.9" ArchGDAL = "0.10" AxisArrays = "0.4" AxisKeys = "0.2" -DimensionalData = "0.27, 0.28, 0.29" +DimensionalData = "0.27, 0.28, 0.29, 0.30" NetCDF = "0.11, 0.12" Zarr = "0.8, 0.9" diff --git a/test/datasets.jl b/test/datasets.jl index 66a3bd7..1629c8a 100644 --- a/test/datasets.jl +++ b/test/datasets.jl @@ -99,9 +99,14 @@ function test_write(T) add_var(ds, 0.5:1:9.5, "lon", ("lon",), Dict("units"=>"degrees_east")) add_var(ds, 20:-1.0:1, "lat", ("lat",), Dict("units"=>"degrees_north")) v = add_var(ds, Float32, "tas", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius")) - w = add_var(ds, Rational{Int}, "tas2", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius")) + if T isa YAXArrayBase.backendlist[:zarr] + w = add_var(ds, Rational{Int}, "tas2", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius")) + w[:,:] = collect(reshape(1:200, 10, 20)) .// 2 + w = get_var_handle(ds, "tas2") + @test w[1:2,1:2] == [1 11; 2 12] .// 2 + end v[:,:] = collect(reshape(1:200, 10, 20)) - w[:,:] = collect(reshape(1:200, 10, 20)) .// 2 + @test sort(get_varnames(ds)) == ["lat","lon","tas", "tas2"] @test get_var_dims(ds, "tas") == ["lon", "lat"] @test get_var_dims(ds, "lon") == ["lon"] From 49e0947a0b36c9f39f805705632b4a921076e3eb Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Mon, 30 Mar 2026 17:04:22 +0200 Subject: [PATCH 5/5] Fix rational test --- test/datasets.jl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/test/datasets.jl b/test/datasets.jl index 1629c8a..e4b4f9e 100644 --- a/test/datasets.jl +++ b/test/datasets.jl @@ -99,15 +99,20 @@ function test_write(T) add_var(ds, 0.5:1:9.5, "lon", ("lon",), Dict("units"=>"degrees_east")) add_var(ds, 20:-1.0:1, "lat", ("lat",), Dict("units"=>"degrees_north")) v = add_var(ds, Float32, "tas", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius")) - if T isa YAXArrayBase.backendlist[:zarr] + # This is needed, since netcdf can not write rationals. + if T == YAXArrayBase.backendlist[:zarr] w = add_var(ds, Rational{Int}, "tas2", (10,20), ("lon", "lat"), Dict{String,Any}("units"=>"Celsius")) w[:,:] = collect(reshape(1:200, 10, 20)) .// 2 w = get_var_handle(ds, "tas2") @test w[1:2,1:2] == [1 11; 2 12] .// 2 + w = get_var_handle(ds, "tas2") + @test w[1:2,1:2] == [1 11; 2 12] .// 2 + @test sort(get_varnames(ds)) == ["lat","lon","tas", "tas2"] + else + @test sort(get_varnames(ds)) == ["lat","lon","tas"] end v[:,:] = collect(reshape(1:200, 10, 20)) - @test sort(get_varnames(ds)) == ["lat","lon","tas", "tas2"] @test get_var_dims(ds, "tas") == ["lon", "lat"] @test get_var_dims(ds, "lon") == ["lon"] @test get_var_attrs(ds,"tas")["units"] == "Celsius" @@ -115,8 +120,6 @@ function test_write(T) @test h[:] == 0.5:1:9.5 v = get_var_handle(ds, "tas") @test v[1:2,1:2] == [1 11; 2 12] - w = get_var_handle(ds, "tas2") - @test w[1:2,1:2] == [1 11; 2 12] .// 2 end @testset "Writing NetCDF" begin