ShinyDataProcessing / utils_process.py
dsmakarov's picture
fixed averaging for reversed frq sort case
3596592
Raw History Blame Contribute Delete
1.73 kB
import numpy as np
def multipass_average(signal: np.ndarray, npts: int) -> np.ndarray:
npts_tot = len(signal)
# npass = npts_tot // npts
signal_avg = np.zeros(npts)
for i in range(npts):
signal_avg[i] = np.average(signal[i:npts_tot:npts])
return signal_avg
def multipass_average2(data: np.ndarray, npts: int) -> np.ndarray:
# this function considers that back passes in the data array might be stored also sorted backwards (higher frq first)
# for this function the whole data array is necessary (i.e. not only one column containing signal, but all columns incl.frequency)
npts_tot = data.shape[0] # total points
npass = npts_tot // npts # number of passes
signal_avg_1 = np.zeros(npts)
signal_avg_2 = np.zeros(npts)
for i in range(npass):
j0 = i * npts # here we have to iterate trough each pass
j1 = (i + 1) * npts # defining the starting and ending index of the pass
tmp_data = np.copy(data[j0:j1, 0:3]) # extract the corresponding pass data
tmp_data = tmp_data[tmp_data[:, 0].argsort()] # sort it by frequency containing in the 0-th column
signal_avg_1 += tmp_data[:, 1] # now averaging should happen correctly
signal_avg_2 += tmp_data[:, 2] # in both cases sorted and reverse sorted frequencies
return signal_avg_1 / npass, signal_avg_2 / npass
def rotate_data(ch_x, ch_y, ang):
ang_rad = ang * np.pi / 180.
cos_a = np.cos(ang_rad)
sin_a = np.sin(ang_rad)
r_x = ch_x[:] * cos_a + ch_y[:] * sin_a
r_y = -1. * ch_x[:] * sin_a + ch_y[:] * cos_a
return r_x, r_y
def frq_recalc(frq: np.ndarray, n_harmonic: int, inter_fr: float) -> np.ndarray:
return frq[:] * n_harmonic + inter_fr