komanawa.kendall_stats.mann_kendall#

created matt_dumont on: 14/09/23

Classes#

MannKendall

an object to hold and calculate kendall trends assumes a pandas dataframe or series with a time index

SeasonalKendall

an object to hold and calculate seasonal kendall trends

Module Contents#

class MannKendall(data, alpha=0.05, data_col=None, rm_na=True)[source]#

Bases: object

an object to hold and calculate kendall trends assumes a pandas dataframe or series with a time index

Parameters:
  • trend – the trend of the data, -1 decreasing, 0 no trend, 1 increasing

  • h – boolean, True if the trend is significant

  • p – the p value of the trend

  • z – the z value of the trend

  • s – the s value of the trend

  • var_s – the variance of the s value

  • alpha – the alpha value used to calculate the trend

  • data – the data used to calculate the trend

  • data_col – the column of the data used to calculate the trend

calc_senslope()[source]#

calculate the senslope of the data

Returns:

senslope, senintercept, lo_slope, up_slope

classmethod map_trend()[source]#

map the trend value to a string (1: increasing, -1: decreasing, 0: no trend)

Parameters:

val – trend value

Returns:

plot_data(ax=None, **kwargs)[source]#

plot the data and the senslope fit

Parameters:
  • ax – optional matplotlib axis to plot the data on

  • kwargs – kwargs to pass to plt.scatter for the raw data

Returns:

class SeasonalKendall(df, data_col, season_col, alpha=0.05, rm_na=True, freq_limit=0.05)[source]#

Bases: MannKendall

Inheritance diagram of komanawa.kendall_stats.mann_kendall.SeasonalKendall

an object to hold and calculate seasonal kendall trends

Parameters:
  • trend – the trend of the data, -1 decreasing, 0 no trend, 1 increasing

  • h – boolean, True if the trend is significant

  • p – the p value of the trend

  • z – the z value of the trend

  • s – the s value of the trend

  • var_s – the variance of the s value

  • alpha – the alpha value used to calculate the trend

  • data – the data used to calculate the trend

  • data_col – the column of the data used to calculate the trend

  • season_col – the column of the season data used to calculate the trend

  • freq_limit – the maximum difference in frequency between seasons (as a fraction), if greater than this will raise a warning

calc_senslope()[source]#

calculate the senslope of the data :return: senslope, senintercept, lo_slope, lo_intercept

classmethod map_trend()[source]#

map the trend value to a string (1: increasing, -1: decreasing, 0: no trend)

Parameters:

val – trend value

Returns:

plot_data(ax=None, **kwargs)[source]#

plot the data and the senslope fit

Parameters:
  • ax – optional matplotlib axis to plot the data on

  • kwargs – kwargs to pass to plt.scatter for the raw data (note that the seasonal column is passed to scatter as c)

Returns: