Skip to content

Commit

Permalink
Merge pull request #314 from jo-mueller/save-and-load-settings
Browse files Browse the repository at this point in the history
Save and load settings
  • Loading branch information
jo-mueller authored Jul 18, 2023
2 parents e0be531 + 432b71f commit 3e82559
Show file tree
Hide file tree
Showing 12 changed files with 679 additions and 481 deletions.
795 changes: 394 additions & 401 deletions docs/01_code_usage/01_toolboxes/demo_analyze_everything.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ install_requires =
napari-tools-menu>=0.1.15
numpy<1.24.0
pandas
pyclesperanto-prototype
pygeodesic
pyocclient
pyshtools<=4.10.0
Expand Down
2 changes: 2 additions & 0 deletions src/napari_stress/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from . import _approximation as approximation
from . import _reconstruction as reconstruction
from . import _sample_data as sample_data
from . import _utils as utils
from . import _stress as stress_backend

from ._preprocess import rescale
from ._surface import smooth_sinc,\
Expand Down
32 changes: 32 additions & 0 deletions src/napari_stress/_measurements/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ def __init__(self, napari_viewer):
# connect buttons
self.pushButton_run.clicked.connect(self._run)
self.spinBox_max_degree.valueChanged.connect(self._check_minimal_point_number)
self.pushButton_import.clicked.connect(self._import_settings)
self.pushButton_export.clicked.connect(self._export_settings)

def _import_settings(self, file_name: str = None):
"""
Import settings from yaml file.
"""
from .._utils.import_export_settings import import_settings

settings = import_settings(parent=self, file_name=file_name)
if settings:
self.spinBox_max_degree.setValue(settings['max_degree'])
self.comboBox_quadpoints.setCurrentIndex(
self.comboBox_quadpoints.findData(settings['n_quadrature_points']))
self.doubleSpinBox_gamma.setValue(settings['gamma'])

def _export_settings(self, file_name: str = None):
"""
Export settings to yaml file.
"""
from .._utils.import_export_settings import export_settings

settings = {'max_degree': self.spinBox_max_degree.value(),
'n_quadrature_points': self.comboBox_quadpoints.currentData(),
'gamma': self.doubleSpinBox_gamma.value()}
export_settings(settings, parent=self, file_name=file_name)

def eventFilter(self, obj: QObject, event: QEvent):
"""https://forum.image.sc/t/composing-workflows-in-napari/61222/3."""
Expand All @@ -74,6 +100,12 @@ def _check_minimal_point_number(self) -> None:

def _run(self):
"""Call analysis function."""
# Prepare before analysis
from .. import stress_backend
_ = stress_backend.lbdv_info(Max_SPH_Deg=self.spinBox_max_degree.value(),
Num_Quad_Pts=int(self.comboBox_quadpoints.currentData()))

