aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: c47c9f689f0e2fcef2404b432590f780e5e7aaef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# scopekit

<img src="logo.svg" width="120" markdown="1">

`scopekit` is a Python library for creating high-performance, interactive oscilloscope-style plots for large time-series datasets using `matplotlib`.

It is designed to handle millions of data points smoothly by automatically decimating data for the current view. When zoomed out, it displays a performance-optimized "envelope" view, and when zoomed in, it seamlessly transitions to show detailed raw data.

## Installation

To install the package from your local repository, run:

```bash
pip install .
```

## Quickstart Example

Here is a simple example of how to create a plot with `scopekit`.

```python
import numpy as np
from scopekit import OscilloscopePlot

# 1. Generate some sample data
fs = 1e7  # 10 MHz sampling rate
duration = 0.1  # 0.1 seconds of data
t = np.arange(0, duration, 1/fs)
# A 50 Hz signal with some high-frequency noise
x = np.sin(2 * np.pi * 50 * t) + np.sin(2 * np.pi * 1e3 * t) * 0.2

# 2. Create an OscilloscopePlot instance
# The plot automatically handles decimation and display modes.
plot = OscilloscopePlot(t, x, name="Sample Waveform")

# 3. Render the plot
# This creates the matplotlib figure and axes.
plot.render()

# 4. Show the plot
# The plot is now interactive: zoom with the mouse and use the toolbar.
plot.show()
```

## API Reference

The primary interface for the library is the `OscilloscopePlot` class.

### `OscilloscopePlot`

#### `__init__`

```python
def __init__(
    self,
    t: Union[np.ndarray, List[np.ndarray]],
    x: Union[np.ndarray, List[np.ndarray]],
    name: Union[str, List[str]] = "Waveform",
    trace_colors: Optional[List[str]] = None,
    max_plot_points: int = 10000,
    mode_switch_threshold: float = 10e-3,
    min_y_range: Optional[float] = None,
    y_margin_fraction: float = 0.15,
    signal_line_width: float = 1.0,
    signal_alpha: float = 0.75,
    envelope_alpha: float = 0.75,
    region_alpha: float = 0.4,
    region_zorder: int = -5,
    envelope_window_samples: Optional[int] = None,
):
```

#### Methods

```python
def add_line(
    self,
    t: Union[np.ndarray, List[np.ndarray]],
    data: Union[np.ndarray, List[np.ndarray]],
    label: str = "Line",
    color: Optional[str] = None,
    alpha: float = 0.75,
    linestyle: str = "-",
    linewidth: float = 1.0,
    display_mode: int = MODE_BOTH,
    trace_idx: int = 0,
    zorder: int = 5,
) -> None:
```

```python
def add_ribbon(
    self,
    t: Union[np.ndarray, List[np.ndarray]],
    center_data: Union[np.ndarray, List[np.ndarray]],
    width: Union[float, np.ndarray],
    label: str = "Ribbon",
    color: str = "gray",
    alpha: float = 0.6,
    display_mode: int = MODE_DETAIL,
    trace_idx: int = 0,
    zorder: int = 2,
) -> None:
```

```python
def add_envelope(
    self,
    min_data: Union[np.ndarray, List[np.ndarray]],
    max_data: Union[np.ndarray, List[np.ndarray]],
    label: str = "Envelope",
    color: Optional[str] = None,
    alpha: float = 0.4,
    display_mode: int = MODE_ENVELOPE,
    trace_idx: int = 0,
    zorder: int = 1,
) -> None:
```

```python
def add_regions(
    self,
    regions: np.ndarray,
    label: str = "Regions",
    color: str = "crimson",
    alpha: float = 0.4,
    display_mode: int = MODE_BOTH,
    trace_idx: int = 0,
    zorder: int = -5,
) -> None:
```

```python
def render(self) -> None:
```

```python
def show(self) -> None:
```

```python
def save(self, filepath: str) -> None:
```

```python
def home(self) -> None:
```

```python
def refresh(self) -> None:
```