celldetective 1.4.2__py3-none-any.whl → 1.5.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- celldetective/__init__.py +25 -0
- celldetective/__main__.py +62 -43
- celldetective/_version.py +1 -1
- celldetective/extra_properties.py +477 -399
- celldetective/filters.py +192 -97
- celldetective/gui/InitWindow.py +541 -411
- celldetective/gui/__init__.py +0 -15
- celldetective/gui/about.py +44 -39
- celldetective/gui/analyze_block.py +120 -84
- celldetective/gui/base/__init__.py +0 -0
- celldetective/gui/base/channel_norm_generator.py +335 -0
- celldetective/gui/base/components.py +249 -0
- celldetective/gui/base/feature_choice.py +92 -0
- celldetective/gui/base/figure_canvas.py +52 -0
- celldetective/gui/base/list_widget.py +133 -0
- celldetective/gui/{styles.py → base/styles.py} +92 -36
- celldetective/gui/base/utils.py +33 -0
- celldetective/gui/base_annotator.py +900 -767
- celldetective/gui/classifier_widget.py +6 -22
- celldetective/gui/configure_new_exp.py +777 -671
- celldetective/gui/control_panel.py +635 -524
- celldetective/gui/dynamic_progress.py +449 -0
- celldetective/gui/event_annotator.py +2023 -1662
- celldetective/gui/generic_signal_plot.py +1292 -944
- celldetective/gui/gui_utils.py +899 -1289
- celldetective/gui/interactions_block.py +658 -0
- celldetective/gui/interactive_timeseries_viewer.py +447 -0
- celldetective/gui/json_readers.py +48 -15
- celldetective/gui/layouts/__init__.py +5 -0
- celldetective/gui/layouts/background_model_free_layout.py +537 -0
- celldetective/gui/layouts/channel_offset_layout.py +134 -0
- celldetective/gui/layouts/local_correction_layout.py +91 -0
- celldetective/gui/layouts/model_fit_layout.py +372 -0
- celldetective/gui/layouts/operation_layout.py +68 -0
- celldetective/gui/layouts/protocol_designer_layout.py +96 -0
- celldetective/gui/pair_event_annotator.py +3130 -2435
- celldetective/gui/plot_measurements.py +586 -267
- celldetective/gui/plot_signals_ui.py +724 -506
- celldetective/gui/preprocessing_block.py +395 -0
- celldetective/gui/process_block.py +1678 -1831
- celldetective/gui/seg_model_loader.py +580 -473
- celldetective/gui/settings/__init__.py +0 -7
- celldetective/gui/settings/_cellpose_model_params.py +181 -0
- celldetective/gui/settings/_event_detection_model_params.py +95 -0
- celldetective/gui/settings/_segmentation_model_params.py +159 -0
- celldetective/gui/settings/_settings_base.py +77 -65
- celldetective/gui/settings/_settings_event_model_training.py +752 -526
- celldetective/gui/settings/_settings_measurements.py +1133 -964
- celldetective/gui/settings/_settings_neighborhood.py +574 -488
- celldetective/gui/settings/_settings_segmentation_model_training.py +779 -564
- celldetective/gui/settings/_settings_signal_annotator.py +329 -305
- celldetective/gui/settings/_settings_tracking.py +1304 -1094
- celldetective/gui/settings/_stardist_model_params.py +98 -0
- celldetective/gui/survival_ui.py +422 -312
- celldetective/gui/tableUI.py +1665 -1701
- celldetective/gui/table_ops/_maths.py +295 -0
- celldetective/gui/table_ops/_merge_groups.py +140 -0
- celldetective/gui/table_ops/_merge_one_hot.py +95 -0
- celldetective/gui/table_ops/_query_table.py +43 -0
- celldetective/gui/table_ops/_rename_col.py +44 -0
- celldetective/gui/thresholds_gui.py +382 -179
- celldetective/gui/viewers/__init__.py +0 -0
- celldetective/gui/viewers/base_viewer.py +700 -0
- celldetective/gui/viewers/channel_offset_viewer.py +331 -0
- celldetective/gui/viewers/contour_viewer.py +394 -0
- celldetective/gui/viewers/size_viewer.py +153 -0
- celldetective/gui/viewers/spot_detection_viewer.py +341 -0
- celldetective/gui/viewers/threshold_viewer.py +309 -0
- celldetective/gui/workers.py +403 -126
- celldetective/log_manager.py +92 -0
- celldetective/measure.py +1895 -1478
- celldetective/napari/__init__.py +0 -0
- celldetective/napari/utils.py +1025 -0
- celldetective/neighborhood.py +1914 -1448
- celldetective/preprocessing.py +1620 -1220
- celldetective/processes/__init__.py +0 -0
- celldetective/processes/background_correction.py +271 -0
- celldetective/processes/compute_neighborhood.py +894 -0
- celldetective/processes/detect_events.py +246 -0
- celldetective/processes/downloader.py +137 -0
- celldetective/processes/measure_cells.py +565 -0
- celldetective/processes/segment_cells.py +760 -0
- celldetective/processes/track_cells.py +435 -0
- celldetective/processes/train_segmentation_model.py +694 -0
- celldetective/processes/train_signal_model.py +265 -0
- celldetective/processes/unified_process.py +292 -0
- celldetective/regionprops/_regionprops.py +358 -317
- celldetective/relative_measurements.py +987 -710
- celldetective/scripts/measure_cells.py +313 -212
- celldetective/scripts/measure_relative.py +90 -46
- celldetective/scripts/segment_cells.py +165 -104
- celldetective/scripts/segment_cells_thresholds.py +96 -68
- celldetective/scripts/track_cells.py +198 -149
- celldetective/scripts/train_segmentation_model.py +324 -201
- celldetective/scripts/train_signal_model.py +87 -45
- celldetective/segmentation.py +844 -749
- celldetective/signals.py +3514 -2861
- celldetective/tracking.py +30 -15
- celldetective/utils/__init__.py +0 -0
- celldetective/utils/cellpose_utils/__init__.py +133 -0
- celldetective/utils/color_mappings.py +42 -0
- celldetective/utils/data_cleaning.py +630 -0
- celldetective/utils/data_loaders.py +450 -0
- celldetective/utils/dataset_helpers.py +207 -0
- celldetective/utils/downloaders.py +235 -0
- celldetective/utils/event_detection/__init__.py +8 -0
- celldetective/utils/experiment.py +1782 -0
- celldetective/utils/image_augmenters.py +308 -0
- celldetective/utils/image_cleaning.py +74 -0
- celldetective/utils/image_loaders.py +926 -0
- celldetective/utils/image_transforms.py +335 -0
- celldetective/utils/io.py +62 -0
- celldetective/utils/mask_cleaning.py +348 -0
- celldetective/utils/mask_transforms.py +5 -0
- celldetective/utils/masks.py +184 -0
- celldetective/utils/maths.py +351 -0
- celldetective/utils/model_getters.py +325 -0
- celldetective/utils/model_loaders.py +296 -0
- celldetective/utils/normalization.py +380 -0
- celldetective/utils/parsing.py +465 -0
- celldetective/utils/plots/__init__.py +0 -0
- celldetective/utils/plots/regression.py +53 -0
- celldetective/utils/resources.py +34 -0
- celldetective/utils/stardist_utils/__init__.py +104 -0
- celldetective/utils/stats.py +90 -0
- celldetective/utils/types.py +21 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/METADATA +1 -1
- celldetective-1.5.0b1.dist-info/RECORD +187 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/WHEEL +1 -1
- tests/gui/test_new_project.py +129 -117
- tests/gui/test_project.py +127 -79
- tests/test_filters.py +39 -15
- tests/test_notebooks.py +8 -0
- tests/test_tracking.py +232 -13
- tests/test_utils.py +123 -77
- celldetective/gui/base_components.py +0 -23
- celldetective/gui/layouts.py +0 -1602
- celldetective/gui/processes/compute_neighborhood.py +0 -594
- celldetective/gui/processes/downloader.py +0 -111
- celldetective/gui/processes/measure_cells.py +0 -360
- celldetective/gui/processes/segment_cells.py +0 -499
- celldetective/gui/processes/track_cells.py +0 -303
- celldetective/gui/processes/train_segmentation_model.py +0 -270
- celldetective/gui/processes/train_signal_model.py +0 -108
- celldetective/gui/table_ops/merge_groups.py +0 -118
- celldetective/gui/viewers.py +0 -1354
- celldetective/io.py +0 -3663
- celldetective/utils.py +0 -3108
- celldetective-1.4.2.dist-info/RECORD +0 -123
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/entry_points.txt +0 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/licenses/LICENSE +0 -0
- {celldetective-1.4.2.dist-info → celldetective-1.5.0b1.dist-info}/top_level.txt +0 -0
|
@@ -9,71 +9,113 @@ from glob import glob
|
|
|
9
9
|
import numpy as np
|
|
10
10
|
from art import tprint
|
|
11
11
|
from celldetective.signals import SignalDetectionModel
|
|
12
|
-
from celldetective.
|
|
12
|
+
from celldetective.utils.model_loaders import locate_signal_model
|
|
13
13
|
|
|
14
14
|
tprint("Train")
|
|
15
15
|
|
|
16
|
-
parser = argparse.ArgumentParser(
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
parser = argparse.ArgumentParser(
|
|
17
|
+
description="Train a signal model from instructions.",
|
|
18
|
+
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
19
|
+
)
|
|
20
|
+
parser.add_argument("-c", "--config", required=True, help="Training instructions")
|
|
19
21
|
|
|
20
22
|
args = parser.parse_args()
|
|
21
23
|
process_arguments = vars(args)
|
|
22
|
-
instructions = str(process_arguments[
|
|
24
|
+
instructions = str(process_arguments["config"])
|
|
23
25
|
|
|
24
26
|
if os.path.exists(instructions):
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
with open(instructions, "r") as f:
|
|
28
|
+
threshold_instructions = json.load(f)
|
|
29
|
+
threshold_instructions.update(
|
|
30
|
+
{"n_channels": len(threshold_instructions["channel_option"])}
|
|
31
|
+
)
|
|
32
|
+
if threshold_instructions["augmentation_factor"] > 1.0:
|
|
33
|
+
threshold_instructions.update({"augment": True})
|
|
34
|
+
else:
|
|
35
|
+
threshold_instructions.update({"augment": False})
|
|
36
|
+
threshold_instructions.update({"test_split": 0.0})
|
|
33
37
|
else:
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
print("The configuration path is not valid. Abort.")
|
|
39
|
+
os.abort()
|
|
36
40
|
|
|
37
41
|
all_classes = []
|
|
38
42
|
for d in threshold_instructions["ds"]:
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
datasets = glob(d + os.sep + "*.npy")
|
|
44
|
+
for dd in datasets:
|
|
45
|
+
data = np.load(dd, allow_pickle=True)
|
|
46
|
+
classes = np.unique([ddd["class"] for ddd in data])
|
|
47
|
+
all_classes.extend(classes)
|
|
44
48
|
all_classes = np.unique(all_classes)
|
|
45
|
-
print(all_classes,len(all_classes))
|
|
49
|
+
print(all_classes, len(all_classes))
|
|
46
50
|
|
|
47
51
|
n_classes = len(all_classes)
|
|
48
52
|
|
|
49
|
-
model_params = {
|
|
50
|
-
|
|
53
|
+
model_params = {
|
|
54
|
+
k: threshold_instructions[k]
|
|
55
|
+
for k in (
|
|
56
|
+
"pretrained",
|
|
57
|
+
"model_signal_length",
|
|
58
|
+
"channel_option",
|
|
59
|
+
"n_channels",
|
|
60
|
+
"label",
|
|
61
|
+
)
|
|
62
|
+
if k in threshold_instructions
|
|
63
|
+
}
|
|
64
|
+
model_params.update({"n_classes": n_classes})
|
|
51
65
|
|
|
52
|
-
train_params = {
|
|
66
|
+
train_params = {
|
|
67
|
+
k: threshold_instructions[k]
|
|
68
|
+
for k in (
|
|
69
|
+
"model_name",
|
|
70
|
+
"target_directory",
|
|
71
|
+
"channel_option",
|
|
72
|
+
"recompile_pretrained",
|
|
73
|
+
"test_split",
|
|
74
|
+
"augment",
|
|
75
|
+
"epochs",
|
|
76
|
+
"learning_rate",
|
|
77
|
+
"batch_size",
|
|
78
|
+
"validation_split",
|
|
79
|
+
"normalization_percentile",
|
|
80
|
+
"normalization_values",
|
|
81
|
+
"normalization_clip",
|
|
82
|
+
)
|
|
83
|
+
if k in threshold_instructions
|
|
84
|
+
}
|
|
53
85
|
|
|
54
|
-
print(f
|
|
55
|
-
print(f
|
|
86
|
+
print(f"model params {model_params}")
|
|
87
|
+
print(f"train params {train_params}")
|
|
56
88
|
|
|
57
89
|
model = SignalDetectionModel(**model_params)
|
|
58
|
-
print(threshold_instructions[
|
|
59
|
-
model.fit_from_directory(threshold_instructions[
|
|
90
|
+
print(threshold_instructions["ds"])
|
|
91
|
+
model.fit_from_directory(threshold_instructions["ds"], **train_params)
|
|
60
92
|
|
|
61
93
|
|
|
62
94
|
# if neighborhood of interest in training instructions, write it in config!
|
|
63
|
-
if
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
95
|
+
if "neighborhood_of_interest" in threshold_instructions:
|
|
96
|
+
if threshold_instructions["neighborhood_of_interest"] is not None:
|
|
97
|
+
|
|
98
|
+
model_path = locate_signal_model(
|
|
99
|
+
threshold_instructions["model_name"], path=None, pairs=True
|
|
100
|
+
)
|
|
101
|
+
complete_path = model_path # +model
|
|
102
|
+
complete_path = rf"{complete_path}"
|
|
103
|
+
model_config_path = os.sep.join([complete_path, "config_input.json"])
|
|
104
|
+
model_config_path = rf"{model_config_path}"
|
|
105
|
+
|
|
106
|
+
f = open(model_config_path)
|
|
107
|
+
config = json.load(f)
|
|
108
|
+
config.update(
|
|
109
|
+
{
|
|
110
|
+
"neighborhood_of_interest": threshold_instructions[
|
|
111
|
+
"neighborhood_of_interest"
|
|
112
|
+
],
|
|
113
|
+
"reference_population": threshold_instructions["reference_population"],
|
|
114
|
+
"neighbor_population": threshold_instructions["neighbor_population"],
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
json_string = json.dumps(config)
|
|
118
|
+
with open(model_config_path, "w") as outfile:
|
|
119
|
+
outfile.write(json_string)
|
|
120
|
+
|
|
121
|
+
print("Done.")
|