# Run analysis
results = comprehensive_analysis(
self.layer_select.value.data,
max_degree=self.spinBox_max_degree.value(),
Expand Down
99 changes: 61 additions & 38 deletions src/napari_stress/_measurements/toolbox.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,64 @@
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<width>709</width>
<height>593</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="4" column="0" colspan="2">
<widget class="QPushButton" name="pushButton_run">
<property name="text">
<string>Run</string>
<item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Stress</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Interfacial surface tension [mN/m]</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_gamma">
<property name="decimals">
<number>3</number>
</property>
<property name="value">
<double>3.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Input pointcloud</string>
<item row="5" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Import &amp; export settings</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="pushButton_export">
<property name="text">
<string>Export settings</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_import">
<property name="text">
<string>Import settings</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item row="1" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Spherical harmonics</string>
Expand Down Expand Up @@ -61,7 +96,14 @@
</layout>
</widget>
</item>
<item row="5" column="1">
<item row="7" column="0" colspan="3">
<widget class="QPushButton" name="pushButton_run">
<property name="text">
<string>Run</string>
</property>
</widget>
</item>
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
Expand All @@ -74,36 +116,17 @@
</property>
</spacer>
</item>
<item row="0" column="1">
<widget class="QWidget" name="input_widget" native="true"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Stress</string>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Input pointcloud</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Interfacial surface tension [mN/m]</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="doubleSpinBox_gamma">
<property name="decimals">
<number>3</number>
</property>
<property name="value">
<double>3.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<item row="0" column="1" colspan="2">
<widget class="QWidget" name="input_widget" native="true"/>
</item>
<item row="6" column="0" colspan="3">
<widget class="QCheckBox" name="checkBox_use_dask">
<property name="text">
<string>Parallelize with dask (only timelapse)</string>
Expand Down
56 changes: 54 additions & 2 deletions src/napari_stress/_reconstruction/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from napari_tools_menu import register_dock_widget
from qtpy import uic
from qtpy.QtCore import QEvent, QObject
from qtpy.QtWidgets import QWidget
from qtpy.QtWidgets import QWidget, QFileDialog

from .._utils.frame_by_frame import frame_by_frame

Expand Down Expand Up @@ -38,9 +38,10 @@ def __init__(self, napari_viewer):

# calculate density/point number
self.spinBox_n_vertices.setValue(256)

self.pushButton_run.clicked.connect(self._run)
self.image_layer_select.changed.connect(self._set_scales)
self.pushButton_export.clicked.connect(self._export_settings)
self.pushButton_import.clicked.connect(self._import_settings)

self._set_scales()

Expand All @@ -62,6 +63,57 @@ def _set_scales(self):
except Exception:
pass

def _export_settings(self, file_name: str = None):
"""
Export reconstruction parameters to YAML file.
"""
from .._utils.import_export_settings import export_settings

reconstruction_parameters = {
'voxelsize': np.asarray([self.doubleSpinBox_voxelsize_z.value(),
self.doubleSpinBox_voxelsize_y.value(),
self.doubleSpinBox_voxelsize_x.value()]),
'target_voxelsize': self.doubleSpinBox_target_voxelsize.value(),
'smoothing_sigma': self.doubleSpinBox_gaussian_blur.value(),
'n_smoothing_iterations': self.spinBox_n_smoothing.value(),
'n_points': self.spinBox_n_vertices.value(),
'n_tracing_iterations': self.spinBox_n_refinement_steps.value(),
'resampling_length': self.doubleSpinBox_sampling_length.value(),
'fit_type': self.comboBox_fittype.currentText(),
'edge_type': self.comboBox_fluorescence_type.currentText(),
'trace_length': self.doubleSpinBox_trace_length.value(),
'sampling_distance': self.doubleSpinBox_sampling_distance.value(),
'interpolation_method': self.comboBox_interpolation_method.currentText(),
'outlier_tolerance': self.doubleSpinBox_outlier_tolerance.value(),
'remove_outliers': self.checkBox_remove_outliers.isChecked()}

export_settings(reconstruction_parameters, self, file_name=file_name)

def _import_settings(self, file_name: str = None):
"""
Import reconstruction parameters from YAML file.
"""
from .._utils.import_export_settings import import_settings

reconstruction_parameters = import_settings(self, file_name=file_name)

self.doubleSpinBox_voxelsize_z.setValue(reconstruction_parameters['voxelsize'][0])
self.doubleSpinBox_voxelsize_y.setValue(reconstruction_parameters['voxelsize'][1])
self.doubleSpinBox_voxelsize_x.setValue(reconstruction_parameters['voxelsize'][2])
self.doubleSpinBox_target_voxelsize.setValue(reconstruction_parameters['target_voxelsize'])
self.doubleSpinBox_gaussian_blur.setValue(reconstruction_parameters['smoothing_sigma'])
self.spinBox_n_smoothing.setValue(reconstruction_parameters['n_smoothing_iterations'])
self.spinBox_n_vertices.setValue(reconstruction_parameters['n_points'])
self.spinBox_n_refinement_steps.setValue(reconstruction_parameters['n_tracing_iterations'])
self.doubleSpinBox_sampling_length.setValue(reconstruction_parameters['resampling_length'])
self.comboBox_fittype.setCurrentText(reconstruction_parameters['fit_type'])
self.comboBox_fluorescence_type.setCurrentText(reconstruction_parameters['edge_type'])
self.doubleSpinBox_trace_length.setValue(reconstruction_parameters['trace_length'])
self.doubleSpinBox_sampling_distance.setValue(reconstruction_parameters['sampling_distance'])
self.comboBox_interpolation_method.setCurrentText(reconstruction_parameters['interpolation_method'])
self.doubleSpinBox_outlier_tolerance.setValue(reconstruction_parameters['outlier_tolerance'])
self.checkBox_remove_outliers.setChecked(reconstruction_parameters['remove_outliers'])

def _run(self):
"""Call analysis function."""
import webbrowser
Expand Down
Loading

0 comments on commit 3e82559

Please sign in to comment.