Skip to content

Commit

Permalink
implementation of signal process ino the app controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalleculated committed Jul 11, 2024
1 parent 82ed4fc commit e9156e8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/fft_analysator/analysis/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

class Plotter:

def __init__(self, channels, tabs_callback, data_callback,window,overlap, color_picker_value,stretch_value=None):
def __init__(self, signal_process_callback, channels, tabs_callback, data_callback,
window, overlap, color_picker_value,stretch_value=None):
self.data_callback = data_callback
self.tabs = tabs_callback
self.fs = self.data_callback.get_abtastrate()
self.block = data_callback.current_block_idx
self.signal_process = Signal_Process(channels, data_callback.file_paths,
block_size=data_callback.block_size, window=window, overlap=overlap)
self.signal_process = signal_process_callback
self.channels = channels
self.color_picker_value = color_picker_value
self.stretch_value = stretch_value
Expand Down
31 changes: 22 additions & 9 deletions src/fft_analysator/analysis/signal_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Signal_Process:
'75%','87.5%'
"""

def __init__(self, channels, file_path, window='Hanning', block_size=1024, overlap='50%'):
def __init__(self, channels=[], file_path=None, window='Hanning', block_size=1024, overlap='50%'):
self.file_path = file_path
self.window = window
self.block_size = block_size
Expand All @@ -32,21 +32,34 @@ def __init__(self, channels, file_path, window='Hanning', block_size=1024, overl
self.source = ac.MaskedTimeSamples(name=self.file_path)
self.abtastrate = self.source.sample_freq
self.numchannels_total = self.source.numchannels_total
#self.invalid_channel_list = []
#self.powerspectra = None
self.invalid_channel_list = []
self.powerspectra = None

if channels:
if len(channels) == 1:
self.input_channel = self.channels[0]
self.output_channel = self.channels[0]
else:
self.input_channel = self.channels[0]
self.output_channel = self.channels[1]


self.invalid_channels([self.input_channel, self.output_channel])
self.powerspectra = ac.PowerSpectra(time_data=self.source, block_size=self.block_size, window=self.window, overlap=self.overlap)


def set_parameters(self, channels, window, overlap):
if channels:
self.channels = channels

if len(channels) == 1:
self.input_channel = self.channels[0]
self.output_channel = self.channels[0]
else:
self.input_channel = self.channels[0]
self.output_channel = self.channels[1]

self.window = window
self.overlap = overlap

self.invalid_channels([self.input_channel, self.output_channel])
self.powerspectra = ac.PowerSpectra(time_data=self.source, block_size=self.block_size,
window=self.window, overlap=self.overlap)

# sort out invalid channels
def invalid_channels(self, valid_channels):
Expand Down
18 changes: 17 additions & 1 deletion src/fft_analysator/gui/controllers/app_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import fft_analysator.analysis.preprocessing as pp
from fft_analysator.gui.views.main_view import MainView
from fft_analysator.gui.views.sidebar import Sidebar
from fft_analysator.analysis.plotting import Plotter
from fft_analysator.analysis.signal_processing import Signal_Process


hv.extension("bokeh", "plotly") # type: ignore
Expand Down Expand Up @@ -85,6 +85,8 @@ def handle_fileupload_event(self, event):

if self.file_paths:
self.preprocessing = pp.Preprocess(self.file_paths, self.sidebar.accordion.blocksize_selector.component.value)
self.signal_process = Signal_Process(channels=[], file_path=self.file_paths,
block_size=self.sidebar.accordion.blocksize_selector.component.value)
# signal_process insert
if event.obj == self.sidebar.accordion.file_input.component:
self.sidebar.update_file_list()
Expand Down Expand Up @@ -129,6 +131,7 @@ def handle_sidebar_event(self, event):
# Update signal
self.main_view.update_signal(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -141,6 +144,7 @@ def handle_sidebar_event(self, event):

self.main_view.update_analysis_plot(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -156,6 +160,7 @@ def handle_sidebar_event(self, event):
self.sidebar.update_color_picker()
self.main_view.update_signal(
self.preprocessing,
self.signal_process,
[],
self.sidebar.accordion.stretching_switch.component.value,
[self.sidebar.accordion.color_picker_ch1.component.value,
Expand All @@ -167,6 +172,7 @@ def handle_sidebar_event(self, event):

self.main_view.update_analysis_plot(
self.preprocessing,
self.signal_process,
[],
self.sidebar.accordion.stretching_switch.component.value,
[self.sidebar.accordion.color_picker_ch1.component.value,
Expand Down Expand Up @@ -206,6 +212,7 @@ def handle_intslider_event(self, event):
self.sidebar.update_nav_index()
self.main_view.update_signal(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -221,6 +228,7 @@ def handle_intslider_event(self, event):
self.sidebar.update_nav_index()
self.main_view.update_signal(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -240,6 +248,8 @@ def handle_blocksize_selector_event(self, event):
if self.file_paths:
# reinitalize the preprocessing object with the new blocksize
self.preprocessing = pp.Preprocess(self.file_paths, self.sidebar.accordion.blocksize_selector.component.value)
self.signal_process = Signal_Process(channels=[], file_path=self.file_paths,
block_size=self.sidebar.accordion.blocksize_selector.component.value)

# update the sidebar components
self.sidebar.update_file_list()
Expand All @@ -248,6 +258,7 @@ def handle_blocksize_selector_event(self, event):
self.sidebar.update_intslider(self.preprocessing)
self.main_view.update_signal(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -259,6 +270,7 @@ def handle_blocksize_selector_event(self, event):
)
self.main_view.update_analysis_plot(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -282,6 +294,7 @@ def handle_update_analysis_event(self, event):

self.main_view.update_signal(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -294,6 +307,7 @@ def handle_update_analysis_event(self, event):

self.main_view.update_analysis_plot(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -307,6 +321,7 @@ def handle_update_analysis_event(self, event):
else:
self.main_view.update_signal(
self.preprocessing,
self.signal_process,
[self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.sidebar.accordion.stretching_switch.component.value,
Expand All @@ -319,6 +334,7 @@ def handle_update_analysis_event(self, event):

self.main_view.update_analysis_plot(
self.preprocessing,
self.signal_process,
[],
self.sidebar.accordion.stretching_switch.component.value,
[self.sidebar.accordion.color_picker_ch1.component.value,
Expand Down
14 changes: 10 additions & 4 deletions src/fft_analysator/gui/views/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self):
self.layout = pn.Column(self.tabs.component, sizing_mode='stretch_width')


def update_signal(self, data_callback, channels, stretch_value, color_picker_value, window, overlap):
def update_signal(self, data_callback, signal_process_callback, channels, stretch_value, color_picker_value, window, overlap):
"""
Updates the signal plots based on the provided data.
Expand All @@ -59,7 +59,10 @@ def update_signal(self, data_callback, channels, stretch_value, color_picker_val
The overlap value for the plot.
"""
if channels:
plot = Plotter(channels, self.tabs, data_callback, window, overlap, color_picker_value, stretch_value)
signal_process_callback.set_parameters(channels, window, overlap)

plot = Plotter(signal_process_callback, channels, self.tabs, data_callback, window, overlap,
color_picker_value, stretch_value)

# generate time plot
plot.create_time_plot()
Expand All @@ -75,7 +78,7 @@ def update_signal(self, data_callback, channels, stretch_value, color_picker_val
self.tabs.component[2] = (self.tabs.str_impulse_response_tab, 'No data chosen!')


def update_analysis_plot(self, data_callback, channels, stretch_value, color_picker_value, analysis_callback,
def update_analysis_plot(self, data_callback, signal_process_callback, channels, stretch_value, color_picker_value, analysis_callback,
window, overlap):
"""
Updates the analysis plots based on the provided data.
Expand All @@ -98,7 +101,10 @@ def update_analysis_plot(self, data_callback, channels, stretch_value, color_pic
The overlap value for the plot.
"""
if channels:
plot = Plotter(channels, self.tabs, data_callback, window, overlap, color_picker_value, stretch_value)
signal_process_callback.set_parameters(channels, window, overlap)

plot = Plotter(signal_process_callback, channels, self.tabs, data_callback, window, overlap,
color_picker_value, stretch_value)

# plot analysis function
if analysis_callback == "Auto Spectral Density - Input":
Expand Down

0 comments on commit e9156e8

Please sign in to comment.