Skip to content
Snippets Groups Projects
Commit e9f4e0ed authored by Mattia Mancini's avatar Mattia Mancini
Browse files

Simplify function

parent cf18c9cd
Branches
No related tags found
1 merge request!5Try numba implementation
Pipeline #38997 failed
...@@ -241,14 +241,13 @@ def move_mean_sq(a, window_arr, out): ...@@ -241,14 +241,13 @@ def move_mean_sq(a, window_arr, out):
def window_stdv_mean_numba(arr: numpy.ndarray, window): def window_stdv_mean_numba(arr: numpy.ndarray, window):
nfreq = numpy.int32(arr.shape[1]) arr = numpy.swapaxes(arr, 0, 1)
std_arr = numpy.empty_like(arr)
mean_arr = numpy.empty_like(arr)
start_index = window // 2 start_index = window // 2
for s in range(nfreq): mean_arr = move_mean(arr, window)
view: numpy.ndarray = arr[:, s] std_arr = numpy.sqrt(numpy.abs(move_mean_sq(arr, window) - numpy.power(mean_arr, 2)))
mean_arr[:, s] = move_mean(view, window)
std_arr[:, s] = numpy.sqrt(numpy.abs(move_mean_sq(view, window) - numpy.power(mean_arr[:, s], 2))) mean_arr = np.swapaxes(mean_arr, 0, 1)
std_arr = np.swapaxes(std_arr, 0, 1)
return std_arr[start_index: -start_index + 1], mean_arr[start_index: -start_index + 1] return std_arr[start_index: -start_index + 1], mean_arr[start_index: -start_index + 1]
...@@ -268,8 +267,8 @@ def getS4Numba(data, window_size, skip_sample_time=65, axis=1, has_nan=False): ...@@ -268,8 +267,8 @@ def getS4Numba(data, window_size, skip_sample_time=65, axis=1, has_nan=False):
# make sure axis to sample = 0-th axis: # make sure axis to sample = 0-th axis:
tmpdata = np.swapaxes(data, 0, axis) tmpdata = np.swapaxes(data, 0, axis)
stddata, avgdata = window_stdv_mean_numba(tmpdata, window_size) stddata, avgdata = window_stdv_mean_numba(tmpdata, window_size)
# S4 = stddata[::skip_sample_time] / avgdata[::skip_sample_time] S4 = stddata[::skip_sample_time] / avgdata[::skip_sample_time]
# return np.swapaxes(S4, 0, axis) return np.swapaxes(S4, 0, axis)
def getS4Naive(data, window_size, skip_sample_time=65, axis=1, has_nan=False): def getS4Naive(data, window_size, skip_sample_time=65, axis=1, has_nan=False):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment