Skip to content

Commit

Permalink
contributors
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarusA committed Feb 22, 2024
1 parent 97b7fb8 commit c57f2e9
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 38 deletions.
1 change: 1 addition & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"
GeoMakie = "db073c08-6b98-4ee5-b6a4-5efafb3259c6"
GitHub = "bc5e4493-9b4d-5f90-b8aa-2b2bcaad7a26"
IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
Expand Down
1 change: 1 addition & 0 deletions docs/src/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default defineConfig({
{ text: 'How do I ...', link: '/HowdoI/howdoi' },
{ text: 'Contribute to docs', link: '/HowdoI/contribute' }
]},
{ text: 'Contributors', link: '/contributors' },
{ text: 'API',
items: [
{ text: 'API Reference', link: 'api' },
Expand Down
6 changes: 3 additions & 3 deletions docs/src/UserGuide/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ using Downloads
using Dates
using Statistics
using GLMakie

# url_path = "https://github.com/pydata/xarray-data/blob/master/"
# filename = Downloads.download(url_path, "rasm.nc")
#ds = Cube(filename)
Expand Down Expand Up @@ -38,15 +39,14 @@ weights = map(./, g_tempo, sum_days)
# verify that the sum per season is 1.
sum.(weights)

# None of this work, they hang forever. # reading a million times the file, related to the othe issue? about indexing.
g_dsW = broadcast_dims.(*, weights, g_ds) #
weighted_g = sum.(g_dsW, dims = :Ti)
weighted_g = sum.(g_dsW, dims = :Ti)
# and lets drop the Time dimension
weighted_g = dropdims.(weighted_g, dims=:Ti)

ds_diff = map(.-, weighted_g, mean_g)

# plot arguments/attributes
# define plot arguments/attributes
colorrange = (-30,30)
colormap = Reverse(:Spectral)
highclip = :red
Expand Down
20 changes: 20 additions & 0 deletions docs/src/UserGuide/contributors.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using GitHub

function getavatars(; n = 90)
contri = GitHub.contributors("JuliaDataCubes/YAXArrays.jl")[1]
avatars = []
contributions = []
urls = []
for i in eachindex(contri)
push!(avatars, contri[i]["contributor"].avatar_url.uri)
push!(contributions, contri[i]["contributions"])
push!(urls, contri[i]["contributor"].html_url.uri)
end
p = sortperm(contributions, rev=true)
return avatars[p], urls[p]
end

avatars, urls = getavatars(; n = 90)
for (i,a) in enumerate(avatars)
println("""<a href="$(urls[i])" target="_blank"><img src="$(a)"></a>""")
end
193 changes: 170 additions & 23 deletions docs/src/UserGuide/group_by.md
Original file line number Diff line number Diff line change
@@ -1,57 +1,204 @@
# GroupBy
In the following example we will use the `groupby` function to calculate temporal and spatial averages.

````@example groupby
The following examples will use the `groupby` function to calculate temporal and spatial averages.

````@example compareXarray
using YAXArrays, DimensionalData
using NetCDF
using Downloads
using Dates
using Statistics
````

````@example compare_with_xarray
url_path = "https://github.com/pydata/xarray-data/blob/master/"
### Seasonal Averages from Time Series of Monthly Means

The following reproduces the example in [xarray](https://docs.xarray.dev/en/stable/examples/monthly-means.html) by [Joe Hamman](https://github.com/jhamman/).

Where the goal is to calculate the seasonal average. And in order to do this properly, is necessary to calculate the weighted average considering that each month has a different number of days.

### Download the data

````@example compareXarray
url_path = "https://github.com/pydata/xarray-data/raw/master/rasm.nc"
filename = Downloads.download(url_path, "rasm.nc")
ds = Cube(filename)
ds_o = Cube(filename)
nothing # hide
````

````@example compare_with_xarray
g = groupby(ds, Ti => season(; start=December))
m_g = mean.(g, dims=:Ti)
dropdims.(m_g, dims=:Ti)
````
::: warning

# Create a named array for the month length
The following rebuild should not be necessary in the next release, plus is unpractical to use for large data sets.
Related to https://github.com/rafaqz/DimensionalData.jl/issues/642

````@example compare_with_xarray
tempo = dims(ds, :Ti)
month_length = YAXArray((tempo,), daysinmonth.(tempo))
:::

````@example compareXarray
axs = dims(ds_o) # get the dimensions
data = ds_o.data[:,:,:] # read the data
_FillValue = ds_o.properties["_FillValue"]
data = replace(data, _FillValue => NaN)
# create new YAXArray
ds = YAXArray(axs, data)
nothing # hide
````

::: info
## GroupBy: seasons

The same is possible with a pure DimArray, namely
::: details function weighted_season(ds) ... end

````julia
month_length = DimArray(daysinmonth.(tempo), (tempo))
function weighted_season(ds)
# calculate weights
tempo = dims(ds, :Ti)
month_length = YAXArray((tempo,), daysinmonth.(tempo))
g_tempo = groupby(month_length, Ti => season(; 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))
mean_g = mean.(g_ds, dims=:Ti)
mean_g = dropdims.(mean_g, dims=:Ti)
# weighted seasons
g_dsW = broadcast_dims.(*, weights, g_ds)
weighted_g = sum.(g_dsW, dims = :Ti);
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
end
````

:::

Now, we continue with the `groupby` operations as usual

g_tempo = groupby(month_length, Ti => season(; start=December))
````@ansi compareXarray
g_ds = groupby(ds, Ti => season(; start=December))
````

sum_days = sum.(g_tempo, dims=:Ti)
And the mean per season is calculated as follows

````@ansi compareXarray
mean_g = mean.(g_ds, dims=:Ti)
````

### dropdims

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)
````

### seasons

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)
````

Next, we will weight this grouping by days/month in each group.

## GroupBy: weight

Create a `YAXArray` for the month length

```julia
````@example compareXarray
tempo = dims(ds, :Ti)
month_length = YAXArray((tempo,), daysinmonth.(tempo))
````

Now group it by season

````@ansi compareXarray
g_tempo = groupby(month_length, Ti => season(; start=December))
````

Get the number of days per season

````@ansi compareXarray
sum_days = sum.(g_tempo, dims=:Ti)
````

### weights

Weight the seasonal groups by `sum_days`

````@ansi compareXarray
weights = map(./, g_tempo, sum_days)
````

Verify that the sum per season is 1

````@ansi compareXarray
sum.(weights)
````
### weighted seasons

g_ds = groupby(ds, Ti => season(; start=December))
Now, let's weight the seasons

````@ansi compareXarray
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)
````

Calculate the differences

````@ansi compareXarray
diff_g = map(.-, weighted_g, mean_g)
````
g_ds .* weights

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)
````

Once all calculations are done we can plot the results with `Makie.jl` as follows:

````@example compareXarray
using CairoMakie
# define plot arguments/attributes
colorrange = (-30,30)
colormap = Reverse(:Spectral)
highclip = :red
lowclip = :grey15
cb_label = ds_o.properties["long_name"]
````

````@example compareXarray
with_theme(theme_ggplot2()) do
hm_o, hm_d, hm_w = nothing, nothing, nothing
# 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)
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,
colormap=:diverging_bwr_20_95_c54_n256)
end
Colorbar(fig[1:2,5], hm_o, label=cb_label)
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)]
Label(fig[0,1:5], "Seasonal Surface Air Temperature", fontsize=18, font=:bold)
axs[1,1].ylabel = "Unweighted"
axs[2,1].ylabel = "Weighted"
axs[3,1].ylabel = "Difference"
colgap!(fig.layout, 5)
rowgap!(fig.layout, 5)
fig
end
````

which shows a good agreement with the results first published by [Joe Hamman](https://github.com/jhamman/).
56 changes: 44 additions & 12 deletions docs/src/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,14 @@ const coreMembers = [
}
]
const partners =[
{
avatar: 'https://www.github.com/yyx990803.png',
name: 'John',
title: 'Creator'
},
{
avatar: 'https://www.github.com/yyx990803.png',
name: 'Doe'
},
]
// const partners =[
// {
// avatar: 'https://www.github.com/yyx990803.png',
// },
// {
// avatar: 'https://www.github.com/yyx990803.png',
// },
// ]
</script>
<VPTeamPage>
Expand All @@ -76,11 +73,46 @@ const partners =[
<template #title>Our valuable contributors</template>
<template #lead>
We appreciate all contributions from the Julia community so that this ecosystem can thrive.<br>
(Add github list)
</template>
<template #members>
<!-- <VPTeamMembers size="small" :members="partners" /> -->
<div class="row">
<a href="https://github.com/meggart" target="_blank"><img src="https://avatars.githubusercontent.com/u/2539563?v=4"></a>
<a href="https://github.com/felixcremer" target="_blank"><img src="https://avatars.githubusercontent.com/u/17124431?v=4"></a>
<a href="https://github.com/lazarusA" target="_blank"><img src="https://avatars.githubusercontent.com/u/19525261?v=4"></a>
<a href="https://github.com/gdkrmr" target="_blank"><img src="https://avatars.githubusercontent.com/u/12512930?v=4"></a>
<a href="https://github.com/apps/github-actions" target="_blank"><img src="https://avatars.githubusercontent.com/in/15368?v=4"></a>
<a href="https://github.com/pdimens" target="_blank"><img src="https://avatars.githubusercontent.com/u/19176506?v=4"></a>
<a href="https://github.com/twinGu" target="_blank"><img src="https://avatars.githubusercontent.com/u/29449917?v=4"></a>
<a href="https://github.com/dpabon" target="_blank"><img src="https://avatars.githubusercontent.com/u/13040959?v=4"></a>
<a href="https://github.com/Qfl3x" target="_blank"><img src="https://avatars.githubusercontent.com/u/20775896?v=4"></a>
<a href="https://github.com/kongdd" target="_blank"><img src="https://avatars.githubusercontent.com/u/9815742?v=4"></a>
<a href="https://github.com/MartinuzziFrancesco" target="_blank"><img src="https://avatars.githubusercontent.com/u/10376688?v=4"></a>
<a href="https://github.com/Sonicious" target="_blank"><img src="https://avatars.githubusercontent.com/u/16307399?v=4"></a>
<a href="https://github.com/rafaqz" target="_blank"><img src="https://avatars.githubusercontent.com/u/2534009?v=4"></a>
<a href="https://github.com/danlooo" target="_blank"><img src="https://avatars.githubusercontent.com/u/5780565?v=4"></a>
<a href="https://github.com/MarkusZehner" target="_blank"><img src="https://avatars.githubusercontent.com/u/56972144?v=4"></a>
<a href="https://github.com/Balinus" target="_blank"><img src="https://avatars.githubusercontent.com/u/3630311?v=4"></a>
<a href="https://github.com/singularitti" target="_blank"><img src="https://avatars.githubusercontent.com/u/25192197?v=4"></a>
<a href="https://github.com/ckrich" target="_blank"><img src="https://avatars.githubusercontent.com/u/28727495?v=4"></a>
<a href="https://github.com/apps/femtocleaner" target="_blank"><img src="https://avatars.githubusercontent.com/in/4123?v=4"></a>
<a href="https://github.com/ikselven" target="_blank"><img src="https://avatars.githubusercontent.com/u/10441332?v=4"></a>
<a href="https://github.com/linamaes" target="_blank"><img src="https://avatars.githubusercontent.com/u/7131773?v=4"></a>
</div>
</template>
</VPTeamPageSection>
</VPTeamPage>
<style>
.row img {
border-radius: 50%;
width: 60px;
heigth: 60px;
}
.row {
display: flex;
flex-wrap: wrap;
padding: 0 4px;
}
</style>
```
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ features:
details: Well integrated with Julia's ecosystem, i.e., distributed operations are native. And plotting with <font color="#D27D2D">Makie.jl</font> is well supported.
- title: Named dimensions and GroupBy
details: Apply operations over named dimensions, select values by labels and integers as well as efficient split-apply-combine operations with <font color="#D27D2D">groupby</font> via DimensionalData.jl.
link: /UserGuide/group_by
- title: Efficiency
details: Efficient <font color="#D27D2D">mapslices(x) </font> and <font color="#D27D2D">mapCube</font> operations on huge multiple arrays, optimized for high-latency data access (object storage, compressed datasets).
```

0 comments on commit c57f2e9

Please sign in to comment.