Skip to main content

This package allows you to run Event Coincidence Analysis and Event Synchronization on your event series on the CPU and Nvidia-GPU

Project description

Event Analysis

Library for Event Synchronization and Event Coincidence Analysis

This Python library facilitates the calculation of Event Synchronization (ES) and Event Coincidence Analysis (ECA) for event series.

Understanding ECA and ES

To learn about ECA, read this 1 To learn about ES, read this 2

Installation

To install the library, execute the following command:

pip install event-analysis

Additional Requirement

To utilize the CUDA method, please install PyCuda separately.

Usage

Refer to the Example.ipnby Jupyter notebook for detailed usage instructions.

from EventAnalysis import EventAnalysis

# Initialize the Event Analysis object with your event dataframe
EA = EventAnalysis(event_dataframe)

# Perform Event Synchronization
Q = EA.ES()

# Calculate Event Coincidence Analysis
p_max, p_mean, t_max, t_mean = EA.ECA(time_delta)

# Calculate ECA with p-values
p_max, p_mean, t_max, t_mean, pval_p, pval_t = EA.ECA(time_delta, return_p_values=True)

# Important: Read the documentation for the EA constructor parameter time_normalization_factor before using the library.

Please read the notes for the EventAnalysis class before you use this library.

Documentation

EventAnalysis Class

Constructor:
EventAnalysis(self, event_df, device_Id=None, time_normalization_factor=3600)
Arguments
  • event_df: pandas.DataFrame
    • This DataFrame must have the following properties:
      • The index must be a pandas.DatetimeIndex.
      • The data type inside the DataFrame must be boolean.
      • Each column represents an event series.
  • device_Id: Optional int
    • Specify the ID of the NVIDIA GPU for computation. Defaults to 0 if not provided.
  • time_normalization_factor: Optional int
    • The library quantizes time to hours, ignoring minutes and seconds. This behavior can be overridden by changing this argument. Possible values include:
      • 1: Quantizes to seconds (allows for 69 years of data).
      • 60: Quantizes to minutes (allows for 4000 years of data).
      • 3600: (default) Quantizes to hours (allows for 250 centuries of data).
Returns:
  • An EventAnalysis object on which you can call the ES and ECA methods.

ES Method

ES(self, tauMax=np.Inf)
Arguments
  • tauMax: Optional, default is np.Inf
    • Currently not utilized; future functionality will be added. Please open an issue if needed.
Return
  • A DataFrame Q of shape N x N, where N is the number of event series. Use Q[event_series_1_name][event_series_2_name] to get the Event Synchronization between two series.

ECA Method

ECA(self, Delta_T_obj, tau=0, return_p_values=False, pValFillNA=True)
Arguments
  • Delta_T_obj: Required
    • Must be a datetime.timedelta object. It is quantized using the same time_normalization_factor as passed to the constructor.
  • tau: Optional, default is 0
    • A parameter of the ECA algorithm. Refer to the associated paper for details.
  • return_p_values: Optional, default is False
    • If set to True, it calculates the p-values for each combination of event series and returns them.
  • pValFillNA: Optional, default is True
    • Replaces NaN p-values with 1.

Return

  • EC_p_max
  • EC_p_mean
  • EC_t_max
  • EC_t_mean
  • pval_precursor (optional): Corresponds to the p-value of EC_p_max and EC_p_mean.
  • pval_trigger (optional): Corresponds to the p-value of EC_t_max and EC_t_mean.

Notes: The paper outlines the conditions for calculating p-values for ECA results:

  1. Na >> 1 and Nb >> 1

  2. ΔT << T/Na

Here, Na and Nb represent the number of events in series A and B, respectively. Δ𝑇 should be sufficiently less than the overall time.

ECA_vec

ECA_vec(self, Delta_T_objs, taus=0, return_p_values=False, pValFillNA=True)
Arguments
  • Delta_T_objs: Required
    • A list of datetime.timedelta objects.
  • taus: Optional, default is 0
    • Can be an integer, list, or numpy array of integers, matching the length of Delta_T_objs. If an integer is provided, all ECAs use that value.
  • return_p_values: Same as ECA.
  • pValFillNA: Same as ECA.
Returns
  • A generator that yields the ECA result for each corresponding pair of Delta_T_objs[i] and taus[i].

CUDA Support

All three methods can be executed on an NVIDIA GPU by appending _Cuda to their names: ES_Cuda, ECA_Cuda, ECA_vec_Cuda. Each requires an additional named parameter, block.

  • ES_Cuda(..., block=None)
    • Defaults to (16, 8, 1). Any tuple of the form (x, y, 1) where 𝑥 × 𝑦 is a multiple of the GPU's warp size is valid.
  • ECA_Cuda(..., block=None)
  • ECA_vec_Cuda(..., block=None)
    • Defaults to (32, 1, 1). Similar to ES_Cuda.

Notes: The p-values returned by the GPU may differ slightly from those calculated by the CPU due to floating-point precision. Setting epsilon to 10−2 should minimize these discrepancies.

References

  1. Event coincidence analysis for quantifying statistical interrelationships between event time series - Jonathan F. Donges, Carl-Friedrich Schleussner, Jonatan F. Siegmund, and Reik V. Donner

  2. Frederik Wolf, Jurek Bauer, Niklas Boers, and Reik V. Donner , "Event synchrony measures for functional climate network analysis: A case study on South American rainfall dynamics", Chaos 30, 033102 (2020) https://doi.org/10.1063/1.5134012

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

event_analysis-1.1.3.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

event_analysis-1.1.3-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file event_analysis-1.1.3.tar.gz.

File metadata

  • Download URL: event_analysis-1.1.3.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for event_analysis-1.1.3.tar.gz
Algorithm Hash digest
SHA256 4c2bdc21a136b5d485131fbb575deb81893a7152af9bdf744b9c39963bbcbad9
MD5 8344fc303c131c8a6badb302c2c7cf93
BLAKE2b-256 22047ba2bca3800b5f3c04c997b903cf7f7e6e8b09ce884cf200dfe2e2d0f21e

See more details on using hashes here.

File details

Details for the file event_analysis-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: event_analysis-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for event_analysis-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b852911c1e3da1be9a72c5fe5107f73c47644389a1112c33ec0c7831a8f4480d
MD5 bbf2d2db64163b9f511ae0737341f84d
BLAKE2b-256 bc877084f1531e215bdacf021bb5e468754736e33db6ee34d9af9eb8432e08b4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page