Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Better serialization mechanism allow for declaration data structure migration locally #462

Merged
merged 163 commits into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
c55b168
ensure separate savefolder
Czaki Nov 4, 2021
e3b47a3
add initial hook to json_hooks
Czaki Nov 4, 2021
2901db2
add basic tests
Czaki Nov 18, 2021
b4546e1
change ROIExtractionProfile to pydantic.BaseModel
Czaki Nov 19, 2021
1f82396
add new class register
Czaki Nov 23, 2021
a9797db
use register in new serialization methods
Czaki Nov 23, 2021
af35416
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 23, 2021
7feb680
fix fixtures
Czaki Nov 23, 2021
fe0a31f
ad test for json hooks
Czaki Nov 23, 2021
b6852b1
add test for as_dict
Czaki Nov 23, 2021
46d75b7
Merge branch 'develop' into feature/better_serialization
Czaki Nov 28, 2021
a0e2318
Merge branch 'develop' into feature/better_serialization
Czaki Dec 6, 2021
479533c
Merge branch 'develop' into feature/better_serialization
Czaki Dec 30, 2021
1527e70
change HistoryElement and MaskProperty to pydantic base
Czaki Dec 30, 2021
be4b2e2
feat: Better serialization mechanism with improved migration (Sourcer…
sourcery-ai[bot] Dec 30, 2021
6f7d28b
dellay imports for avoid circular imports
Czaki Dec 31, 2021
56c638b
fix Unnecessary `None` provided as default
Czaki Dec 31, 2021
70f7dd0
next change class to BaseModel, add migration informations
Czaki Jan 1, 2022
ee10d99
fix bug in conftest
Czaki Jan 1, 2022
d984121
fix for notebook
Czaki Jan 2, 2022
0677aae
change MeasurementEntry to BaseModel
Czaki Jan 2, 2022
dbab1c9
ommit missed version
Czaki Jan 2, 2022
6307c4f
fix old_paths of MeasurementEntry
Czaki Jan 2, 2022
c19e074
fix warnings
Czaki Jan 2, 2022
a7b83f3
fix replace_ usage
Czaki Jan 2, 2022
9dca6c4
fix bug in coping EventedDict
Czaki Jan 2, 2022
a48b6c8
automatically report error with importing saved profiles
Czaki Jan 2, 2022
7d4c2b2
add support of sub class serialization,
Czaki Jan 7, 2022
191ca6f
base generate class using descriptor
Czaki Jan 8, 2022
c61ed22
sourcery refactor
Czaki Jan 10, 2022
b9aa9dd
add algorithm selection base model and test
Czaki Jan 10, 2022
6ea4b1e
start threshold section migration
Czaki Jan 10, 2022
47cc5b7
initial conversion function from Base model to old type
Czaki Jan 10, 2022
89fbcb3
protetec contextmanager cleaning
Czaki Jan 10, 2022
b17a45b
Merge remote-tracking branch 'origin-public/develop' into feature/bet…
Czaki Jan 13, 2022
3cff873
feat: Better serialization mechanism with improved migration (Sourcer…
sourcery-ai[bot] Jan 13, 2022
5e33252
Merge branch 'develop' into feature/better_serialization
Czaki Jan 18, 2022
996f76f
move register inside AlgorithmSelection
Czaki Jan 19, 2022
d7bdecc
update threshold
Czaki Jan 19, 2022
4ff7aa3
add support for int bounds
Czaki Jan 31, 2022
2073674
fix type annotation
Czaki Jan 31, 2022
7002afa
Merge remote-tracking branch 'origin-public/develop' into feature/bet…
Czaki Feb 1, 2022
f9934c3
finish test for base types
Czaki Feb 1, 2022
5632882
add support for AlgorithmSelection in Base model conversion
Czaki Feb 1, 2022
4d5b429
add tests for FormWidget
Czaki Feb 3, 2022
b5e9bb4
add sub class support using __argument_class__
Czaki Feb 3, 2022
1f71fa7
add migrations from dict
Czaki Feb 3, 2022
2ed806f
Merge remote-tracking branch 'origin-public/develop' into feature/bet…
Czaki Feb 3, 2022
2283988
image writter simplify code
Czaki Feb 4, 2022
49c03ea
fix json test and serialization
Czaki Feb 7, 2022
be7d9ea
use class base threshold arguments
Czaki Feb 7, 2022
f67aab9
fix LGTM warning
Czaki Feb 7, 2022
2b085cf
add .sourcery.yml
Czaki Feb 7, 2022
72d6142
update name to reflect sourcery documentation
Czaki Feb 7, 2022
1a8b92f
feat: Better serialization mechanism with improved migration (Sourcer…
sourcery-ai[bot] Feb 8, 2022
3a3ff42
Fix manifest declaration
Czaki Feb 8, 2022
d0779a2
feat: Better serialization mechanism with improved migration (Sourcer…
sourcery-ai[bot] Feb 8, 2022
493642d
update watersheed
Czaki Feb 9, 2022
1d68cdd
migrate noise filtering
Czaki Feb 9, 2022
6bf5ef0
use AlgorithmSelection for noise_filtering and watersheed
Czaki Feb 9, 2022
e56dc37
better register initialization
Czaki Feb 9, 2022
4eaf0d3
update Double threshold
Czaki Feb 9, 2022
a0414a0
fix description text
Czaki Feb 9, 2022
fd1bc99
fix xvfb configuration
Czaki Feb 9, 2022
dcdec6c
fix type annotation
Czaki Feb 9, 2022
14ac0b7
fix part of deepsource warnings
Czaki Feb 10, 2022
3ee734a
Merge branch 'develop' into feature/better_serialization
Czaki Feb 10, 2022
7a4ec7d
update border smoothing
Czaki Feb 10, 2022
9f8ee8c
add empty __argument_class__
Czaki Feb 10, 2022
9664655
Merge remote-tracking branch 'origin-public/develop' into feature/bet…
Czaki Feb 13, 2022
07b1bab
forbide extra arguments in pydantic model
Czaki Feb 13, 2022
67c8102
migrate segmentation module
Czaki Feb 14, 2022
8a7dc09
forbide extra arguments of segmentation algorithm
Czaki Feb 14, 2022
48133e2
migrate mask_partition_utils
Czaki Feb 14, 2022
9d9e6b9
add text addition
Czaki Feb 15, 2022
8ff73e5
allow to control position in base_model_to_algorithm_property output
Czaki Feb 15, 2022
27ae473
sibplify code by refactor on two functions
Czaki Feb 15, 2022
afb1cf4
fix type error
Czaki Feb 15, 2022
0e18569
migrate mu mid
Czaki Feb 15, 2022
3052408
add basic support for rename algorithms
Czaki Feb 16, 2022
5973f42
forbide extra fields in test
Czaki Feb 16, 2022
89792b0
add optional parameter to rename_key function
Czaki Feb 16, 2022
04661f8
migrate restartable algorithm, clean part of warnings
Czaki Feb 17, 2022
6d0a235
move mask register dict to AlgorithmSelection subclass
Czaki Feb 17, 2022
755f247
move model update to new miigrations mechanism
Czaki Feb 18, 2022
c489335
capitalize default title
Czaki Feb 18, 2022
c443919
exclude typing.TYPE_CHECKING from coverage
Czaki Feb 18, 2022
75222b8
simplify code
Czaki Feb 18, 2022
391ff39
migrate measurement part 1
Czaki Feb 18, 2022
5817c7c
Merge remote-tracking branch 'origin-public/develop' into feature/bet…
Czaki Feb 18, 2022
3ab50d1
merge obsolete else clause
Czaki Feb 21, 2022
d5f6230
allow to use migrations of parrent class
Czaki Feb 21, 2022
e4a166a
fix version numbers
Czaki Feb 21, 2022
28d832d
fix version
Czaki Feb 21, 2022
f4764ac
add option to ignore parents migration
Czaki Feb 21, 2022
6b03761
feat: Better serialization mechanism with improved migration (Sourcer…
sourcery-ai[bot] Feb 21, 2022
e145421
fix: Module 'typing' is imported with both 'import' and 'import from'
Czaki Feb 21, 2022
66c8c6c
try to solve linter warnings
Czaki Feb 21, 2022
30ff200
first docs update
Czaki Feb 22, 2022
3d72fc6
update docs
Czaki Feb 22, 2022
efe20fc
better super class migrations mechanism
Czaki Feb 22, 2022
33dd65f
add more documentation text
Czaki Feb 22, 2022
f50cbf8
move implementation of ProfileDict and EventedDict to utils module
Czaki Feb 22, 2022
023507a
fix wrong usage of analysis_algorithm_dict
Czaki Feb 22, 2022
01ed6f6
Better detection if AlgorithmDescribeBase is new style
Czaki Feb 22, 2022
0441af0
fix type annotations
Czaki Feb 23, 2022
8f60e1d
Add wield list for support nested base model.
Czaki Feb 23, 2022
3635410
fix pyside signal connection
Czaki Feb 24, 2022
9092c39
use __new_style__ to determine fields description
Czaki Feb 24, 2022
a1f6b6b
initial fixes for channel in napari widgets
Czaki Mar 1, 2022
51a8607
fix type annotation
Czaki Mar 14, 2022
f041091
fix repetitive constant
Czaki Mar 14, 2022
4abf8c3
Merge remote-tracking branch 'origin-public/develop' into feature/bet…
Czaki Mar 21, 2022
efdc63b
move Channel to PartSegImage and change It to class
Czaki Mar 21, 2022
933a578
make MeasurementProfile pydantic
Czaki Mar 21, 2022
2397789
fix "Module is imported with 'import' and 'import from'"
Czaki Mar 21, 2022
a0ac0ae
fix notebook
Czaki Mar 21, 2022
e942800
fix part of deepsource warnings
Czaki Mar 21, 2022
0800afb
silence R0201 in tests
Czaki Mar 21, 2022
129eb7b
fix notebook
Czaki Mar 22, 2022
7324708
fix pylint warnings a,d fix set_parameters in roi extraction
Czaki Mar 22, 2022
b71bbe9
fix typo
Czaki Mar 22, 2022
f23b4ed
fix notebook part 2
Czaki Mar 22, 2022
c6ae960
clean deprecations in notebook
Czaki Mar 22, 2022
fb6346b
update documentation
Czaki Mar 22, 2022
27f43b8
fix type annotation and code coverage
Czaki Mar 23, 2022
9e8bb14
clean enum_register usage
Czaki Mar 23, 2022
160e291
remove obsolete code
Czaki Mar 23, 2022
e02bf8f
ignore few module __getattr__ in codecov
Czaki Mar 23, 2022
756b93b
fix double import
Czaki Mar 23, 2022
37bc61f
fix tests
Czaki Mar 24, 2022
329f8a6
add common_gui.algorithm_descriptions tests
Czaki Mar 24, 2022
d79172a
move mesurements name migration to a proper place
Czaki Mar 24, 2022
cd51c6b
clean Leaf migration
Czaki Mar 24, 2022
3a990fd
fix pyside test error
Czaki Mar 25, 2022
7bca342
update to use Extra.Forbide for each model
Czaki Mar 25, 2022
9a8edb3
Add code for convert data structures in ROIExtractionProfile
Czaki Mar 25, 2022
e23caf0
clean old migration code
Czaki Mar 25, 2022
d8ef16f
Notebook fix
Czaki Mar 25, 2022
d1c80d7
update manifest
Czaki Mar 25, 2022
8b1a7d1
fix linter warnings
Czaki Mar 25, 2022
251cd25
Merge remote-tracking branch 'origin-public/develop' into feature/bet…
Czaki Mar 28, 2022
d05f156
add test for loading old saves, fix bugs
Czaki Mar 28, 2022
8a85c1d
fix bug in set algorithm parameters
Czaki Mar 28, 2022
e84f85d
fix bug in measurement load
Czaki Mar 28, 2022
21f6be9
fix manifest file
Czaki Mar 28, 2022
aef2287
colapse test data files
Czaki Mar 28, 2022
a961a00
clean after review
Czaki Mar 28, 2022
c5fe28e
try to prevent windows sesion test fail
Czaki Mar 28, 2022
ec9fc64
silence dummy pylint warnings
Czaki Mar 28, 2022
51b459b
fix getting channel by name
Czaki Mar 28, 2022
e8e6748
fix checking Chanel subclassing
Czaki Mar 28, 2022
63dc3c2
fix advanced window
Czaki Mar 28, 2022
c3cd830
update DistanceMaskROIParameters field name
Czaki Mar 28, 2022
605c31f
fix version annotation
Czaki Mar 28, 2022
dc8706e
Improve Leaf.parameters validation
Czaki Mar 28, 2022
5bd77b7
undo save suffix add
Czaki Mar 28, 2022
838e307
fix black configuration
Czaki Mar 28, 2022
eabdaab
silence pylint warning
Czaki Mar 28, 2022
cbeaf5a
do not allow exception to break application on startup
Czaki Mar 28, 2022
dc061ef
fix json_hooks tests
Czaki Mar 28, 2022
1a973a9
fix utils test
Czaki Mar 28, 2022
777ea1d
bump black version
Czaki Mar 28, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ test_data/
/PartSegCore/segmentation/multiscale_opening/*.gch
package/PartSegCore/multiscale_opening/\.vscode/

package/PartSegCore/multiscale_opening/\.vscode/
/tutorials/tutorial-chromosome-1/tutorial-chromosome1.pdf
!/package/tests/test_data/measurements_profile.json

Expand All @@ -489,3 +488,6 @@ package/PartSegCore/multiscale_opening/\.vscode/
*.e6t

!docs/Makefile

!package/tests/test_data/old_saves/*.[0-9]
!package/tests/test_data/old_saves/*.[0-9][0-9]
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 22.3.0
hooks:
- id: black
pass_filenames: true
Expand Down
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ global-include *.pyx
global-include *.pxd
include package/tests/test_data/ome.xsd.xml
include package/tests/test_data/napari_measurements_profile.json
include package/tests/test_data/notebook/*.json
include package/tests/test_data/old_saves/*/*/*.json
include Readme.md
include changelog.md
include pyproject.toml
Expand Down
6 changes: 0 additions & 6 deletions docs/PartSegCore/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ On this page there are described base classes of PartSegCore module
.. automodule:: PartSegCore.algorithm_describe_base
:members:

.channel_class
--------------
.. automodule:: PartSegCore.channel_class
:members:
:show-inheritance:

.image_operations
-----------------
.. automodule:: PartSegCore.image_operations
Expand Down
9 changes: 9 additions & 0 deletions docs/PartSegCore/class_register.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PartSegCore.class_register
==========================



.. automodule:: PartSegCore.class_register
:members:
:inherited-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/PartSegCore/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This package contains calculation backend of PartSeg
:caption: Contents:

base
class_register
color_image
segmentation
analysis/base
Expand Down
7 changes: 0 additions & 7 deletions docs/PartSegImage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,3 @@ PartSegImage.image_reader
:members:
:exclude-members: ImageReader, MyTiffPage
:show-inheritance:


PartSegImage.tifffile_fixes
---------------------------

.. autoclass:: PartSegImage.tifffile_fixes.MyTiffPage
:members: asarray
8 changes: 7 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

from datetime import date

import PartSeg

# -- Project information -----------------------------------------------------

project = "PartSeg"
copyright = "2019, Laboratory of Functional and Structural Genomics"
copyright = f"{date.today().year}, Laboratory of Functional and Structural Genomics"
author = "Grzegorz Bokota (LFSG)"

# The full version, including alpha/beta/rc tags
Expand All @@ -37,7 +40,9 @@
"sphinx_qt_documentation",
"sphinx.ext.viewcode",
"sphinx.ext.graphviz",
"sphinx_autodoc_typehints",
"PartSegCore.sphinx.auto_parameters",
"sphinxcontrib.autodoc_pydantic",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -67,6 +72,7 @@
"python": ("https://docs.python.org/3", None),
"PyQt5": ("https://www.riverbankcomputing.com/static/Docs/PyQt5", None),
"Numpy": ("https://docs.scipy.org/doc/numpy/", None),
"packaging": ("https://packaging.pypa.io/en/latest/", None),
}

qt_documentation = "Qt5"
Expand Down
6 changes: 0 additions & 6 deletions docs/custom_application.rst

This file was deleted.

1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ The documentation is incomplete. Many utilities are undocumented.
PartSegCore/index
common_gui/index
common_backend/index
custom_application
PartSegImage
interface-overview/interface-overview

Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
sphinx-autodoc-annotation==1.0.post1
sphinx-autodoc-typehints==1.17.0
autodoc_pydantic==1.6.1
sphinx-qt-documentation==0.3
sphinx!=3.0.0, !=3.5.0
27 changes: 15 additions & 12 deletions package/PartSeg/_roi_analysis/advanced_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from contextlib import suppress
from copy import deepcopy
from typing import Optional, Tuple, Union
from typing import Optional, Tuple, Union, cast

from qtpy.QtCore import QEvent, Qt, Slot
from qtpy.QtGui import QIcon
Expand Down Expand Up @@ -31,7 +31,7 @@
from superqt import QEnumComboBox, ensure_main_thread

from PartSeg.common_gui.advanced_tabs import AdvancedWindow
from PartSegCore.analysis.algorithm_description import analysis_algorithm_dict
from PartSegCore.analysis.algorithm_description import AnalysisAlgorithmSelection
from PartSegCore.analysis.measurement_base import AreaType, Leaf, MeasurementEntry, Node, PerComponent
from PartSegCore.analysis.measurement_calculation import MEASUREMENT_DICT, MeasurementProfile
from PartSegCore.universal_const import UNIT_SCALE, Units
Expand Down Expand Up @@ -108,7 +108,7 @@ def __init__(self, settings: PartSettings):
spacing_layout = QHBoxLayout()
spacing_layout.addWidget(self.lock_spacing)
for txt, el in zip(["x", "y", "z"], self.spacing[::-1]):
spacing_layout.addWidget(QLabel(txt + ":"))
spacing_layout.addWidget(QLabel(f"{txt}:"))
spacing_layout.addWidget(el)
spacing_layout.addWidget(self.units)
spacing_layout.addStretch(1)
Expand Down Expand Up @@ -167,14 +167,15 @@ def profile_chosen(self, text):
# TODO update with knowledge from profile dict
self.delete_btn.setEnabled(True)
self.rename_btn.setEnabled(True)
self.info_label.setPlainText(profile.pretty_print(analysis_algorithm_dict))
self.info_label.setPlainText(profile.pretty_print(AnalysisAlgorithmSelection.__register__))

def synchronize_spacing(self):
if self.lock_spacing.isChecked():
self.spacing[1].setValue(self.spacing[2].value())

def image_spacing_change(self):
spacing = [el.value() / UNIT_SCALE[self.units.currentIndex()] for i, el in enumerate(self.spacing)]
spacing = [el.value() / UNIT_SCALE[self.units.currentIndex()] for el in self.spacing]

if not self.spacing[0].isEnabled():
spacing = spacing[1:]
self._settings.image_spacing = spacing
Expand Down Expand Up @@ -637,7 +638,7 @@ def get_parameters(self, node: Union[Node, Leaf], area: AreaType, component: Per
node = node.replace_(per_component=component)
with suppress(KeyError):
arguments = MEASUREMENT_DICT[str(node.name)].get_fields()
if len(arguments) > 0 and len(node.dict) == 0:
if len(arguments) > 0 and len(dict(node.parameters)) == 0:
dial = self.form_dialog(arguments)
if dial.exec_():
node = node._replace(dict=dial.get_values())
Expand Down Expand Up @@ -697,9 +698,9 @@ def save_action(self):
return
selected_values = []
for i in range(self.profile_options_chosen.count()):
element: MeasurementListWidgetItem = self.profile_options_chosen.item(i)
selected_values.append(MeasurementEntry(element.text(), element.stat))
stat_prof = MeasurementProfile(self.profile_name.text(), selected_values)
element = cast(MeasurementListWidgetItem, self.profile_options_chosen.item(i))
selected_values.append(MeasurementEntry(name=element.text(), calculation_tree=element.stat))
stat_prof = MeasurementProfile(name=self.profile_name.text(), chosen_fields=selected_values)
self.settings.measurement_profiles[stat_prof.name] = stat_prof
self.settings.dump()
self.export_profiles_butt.setEnabled(True)
Expand All @@ -722,9 +723,11 @@ def named_save_action(self):
if val_dialog.exec_():
selected_values = []
for i in range(self.profile_options_chosen.count()):
element: MeasurementListWidgetItem = self.profile_options_chosen.item(i)
selected_values.append(MeasurementEntry(val_dialog.result[element.text()], element.stat))
stat_prof = MeasurementProfile(self.profile_name.text(), selected_values)
element = cast(MeasurementListWidgetItem, self.profile_options_chosen.item(i))
selected_values.append(
MeasurementEntry(name=val_dialog.result[element.text()], calculation_tree=element.stat)
)
stat_prof = MeasurementProfile(name=self.profile_name.text(), chosen_fields=selected_values)
self.settings.measurement_profiles[stat_prof.name] = stat_prof
self.export_profiles_butt.setEnabled(True)

Expand Down
4 changes: 2 additions & 2 deletions package/PartSeg/_roi_analysis/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def __init__(
self.choose_profile.textActivated.connect(self.change_profile)
self.interactive_use.stateChanged.connect(self.execute_btn.setDisabled)
self.interactive_use.stateChanged.connect(self.interactive_change)
self.algorithm_choose_widget = AlgorithmChoose(settings, algorithm_description.analysis_algorithm_dict)
self.algorithm_choose_widget = AlgorithmChoose(settings, algorithm_description.AnalysisAlgorithmSelection)
self.algorithm_choose_widget.result.connect(self.execution_done)
self.algorithm_choose_widget.finished.connect(self.calculation_finished)
self.algorithm_choose_widget.value_changed.connect(self.interactive_algorithm_execute)
Expand Down Expand Up @@ -627,7 +627,7 @@ def image_read(self):
self.options_panel.interactive_algorithm_execute()

def reload(self):
self.options_panel.algorithm_choose_widget.reload(algorithm_description.analysis_algorithm_dict)
self.options_panel.algorithm_choose_widget.reload(algorithm_description.AnalysisAlgorithmSelection)

def closeEvent(self, event):
self.settings.set_in_profile("main_window_geometry", self.saveGeometry().toHex().data().decode("ascii"))
Expand Down
10 changes: 5 additions & 5 deletions package/PartSeg/_roi_analysis/partseg_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
from PartSegCore.analysis.io_utils import MaskInfo, ProjectTuple
from PartSegCore.analysis.load_functions import load_metadata
from PartSegCore.analysis.measurement_calculation import MeasurementProfile
from PartSegCore.analysis.save_hooks import PartEncoder
from PartSegCore.io_utils import PointsInfo
from PartSegCore.json_hooks import EventedDict, ProfileDict
from PartSegCore.json_hooks import PartSegEncoder
from PartSegCore.project_info import HistoryElement
from PartSegCore.roi_info import ROIInfo
from PartSegCore.utils import EventedDict, ProfileDict

from ..common_backend.base_settings import BaseSettings, SaveSettingsDescription

Expand All @@ -29,7 +29,7 @@ class PartSettings(BaseSettings):
roi_pipelines_changed = Signal()
measurement_profiles_changed = Signal()
batch_plans_changed = Signal()
json_encoder_class = PartEncoder
json_encoder_class = PartSegEncoder
load_metadata = staticmethod(load_metadata)
last_executed_algorithm: str
save_locations_keys = [
Expand Down Expand Up @@ -60,8 +60,8 @@ def fix_history(self, algorithm_name, algorithm_values):
:param str algorithm_name:
:param dict algorithm_values:
"""
self.history[self.history_index + 1] = self.history[self.history_index + 1].replace_(
roi_extraction_parameters={"algorithm_name": algorithm_name, "values": algorithm_values}
self.history[self.history_index + 1] = self.history[self.history_index + 1].copy(
update=dict(roi_extraction_parameters={"algorithm_name": algorithm_name, "values": algorithm_values})
)

@staticmethod
Expand Down
10 changes: 5 additions & 5 deletions package/PartSeg/_roi_analysis/prepare_plan_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from superqt import QEnumComboBox

from PartSegCore.algorithm_describe_base import AlgorithmProperty, ROIExtractionProfile
from PartSegCore.analysis.algorithm_description import analysis_algorithm_dict
from PartSegCore.analysis.algorithm_description import AnalysisAlgorithmSelection
from PartSegCore.analysis.calculation_plan import (
CalculationPlan,
MaskBase,
Expand Down Expand Up @@ -599,7 +599,7 @@ def create_mask(self):
return
names = dial.get_result()

mask_ob = MaskConstruct(text, *names)
mask_ob = MaskConstruct(name=text, mask1=names[0], mask2=names[1])
else:
raise ValueError("Unknowsn widget")

Expand Down Expand Up @@ -868,7 +868,7 @@ def show_segment_info(self, text=None):
else:
return
profile = self.settings.roi_pipelines[text]
self.information.setText(profile.pretty_print(analysis_algorithm_dict))
self.information.setText(profile.pretty_print(AnalysisAlgorithmSelection))

def show_segment(self):
if self.update_element_chk.isChecked() and self.segment_stack.currentIndex() == 0:
Expand Down Expand Up @@ -963,7 +963,7 @@ def explore_tree(self, up_widget, node_plan, deep=True):
desc = QTreeWidgetItem(widget)
desc.setText(0, "Description")
if isinstance(node_plan.operation, ROIExtractionProfile):
txt = node_plan.operation.pretty_print(analysis_algorithm_dict)
txt = node_plan.operation.pretty_print(AnalysisAlgorithmSelection)
else:
txt = str(node_plan.operation)
for line in txt.split("\n")[1:]:
Expand Down Expand Up @@ -1015,7 +1015,7 @@ def update_view(self, reset=False):
child = node.child(0)
child.takeChildren()
if isinstance(el.operation, ROIExtractionProfile):
txt = el.operation.pretty_print(analysis_algorithm_dict)
txt = el.operation.pretty_print(AnalysisAlgorithmSelection)
else:
txt = str(el.operation)
for line in txt.split("\n")[1:]:
Expand Down
4 changes: 2 additions & 2 deletions package/PartSeg/_roi_analysis/profile_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from PartSeg.common_gui.searchable_list_widget import SearchableListWidget
from PartSegCore.algorithm_describe_base import ROIExtractionProfile
from PartSegCore.analysis.algorithm_description import analysis_algorithm_dict
from PartSegCore.analysis.algorithm_description import AnalysisAlgorithmSelection


class ExportDialog(QDialog):
Expand Down Expand Up @@ -314,5 +314,5 @@ class ProfileDictViewer(ObjectPreview):
"""

def preview_object(self, ob: ROIExtractionProfile):
text = ob.pretty_print(analysis_algorithm_dict)
text = ob.pretty_print(AnalysisAlgorithmSelection.__register__)
self.setText(text)
6 changes: 3 additions & 3 deletions package/PartSeg/_roi_mask/batch_proceed.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from PartSeg._roi_mask.stack_settings import StackSettings, get_mask
from PartSegCore.algorithm_describe_base import ROIExtractionProfile
from PartSegCore.mask.algorithm_description import mask_algorithm_dict
from PartSegCore.mask.algorithm_description import MaskAlgorithmSelection
from PartSegCore.mask.io_functions import LoadROIImage, LoadStackImage, MaskProjectTuple, SaveROI
from PartSegCore.segmentation import StackAlgorithm
from PartSegCore.segmentation.algorithm_base import ROIExtractionAlgorithm
Expand Down Expand Up @@ -66,7 +66,7 @@ def run_calculation(self):
try:
name = path.basename(file_path)
blank = get_mask(project_tuple.roi, project_tuple.mask, project_tuple.selected_components)
algorithm: StackAlgorithm = mask_algorithm_dict[task.parameters.algorithm]()
algorithm: StackAlgorithm = MaskAlgorithmSelection[task.parameters.algorithm]()
algorithm.set_image(project_tuple.image)
algorithm.set_mask(blank)
algorithm.set_parameters(**task.parameters.values)
Expand All @@ -81,7 +81,7 @@ def run_calculation(self):
)
if isinstance(task.save_prefix, tuple):
self.progress_info(name, "saving", algorithm.get_steps_num())
name = path.splitext(path.basename(file_path))[0] + ".seg"
name = f"{path.splitext(path.basename(file_path))[0]}.seg"
re_end = re.compile(r"(.*_version)(\d+)\.seg$")
while path.exists(path.join(task.save_prefix[0], name)):
match = re_end.match(name)
Expand Down
Loading