Deseasonalization: climatology and anomalies (s2stools.clim)
This is to compute a climatology from s2s data.
Functions
- s2stools.clim.climatology(data: DataArray | Dataset, window_size: int = 15, mean_or_std: str = 'mean', ndays_clim_filter: int = 7, hide_warnings: bool = False, groupby: str = 'leadtime', dim_number_non_exist: bool = False)
Compute anomalies from the climatological mean. Deseasonalization is based on hindcasts.
- Parameters:
data (xr.Dataset or xr.DataArray) – The raw data.
window_size (int) – The mean is constructed using all reftimes within this plus-minus-day-interval.
mean_or_std (str) – either ‘mean’ or ‘std’
ndays_clim_filter (int) – Apply running mean to the climatology.
hide_warnings (boolean) – e.g. for UKMO it can happen that one is interested in the climatology for 2020-11-01, but hindcasts are available only at 2020-11-05; by default, the climatology is computed for 2020-11-05 onwards and the missing previous 4 days are linearly extrapolated; if this happens, hide_warnings=False will warn you!
groupby (str) –
must be ‘leadtime’ or ‘validtime’
If “leadtime”, create climatology along same leadtime, e.g., different forecasts but always for leaditme=+4 days, leadtime=+5 days, …; If “validtime”, create climatology along same day-of-year, e.g., different forecasts but always for March 03, March 04, March 05. Defaults to “leadtime”.
dim_number_non_exist (bool) – Depracated, because it is now automatically checked whether adding dimension “number” is neceesary. If True, an ensemble member dimension “number” is added, because it is required for deseasonalization. Defaults to False.
- Returns:
climatology – climatological mean or climatological std based on hindcasts
- Return type:
xr.DataArray or xr.Dataset
Warning
If reftimes +- time window are not available then anomalies are still computed, but climatology is less robust.
Warning
In latest version, groupby=”validtime” is not yet implemented to work with the new xarray version. Therefore, default changed to groupby=”leadtime”.
Notes
There my be use cases where no running mean should be used, e.g., for computing anomalies of forecast variance, which grows non-linearly! Moreover, if anomalies of variance are computed, make sure that groupby is set to “leadtime”, because spread is more sensitive to the leadtime of course than to the day of year.
- s2stools.clim.deseasonalize(data, window_size=15, standardize=False, ndays_clim_filter=7, hide_print=True, hide_plot=True, hide_warnings=False, return_clim_lists=False, dim_number_non_exist=False)
Compute anomalies from the climatological mean. Deseasonalization is based on hindcasts.
- Parameters:
data (xr.Dataset or xr.DataArray) – The raw data.
window_size (int) – The mean is constructed using all reftimes within this plus-minus-day-interval.
standardize (bool) – If True, compute standardized anomalies.
ndays_clim_filter (int) – Apply running mean to the climatology.
hide_print (bool) – If False, print how many reftimes are used for each climatology. Defaults to True.
hide_plot (bool) – If False, plot the climatology.
hide_warnings (bool) –
???
return_clim_lists (bool) – If True, also return the constructed climatologies. If False, only return anomalies.
dim_number_non_exist (bool) – If True, an ensemble member dimension “number” is added, because it is required for deseasonalization. Defaults to False.
- Returns:
Anomalies If return_clim_lists=True, return tuple anom, clim_list, climstd_list.
- Return type:
xr.Dataset or xr.DataArray
Warning
Deprecated since version 0.3.0:
deseasonalizewill be removed in the future, it is replaced byclimatology