Skip to content

Views

sidebar

Sidebar

Sidebar(callback_fileupload=None, callback=None, callback_table_chooser=None, callback_intslider=None, callback_block_selector=None, callback_analysis_event=None, callback_exporter_event=None, callback_method_event=None)

A class used to represent the sidebar of the application.

This class is responsible for handling user interactions with the sidebar and updating the sidebar's state accordingly.

Attributes:

Name Type Description
accordion object

An instance of the Accordion class.

layout object

A panel Column layout containing the accordion component.

ch list

A list of selected channels.

amount_ch int

The number of selected channels.

Methods:

Name Description
update_channel_selector

Updates the channel selector based on the provided data.

update_color_picker

Updates the color picker based on the selected channels.

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.

Parameters:

Name Type Description Default
callback_fileupload function

A callback function for file upload events.

None
callback function

A general callback function.

None
callback_table_chooser function

A callback function for table chooser events.

None
callback_intslider function

A callback function for intslider events.

None
callback_block_selector function

A callback function for block selector events.

None
callback_analysis_event function

A callback function for analysis events.

None
callback_exporter_event function

A callback function for exporter events.

None
callback_method_event function

A callback function for method events.

None
Source code in src/fft_analysator/gui/views/sidebar.py
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def __init__(self, callback_fileupload=None, callback=None, callback_table_chooser=None, callback_intslider=None,
             callback_block_selector=None, callback_analysis_event=None, callback_exporter_event=None,
             callback_method_event=None):
    """
    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.

    Args:
        callback_fileupload (function, optional): A callback function for file upload events.
        callback (function, optional): A general callback function.
        callback_table_chooser (function, optional): A callback function for table chooser events.
        callback_intslider (function, optional): A callback function for intslider events.
        callback_block_selector (function, optional): A callback function for block selector events.
        callback_analysis_event (function, optional): A callback function for analysis events.
        callback_exporter_event (function, optional): A callback function for exporter events.
        callback_method_event (function, optional): A callback function for method events.
    """

    self.accordion = Accordion()
    self.layout = self.accordion.component

    if (callback or callback_fileupload or callback_table_chooser or callback_analysis_event or
        callback_exporter_event or callback_method_event):
        self.accordion.file_input.component.param.watch(callback_fileupload, "value")
        self.accordion.channel_selector_input.component.param.watch(callback, "value")
        self.accordion.channel_selector_output.component.param.watch(callback, "value")
        self.accordion.color_picker_ch1.component.param.watch(callback, "value")
        self.accordion.color_picker_ch2.component.param.watch(callback, "value")
        self.accordion.color_picker_result.component.param.watch(callback, "value")
        self.accordion.selector.component.param.watch(callback_table_chooser, "value")
        self.accordion.int_slider.component.param.watch(callback_intslider, "value")
        self.accordion.blocksize_selector.component.param.watch(callback_block_selector, "value")
        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")
        self.accordion.method_selector.component.param.watch(callback_method_event, "value")
        self.accordion.toggle_group.component.param.watch(callback, "value")
        self.accordion.toggle_x_axis.component.param.watch(callback, "value")
        self.accordion.toggle_y_axis.component.param.watch(callback, "value")

servable

servable()

Makes the sidebar servable.

Source code in src/fft_analysator/gui/views/sidebar.py
309
310
311
312
313
def servable(self):
    """
    Makes the sidebar servable.
    """
    return self.layout.servable(target="sidebar")

update_channel_selector

update_channel_selector(data_callback=None)

Updates the channel selector based on the provided data.

Parameters:

Name Type Description Default
data_callback function

A callback function that returns the data to be used for updating the channel selector.

None

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def update_channel_selector(self, data_callback=None):
    """
    Updates the channel selector based on the provided data.

    Args:
        data_callback (function): A callback function that returns the data to be used for updating the channel selector.

    Returns:
        None
    """
    if data_callback:
        self.accordion.channel_selector_output.component.disabled = False
        self.accordion.channel_selector_input.component.disabled = False
        self.accordion.channel_selector_output.component.name = "Output channel:"
        self.accordion.channel_selector_input.component.name = "Input channel:"
        self.accordion.channel_selector_input.component.options = (list(range(data_callback.get_channel_count())))
        self.accordion.channel_selector_output.component.options = (list(range(data_callback.get_channel_count())))
    else:
        self.accordion.channel_selector_output.component.name = "No data chosen!"
        self.accordion.channel_selector_input.component.name = "No data chosen!"
        self.accordion.channel_selector_input.component.options = []
        self.accordion.channel_selector_output.component.options = []
        self.accordion.channel_selector_output.component.disabled = True
        self.accordion.channel_selector_input.component.disabled = True

