Events#

TSCC.exploration.events.addShapes(K, J, fig)[source]#

for internal use only

TSCC.exploration.events.fct_indicator(x, threshold_min, threshold_max)[source]#

for internal use only

TSCC.exploration.events.getEventReturnPeriod(series, KOSTRA_DS)[source]#

Calculate heavy rainfall events based on rolling sums over different durations and thresholds from the KOSTRA_DS dataset.

Parameters:
seriespandas series

A time series of rainfall data with a datetime index and rainfall amounts as values.

KOSTRA_DSpandas dataframe

A DataFrame containing threshold values from the KOSTRA-DS dataset. Columns represent different probabilities (wdkzeit), and rows represent durations (duration_level) for heavy rainfall.

Returns:
pandas dataframe

A DataFrame where each row corresponds to a timestamp and includes binary indicators for whether heavy rainfall occurred for each probability (wdkzeit).

TSCC.exploration.events.getEvents(s, max_time_dist_from_center, center_valley=(- inf, inf), center_peak=(- inf, inf), event_sum=(- inf, inf), event_dist=(- inf, inf, 0.0))[source]#

Finds events that satisfy the following conditions: A minimal intensity, a minimal and maximal time span of the event of event.

Parameters:
spandas series

Series with numerical entries, index in datetime format timestep must be equidistant

max_time_dist_from_centerstring

Defines the timestep lengths of the maximal distance to the center of the event Has to be the format number + letter. Possible for time step units (letter):

seconds, minutes, hours, days, years.

Examples: “2s” for two seconds, “5t” for five minute,

“5h” for five hours, “4d” for four day or “1y” for one year.

center_valleyoptional, numeric duple

The min and max valley intensity that an event must have

center_peakoptional, numeric duple

The min and max peak intensity that an event must have

event_sumoptional, numeric duple

The min and max event sum that an event must have

event_dist(min, max, rate_included)

The event range by min and max value combined with the rate range in [0,1], stating the value rate outside the typical event interval

Returns:
list

nested list with a sublist of each event including the - starting time - ending time - minimal intensity - maximal intensity - event sum in that order.

Examples

>>> import pandas as pd
>>> import numpy as np
>>>
>>> # Create a date range for the timestamps
>>> date_range = pd.date_range(start='2000-04-29', periods=50, freq='5min')
>>>
>>> # Generate random data for 'value_plaus'
>>> np.random.seed(0)  # For reproducibility
>>> value_plaus = np.random.poisson(lam=1, size=len(date_range))  # Lambda set to 3
>>>
>>> # Create the DataFrame
>>> df = pd.DataFrame({
>>>     'timestamp': date_range,
>>>     'value_plaus': value_plaus
>>> })
>>>
>>> event_list = TSCC.exploration.getEvents(df.set_index("timestamp")["value_plaus"],
>>>     max_time_dist_from_center = "45t",
>>>     #center_valley = (-float("inf"), float("inf")),
>>>     center_peak = (2, float("inf")),
>>>     event_sum=(3, 140),
>>>     event_dist = (0.000001, float("inf"), .3))
>>> print(event_list)
[[Timestamp('2000-04-29 00:00:00'),
  Timestamp('2000-04-29 00:45:00'),
  0,
  5,
  15],
 [Timestamp('2000-04-29 00:10:00'),
  Timestamp('2000-04-29 01:40:00'),
  0,
  5,
  24],
 [Timestamp('2000-04-29 02:15:00'),
  Timestamp('2000-04-29 03:45:00'),
  0,
  3,
  13],
 [Timestamp('2000-04-29 03:05:00'),
  Timestamp('2000-04-29 04:05:00'), 0, 2, 9]]
TSCC.exploration.events.highlightEventsPlot(s, event_list)[source]#

Highlights specific events on a time series plot using Plotly.

Parameters:
spandas Series

A series with a datetime index representing a time series.

event_listnested list

A list containing event intervals, where each event is defined by two timestamps (start and end). This is typically the output from the getEvents() function.

Returns:
plotPlotly plot

A time series plot with highlighted event intervals.

Examples

# Assuming the DataFrame ‘df’ has a ‘timestamp’ column and a ‘value_plaus’ column:

>>> df_time = "timestamp"
>>> df_value_raw = "value_plaus"
>>> # Get the list of events using the getEvents() function:
>>> event_list = getEvents(df.iloc[:60000].set_index(df_time)[df_value_raw],
>>>                        max_time_dist_from_center="45t",
>>>                        center_peak=(2, float("inf")),
>>>                        event_sum=(3, 140),
>>>                        event_dist=(0.000001, float("inf"), .3))
>>> # Plot the time series with highlighted events:
>>> highlightEventsPlot(df.set_index("timestamp").iloc[:60000]["value_plaus"],
>>>                     event_list)
TSCC.exploration.events.indices2dict(K, J)[source]#

for internal use only

TSCC.exploration.events.setDictRect(x0, x1)[source]#

for internal use only

The function generates a dictionary with characteristics of a rectangle.