spacr 0.2.2__py3-none-any.whl → 0.2.21__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.
- spacr/gui.py +2 -1
- spacr/gui_elements.py +1 -5
- spacr/resources/icons/abort.png +0 -0
- spacr/resources/icons/classify.png +0 -0
- spacr/resources/icons/make_masks.png +0 -0
- spacr/resources/icons/mask.png +0 -0
- spacr/resources/icons/measure.png +0 -0
- spacr/resources/icons/recruitment.png +0 -0
- spacr/resources/icons/regression.png +0 -0
- spacr/resources/icons/run.png +0 -0
- spacr/resources/icons/umap.png +0 -0
- {spacr-0.2.2.dist-info → spacr-0.2.21.dist-info}/METADATA +1 -1
- spacr-0.2.21.dist-info/RECORD +56 -0
- spacr/alpha.py +0 -807
- spacr/annotate_app.py +0 -670
- spacr/annotate_app_v2.py +0 -670
- spacr/app_make_masks_v2.py +0 -686
- spacr/classify_app.py +0 -201
- spacr/cli.py +0 -41
- spacr/foldseek.py +0 -779
- spacr/get_alfafold_structures.py +0 -72
- spacr/gui_2.py +0 -157
- spacr/gui_annotate.py +0 -145
- spacr/gui_classify_app.py +0 -201
- spacr/gui_make_masks_app.py +0 -927
- spacr/gui_make_masks_app_v2.py +0 -688
- spacr/gui_mask_app.py +0 -249
- spacr/gui_measure_app.py +0 -246
- spacr/gui_run.py +0 -58
- spacr/gui_sim_app.py +0 -0
- spacr/gui_wrappers.py +0 -149
- spacr/icons/abort.png +0 -0
- spacr/icons/abort.svg +0 -1
- spacr/icons/download.png +0 -0
- spacr/icons/download.svg +0 -1
- spacr/icons/download_for_offline_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.png +0 -0
- spacr/icons/download_for_offline_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.svg +0 -1
- spacr/icons/logo_spacr.png +0 -0
- spacr/icons/make_masks.png +0 -0
- spacr/icons/make_masks.svg +0 -1
- spacr/icons/map_barcodes.png +0 -0
- spacr/icons/map_barcodes.svg +0 -1
- spacr/icons/mask.png +0 -0
- spacr/icons/mask.svg +0 -1
- spacr/icons/measure.png +0 -0
- spacr/icons/measure.svg +0 -1
- spacr/icons/play_circle_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.png +0 -0
- spacr/icons/play_circle_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.svg +0 -1
- spacr/icons/run.png +0 -0
- spacr/icons/run.svg +0 -1
- spacr/icons/sequencing.png +0 -0
- spacr/icons/sequencing.svg +0 -1
- spacr/icons/settings.png +0 -0
- spacr/icons/settings.svg +0 -1
- spacr/icons/settings_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.png +0 -0
- spacr/icons/settings_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.svg +0 -1
- spacr/icons/stop_circle_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.png +0 -0
- spacr/icons/stop_circle_100dp_E8EAED_FILL0_wght100_GRAD-25_opsz48.svg +0 -1
- spacr/icons/theater_comedy_100dp_E8EAED_FILL0_wght100_GRAD200_opsz48.png +0 -0
- spacr/icons/theater_comedy_100dp_E8EAED_FILL0_wght100_GRAD200_opsz48.svg +0 -1
- spacr/make_masks_app.py +0 -929
- spacr/make_masks_app_v2.py +0 -688
- spacr/mask_app.py +0 -249
- spacr/measure_app.py +0 -246
- spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model +0 -0
- spacr/models/cp/toxo_plaque_cyto_e25000_X1120_Y1120.CP_model_settings.csv +0 -23
- spacr/models/cp/toxo_pv_lumen.CP_model +0 -0
- spacr/old_code.py +0 -358
- spacr/resources/icons/abort.svg +0 -1
- spacr/resources/icons/annotate.svg +0 -1
- spacr/resources/icons/classify.svg +0 -1
- spacr/resources/icons/download.svg +0 -1
- spacr/resources/icons/icon.psd +0 -0
- spacr/resources/icons/make_masks.svg +0 -1
- spacr/resources/icons/map_barcodes.svg +0 -1
- spacr/resources/icons/mask.svg +0 -1
- spacr/resources/icons/measure.svg +0 -1
- spacr/resources/icons/run.svg +0 -1
- spacr/resources/icons/run_2.png +0 -0
- spacr/resources/icons/run_2.svg +0 -1
- spacr/resources/icons/sequencing.svg +0 -1
- spacr/resources/icons/settings.svg +0 -1
- spacr/resources/icons/train_cellpose.svg +0 -1
- spacr/test_gui.py +0 -0
- spacr-0.2.2.dist-info/RECORD +0 -126
- /spacr/resources/icons/{cellpose.png → cellpose_all.png} +0 -0
- {spacr-0.2.2.dist-info → spacr-0.2.21.dist-info}/LICENSE +0 -0
- {spacr-0.2.2.dist-info → spacr-0.2.21.dist-info}/WHEEL +0 -0
- {spacr-0.2.2.dist-info → spacr-0.2.21.dist-info}/entry_points.txt +0 -0
- {spacr-0.2.2.dist-info → spacr-0.2.21.dist-info}/top_level.txt +0 -0
spacr/mask_app.py
DELETED
@@ -1,249 +0,0 @@
|
|
1
|
-
#import customtkinter as ctk
|
2
|
-
|
3
|
-
import sys, ctypes, matplotlib
|
4
|
-
import tkinter as tk
|
5
|
-
from tkinter import ttk, scrolledtext
|
6
|
-
from matplotlib.figure import Figure
|
7
|
-
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
8
|
-
matplotlib.use('Agg')
|
9
|
-
from tkinter import filedialog
|
10
|
-
from multiprocessing import Process, Queue, Value
|
11
|
-
import traceback
|
12
|
-
|
13
|
-
try:
|
14
|
-
ctypes.windll.shcore.SetProcessDpiAwareness(True)
|
15
|
-
except AttributeError:
|
16
|
-
pass
|
17
|
-
|
18
|
-
from .logger import log_function_call
|
19
|
-
from .gui_utils import ScrollableFrame, StdoutRedirector, ToggleSwitch, CustomButton, ToolTip
|
20
|
-
from .gui_utils import clear_canvas, main_thread_update_function, set_dark_style, generate_fields, process_stdout_stderr, set_default_font, style_text_boxes
|
21
|
-
from .gui_utils import mask_variables, check_mask_gui_settings, preprocess_generate_masks_wrapper, read_settings_from_csv, update_settings_from_csv, create_menu_bar
|
22
|
-
|
23
|
-
thread_control = {"run_thread": None, "stop_requested": False}
|
24
|
-
|
25
|
-
def toggle_test_mode():
|
26
|
-
global vars_dict
|
27
|
-
current_state = vars_dict['test_mode'][2].get()
|
28
|
-
new_state = not current_state
|
29
|
-
vars_dict['test_mode'][2].set(new_state)
|
30
|
-
if new_state:
|
31
|
-
test_mode_button.config(bg="blue")
|
32
|
-
else:
|
33
|
-
test_mode_button.config(bg="gray")
|
34
|
-
|
35
|
-
def toggle_advanced_settings():
|
36
|
-
global vars_dict
|
37
|
-
|
38
|
-
timelapse_settings = ['timelapse', 'timelapse_memory', 'timelapse_remove_transient', 'timelapse_mode', 'timelapse_objects', 'timelapse_displacement', 'timelapse_frame_limits', 'fps']
|
39
|
-
misc_settings = ['examples_to_plot', 'all_to_mip', 'pick_slice', 'skip_mode']
|
40
|
-
opperational_settings = ['preprocess', 'masks', 'randomize', 'batch_size', 'custom_regex', 'merge', 'normalize_plots', 'workers', 'plot', 'remove_background', 'lower_quantile']
|
41
|
-
|
42
|
-
advanced_settings = timelapse_settings+misc_settings+opperational_settings
|
43
|
-
|
44
|
-
# Toggle visibility of advanced settings
|
45
|
-
for setting in advanced_settings:
|
46
|
-
label, widget, var = vars_dict[setting]
|
47
|
-
if advanced_var.get() is False:
|
48
|
-
label.grid_remove() # Hide the label
|
49
|
-
widget.grid_remove() # Hide the widget
|
50
|
-
else:
|
51
|
-
label.grid() # Show the label
|
52
|
-
widget.grid() # Show the widget
|
53
|
-
|
54
|
-
#@log_function_call
|
55
|
-
def initiate_abort():
|
56
|
-
global thread_control
|
57
|
-
if thread_control.get("stop_requested") is not None:
|
58
|
-
thread_control["stop_requested"].value = 1
|
59
|
-
|
60
|
-
if thread_control.get("run_thread") is not None:
|
61
|
-
thread_control["run_thread"].join(timeout=5)
|
62
|
-
if thread_control["run_thread"].is_alive():
|
63
|
-
thread_control["run_thread"].terminate()
|
64
|
-
thread_control["run_thread"] = None
|
65
|
-
|
66
|
-
#@log_function_call
|
67
|
-
def run_mask_gui(q, fig_queue, stop_requested):
|
68
|
-
global vars_dict
|
69
|
-
process_stdout_stderr(q)
|
70
|
-
try:
|
71
|
-
settings = check_mask_gui_settings(vars_dict)
|
72
|
-
preprocess_generate_masks_wrapper(settings, q, fig_queue)
|
73
|
-
except Exception as e:
|
74
|
-
q.put(f"Error during processing: {e}")
|
75
|
-
traceback.print_exc()
|
76
|
-
finally:
|
77
|
-
stop_requested.value = 1
|
78
|
-
|
79
|
-
#@log_function_call
|
80
|
-
def start_process(q, fig_queue):
|
81
|
-
global thread_control
|
82
|
-
if thread_control.get("run_thread") is not None:
|
83
|
-
initiate_abort()
|
84
|
-
|
85
|
-
stop_requested = Value('i', 0) # multiprocessing shared value for inter-process communication
|
86
|
-
thread_control["stop_requested"] = stop_requested
|
87
|
-
thread_control["run_thread"] = Process(target=run_mask_gui, args=(q, fig_queue, stop_requested))
|
88
|
-
thread_control["run_thread"].start()
|
89
|
-
|
90
|
-
def import_settings(scrollable_frame):
|
91
|
-
global vars_dict
|
92
|
-
|
93
|
-
csv_file_path = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")])
|
94
|
-
csv_settings = read_settings_from_csv(csv_file_path)
|
95
|
-
variables = mask_variables()
|
96
|
-
new_settings = update_settings_from_csv(variables, csv_settings)
|
97
|
-
vars_dict = generate_fields(new_settings, scrollable_frame)
|
98
|
-
|
99
|
-
#@log_function_call
|
100
|
-
def initiate_mask_root(parent_frame):
|
101
|
-
global vars_dict, q, canvas, fig_queue, canvas_widget, thread_control, advanced_var, scrollable_frame
|
102
|
-
|
103
|
-
style = ttk.Style(parent_frame)
|
104
|
-
set_dark_style(style)
|
105
|
-
style_text_boxes(style)
|
106
|
-
set_default_font(parent_frame, font_name="Helvetica", size=8)
|
107
|
-
parent_frame.configure(bg='black')
|
108
|
-
parent_frame.grid_rowconfigure(0, weight=1)
|
109
|
-
parent_frame.grid_columnconfigure(0, weight=1)
|
110
|
-
|
111
|
-
fig_queue = Queue()
|
112
|
-
|
113
|
-
# Initialize after_tasks if not already done
|
114
|
-
if not hasattr(parent_frame, 'after_tasks'):
|
115
|
-
parent_frame.after_tasks = []
|
116
|
-
|
117
|
-
def _process_fig_queue():
|
118
|
-
global canvas
|
119
|
-
try:
|
120
|
-
while not fig_queue.empty():
|
121
|
-
clear_canvas(canvas)
|
122
|
-
fig = fig_queue.get_nowait()
|
123
|
-
for ax in fig.get_axes():
|
124
|
-
ax.set_xticks([]) # Remove x-axis ticks
|
125
|
-
ax.set_yticks([]) # Remove y-axis ticks
|
126
|
-
ax.xaxis.set_visible(False) # Hide the x-axis
|
127
|
-
ax.yaxis.set_visible(False) # Hide the y-axis
|
128
|
-
fig.tight_layout()
|
129
|
-
fig.set_facecolor('black')
|
130
|
-
canvas.figure = fig
|
131
|
-
fig_width, fig_height = canvas_widget.winfo_width(), canvas_widget.winfo_height()
|
132
|
-
fig.set_size_inches(fig_width / fig.dpi, fig_height / fig.dpi, forward=True)
|
133
|
-
canvas.draw_idle()
|
134
|
-
except Exception as e:
|
135
|
-
traceback.print_exc()
|
136
|
-
finally:
|
137
|
-
after_id = canvas_widget.after(100, _process_fig_queue)
|
138
|
-
parent_frame.after_tasks.append(after_id)
|
139
|
-
|
140
|
-
def _process_console_queue():
|
141
|
-
while not q.empty():
|
142
|
-
message = q.get_nowait()
|
143
|
-
console_output.insert(tk.END, message)
|
144
|
-
console_output.see(tk.END)
|
145
|
-
after_id = console_output.after(100, _process_console_queue)
|
146
|
-
parent_frame.after_tasks.append(after_id)
|
147
|
-
|
148
|
-
# Clear previous content if any
|
149
|
-
for widget in parent_frame.winfo_children():
|
150
|
-
widget.destroy()
|
151
|
-
|
152
|
-
vertical_container = tk.PanedWindow(parent_frame, orient=tk.HORIZONTAL)
|
153
|
-
vertical_container.grid(row=0, column=0, sticky=tk.NSEW)
|
154
|
-
parent_frame.grid_rowconfigure(0, weight=1)
|
155
|
-
parent_frame.grid_columnconfigure(0, weight=1)
|
156
|
-
|
157
|
-
# Settings Section
|
158
|
-
settings_frame = tk.Frame(vertical_container, bg='black')
|
159
|
-
vertical_container.add(settings_frame, stretch="always")
|
160
|
-
settings_label = ttk.Label(settings_frame, text="Settings", style="Custom.TLabel")
|
161
|
-
settings_label.grid(row=0, column=0, pady=10, padx=10)
|
162
|
-
scrollable_frame = ScrollableFrame(settings_frame, width=600)
|
163
|
-
scrollable_frame.grid(row=1, column=0, sticky="nsew")
|
164
|
-
settings_frame.grid_rowconfigure(1, weight=1)
|
165
|
-
settings_frame.grid_columnconfigure(0, weight=1)
|
166
|
-
|
167
|
-
# Create advanced settings checkbox
|
168
|
-
advanced_var = tk.BooleanVar(value=False)
|
169
|
-
advanced_Toggle = ToggleSwitch(scrollable_frame.scrollable_frame, text="Advanced Settings", variable=advanced_var, command=toggle_advanced_settings)
|
170
|
-
advanced_Toggle.grid(row=48, column=0, pady=10, padx=10)
|
171
|
-
variables = mask_variables()
|
172
|
-
vars_dict = generate_fields(variables, scrollable_frame)
|
173
|
-
toggle_advanced_settings()
|
174
|
-
vars_dict['Test mode'] = (None, None, tk.BooleanVar(value=False))
|
175
|
-
|
176
|
-
# Button section
|
177
|
-
test_mode_button = CustomButton(scrollable_frame.scrollable_frame, text="Test Mode", command=toggle_test_mode, font=('Helvetica', 10))
|
178
|
-
#CustomButton(buttons_frame, text=app_name, command=lambda app_name=app_name: self.load_app(app_name, app_func), font=('Helvetica', 12))
|
179
|
-
|
180
|
-
test_mode_button.grid(row=47, column=1, pady=10, padx=10)
|
181
|
-
import_btn = CustomButton(scrollable_frame.scrollable_frame, text="Import", command=lambda: import_settings(scrollable_frame), font=('Helvetica', 10))
|
182
|
-
import_btn.grid(row=47, column=0, pady=10, padx=10)
|
183
|
-
run_button = CustomButton(scrollable_frame.scrollable_frame, text="Run", command=lambda: start_process(q, fig_queue))
|
184
|
-
run_button.grid(row=45, column=0, pady=10, padx=10)
|
185
|
-
abort_button = CustomButton(scrollable_frame.scrollable_frame, text="Abort", command=initiate_abort, font=('Helvetica', 10))
|
186
|
-
abort_button.grid(row=45, column=1, pady=10, padx=10)
|
187
|
-
progress_label = ttk.Label(scrollable_frame.scrollable_frame, text="Processing: 0%", background="black", foreground="white")
|
188
|
-
progress_label.grid(row=50, column=0, columnspan=2, sticky="ew", pady=(5, 0), padx=10)
|
189
|
-
|
190
|
-
# Plot Canvas Section
|
191
|
-
plot_frame = tk.PanedWindow(vertical_container, orient=tk.VERTICAL)
|
192
|
-
vertical_container.add(plot_frame, stretch="always")
|
193
|
-
figure = Figure(figsize=(30, 4), dpi=100, facecolor='black')
|
194
|
-
plot = figure.add_subplot(111)
|
195
|
-
plot.plot([], []) # This creates an empty plot.
|
196
|
-
plot.axis('off')
|
197
|
-
canvas = FigureCanvasTkAgg(figure, master=plot_frame)
|
198
|
-
canvas.get_tk_widget().configure(cursor='arrow', background='black', highlightthickness=0)
|
199
|
-
canvas_widget = canvas.get_tk_widget()
|
200
|
-
plot_frame.add(canvas_widget, stretch="always")
|
201
|
-
canvas.draw()
|
202
|
-
canvas.figure = figure
|
203
|
-
|
204
|
-
# Console Section
|
205
|
-
console_frame = tk.Frame(vertical_container, bg='black')
|
206
|
-
vertical_container.add(console_frame, stretch="always")
|
207
|
-
console_label = ttk.Label(console_frame, text="Console", background="black", foreground="white")
|
208
|
-
console_label.grid(row=0, column=0, pady=10, padx=10)
|
209
|
-
console_output = scrolledtext.ScrolledText(console_frame, height=10, bg='black', fg='white', insertbackground='white')
|
210
|
-
console_output.grid(row=1, column=0, sticky="nsew")
|
211
|
-
console_frame.grid_rowconfigure(1, weight=1)
|
212
|
-
console_frame.grid_columnconfigure(0, weight=1)
|
213
|
-
|
214
|
-
q = Queue()
|
215
|
-
sys.stdout = StdoutRedirector(console_output)
|
216
|
-
sys.stderr = StdoutRedirector(console_output)
|
217
|
-
|
218
|
-
_process_console_queue()
|
219
|
-
_process_fig_queue()
|
220
|
-
|
221
|
-
after_id = parent_frame.after(100, lambda: main_thread_update_function(parent_frame, q, fig_queue, canvas_widget, progress_label))
|
222
|
-
parent_frame.after_tasks.append(after_id)
|
223
|
-
|
224
|
-
return parent_frame, vars_dict
|
225
|
-
|
226
|
-
def gui_mask():
|
227
|
-
root = tk.Tk()
|
228
|
-
width = root.winfo_screenwidth()
|
229
|
-
height = root.winfo_screenheight()
|
230
|
-
root.geometry(f"{width}x{height}")
|
231
|
-
root.title("SpaCr: generate masks")
|
232
|
-
|
233
|
-
# Clear previous content if any
|
234
|
-
if hasattr(root, 'content_frame'):
|
235
|
-
for widget in root.content_frame.winfo_children():
|
236
|
-
widget.destroy()
|
237
|
-
root.content_frame.grid_forget()
|
238
|
-
else:
|
239
|
-
root.content_frame = tk.Frame(root)
|
240
|
-
root.content_frame.grid(row=1, column=0, sticky="nsew")
|
241
|
-
root.grid_rowconfigure(1, weight=1)
|
242
|
-
root.grid_columnconfigure(0, weight=1)
|
243
|
-
|
244
|
-
initiate_mask_root(root.content_frame)
|
245
|
-
create_menu_bar(root)
|
246
|
-
root.mainloop()
|
247
|
-
|
248
|
-
if __name__ == "__main__":
|
249
|
-
gui_mask()
|
spacr/measure_app.py
DELETED
@@ -1,246 +0,0 @@
|
|
1
|
-
import sys, traceback, matplotlib, ctypes
|
2
|
-
import tkinter as tk
|
3
|
-
from tkinter import ttk, scrolledtext
|
4
|
-
from matplotlib.figure import Figure
|
5
|
-
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
|
6
|
-
matplotlib.use('Agg') # Use the non-GUI Agg backend
|
7
|
-
from multiprocessing import Process, Queue, Value
|
8
|
-
from tkinter import filedialog
|
9
|
-
|
10
|
-
try:
|
11
|
-
ctypes.windll.shcore.SetProcessDpiAwareness(True)
|
12
|
-
except AttributeError:
|
13
|
-
pass
|
14
|
-
|
15
|
-
from .logger import log_function_call
|
16
|
-
from .gui_utils import ScrollableFrame, StdoutRedirector, CustomButton, ToggleSwitch, ToolTip
|
17
|
-
from .gui_utils import process_stdout_stderr, set_dark_style, set_default_font, generate_fields, main_thread_update_function, create_menu_bar
|
18
|
-
from .gui_utils import measure_variables, measure_crop_wrapper, clear_canvas, check_measure_gui_settings, read_settings_from_csv, update_settings_from_csv, style_text_boxes
|
19
|
-
|
20
|
-
thread_control = {"run_thread": None, "stop_requested": False}
|
21
|
-
|
22
|
-
def import_settings(scrollable_frame):
|
23
|
-
global vars_dict
|
24
|
-
|
25
|
-
csv_file_path = filedialog.askopenfilename(filetypes=[("CSV files", "*.csv")])
|
26
|
-
csv_settings = read_settings_from_csv(csv_file_path)
|
27
|
-
variables = measure_variables()
|
28
|
-
new_settings = update_settings_from_csv(variables, csv_settings)
|
29
|
-
vars_dict = generate_fields(new_settings, scrollable_frame)
|
30
|
-
|
31
|
-
def toggle_test_mode():
|
32
|
-
global vars_dict
|
33
|
-
current_state = vars_dict['test_mode'][2].get()
|
34
|
-
new_state = not current_state
|
35
|
-
vars_dict['test_mode'][2].set(new_state)
|
36
|
-
if new_state:
|
37
|
-
test_mode_button.config(bg="blue")
|
38
|
-
else:
|
39
|
-
test_mode_button.config(bg="gray")
|
40
|
-
|
41
|
-
def toggle_advanced_settings():
|
42
|
-
global vars_dict
|
43
|
-
|
44
|
-
timelapse_settings = ['timelapse', 'timelapse_objects']
|
45
|
-
misc_settings = ['representative_images', 'plot', 'plot_filtration', 'include_uninfected', 'dialate_pngs', 'dialate_png_ratios']
|
46
|
-
opperational_settings = ['max_workers','experiment','cells','cell_loc','pathogens','pathogen_loc','treatments','treatment_loc','channel_of_interest','compartments','measurement','nr_imgs', 'um_per_pixel']
|
47
|
-
|
48
|
-
advanced_settings = timelapse_settings+misc_settings+opperational_settings
|
49
|
-
|
50
|
-
# Toggle visibility of advanced settings
|
51
|
-
for setting in advanced_settings:
|
52
|
-
label, widget, var = vars_dict[setting]
|
53
|
-
if advanced_var.get() is False:
|
54
|
-
label.grid_remove() # Hide the label
|
55
|
-
widget.grid_remove() # Hide the widget
|
56
|
-
else:
|
57
|
-
label.grid() # Show the label
|
58
|
-
widget.grid() # Show the widget
|
59
|
-
|
60
|
-
#@log_function_call
|
61
|
-
def run_measure_gui(q, fig_queue, stop_requested):
|
62
|
-
global vars_dict
|
63
|
-
process_stdout_stderr(q)
|
64
|
-
try:
|
65
|
-
print('hello')
|
66
|
-
settings = check_measure_gui_settings(vars_dict)
|
67
|
-
measure_crop_wrapper(settings=settings, q=q, fig_queue=fig_queue)
|
68
|
-
except Exception as e:
|
69
|
-
q.put(f"Error during processing: {e}")
|
70
|
-
traceback.print_exc()
|
71
|
-
finally:
|
72
|
-
stop_requested.value = 1
|
73
|
-
|
74
|
-
#@log_function_call
|
75
|
-
def start_process(q, fig_queue):
|
76
|
-
global thread_control
|
77
|
-
if thread_control.get("run_thread") is not None:
|
78
|
-
initiate_abort()
|
79
|
-
|
80
|
-
stop_requested = Value('i', 0) # multiprocessing shared value for inter-process communication
|
81
|
-
thread_control["stop_requested"] = stop_requested
|
82
|
-
thread_control["run_thread"] = Process(target=run_measure_gui, args=(q, fig_queue, stop_requested))
|
83
|
-
thread_control["run_thread"].start()
|
84
|
-
|
85
|
-
#@log_function_call
|
86
|
-
def initiate_abort():
|
87
|
-
global thread_control
|
88
|
-
if thread_control.get("stop_requested") is not None:
|
89
|
-
thread_control["stop_requested"].value = 1
|
90
|
-
|
91
|
-
if thread_control.get("run_thread") is not None:
|
92
|
-
thread_control["run_thread"].join(timeout=5)
|
93
|
-
if thread_control["run_thread"].is_alive():
|
94
|
-
thread_control["run_thread"].terminate()
|
95
|
-
thread_control["run_thread"] = None
|
96
|
-
|
97
|
-
#@log_function_call
|
98
|
-
def initiate_measure_root(parent_frame):
|
99
|
-
global vars_dict, q, canvas, fig_queue, canvas_widget, thread_control, variables, advanced_var, scrollable_frame
|
100
|
-
|
101
|
-
style = ttk.Style(parent_frame)
|
102
|
-
set_dark_style(style)
|
103
|
-
style_text_boxes(style)
|
104
|
-
set_default_font(parent_frame, font_name="Helvetica", size=8)
|
105
|
-
|
106
|
-
parent_frame.configure(bg='black')
|
107
|
-
parent_frame.grid_rowconfigure(0, weight=1)
|
108
|
-
parent_frame.grid_columnconfigure(0, weight=1)
|
109
|
-
|
110
|
-
fig_queue = Queue()
|
111
|
-
|
112
|
-
# Initialize after_tasks if not already done
|
113
|
-
if not hasattr(parent_frame, 'after_tasks'):
|
114
|
-
parent_frame.after_tasks = []
|
115
|
-
|
116
|
-
def _process_fig_queue():
|
117
|
-
global canvas
|
118
|
-
try:
|
119
|
-
while not fig_queue.empty():
|
120
|
-
clear_canvas(canvas)
|
121
|
-
fig = fig_queue.get_nowait()
|
122
|
-
for ax in fig.get_axes():
|
123
|
-
ax.set_xticks([]) # Remove x-axis ticks
|
124
|
-
ax.set_yticks([]) # Remove y-axis ticks
|
125
|
-
ax.xaxis.set_visible(False) # Hide the x-axis
|
126
|
-
ax.yaxis.set_visible(False) # Hide the y-axis
|
127
|
-
fig.tight_layout()
|
128
|
-
fig.set_facecolor('black')
|
129
|
-
canvas.figure = fig
|
130
|
-
fig_width, fig_height = canvas_widget.winfo_width(), canvas_widget.winfo_height()
|
131
|
-
fig.set_size_inches(fig_width / fig.dpi, fig_height / fig.dpi, forward=True)
|
132
|
-
canvas.draw_idle()
|
133
|
-
except Exception as e:
|
134
|
-
traceback.print_exc()
|
135
|
-
finally:
|
136
|
-
after_id = canvas_widget.after(100, _process_fig_queue)
|
137
|
-
parent_frame.after_tasks.append(after_id)
|
138
|
-
|
139
|
-
def _process_console_queue():
|
140
|
-
while not q.empty():
|
141
|
-
message = q.get_nowait()
|
142
|
-
console_output.insert(tk.END, message)
|
143
|
-
console_output.see(tk.END)
|
144
|
-
after_id = console_output.after(100, _process_console_queue)
|
145
|
-
parent_frame.after_tasks.append(after_id)
|
146
|
-
|
147
|
-
# Clear previous content if any
|
148
|
-
for widget in parent_frame.winfo_children():
|
149
|
-
widget.destroy()
|
150
|
-
|
151
|
-
vertical_container = tk.PanedWindow(parent_frame, orient=tk.HORIZONTAL)
|
152
|
-
vertical_container.grid(row=0, column=0, sticky=tk.NSEW)
|
153
|
-
parent_frame.grid_rowconfigure(0, weight=1)
|
154
|
-
parent_frame.grid_columnconfigure(0, weight=1)
|
155
|
-
|
156
|
-
# Settings Section
|
157
|
-
settings_frame = tk.Frame(vertical_container, bg='black')
|
158
|
-
vertical_container.add(settings_frame, stretch="always")
|
159
|
-
settings_label = ttk.Label(settings_frame, text="Settings", background="black", foreground="white")
|
160
|
-
settings_label.grid(row=0, column=0, pady=10, padx=10)
|
161
|
-
scrollable_frame = ScrollableFrame(settings_frame, width=500)
|
162
|
-
scrollable_frame.grid(row=1, column=0, sticky="nsew")
|
163
|
-
settings_frame.grid_rowconfigure(1, weight=1)
|
164
|
-
settings_frame.grid_columnconfigure(0, weight=1)
|
165
|
-
|
166
|
-
# Create advanced settings checkbox
|
167
|
-
advanced_var = tk.BooleanVar(value=False)
|
168
|
-
advanced_Toggle = ToggleSwitch(scrollable_frame.scrollable_frame, text="Advanced Settings", variable=advanced_var, command=toggle_advanced_settings)
|
169
|
-
advanced_Toggle.grid(row=48, column=0, pady=10, padx=10)
|
170
|
-
variables = measure_variables()
|
171
|
-
vars_dict = generate_fields(variables, scrollable_frame)
|
172
|
-
toggle_advanced_settings()
|
173
|
-
vars_dict['Test mode'] = (None, None, tk.BooleanVar(value=False))
|
174
|
-
|
175
|
-
# Button section
|
176
|
-
test_mode_button = CustomButton(scrollable_frame.scrollable_frame, text="Test Mode", command=toggle_test_mode)
|
177
|
-
test_mode_button.grid(row=47, column=1, pady=10, padx=10)
|
178
|
-
import_btn = CustomButton(scrollable_frame.scrollable_frame, text="Import", command=lambda: import_settings(scrollable_frame), font=('Helvetica', 10))
|
179
|
-
import_btn.grid(row=47, column=0, pady=20, padx=20)
|
180
|
-
run_button = CustomButton(scrollable_frame.scrollable_frame, text="Run", command=lambda: start_process(q, fig_queue), font=('Helvetica', 10))
|
181
|
-
run_button.grid(row=45, column=0, pady=20, padx=20)
|
182
|
-
abort_button = CustomButton(scrollable_frame.scrollable_frame, text="Abort", command=initiate_abort, font=('Helvetica', 10))
|
183
|
-
abort_button.grid(row=45, column=1, pady=20, padx=20)
|
184
|
-
progress_label = ttk.Label(scrollable_frame.scrollable_frame, text="Processing: 0%", background="black", foreground="white") # Create progress field
|
185
|
-
progress_label.grid(row=50, column=0, columnspan=2, sticky="ew", pady=(5, 0), padx=10)
|
186
|
-
|
187
|
-
# Plot Canvas Section
|
188
|
-
plot_frame = tk.PanedWindow(vertical_container, orient=tk.VERTICAL)
|
189
|
-
vertical_container.add(plot_frame, stretch="always")
|
190
|
-
figure = Figure(figsize=(30, 4), dpi=100, facecolor='black')
|
191
|
-
plot = figure.add_subplot(111)
|
192
|
-
plot.plot([], [])
|
193
|
-
plot.axis('off')
|
194
|
-
canvas = FigureCanvasTkAgg(figure, master=plot_frame)
|
195
|
-
canvas.get_tk_widget().configure(cursor='arrow', background='black', highlightthickness=0)
|
196
|
-
canvas_widget = canvas.get_tk_widget()
|
197
|
-
plot_frame.add(canvas_widget, stretch="always")
|
198
|
-
canvas.draw()
|
199
|
-
canvas.figure = figure
|
200
|
-
|
201
|
-
# Console Section
|
202
|
-
console_frame = tk.Frame(vertical_container, bg='black')
|
203
|
-
vertical_container.add(console_frame, stretch="always")
|
204
|
-
console_label = ttk.Label(console_frame, text="Console", background="black", foreground="white")
|
205
|
-
console_label.grid(row=0, column=0, pady=10, padx=10)
|
206
|
-
console_output = scrolledtext.ScrolledText(console_frame, height=10, bg='black', fg='white', insertbackground='white')
|
207
|
-
console_output.grid(row=1, column=0, sticky="nsew")
|
208
|
-
console_frame.grid_rowconfigure(1, weight=1)
|
209
|
-
console_frame.grid_columnconfigure(0, weight=1)
|
210
|
-
|
211
|
-
q = Queue()
|
212
|
-
sys.stdout = StdoutRedirector(console_output)
|
213
|
-
sys.stderr = StdoutRedirector(console_output)
|
214
|
-
|
215
|
-
_process_console_queue()
|
216
|
-
_process_fig_queue()
|
217
|
-
|
218
|
-
after_id = parent_frame.after(100, lambda: main_thread_update_function(parent_frame, q, fig_queue, canvas_widget, progress_label))
|
219
|
-
parent_frame.after_tasks.append(after_id)
|
220
|
-
|
221
|
-
return parent_frame, vars_dict
|
222
|
-
|
223
|
-
def gui_measure():
|
224
|
-
root = tk.Tk()
|
225
|
-
width = root.winfo_screenwidth()
|
226
|
-
height = root.winfo_screenheight()
|
227
|
-
root.geometry(f"{width}x{height}")
|
228
|
-
root.title("SpaCr: measure objects")
|
229
|
-
|
230
|
-
# Clear previous content if any
|
231
|
-
if hasattr(root, 'content_frame'):
|
232
|
-
for widget in root.content_frame.winfo_children():
|
233
|
-
widget.destroy()
|
234
|
-
root.content_frame.grid_forget()
|
235
|
-
else:
|
236
|
-
root.content_frame = tk.Frame(root)
|
237
|
-
root.content_frame.grid(row=1, column=0, sticky="nsew")
|
238
|
-
root.grid_rowconfigure(1, weight=1)
|
239
|
-
root.grid_columnconfigure(0, weight=1)
|
240
|
-
|
241
|
-
initiate_measure_root(root.content_frame)
|
242
|
-
create_menu_bar(root)
|
243
|
-
root.mainloop()
|
244
|
-
|
245
|
-
if __name__ == "__main__":
|
246
|
-
gui_measure()
|
Binary file
|
@@ -1,23 +0,0 @@
|
|
1
|
-
Key,Value
|
2
|
-
img_src,/nas_mnt/carruthers/patrick/Plaque_assay_training/train
|
3
|
-
model_name,toxo_plaque
|
4
|
-
model_type,cyto
|
5
|
-
Signal_to_noise,10
|
6
|
-
background,200
|
7
|
-
remove_background,False
|
8
|
-
learning_rate,0.2
|
9
|
-
weight_decay,1e-05
|
10
|
-
batch_size,8
|
11
|
-
n_epochs,25000
|
12
|
-
from_scratch,False
|
13
|
-
diameter,30
|
14
|
-
resize,True
|
15
|
-
width_height,"[1120, 1120]"
|
16
|
-
verbose,True
|
17
|
-
channels,"[0, 0]"
|
18
|
-
normalize,True
|
19
|
-
percentiles,
|
20
|
-
circular,False
|
21
|
-
invert,False
|
22
|
-
grayscale,True
|
23
|
-
test,False
|
Binary file
|