2026-10-29 10:13:01 +01:00
|
|
|
|
"""Fixture comuni: configurazione, segnale sintetico (verità nota) e CSV generati da gen_data (se presenti)."""
|
|
|
|
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
import numpy as np
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
|
|
from fitseg import config
|
|
|
|
|
|
|
|
|
|
|
|
RADICE = Path(__file__).parent.parent
|
|
|
|
|
|
SEEDS = [1, 2, 3]
|
|
|
|
|
|
|
|
|
|
|
|
# verità del segnale sintetico
|
|
|
|
|
|
TAU, T_AMB = 16.0, 23.0
|
|
|
|
|
|
GRADINI = [(15.0, 80.0), (18.0, 70.0), (22.0, 60.0)] # (istante [s], ampiezza [°C])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
|
|
def cfg():
|
|
|
|
|
|
return config.leggi(RADICE / "config.toml")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def segnale(rumore=0.1, seed=0, gradini=GRADINI, durata=120.0, dt=0.15):
|
|
|
|
|
|
"""T(t) = ambiente + Σ ampiezza·exp(−(t−t_j)/τ) per t ≥ t_j, più rumore gaussiano: nessun disturbo a salto."""
|
|
|
|
|
|
rng = np.random.default_rng(seed)
|
|
|
|
|
|
t = np.arange(dt, durata, dt)
|
|
|
|
|
|
x = sum(a * np.exp(-(t - tj) / TAU) * (t >= tj) for tj, a in gradini) if gradini else np.zeros_like(t)
|
|
|
|
|
|
T = T_AMB + x + rumore * rng.standard_normal(len(t))
|
|
|
|
|
|
return t, {"T_C": T, "dT_C": T - T_AMB}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
|
|
def sintetico():
|
|
|
|
|
|
return segnale()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(params=SEEDS)
|
|
|
|
|
|
def csv_gen(request):
|
2026-10-29 10:18:12 +01:00
|
|
|
|
"""CSV prodotto da gen_data per il seed; il test è saltato se il file non c'è (input/*.csv non è in git)."""
|
|
|
|
|
|
percorso = RADICE / f"input/gen_{request.param}.csv"
|
2026-10-29 10:13:01 +01:00
|
|
|
|
if not percorso.exists():
|
|
|
|
|
|
pytest.skip(f"{percorso} assente: rigenera con gen_data (vedi README)")
|
|
|
|
|
|
return percorso
|