code: def find_harmonics(y, m):
      # Compute a 2 x m moving average to estimate the trend
      window_size = 2 * m
      data = pd.DataFrame({"value": y})
      f_t = (
          data["value"].rolling(window=window_size, center=True).mean()
      )
  
      # Obtain an approximation of seasonal component using z_t = y_t - f_t
      data["f_t"] = f_t
      data["z_t"] = data["value"] - data["f_t"]
  
      # Drop missing values (due to the moving average)
      data.dropna(inplace=True)
  
      if data.empty:
          return 1
  
      # Approximate the seasonal component using trigonometric terms
      t = np.arange(len(data))
      if m % 2 == 0:
          max_harmonics = int(m / 2)
      else:
          max_harmonics = int((m - 1) / 2)
  
      max_harmonics = min(max_harmonics, len(data))
  
      aic = np.inf
      num_harmonics = 0
      for h in range(1, max_harmonics + 1):
          columns = []
          for i in range(1, h + 1):
              data[f"cos_{i}"] = np.cos(2 * np.pi * i * t / m)
              data[f"sin_{i}"] = np.sin(2 * np.pi * i * t / m)
              columns.extend([f"cos_{i}", f"sin_{i}"])
  
          # Perform regression to estimate the coefficients
          X = data[columns]
          y = data["z_t"]
          model = sm.OLS(y, X).fit()
          new_aic = model.aic
  
          if new_aic < aic:
              aic = new_aic
              num_harmonics = h
          else:
              break
  
      if num_harmonics == 0:
          num_harmonics += 1
  
      return num_harmonics
  
imports: import warnings
  from functools import partial
  import numpy
  import pandas
  import scipy.linalg
  import statsmodels.api
  from numba import njit
  from numpy.polynomial.polynomial import Polynomial
  from scipy.special import inv_boxcox
  from scipy.stats import boxcox
  from scipy.optimize import minimize
  from statsmodels.tsa.stattools import adfuller
  from .arima import auto_arima_f
  from .utils import NOGIL, CACHE
label_desc: Use image node_id 1 for calling a global function with example usage: find_harmonics(y, m) and returns: num_harmonics, int