Commit 501d5ade authored by Lorenz Halt's avatar Lorenz Halt 🔀
Browse files

ilc_notebook sandbox

parent 3db32333
%% Cell type:code id: tags:
``` python
import numpy as np
import ilc_lib
import os
from ilc_lib import cos_traj,e_traj
```
%% Cell type:code id: tags:
``` python
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
```
%% Cell type:code id: tags:
``` python
ws_path = "/home/ipa325/logs"
error_path = ws_path + "/logger_0.csv"
ff_path = ws_path + "/server/lin_ff_2.txt"
ff_path = ws_path + "/lin_ff_2.txt"
traj_path = ws_path + "/server/trajectory.txt"
out_path = ws_path + "/lin_ff_out.txt"
traj_type = "cos"
L = 1.0
L = 2.0
cutoff_freq = 0.5
T = 8 #ms
```
%% Cell type:code id: tags:
``` python
data_org, header = ilc_lib.read(error_path)
#remove first row with negative tick
#data = data[1:]
#plt.plot(data[:,0], data[:,1])
#plt.plot(data[:,0], data[:,2])
plt.plot(data_org[:,0], data_org[:,3], '.-')
```
%% Cell type:code id: tags:
``` python
data = ilc_lib.resample(data_org, 8)
data = ilc_lib.resample(data_org, T)
plt.plot(data[:,0], data[:,3], '-o')
plt.plot(data_org[:,0], data_org[:,3], 'x')
```
%% Cell type:code id: tags:
``` python
trajectory = ilc_lib.traj_handle(data, "cos", decay_time=None)
#print(trajectory)
#plt.plot(trajectory[:,0], trajectory[:,1])
#plt.plot(trajectory[:,0], trajectory[:,2])
plt.plot(trajectory[:,0], trajectory[:,3])
plt.plot(trajectory[:,0], trajectory[:,3], '-o')
print trajectory
print(len(trajectory))
```
%% Cell type:code id: tags:
``` python
d1 = trajectory
d2 = data
print d1.shape
print d2.shape
print(d1.shape == d2.shape)
```
%% Cell type:code id: tags:
``` python
plt.plot(data[:,0], data[:,3])
plt.plot(trajectory[:,0], trajectory[:,3])
plt.show()
data_diff = ilc_lib.combine_data(data, trajectory, "diff")
plt.plot(data_diff[:,0], data_diff[:,3], label='diff')
data_sum = ilc_lib.combine_data(data, trajectory, "sum")
plt.plot(data_sum[:,0], data_sum[:,3], label='sum')
plt.legend()
```
%% Cell type:code id: tags:
``` python
test = data[:,0:2]
test[:,1] = np.arange(0, data[-1,0]+1, T) / (data[-1,0]+1) * L
#plt.plot(test[:,0], test[:,1])
#plt.show()
data_ff = ilc_lib.ilc_calculations(data_diff, L)
data_ff_vec = ilc_lib.ilc_calculations(data_diff[:,0:2], test)
plt.plot(data_diff[:,0], data_diff[:,1], label='diff')
plt.plot(data_ff[:,0], data_ff[:,1], label="np.mult(L)")
plt.plot(data_ff_vec[:,0], data_ff_vec[:,1], label="np.mult(vec)")
plt.legend()
```
%% Cell type:code id: tags:
``` python
old_ff = ilc_lib.ilc_calculations(data_diff, 5)
ilc_data = ilc_lib.combine_data(data_ff, data_ff, "sum")
plt.plot(data_ff[:,0], data_ff[:,3], label="last_ff")
plt.plot(data_ff[:,0], data_ff[:,3], label="data_ff")
plt.plot(ilc_data[:,0], ilc_data[:,3], label="addition")
plt.legend()
```
%% Cell type:code id: tags:
``` python
def pad_data(a, b, val=0):
print a.shape[0]
print b.shape[0]
if a.shape[0] > b.shape[0]:
b = np.pad(b, [(0, a.shape[0]-b.shape[0]), (0, 0)], mode='constant', constant_values=val)
b[:,0] = a[:,0] # restore timestamp
elif b.shape[0] > a.shape[0]:
a = np.pad(a, [(0, b.shape[0]-a.shape[0]), (0, 0)], mode='constant', constant_values=val)
a[:,0] = b[:,0] # restore timestamp
return a, b
```
%% Cell type:code id: tags:
``` python
old_ff, _ = ilc_lib.read(ff_path)
try:
ilc_data = ilc_lib.combine_data(data_ff, old_ff, "sum")
except:
data_ff, old_ff = ilc_lib.pad_data(data_ff, old_ff)
ilc_data = ilc_lib.combine_data(data_ff, old_ff, "sum")
plt.plot(old_ff[:,0], old_ff[:,3], label="last_ff")
plt.plot(data_ff[:,0], data_ff[:,3], label="data_ff")
plt.plot(ilc_data[:,0], ilc_data[:,3], label="addition")
plt.legend()
```
%% Cell type:code id: tags:
``` python
plt.plot(ilc_data[:,0], ilc_data[:,3], label="ilc_data")
ilc_data_t = ilc_lib.butter_lowpass_filter(ilc_data, cutoff_freq, 1/(T*0.001), 5)
plt.plot(ilc_data_t[:,0], ilc_data_t[:,3], label="ilc_data")
```
%% Cell type:code id: tags:
``` python
ilc_lib.write(out_path, ilc_data_t, header)
data_new, header = ilc_lib.read(out_path)
plt.plot(ilc_data_t[:,0], ilc_data_t[:,3], 'x')
plt.plot(data_new[:,0], data_new[:,3], '-')
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
### TO CONTINUE ###
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
data = ilc_lib.combine_data(data,trajectory,"diff")
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
ff_data = ilc_lib.ilc_calculations(data, L)
``` python
```
%% Cell type:code id: tags:
``` python
if os.path.exists(ff_path):
old_ff, old_header = ilc_lib.read(ff_path)
ilc_data = ilc_lib.combine_data(ff_data, old_ff,"sum")
else:
ilc_data = ff_data
```
%% Cell type:code id: tags:
``` python
```
ilc_data_t = list( zip(*ilc_data) )
ilc_data_t[1:4][:] = ilc_lib.butter_lowpass_filter(ilc_data_t[1:4][:], cutoff_freq, 120, 5)
ilc_data = list( zip(*ilc_data_t) )
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
ilc_lib.write(ff_path,ilc_data,header)
```
%% Cell type:code id: tags:
``` python
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment