-
Notifications
You must be signed in to change notification settings - Fork 0
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
3 changed files
with
122 additions
and
89 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
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 |
---|---|---|
@@ -1,45 +1,62 @@ | ||
""" | ||
Seasonally moving thresholds | ||
Calculate yearly air temperature. | ||
# Description | ||
we use the fixed thresholds and add the seasonal warming signal. | ||
Thus, thresholds are defined as a fixed baseline (such as for the fixed threshold) plus | ||
seasonally moving mean warming of the corresponding future climate based on the | ||
31-year moving mean of the warmest three months. | ||
# Details | ||
This function calculates the yearly air temperature based on the input temperature data and dates. If `only_summer` is true, it only calculates the temperature for summer months. The function applies the calculation along the specified dimensions. | ||
# Arguments | ||
- `A::AbstractArray{T,N}`: input array of temperature data. | ||
- `dates`: array of dates corresponding to the temperature data. | ||
- `dims=N`: dimensions to apply the function along. | ||
- `only_summer=false`: if true, only calculate temperature for summer months. | ||
# Returns | ||
- `T_year`: array of yearly temperature data. | ||
""" | ||
function cal_yearly_Tair(arr::AbstractArray{<:Real, 3}, dates; only_summer=false) | ||
function cal_yearly_Tair(A::AbstractArray{T,N}, dates; | ||
dims=N, only_summer=false) where {T<:Real,N} | ||
|
||
if only_summer | ||
yms = format.(dates, "yyyy-mm") | ||
ys = SubString.(unique(yms), 1, 4) | ||
T_mon = apply(arr, 3; by=yms) | ||
T_mon = movmean(T_mon, 1; dims=3) #3个月滑动平均 | ||
T_year = apply(T_mon, 3; by=ys, fun=maximum) # 最热的3个月,作为每年的升温幅度 | ||
T_mon = apply(A, dims; by=yms) | ||
T_mon = movmean(T_mon, 1; dims) #3个月滑动平均 | ||
|
||
T_year = apply(T_mon, dims; by=ys, fun=maximum) # 最热的3个月,作为每年的升温幅度 | ||
else | ||
ys = format.(dates, "yyyy") | ||
T_year = apply(arr, 3; by=ys) | ||
T_year = apply(A, dims; by=ys) | ||
end | ||
T_year | ||
end | ||
|
||
cal_climatology_season(arr::AbstractArray, dates) = cal_yearly_Tair(arr, dates; only_summer=false) | ||
cal_climatology_season(A::AbstractArray, dates) = cal_yearly_Tair(A, dates; only_summer=false) | ||
|
||
cal_mTRS_season(arr::AbstractArray, dates) = cal_yearly_Tair(arr, dates; only_summer=true) | ||
cal_mTRS_season(A::AbstractArray, dates) = cal_yearly_Tair(A, dates; only_summer=true) | ||
|
||
|
||
""" | ||
$(TYPEDSIGNATURES) | ||
""" | ||
function cal_warming_level(arr::AbstractArray{<:Real, 3}, dates; | ||
p1=1981, p2=2010, only_summer=false) | ||
T_year = cal_yearly_Tair(arr, dates; only_summer) | ||
function cal_warming_level(A::AbstractArray{T,N}, dates; | ||
p1=1981, p2=2010, dims=N, only_summer=false) where {T<:Real,N} | ||
|
||
T_year = cal_yearly_Tair(A, dates; dims, only_summer) | ||
|
||
# yms = format.(dates, "yyyy-mm") | ||
# ys = SubString.(unique(yms), 1, 4) | ||
# grps = unique_sort(ys) | ||
grps = year.(dates) |> unique_sort | ||
grps = year.(dates) |> unique_sort | ||
inds_clim = @.(p1 <= grps <= p2) | ||
T_clim = apply(@view(T_year[:, :, inds_clim]), 3; fun=nanmean) | ||
|
||
T_year_clim = selectdim(T_year, dims, inds_clim) | ||
T_clim = apply(T_year_clim, dims; fun=nanmean) | ||
|
||
T_year .- T_clim | ||
end |
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