YAXArrays.jl
YAXArrays.jl copied to clipboard
collect examples for docs, distributed section
Please, let's collect some examples here that could be included in the Distributed section, which is currently mostly empty.
@felixcremer @TabeaW have some small ones already?
Unfortunately, distributed filling an empty/skeleton cube currently does not work. I have an easy example for a mapcube for monthly mean of 5-minute data that is hopefully right :D
using Distributed, Dates
addprocs(4)
@everywhere using YAXArrays, Zarr, Statistics
#open cube here
q=cube[Ti=Date(2018,1,1)..Date(2023,1,1)]
index_list=cumsum([0;[size(collect(x:Minute(5):x+Month(1)-Minute(5)),1) for x in DateTime(2018,1,1,0,0):Month(1):DateTime(2022,12,1,0,0)]])
@everywhere function do_fun(xout, xin; index_list = time_to_index)
xout .= NaN
for i in eachindex(index_list)[1:end-1]
xout[i] = mean(filter(!isnan, skipmissing(view(xin, index_list[i]+1:index_list[i+1]))))
end
end
monthly_mean=mapCube(do_fun,
q,
indims = InDims("Ti"),
outdims = OutDims(Dim{:Ti}(DateTime(2018,1,1,0,0):Month(1):DateTime(2022,12,1,0,0))),index_list=index_list)
savecube(monthly_mean, "monthly_mean.zarr"; backend=:zarr)