parameters: (y, x=None, nc=None, xc=None, err=None)
return_statement: return sum((B * coeff).T), HarmFunctor(A, coeff, xmi, xspan)
docstring: Python-based curve-fit by harmonic functions.
  
      Parameters
      ----------
      y : iterable
          values of a curve to be fitted
      x : iterable
          abscissa, if none [0..len(y))
      nc : int
          number of coefficients
      err : iterable
          absolute data error
      xc : iterable
          abscissa to predict y on (otherwise equal to x)
docstring_summary: Python-based curve-fit by harmonic functions.
docstring_tokens: Python - based curve - fit by harmonic functions .
function: def harmfitNative(y, x=None, nc=None, xc=None, err=None):
      """Python-based curve-fit by harmonic functions.
  
      Parameters
      ----------
      y : iterable
          values of a curve to be fitted
      x : iterable
          abscissa, if none [0..len(y))
      nc : int
          number of coefficients
      err : iterable
          absolute data error
      xc : iterable
          abscissa to predict y on (otherwise equal to x)
      """
      y = np.asarray(y)
  
      if x is None:
          x = list(range(len(y)))
  
      x = np.asarray(x)
  
      if xc is not None:
          xc = np.asarray(xc)
      else:
          xc = x
  
      if err is None:
          err = np.ones((1, len(x)))  # ones(size(x)) end
  
      if nc is None or nc == 0:
          # nc=round(length(x)/30) % number of coefficients
          nc = int(len(x) / 30)
  
      xspan = max(x) - min(x)
      xmi = min(x)
  
      # A=ones(length(x),nc*2+2)/2 %nc*(sin+cos)+offset+drift
      A = np.ones((len(x), nc * 2 + 2)) / 2.0  # %nc*(sin+cos)+offset+drift
      # B=ones(length(xc),nc*2+2)/2
      B = np.ones((len(xc), nc * 2 + 2)) / 2.0
  
      A[:, 1] = x[:] * 3.0
      B[:, 1] = xc[:] * 3.0
  
      for i in range(1, nc + 1):
          # A(:,i*2+1)=sin(2*i*pi*(x-xmi)/xspan)
          # A(:,i*2+2)=cos(2*i*pi*(x-xmi)/xspan)
          # B(:,i*2+1)=sin(2*i*pi*(xc(:)-xmi)/xspan)
          # B(:,i*2+2)=cos(2*i*pi*(xc(:)-xmi)/xspan)
  
          A[:, i * 2 + 0] = np.sin(2.0 * i * np.pi * (x - xmi) / xspan)
          A[:, i * 2 + 1] = np.cos(2.0 * i * np.pi * (x - xmi) / xspan)
          B[:, i * 2 + 0] = np.sin(2.0 * i * np.pi * (xc - xmi) / xspan)
          B[:, i * 2 + 1] = np.cos(2.0 * i * np.pi * (xc - xmi) / xspan)
  
      # w = 1.0 / err w(~isfinite(w))=0
      w = 1.0 / err
      # w[(~isfinite(w)]=0
  
      # coeff=(spdiags(w,0,length(w),length(w))*A)\(y.*w)
      # WA = np.diag(w, 0).dot(A)
      # coeff, res, rank, s = np.linalg.lstsq(WA, y * w, rcond=None)
      coeff, res, rank, s = np.linalg.lstsq(np.diag(w, 0) * A, (y * w)[0, :],
                                            rcond=None)
  
      return sum((B * coeff).T), HarmFunctor(A, coeff, xmi, xspan)
function_tokens: def harmfitNative ( y , x = None , nc = None , xc = None , err = None ) : y = np . asarray ( y ) if x is None : x = list ( range ( len ( y ) ) ) x = np . asarray ( x ) if xc is not None : xc = np . asarray ( xc ) else : xc = x if err is None : err = np . ones ( ( 1 , len ( x ) ) ) # ones(size(x)) end if nc is None or nc == 0 : # nc=round(length(x)/30) % number of coefficients nc = int ( len ( x ) / 30 ) xspan = max ( x ) - min ( x ) xmi = min ( x ) # A=ones(length(x),nc*2+2)/2 %nc*(sin+cos)+offset+drift A = np . ones ( ( len ( x ) , nc * 2 + 2 ) ) / 2.0 # %nc*(sin+cos)+offset+drift # B=ones(length(xc),nc*2+2)/2 B = np . ones ( ( len ( xc ) , nc * 2 + 2 ) ) / 2.0 A [ : , 1 ] = x [ : ] * 3.0 B [ : , 1 ] = xc [ : ] * 3.0 for i in range ( 1 , nc + 1 ) : # A(:,i*2+1)=sin(2*i*pi*(x-xmi)/xspan) # A(:,i*2+2)=cos(2*i*pi*(x-xmi)/xspan) # B(:,i*2+1)=sin(2*i*pi*(xc(:)-xmi)/xspan) # B(:,i*2+2)=cos(2*i*pi*(xc(:)-xmi)/xspan) A [ : , i * 2 + 0 ] = np . sin ( 2.0 * i * np . pi * ( x - xmi ) / xspan ) A [ : , i * 2 + 1 ] = np . cos ( 2.0 * i * np . pi * ( x - xmi ) / xspan ) B [ : , i * 2 + 0 ] = np . sin ( 2.0 * i * np . pi * ( xc - xmi ) / xspan ) B [ : , i * 2 + 1 ] = np . cos ( 2.0 * i * np . pi * ( xc - xmi ) / xspan ) # w = 1.0 / err w(~isfinite(w))=0 w = 1.0 / err # w[(~isfinite(w)]=0 # coeff=(spdiags(w,0,length(w),length(w))*A)\(y.*w) # WA = np.diag(w, 0).dot(A) # coeff, res, rank, s = np.linalg.lstsq(WA, y * w, rcond=None) coeff , res , rank , s = np . linalg . lstsq ( np . diag ( w , 0 ) * A , ( y * w ) [ 0 , : ] , rcond = None ) return sum ( ( B * coeff ) . T ) , HarmFunctor ( A , coeff , xmi , xspan )