code: def find_shift_pyr(ts1,ts2,nlevels):
      
      pyr1 = create_pyramid(ts1,nlevels)
      pyr2 = create_pyramid(ts2,nlevels)
      
      logger.debug("pyramid size = %d" % len(pyr1))
      logger.debug("size of first element %d " % np.size(pyr1[0]))
      logger.debug("size of last element %d " % np.size(pyr1[-1]))
  
      ishift, corrfn = zncc(pyr1[-1],pyr2[-1])
  
      for k in range(1,nlevels+1):
          ishift, corrfn = refine_correlation(pyr1[-k-1],pyr2[-k-1],ishift*2)
  
      return ishift
docs: Find shift that best aligns two time series
  
      The shift that aligns the timeseries ts1 with ts2.
      This is sought using zero mean normalized cross correlation (ZNCC) in a coarse to fine search with an octave pyramid on nlevels levels.
  
      Parameters
      ----------------
      ts1 : list_like
              The first timeseries
      ts2 : list_like
              The seconds timeseries
      nlevels : int
              Number of levels in pyramid
  
      Returns
      ----------------
         ts1_shift : float
                 How many samples to shift ts1 to align with ts2