update_color_picker

update_color_picker()

Updates the color picker based on the selected channels.

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
def update_color_picker(self):
    """
    Updates the color picker based on the selected channels.

    Returns:
        None
    """
    # The selector always has a value, so we can check if the options are set
    if (self.accordion.channel_selector_input.component.value is not None
        and self.accordion.channel_selector_output.component.value is not None):

        self.ch = list(dict.fromkeys([self.accordion.channel_selector_input.component.value,
                                      self.accordion.channel_selector_output.component.value]))
        self.amount_ch = len(self.ch)

        if self.amount_ch == 1:
            self.accordion.color_picker_ch1.component.visible = True
            self.accordion.color_picker_ch2.component.visible = False
            self.accordion.color_picker_ch1.component.name = f'CH: {self.ch[0]}'
            self.accordion.color_picker_ch2.component.name = ''
            self.amount_ch = 0
        elif self.amount_ch == 2:
            self.accordion.color_picker_ch1.component.visible = True
            self.accordion.color_picker_ch2.component.visible = True
            self.accordion.color_picker_result.component.visible = True
            self.accordion.color_picker_ch1.component.name = f'CH: {self.ch[0]}'
            self.accordion.color_picker_ch2.component.name = f'CH: {self.ch[1]}'
            self.accordion.color_picker_result.component.name = f'Result'
            self.amount_ch = 0

    else:
        self.accordion.color_picker_ch1.component.visible = False
        self.accordion.color_picker_ch2.component.visible = False
        self.accordion.color_picker_result.component.visible = False
        self.accordion.color_picker_ch1.component.name = ''
        self.accordion.color_picker_ch2.component.name = ''
        self.accordion.color_picker_result.component.name = ''
        self.amount_ch = 0

update_exporter

update_exporter(method_callback=None)

Updates the exporter based on the provided method callback.

If the method callback is "No Analysis Function" or None, the exporter selector and the file exporter are disabled. Otherwise, they are enabled.

Parameters:

Name Type Description Default
method_callback function

A callback function to retrieve the method. If not provided or if it is "No Analysis Function", the exporter selector and the file exporter are disabled.

None

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
def update_exporter(self, method_callback=None):
    """
    Updates the exporter based on the provided method callback.

    If the method callback is "No Analysis Function" or None, the exporter selector and the file exporter are disabled. Otherwise, they are enabled.

    Args:
        method_callback (function, optional): A callback function to retrieve the method. If not provided or if it is "No Analysis Function", the exporter selector and the file exporter are disabled.

    Returns:
        None
    """
    if method_callback == "No Analysis Function" or method_callback is None:
        self.accordion.exporter_selector.component.disabled = True
        self.accordion.file_exporter.component.disabled = True
    else:
        self.accordion.exporter_selector.component.disabled = False
        self.accordion.file_exporter.component.disabled = False

update_file_list

update_file_list()

Updates the file list based on the file paths in the file input component.

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
162
163
164
165
166
167
168
169
170
171
172
173
def update_file_list(self):
    """
    Updates the file list based on the file paths in the file input component.

    Returns:
        None
    """
    if self.accordion.file_input.file_paths:
        self.accordion.data_selector.component.options = [path.basename(self.accordion.file_input.file_paths)]

    else:
        self.accordion.data_selector.component.options = []

update_general_plotting_widgets

update_general_plotting_widgets(data_callback=None)

Updates the general plotting widgets based on the provided data.

If a data callback function is provided, the widgets are enabled. Otherwise, they are disabled.

Parameters:

Name Type Description Default
data_callback function

A callback function to retrieve the data. If not provided, the widgets are disabled.

