code: def extract_trend_and_seasonality(
      ts: TimeSeries,
      freq: Union[int, Sequence[int]] = None,
      model: Union[
          SeasonalityMode, ModelMode
      ] = ModelMode.MULTIPLICATIVE,
      method: str = "naive",
      **kwargs,
  ) -> Tuple[TimeSeries, TimeSeries]:
      """
      Extracts trend and seasonality from a TimeSeries instance using `statsmodels.tsa`.
  
      Parameters
      ----------
      ts
          The series to decompose
      freq
          The seasonality period to use.
      model
          The type of decomposition to use.
          Must be ``from darts.utils.utils import ModelMode, SeasonalityMode`` Enum member.
          Either ``MULTIPLICATIVE`` or ``ADDITIVE``.
          Defaults ``ModelMode.MULTIPLICATIVE``.
      method
          The method to be used to decompose the series.
          - "naive" : Seasonal decomposition using moving averages [1]_.
          - "STL" : Season-Trend decomposition using LOESS [2]_. Only compatible with ``ADDITIVE`` model type.
          - "MSTL" : Season-Trend decomposition using LOESS with multiple seasonalities [3]_.
          Only compatible with ``ADDITIVE`` model type.
      kwargs
          Other keyword arguments are passed down to the decomposition method.
  
      Returns
      -------
      Tuple[TimeSeries, TimeSeries]
          A tuple of (trend, seasonal) time series.
  
      References
      ----------
      .. [1] https://www.statsmodels.org/devel/generated/statsmodels.tsa.seasonal.seasonal_decompose.html
      .. [2] https://www.statsmodels.org/devel/generated/statsmodels.tsa.seasonal.STL.html
      .. [3] https://www.statsmodels.org/devel/generated/statsmodels.tsa.seasonal.MSTL.html
      """
  
      ts._assert_univariate()
      raise_if_not(
          model in ModelMode or model in SeasonalityMode,
          f"Unknown value for model_mode: {model}.",
          logger,
      )
  
      raise_if_not(
          model is not SeasonalityMode.NONE,
          "The model must be either MULTIPLICATIVE or ADDITIVE.",
      )
  
      raise_if(
          isinstance(freq, Sequence) and method != "MSTL",
          f"{method} decomposition cannot be performed with more than one seasonality, received {freq}.",
      )
  
      if method == "naive":
          decomp = seasonal_decompose(
              ts.pd_series(),
              period=freq,
              model=model.value,
              extrapolate_trend="freq",
          )
  
      elif method == "STL":
          raise_if_not(
              model in [SeasonalityMode.ADDITIVE, ModelMode.ADDITIVE],
              f"Only ADDITIVE model is compatible with the STL method. Current model is {model}.",
              logger,
          )
  
          decomp = STL(
              endog=ts.pd_series(),
              period=freq,
              **kwargs,
          ).fit()
  
      elif method == "MSTL":
          raise_if_not(
              model in [SeasonalityMode.ADDITIVE, ModelMode.ADDITIVE],
              f"Only ADDITIVE model is compatible with the MSTL method. Current model is {model}.",
              logger,
          )
  
          decomp = MSTL(
              endog=ts.pd_series(),
              periods=freq,
              **kwargs,
          ).fit()
  
      else:
          raise_log(
              ValueError(f"Unknown value for method: {method}"), logger
          )
  
      season = TimeSeries.from_times_and_values(
          ts.time_index,
          decomp.seasonal,
          static_covariates=ts.static_covariates,
          hierarchy=ts.hierarchy,
      )
      trend = TimeSeries.from_times_and_values(
          ts.time_index,
          decomp.trend,
          static_covariates=ts.static_covariates,
          hierarchy=ts.hierarchy,
      )
  
      return trend, season
  
imports: import math
  from typing import List, Optional, Sequence, Tuple, Union
  import matplotlib.pyplot
  import numpy
  from scipy.signal import argrelmax
  from scipy.stats import norm
  from statsmodels.tsa.seasonal import MSTL, STL, seasonal_decompose
  from statsmodels.tsa.stattools import acf, adfuller, grangercausalitytests, kpss, pacf
  from darts import TimeSeries
  from darts.logging import get_logger, raise_if, raise_if_not, raise_log
  from .missing_values import fill_missing_values
  from .utils import ModelMode, SeasonalityMode
label_desc: Use image node_id 3 for calling a global function with example usage: extract_trend_and_seasonality(ts, freq, model, method) and returns: trend,  season