"""CPV1-v2 · paso 12 (Python puro): la lista LOSO de cada ventana por la regla del pre-registro v2 §0.7 (S de L con ≥ 1.000 filas de E en la ventana que se mide, recontadas en interno/datos/E.tsv) y las especificaciones de los entrenamientos (py/specs_val.json: M_en ≤ 2024 y M_fu ≤ 2024 sin S; py/specs_prueba.json: M_en y M_fu ≤ 2025 y M_fu ≤ 2025 sin S). Escribe salidas/12_fuentes.json.""" import json, collections L = ['ANDALUCIA', 'CATALUNYA', 'CATALUNYA_PSCP', 'EUSKADI', 'EXTREMADURA', 'VALENCIA', 'ARAGON', 'TED', 'MURCIA'] n = collections.Counter() with open('/w/interno/datos/E.tsv', encoding='utf-8') as f: cab = f.readline().rstrip('\n').split('\t'); I = {c: i for i, c in enumerate(cab)} for l in f: r = l.rstrip('\n').split('\t') a = r[I['anio_ref']] if a in ('2025', '2026'): n[(r[I['source']], a)] += 1 L25 = [s for s in L if n[(s, '2025')] >= 1000]; L26 = [s for s in L if n[(s, '2026')] >= 1000] base = {'F': 'F1', 'alpha': 1e-06, 'taus': [0.1], 'objetivo': 'div'} val = [dict(base, nombre='v24_en', corte=2024)] + [dict(base, nombre=f'v24fu_sin_{s}', corte=2024, excluir=[s], sin_organo=True) for s in L25] pru = [dict(base, nombre='f25_en', corte=2025), dict(base, nombre='f25_fu', corte=2025, sin_organo=True)] + \ [dict(base, nombre=f'f25fu_sin_{s}', corte=2025, excluir=[s], sin_organo=True) for s in L26] json.dump(val, open('/w/py/specs_val.json', 'w'), indent=1); json.dump(pru, open('/w/py/specs_prueba.json', 'w'), indent=1) out = {'recuento': {f'{s}|{a}': n[(s, a)] for s in L for a in ('2025', '2026')}, 'L_validacion_2025': L25, 'L_prueba_2026': L26} json.dump(out, open('/w/salidas/12_fuentes.json', 'w'), indent=1) print(json.dumps(out, indent=1))