-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
""" | ||
ERA5Land_dailysum(xout, xin; index_list = time_to_index) | ||
Compute the daily sum of ERA5 land data. **used internally** | ||
# Arguments | ||
- `xout::AbstractArray`: Output array to store the computed daily sums. | ||
- `xin::AbstractArray`: Input array containing ERA5 land data. | ||
- `index_list::Function`: (optional) Function to convert time indices. | ||
# Details | ||
- The function computes the daily sum of ERA5 land data by doing first a diff operator and then summing the non-missing values in each day's data. | ||
- Missing values are represented as `missing` in the input array and are replaced with `NaN` before computation. | ||
""" | ||
function ERA5Land_dailysum(xout, xin; index_list = time_to_index) | ||
|
||
xout .= NaN | ||
if !all(ismissing, xin) | ||
for i in eachindex(index_list) | ||
data = view(xin, index_list[i]) | ||
if !all(ismissing, data) | ||
diffxin = Base.diff(replace(data, missing => NaN)) | ||
xout[i] = sum(.!isnan.(diffxin)) | ||
end | ||
end | ||
end | ||
end | ||
|
||
""" | ||
ERA5Land_dailysum(cube::YAXArray; keep_1stday=false, kwargs...) | ||
Process ERA5-Land data by converting it to daily resolution. The function applies a diff function and then a sum for daily accumulated values. | ||
# Arguments | ||
- `cube::YAXArray`: The input data cube. | ||
- `keep_1stday::Bool`: Whether to keep the first day of the data. Default is `false`. | ||
- `kwargs...`: Additional keyword arguments. | ||
# Returns | ||
- `cube::YAXArray`: The processed data cube. | ||
""" | ||
function ERA5Land_dailysum(cube::YAXArray; keep_1stday=false, kwargs...) | ||
|
||
# On veut des données quotidiennes pour ERA5-Land | ||
time_to_index = (cube.time .- Hour(1)) | ||
time_index = yearmonthday.(time_to_index) | ||
new_dates = unique(time_index) | ||
|
||
if keep_1stday | ||
firstindex = 1 | ||
else | ||
firstindex = 2 | ||
end | ||
index_in_cube = [findall(==(i), time_index) for i in unique(time_index)][firstindex:end] | ||
|
||
# Dimensions | ||
indims = InDims("Ti") | ||
# outdims = OutDims(RangeAxis("time", dates_builder_yearmonthday(new_dates[firstindex:end]))) | ||
outdims = OutDims(Dim{:Ti}(dates_builder_yearmonthday(new_dates[firstindex:end]))) | ||
|
||
return mapCube(ERA5Land_dailysum, cube, indims=indims, outdims=outdims, index_list=index_in_cube) | ||
|
||
end |