Fixed SimpleNormalize, added NormalizeAmplitude
This commit is contained in:
parent
1260298a42
commit
99ba4e390e
@ -9,20 +9,37 @@ class Normalize:
|
|||||||
assert(low < high)
|
assert(low < high)
|
||||||
self.low = low
|
self.low = low
|
||||||
self.high = high
|
self.high = high
|
||||||
def __call__(self, a):
|
def __call__(self, data):
|
||||||
min_ = np.min(a)
|
min_ = np.min(data)
|
||||||
a = a - min_
|
data = data - min_ # smallest point is 0 now
|
||||||
max_ = np.max(a)
|
max_ = np.max(data)
|
||||||
if max_ != 0:
|
if max_ != 0:
|
||||||
a = (a / max_)
|
data = (data / max_)
|
||||||
# now normalized between 0 and 1
|
# now normalized between 0 and 1
|
||||||
a *= (self.high - self.low)
|
data *= (self.high - self.low)
|
||||||
a -= self.low
|
data += self.low
|
||||||
return a
|
return data
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"Normalize(low={self.low}, high={self.high})"
|
return f"Normalize(low={self.low}, high={self.high})"
|
||||||
|
|
||||||
|
class NormalizeAmplitude:
|
||||||
|
"""
|
||||||
|
scale data so that all values are between -high and high
|
||||||
|
"""
|
||||||
|
def __init__(self, high=1):
|
||||||
|
self.high = high
|
||||||
|
|
||||||
|
def __call__(self, data):
|
||||||
|
min_ = np.min(data)
|
||||||
|
max_ = np.max(data)
|
||||||
|
scale = np.max([np.abs(min_), np.abs(max_)])
|
||||||
|
if scale != 0:
|
||||||
|
data = data / scale * self.high
|
||||||
|
return data
|
||||||
|
def __repr__(self):
|
||||||
|
return f"NormalizeAmplitude(high={self.high})"
|
||||||
|
|
||||||
|
|
||||||
class ConstantInterval:
|
class ConstantInterval:
|
||||||
"""
|
"""
|
||||||
@ -32,15 +49,15 @@ class ConstantInterval:
|
|||||||
def __init__(self, interval):
|
def __init__(self, interval):
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
|
|
||||||
def __call__(self, a):
|
def __call__(self, data):
|
||||||
"""
|
"""
|
||||||
array: [timestamps, data1, data2...]
|
array: [timestamps, data1, data2...]
|
||||||
"""
|
"""
|
||||||
timestamps = a[:,0]
|
timestamps = data[:,0]
|
||||||
new_stamps = np.arange(timestamps[0], timestamps[-1], self.interval)
|
new_stamps = np.arange(timestamps[0], timestamps[-1], self.interval)
|
||||||
ret = new_stamps
|
ret = new_stamps
|
||||||
for i in range(1, a.shape[1]): #
|
for i in range(1, data.shape[1]): #
|
||||||
interp = interp1d(timestamps, a[:,i])
|
interp = interp1d(timestamps, data[:,i])
|
||||||
new_vals = interp(new_stamps)
|
new_vals = interp(new_stamps)
|
||||||
ret = np.vstack((ret, new_vals))
|
ret = np.vstack((ret, new_vals))
|
||||||
return ret.T
|
return ret.T
|
||||||
|
Loading…
Reference in New Issue
Block a user