Repository navigation
Expand file tree
/
Copy pathgenerate_examples.py
More file actions
168 lines (141 loc) · 5.65 KB
/
Copy pathgenerate_examples.py
File metadata and controls
168 lines (141 loc) · 5.65 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
"""Generate example datasets for every plot type in the EaglePlot app.
Run once from the example-data/Artificial/ directory (or anywhere — paths are
resolved relative to this file):
python generate_examples.py
All output files are written to the same directory as this script.
"""
import numpy as np
import pandas as pd
from pathlib import Path
rng = np.random.default_rng(42)
OUT = Path(__file__).resolve().parent / "eagleplot" / "example-data" / "Artificial"
OUT.mkdir(parents=True, exist_ok=True)
# ── 1. Normal distribution (Histogram, Distribution, Interactive Histogram) ──
n = 400
normal = pd.DataFrame(
{
"temperature_K": rng.normal(loc=298.15, scale=12.0, size=n),
}
)
normal.to_csv(OUT / "normal_distribution.csv", index=False)
print("Wrote normal_distribution.csv")
# ── 2. Bimodal distribution (Distribution / overlaid distributions) ───────────
bimodal = pd.DataFrame(
{
"absorbance": np.concatenate(
[
rng.normal(loc=0.35, scale=0.07, size=250),
rng.normal(loc=0.75, scale=0.06, size=250),
]
)
}
)
bimodal.to_csv(OUT / "bimodal_distribution.csv", index=False)
print("Wrote bimodal_distribution.csv")
# ── 3. Sine / cosine waves (Line Plot, Interactive Line) ──────────────────────
x = np.linspace(0, 4 * np.pi, 300)
waves = pd.DataFrame(
{
"angle_rad": x,
"sin_wave": np.sin(x),
"cos_wave": np.cos(x),
"damped_sin": np.exp(-x / 8) * np.sin(x),
}
)
waves.to_csv(OUT / "sine_cosine_waves.csv", index=False)
print("Wrote sine_cosine_waves.csv")
# ── 4. Correlated scatter (Scatter Plot, Regression, Interactive Scatter) ─────
x_scat = rng.uniform(0, 10, 200)
scatter = pd.DataFrame(
{
"reaction_time_s": x_scat,
"product_yield": 0.72 * x_scat + rng.normal(0, 1.0, 200),
"temperature_C": 25 + 3 * x_scat + rng.normal(0, 2.0, 200),
}
)
scatter.to_csv(OUT / "scatter_correlation.csv", index=False)
print("Wrote scatter_correlation.csv")
# ── 5. Grouped categorical (Box / Violin / Swarm) ────────────────────────────
groups = []
for catalyst in ["Pd", "Pt", "Rh", "Ru"]:
for solvent in ["MeOH", "EtOH", "DCM"]:
yields = rng.normal(
loc={"Pd": 82, "Pt": 75, "Rh": 88, "Ru": 71}[catalyst],
scale=5.0,
size=20,
)
for y in yields:
groups.append({"catalyst": catalyst, "solvent": solvent, "yield_pct": round(y, 2)})
groups_df = pd.DataFrame(groups)
groups_df.to_csv(OUT / "grouped_categorical.csv", index=False)
print("Wrote grouped_categorical.csv")
# ── 6. Multi-column chemistry (Advanced / Correlation Heatmap) ───────────────
n_mol = 120
mol_props = pd.DataFrame(
{
"MW": rng.uniform(50, 500, n_mol),
"logP": rng.uniform(-2, 6, n_mol),
"TPSA": rng.uniform(0, 140, n_mol),
"HBD": rng.integers(0, 6, n_mol).astype(float),
"HBA": rng.integers(0, 11, n_mol).astype(float),
"RotBonds": rng.integers(0, 15, n_mol).astype(float),
}
)
# Add correlated activity column
mol_props["pIC50"] = (
0.012 * mol_props["MW"]
- 0.3 * mol_props["TPSA"]
+ 0.5 * mol_props["logP"]
+ rng.normal(0, 0.8, n_mol)
)
mol_props = mol_props.round(3)
mol_props.to_csv(OUT / "molecular_properties.csv", index=False)
print("Wrote molecular_properties.csv")
# ── 7. IR spectrum (Line Plot / Scatter) ─────────────────────────────────────
wavenumbers = np.arange(4000, 399, -2)
ir_spec = pd.DataFrame(
{
"wavenumber_cm-1": wavenumbers,
"transmittance": (
0.85
- 0.6 * np.exp(-(((wavenumbers - 2920) / 30) ** 2)) # C-H stretch
- 0.55 * np.exp(-(((wavenumbers - 1715) / 20) ** 2)) # C=O stretch
- 0.35 * np.exp(-(((wavenumbers - 3350) / 80) ** 2)) # O-H stretch
- 0.25 * np.exp(-(((wavenumbers - 1250) / 30) ** 2)) # C-O stretch
+ rng.normal(0, 0.015, len(wavenumbers))
).clip(0, 1),
}
)
ir_spec = ir_spec.round(4)
ir_spec.to_csv(OUT / "ir_spectrum.csv", index=False)
print("Wrote ir_spectrum.csv")
# ── 8. 2D Gaussian surface (Contour Plot, 3D Surface, Heatmap, Interactive) ──
grid_size = 60
xi = np.linspace(-3, 3, grid_size)
yi = np.linspace(-3, 3, grid_size)
Xi, Yi = np.meshgrid(xi, yi)
Z_gauss = np.exp(-0.5 * ((Xi - 0.5) ** 2 + (Yi - 0.5) ** 2)) + 0.6 * np.exp(
-0.5 * ((Xi + 1.0) ** 2 + (Yi + 1.0) ** 2)
)
np.save(OUT / "gaussian_surface.npy", Z_gauss)
print("Wrote gaussian_surface.npy (shape:", Z_gauss.shape, ")")
# ── 9. Correlation matrix-like heatmap (10 × 10) ─────────────────────────────
A = rng.standard_normal((50, 10))
corr_mat = np.corrcoef(A.T) # exact correlation matrix [-1, 1]
np.save(OUT / "correlation_matrix.npy", corr_mat)
print("Wrote correlation_matrix.npy (shape:", corr_mat.shape, ")")
# ── 10. Time-series kinetics (Line Plot / Interactive Line) ──────────────────
t = np.linspace(0, 60, 120) # minutes
k1, k2, k3 = 0.08, 0.04, 0.02
kinetics = pd.DataFrame(
{
"time_min": t,
"reactant_A": np.exp(-k1 * t),
"intermediate_B": (k1 / (k2 - k1)) * (np.exp(-k1 * t) - np.exp(-k2 * t)),
"product_C": 1 - np.exp(-k3 * t),
}
)
kinetics = kinetics.round(5)
kinetics.to_csv(OUT / "reaction_kinetics.csv", index=False)
print("Wrote reaction_kinetics.csv")
print("\nAll example datasets generated successfully.")