File size: 1,300 Bytes
17b7ba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
from typing import Any, Dict

from ..core import DecompResult
from ..registry import MethodRegistry

try:
    from synthetic_ts_bench.dr_ts_ae import dr_ts_ae_decompose
    _HAS_DR_TS_AE = True
except ImportError as exc:  # pragma: no cover - optional dependency path
    dr_ts_ae_decompose = None
    _HAS_DR_TS_AE = False
    _IMPORT_ERROR = exc


@MethodRegistry.register("DR_TS_AE")
def dr_ts_ae_wrapper(

    y: np.ndarray,

    params: Dict[str, Any],

) -> DecompResult:
    if not _HAS_DR_TS_AE:
        raise ImportError(
            "synthetic_ts_bench is required for DR_TS_AE decomposition."
        ) from _IMPORT_ERROR

    cfg = dict(params or {})
    meta = {}
    if "primary_period" in cfg:
        meta["primary_period"] = cfg["primary_period"]

    res = dr_ts_ae_decompose(
        np.asarray(y, dtype=float).ravel(),
        config=cfg,
        fs=float(cfg.get("fs", 1.0)),
        meta=meta or None,
    )
    meta_out = dict(getattr(res, "extra", {}) or {})
    meta_out.setdefault("method", "DR_TS_AE")
    return DecompResult(
        trend=np.asarray(res.trend, dtype=float),
        season=np.asarray(res.season, dtype=float),
        residual=np.asarray(res.residual, dtype=float),
        meta=meta_out,
    )