Tools

A number of utility functions, for example for dealing with autocorrelation functions, Fourier transforms, and smoothing.

dynasor.tools.acfs.compute_acf(Z, delta_t=1.0, method='scipy')[source]

Computes the autocorrelation function (ACF) for a one-dimensional signal \(Z\) in time as

\[ACF(\tau) = \frac{\left < Z(t) Z^*(t+\tau) \right >}{\left < Z(t) Z^*(t) \right >}\]

Here, only the real part of the ACF is returned since if \(Z\) is complex the imaginary part should average out to zero for any stationary signal.

Parameters
  • Z (ndarray[Any, dtype[float]]) – complex time signal

  • delta_t (float) – spacing in time between two consecutive values in \(Z\)

  • method – implementation to use; possible values: numpy and scipy (default and usually faster)

dynasor.tools.acfs.fermi_dirac(t, t_0, t_width)[source]

Evaluates a Fermi-Dirac-like function in time \(f(t)\), which can be applied to an ACF in time to artificially damp it, i.e., forcing it to go to zero for long times without affecting the short-time correlations too much.

\[f(t) = \frac{1}{\exp{[(t-t_0)/t_\mathrm{width}}] + 1}\]
Parameters
  • t (ndarray[Any, dtype[float]]) – time array

  • t_0 (float) – starting time for decay

  • t_width (float) – width of the decay

dynasor.tools.acfs.gaussian_decay(t, t_sigma)[source]

Evaluates a gaussian distribution in time \(f(t)\), which can be applied to an ACF in time to artificially damp it, i.e., forcing it to go to zero for long times.

\[f(t) = \exp{\left [-\frac{1}{2} \left (\frac{t}{t_\mathrm{sigma}}\right )^2 \right ] }\]
Parameters
  • t (ndarray[Any, dtype[float]]) – time array

  • t_sigma (float) – width (standard deviation of the gaussian) of the decay

dynasor.tools.acfs.smoothing_function(data, window_size, window_type='hamming')[source]

Smoothing function for 1D arrays. This functions employs pandas rolling window average

Parameters
  • data (ndarray[Any, dtype[float]]) – 1D data array

  • window_size (int) – The size of smoothing/smearing window

  • window_type (str) – What type of window-shape to use, e.g. 'blackman', 'hamming', 'boxcar' (see pandas and scipy documentaiton for more details)

dynasor.tools.damped_harmonic_oscillator.acf_position_dho(t, w0, gamma, A=1.0)[source]

The damped damped harmonic oscillator (DHO) autocorrelation function for the position in the under-damped case.

\[F(t) = A \exp{ (-\Gamma t/2)} \left [ \cos(\omega_e t) + \frac{\Gamma}{2\omega_e} \sin(\omega_e t) \right ]\]

with

\[\omega_e = \sqrt{\omega_0^2 - \Gamma^2 / 4}\]
Parameters
  • t (ndarray[Any, dtype[float]]) – time array

  • w0 (float) – natural angular frequency of the DHO

  • gamma (float) – Damping of DHO

  • A (float) – amplitude of the DHO

dynasor.tools.damped_harmonic_oscillator.spectra_position_dho(w, w0, gamma, A=1.0)[source]

The damped harmonic oscillator (DHO) spectral function (i.e., the Fourier transform of the autocorrelation function) for the position.

\[S(\omega) = \frac{2 A \omega_0^2 \Gamma} {(\omega^2 - \omega_0^2)^2 + (\omega \Gamma)^2}\]
Parameters
  • w (ndarray[Any, dtype[float]]) – angular frequency array

  • w0 (float) – natural angular frequency of the DHO

  • gamma (float) – Damping of DHO

  • A (float) – amplitude of the DHO