Skip to content

Commit

Permalink
adds dims
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarusA committed Dec 15, 2024
1 parent 273b8c9 commit 7c99072
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
9 changes: 5 additions & 4 deletions docs/src/UserGuide/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The following examples will use the `groupby` function to calculate temporal and

````@example compareXarray
using YAXArrays, DimensionalData
using YAXArrays: YAXArrays as YAX
using NetCDF
using Downloads
using Dates
Expand Down Expand Up @@ -52,11 +53,11 @@ function weighted_seasons(ds)
# calculate weights
tempo = dims(ds, :time)
month_length = YAXArray((tempo,), daysinmonth.(tempo))
g_tempo = groupby(month_length, Dim{:time} => seasons(; start=December))
g_tempo = groupby(month_length, YAX.time => seasons(; start=December))
sum_days = sum.(g_tempo, dims=:time)
weights = map(./, g_tempo, sum_days)
# unweighted seasons
g_ds = groupby(ds, Dim{:time} => seasons(; start=December))
g_ds = groupby(ds, YAX.time => seasons(; start=December))
mean_g = mean.(g_ds, dims=:time)
mean_g = dropdims.(mean_g, dims=:time)
# weighted seasons
Expand All @@ -74,7 +75,7 @@ end
Now, we continue with the `groupby` operations as usual

````@ansi compareXarray
g_ds = groupby(ds, Dim{:time} => seasons(; start=December))
g_ds = groupby(ds, YAX.time => seasons(; start=December))
````

And the mean per season is calculated as follows
Expand Down Expand Up @@ -113,7 +114,7 @@ month_length = YAXArray((tempo,), daysinmonth.(tempo))
Now group it by season

````@ansi compareXarray
g_tempo = groupby(month_length, Dim{:time} => seasons(; start=December))
g_tempo = groupby(month_length, YAX.time => seasons(; start=December))
````

Get the number of days per season
Expand Down
2 changes: 1 addition & 1 deletion src/YAXArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ recalculate() = YAXDefaults.recal[]
YAXdir() = YAXDefaults.workdir[]
export YAXdir
include("helpers.jl")

include("dims.jl")
include("YAXTools.jl")
include("Cubes/Cubes.jl")
include("DatasetAPI/Datasets.jl")
Expand Down
28 changes: 28 additions & 0 deletions src/dims.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using DimensionalData: @dim, YDim, XDim, ZDim, TimeDim
export Lat, lat, latitude, Latitude
export rlat, lat_c
export Lon, lon, longitude, long, Longitude
export rlon, lon_c
export height, depth

@dim Lat YDim "Latitude"
@dim lat YDim "Latitude"
@dim latitude YDim "Latitude"
@dim Latitude YDim "Latitude"
@dim rlat YDim
@dim lat_c YDim

@dim Lon XDim "Longitude"
@dim lon XDim "Longitude"
@dim long XDim "Longitude"
@dim longitude XDim "Longitude"
@dim Longitude XDim "Longitude"
@dim rlon XDim
@dim lon_c XDim

@dim height ZDim
@dim depth ZDim

@dim time TimeDim "time"
@dim Time TimeDim "time"

0 comments on commit 7c99072

Please sign in to comment.