|
1 | 1 | Quickstart |
2 | 2 | ========== |
3 | 3 |
|
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). |
5 | 5 |
|
6 | | -Basic Usage |
7 | | ----------- |
| 6 | +Basic Setup |
| 7 | +----------- |
8 | 8 |
|
9 | 9 | First, import the necessary packages: |
10 | 10 |
|
11 | 11 | .. code-block:: python |
12 | 12 |
|
13 | 13 | import numpy as np |
14 | 14 | import xarray as xr |
15 | | - import matplotlib.pyplot as plt |
16 | 15 | import dominosee as ds |
17 | 16 |
|
18 | | -Event Analysis |
19 | | -------------- |
| 17 | +Creating Sample Data |
| 18 | +-------------------- |
20 | 19 |
|
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: |
22 | 21 |
|
23 | 22 | .. code-block:: python |
24 | 23 |
|
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 |
28 | 26 | |
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") |
31 | 31 | |
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 | + ) |
40 | 57 |
|
41 | | -Working with xarray DataArrays |
42 | | ------------------------------ |
| 58 | +Event Coincidence Analysis (ECA) |
| 59 | +--------------------------------- |
43 | 60 |
|
44 | | -For multidimensional gridded climate data, `dominosee` provides xarray-compatible functions: |
| 61 | +Calculate event coincidences between location pairs: |
45 | 62 |
|
46 | 63 | .. code-block:: python |
47 | 64 |
|
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 | + ) |
51 | 71 | |
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 |
60 | 79 | ) |
61 | 80 | |
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 |
67 | 87 | ) |
68 | 88 | |
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 | + ) |
71 | 95 | |
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 | + ) |
77 | 101 |
|
78 | | -Network Analysis |
79 | | ----------------- |
| 102 | +Constructing Networks |
| 103 | +--------------------- |
80 | 104 |
|
81 | | -dominosee can generate and analyze networks from event data: |
| 105 | +Create network adjacency matrices from significant connections: |
82 | 106 |
|
83 | 107 | .. code-block:: python |
84 | 108 |
|
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 |
88 | 110 | |
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 | + ) |
91 | 116 | |
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}%") |
97 | 120 |
|
98 | | -To dive deeper into dominosee: |
99 | 121 |
|
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