Lv2_dj_lsp.py
def lsp(times, rates):
	"""
	cast times and rates as numpy arrays
	"""
	times = np.array(times)
	rates = np.array(rates)
	"""
	Set the initial time to 0
	"""
	tmin = min(times)
	times = times - tmin
	"""
	calculate the number of independent frequencies
	"""
	n0 = len(times)
	Ni = int(-6.362 + 1.193*n0 + 0.00098*n0**2)

	"""
	estimate the minimum and maximum frequencies to be sampled
	"""
	fmin = 1/np.max(times)
	fmax = n0/(2.0*np.max(times))
	#print('Minimum frequency: ' + str(fmin))
	#print('Maximum frequency: ' + str(fmax))
	#print(fmax)
	fmax = 1e-5

	"""
	The frequencies that will be sampled
	"""
	omega = 2*np.pi *(fmin+(fmax-fmin)*np.arange(Ni)/(Ni-1.))

	"""
	subtract the mean from data
	"""
	cn = rates - np.mean(rates)
	"""
	compute the lsp
	"""
	psd = np.zeros(Ni)

	print('Calculating the PSD...')
	for i in tqdm(range(Ni)):
		tau = np.arctan(np.sum(np.sin(2.*omega[i]*times))/np.sum(np.cos(2.*omega[i]*times)))
		tau = tau/(2*omega[i])

		co = np.cos(omega[i]*(times-tau))
		si = np.sin(omega[i]*(times-tau))
		psd[i] = 0.5*(np.sum(cn*co)**2/np.sum(co**2)+np.sum(cn*si)**2/np.sum(si**2))
	"""
	correct normalization
	"""
	var = np.std(cn)
	psd = psd/var**2

	"""
	calculate the false alarm probabilities
	"""

	sigmathree=2.7e-03
	sigmafour=6.33e-05
	sigmafive=5.73e-7

	probthree = -np.log(1.0 - ((1.0-sigmathree)**(1./Ni))  )
	probfour = -np.log(1.0 - ((1.0-sigmafour)**(1./Ni))  )
	probfive = -np.log(1.0 - ((1.0-sigmafive)**(1./Ni))  )

	return omega, psd, probthree, probfour, probfive

	cast times and rates as numpy arrays
	
cast times and rates as numpy arrays
cast times and rates as numpy arrays
def lsp(times, rates):
	times = np.array(times)
	rates = np.array(rates)
	tmin = min(times)
	times = times - tmin
	n0 = len(times)
	Ni = int(-6.362 + 1.193*n0 + 0.00098*n0**2)
	fmin = 1/np.max(times)
	fmax = n0/(2.0*np.max(times))
	fmax = 1e-5
	omega = 2*np.pi *(fmin+(fmax-fmin)*np.arange(Ni)/(Ni-1.))
	cn = rates - np.mean(rates)
	psd = np.zeros(Ni)
	print('Calculating the PSD...')
	for i in tqdm(range(Ni)):
		tau = np.arctan(np.sum(np.sin(2.*omega[i]*times))/np.sum(np.cos(2.*omega[i]*times)))
		tau = tau/(2*omega[i])
		co = np.cos(omega[i]*(times-tau))
		si = np.sin(omega[i]*(times-tau))
		psd[i] = 0.5*(np.sum(cn*co)**2/np.sum(co**2)+np.sum(cn*si)**2/np.sum(si**2))
	var = np.std(cn)
	psd = psd/var**2
	sigmathree=2.7e-03
	sigmafour=6.33e-05
	sigmafive=5.73e-7
	probthree = -np.log(1.0 - ((1.0-sigmathree)**(1./Ni))  )
	probfour = -np.log(1.0 - ((1.0-sigmafour)**(1./Ni))  )
	probfive = -np.log(1.0 - ((1.0-sigmafive)**(1./Ni))  )
	return omega, psd, probthree, probfour, probfive
def lsp ( times , rates ) : times = np . array ( times ) rates = np . array ( rates ) """
	Set the initial time to 0
	""" tmin = min ( times ) times = times - tmin """
	calculate the number of independent frequencies
	""" n0 = len ( times ) Ni = int ( - 6.362 + 1.193 * n0 + 0.00098 * n0 ** 2 ) """
	estimate the minimum and maximum frequencies to be sampled
	""" fmin = 1 / np . max ( times ) fmax = n0 / ( 2.0 * np . max ( times ) ) fmax = 1e-5 """
	The frequencies that will be sampled
	""" omega = 2 * np . pi * ( fmin + ( fmax - fmin ) * np . arange ( Ni ) / ( Ni - 1. ) ) """
	subtract the mean from data
	""" cn = rates - np . mean ( rates ) """
	compute the lsp
	""" psd = np . zeros ( Ni ) print ( 'Calculating the PSD...' ) for i in tqdm ( range ( Ni ) ) : tau = np . arctan ( np . sum ( np . sin ( 2. * omega [ i ] * times ) ) / np . sum ( np . cos ( 2. * omega [ i ] * times ) ) ) tau = tau / ( 2 * omega [ i ] ) co = np . cos ( omega [ i ] * ( times - tau ) ) si = np . sin ( omega [ i ] * ( times - tau ) ) psd [ i ] = 0.5 * ( np . sum ( cn * co ) ** 2 / np . sum ( co ** 2 ) + np . sum ( cn * si ) ** 2 / np . sum ( si ** 2 ) ) """
	correct normalization
	""" var = np . std ( cn ) psd = psd / var ** 2 """
	calculate the false alarm probabilities
	""" sigmathree = 2.7e-03 sigmafour = 6.33e-05 sigmafive = 5.73e-7 probthree = - np . log ( 1.0 - ( ( 1.0 - sigmathree ) ** ( 1. / Ni ) ) ) probfour = - np . log ( 1.0 - ( ( 1.0 - sigmafour ) ** ( 1. / Ni ) ) ) probfive = - np . log ( 1.0 - ( ( 1.0 - sigmafive ) ** ( 1. / Ni ) ) ) return omega , psd , probthree , probfour , probfive
cast times and rates as numpy arrays
cast times and rates as numpy arrays
"""
	cast times and rates as numpy arrays
	""" """
	Set the initial time to 0
	""" """
	calculate the number of independent frequencies
	""" """
	estimate the minimum and maximum frequencies to be sampled
	""" #print('Minimum frequency: ' + str(fmin)) #print('Maximum frequency: ' + str(fmax)) #print(fmax) """
	The frequencies that will be sampled
	""" """
	subtract the mean from data
	""" """
	compute the lsp
	""" """
	correct normalization
	""" """
	calculate the false alarm probabilities
	"""
times
rates