Spaces:
Running
Running
fixed averaging for reversed frq sort case
Browse files- app.py +13 -12
- utils_process.py +16 -0
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from matplotlib import pyplot as plt
|
|
| 10 |
import pandas as pd
|
| 11 |
import time
|
| 12 |
|
| 13 |
-
from utils_process import multipass_average, rotate_data, frq_recalc
|
| 14 |
|
| 15 |
app_ui = ui.page_fluid(
|
| 16 |
ui.panel_title("RAD data processing"),
|
|
@@ -79,9 +79,9 @@ def server(input, output, session):
|
|
| 79 |
def aux_data_show():
|
| 80 |
if input.aux_data() is None:
|
| 81 |
return 'No recording conditions data loaded'
|
| 82 |
-
aux_file: list[FileInfo] = input.aux_data()
|
| 83 |
-
aux_names = ['File', 'P', 'T', 'dev']
|
| 84 |
-
aux_out = pd.read_csv(aux_file[0]["datapath"], names=aux_names, delim_whitespace=True, index_col=0)
|
| 85 |
aux_df.set(aux_out)
|
| 86 |
return ui.HTML(aux_out.to_html(classes="table table-striped"))
|
| 87 |
|
|
@@ -139,17 +139,18 @@ def server(input, output, session):
|
|
| 139 |
|
| 140 |
for ifil in range(nrecs.get()):
|
| 141 |
tmp_rec = raw_data.get()[ifil]
|
| 142 |
-
tmp_synth = tmp_rec[:, 0]
|
| 143 |
-
synth_uniq, synth_counts = np.unique(tmp_synth, return_counts=True)
|
| 144 |
-
tmp_pps = synth_uniq.shape[0]
|
| 145 |
-
tmp_nscan = synth_counts[0]
|
| 146 |
-
tmp_ch1 = tmp_rec[:, 1]
|
| 147 |
-
tmp_ch2 = tmp_rec[:, 2]
|
| 148 |
|
| 149 |
frq_ready = frq_recalc(synth_uniq*1000., input.n_harm(), input.ifrq())
|
| 150 |
tmp_ctr = 0.5 * (min(frq_ready) + max(frq_ready))
|
| 151 |
-
ch1_ready = multipass_average(tmp_ch1, tmp_pps)
|
| 152 |
-
ch2_ready = multipass_average(tmp_ch2, tmp_pps)
|
|
|
|
| 153 |
|
| 154 |
if input.s_normalize():
|
| 155 |
ch2_ready[:] = ch2_ready[:]/max(ch1_ready)
|
|
|
|
| 10 |
import pandas as pd
|
| 11 |
import time
|
| 12 |
|
| 13 |
+
from utils_process import multipass_average, multipass_average2, rotate_data, frq_recalc
|
| 14 |
|
| 15 |
app_ui = ui.page_fluid(
|
| 16 |
ui.panel_title("RAD data processing"),
|
|
|
|
| 79 |
def aux_data_show():
|
| 80 |
if input.aux_data() is None:
|
| 81 |
return 'No recording conditions data loaded'
|
| 82 |
+
aux_file: list[FileInfo] = input.aux_data() # read data on the aux file (name, size, type, datapath)
|
| 83 |
+
aux_names = ['File', 'P', 'T', 'dev'] # column names of the aux data
|
| 84 |
+
aux_out = pd.read_csv(aux_file[0]["datapath"], names=aux_names, delim_whitespace=True, index_col=0) # make a dataframe from the aux data
|
| 85 |
aux_df.set(aux_out)
|
| 86 |
return ui.HTML(aux_out.to_html(classes="table table-striped"))
|
| 87 |
|
|
|
|
| 139 |
|
| 140 |
for ifil in range(nrecs.get()):
|
| 141 |
tmp_rec = raw_data.get()[ifil]
|
| 142 |
+
tmp_synth = tmp_rec[:, 0] # synth frequencies from RAD data
|
| 143 |
+
synth_uniq, synth_counts = np.unique(tmp_synth, return_counts=True) # use numpy functions to retrieve necessary metadata
|
| 144 |
+
tmp_pps = synth_uniq.shape[0] # points per scan from RAD data
|
| 145 |
+
tmp_nscan = synth_counts[0] # number of scans from RAD data
|
| 146 |
+
tmp_ch1 = tmp_rec[:, 1] # signal channel 1
|
| 147 |
+
tmp_ch2 = tmp_rec[:, 2] # signal channel 2
|
| 148 |
|
| 149 |
frq_ready = frq_recalc(synth_uniq*1000., input.n_harm(), input.ifrq())
|
| 150 |
tmp_ctr = 0.5 * (min(frq_ready) + max(frq_ready))
|
| 151 |
+
# ch1_ready = multipass_average(tmp_ch1, tmp_pps)
|
| 152 |
+
# ch2_ready = multipass_average(tmp_ch2, tmp_pps)
|
| 153 |
+
ch1_ready, ch2_ready = multipass_average2(tmp_rec, tmp_pps)
|
| 154 |
|
| 155 |
if input.s_normalize():
|
| 156 |
ch2_ready[:] = ch2_ready[:]/max(ch1_ready)
|
utils_process.py
CHANGED
|
@@ -8,6 +8,22 @@ def multipass_average(signal: np.ndarray, npts: int) -> np.ndarray:
|
|
| 8 |
signal_avg[i] = np.average(signal[i:npts_tot:npts])
|
| 9 |
return signal_avg
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def rotate_data(ch_x, ch_y, ang):
|
| 12 |
ang_rad = ang * np.pi / 180.
|
| 13 |
cos_a = np.cos(ang_rad)
|
|
|
|
| 8 |
signal_avg[i] = np.average(signal[i:npts_tot:npts])
|
| 9 |
return signal_avg
|
| 10 |
|
| 11 |
+
def multipass_average2(data: np.ndarray, npts: int) -> np.ndarray:
|
| 12 |
+
# this function considers that back passes in the data array might be stored also sorted backwards (higher frq first)
|
| 13 |
+
# for this function the whole data array is necessary (i.e. not only one column containing signal, but all columns incl.frequency)
|
| 14 |
+
npts_tot = data.shape[0] # total points
|
| 15 |
+
npass = npts_tot // npts # number of passes
|
| 16 |
+
signal_avg_1 = np.zeros(npts)
|
| 17 |
+
signal_avg_2 = np.zeros(npts)
|
| 18 |
+
for i in range(npass):
|
| 19 |
+
j0 = i * npts # here we have to iterate trough each pass
|
| 20 |
+
j1 = (i + 1) * npts # defining the starting and ending index of the pass
|
| 21 |
+
tmp_data = np.copy(data[j0:j1, 0:3]) # extract the corresponding pass data
|
| 22 |
+
tmp_data = tmp_data[tmp_data[:, 0].argsort()] # sort it by frequency containing in the 0-th column
|
| 23 |
+
signal_avg_1 += tmp_data[:, 1] # now averaging should happen correctly
|
| 24 |
+
signal_avg_2 += tmp_data[:, 2] # in both cases sorted and reverse sorted frequencies
|
| 25 |
+
return signal_avg_1 / npass, signal_avg_2 / npass
|
| 26 |
+
|
| 27 |
def rotate_data(ch_x, ch_y, ang):
|
| 28 |
ang_rad = ang * np.pi / 180.
|
| 29 |
cos_a = np.cos(ang_rad)
|