-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_data.py
More file actions
executable file
·139 lines (118 loc) · 5.46 KB
/
Copy pathplot_data.py
File metadata and controls
executable file
·139 lines (118 loc) · 5.46 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
import os
import matplotlib.pyplot as plt
import pandas as pd
# ========================= CONFIGURATION =========================
#LSB_SIZE_V = 4.096 / 32768
LSB_SIZE_V = 2.048 / 32768
LSB_SIZE_MV = LSB_SIZE_V * 1000
# ========================= LOAD OPTIONAL DATA =========================
has_compare = False
has_spectro = False
df_compare = None
df_spectro = None
spectro_filename = None
print("=== Recherche des fichiers CSV dans le dossier actuel ===")
# 1. Chargement optionnel de compare_results.csv
if os.path.exists("compare_results.csv"):
try:
df_compare = pd.read_csv("compare_results.csv")
df_compare['bruit_mv'] = df_compare['bruit'] * LSB_SIZE_MV
df_compare['signal_mv'] = df_compare['signal'] * LSB_SIZE_MV
df_compare['diff_mv'] = df_compare['signal_mv'] - df_compare['bruit_mv']
has_compare = True
print("✓ compare_results.csv chargé (comparaison bruit/signal)")
except Exception as e:
print(f"✗ Erreur lors du chargement de compare_results.csv : {e}")
else:
print(" compare_results.csv non trouvé → comparaison sautée")
# 2. Chargement optionnel du profil spectro (priorité à find_peak_results.csv, sinon find_peak_results.csv)
if os.path.exists("find_peak_results.csv"):
try:
df_spectro = pd.read_csv("find_peak_results.csv")
df_spectro['tension_mv'] = pd.to_numeric(df_spectro['tension_mv'], errors='coerce')
has_spectro = True
spectro_filename = "find_peak_results.csv"
print("✓ find_peak_results.csv chargé (profil de diffraction)")
except Exception as e:
print(f"✗ Erreur lors du chargement de find_peak_results.csv : {e}")
elif os.path.exists("find_peak_results.csv"):
try:
df_spectro = pd.read_csv("find_peak_results.csv")
df_spectro['tension_mv'] = pd.to_numeric(df_spectro['tension_mv'], errors='coerce')
has_spectro = True
spectro_filename = "find_peak_results.csv"
print("✓ find_peak_results.csv chargé (profil de diffraction)")
except Exception as e:
print(f"✗ Erreur lors du chargement de find_peak_results.csv : {e}")
else:
print(" Aucun fichier de profil (find_peak_results.csv ou find_peak_results.csv) trouvé → profil sauté")
if not has_compare and not has_spectro:
print("\n❌ Aucun fichier CSV trouvé dans le dossier. Rien à afficher.")
exit()
# ========================= PLOTTING (dynamique selon les fichiers présents) =========================
if has_compare and has_spectro:
# Les deux fichiers → 3 sous-graphiques
fig = plt.figure(figsize=(12, 10))
row_compare1 = 1
row_compare2 = 2
row_spectro = 3
suptitle = "Comparison + Spectro Data Analysis"
elif has_compare:
# Seulement compare → 2 sous-graphiques
fig = plt.figure(figsize=(12, 8))
row_compare1 = 1
row_compare2 = 2
row_spectro = None
suptitle = "Comparison Data Analysis (bruit / signal / différence)"
else:
# Seulement spectro → 1 graphique plein
fig = plt.figure(figsize=(12, 6))
row_compare1 = None
row_compare2 = None
row_spectro = 1
suptitle = f"Profil du Pic de Diffraction - {spectro_filename}"
# --- Graphique 1 & 2 : Compare (si présent) ---
if has_compare:
# Premier subplot : Bruit + Signal
ax1 = plt.subplot(3 if has_spectro else 2, 1, row_compare1)
ax1.plot(df_compare['bruit_mv'], label='Bruit (Noir)', alpha=0.7, color='gray')
ax1.plot(df_compare['signal_mv'], label='Signal (Lumière)', alpha=0.7, color='gold')
ax1.set_title("Signaux Bruts en Tension (mV) - compare_results.csv")
ax1.set_ylabel("Tension (mV)")
ax1.legend()
ax1.grid(True)
# Deuxième subplot : Différence nette
ax2 = plt.subplot(3 if has_spectro else 2, 1, row_compare2, sharex=ax1)
ax2.plot(df_compare['diff_mv'], label='Signal Net (Signal - Bruit)', color='red', linewidth=1.5)
ax2.axhline(0, color='black', linestyle='--', alpha=0.5)
ax2.set_title("Signal Différentiel Net (mV) - compare_results.csv")
ax2.set_ylabel("Tension (mV)")
ax2.set_xlabel("Échantillons / Temps (index)")
ax2.legend()
ax2.grid(True)
# --- Graphique 3 : Profil spectro / find_peak (si présent) ---
if has_spectro:
ax3 = plt.subplot(3 if has_compare else 1, 1, row_spectro)
# Tri optionnel pour un profil plus naturel (croissant)
df_plot = df_spectro.sort_values('pas_relatif')
line1 = ax3.plot(df_plot['pas_relatif'], df_plot['tension_mv'],
label='Tension (mV)', color='blue', linewidth=1.5)
ax3.set_ylabel("Tension (mV)", color='blue')
ax3.tick_params(axis='y', labelcolor='blue')
ax3.set_xlabel("Pas Relatif (0 = Position initiale)")
ax3.grid(True, alpha=0.3)
# Double axe bits ADC
ax3b = ax3.twinx()
line2 = ax3b.plot(df_plot['pas_relatif'], df_plot['bits_adc'],
label='ADC Bits (raw)', color='purple', linestyle='--', alpha=0.5)
ax3b.set_ylabel("Bits ADC (Brut)", color='purple')
ax3b.tick_params(axis='y', labelcolor='purple')
# Légende combinée
lns = line1 + line2
labs = [l.get_label() for l in lns]
ax3.legend(lns, labs, loc='upper right')
ax3.set_title(f"Profil du Pic de Diffraction ({spectro_filename})")
# Supertitre global
plt.suptitle(suptitle, fontsize=14, fontweight='bold')
plt.tight_layout(rect=[0, 0, 1, 0.96]) # Espace pour le suptitle
plt.show()