-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_mmse.py
More file actions
64 lines (50 loc) · 1.66 KB
/
Copy pathplot_mmse.py
File metadata and controls
64 lines (50 loc) · 1.66 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
import pandas as pd
import matplotlib.pyplot as plt
from pathlib import Path
# ----------------------------
# Paths
# ----------------------------
EXCEL_FILE = Path("/auto/home/users/v/l/vlahy/excel/TAU_Dg_neuro_complet_edit.xlsx")
SHEET_NAME = "DATA" # adapte si besoin
OUT_DIR = Path("/auto/home/users/v/l/vlahy/test/mmse_longitudinal")
OUT_DIR.mkdir(parents=True, exist_ok=True)
# ----------------------------
# 1) Read & clean Excel
# ----------------------------
df = pd.read_excel(EXCEL_FILE, sheet_name=SHEET_NAME)
# garder uniquement les lignes patients
df = df[df["ID"].astype(str).str.isdigit()].copy()
df["ID"] = df["ID"].astype(int)
df["Visit_number"] = pd.to_numeric(df["Visit_number"], errors="coerce")
df["MMSE"] = pd.to_numeric(df["MMSE"], errors="coerce")
# garder les lignes valides
df = df.dropna(subset=["Visit_number", "MMSE"]).copy()
# option : limiter les visits si nécessaire
df = df[df["Visit_number"].isin([0, 1, 2, 3, 4, 5])].copy()
df = df.sort_values(["ID", "Visit_number"])
print("N patients =", df["ID"].nunique())
# ----------------------------
# 2) Spaghetti plot (all patients)
# ----------------------------
plt.figure(figsize=(8, 6))
for pid, g in df.groupby("ID"):
if len(g) < 2:
continue # pas de ligne si une seule visite
plt.plot(
g["Visit_number"],
g["MMSE"],
color="gray",
alpha=0.25,
linewidth=1
)
plt.xlabel("Visit number")
plt.ylabel("MMSE")
plt.title("MMSE longitudinal trajectories (all patients)")
plt.grid(alpha=0.3)
plt.savefig(
OUT_DIR / "mmse_spaghetti_all_patients.png",
dpi=200,
bbox_inches="tight"
)
plt.close()
print("Saved spaghetti plot for all patients")