Skip to content

Commit af0b133

Browse files
committed
fixed errors in review + improved layout
1 parent dc778ee commit af0b133

File tree

6 files changed

+66
-53
lines changed

6 files changed

+66
-53
lines changed

src/napari_cellseg3d/launch_review.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ def launch_review(
149149

150150
layer = view1.layers[0]
151151
layer1 = view1.layers[1]
152-
if not as_folder:
153-
r_path = os.path.dirname(r_path)
152+
# if not as_folder:
153+
# r_path = os.path.dirname(r_path)
154154

155155
@magicgui(
156156
dirname={"mode": "d", "label": "Save labels in... "},
157157
call_button="Save",
158+
# call_button_2="Save & quit",
158159
)
159160
def file_widget(
160161
dirname=Path(r_path),
@@ -182,7 +183,11 @@ def quicksave():
182183
dat = viewer.layers["labels"].data
183184
utils.save_stack(dat, dir_name, filetype=filetype)
184185

185-
return dirname, quicksave()
186+
# def quicksave_quit():
187+
# quicksave()
188+
# viewer.window.close()
189+
190+
return dirname, quicksave() #, quicksave_quit()
186191

187192
# gui = file_widget.show(run=True) # dirpicker.show(run=True)
188193

src/napari_cellseg3d/plugin_dock.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def __init__(self, parent: "napari.viewer.Viewer"):
6565
self.csv_path = ""
6666
self.slice_num = 0
6767
self.filetype = ""
68+
self.filename = None
6869
self.image_dims = self.viewer.layers[0].data.shape
6970
self.as_folder = False
7071
"""Whether to load as folder or single file"""
@@ -86,6 +87,14 @@ def prepare(self, label_dir, filetype, model_type, checkbox, as_folder):
8687
print(label_dir)
8788
self.filetype = filetype
8889
self.as_folder = as_folder
90+
91+
if not self.as_folder:
92+
self.filename = os.path.split(label_dir)[1]
93+
label_dir = os.path.split(label_dir)[0]
94+
print("Loading single image")
95+
print(self.filename)
96+
print(label_dir)
97+
8998
self.df, self.csv_path = self.load_csv(label_dir, model_type, checkbox)
9099

91100
print(self.csv_path, checkbox)
@@ -98,7 +107,7 @@ def load_csv(self, label_dir, model_type, checkbox):
98107
99108
Args:
100109
label_dir (str): label path
101-
model_type (str):model type
110+
model_type (str): model type
102111
checkbox ( bool ): create new dataset or not
103112
104113
Returns:
@@ -131,7 +140,7 @@ def load_csv(self, label_dir, model_type, checkbox):
131140
pass
132141
return df, csv_path
133142

134-
def create(self, label_dir, model_type):
143+
def create(self, label_dir, model_type, filename=None):
135144
"""
136145
Create a new dataframe and save the csv
137146
Args:
@@ -148,20 +157,16 @@ def create(self, label_dir, model_type):
148157
for path in Path(label_dir).glob("./*" + self.filetype)
149158
)
150159
)
151-
elif not self.as_folder:
152-
path = list(Path(label_dir).glob("./*" + self.filetype))
160+
else:
153161
# print(self.image_dims[0])
154-
print(path)
155-
filename = path
162+
if self.filename is not None:
163+
filename = self.filename
164+
else:
165+
filename="image"
156166
labels = [str(filename) for i in range(self.image_dims[0])]
157167

158-
else:
159-
raise ValueError(
160-
"Error: Loading behaviour should be determined on launch"
161-
)
162-
163168
df = pd.DataFrame(
164-
{"filename": labels, "train": ["Not Checked"] * len(labels)}
169+
{"filename": labels, "train": ["Not checked"] * len(labels)}
165170
)
166171
csv_path = os.path.join(label_dir, f"{model_type}_train0.csv")
167172
print("csv path for create")
@@ -188,13 +193,14 @@ def button_func(self): # updates csv every time you press button...
188193
if self.viewer.dims.ndisplay != 2:
189194
# TODO test if undefined behaviour or if okay
190195
warnings.warn("Please switch back to 2D mode !")
191-
if self.button.text() == "Not Checked":
196+
return
197+
if self.button.text() == "Not checked":
192198
self.button.setText("Checked")
193199
self.df.at[self.df.index[self.slice_num], "train"] = "Checked"
194200
self.df.to_csv(self.csv_path)
195201
else:
196-
self.button.setText("Not Checked")
197-
self.df.at[self.df.index[self.slice_num], "train"] = "Not Checked"
202+
self.button.setText("Not checked")
203+
self.df.at[self.df.index[self.slice_num], "train"] = "Not checked"
198204
self.df.to_csv(self.csv_path)
199205

200206
# def move_data(self):

src/napari_cellseg3d/plugin_model_inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ def build(self):
374374
self.show_original_checkbox.setVisible(False)
375375
self.lbl_display_number.setVisible(False)
376376

377-
# TODO : add custom model handling ? using exec() to read user provided model class
377+
# TODO : add custom model handling ?
378378
# self.lbl_label.setText("model.pth directory :")
379379

380380
display_opt_group.setLayout(display_opt_layout)
@@ -392,7 +392,7 @@ def build(self):
392392
ui.make_scrollable(
393393
containing_widget=tab,
394394
contained_layout=tab_layout,
395-
min_wh=[200, 100],
395+
min_wh=[200, 300],
396396
)
397397
self.addTab(tab, "Inference")
398398

src/napari_cellseg3d/plugin_model_training.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,6 @@ def start(self):
750750
"seed": self.box_seed.value(),
751751
}
752752

753-
754753
self.patch_size = []
755754
[
756755
self.patch_size.append(w.value())
@@ -762,8 +761,8 @@ def start(self):
762761
"name": self.model_choice.currentText(),
763762
}
764763
self.results_path = (
765-
self.results_path
766-
+ f"/{model_dict['name']}_results_{utils.get_date_time()}"
764+
self.results_path
765+
+ f"/{model_dict['name']}_results_{utils.get_date_time()}"
767766
)
768767
os.makedirs(
769768
self.results_path, exist_ok=False

src/napari_cellseg3d/plugin_review.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
5555
"Start reviewing", self.run_review, self
5656
)
5757

58-
self.lbl_mod = QLabel("Model name", self)
58+
self.lbl_mod = QLabel("Name", self)
5959

6060
self.warn_label = QLabel(
6161
"WARNING : You already have a review session running.\n"
@@ -71,23 +71,27 @@ def __init__(self, viewer: "napari.viewer.Viewer"):
7171
def build(self):
7272
"""Build buttons in a layout and add them to the napari Viewer"""
7373

74-
w, vbox = ui.make_container_widget(0, 0, 1, 11)
74+
self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.MinimumExpanding)
75+
76+
tab, layout = ui.make_container_widget(0, 0, 1, 1)
7577

7678
global global_launched_before
7779
if global_launched_before:
78-
vbox.addWidget(self.warn_label)
80+
layout.addWidget(self.warn_label)
7981
warnings.warn(
8082
"You already have a review session running.\n"
8183
"Launching another will close the current one,\n"
8284
" make sure to save your work beforehand"
8385
)
8486

85-
ui.add_blank(self, vbox)
87+
# ui.add_blank(self, layout)
8688
###########################
8789
data_group_w, data_group_l = ui.make_group("Data")
8890

8991
data_group_l.addWidget(
90-
ui.combine_blocks(self.filetype_choice, self.file_handling_box),
92+
ui.combine_blocks(
93+
self.filetype_choice, self.file_handling_box, horizontal=False
94+
),
9195
alignment=ui.LEFT_AL,
9296
)
9397
self.filetype_choice.setVisible(False)
@@ -101,11 +105,10 @@ def build(self):
101105
)
102106

103107
data_group_w.setLayout(data_group_l)
104-
vbox.addWidget(data_group_w)
108+
layout.addWidget(data_group_w)
105109
###########################
106-
ui.add_blank(self, vbox)
110+
ui.add_blank(self, layout)
107111
###########################
108-
# vbox.addWidget(self.lblft2)
109112
csv_param_w, csv_param_l = ui.make_group("CSV parameters")
110113

111114
csv_param_l.addWidget(
@@ -114,28 +117,29 @@ def build(self):
114117
self.lbl_mod,
115118
horizontal=False,
116119
l=5,
117-
t=5,
120+
t=0,
118121
r=5,
119122
b=5,
120123
)
121124
)
122125
csv_param_l.addWidget(self.checkBox)
123126

124127
csv_param_w.setLayout(csv_param_l)
125-
vbox.addWidget(csv_param_w)
128+
layout.addWidget(csv_param_w)
126129
###########################
127-
ui.add_blank(self, vbox)
130+
ui.add_blank(self, layout)
128131
###########################
129132

130-
vbox.addWidget(self.btn_start)
131-
vbox.addWidget(self.btn_close)
133+
layout.addWidget(self.btn_start)
134+
layout.addWidget(self.btn_close)
132135

133136
ui.make_scrollable(
134-
contained_layout=vbox,
135-
containing_widget=self,
136-
min_wh=[185, 200],
137-
base_wh=[190, 600],
137+
contained_layout=layout,
138+
containing_widget=tab,
139+
min_wh=[190,300]
138140
)
141+
142+
self.addTab(tab, "Review")
139143
# self.show()
140144
# self._viewer.window.add_dock_widget(self, name="Reviewer", area="right")
141145

@@ -178,7 +182,7 @@ def run_review(self):
178182
self.image_path, self.filetype, self.as_folder
179183
)
180184
if (
181-
self.label_path == ""
185+
self.label_path == "" # TODO check if it works
182186
): # saves empty images of the same size as original images
183187
if self.as_folder:
184188
labels = np.zeros_like(images.compute()) # dask to numpy

src/napari_cellseg3d/utils.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,9 @@ def anisotropy_zoom_factor(resolutions):
170170
Args:
171171
resolutions: array for resolution (float) in microns for each axis
172172
173-
Returns: an array with the corresponding zoom factors for each axis
173+
ith Returns: an array with the corresponding zoom factors for each axis (all values divided by min)
174174
175175
"""
176-
# TODO docs
177176

178177
base = min(resolutions)
179178
zoom_factors = [base / res for res in resolutions]
@@ -376,16 +375,16 @@ def load_images(dir_or_path, filetype="", as_folder: bool = False):
376375
return images_original
377376

378377

379-
def load_predicted_masks(mito_mask_dir, er_mask_dir, filetype):
380-
381-
images_mito_label = load_images(mito_mask_dir, filetype)
382-
# TODO : check that there is no problem with compute when loading as single file
383-
images_mito_label = images_mito_label.compute()
384-
images_er_label = load_images(er_mask_dir, filetype)
385-
# TODO : check that there is no problem with compute when loading as single file
386-
images_er_label = images_er_label.compute()
387-
base_label = (images_mito_label > 127) * 1 + (images_er_label > 127) * 2
388-
return base_label
378+
# def load_predicted_masks(mito_mask_dir, er_mask_dir, filetype):
379+
#
380+
# images_mito_label = load_images(mito_mask_dir, filetype)
381+
# # TODO : check that there is no problem with compute when loading as single file
382+
# images_mito_label = images_mito_label.compute()
383+
# images_er_label = load_images(er_mask_dir, filetype)
384+
# # TODO : check that there is no problem with compute when loading as single file
385+
# images_er_label = images_er_label.compute()
386+
# base_label = (images_mito_label > 127) * 1 + (images_er_label > 127) * 2
387+
# return base_label
389388

390389

391390
def load_saved_masks(mod_mask_dir, filetype, as_folder: bool):

0 commit comments

Comments
 (0)