None

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
def update_general_plotting_widgets(self, data_callback=None):
    """
    Updates the general plotting widgets based on the provided data.

    If a data callback function is provided, the widgets are enabled. Otherwise, they are disabled.

    Args:
        data_callback (function, optional): A callback function to retrieve the data. If not provided, the widgets are disabled.

    Returns:
        None
    """
    if data_callback:
        self.accordion.toggle_group.component.disabled = False
        self.accordion.toggle_x_axis.component.disabled = False
        self.accordion.toggle_y_axis.component.disabled = False
        self.accordion.window_selector.component.disabled = False
        self.accordion.overlap_selector.component.disabled = False
        self.accordion.method_selector.component.disabled = False
    else:
        self.accordion.toggle_group.component.disabled = True
        self.accordion.toggle_x_axis.component.disabled = True
        self.accordion.toggle_y_axis.component.disabled = True
        self.accordion.window_selector.component.disabled = True
        self.accordion.overlap_selector.component.disabled = True
        self.accordion.method_selector.component.disabled = True

update_intslider

update_intslider(data_callback=None)

Updates the integer slider and the navigation buttons based on the provided data.

If the file paths attribute of the file input component is not empty and a data callback function is provided, the integer slider and the navigation buttons are enabled and updated based on the data. Otherwise, they are disabled.

Parameters:

Name Type Description Default
data_callback function

A callback function to retrieve the data. If not provided, the integer slider and the navigation buttons are disabled.

None

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def update_intslider(self, data_callback=None):
    """
    Updates the integer slider and the navigation buttons based on the provided data.

    If the file paths attribute of the file input component is not empty and a data callback function is provided, the integer slider and the navigation buttons are enabled and updated based on the data. Otherwise, they are disabled.

    Args:
        data_callback (function, optional): A callback function to retrieve the data. If not provided, the integer slider and the navigation buttons are disabled.

    Returns:
        None
    """
    if self.accordion.file_input.file_paths and data_callback:
        self.accordion.int_slider.component.disabled = False
        self.accordion.int_slider.component.value = 0
        self.accordion.int_slider.component.start = 0
        self.accordion.int_slider.component.end = math.ceil(
            (data_callback.source.numsamples) / data_callback.block_size) - 1

        # update the navigation buttons as well since they are coupled with the int_slider
        self.accordion.gen_nav.index_box.disabled = False
        self.accordion.gen_nav.index_box.start = self.accordion.int_slider.component.start
        self.accordion.gen_nav.index_box.end = self.accordion.int_slider.component.end
        self.accordion.gen_nav.index_box.name = f'{self.accordion.int_slider.component.value}/{self.accordion.gen_nav.index_box.start}-{self.accordion.gen_nav.index_box.end}'
        self.accordion.gen_nav.button_back.disabled = False
        self.accordion.gen_nav.button_forward.disabled = False
        self.accordion.gen_nav.goto_button.disabled = False
        self.accordion.gen_nav.reset_button.disabled = False

    else:
        self.accordion.int_slider.component.disabled = True
        self.accordion.int_slider.component.value = 0

        # update the navigation buttons as well since they are coupled with the int_slider
        self.accordion.gen_nav.index_box.value = 0
        self.accordion.gen_nav.index_box.name = "Index:"
        self.accordion.gen_nav.index_box.disabled = True
        self.accordion.gen_nav.button_back.disabled = True
        self.accordion.gen_nav.button_forward.disabled = True
        self.accordion.gen_nav.goto_button.disabled = True
        self.accordion.gen_nav.reset_button.disabled = True

update_nav_index

update_nav_index()

Updates the navigation index based on the current value of the integer slider.

The navigation index is updated to a string of the format 'current value/start-end', where 'current value' is the current value of the integer slider, and 'start' and 'end' are the start and end values of the navigation index box.

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
217
218
219
220
221
222
223
224
225
226
def update_nav_index(self):
    """
    Updates the navigation index based on the current value of the integer slider.

    The navigation index is updated to a string of the format 'current value/start-end', where 'current value' is the current value of the integer slider, and 'start' and 'end' are the start and end values of the navigation index box.

    Returns:
        None
    """
    self.accordion.gen_nav.index_box.name = f'{self.accordion.int_slider.component.value}/{self.accordion.gen_nav.index_box.start}-{self.accordion.gen_nav.index_box.end}'

