F2b: TEA record after the 3 Dec review

Translate EEG quality value text and units into Spanish without changing
check codes, stored triage identifiers, thresholds or analysis behavior.

Choices left open by the spec:
- Use Canal muerto, Señal congelada, Señal saturada and Valores infinitos
  for temporal findings.
- Describe channel gaps as Interrupciones del canal with the excess
  percentage followed by más que el resto; bridges as Puente con followed
  by the electrode; amplitude as veces la mediana del cuero cabelludo.
- Describe failed correlation as Sin correlación con los vecinos with
  the two values separated by frente a; contact loss as Contacto
  intermitente with the percentage de bloques sin señal; bursts as
  Contacto intermitente por ráfagas with the percentage de bloques por
  encima de 4 veces el montaje.
- Render auxiliary amplitude in µV with fuera de rango incluso para and
  the existing auxiliary channel type.
- Use fracción and electrodos as the translated units; keep % and dB.
- Display triage as No analizable, Parcial, Sin referencia auricular or
  Completo, retaining not_analyzable, partial, no_ear_reference and complete
  as the stored identifiers.
- Detect the dead-channel finding by its code rather than matching its
  translated text, preserving the existing early exit for dead channels.

Verification from the superproject root with its Ruff configuration:
ruff check passed; ruff format --check passed for all 144 Python files;
git diff --check passed. Python imports did not change. No heavy checks
were run on the lab server, as specified. No API schema changes.
This commit is contained in:
2026-12-03 13:51:40 -06:00
parent 4056297608
commit 4c24d4efca
+32 -20
View File
@@ -70,14 +70,14 @@ def _filtered(x, fs, mains_hz, lo, hi):
def _temporal(v: np.ndarray) -> list[tuple[str, str]]:
finite = v[np.isfinite(v)]
if len(finite) < 10 or np.std(finite) < 0.5:
return [("dead-channel", "dead channel")]
return [("dead-channel", "Canal muerto")]
out = []
if np.mean(np.abs(np.diff(finite)) < 1e-9) > 0.5:
out.append(("frozen", "frozen"))
out.append(("frozen", "Señal congelada"))
if np.mean(np.abs(finite) > 0.98 * np.max(np.abs(finite))) > 0.001:
out.append(("saturated", "saturated"))
out.append(("saturated", "Señal saturada"))
if np.isinf(v).any():
out.append(("inf-values", "Inf values"))
out.append(("inf-values", "Valores infinitos"))
return out
@@ -140,9 +140,7 @@ def _ears(y: np.ndarray, fs: float, names: list[str]) -> dict[str, tuple[float,
def bad_channels(rec: Recording, mains_hz: float) -> dict[str, list[tuple[str, str]]]:
x, fs, names, kinds = rec.x, rec.fs, list(rec.names), rec.kinds()
reasons = {name: _temporal(x[:, i]) for i, name in enumerate(names)}
dead = {
name for name, found in reasons.items() if found[:1] == [("dead-channel", "dead channel")]
}
dead = {name for name, found in reasons.items() if found and found[0][0] == "dead-channel"}
notched = signals.notch(x, fs, mains_hz)
y45 = signals.bandpass(notched, fs, 0.5, min(45.0, fs / 2 * 0.9))
y40 = signals.bandpass(notched, fs, 1.0, 40.0)
@@ -158,34 +156,38 @@ def bad_channels(rec: Recording, mains_hz: float) -> dict[str, list[tuple[str, s
found, k = reasons[name], kinds[name]
if missing[i] > missing.min() + 0.02:
excess = 100 * (missing[i] - missing.min())
found.append(("own-gaps", f"own gaps ({excess:.1f}% more than the rest)"))
found.append(
("own-gaps", f"Interrupciones del canal ({excess:.1f} % más que el resto)")
)
if name in dead:
continue
if k == "eeg" and name in bridges:
found.append(("bridge", f"bridge with {bridges[name]}"))
found.append(("bridge", f"Puente con {bridges[name]}"))
if k in ("eeg", "ear") and np.isfinite(ratio[i]) and ratio[i] > 4.0:
found.append(("amplitude", f"amplitude {ratio[i]:.1f} x the scalp median"))
found.append(
("amplitude", f"Amplitud {ratio[i]:.1f} veces la mediana del cuero cabelludo")
)
if name in ears and ears[name][1] > 0.2 and ears[name][0] < 0.5 * ears[name][1]:
c, e = ears[name]
found.append(
(
"does-not-correlate",
f"does not correlate with its neighbours ({c:.2f} vs {e:.2f})",
f"Sin correlación con los vecinos ({c:.2f} frente a {e:.2f})",
)
)
if np.isfinite(low[i]) and low[i] > 0.10:
found.append(
(
"intermittent-contact",
f"intermittent contact ({100 * low[i]:.0f}% of blocks silent)",
f"Contacto intermitente ({100 * low[i]:.0f} % de bloques sin señal)",
)
)
if k in ("eeg", "ear") and np.isfinite(burst[i]) and burst[i] > 0.05:
found.append(
(
"intermittent-bursts",
f"intermittent contact by bursts "
f"({100 * burst[i]:.0f}% of blocks above 4 x the montage)",
f"Contacto intermitente por ráfagas "
f"({100 * burst[i]:.0f} % de bloques por encima de 4 veces el montaje)",
)
)
if k in ("eog", "ecg"):
@@ -194,8 +196,8 @@ def bad_channels(rec: Recording, mains_hz: float) -> dict[str, list[tuple[str, s
found.append(
(
"aux-amplitude",
f"amplitude {np.sqrt(np.mean(v**2)):.0f} uV, "
f"out of range even for {k.upper()}",
f"Amplitud {np.sqrt(np.mean(v**2)):.0f} µV, "
f"fuera de rango incluso para {k.upper()}",
)
)
return {name: found for name, found in reasons.items() if found}
@@ -286,7 +288,7 @@ def validate(rec: Recording, mains_hz: float) -> Validation:
check(
"internal-coverage",
value=coverage,
unit="fraction",
unit="fracción",
low=MIN_COVERAGE,
abnormal=coverage < MIN_COVERAGE,
decisive=True,
@@ -294,7 +296,7 @@ def validate(rec: Recording, mains_hz: float) -> Validation:
check(
"bad-scalp-triage",
value=float(len(triaged)),
unit="electrodes",
unit="electrodos",
high=float(MAX_BAD_SCALP),
abnormal=len(triaged) > MAX_BAD_SCALP,
decisive=True,
@@ -302,12 +304,22 @@ def validate(rec: Recording, mains_hz: float) -> Validation:
check(
"usable-scalp",
value=float(len(usable)),
unit="electrodes",
unit="electrodos",
low=float(MIN_SCALP),
abnormal=len(usable) < MIN_SCALP,
decisive=True,
),
check("triage-level", text=level, abnormal=level == NOT_ANALYZABLE, decisive=True),
check(
"triage-level",
text={
NOT_ANALYZABLE: "No analizable",
"partial": "Parcial",
"no_ear_reference": "Sin referencia auricular",
"complete": "Completo",
}[level],
abnormal=level == NOT_ANALYZABLE,
decisive=True,
),
]
if np.isfinite(line):
rows.append(