def get_regression_coefs(train_array):
  """ Get regression coefficients for the training period """
  # Code from Google Earth Engine tutorial:
  # https://developers.google.com/earth-engine/reducers_regression
  # Define the axes of iation in the collection array.                 
  imageAxis = 0
  bandAxis = 1
  # Check the length of the image axis (number of images).
  arrayLength = train_array.arrayLength(imageAxis)
  # Update the mask to ensure that the number of images is greater than or
  # equal to the number of predictors (the linear model is solveable).
  train_array = train_array.updateMask(arrayLength.gt(3))
  # Get slices of the array according to positions along the band axis.
  predictors = train_array.arraySlice(bandAxis, 0, 3)
  response = train_array.arraySlice(bandAxis, 3)
  # coefficients = predictors.matrixSolve(response)
  coefficients = predictors.matrixPseudoInverse().matrixMultiply(response)
  # Turn the results into a multi-band image.
  coefficientsImage = coefficients.arrayProject([0]).arrayFlatten(
                        [['coef_constant', 'coef_sin', 'coef_cos']])
  return coefficientsImage