update_selector

update_selector(data_callback=None)

Updates the selector based on the provided data.

Parameters:

Name Type Description Default
data_callback function

A callback function to retrieve the data. If not provided, the selector is cleared.

None

Returns:

Name Type Description
bool

Always returns True.

Source code in src/fft_analysator/gui/views/sidebar.py
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def update_selector(self, data_callback=None):
    """
    Updates the selector based on the provided data.

    Args:
        data_callback (function, optional): A callback function to retrieve the data. If not provided, the selector is cleared.

    Returns:
        bool: Always returns True.
    """
    if data_callback:
        self.accordion.selector.component.options = data_callback.get_table_names()
        self.accordion.selector.component.value = data_callback.get_table_names()[0]
        if (len(data_callback.get_table_names()) + 2) > 3:
            self.accordion.selector.component.size = len(data_callback.get_table_names()) + 2

    else:
        self.accordion.selector.component.options = []
        self.accordion.selector.component.value = ""

    return True

update_toggle_group

update_toggle_group()

Updates the toggle group based on its current value.

If 'Stretch' is in the toggle group's value, the stretch attribute of the toggle group is set to True. Otherwise, it is set to False. If 'Grid' is in the toggle group's value, the grid attribute of the toggle group is set to True. Otherwise, it is set to False.

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/sidebar.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
def update_toggle_group(self):
    """
    Updates the toggle group based on its current value.

    If 'Stretch' is in the toggle group's value, the stretch attribute of the toggle group is set to True. Otherwise, it is set to False.
    If 'Grid' is in the toggle group's value, the grid attribute of the toggle group is set to True. Otherwise, it is set to False.

    Returns:
        None
    """
    if 'Stretch' in self.accordion.toggle_group.component.value:
        self.accordion.toggle_group.stretch = True
    else:
        self.accordion.toggle_group.stretch = False

    if 'Grid' in self.accordion.toggle_group.component.value:
        self.accordion.toggle_group.grid = True
    else:
        self.accordion.toggle_group.grid = False

    if self.accordion.toggle_x_axis.component.value == 'x-log':
        self.accordion.toggle_x_axis.x_log = True
    else:
        self.accordion.toggle_x_axis.x_log = False

    if self.accordion.toggle_y_axis.component.value == 'y-log':
        self.accordion.toggle_y_axis.y_log = True
    else:
        self.accordion.toggle_y_axis.y_log = False

    if "dB" in self.accordion.toggle_group.component.value:
        self.accordion.toggle_group.db = True
    else:
        self.accordion.toggle_group.db = False

Main View

main_view

MainView

MainView()

A class used to represent the main view of the application.

This class is responsible for updating the signal and analysis plots based on the provided data.

Attributes:

Name Type Description
tabs object

An instance of the Tabs class.

layout object

A panel Column layout containing the tabs component.

Methods:

Name Description
update_signal

Updates the signal plots based on the provided data.

update_analysis_plot

Updates the analysis plots based on the provided data.

The tabs attribute is initialized as a Tabs instance. The layout attribute is initialized as a panel Column layout containing the tabs component.

Source code in src/fft_analysator/gui/views/main_view.py
29
30
31
32
33
34
35
36
37
def __init__(self):
    """
    Constructs all the necessary attributes for the MainView object.

    The tabs attribute is initialized as a Tabs instance.
    The layout attribute is initialized as a panel Column layout containing the tabs component.
    """
    self.tabs = Tabs()
    self.layout = pn.Column(self.tabs.component, sizing_mode='stretch_width')

servable

servable()

Makes the main view servable.

Source code in src/fft_analysator/gui/views/main_view.py
138
139
140
141
142
def servable(self):
    """
    Makes the main view servable.
    """
    self.layout.servable(target="main")

update_analysis_plot

update_analysis_plot(data_callback, signal_process_callback, channels, stretch_value, color_picker_value, analysis_callback, window, overlap, show_grid, x_log, y_log, db)

Updates the analysis plots based on the provided data.

Parameters:

Name Type Description Default
data_callback function

A callback function that returns the data to be plotted.

required
channels list

A list of channels to be plotted.

required
stretch_value int

The stretch value for the plot.

