Skip to content

Instantly share code, notes, and snippets.

@KobaWeather
Created July 24, 2012 03:35
Show Gist options
  • Save KobaWeather/3167862 to your computer and use it in GitHub Desktop.
Save KobaWeather/3167862 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import sys
import numpy as np
from scipy.interpolate import interp1d
# from scipy.interpolate import UnivariateSpline
def read_csv2(data):
x = data[:, 1]
y = data[:, 2]
z = data[:, 3]
for i, v in enumerate(z):
if v == 100 and z[i-1] != 100:
z[i-1] = 100
t1 = np.cumsum(data[:, 4]) - data[0, 4]
t2 = np.arange(0, t1[-1], 0.02)
return np.vstack([t2, [func(t2) for func in (interp1d(t1, p) for p in (x, y, z))]]).T
def trans_data(filename):
data1 = read_csv2(np.loadtxt(filename, delimiter = ","))
data2 = (data1[:, 1:4] - np.average(data1[:, 1:4], axis = 0)) / np.std(data1[:, 1:4], axis = 0)
data2 = data2 + (np.random.randn(*data2.shape) / 10)
v = np.vstack([0.5 * data2[1],
0.5 * (data2[2:] - data2[:-2]),
-0.5 * data2[-2]])
return np.hstack([data2, v])
if __name__ == "__main__":
usecol = (0, 1, 3, 4)
np.savetxt(sys.argv[2], trans_data(sys.argv[1])[:, usecol], delimiter = "\t", fmt = "%0.6f")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment