Skip to content

Commit

Permalink
choose folder instead of file
Browse files Browse the repository at this point in the history
  • Loading branch information
GiorgiaTortora committed Nov 6, 2023
1 parent c538f64 commit f871d81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/napari_roi_registration/_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"""

from .registration_utils import plot_data, save_in_excel, normalize_stack, select_rois_from_stack, select_rois_from_image
from .registration_utils import align_with_registration, update_position, resize_stack,rescale_position, filter_images
from .registration_utils import calculate_spectrum, correct_decay
from napari_roi_registration.registration_utils import plot_data, save_in_excel, normalize_stack, select_rois_from_stack, select_rois_from_image
from napari_roi_registration.registration_utils import align_with_registration, update_position, resize_stack,rescale_position, filter_images
from napari_roi_registration.registration_utils import calculate_spectrum, correct_decay
import numpy as np
from magicgui import magic_factory
from magicgui.widgets import FunctionGui
Expand Down Expand Up @@ -286,7 +286,6 @@ def add_rois(params):
face_color=[1,1,1,0],
name = points_layer_name
)

if show_registered_stack:
for roi_idx in range(roi_num):
pos = _centers[:,roi_idx,:]
Expand Down Expand Up @@ -325,7 +324,6 @@ def add_rois(params):

@thread_worker(connect={'returned':add_rois})
def _register_rois():

warnings.filterwarnings('ignore')
resized = resize_stack(stack, scale)
resized, _vmin, _vmax = normalize_stack(resized)
Expand All @@ -341,7 +339,7 @@ def _register_rois():
centers = np.zeros([time_frames_num,roi_num,4])
# register forwards
next_positions = initial_positions.copy()
real_next_positions = rescale_position(next_positions,1/scale)
real_next_positions = rescale_position(next_positions,1/scale)
centers[initial_time_index, :, :] = np.array(real_next_positions)
rectangles[initial_time_index, :, :, :] = create_rectangles(real_next_positions, real_roi_sy, real_roi_sx)
for t_index in range(initial_time_index+1, time_frames_num, 1):
Expand Down Expand Up @@ -446,7 +444,8 @@ def measure_displacement(image, roi_num, points, channel):

@magic_factory(call_button="Process registered ROIs",
widget_init=init_the_widget,
selected_channel={'visible':False})
selected_channel={'visible':False},
saving_folder={'mode': 'd'})
def process_rois(viewer: Viewer,
image: Image,
registered_points: Points,
Expand All @@ -455,7 +454,8 @@ def process_rois(viewer: Viewer,
correct_photobleaching: bool = False,
plot_results:bool = True,
save_results:bool = False,
path: pathlib.Path = os.getcwd()+'\\temp.xlsx'
saving_folder: pathlib.Path = os.getcwd(),
saving_filename:str = 'temp'
):

'''
Expand All @@ -477,6 +477,7 @@ def process_rois(viewer: Viewer,
path: str
Folder with filename of the excel file.
'''

if registered_points is None or labels_layer is None or image is None:
return
warnings.filterwarnings('ignore')
Expand Down Expand Up @@ -513,7 +514,8 @@ def process_rois(viewer: Viewer,
#directory, filename = os.path.split(path)
#newpath = directory +'\\'+image.name
if save_results:
save_in_excel(filename_xls = path,
filename = os.path.join(saving_folder,saving_filename +'.xlsx')
save_in_excel(filename,
sheet_name = 'Roi',
x = yx[...,1],
y = yx[...,0],
Expand All @@ -540,7 +542,7 @@ class Shared_variables:


if __name__ == '__main__':

import napari
viewer = napari.Viewer()
background_widget = subtract_background()
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion src/napari_roi_registration/registration_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def save_in_excel(filename_xls, sheet_name, **kwargs):
table.to_excel(writer, f'{sheet_name}_{sheet_idx}')
# print(table)

writer.save()
writer.close()



0 comments on commit f871d81

Please sign in to comment.