required
color_picker_value str

The color for the plot.

required
analysis_callback function

A callback function that returns the analysis data to be plotted.

required
window str

The window type for the plot.

required
overlap float

The overlap value for the plot.

required

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/main_view.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
def update_analysis_plot(self, data_callback, signal_process_callback, channels, stretch_value, color_picker_value, analysis_callback,
                         window, overlap, show_grid,x_log,y_log, db):
    """
    Updates the analysis plots based on the provided data.

    Args:
        data_callback (function): A callback function that returns the data to be plotted.
        channels (list): A list of channels to be plotted.
        stretch_value (int): The stretch value for the plot.
        color_picker_value (str): The color for the plot.
        analysis_callback (function): A callback function that returns the analysis data to be plotted.
        window (str): The window type for the plot.
        overlap (float): The overlap value for the plot.

    Returns:
        None
    """
    if channels:
        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, show_grid,x_log,y_log, db)

        # plot analysis function
        if analysis_callback == "Auto Spectral Density - Input":
            # generate Auto Spectral Density plot
            plot.create_auto_and_cross_power_spectrum_plot(type='xx')

        elif analysis_callback == "Auto Spectral Density - Output":
            # generate Auto Spectral Density plot
            plot.create_auto_and_cross_power_spectrum_plot(type='yy')

        elif analysis_callback == "Cross Spectral Density":
            # generate Cross Spectral Density plot
            plot.create_auto_and_cross_power_spectrum_plot(type='xy')

        elif analysis_callback == "Auto Correlation - Input":
            # generate Auto Correlation - Input plot
            plot.create_correlation_plot(type='xx')

        elif analysis_callback == "Auto Correlation - Output":
            # generate Auto Correlation - Output plot
            plot.create_correlation_plot(type='yy')

        elif analysis_callback == "Cross Correlation":
            # generate Cross Spectral Density plot
            plot.create_correlation_plot(type='xy')

        elif analysis_callback == "Coherence":
            # generate coherence plot
            plot.create_coherence_plot()

        elif analysis_callback == "No Analysis Function":
            self.tabs.component[3] = (self.tabs.str_analysis_function_tab, "No Analysis Function is choosen")

        elif analysis_callback == "Impulse Response" or analysis_callback == "Amplitude Response" or analysis_callback == "Phase Response":

            self.tabs.component[3] = (self.tabs.str_analysis_function_tab, "No Analysis Function for this Tab is choosen")

    else:
        self.tabs.component[3] = (self.tabs.str_analysis_function_tab, 'No data chosen!')

update_signal

update_signal(data_callback, signal_process_callback, channels, stretch_value, color_picker_value, window, overlap, show_grid, x_log, y_log, db)

Updates the signal plots based on the provided data.

Parameters:

Name Type Description Default
data_callback function

A callback function that returns the data to be plotted.

required
channels list

A list of channels to be plotted.

required
stretch_value int

The stretch value for the plot.

required
color_picker_value str

The color for the plot.

required
window str

The window type for the plot.

required
overlap float

The overlap value for the plot.

required

Returns:

Type Description

None

Source code in src/fft_analysator/gui/views/main_view.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def update_signal(self, data_callback, signal_process_callback, channels, stretch_value, color_picker_value, window, overlap, show_grid,x_log,y_log, db):
    """
    Updates the signal plots based on the provided data.

    Args:
        data_callback (function): A callback function that returns the data to be plotted.
        channels (list): A list of channels to be plotted.
        stretch_value (int): The stretch value for the plot.
        color_picker_value (str): The color for the plot.
        window (str): The window type for the plot.
        overlap (float): The overlap value for the plot.

    Returns:
        None
    """
    if channels:
        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, show_grid,x_log,y_log, db)

        # generate time plot
        plot.create_time_plot()

        # generate frequency response plot
        plot.create_frequency_response_plot()

        # generate frequency response plot
        plot.create_impulse_response_plot()
    else:
        self.tabs.component[0] = (self.tabs.str_signal_tab, 'No data chosen!')
        self.tabs.component[1] = (self.tabs.str_frequency_response_tab, 'No data chosen!')
        self.tabs.component[2] = (self.tabs.str_impulse_response_tab, 'No data chosen!')