# Getting more of the pulser 20171111a

import numpy as np
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
import math
from matplotlib import colors as mcolors

RawData = "75V.DAT"
f = open(RawData, "r")
a = np.fromfile(f, dtype=np.uint32)
t = a[-1]
V = a[:-1].copy()

Fech = 100000.0*len(V)/t # in MHz

print Fech
25.3575584367

def GetV2(Volts):
Signal = []
for i in range(len(Volts)):
val = int(V[i])
SignalZero = 0
Map[i][k] = (val & 2**k)/2**k
Signal.append(SignalZero)

return Signal,Map

def GetV1(Volts):
Signal = []
for i in range(len(Volts)):
val = int(V[i])
SignalZero = 0
Map[i][k] = (val & 2**k)/2**k
Signal.append(SignalZero)

return Signal,Map
M = GetV2(V)[0]
M2 = GetV1(V)[0]
Ma = M - np.average(M[5000:7000])
Mb = M2 - np.average(M2[5000:7000])
rawSig = []
for k in range(len(Ma)):
rawSig.append(Mb[k])
rawSig.append(Ma[k])
rawSig = rawSig - np.average(rawSig)
for i in range(len(rawSig)-2):
if (rawSig[i+1] > 150 and rawSig[i] < 200 and rawSig[i+2] < 200 ):
rawSig[i+1] = (rawSig[i] + rawSig[i+2])/2
colors = ["m","pink","chartreuse","red","k","lime","cyan","c","y"]
plt.figure(figsize=(15,5))
for k in range(8):
s = (k+1)*10000
plt.plot(rawSig[s:s+1500],colors[k])

plt.title('9 Pulses from '+RawData.split(".")[0])
plt.savefig('Pulses_'+RawData.split(".")[0]+'.jpg', bbox_inches='tight')
plt.show()

plt.figure(figsize=(15,5))

plt.plot(rawSig[10900:11000],"r")

plt.title('A nice echo from '+RawData.split(".")[0])
plt.savefig('Pulses_details_focus_'+RawData.split(".")[0]+'.jpg', bbox_inches='tight')
plt.show()

plt.figure(figsize=(15,5))

acc = rawSig[0:5000]
for k in range(7):
s = (k+2)*10000
acc += rawSig[s:s+5000]

plt.plot(acc[600:2000],"r")

plt.title('Averaged pulses from '+RawData.split(".")[0])
plt.savefig('Pulses_average_'+RawData.split(".")[0]+'.jpg', bbox_inches='tight')
plt.show()