From 5f235be27e157c3824b83a00dabc831b58371e22 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Fri, 15 Mar 2024 14:27:16 -0400 Subject: [PATCH 01/13] reorganizing visualization tab widgets. adding two additional float fields for data comparison --- hnn_core/gui/_viz_manager.py | 75 ++++++++++++++++++++++++------------ hnn_core/gui/gui.py | 6 ++- 2 files changed, 55 insertions(+), 26 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index 4f9437454..34f91bda8 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -17,6 +17,7 @@ from hnn_core.gui._logging import logger from hnn_core.viz import plot_dipole + _fig_placeholder = 'Run simulation to add figures here.' _plot_types = [ @@ -116,17 +117,21 @@ def unlink_relink(attribute): def _unlink_relink(f): @wraps(f) def wrapper(self, *args, **kwargs): - # Unlink the widgets using the provided link object - link_attribute: link = getattr(self, attribute) - link_attribute.unlink() + try: + # Unlink the widgets using the provided link object + link_attribute: link = getattr(self, attribute) + link_attribute.unlink() - # Call the original function - result = f(self, *args, **kwargs) + # Call the original function + result = f(self, *args, **kwargs) - # Re-link the widgets - link_attribute.link() + # Re-link the widgets + link_attribute.link() - return result + return result + except Exception as e: + # Handle the exception and print it + print(f"An error occurred: {e}") return wrapper return _unlink_relink @@ -273,10 +278,10 @@ def _dynamic_rerender(fig): fig.tight_layout() -def _plot_on_axes(b, widgets_simulation, widgets_plot_type, - target_simulations, +def _plot_on_axes(b, simulations_widget, widgets_plot_type, + data_widget, spectrogram_colormap_selection, dipole_smooth, - max_spectral_frequency, dipole_scaling, widgets, data, + max_spectral_frequency, dipole_scaling,data_smooth,data_scaling, widgets, data, fig_idx, fig, ax, existing_plots): """Plotting different types of data on the given axes. @@ -314,7 +319,7 @@ def _plot_on_axes(b, widgets_simulation, widgets_plot_type, existing_plots : ipywidgets.VBox A VBox widget that contains all the existing plots. """ - sim_name = widgets_simulation.value + sim_name = simulations_widget.value plot_type = widgets_plot_type.value # disable add plots for types that do not support overlay if plot_type in _no_overlay_plot_types: @@ -325,7 +330,7 @@ def _plot_on_axes(b, widgets_simulation, widgets_plot_type, single_simulation = data['simulations'][sim_name] - plot_config = { + simulation_plot_config = { "max_spectral_frequency": max_spectral_frequency.value, "dipole_scaling": dipole_scaling.value, "dipole_smooth": dipole_smooth.value, @@ -333,24 +338,31 @@ def _plot_on_axes(b, widgets_simulation, widgets_plot_type, } dpls_processed = _update_ax(fig, ax, single_simulation, sim_name, - plot_type, plot_config) + plot_type, simulation_plot_config) # If target_simulations is not None and we are plotting a dipole, # we need to plot the target dipole as well. - if target_simulations.value in data['simulations'].keys( + if data_widget.value in data['simulations'].keys( ) and plot_type == 'current dipole': - target_sim_name = target_simulations.value + target_sim_name = data_widget.value target_sim = data['simulations'][target_sim_name] + data_plot_config = { + "max_spectral_frequency": max_spectral_frequency.value, + "dipole_scaling": data_scaling.value, + "dipole_smooth": data_smooth.value, + "spectrogram_cm": spectrogram_colormap_selection.value + } + # plot the target dipole. # disable scaling for the target dipole. - plot_config['dipole_scaling'] = 1. + simulation_plot_config['dipole_scaling'] = 1. # plot the target dipole. target_dpl_processed = _update_ax( fig, ax, target_sim, target_sim_name, plot_type, - plot_config)[0] # we assume there is only one dipole. + data_plot_config)[0] # we assume there is only one dipole. # calculate the RMSE between the two dipoles. t0 = 0.0 @@ -447,13 +459,23 @@ def _get_ax_control(widgets, data, fig_idx, fig, ax): layout=layout, style=analysis_style, ) - dipole_smooth = FloatText(value=30, + simulation_dipole_smooth = FloatText(value=30, description='Dipole Smooth Window (ms):', disabled=False, layout=layout, style=analysis_style) - dipole_scaling = FloatText(value=3000, - description='Dipole Scaling:', + simulation_dipole_scaling = FloatText(value=3000, + description='Simulation Dipole Scaling:', + disabled=False, + layout=layout, + style=analysis_style) + data_dipole_smooth = FloatText(value=30, + description='Data Smooth Window (ms):', + disabled=False, + layout=layout, + style=analysis_style) + data_dipole_scaling = FloatText(value=3000, + description='Data Dipole Scaling:', disabled=False, layout=layout, style=analysis_style) @@ -505,9 +527,11 @@ def _on_plot_type_change(new_plot_type): widgets_plot_type=plot_type_selection, target_simulations=target_data_selection, spectrogram_colormap_selection=spectrogram_colormap_selection, - dipole_smooth=dipole_smooth, + dipole_smooth=simulation_dipole_smooth, max_spectral_frequency=max_spectral_frequency, - dipole_scaling=dipole_scaling, + dipole_scaling=simulation_dipole_scaling, + data_smooth=data_dipole_smooth, + data_scaling=data_dipole_scaling, widgets=widgets, data=data, fig_idx=fig_idx, @@ -517,8 +541,9 @@ def _on_plot_type_change(new_plot_type): )) vbox = VBox([ - simulation_selection, plot_type_selection, target_data_selection, - dipole_smooth, dipole_scaling, max_spectral_frequency, + plot_type_selection,simulation_selection, simulation_dipole_smooth, + simulation_dipole_scaling,target_data_selection, data_dipole_smooth, + data_dipole_scaling,max_spectral_frequency, spectrogram_colormap_selection, HBox( [plot_button, clear_button], diff --git a/hnn_core/gui/gui.py b/hnn_core/gui/gui.py index 70622d1d8..c8e2ee76b 100644 --- a/hnn_core/gui/gui.py +++ b/hnn_core/gui/gui.py @@ -1123,6 +1123,10 @@ def load_drive_and_connectivity(params, log_out, drives_out, add_drive_tab(params, drives_out, drive_widgets, drive_boxes, tstop, layout) +def is_loaded_data(simulation_data): + if 'net' in simulation_data: + return True + return False def on_upload_data_change(change, data, viz_manager, log_out): if len(change['owner'].value) == 0: @@ -1135,7 +1139,7 @@ def on_upload_data_change(change, data, viz_manager, log_out): if data_fname in data['simulation_data'].keys(): logger.error(f"Found existing data: {data_fname}.") return - + ext_content = data_dict['content'] ext_content = codecs.decode(ext_content, encoding="utf-8") with log_out: From 95ed9c1698041dcb1465b99d4e46a7feed508052 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Mon, 18 Mar 2024 11:31:39 -0400 Subject: [PATCH 02/13] fixing gui test and funciton args name --- hnn_core/gui/_viz_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index 34f91bda8..98679f1c0 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -523,9 +523,9 @@ def _on_plot_type_change(new_plot_type): plot_button.on_click( partial( _plot_on_axes, - widgets_simulation=simulation_selection, + simulations_widget=simulation_selection, widgets_plot_type=plot_type_selection, - target_simulations=target_data_selection, + data_widget=target_data_selection, spectrogram_colormap_selection=spectrogram_colormap_selection, dipole_smooth=simulation_dipole_smooth, max_spectral_frequency=max_spectral_frequency, @@ -841,11 +841,11 @@ def _simulate_edit_figure(self, fig_name, ax_name, simulation_name, ax_control_tabs.selected_index = ax_idx # ax config - simulation_ctrl = ax_control_tabs.children[ax_idx].children[0] + simulation_ctrl = ax_control_tabs.children[ax_idx].children[1] # return simulation_ctrl simulation_ctrl.value = simulation_name - plot_type_ctrl = ax_control_tabs.children[ax_idx].children[1] + plot_type_ctrl = ax_control_tabs.children[ax_idx].children[0] plot_type_ctrl.value = plot_type config_name_idx = { From 3ac138600b4560dbf10a3d14fbffa5395c99bb22 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Mon, 18 Mar 2024 11:52:32 -0400 Subject: [PATCH 03/13] fix linting errors --- hnn_core/gui/_viz_manager.py | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index 98679f1c0..1f48bcd1c 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -281,7 +281,8 @@ def _dynamic_rerender(fig): def _plot_on_axes(b, simulations_widget, widgets_plot_type, data_widget, spectrogram_colormap_selection, dipole_smooth, - max_spectral_frequency, dipole_scaling,data_smooth,data_scaling, widgets, data, + max_spectral_frequency, dipole_scaling, data_smooth, + data_scaling, widgets, data, fig_idx, fig, ax, existing_plots): """Plotting different types of data on the given axes. @@ -459,26 +460,33 @@ def _get_ax_control(widgets, data, fig_idx, fig, ax): layout=layout, style=analysis_style, ) - simulation_dipole_smooth = FloatText(value=30, - description='Dipole Smooth Window (ms):', - disabled=False, - layout=layout, - style=analysis_style) - simulation_dipole_scaling = FloatText(value=3000, - description='Simulation Dipole Scaling:', - disabled=False, - layout=layout, - style=analysis_style) - data_dipole_smooth = FloatText(value=30, - description='Data Smooth Window (ms):', - disabled=False, - layout=layout, - style=analysis_style) - data_dipole_scaling = FloatText(value=3000, - description='Data Dipole Scaling:', - disabled=False, - layout=layout, - style=analysis_style) + simulation_dipole_smooth = FloatText( + value=30, + description='Dipole Smooth Window (ms):', + disabled=False, + layout=layout, + style=analysis_style) + + simulation_dipole_scaling = FloatText( + value=3000, + description='Simulation Dipole Scaling:', + disabled=False, + layout=layout, + style=analysis_style) + + data_dipole_smooth = FloatText( + value=30, + description='Data Smooth Window (ms):', + disabled=False, + layout=layout, + style=analysis_style) + + data_dipole_scaling = FloatText( + value=3000, + description='Data Dipole Scaling:', + disabled=False, + layout=layout, + style=analysis_style) max_spectral_frequency = FloatText( value=100, @@ -541,9 +549,9 @@ def _on_plot_type_change(new_plot_type): )) vbox = VBox([ - plot_type_selection,simulation_selection, simulation_dipole_smooth, - simulation_dipole_scaling,target_data_selection, data_dipole_smooth, - data_dipole_scaling,max_spectral_frequency, + plot_type_selection, simulation_selection, simulation_dipole_smooth, + simulation_dipole_scaling, target_data_selection, data_dipole_smooth, + data_dipole_scaling, max_spectral_frequency, spectrogram_colormap_selection, HBox( [plot_button, clear_button], From ccb255aaf801902feef88b572047bcdcd38a78b2 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Mon, 18 Mar 2024 11:56:41 -0400 Subject: [PATCH 04/13] fix lint errors in gui.py --- hnn_core/gui/gui.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hnn_core/gui/gui.py b/hnn_core/gui/gui.py index c8e2ee76b..3d28fab41 100644 --- a/hnn_core/gui/gui.py +++ b/hnn_core/gui/gui.py @@ -1123,11 +1123,13 @@ def load_drive_and_connectivity(params, log_out, drives_out, add_drive_tab(params, drives_out, drive_widgets, drive_boxes, tstop, layout) + def is_loaded_data(simulation_data): if 'net' in simulation_data: return True return False + def on_upload_data_change(change, data, viz_manager, log_out): if len(change['owner'].value) == 0: logger.info("Empty change") @@ -1139,7 +1141,7 @@ def on_upload_data_change(change, data, viz_manager, log_out): if data_fname in data['simulation_data'].keys(): logger.error(f"Found existing data: {data_fname}.") return - + ext_content = data_dict['content'] ext_content = codecs.decode(ext_content, encoding="utf-8") with log_out: From d4809471d465e4cec0b3dd69d5a6ca1657342b99 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Mon, 18 Mar 2024 13:38:33 -0400 Subject: [PATCH 05/13] fixing gui tests --- hnn_core/tests/test_gui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hnn_core/tests/test_gui.py b/hnn_core/tests/test_gui.py index aeb1f7512..423a7afa6 100644 --- a/hnn_core/tests/test_gui.py +++ b/hnn_core/tests/test_gui.py @@ -359,7 +359,7 @@ def test_gui_edit_figure(): assert len(axes_config_tabs.children) == n_figs axes_config = axes_config_tabs.children[-1].children[1] - simulation_selection = axes_config.children[0].children[0] + simulation_selection = axes_config.children[0].children[1] assert simulation_selection.options == tuple(sim_names[:n_figs]) plt.close('all') @@ -378,7 +378,7 @@ def test_gui_figure_overlay(): for controls in tab.children[1].children: add_plot_button = controls.children[-2].children[0] clear_ax_button = controls.children[-2].children[1] - plot_type_selection = controls.children[1] + plot_type_selection = controls.children[0] assert plot_type_selection.disabled is True clear_ax_button.click() From affbfda203ef75b7ec8b826e83651f4f3af44b3c Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Thu, 21 Mar 2024 16:46:26 -0400 Subject: [PATCH 06/13] adding scaling and smooth input parameters for data comparison visualization --- hnn_core/gui/_viz_manager.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index 1f48bcd1c..cc4eb6787 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -330,11 +330,13 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type, widgets_plot_type.disabled = True single_simulation = data['simulations'][sim_name] - + target_is_sim = True if single_simulation['net'] is not None else False + scaling = dipole_scaling.value if target_is_sim else data_scaling.value + smooth = dipole_smooth.value if target_is_sim else data_smooth.value simulation_plot_config = { "max_spectral_frequency": max_spectral_frequency.value, - "dipole_scaling": dipole_scaling.value, - "dipole_smooth": dipole_smooth.value, + "dipole_scaling": scaling, + "dipole_smooth": smooth, "spectrogram_cm": spectrogram_colormap_selection.value } @@ -348,11 +350,13 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type, target_sim_name = data_widget.value target_sim = data['simulations'][target_sim_name] - + target_is_sim = True if target_sim['net'] is not None else False + scaling = dipole_scaling.value if target_is_sim else data_scaling.value + smooth = dipole_smooth.value if target_is_sim else data_smooth.value data_plot_config = { "max_spectral_frequency": max_spectral_frequency.value, - "dipole_scaling": data_scaling.value, - "dipole_smooth": data_smooth.value, + "dipole_scaling": scaling, + "dipole_smooth": smooth, "spectrogram_cm": spectrogram_colormap_selection.value } @@ -414,6 +418,7 @@ def _get_ax_control(widgets, data, fig_idx, fig, ax): layout = Layout(width="98%") simulation_names = tuple(data['simulations'].keys()) sim_name_default = simulation_names[-1] + if len(simulation_names) == 0: simulation_names = [ "None", @@ -421,7 +426,7 @@ def _get_ax_control(widgets, data, fig_idx, fig, ax): simulation_selection = Dropdown( options=simulation_names, - value=sim_name_default, + value=simulation_names[0], description='Simulation Data:', disabled=False, layout=layout, @@ -444,8 +449,12 @@ def _get_ax_control(widgets, data, fig_idx, fig, ax): style=analysis_style, ) + tagert_names = simulation_names[0:-1] + if len(simulation_names) > 1: + tagert_names = simulation_names[1:] + target_data_selection = Dropdown( - options=simulation_names[:-1] + ('None',), + options=tagert_names + ('None',), value='None', description='Data to Compare:', disabled=False, @@ -475,14 +484,14 @@ def _get_ax_control(widgets, data, fig_idx, fig, ax): style=analysis_style) data_dipole_smooth = FloatText( - value=30, + value=0, description='Data Smooth Window (ms):', disabled=False, layout=layout, style=analysis_style) data_dipole_scaling = FloatText( - value=3000, + value=1, description='Data Dipole Scaling:', disabled=False, layout=layout, From e47a1e8364f75ae3a77ca03a06322b5bcbd10d61 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Fri, 22 Mar 2024 14:33:14 -0400 Subject: [PATCH 07/13] applied code review suggestions. Added functio to avoid repeated code --- hnn_core/gui/_viz_manager.py | 64 ++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index cc4eb6787..d762b2d75 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -278,12 +278,26 @@ def _dynamic_rerender(fig): fig.tight_layout() +def create_plot_config(data, dipole_scaling, data_scaling, dipole_smooth, + data_smooth, max_spectral_frequency, + spectrogram_colormap_selection): + + target_is_sim = data['net'] is not None + scaling = dipole_scaling.value if target_is_sim else data_scaling.value + smooth = dipole_smooth.value if target_is_sim else data_smooth.value + return { + "max_spectral_frequency": max_spectral_frequency.value, + "dipole_scaling": scaling, + "dipole_smooth": smooth, + "spectrogram_cm": spectrogram_colormap_selection.value + } + + def _plot_on_axes(b, simulations_widget, widgets_plot_type, data_widget, - spectrogram_colormap_selection, dipole_smooth, - max_spectral_frequency, dipole_scaling, data_smooth, - data_scaling, widgets, data, - fig_idx, fig, ax, existing_plots): + spectrogram_colormap_selection, max_spectral_frequency, + dipole_smooth, dipole_scaling, data_smooth, data_scaling, + widgets, data, fig_idx, fig, ax, existing_plots): """Plotting different types of data on the given axes. Now this function is also responsible for comparing multiple simulations, @@ -330,15 +344,14 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type, widgets_plot_type.disabled = True single_simulation = data['simulations'][sim_name] - target_is_sim = True if single_simulation['net'] is not None else False - scaling = dipole_scaling.value if target_is_sim else data_scaling.value - smooth = dipole_smooth.value if target_is_sim else data_smooth.value - simulation_plot_config = { - "max_spectral_frequency": max_spectral_frequency.value, - "dipole_scaling": scaling, - "dipole_smooth": smooth, - "spectrogram_cm": spectrogram_colormap_selection.value - } + simulation_plot_config = create_plot_config( + data=single_simulation, + dipole_scaling=dipole_scaling, + data_scaling=data_scaling, + dipole_smooth=dipole_smooth, + data_smooth=data_smooth, + max_spectral_frequency=max_spectral_frequency, + spectrogram_colormap_selection=spectrogram_colormap_selection) dpls_processed = _update_ax(fig, ax, single_simulation, sim_name, plot_type, simulation_plot_config) @@ -350,19 +363,14 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type, target_sim_name = data_widget.value target_sim = data['simulations'][target_sim_name] - target_is_sim = True if target_sim['net'] is not None else False - scaling = dipole_scaling.value if target_is_sim else data_scaling.value - smooth = dipole_smooth.value if target_is_sim else data_smooth.value - data_plot_config = { - "max_spectral_frequency": max_spectral_frequency.value, - "dipole_scaling": scaling, - "dipole_smooth": smooth, - "spectrogram_cm": spectrogram_colormap_selection.value - } - - # plot the target dipole. - # disable scaling for the target dipole. - simulation_plot_config['dipole_scaling'] = 1. + data_plot_config = create_plot_config( + data=target_sim, + dipole_scaling=dipole_scaling, + data_scaling=data_scaling, + dipole_smooth=dipole_smooth, + data_smooth=data_smooth, + max_spectral_frequency=max_spectral_frequency, + spectrogram_colormap_selection=spectrogram_colormap_selection) # plot the target dipole. target_dpl_processed = _update_ax( @@ -449,7 +457,7 @@ def _get_ax_control(widgets, data, fig_idx, fig, ax): style=analysis_style, ) - tagert_names = simulation_names[0:-1] + tagert_names = simulation_names[:-1] if len(simulation_names) > 1: tagert_names = simulation_names[1:] @@ -544,8 +552,8 @@ def _on_plot_type_change(new_plot_type): widgets_plot_type=plot_type_selection, data_widget=target_data_selection, spectrogram_colormap_selection=spectrogram_colormap_selection, - dipole_smooth=simulation_dipole_smooth, max_spectral_frequency=max_spectral_frequency, + dipole_smooth=simulation_dipole_smooth, dipole_scaling=simulation_dipole_scaling, data_smooth=data_dipole_smooth, data_scaling=data_dipole_scaling, From e3ae1c4d49d845c7b025126f9214dcce200598da Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Fri, 22 Mar 2024 18:19:50 -0400 Subject: [PATCH 08/13] adding docustring to new funtion. removing unused is_loaded_data --- hnn_core/gui/_viz_manager.py | 31 +++++++++++++++++++++++++++++-- hnn_core/gui/gui.py | 6 ------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index d762b2d75..62d9fcdb1 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -278,10 +278,37 @@ def _dynamic_rerender(fig): fig.tight_layout() -def create_plot_config(data, dipole_scaling, data_scaling, dipole_smooth, - data_smooth, max_spectral_frequency, +def create_plot_config(data, dipole_scaling, dipole_smooth, + data_scaling, data_smooth, max_spectral_frequency, spectrogram_colormap_selection): + """ Returns dict of plotting parameters from input widgets + Parameters + ---------- + + Parameters: + data (dict): + A dictionary containing simulation data + sim_name (str): + The name of the simulation to access within the 'simulations' dictionary. + dipole_scaling (ipywidgets.FloatText): + An object with a 'value' attribute for dipole scaling in simulations. + data_scaling (ipywidgets.FloatText): + An object with a 'value' attribute for scaling in data visualizations. + dipole_smooth (ipywidgets.FloatText): + An object with a 'value' attribute for dipole smoothing in simulations. + data_smooth (ipywidgets.FloatText): + An object with a 'value' attribute for smoothing in data visualizations. + max_spectral_frequency (ipywidgets.FloatText): + An object with a 'value' attribute representing the maximum spectral frequency for the plot. + spectrogram_colormap_selection (ipywidgets.Dropdown): + An object with a 'value' attribute specifying the colormap for the spectrogram. + + Returns: + dict: A dictionary containing the plot configuration with keys 'max_spectral_frequency', + 'dipole_scaling', 'dipole_smooth', and 'spectrogram_cm'. + + """ target_is_sim = data['net'] is not None scaling = dipole_scaling.value if target_is_sim else data_scaling.value smooth = dipole_smooth.value if target_is_sim else data_smooth.value diff --git a/hnn_core/gui/gui.py b/hnn_core/gui/gui.py index 3d28fab41..70622d1d8 100644 --- a/hnn_core/gui/gui.py +++ b/hnn_core/gui/gui.py @@ -1124,12 +1124,6 @@ def load_drive_and_connectivity(params, log_out, drives_out, layout) -def is_loaded_data(simulation_data): - if 'net' in simulation_data: - return True - return False - - def on_upload_data_change(change, data, viz_manager, log_out): if len(change['owner'].value) == 0: logger.info("Empty change") From c4f23198099074b35752eaa7a54524deb3f32cc7 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Fri, 22 Mar 2024 20:43:20 -0400 Subject: [PATCH 09/13] fixing flake8 erros --- hnn_core/gui/_viz_manager.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index 62d9fcdb1..c8c4deb68 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -292,21 +292,23 @@ def create_plot_config(data, dipole_scaling, dipole_smooth, sim_name (str): The name of the simulation to access within the 'simulations' dictionary. dipole_scaling (ipywidgets.FloatText): - An object with a 'value' attribute for dipole scaling in simulations. + textfield widget for dipole scaling in simulations. data_scaling (ipywidgets.FloatText): - An object with a 'value' attribute for scaling in data visualizations. + textfield widget for scaling in data visualizations. dipole_smooth (ipywidgets.FloatText): - An object with a 'value' attribute for dipole smoothing in simulations. + textfield widget for dipole smoothing in simulations. data_smooth (ipywidgets.FloatText): - An object with a 'value' attribute for smoothing in data visualizations. + textfield widget for smoothing in data visualizations. max_spectral_frequency (ipywidgets.FloatText): - An object with a 'value' attribute representing the maximum spectral frequency for the plot. + textfield widget representing the maximum spectral frequency for the plot. spectrogram_colormap_selection (ipywidgets.Dropdown): - An object with a 'value' attribute specifying the colormap for the spectrogram. + textfield widget specifying the colormap for the spectrogram. Returns: - dict: A dictionary containing the plot configuration with keys 'max_spectral_frequency', - 'dipole_scaling', 'dipole_smooth', and 'spectrogram_cm'. + dict: A dictionary containing the plot configuration with keys: + 'max_spectral_frequency', + 'dipole_scaling', + 'dipole_smooth', and 'spectrogram_cm'. """ target_is_sim = data['net'] is not None From 3be7a2d394d4ad181d512b57fb3cd8df46b4a035 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Tue, 26 Mar 2024 09:34:18 -0400 Subject: [PATCH 10/13] removed logic to determine if data is a sim or loaded data --- hnn_core/gui/_viz_manager.py | 72 ++++++------------------------------ 1 file changed, 12 insertions(+), 60 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index c8c4deb68..1654cdf14 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -278,50 +278,6 @@ def _dynamic_rerender(fig): fig.tight_layout() -def create_plot_config(data, dipole_scaling, dipole_smooth, - data_scaling, data_smooth, max_spectral_frequency, - spectrogram_colormap_selection): - """ Returns dict of plotting parameters from input widgets - - Parameters - ---------- - - Parameters: - data (dict): - A dictionary containing simulation data - sim_name (str): - The name of the simulation to access within the 'simulations' dictionary. - dipole_scaling (ipywidgets.FloatText): - textfield widget for dipole scaling in simulations. - data_scaling (ipywidgets.FloatText): - textfield widget for scaling in data visualizations. - dipole_smooth (ipywidgets.FloatText): - textfield widget for dipole smoothing in simulations. - data_smooth (ipywidgets.FloatText): - textfield widget for smoothing in data visualizations. - max_spectral_frequency (ipywidgets.FloatText): - textfield widget representing the maximum spectral frequency for the plot. - spectrogram_colormap_selection (ipywidgets.Dropdown): - textfield widget specifying the colormap for the spectrogram. - - Returns: - dict: A dictionary containing the plot configuration with keys: - 'max_spectral_frequency', - 'dipole_scaling', - 'dipole_smooth', and 'spectrogram_cm'. - - """ - target_is_sim = data['net'] is not None - scaling = dipole_scaling.value if target_is_sim else data_scaling.value - smooth = dipole_smooth.value if target_is_sim else data_smooth.value - return { - "max_spectral_frequency": max_spectral_frequency.value, - "dipole_scaling": scaling, - "dipole_smooth": smooth, - "spectrogram_cm": spectrogram_colormap_selection.value - } - - def _plot_on_axes(b, simulations_widget, widgets_plot_type, data_widget, spectrogram_colormap_selection, max_spectral_frequency, @@ -373,14 +329,12 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type, widgets_plot_type.disabled = True single_simulation = data['simulations'][sim_name] - simulation_plot_config = create_plot_config( - data=single_simulation, - dipole_scaling=dipole_scaling, - data_scaling=data_scaling, - dipole_smooth=dipole_smooth, - data_smooth=data_smooth, - max_spectral_frequency=max_spectral_frequency, - spectrogram_colormap_selection=spectrogram_colormap_selection) + simulation_plot_config = { + "dipole_scaling": dipole_scaling.value, + "dipole_smooth": dipole_smooth.value, + "max_spectral_frequency": max_spectral_frequency.value, + "spectrogram_cm": spectrogram_colormap_selection.value + } dpls_processed = _update_ax(fig, ax, single_simulation, sim_name, plot_type, simulation_plot_config) @@ -392,14 +346,12 @@ def _plot_on_axes(b, simulations_widget, widgets_plot_type, target_sim_name = data_widget.value target_sim = data['simulations'][target_sim_name] - data_plot_config = create_plot_config( - data=target_sim, - dipole_scaling=dipole_scaling, - data_scaling=data_scaling, - dipole_smooth=dipole_smooth, - data_smooth=data_smooth, - max_spectral_frequency=max_spectral_frequency, - spectrogram_colormap_selection=spectrogram_colormap_selection) + data_plot_config = { + "dipole_scaling": data_scaling.value, + "dipole_smooth": data_smooth.value, + "max_spectral_frequency": max_spectral_frequency.value, + "spectrogram_cm": spectrogram_colormap_selection.value + } # plot the target dipole. target_dpl_processed = _update_ax( From 7de6d8f851b9adff0289b41d708a4ca09c75ef48 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Tue, 26 Mar 2024 12:17:14 -0400 Subject: [PATCH 11/13] MAINT: commenting out try-except block --- hnn_core/gui/_viz_manager.py | 39 +++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index 1654cdf14..b78573a6c 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -117,21 +117,36 @@ def unlink_relink(attribute): def _unlink_relink(f): @wraps(f) def wrapper(self, *args, **kwargs): - try: - # Unlink the widgets using the provided link object - link_attribute: link = getattr(self, attribute) - link_attribute.unlink() + link_attribute: link = getattr(self, attribute) + link_attribute.unlink() - # Call the original function - result = f(self, *args, **kwargs) + # Call the original function + result = f(self, *args, **kwargs) - # Re-link the widgets - link_attribute.link() + # Re-link the widgets + link_attribute.link() - return result - except Exception as e: - # Handle the exception and print it - print(f"An error occurred: {e}") + return result + + # For development purposes only + # Remove after gui development + # try: + # # Unlink the widgets using the provided link object + # link_attribute: link = getattr(self, attribute) + # link_attribute.unlink() + + # # Call the original function + # result = f(self, *args, **kwargs) + + # # Re-link the widgets + # link_attribute.link() + + # return result + # except IndexError: + # pass + # except Exception as e: + # # Handle the exception and print it + # print(f"An error occurred: {e}") return wrapper return _unlink_relink From 2dcf972201443d11e3923f8edc1e8fed1a89e904 Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Wed, 27 Mar 2024 12:10:40 -0400 Subject: [PATCH 12/13] MAINT: uncommenting atry-except dev code in viz_manager --- hnn_core/gui/_viz_manager.py | 41 +++++++++++++----------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index b78573a6c..783dc1c2a 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -117,36 +117,25 @@ def unlink_relink(attribute): def _unlink_relink(f): @wraps(f) def wrapper(self, *args, **kwargs): - link_attribute: link = getattr(self, attribute) - link_attribute.unlink() - # Call the original function - result = f(self, *args, **kwargs) + # For development purposes only + # Remove after gui development + try: + # Unlink the widgets using the provided link object + link_attribute: link = getattr(self, attribute) + link_attribute.unlink() - # Re-link the widgets - link_attribute.link() + # Call the original function + result = f(self, *args, **kwargs) - return result + # Re-link the widgets + link_attribute.link() + + return result + except Exception as e: + # Handle the exception and print it + print(f"An error occurred: {e}") - # For development purposes only - # Remove after gui development - # try: - # # Unlink the widgets using the provided link object - # link_attribute: link = getattr(self, attribute) - # link_attribute.unlink() - - # # Call the original function - # result = f(self, *args, **kwargs) - - # # Re-link the widgets - # link_attribute.link() - - # return result - # except IndexError: - # pass - # except Exception as e: - # # Handle the exception and print it - # print(f"An error occurred: {e}") return wrapper return _unlink_relink From e83b008c6e5143df672facc101e262f117f9737d Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Fri, 29 Mar 2024 13:08:39 -0400 Subject: [PATCH 13/13] MAINT: remove try-except block --- hnn_core/gui/_viz_manager.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/hnn_core/gui/_viz_manager.py b/hnn_core/gui/_viz_manager.py index 783dc1c2a..b8f1e0e88 100644 --- a/hnn_core/gui/_viz_manager.py +++ b/hnn_core/gui/_viz_manager.py @@ -117,25 +117,17 @@ def unlink_relink(attribute): def _unlink_relink(f): @wraps(f) def wrapper(self, *args, **kwargs): + # Unlink the widgets using the provided link object + link_attribute: link = getattr(self, attribute) + link_attribute.unlink() - # For development purposes only - # Remove after gui development - try: - # Unlink the widgets using the provided link object - link_attribute: link = getattr(self, attribute) - link_attribute.unlink() + # Call the original function + result = f(self, *args, **kwargs) - # Call the original function - result = f(self, *args, **kwargs) - - # Re-link the widgets - link_attribute.link() - - return result - except Exception as e: - # Handle the exception and print it - print(f"An error occurred: {e}") + # Re-link the widgets + link_attribute.link() + return result return wrapper return _unlink_relink