Skip to content

Commit

Permalink
Create ensembles.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Balinus authored Sep 12, 2024
1 parent 334ef39 commit a7bcd92
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/ensembles.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
ensemble_stats(xout, xin)
Compute the daily maximum, mean, and minimum values from the input array `xin` and store the results in the output array `xout`.
# Arguments
- `xout::AbstractArray`: The output array where the computed values will be stored.
- `xin::AbstractArray`: The input array from which the values will be computed.
# Details
- The function replaces missing values in `xin` with `NaN` before computing the maximum, mean, and minimum values.
- The computed values are stored in `xout` as an array, where each row corresponds to a different index in `index_list`.
"""
function ensemble_stats(xout, xin)
xout .= NaN
if !all(ismissing, xin)
xout[1] = maximum(skipmissing(xin))
xout[2] = mean(skipmissing(xin))
xout[3] = minimum(skipmissing(xin))
end
end

"""
ensemble_stats(cube::YAXArray; dim="Ti")
Compute the maximum, mean, and minimum values from a YAXArray Cube along dimension `dim` (default to :Ti).
# Arguments
- `cube::YAXArray`: A Cube of data
- `dim::String`: The dimension along which to compute the statistics. Default is "Ti".
# Returns
- A Cube with maximum, mean and minimum values. The output cube has the following additional dimension:
- `stats`: max, mean and min
"""
function ensemble_stats(cube::YAXArray; dim="Ti")


# Dimensions
indims = InDims(dim)
# outdims = OutDims(RangeAxis("time", dates_builder_yearmonthday(new_dates)), CategoricalAxis("stats",["max","mean","min"]))
outdims = OutDims(Dim{:stats}(["max","mean","min"]))

mapCube(ensemble_stats, cube, indims=indims, outdims=outdims)
end

0 comments on commit a7bcd92

Please sign in to comment.