at.physics.harmonic_analysis#

Simplified version of harpy from Jaime Coello Maria de Portugal - Martinez Vazquez Github: pylhc/harpy

Functions

get_spectrum_harmonic(cent[, method, ...])

Frequency analysis of beam motion

get_main_harmonic(cents[, method, hann, ...])

Computes tunes, amplitudes and phases from harmonic analysis The tune is defined as the harmonic with the maximum amplitude within the search range.

get_tunes_harmonic(cents[, method, hann, ...])

Computes tunes from harmonic analysis.

get_main_harmonic(cents, method='interp_fft', hann=False, fmin=0, fmax=1, num_harmonics=1, maxiter=10, pad_length=None, use_mp=False, pool_size=None, start_method=None, remove_mean=True)[source]#

Computes tunes, amplitudes and phases from harmonic analysis The tune is defined as the harmonic with the maximum amplitude within the search range.

Parameters:
  • cents (ndarray) – Centroid motions of the particle

  • method (str) – 'interp_fft' or 'fft'. Default: 'interp_fft'

  • fmin (float) – Lower bound for tune search

  • fmax (float) – Upper bound for tune search

  • num_harmonics (int) – Number of harmonics to search for. Default=1.

  • maxiter (float) – Maximum number of iterations for the search

  • hann (bool) – Turn on Hanning window. Default: False. Ignored for interpolated FFT

  • pad_length – Zero pad the input signal. Rounded to the higher power of 2 Ignored for interpolated FFT

  • use_mp (bool) – Flag to activate multiprocessing (default: False)

  • pool_size (int | None) – number of processes used when use_mp is True. If None, min(npart,nproc) is used. It can be globally set using the variable at.lattice.DConstant.patpass_poolsize

  • start_method (str | None) – Python multiprocessing start method. Default None uses the OS default method.

  • remove_mean (bool) – Remove the mean of the input signal. Default: True.

Returns:
  • tunes (ndarray) – numpy array of length len(cents), max of the

  • spectrum within [fmin fmax]

  • amplitude (ndarray) – (len(cents), ) array of amplitudes corresponding to the tune

  • phase (ndarray) – (len(cents), ) array of phases corresponding to the tune

Note

  • The tune is defined as the harmonic with the maximum amplitude within the search range (fmin, fmax).

  • In case a Nan is present in the input vector or the tune cannot be found within the range, the function returns NaN.

  • For the method 'interp_fft', harmonics are calculated iteratively starting from the maximum peak of the raw FFT. num_harmonics=1 is the default, only the first harmonic is calculated. However, it is possible that the maximum of the interpolated FFT does not correspond to the maximum of the raw FFT, in which case num_harmonics has to be increased to get the correct peak.

get_spectrum_harmonic(cent, method='interp_fft', num_harmonics=20, hann=False, fmin=0, fmax=1, maxiter=10, pad_length=None, remove_mean=True)[source]#

Frequency analysis of beam motion

Parameters:
  • cent (ndarray) – Centroid motions of the particle

  • method (str) – 'interp_fft' or 'interp_fft'. Default: 'interp_fft'

  • num_harmonics (int) – Number of harmonics to search for with interp_fft

  • fmin (float) – Lower bound for spectrum search with interp_fft

  • fmax (float) – Upper bound for spectrum search with interp_fft

  • maxiter (float) – Multiplies num_harmonics to define the max. number of iteration for the search

  • hann (bool) – Turn on Hanning window. Default: False. Ignored for interpolated FFT

  • signal. (pad_length Zero pad the input) – Rounded to the higher power of 2 Ignored for interpolated FFT

  • remove_mean (bool) – Remove the mean of the input signal. Default: True.

Returns:
  • frequency (ndarray) – (num_harmonics,) array of frequencies

  • amplitude (ndarray) – (num_harmonics,) array of amplitudes

  • phase (ndarray) – (num_harmonics,) array of phases

get_tunes_harmonic(cents, method='interp_fft', hann=False, fmin=0, fmax=1, num_harmonics=1, maxiter=10, pad_length=None, use_mp=False, pool_size=None, start_method=None, remove_mean=True, **kwargs)[source]#

Computes tunes from harmonic analysis.

Parameters:
  • cents (ndarray) – Centroid motions of the particle

  • method (str) – 'interp_fft' or 'fft'. Default: 'interp_fft'

  • fmin (float) – Lower bound for tune search

  • fmax (float) – Upper bound for tune search

  • num_harmonics (int) – Number of harmonics to search for. Default=1.

  • maxiter (float) – Maximum number of iterations for the search

  • hann (bool) – Turn on Hanning window. Default: False. Ignored for interpolated FFT.

  • pad_length – Zero pad the input signal. Rounded to the higher power of 2 Ignored for interpolated FFT

  • use_mp (bool) – Flag to activate multiprocessing (default: False)

  • pool_size (int | None) – number of processes used when use_mp is True. If None, min(npart,nproc) is used. It can be globally set using the variable at.lattice.DConstant.patpass_poolsize

  • start_method (str | None) – Python multiprocessing start method. Default None uses the OS default method.

  • remove_mean (bool) – Remove the mean of the input signal. Default: True.

Returns:
  • tunes (ndarray) – numpy array of length len(cents), max of the

  • spectrum within [fmin fmax]

Note

  • The tune is defined as the harmonic with the maximum amplitude within the search range (fmin, fmax).

  • In case a Nan is present in the input vector or the tune cannot be found within the range, the function returns NaN.

  • For the method 'interp_fft', harmonics are calculated iteratively starting from the maximum peak of the raw FFT. num_harmonics=1 is the default, only the first harmonic is calculated. However, it is possible that the maximum of the interpolated FFT does not correspond to the maximum of the raw FFT, in which case num_harmonics has to be increased to get the correct peak.