Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions PyNAFF/PyNAFF.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
except ImportError:
from __builtin__ import range, int
import numpy as np
import math
"""
# NAFF - Numerical Analysis of Fundamental Frequencies
# Version : 1.1.4
Expand All @@ -18,7 +19,7 @@
__contact = ['nkarast .at. cern .dot. ch']


def naff(data, turns=300, nterms=1, skipTurns=0, getFullSpectrum=False, window=1):
def naff(data, turns=300, nterms=1, skipTurns=0, getFullSpectrum=False, window=1, warnings=False):
'''
The driving function for the NAFF algorithm.
Inputs :
Expand Down Expand Up @@ -141,7 +142,7 @@ def fretes(FR, FREFON):
for i in range(len(vars['TFS'])):
TEST = np.abs(vars['TFS'][i] - FR)
if TEST < ECART:
if np.float(TEST)/np.float(ECART) < TOL:
if float(TEST)/float(ECART) < TOL:
IFLAG = -1
NUMFR = i
break
Expand Down Expand Up @@ -208,7 +209,7 @@ def gramsc(turns, FR, A, B):
ZDIV = ZDIV + np.conj(vars['ZALP'][NF-1, i])*ZTEE[i]
DIV = np.sqrt(np.abs(ZDIV))
vars['ZALP'][NF-1,:] = vars['ZALP'][NF-1,:]/DIV
ZMUL = np.complex(A,B)/DIV
ZMUL = complex(A,B)/DIV
ZI = 0.0+1.0j

for i in range(0, NF):
Expand All @@ -229,7 +230,7 @@ def gramsc(turns, FR, A, B):

T = np.linspace(0, turns, num=turns+1, endpoint=True)*2.0*np.pi - np.pi*turns
vars['TWIN'] = 1.0+np.cos(T/turns)
vars['TWIN'] = ((2.0**window*np.math.factorial(window)**2)/float(np.math.factorial(2*window)))*(1.0+np.cos(T/turns))**window
vars['TWIN'] = ((2.0**window*math.factorial(window)**2)/float(math.factorial(2*window)))*(1.0+np.cos(T/turns))**window
vars['ZTABS'] = data[skipTurns:skipTurns+turns+1]

TOL = 1.0e-4
Expand All @@ -239,13 +240,13 @@ def gramsc(turns, FR, A, B):
if getFullSpectrum:
y = np.fft.fft(data_for_fft)
else:
y = np.fft.rfft(data_for_fft.astype('float64'))
y = np.fft.rfft(np.real(data_for_fft))#.astype('float64'))

RTAB = np.sqrt(np.real(y)**2 + np.imag(y)**2)/turns # normalized
INDX = np.argmax(RTAB)
VMAX = np.max(RTAB)

if INDX == 0 :
if INDX == 0 and warnings :
print('## PyNAFF::naff: Remove the DC component from the data (i.e. the mean).')
if INDX <= turns/2.0:
IFR = INDX - 1
Expand Down
Binary file added PyNAFF/__pycache__/PyNAFF.cpython-313.pyc
Binary file not shown.