easyclimate.core.variability¶
This module calculate climate variability
Functions¶
|
Calculation of the climatological mean over the entire time range. |
|
Calculation of the seasonal climatological mean over the entire time range. |
|
Calculation of the seasonal cycle means over the entire time range. |
|
Calculation of the seasonal cycle standard deviation over the entire time range. |
|
Calculation of the seasonal cycle standard deviation over the entire time range. |
|
Calculation of the seasonal means per year over the entire time range. |
|
Remove of the seasonal cycle means over the entire time range. |
|
Calculate the standard deviation of monthly data anomalies over the entire time range. |
|
Calculate the variance of monthly data anomalies over the entire time range. |
|
Calculates a smooth mean daily annual cycle for an array nominally dimensioned. |
|
Calculation of the daily means per year over the entire time range. |
|
Calculation of the daily standard deviation per year over the entire time range. |
|
Calculation of the daily variance per year over the entire time range. |
|
Removes the smooth daily annual cycle mean from the input data. |
|
Calculate the standard deviation of vector wind speed and direction. |
|
Calculate the horizontal wind speed from zonal and meridional wind components in a |
|
Calculate the horizontal wind speed from zonal and meridional wind components in |
|
Populate the data of each month using the monthly mean state of the data_monthly or given dataset. |
|
Populate the data of each day using the daily mean state of the data_daily or given dataset. |
Calulate daily anomaly using the given dataset of climatological mean state . |
|
|
Remove low-frequency signal by subtracting the running mean from a time series. |
Module Contents¶
- easyclimate.core.variability.calc_all_climatological_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the climatological mean over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.- dim:
str Dimension(s) over which to apply extracting. By default extracting is applied over the time dimension.
- **kwargs:
Additional keyword arguments passed on to the appropriate array function for calculating mean on this object’s data. These could include dask-specific kwargs like split_every.
Returns¶
- data_input
- easyclimate.core.variability.calc_seasonal_climatological_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the seasonal climatological mean over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.- dim:
str Dimension(s) over which to apply extracting. By default extracting is applied over the time dimension.
- **kwargs:
Additional keyword arguments passed on to the appropriate array function for calculating mean on this object’s data. These could include dask-specific kwargs like split_every.
Returns¶
- data_input
- easyclimate.core.variability.calc_seasonal_cycle_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the seasonal cycle means over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be monthly data.
Returns¶
- data_input
- easyclimate.core.variability.calc_seasonal_cycle_std(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the seasonal cycle standard deviation over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be monthly data.
- dim:
str Dimension(s) over which to apply extracting. By default extracting is applied over the time dimension.
- **kwargs:
Additional keyword arguments passed on to the appropriate array function for calculating standard deviation on this object’s data. These could include dask-specific kwargs like split_every.
Returns¶
- data_input
- easyclimate.core.variability.calc_seasonal_cycle_var(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the seasonal cycle standard deviation over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be monthly data.
Returns¶
- data_input
- easyclimate.core.variability.calc_seasonal_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', extract_season: Literal['seasonly', 'DJF', 'MAM', 'JJA', 'SON', 'JJAS', 'OND'] = 'seasonly', **kwargs) xarray.DataArray¶
Calculation of the seasonal means per year over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be monthly data.
- dim:
str Dimension(s) over which to apply extracting. By default extracting is applied over the time dimension.
- extract_season:
list. default: “seasonly”. Extraction seasons.
“seasonly”: Calculate by meteorological seasons (DJF, MAM, JJA, SON)
custom seasons: Calculate climatology by custom seasons, e.g., ‘DJF’, ‘MAM’, ‘JJA’, ‘SON’,
'JJAS','OND'.
Returns¶
- data_input
- easyclimate.core.variability.remove_seasonal_cycle_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', time_range: slice = slice(None, None)) xarray.DataArray¶
Remove of the seasonal cycle means over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset. The data of
xarray.DataArrayto be calculated.
Caution
data_input must be monthly data.
Returns¶
- data_input
- easyclimate.core.variability.calc_monthly_climatological_std_without_seasonal_cycle_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculate the standard deviation of monthly data anomalies over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be monthly data.
- dim:
str Dimension(s) over which to apply extracting. By default extracting is applied over the time dimension.
- **kwargs:
Additional keyword arguments passed on to the appropriate array function for calculating standard deviation on this object’s data. These could include dask-specific kwargs like split_every.
Returns¶
- data_input
- easyclimate.core.variability.calc_monthly_climatological_var_without_seasonal_cycle_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculate the variance of monthly data anomalies over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayorxarray.Datasetto be calculated.
Caution
data_input must be monthly data.
Returns¶
- data_input
- easyclimate.core.variability.smooth_daily_annual_cycle(daily_annual_cycle_data: xarray.DataArray, harmonics_num: int = 3, time_dim: str = 'dayofyear') xarray.DataArray¶
Calculates a smooth mean daily annual cycle for an array nominally dimensioned.
Parameters¶
- daily_annual_cycle_data
xarray.DataArray The input data array with time as the first dimension. The time dimension should be named as specified by time_dim.
- harmonics_numint, optional
The number of harmonics to retain in the FFT. Default is 3.
- time_dimstr, optional
The name of the time dimension in the DataArray. Default is “dayofyear”.
Returns¶
The smoothed daily cycle data.
- daily_annual_cycle_data
- easyclimate.core.variability.calc_daily_annual_cycle_mean(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the daily means per year over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be daily or hourly data. At least one year of time range must be included in the data_input.
Returns¶
xarray.DataArrayorxarray.Dataset.Caution
For complete coverage, the data should span at least one full year.
If the data is sub-daily (e.g., hourly), the mean is taken over all sub-daily time points for each day of the year.
- data_input
- easyclimate.core.variability.calc_daily_annual_cycle_std(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the daily standard deviation per year over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be daily or hourly data. At least one year of time range must be included in the data_input.
Returns¶
xarray.DataArrayorxarray.Dataset.Caution
For complete coverage, the data should span at least one full year.
If the data is sub-daily (e.g., hourly), the std is taken over all sub-daily time points for each day of the year.
- data_input
- easyclimate.core.variability.calc_daily_annual_cycle_var(data_input: xarray.DataArray | xarray.Dataset, dim: str = 'time', **kwargs) xarray.DataArray¶
Calculation of the daily variance per year over the entire time range.
Parameters¶
- data_input
xarray.DataArrayorxarray.Dataset The data of
xarray.DataArrayto be calculated.
Caution
data_input must be daily or hourly data. At least one year of time range must be included in the data_input.
Returns¶
xarray.DataArrayorxarray.Dataset.Caution
For complete coverage, the data should span at least one full year.
If the data is sub-daily (e.g., hourly), the var is taken over all sub-daily time points for each day of the year.
- data_input
- easyclimate.core.variability.remove_smooth_daily_annual_cycle_mean(data_input: xarray.DataArray, daily_cycle_mean_time_range: slice = slice(None, None), extract_time_range: slice = slice(None, None), harmonics_num: int = 3, dim: str = 'time')¶
Removes the smooth daily annual cycle mean from the input data.
This function first calculates the daily cycle mean over a specified time range, smooths that mean using a specified number of harmonics, and then subtracts this smoothed cycle from the input data over another specified time range.
Parameters¶
- data_input
xarray.DataArray The input data from which to remove the smooth daily annual cycle mean.
- daily_cycle_mean_time_rangeslice, optional
The time range used to compute the daily annual cycle mean. Default is all time.
- extract_time_rangeslice, optional
The time range from which to extract the data and remove the daily annual cycle. Default is all time.
- harmonics_numint, optional
The number of harmonics to use in smoothing the daily annual cycle mean. Default is 3.
- dimstr, optional
The name of the time dimension. Default is “time”.
Returns¶
xarray.DataArrayThe input data with the smooth daily cycle mean removed.
- data_input
- easyclimate.core.variability.calc_horizontal_wind_components_std(uv_dataset: xarray.Dataset, u_dim='u', v_dim='v', time_dim='time', ddof=0) xarray.Dataset¶
Calculate the standard deviation of vector wind speed and direction.
The standard deviation of vector wind speed
\[\sigma_s = [U^2 \sigma_u^2 + V^2 \sigma_v^2 + 2 U V \sigma_{uv}]^{1/2} S^{-1},\]The standard deviation of vector wind direction
\[\sigma_d = [V^2 \sigma_u^2 + U^2 \sigma_v^2 + 2 U V \sigma_{uv}]^{1/2} S^{-2},\]Where time mean of \(u\) is \(U = n^{-1} \sum u_i\), time mean of \(v\) is \(V = n^{-1} \sum v_i\), time variance of \(u\) is \(\sigma_u^2 = n^{-1} \sum u_{i}^{2} - U^2\), time variance of \(v\) is \(\sigma_v^2 = n^{-1} \sum v_{i}^{2} - V^2\), time covariance of \(u\), \(v\) is \(\sigma_{uv} = n^{-1} \sum u_i v_i - UV\), vector mean wind speed is \(S = (U^2 + V^2)^{1/2}\).
Parameters¶
- uv_dataset
xarray.Dataset xarray.Datasetdata containing zonal and meridional wind components.- u_dim:
str, default: u Variable name for the u velocity (in x direction).
- v_dim:
str, default: v Variable name for the v velocity (in y direction).
- time_dim
str, default: time Dimension(s) over which to apply. By default is applied over the time dimension.
- ddof
int, default: 1 If ddof=1, covariance is normalized by N-1, giving an unbiased estimate, else normalization is by N.
Returns¶
xarray.Datasetsigma_s: the standard deviation of vector wind speed.
sigma_d: the standard deviation of vector wind direction.
Reference¶
Ackermann. (1983). Means and Standard Deviations of Horizontal Wind Components. https://doi.org/10.1175/1520-0450(1983)022%3C0959:MASDOH%3E2.0.CO;2
- uv_dataset
- easyclimate.core.variability.calc_windspeed_dataset(uv_dataset: xarray.Dataset, u_dim: str = 'u', v_dim: str = 'v') xarray.Dataset¶
Calculate the horizontal wind speed from zonal and meridional wind components in a
xarray.Dataset.The wind speed is computed as the magnitude of the horizontal wind vector:
\[S = \sqrt{u^2 + v^2},\]where \(u\) is the zonal wind component and \(v\) is the meridional wind component.
Parameters¶
- uv_dataset
xarray.Dataset xarray.Datasetcontaining zonal and meridional wind components.- u_dim
str, default: u Variable name for the zonal wind component (in x direction).
- v_dim
str, default: v Variable name for the meridional wind component (in y direction).
Returns¶
xarray.DatasetA copy of the input dataset with an additional variable speed containing the wind speed.
Examples¶
>>> ds = xr.Dataset({"u": (("time",), [1, 2, 3]), "v": (("time",), [4, 5, 6])}) >>> ds_with_speed = calc_windspeed_dataset(ds, u_dim="u", v_dim="v") >>> print(ds_with_speed["speed"]) <xarray.DataArray 'speed' (time: 3)> Size: 24B array([4.12310563, 5.38516481, 6.70820393]) Dimensions without coordinates: time
- uv_dataset
- easyclimate.core.variability.calc_windspeed_dataarray(u_data: xarray.DataArray, v_data: xarray.DataArray) xarray.DataArray¶
Calculate the horizontal wind speed from zonal and meridional wind components in
xarray.DataArray.The wind speed is computed as the magnitude of the horizontal wind vector:
\[S = \sqrt{u^2 + v^2},\]where \(u\) is the zonal wind component and \(v\) is the meridional wind component.
Parameters¶
- u_data
xarray.DataArray xarray.DataArraycontaining the zonal wind component (in x direction).- v_data
xarray.DataArray xarray.DataArraycontaining the meridional wind component (in y direction).
Returns¶
xarray.DataArrayA
xarray.DataArraycontaining the wind speed.
Examples¶
>>> u = xr.DataArray([1, 2, 3], dims="time") >>> v = xr.DataArray([4, 5, 6], dims="time") >>> speed = calc_windspeed_dataarray(u, v) >>> print(speed) <xarray.DataArray (time: 3)> Size: 24B array([4.12310563, 5.38516481, 6.70820393]) Dimensions without coordinates: time
- u_data
- easyclimate.core.variability.populate_monmean2everymon(data_monthly: xarray.DataArray, data_climatology_monthly_data: xarray.DataArray = None, time_dim: str = 'time') xarray.DataArray¶
Populate the data of each month using the monthly mean state of the data_monthly or given dataset.
Parameters¶
- data_monthly:
xarray.DataArray. xarray.DataArrayto be calculated.- data_climatology_monthly_data:
xarray.DataArray, default None. The monthly climatology dataset. If it is None, the climatology is derived from data_monthly.
- time_dim:
str, default: time. The time coordinate dimension name.
Returns¶
- data_monthly:
- easyclimate.core.variability.populate_daymean2everyday(data_daily: xarray.DataArray, data_climatology_daily_data: xarray.DataArray = None, time_dim: str = 'time') xarray.DataArray¶
Populate the data of each day using the daily mean state of the data_daily or given dataset.
Parameters¶
- data_daily:
xarray.DataArray. xarray.DataArrayto be calculated.
- data_daily:
- data_climatology_daily_data:
xarray.DataArray, default None. The daily climatology dataset. If it is None, the climatology is derived from data_monthly.
- data_climatology_daily_data:
- time_dim:
str, default: time. The time coordinate dimension name.
- time_dim:
Returns¶
- easyclimate.core.variability.calc_daily_climatological_anomaly(data_daily: xarray.DataArray | xarray.Dataset, data_climatology_daily_data: xarray.DataArray | xarray.Dataset, timd_dim='time') xarray.DataArray | xarray.Dataset¶
Calulate daily anomaly using the given dataset of climatological mean state .
- data_daily:
xarray.DataArrayorxarray.Dataset. xarray.DataArrayto be calculated.
- data_daily:
- data_climatology_daily_data:
xarray.DataArrayorxarray.Dataset. The daily climatology dataset.
- data_climatology_daily_data:
- time_dim:
str, default: time. The time coordinate dimension name.
- time_dim:
Returns¶
- easyclimate.core.variability.remove_low_frequency_signal(da: xarray.DataArray, window: int = 120, center: bool = False, time_dim: str = 'time') xarray.DataArray¶
Remove low-frequency signal by subtracting the running mean from a time series.
This function removes the effect of interannual variability by subtracting the running mean of the specified window (default 120 days), as described in Wheeler and Hendon (2004). The method is commonly used in the context of the Madden-Julian Oscillation (MJO) index calculation for monitoring and prediction.
Parameters¶
- da
xarray.DataArray Input time series data array with a time dimension.
- window
int, optional Size of the moving average window in days (default is 120).
- center
bool, optional If
True, the moving average is centered (mean of window around each point). IfFalse, the moving average is trailing (mean of last window days). Default isFalse.- time_dim
str, optional Name of the time dimension in the input DataArray (default is “time”).
Returns¶
xarray.DataArrayThe input data array with the low-frequency signal (running mean) removed.
References¶
Wheeler, M. C., & Hendon, H. H. (2004). An All-Season Real-Time Multivariate MJO Index: Development of an Index for Monitoring and Prediction. Monthly Weather Review, 132(8), 1917-1932. https://journals.ametsoc.org/view/journals/mwre/132/8/1520-0493_2004_132_1917_aarmmi_2.0.co_2.xml
Examples¶
>>> import xarray as xr >>> da = xr.DataArray([...], dims=['time'], coords={'time': [...]}) >>> result = remove_low_frequency_signal(da, window=120, center=False, time_dim='time')
- da