spei.knmi module¶
- spei.knmi.cumsum(deficit: Series, allow_below_zero: bool = True) Series ¶
Calculate the cumulative sum of a deficit series.
Parameters:¶
- deficitpd.Series
A pandas Series representing the deficit values.
- allow_below_zerobool, optional
If True, the cumulative sum is calculated as-is, allowing negative values. If False, the cumulative sum is constrained to be non-negative, resetting to zero whenever the sum would drop below zero. Default is True.
Returns:¶
- pd.Series
A pandas Series containing the cumulative sum of the deficit values, optionally constrained to be non-negative.
- spei.knmi.deficit_apr1(deficit: Series) Series ¶
Calculate the maximum change in cumulative deficit within a specified date range.
This function computes the cumulative deficit for the given deficit series between April 1st and September 30th of the year 2000. It then calculates the maximum change in the cumulative deficit over this period.
- Parameters:
deficit (pd.Series) – A pandas Series representing the deficit values. The index is expected to be datetime-like.
- Returns:
A pandas Series containing the maximum change in cumulative deficit over the specified period, labeled as “DIapr1”.
- Return type:
pd.Series
- spei.knmi.deficit_gdd(deficit: Series, temp: Series, threshold: float = 440.0) Series ¶
Calculate the maximum change in cumulative deficit starting from the first day when the temperature sum (growing degree days; GDD) exceeds a specified threshold.
Parameters:¶
- deficitpd.Series
A pandas Series representing the daily deficit values.
- temppd.Series
A pandas Series representing the daily temperature values.
- thresholdfloat, optional
The temperature sum GDD threshold to determine the starting date for the calculation. Defaults to 440.0.
Returns:¶
- pd.Series
A pandas Series containing the maximum change in cumulative deficit, labeled as “DIgdd”.
- spei.knmi.deficit_max(deficit: Series) Series ¶
Calculate the maximum cumulative deficit within a specified period.
This function computes the maximum cumulative deficit for a given deficit time series, starting from April 1st to September 30th. The cumulative deficit is calculated using the get_cumulative_deficit function, ensuring that values below zero are not allowed.
Parameters:¶
- deficitpd.Series
A pandas Series representing the deficit values over time.
Returns:¶
- pd.Series
A pandas Series containing the maximum cumulative deficit within the specified period, labeled as “Dmax”.
- spei.knmi.deficit_oct1(deficit: Series) Series ¶
Calculate the cumulative deficit on October 1st.
This function computes the cumulative deficit for a given time series of deficits, considering only the period between April 1st and September 30th. The cumulative deficit is reset to zero if it goes below zero during this period.
Parameters:¶
- deficitpd.Series
A pandas Series representing the deficit time series. The index should be datetime-like, and the values should represent the deficit amounts.
Returns:¶
- pd.Series
A pandas Series containing the cumulative deficit values on October 1st. The index of the returned Series corresponds to the columns of the cumulative deficit DataFrame, and the name of the Series is “Doct1”.
- spei.knmi.deficit_wet(deficit: Series) Series ¶
Calculate the maximum change in cumulative deficit for a specified period.
This function computes the maximum change in cumulative deficit from January 1st to September 30th of a given year. The cumulative deficit is calculated using the get_cumulative_deficit function, allowing values below zero.
Parameters:¶
- deficitpd.Series
A pandas Series representing the deficit values over time.
Returns:¶
- pd.Series
A pandas Series containing the maximum change in cumulative deficit for the specified period, labeled as “DIwet”.
- spei.knmi.get_cumulative_deficit(deficit: Series, startdate: Timestamp | Series, enddate: Timestamp | Series, allow_below_zero: bool = True) DataFrame ¶
Calculate the cumulative deficit for a given time period.
This function computes the cumulative deficit for each column in a grouped yearly DataFrame, starting from startdate to enddate. The cumulative sum can optionally allow values below zero.
Parameters:¶
- deficitpd.Series
A pandas Series representing the deficit time series.
- startdatepd.Timestamp | pd.Series
The start date(s) for the cumulative deficit calculation. If a single timestamp is provided, it is applied to all columns. If a Series is provided, it should align with the columns of the grouped DataFrame.
- enddatepd.Timestamp | pd.Series
The end date(s) for the cumulative deficit calculation. Similar to startdate, it can be a single timestamp or a Series aligned with the columns.
- allow_below_zerobool, optional
If True, allows the cumulative sum to include values below zero. Defaults to True.
Returns:¶
- pd.DataFrame
A DataFrame containing the cumulative deficit for each column over the specified time period. The index represents the date range, and the columns correspond to the year.
- spei.knmi.get_yearly_temp_date(temp: Series, threshold: float) Series ¶
Get the first date in each year where the cumulative temperature exceeds a given threshold.
- Parameters:
temp (pd.Series) – A pandas Series representing the temperature time series, indexed by date.
threshold (float) – The temperature threshold to identify the first date above it.
- Returns:
A pandas Series containing the first date in each year where the cumulative temperature exceeds the threshold. The index corresponds to the years.
- Return type:
pd.Series