code: def etscalc(
      y,
      n,
      x,
      m,
      error,
      trend,
      season,
      alpha,
      beta,
      gamma,
      phi,
      e,
      amse,
      nmse,
  ):
      oldb = 0.0
      olds = np.zeros(max(24, m))
      s = np.zeros(max(24, m))
      f = np.zeros(30)
      denom = np.zeros(30)
      if m < 1:
          m = 1
      if nmse > 30:
          nmse = 30
      nstates = m * (season > NONE) + 1 + (trend > NONE)
      # Copy initial state components
      l = x[0]
      if trend > NONE:
          b = x[1]
      else:
          b = 0.0
      if season > NONE:
          for j in range(m):
              s[j] = x[(trend > NONE) + j + 1]
      lik = 0.0
      lik2 = 0.0
      for j in range(nmse):
          amse[j] = 0.0
          denom[j] = 0.0
      for i in range(n):
          # Copy previous state
          oldl = l
          if trend > NONE:
              oldb = b
          if season > NONE:
              for j in range(m):
                  olds[j] = s[j]
          # one step forecast
          forecast(oldl, oldb, olds, m, trend, season, phi, f, nmse)
          if math.fabs(f[0] - NA) < TOL:
              lik = NA
              return lik
          if error == ADD:
              e[i] = y[i] - f[0]
          else:
              if math.fabs(f[0]) < TOL:
                  f_0 = f[0] + TOL
              else:
                  f_0 = f[0]
              e[i] = (y[i] - f[0]) / f_0
          for j in range(nmse):
              if (i + j) < n:
                  denom[j] += 1.0
                  tmp = y[i + j] - f[j]
                  amse[j] = (
                      amse[j] * (denom[j] - 1.0) + (tmp * tmp)
                  ) / denom[j]
          # update state
          l, b, s = update(
              oldl,
              l,
              oldb,
              b,
              olds,
              s,
              m,
              trend,
              season,
              alpha,
              beta,
              gamma,
              phi,
              y[i],
          )
          # store new state
          x[nstates * (i + 1)] = l
          if trend > NONE:
              x[nstates * (i + 1) + 1] = b
          if season > NONE:
              for j in range(m):
                  x[nstates * (i + 1) + (trend > NONE) + j + 1] = s[j]
          lik = lik + e[i] * e[i]
          val = math.fabs(f[0])
          if val > 0.0:
              lik2 += math.log(val)
          else:
              lik2 += math.log(val + 1e-8)
      if lik > 0.0:
          lik = n * math.log(lik)
      else:
          lik = n * math.log(lik + 1e-8)
      if error == MULT:
          lik += 2 * lik2
      return lik
  
imports: import math
  from collections import namedtuple
  from typing import Tuple
  import numpy
  from numba import njit
  from numba.typed import List
  from statsmodels.tsa.seasonal import seasonal_decompose
  from .utils import _calculate_intervals, CACHE, NOGIL
label_desc: Use image node_id 1 for calling a global function with example usage: etscalc(y, n, x, m, error, trend, season, alpha, beta, gamma, phi, e, amse, nmse) and returns: lik, lik