<commit_before>from __future__ import division
import numpy as np
from scipy.fftpack import ifft, fft, fftfreq

def calc_phase_difference(t, ref, obj):
	"""Calculate the phase difference between the reference and object
	signals. Returns phase difference in radians.
	"""
	f = fftfreq(len(ref), t[1]-t[0])

	# low pass filter
	lp_filter = np.ones(len(f)) / (1 + ((f / 6)**2))   
	ref = ifft(fft(ref) * lp_filter)
	obj = ifft(fft(obj) * lp_filter)

	# apodising filter (time domain)
	a0 = 0.355768
	a1 = 0.487396
	a2 = 0.144232
	a3 = 0.012604
	n = np.arange(0,len(t),1)
	apodize_filter =  (a0 - a1*np.cos(2*np.pi*n/len(t))
					  + a2*np.cos(4*np.pi*n/len(t))
					  - a3*np.cos(6*np.pi*n/len(t)))
	ref *= apodize_filter
	obj *= apodize_filter

	# bp filter in freq domain
	sig = 1
	f0 = 7
	bp_filter = np.exp(-(f-f0)**2 / (2*sig*sig))    
	ref = ifft(fft(ref) * bp_filter)
	obj = ifft(fft(obj) * bp_filter)

	delta_phi = np.angle(obj * ref.conjugate()) / 2

	# exclude outer 25% because of edge effects
	return np.mean(delta_phi[len(f)*0.25:len(f)*0.75])<commit_msg>Created polarimeter data class<commit_after>from __future__ import division
import numpy as np
from scipy.fftpack import ifft, fft, fftfreq

class PolarimeterData:
	def __init__(self, t, ref, obj):
		self.t = t
		self.ref = ref
		self.obj = obj
		self.calc_phase_difference()

	def calc_phase_difference(self):
		"""Calculate the phase difference between the reference and object
		signals. Returns phase difference in radians.
		"""
		t = self.t
		ref = self.ref
		obj = self.obj

		f = fftfreq(len(ref), t[1]-t[0])

		# low pass filter
		lp_filter = np.ones(len(f)) / (1 + ((f / 6)**2))   
		ref = ifft(fft(ref) * lp_filter)
		obj = ifft(fft(obj) * lp_filter)

		# apodising filter (time domain)
		a0 = 0.355768
		a1 = 0.487396
		a2 = 0.144232
		a3 = 0.012604
		n = np.arange(0,len(t),1)
		apodize_filter =  (a0 - a1*np.cos(2*np.pi*n/len(t))
						  + a2*np.cos(4*np.pi*n/len(t))
						  - a3*np.cos(6*np.pi*n/len(t)))
		ref *= apodize_filter
		obj *= apodize_filter

		# bp filter in freq domain
		sig = 1
		f0 = 7
		bp_filter = np.exp(-(f-f0)**2 / (2*sig*sig))    
		ref = ifft(fft(ref) * bp_filter)
		obj = ifft(fft(obj) * bp_filter)

		self.delta_phi = np.angle(obj * ref.conjugate()) / 2
		# exclude outer 25% because of edge effects
		self.delta_phi = self.delta_phi[len(f)*0.25:len(f)*0.75]
{'fraction_non_alphanumeric': 0.15602536997885835, 'fraction_numerical': 0.051585623678646934, 'mean_word_length': 3.4224299065420563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1851455', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1004, 'n_words': 228}