Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalleculated committed Jul 11, 2024
2 parents e9156e8 + c270802 commit cd7cfd2
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 16 deletions.
9 changes: 7 additions & 2 deletions src/fft_analysator/gui/components/accordion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from fft_analysator.gui.components.channel_selector import ChannelSelector
from fft_analysator.gui.components.window_selector import WindowSelector
from fft_analysator.gui.components.overlap_selector import OverlapSelector
from fft_analysator.gui.components.exporter import FileExporter
from fft_analysator.gui.components.exporter_selector import ExporterSelector


class Accordion:
Expand Down Expand Up @@ -56,6 +58,8 @@ def __init__(self):
self.channel_selector_output = ChannelSelector()
self.window_selector = WindowSelector()
self.overlap_selector = OverlapSelector()
self.file_exporter = FileExporter()
self.exporter_selector = ExporterSelector()
self.accordion = pn.Accordion

# Set default colors
Expand All @@ -80,8 +84,9 @@ def __init__(self):
('Calculation', pn.Column(pn.Row(self.window_selector.component,
self.overlap_selector.component),
self.method_selector.component)
), sizing_mode='stretch_width')

),
('Export', pn.Column(self.exporter_selector.component,self.file_exporter.component)),
sizing_mode='stretch_width')

@property
def component(self):
Expand Down
31 changes: 31 additions & 0 deletions src/fft_analysator/gui/components/exporter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import panel as pn
import numpy as np
from tkinter import Tk, filedialog
import os
class FileExporter:
def __init__(self):
self.file_input_button = pn.widgets.Button
self._component = self.file_input_button(name='\U0001F4BE ' 'Save and Export', margin=(10, 0, 10, 10), width=150)
self.dir_path = None

def select_directory(self, event, data, chn1, chn2, method, ext, window, overlap):
root = Tk()
root.withdraw()
root.call('wm', 'attributes', '.', '-topmost', True)
dir = filedialog.askdirectory(initialdir=os.getcwd())
method = method.replace(" ", "")
if dir:
self.dir_path = dir
file_name = str(dir) + "/" + str(method) + "_" + str(chn1) + "_" + str(chn2) + "_" + str(window) + "_" + str(overlap)
print(file_name)
if ext == "Numpy Array":
np.save(file_name, data)
if ext == "Binary":
data.astype(np.int64).tofile(file_name)
else:
self.dir_path = None
root.destroy()

@property
def component(self):
return self._component
11 changes: 11 additions & 0 deletions src/fft_analysator/gui/components/exporter_selector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import panel as pn

class ExporterSelector:
def __init__(self):
self.export_selector = pn.widgets.Select
self.options = ['Numpy Array', 'Binary']
self._component = self.export_selector(name='Choose export extension:', options=self.options, width=300,
value='Numpy Array', disabled=False)
@property
def component(self):
return self._component
6 changes: 3 additions & 3 deletions src/fft_analysator/gui/components/method_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def __init__(self):
self.selector = pn.widgets.Select
self.options = ["No Analysis Function", "Auto Spectral Density - Input", "Auto Spectral Density - Output",
"Cross Spectral Density", "Coherence","Auto Correlation - Input", "Auto Correlation - Output",
"Cross Correlation"]
self._component = self.selector(name='Choose analysis method:', options=self.options, width=300, value='No Analysis Function',
disabled=True)
"Cross Correlation", "Impulse response", "Frequency Response"]
self._component = self.selector(name='Choose analysis and saving method:', options=self.options, width=300,
value='No Analysis Function', disabled=True)

@property
def component(self):
Expand Down
1 change: 0 additions & 1 deletion src/fft_analysator/gui/components/overlap_selector.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import panel as pn


