diff --git a/docs/src/UserGuide/group.md b/docs/src/UserGuide/group.md index 389efbe0..4101e21e 100644 --- a/docs/src/UserGuide/group.md +++ b/docs/src/UserGuide/group.md @@ -50,22 +50,22 @@ nothing # hide ````julia function weighted_seasons(ds) # calculate weights - tempo = dims(ds, :Ti) + tempo = dims(ds, :time) month_length = YAXArray((tempo,), daysinmonth.(tempo)) - g_tempo = groupby(month_length, Ti => seasons(; start=December)) - sum_days = sum.(g_tempo, dims=:Ti) + g_tempo = groupby(month_length, Dim{:time} => seasons(; start=December)) + sum_days = sum.(g_tempo, dims=:time) weights = map(./, g_tempo, sum_days) # unweighted seasons - g_ds = groupby(ds, Ti => seasons(; start=December)) - mean_g = mean.(g_ds, dims=:Ti) - mean_g = dropdims.(mean_g, dims=:Ti) + g_ds = groupby(ds, Dim{:time} => seasons(; start=December)) + mean_g = mean.(g_ds, dims=:time) + mean_g = dropdims.(mean_g, dims=:time) # weighted seasons g_dsW = broadcast_dims.(*, weights, g_ds) - weighted_g = sum.(g_dsW, dims = :Ti); - weighted_g = dropdims.(weighted_g, dims=:Ti) + weighted_g = sum.(g_dsW, dims = :time); + weighted_g = dropdims.(weighted_g, dims=:time) # differences diff_g = map(.-, weighted_g, mean_g) - seasons_g = lookup(mean_g, :Ti) + seasons_g = lookup(mean_g, :time) return mean_g, weighted_g, diff_g, seasons_g end ```` @@ -74,13 +74,13 @@ end Now, we continue with the `groupby` operations as usual ````@ansi compareXarray -g_ds = groupby(ds, Ti => seasons(; start=December)) +g_ds = groupby(ds, Dim{:time} => seasons(; start=December)) ```` And the mean per season is calculated as follows ````@ansi compareXarray -mean_g = mean.(g_ds, dims=:Ti) +mean_g = mean.(g_ds, dims=:time) ```` ### dropdims @@ -88,7 +88,7 @@ mean_g = mean.(g_ds, dims=:Ti) Note that now the time dimension has length one, we can use `dropdims` to remove it ````@ansi compareXarray -mean_g = dropdims.(mean_g, dims=:Ti) +mean_g = dropdims.(mean_g, dims=:time) ```` ### seasons @@ -96,7 +96,7 @@ mean_g = dropdims.(mean_g, dims=:Ti) Due to the `groupby` function we will obtain new grouping names, in this case in the time dimension: ````@example compareXarray -seasons_g = lookup(mean_g, :Ti) +seasons_g = lookup(mean_g, :time) ```` Next, we will weight this grouping by days/month in each group. @@ -106,20 +106,20 @@ Next, we will weight this grouping by days/month in each group. Create a `YAXArray` for the month length ````@example compareXarray -tempo = dims(ds, :Ti) +tempo = dims(ds, :time) month_length = YAXArray((tempo,), daysinmonth.(tempo)) ```` Now group it by season ````@ansi compareXarray -g_tempo = groupby(month_length, Ti => seasons(; start=December)) +g_tempo = groupby(month_length, Dim{:time} => seasons(; start=December)) ```` Get the number of days per season ````@ansi compareXarray -sum_days = sum.(g_tempo, dims=:Ti) +sum_days = sum.(g_tempo, dims=:time) ```` ### weights @@ -146,8 +146,8 @@ g_dsW = broadcast_dims.(*, weights, g_ds) apply a `sum` over the time dimension and drop it ````@ansi compareXarray -weighted_g = sum.(g_dsW, dims = :Ti); -weighted_g = dropdims.(weighted_g, dims=:Ti) +weighted_g = sum.(g_dsW, dims = :time); +weighted_g = dropdims.(weighted_g, dims=:time) ```` Calculate the differences @@ -181,9 +181,9 @@ with_theme(theme_ggplot2()) do fig = Figure(; size = (850,500)) axs = [Axis(fig[i,j], aspect=DataAspect()) for i in 1:3, j in 1:4] for (j, s) in enumerate(seasons_g) - hm_o = heatmap!(axs[1,j], mean_g[Ti=At(s)]; colorrange, lowclip, highclip, colormap) - hm_w = heatmap!(axs[2,j], weighted_g[Ti=At(s)]; colorrange, lowclip, highclip, colormap) - hm_d = heatmap!(axs[3,j], diff_g[Ti=At(s)]; colorrange=(-0.1,0.1), lowclip, highclip, + hm_o = heatmap!(axs[1,j], mean_g[time=At(s)]; colorrange, lowclip, highclip, colormap) + hm_w = heatmap!(axs[2,j], weighted_g[time=At(s)]; colorrange, lowclip, highclip, colormap) + hm_d = heatmap!(axs[3,j], diff_g[time=At(s)]; colorrange=(-0.1,0.1), lowclip, highclip, colormap=:diverging_bwr_20_95_c54_n256) end Colorbar(fig[1:2,5], hm_o, label=cb_label) diff --git a/src/Cubes/Cubes.jl b/src/Cubes/Cubes.jl index 6487b718..ac1c2e6a 100644 --- a/src/Cubes/Cubes.jl +++ b/src/Cubes/Cubes.jl @@ -480,14 +480,7 @@ function Base.getindex(a::YAXArray, args::DD.Dimension...; kwargs...) for (k,v) in kwargsdict d = getAxis(k,a) if d !== nothing - if d isa DD.Ti - if v isa UnitRange{Int} - v = Date(first(v))..Date(last(v),12,31) - end - d2[:Ti] = v - else - d2[DD.name(d)] = v - end + d2[DD.name(d)] = v else d2[k] = v end diff --git a/src/DatasetAPI/Datasets.jl b/src/DatasetAPI/Datasets.jl index 7a4bcf68..e3de1f1f 100644 --- a/src/DatasetAPI/Datasets.jl +++ b/src/DatasetAPI/Datasets.jl @@ -285,7 +285,7 @@ function toaxis(dimname, g, offs, len) catch ar[:] end - DD.Ti(tsteps[offs+1:end]) + DD.rebuild(DD.name2dim(axname), tsteps[offs+1:end]) elseif haskey(aratts, "_ARRAYVALUES") vals = identity.(aratts["_ARRAYVALUES"]) DD.rebuild(DD.name2dim(axname),(vals)) diff --git a/test/Datasets/datasets.jl b/test/Datasets/datasets.jl index 67e31d09..21493d21 100644 --- a/test/Datasets/datasets.jl +++ b/test/Datasets/datasets.jl @@ -24,7 +24,7 @@ using Dates YAXArray(axlist2, data[3], props[3]), ) ds = Dataset(avar=c1, something=c2, smaller=c3) - # previous version will throw this error: `KeyError: key :Ti not found` + # previous version will throw this error: `KeyError: key :time not found` f = "./temp.zarr" @test_nowarn savedataset(ds; path=f) rm(f, recursive=true, force=true) @@ -215,11 +215,11 @@ end ds = open_dataset("test.mock") @test size(ds.Var1) == (10, 5, 2) @test size(ds.Var2) == (10, 5) - @test all(in(keys(ds.axes)), (:Ti, :d2, :d3)) + @test all(in(keys(ds.axes)), (:time, :d2, :d3)) ar = Cube(ds) @test ar isa YAXArray @test size(ar) == (10, 5, 2, 2) - @test DD.name.(ar.axes) == (:Ti, :d2, :d3, :Variable) + @test DD.name.(ar.axes) == (:time, :d2, :d3, :Variable) @test DD.lookup(ar.axes[4]) == ["Var1", "Var3"] end @testset "Dataset creation" begin