Skip to content

Commit fe438b8

Browse files
committed
docs: update quickstart guide with ECA workflow and tests
1 parent d6d3c1e commit fe438b8

2 files changed

Lines changed: 363 additions & 63 deletions

File tree

docs/source/quickstart.rst

Lines changed: 82 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,121 @@
11
Quickstart
22
==========
33

4-
This quickstart guide will help you get up and running with `dominosee` for analyzing interconnected hydroclimatic extreme events.
4+
This quickstart guide will help you get up and running with `dominosee` for analyzing interconnected hydroclimatic extreme events using Event Coincidence Analysis (ECA).
55

6-
Basic Usage
7-
----------
6+
Basic Setup
7+
-----------
88

99
First, import the necessary packages:
1010

1111
.. code-block:: python
1212
1313
import numpy as np
1414
import xarray as xr
15-
import matplotlib.pyplot as plt
1615
import dominosee as ds
1716
18-
Event Analysis
19-
-------------
17+
Creating Sample Data
18+
--------------------
2019

21-
One of the core functionalities of `dominosee` is selecting and analyzing event periods:
20+
Let's create a sample climate dataset with SPI (Standardized Precipitation Index) values:
2221

2322
.. code-block:: python
2423
25-
# Create sample event data
26-
events = np.random.randn(100, 10) # 100 time steps, 10 events
27-
duration = np.arange(1, 11) # Duration of each event
24+
# Create a sample dataset
25+
nx, ny, nt = 20, 20, 365 # 20x20 grid, 365 days
2826
29-
# Select the first few days of events based on duration
30-
first_period = ds.select_first_period(events, duration, days=5)
27+
# Create coordinates
28+
lats = np.linspace(-90, 90, nx)
29+
lons = np.linspace(-180, 180, ny)
30+
times = xr.date_range("1950-01-01", periods=nt, freq="D")
3131
32-
# Plot the results
33-
plt.figure(figsize=(10, 6))
34-
plt.plot(first_period)
35-
plt.title('First 5 Days of Events')
36-
plt.xlabel('Time Step')
37-
plt.ylabel('Value')
38-
plt.grid(True)
39-
plt.show()
32+
# Create standard normal data for SPI values
33+
spi_data = np.random.normal(0, 1, size=(nx, ny, nt))
34+
35+
# Create xarray Dataset
36+
spi = xr.Dataset(
37+
data_vars={"SPI1": (["lat", "lon", "time"], spi_data)},
38+
coords={"lat": lats, "lon": lons, "time": times}
39+
)
40+
41+
Extracting Extreme Events
42+
--------------------------
43+
44+
Identify extreme events using a threshold:
45+
46+
.. code-block:: python
47+
48+
from dominosee.eventorize import get_event
49+
50+
# Extract drought events (SPI < -1.0)
51+
da_event = get_event(
52+
spi.SPI1,
53+
threshold=-1.0,
54+
extreme="below",
55+
event_name="drought"
56+
)
4057
41-
Working with xarray DataArrays
42-
-----------------------------
58+
Event Coincidence Analysis (ECA)
59+
---------------------------------
4360

44-
For multidimensional gridded climate data, `dominosee` provides xarray-compatible functions:
61+
Calculate event coincidences between location pairs:
4562

4663
.. code-block:: python
4764
48-
# Create a sample xarray DataArray
49-
times = pd.date_range('2025-01-01', periods=100)
50-
events = np.random.randn(100, 5, 3) # time, event, location
65+
from dominosee.eca import (
66+
get_eca_precursor_from_events,
67+
get_eca_trigger_from_events,
68+
get_eca_precursor_confidence,
69+
get_eca_trigger_confidence
70+
)
5171
52-
da = xr.DataArray(
53-
events,
54-
dims=('time', 'event', 'location'),
55-
coords={
56-
'time': times,
57-
'event': np.arange(5),
58-
'location': ['A', 'B', 'C']
59-
}
72+
# Calculate precursor and trigger events
73+
da_precursor = get_eca_precursor_from_events(
74+
eventA=da_event,
75+
eventB=da_event,
76+
delt=2, # Time window
77+
sym=True, # Symmetric window
78+
tau=0
6079
)
6180
62-
# Create duration array
63-
duration = xr.DataArray(
64-
np.array([3, 5, 2, 7, 4]),
65-
dims=('event'),
66-
coords={'event': np.arange(5)}
81+
da_trigger = get_eca_trigger_from_events(
82+
eventA=da_event,
83+
eventB=da_event,
84+
delt=10,
85+
sym=True,
86+
tau=0
6787
)
6888
69-
# Select first period using xarray function
70-
first_period_xr = ds.select_first_period_xr(da, duration, days=3)
89+
# Calculate statistical confidence
90+
da_prec_conf = get_eca_precursor_confidence(
91+
precursor=da_precursor,
92+
eventA=da_event,
93+
eventB=da_event
94+
)
7195
72-
# Plot results for one location
73-
first_period_xr.sel(location='A').plot.line(x='time')
74-
plt.title('First 3 Days of Events at Location A')
75-
plt.grid(True)
76-
plt.show()
96+
da_trig_conf = get_eca_trigger_confidence(
97+
trigger=da_trigger,
98+
eventA=da_event,
99+
eventB=da_event
100+
)
77101
78-
Network Analysis
79-
----------------
102+
Constructing Networks
103+
---------------------
80104

81-
dominosee can generate and analyze networks from event data:
105+
Create network adjacency matrices from significant connections:
82106

83107
.. code-block:: python
84108
85-
# Generate a sample network from event data
86-
# This is a simplified example
87-
network = ds.generate_network(da, threshold=0.5)
109+
from dominosee.network import get_link_from_confidence
88110
89-
# Analyze network properties
90-
centrality = ds.calculate_centrality(network)
111+
# Create network from ECA confidence levels
112+
da_link = (
113+
get_link_from_confidence(da_prec_conf, 0.99) &
114+
get_link_from_confidence(da_trig_conf, 0.99)
115+
)
91116
92-
# Visualize the network
93-
ds.plot_network(network, centrality)
94-
95-
Next Steps
96-
----------
117+
# Calculate network density
118+
density = da_link.sum().values / da_link.size * 100
119+
print(f"Network density: {density:.2f}%")
97120
98-
To dive deeper into dominosee:
99121
100-
.. - Explore the :doc:`user_guide/index` for detailed explanations
101-
.. - Check out the :doc:`examples/index` for practical examples
102-
- Refer to the :doc:`api/index` for complete function documentation

0 commit comments

Comments
 (0)