From 149dc8af19e3500268bf3f21e4f798a3fb232654 Mon Sep 17 00:00:00 2001 From: Lazaro Alonso Date: Tue, 12 Mar 2024 21:41:47 +0100 Subject: [PATCH] groupby example --- docs/src/.vitepress/config.mts | 7 +++- docs/src/.vitepress/theme/style.css | 55 ++++++++++++++++++++------- docs/src/UserGuide/group_by.md | 28 +++++++------- docs/src/components/AsideTrustees.vue | 2 +- docs/src/contributors.md | 2 +- docs/src/index.md | 2 +- 6 files changed, 63 insertions(+), 33 deletions(-) diff --git a/docs/src/.vitepress/config.mts b/docs/src/.vitepress/config.mts index 62ca0b69..ecbd8e84 100644 --- a/docs/src/.vitepress/config.mts +++ b/docs/src/.vitepress/config.mts @@ -43,6 +43,7 @@ export default defineConfig({ { text: 'Setting chunks size', link: '/UserGuide/setchuncks' }, { text: 'Apply functions on YAXArrays', link: '/UserGuide/applyfunctions' }, { text: 'Create Cube from function', link: '/UserGuide/create_cube_from_function' }, + { text: 'Group by', link: '/UserGuide/group_by' }, { text: 'Distributed computing', link: '/UserGuide/distributed' }, { text: 'Open NetCDF', link: '/UserGuide/openNetCDF' }, { text: 'Open Zarr (Store)', link: '/UserGuide/openZarr' }, @@ -64,7 +65,8 @@ export default defineConfig({ { text: 'How do I?', items: [ { text: 'How do I ...', link: '/HowdoI/howdoi' }, - { text: 'Contribute to docs', link: '/HowdoI/contribute' } + { text: 'Contribute to docs', link: '/HowdoI/contribute' }, + { text: 'Contributors', link: '/contributors' } ]}, ], @@ -78,6 +80,7 @@ export default defineConfig({ { text: 'Setting chunks size', link: '/UserGuide/setchuncks' }, { text: 'Apply functions on YAXArrays', link: '/UserGuide/applyfunctions' }, { text: 'Create Cube from function', link: '/UserGuide/create_cube_from_function' }, + { text: 'Group by', link: '/UserGuide/group_by' }, { text: 'Distributed computing', link: '/UserGuide/distributed' }, { text: 'Open NetCDF', link: '/UserGuide/openNetCDF' }, { text: 'Open Zarr (Store)', link: '/UserGuide/openZarr' }, @@ -91,7 +94,7 @@ export default defineConfig({ { text: 'How do I?', items: [ { text: 'How do I ...', link: '/HowdoI/howdoi' }, - { text: 'Contribute to docs', link: '/HowdoI/contribute' } + { text: 'Contribute to docs', link: '/HowdoI/contribute' }, ]}, { text: 'Contributors', link: '/contributors' }, { text: 'API', diff --git a/docs/src/.vitepress/theme/style.css b/docs/src/.vitepress/theme/style.css index 83967bdd..cbc881a0 100644 --- a/docs/src/.vitepress/theme/style.css +++ b/docs/src/.vitepress/theme/style.css @@ -1,26 +1,53 @@ -@import url(https://fonts.googleapis.com/css?family=Space+Mono:regular,italic,700,700italic); -@import url(https://fonts.googleapis.com/css?family=Space+Grotesk:regular,italic,700,700italic); - -/** - * Customize default theme styling by overriding CSS variables: - * https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css +/* Customize default theme styling by overriding CSS variables: +https://github.com/vuejs/vitepress/blob/main/src/client/theme-default/styles/vars.css */ -/** - * Fonts - * -------------------------------------------------------------------------- - */ -:root { + /* Layouts */ + +/* + :root { + --vp-layout-max-width: 1440px; +} */ + +.VPHero .clip { + white-space: pre; + max-width: 500px; +} + +/* Fonts */ + +@font-face { + font-family: JuliaMono-Regular; + src: url("https://cdn.jsdelivr.net/gh/cormullion/juliamono/webfonts/JuliaMono-Regular.woff2"); +} + + :root { /* Typography */ - --vp-font-family-base: "Space Grotesk", "Inter var experimental", "Inter var", + --vp-font-family-base: "Barlow", "Inter var experimental", "Inter var", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; /* Code Snippet font */ - --vp-font-family-mono: "Space Mono", Menlo, Monaco, Consolas, "Courier New", - monospace; + --vp-font-family-mono: JuliaMono-Regular, monospace; + +} + +.mono { + /* + Disable contextual alternates (kind of like ligatures but different) in monospace, + which turns `/>` to an up arrow and `|>` (the Julia pipe symbol) to an up arrow as well. + This is pretty bad for Julia folks reading even though copy+paste retains the same text. + */ + font-feature-settings: 'calt' 0; + pre { + font-family: JuliaMono-Light; +}; +code { + font-family: JuliaMono-Light; + }; } + /** * Colors For inspiration visit diff --git a/docs/src/UserGuide/group_by.md b/docs/src/UserGuide/group_by.md index 1eff2704..b63787cb 100644 --- a/docs/src/UserGuide/group_by.md +++ b/docs/src/UserGuide/group_by.md @@ -1,6 +1,6 @@ # GroupBy -The next examples will use the `groupby` function to calculate temporal and spatial averages. +The following examples will use the `groupby` function to calculate temporal and spatial averages. ````@example compareXarray using YAXArrays, DimensionalData @@ -27,7 +27,7 @@ nothing # hide ::: warning -The following rebuild should not be necessary in the future, plus is unpractical to use for large data sets. Support for out of memory data is not available yet. +The following rebuild should not be necessary in the future, plus is unpractical to use for large data sets. Out of memory groupby currently is work in progress. Related to https://github.com/rafaqz/DimensionalData.jl/issues/642 ::: @@ -45,18 +45,18 @@ nothing # hide ## GroupBy: seasons -::: details function weighted_season(ds) ... end +::: details function weighted_seasons(ds) ... end ````julia -function weighted_season(ds) +function weighted_seasons(ds) # calculate weights tempo = dims(ds, :Ti) month_length = YAXArray((tempo,), daysinmonth.(tempo)) - g_tempo = groupby(month_length, Ti => season(; start=December)) + g_tempo = groupby(month_length, Ti => seasons(; start=December)) sum_days = sum.(g_tempo, dims=:Ti) weights = map(./, g_tempo, sum_days) # unweighted seasons - g_ds = groupby(ds, Ti => season(; start=December)) + g_ds = groupby(ds, Ti => seasons(; start=December)) mean_g = mean.(g_ds, dims=:Ti) mean_g = dropdims.(mean_g, dims=:Ti) # weighted seasons @@ -65,8 +65,8 @@ function weighted_season(ds) weighted_g = dropdims.(weighted_g, dims=:Ti) # differences diff_g = map(.-, weighted_g, mean_g) - seasons = lookup(mean_g, :Ti) - return mean_g, weighted_g, diff_g, seasons + seasons_g = lookup(mean_g, :Ti) + return mean_g, weighted_g, diff_g, seasons_g end ```` ::: @@ -74,7 +74,7 @@ end Now, we continue with the `groupby` operations as usual ````@ansi compareXarray -g_ds = groupby(ds, Ti => season(; start=December)) +g_ds = groupby(ds, Ti => seasons(; start=December)) ```` And the mean per season is calculated as follows @@ -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 = lookup(mean_g, :Ti) +seasons_g = lookup(mean_g, :Ti) ```` Next, we will weight this grouping by days/month in each group. @@ -113,7 +113,7 @@ month_length = YAXArray((tempo,), daysinmonth.(tempo)) Now group it by season ````@ansi compareXarray -g_tempo = groupby(month_length, Ti => season(; start=December)) +g_tempo = groupby(month_length, Ti => seasons(; start=December)) ```` Get the number of days per season @@ -159,7 +159,7 @@ diff_g = map(.-, weighted_g, mean_g) All the previous steps are equivalent to calling the function defined at the top: ````julia -mean_g, weighted_g, diff_g, seasons = weighted_season(ds) +mean_g, weighted_g, diff_g, seasons_g = weighted_seasons(ds) ```` Once all calculations are done we can plot the results with `Makie.jl` as follows: @@ -180,7 +180,7 @@ with_theme(theme_ggplot2()) do # the figure 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) + 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, @@ -190,7 +190,7 @@ with_theme(theme_ggplot2()) do Colorbar(fig[3,5], hm_d, label="Tair") hidedecorations!.(axs, grid=false, ticks=false, label=false) # some labels - [axs[1,j].title = string.(s) for (j,s) in enumerate(seasons)] + [axs[1,j].title = string.(s) for (j,s) in enumerate(seasons_g)] Label(fig[0,1:5], "Seasonal Surface Air Temperature", fontsize=18, font=:bold) axs[1,1].ylabel = "Unweighted" axs[2,1].ylabel = "Weighted" diff --git a/docs/src/components/AsideTrustees.vue b/docs/src/components/AsideTrustees.vue index 67989e03..836a6a86 100644 --- a/docs/src/components/AsideTrustees.vue +++ b/docs/src/components/AsideTrustees.vue @@ -1,6 +1,6 @@