-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
75 lines (60 loc) · 2.91 KB
/
data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import numpy as np
from math import pi, floor, ceil
def read_cvsin_type_1(filename):
""" read in a datafile of format svsin_type_1
Args:
filename (str): filename of the data file
returns:
time (numpy vector): vector of time samples
current (numpy vector): vector of current samples
"""
exp_data = np.loadtxt(filename, skiprows=19)
if filename[-11:] == '_cv_current':
t_index = 0
c_index = 1
else:
t_index = 2
c_index = 1
return exp_data[:, t_index], exp_data[:, c_index]
class ECTimeData:
def __init__(self, filename, model, ignore_begin_samples,
ignore_end_samples=0, samples_per_period=200, datafile_type='scsin_type_1'):
print('ECTimeData: loading data from filename = ', filename, ' ...')
self.times, self.current = read_cvsin_type_1(filename)
print('\tUsing samples from ', ignore_begin_samples,
' to ', len(self.times) - ignore_end_samples)
if (ignore_end_samples > 0):
self.times = self.times[ignore_begin_samples:-ignore_end_samples]
self.current = self.current[
ignore_begin_samples:-ignore_end_samples]
else:
self.times = self.times[ignore_begin_samples:]
self.current = self.current[ignore_begin_samples:]
print('\tCut data to multiple of period')
dt = self.times[100] - self.times[99]
data_samples_per_period = 1.0 / (model._omega_d * dt)
discard_samples = int(len(self.current) % data_samples_per_period)
if (discard_samples > 0):
self.times = self.times[0:-discard_samples]
self.current = self.current[0:-discard_samples]
downsample = int(floor(data_samples_per_period /
samples_per_period))
if downsample == 0:
downsample = 1
print('\tBefore downsampling, have ', len(self.times), ' data points')
print('\tDatafile has ', data_samples_per_period, ' samples per period.')
print(
'\tReducing number of samples using a moving average window of size ', downsample)
#new_length = int(len(self.times) / downsample)
#pad_size = int(
# ceil(float(len(self.times)) / downsample) * downsample) - len(self.times)
#self.times = np.append(self.times, np.zeros(pad_size) * np.NaN)
#self.times = np.nanmean(self.times.reshape(-1, downsample), axis=1)
#self.current = np.append(self.current, np.zeros(pad_size) * np.NaN)
#self.current = np.nanmean(self.current.reshape(-1, downsample), axis=1)
self.current = self.current[::downsample]
self.times = self.times[::downsample]
self.current = self.current / model._I_0
self.times = self.times / model._T_0
# self.distance_scale = np.linalg.norm(self.current)
print('\tAfter downsampling, have ', len(self.times), ' data points')