class OverlapSelector:
"""
A class used to represent an Overlap Selector widget.
Expand Down
32 changes: 30 additions & 2 deletions src/fft_analysator/gui/controllers/app_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import holoviews as hv
import panel as pn
import numpy as np

import fft_analysator.analysis.preprocessing as pp
import fft_analysator.analysis.signal_processing as sp
from fft_analysator.gui.views.main_view import MainView
from fft_analysator.gui.views.sidebar import Sidebar
from fft_analysator.analysis.signal_processing import Signal_Process
Expand Down Expand Up @@ -59,7 +61,8 @@ def __init__(self):
self.main_view = MainView()
self.current_method = 'No Analysis Function'
self.sidebar = Sidebar(self.handle_fileupload_event, self.handle_sidebar_event, self.handle_table_choose_event,
self.handle_intslider_event, self.handle_blocksize_selector_event, self.handle_update_analysis_event)
self.handle_intslider_event, self.handle_blocksize_selector_event, self.handle_update_analysis_event,
self.handle_export_event)

# Initialization of panel extensions and template
self.template_layout = pn.template.FastListTemplate(title="FFT-Analysator",
Expand Down Expand Up @@ -116,6 +119,9 @@ def handle_sidebar_event(self, event):
or event.obj == self.sidebar.accordion.color_picker_result.component
or event.obj == self.sidebar.accordion.channel_selector_input.component
or event.obj == self.sidebar.accordion.channel_selector_output.component
or event.obj == self.sidebar.accordion.calculation_menu.signal_menu.clicked
or event.obj == self.sidebar.accordion.overlap_menu.overlap_menu.clicked
or event.obj == self.sidebar.accordion.window_menu.window_menu.clicked

or event.obj == self.sidebar.accordion.method_selector.component
or event.obj == self.sidebar.accordion.overlap_selector.component
Expand All @@ -127,7 +133,6 @@ def handle_sidebar_event(self, event):

# Update the color picker
self.sidebar.update_color_picker()

# Update signal
self.main_view.update_signal(
self.preprocessing,
Expand Down Expand Up @@ -345,6 +350,29 @@ def handle_update_analysis_event(self, event):
self.sidebar.accordion.overlap_selector.component.value
)

def handle_export_event(self, event):
data = np.array([1, 2, 3, 4])
if (event.obj == self.sidebar.accordion.file_exporter.component):

sig_pro = sp.Signal_Process([self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value],
self.preprocessing.file_paths,
self.sidebar.accordion.window_selector.component.value,
self.sidebar.accordion.blocksize_selector.component.value,
self.sidebar.accordion.overlap_selector.component.value)

if self.sidebar.accordion.method_selector.component.value == "Cross Spectral Density":
data = sig_pro.csm()

self.sidebar.accordion.file_exporter.select_directory(event,data,
self.sidebar.accordion.channel_selector_input.component.value,
self.sidebar.accordion.channel_selector_output.component.value,
self.sidebar.accordion.method_selector.component.value,
self.sidebar.accordion.exporter_selector.component.value,
self.sidebar.accordion.window_selector.component.value,
self.sidebar.accordion.overlap_selector.component.value,
)

def servable(self):
"""
Makes the application servable.
Expand Down
19 changes: 11 additions & 8 deletions src/fft_analysator/gui/views/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,20 @@ class Sidebar:
"""

def __init__(self, callback_fileupload=None, callback=None, callback_table_chooser=None, callback_intslider=None,
callback_block_selector=None, callback_analysis_event=None):
callback_block_selector=None, callback_analysis_event=None, callback_exporter_event=None):
"""
Constructs all the necessary attributes for the Sidebar object.
Constructs all the necessary attributes for the Sidebar object.
The accordion attribute is initialized as an Accordion instance.
The layout attribute is initialized as a panel Column layout containing the accordion component.
The ch attribute is initialized as an empty list.
The amount_ch attribute is initialized as 0.
"""

The accordion attribute is initialized as an Accordion instance.
The layout attribute is initialized as a panel Column layout containing the accordion component.
The ch attribute is initialized as an empty list.
The amount_ch attribute is initialized as 0.
"""
self.accordion = Accordion()
self.layout = self.accordion.component

if callback or callback_fileupload or callback_table_chooser or callback_analysis_event:
if callback or callback_fileupload or callback_table_chooser or callback_analysis_event or callback_exporter_event:
self.accordion.file_input.component.param.watch(callback_fileupload, "value")
self.accordion.stretching_switch.component.param.watch(callback, "value")
self.accordion.channel_selector_input.component.param.watch(callback, "value")
Expand All @@ -56,6 +57,8 @@ def __init__(self, callback_fileupload=None, callback=None, callback_table_choos
self.accordion.method_selector.component.param.watch(callback_analysis_event, "value")
self.accordion.overlap_selector.component.param.watch(callback_analysis_event, "value")
self.accordion.window_selector.component.param.watch(callback_analysis_event, "value")
self.accordion.file_exporter.component.param.watch(callback_exporter_event, "value")



def update_channel_selector(self, data_callback=None):
Expand Down

0 comments on commit cd7cfd2

Please sign in to comment.