def fit_component_ipy(obj, **kwargs): wdict = {} only_current = Checkbox() iterpath = enum2dropdown(obj.traits()["iterpath"]) def disable_iterpath(change): iterpath.disabled = change.new only_current.observe(disable_iterpath, "value") wdict["only_current"] = only_current wdict["iterpath"] = iterpath help_text = HTML( "Click on the signal figure and drag to the right to select a" "range. Press `Fit` to fit the component in that range. If only " "current is unchecked the fit is performed in the whole dataset.", layout=ipywidgets.Layout(width="auto")) wdict["help_text"] = help_text help = Accordion(children=[help_text], selected_index=None) set_title_container(help, ["Help"]) link((obj, "only_current"), (only_current, "value")) link((obj, "iterpath"), (iterpath, "value")) fit = Button(description="Fit", tooltip="Fit in the selected signal range") close = Button( description="Close", tooltip="Close widget and remove span selector from the signal figure." ) wdict["close_button"] = close wdict["fit_button"] = fit def on_fit_clicked(b): obj._fit_fired() fit.on_click(on_fit_clicked) box = VBox([ labelme("Only current", only_current), labelme("Iterpath", wdict["iterpath"]), help, HBox((fit, close)) ]) def on_close_clicked(b): obj.span_selector_switch(False) box.close() close.on_click(on_close_clicked) return { "widget": box, "wdict": wdict, }
def spikes_removal_ipy(obj, **kwargs): wdict = {} threshold = ipywidgets.FloatText() add_noise = ipywidgets.Checkbox() default_spike_width = ipywidgets.IntText() interpolator_kind = enum2dropdown(obj.traits()["interpolator_kind"]) spline_order = ipywidgets.IntSlider(min=1, max=10) progress_bar = ipywidgets.IntProgress(max=len(obj.coordinates) - 1) help = ipywidgets.HTML( value=SPIKES_REMOVAL_INSTRUCTIONS.replace('\n', '<br/>')) help = ipywidgets.Accordion(children=[help]) help.set_title(0, "Help") show_diff = ipywidgets.Button( description="Show derivative histogram", tooltip="This figure is useful to estimate the threshold.", layout=ipywidgets.Layout(width="auto")) close = ipywidgets.Button( description="Close", tooltip="Close widget and remove span selector from the signal figure.") next = ipywidgets.Button( description="Find next", tooltip="Find next spike") previous = ipywidgets.Button( description="Find previous", tooltip="Find previous spike") remove = ipywidgets.Button( description="Remove spike", tooltip="Remove spike and find next one.") wdict["threshold"] = threshold wdict["add_noise"] = add_noise wdict["default_spike_width"] = default_spike_width wdict["interpolator_kind"] = interpolator_kind wdict["spline_order"] = spline_order wdict["progress_bar"] = progress_bar wdict["show_diff_button"] = show_diff wdict["close_button"] = close wdict["next_button"] = next wdict["previous_button"] = previous wdict["remove_button"] = remove def on_show_diff_clicked(b): obj._show_derivative_histogram_fired() show_diff.on_click(on_show_diff_clicked) def on_next_clicked(b): obj.find() next.on_click(on_next_clicked) def on_previous_clicked(b): obj.find(back=True) previous.on_click(on_previous_clicked) def on_remove_clicked(b): obj.apply() remove.on_click(on_remove_clicked) labeled_spline_order = labelme("Spline order", spline_order) def enable_interpolator_kind(change): if change.new == "Spline": for child in labeled_spline_order.children: child.layout.display = "" else: for child in labeled_spline_order.children: child.layout.display = "none" interpolator_kind.observe(enable_interpolator_kind, "value") link((obj, "interpolator_kind"), (interpolator_kind, "value")) link((obj, "threshold"), (threshold, "value")) link((obj, "add_noise"), (add_noise, "value")) link((obj, "default_spike_width"), (default_spike_width, "value")) link((obj, "spline_order"), (spline_order, "value")) link((obj, "index"), (progress_bar, "value")) # Trigger the function that controls the visibility as # setting the default value doesn't trigger it. class Dummy: new = interpolator_kind.value enable_interpolator_kind(change=Dummy()) advanced = ipywidgets.Accordion(( ipywidgets.VBox([ labelme("Add noise", add_noise), labelme("Interpolator kind", interpolator_kind), labelme("Default spike width", default_spike_width), labelme("Spline order", spline_order), ]),)) advanced.set_title(0, "Advanced settings") box = ipywidgets.VBox([ ipywidgets.VBox([ show_diff, labelme("Threshold", threshold), labelme("Progress", progress_bar), ]), advanced, help, ipywidgets.HBox([previous, next, remove, close]) ]) def on_close_clicked(b): obj.span_selector_switch(False) box.close() close.on_click(on_close_clicked) return { "widget": box, "wdict": wdict, }
def remove_background_ipy(obj, **kwargs): wdict = {} left = ipywidgets.FloatText(disabled=True, description="Left") right = ipywidgets.FloatText(disabled=True, description="Right") link((obj, "ss_left_value"), (left, "value")) link((obj, "ss_right_value"), (right, "value")) fast = ipywidgets.Checkbox(description="Fast") zero_fill = ipywidgets.Checkbox(description="Zero Fill") help = ipywidgets.HTML( "Click on the signal figure and drag to the right to select a " "range. Press `Apply` to remove the background in the whole dataset. " "If \"Fast\" is checked, the background parameters are estimated " "using a fast (analytical) method that can compromise accuracy. " "When unchecked, non-linear least squares is employed instead. " "If \"Zero Fill\" is checked, all the channels prior to the fitting " "region will be set to zero. " "Otherwise the background subtraction will be performed in the " "pre-fitting region as well.",) wdict["help"] = help help = ipywidgets.Accordion(children=[help]) help.set_title(0, "Help") close = ipywidgets.Button( description="Close", tooltip="Close widget and remove span selector from the signal figure.") apply = ipywidgets.Button( description="Apply", tooltip="Remove the background in the whole dataset.") polynomial_order = ipywidgets.IntText(description="Polynomial order") background_type = enum2dropdown(obj.traits()["background_type"]) background_type.description = "Background type" def enable_poly_order(change): if change.new == "Polynomial": polynomial_order.layout.display = "" else: polynomial_order.layout.display = "none" background_type.observe(enable_poly_order, "value") link((obj, "background_type"), (background_type, "value")) # Trigger the function that controls the visibility of poly order as # setting the default value doesn't trigger it. class Dummy: new = background_type.value enable_poly_order(change=Dummy()) link((obj, "polynomial_order"), (polynomial_order, "value")) link((obj, "fast"), (fast, "value")) link((obj, "zero_fill"), (zero_fill, "value")) wdict["left"] = left wdict["right"] = right wdict["fast"] = fast wdict["zero_fill"] = zero_fill wdict["polynomial_order"] = polynomial_order wdict["background_type"] = background_type wdict["apply_button"] = apply box = ipywidgets.VBox([ left, right, background_type, polynomial_order, fast, zero_fill, help, ipywidgets.HBox((apply, close)), ]) def on_apply_clicked(b): obj.apply() box.close() apply.on_click(on_apply_clicked) def on_close_clicked(b): obj.span_selector_switch(False) box.close() close.on_click(on_close_clicked) return { "widget": box, "wdict": wdict, }
def find_peaks2D_ipy(obj, **kwargs): wdict = {} # Define widgets # For "local max" method local_max_distance = ipywidgets.IntSlider(min=1, max=20, value=3) local_max_threshold = ipywidgets.FloatSlider(min=0, max=20, value=10) # For "max" method max_alpha = ipywidgets.FloatSlider(min=0, max=6, value=3) max_distance = ipywidgets.IntSlider(min=1, max=20, value=10) # For "minmax" method minmax_distance = ipywidgets.FloatSlider(min=0, max=6, value=3) minmax_threshold = ipywidgets.FloatSlider(min=0, max=20, value=10) # For "Zaefferer" method zaefferer_grad_threshold = ipywidgets.FloatSlider(min=0, max=0.2, value=0.1, step=0.2 * 1E-1) zaefferer_window_size = ipywidgets.IntSlider(min=2, max=80, value=40) zaefferer_distance_cutoff = ipywidgets.FloatSlider(min=0, max=100, value=50) # For "stat" method stat_alpha = ipywidgets.FloatSlider(min=0, max=2, value=1) stat_window_radius = ipywidgets.IntSlider(min=5, max=20, value=10) stat_convergence_ratio = ipywidgets.FloatSlider(min=0, max=0.1, value=0.05) # For "Laplacian of Gaussians" method log_min_sigma = ipywidgets.FloatSlider(min=0, max=2, value=1) log_max_sigma = ipywidgets.FloatSlider(min=0, max=100, value=50) log_num_sigma = ipywidgets.FloatSlider(min=0, max=20, value=10) log_threshold = ipywidgets.FloatSlider(min=0, max=0.4, value=0.2) log_overlap = ipywidgets.FloatSlider(min=0, max=1, value=0.5) log_log_scale = ipywidgets.Checkbox() # For "Difference of Gaussians" method dog_min_sigma = ipywidgets.FloatSlider(min=0, max=2, value=1) dog_max_sigma = ipywidgets.FloatSlider(min=0, max=100, value=50) dog_sigma_ratio = ipywidgets.FloatSlider(min=0, max=3.2, value=1.6) dog_threshold = ipywidgets.FloatSlider(min=0, max=0.4, value=0.2) dog_overlap = ipywidgets.FloatSlider(min=0, max=1, value=0.5) # For "Cross correlation" method xc_distance = ipywidgets.FloatSlider(min=0, max=10., value=5.) xc_threshold = ipywidgets.FloatSlider(min=0, max=2., value=0.5) wdict["local_max_distance"] = local_max_distance wdict["local_max_threshold"] = local_max_threshold wdict["max_alpha"] = max_alpha wdict["max_distance"] = max_distance wdict["minmax_distance"] = minmax_distance wdict["minmax_threshold"] = minmax_threshold wdict["zaefferer_grad_threshold"] = zaefferer_grad_threshold wdict["zaefferer_window_size"] = zaefferer_window_size wdict["zaefferer_distance_cutoff"] = zaefferer_distance_cutoff wdict["stat_alpha"] = stat_alpha wdict["stat_window_radius"] = stat_window_radius wdict["stat_convergence_ratio"] = stat_convergence_ratio wdict["log_min_sigma"] = log_min_sigma wdict["log_max_sigma"] = log_max_sigma wdict["log_num_sigma"] = log_num_sigma wdict["log_threshold"] = log_threshold wdict["log_overlap"] = log_overlap wdict["log_log_scale"] = log_log_scale wdict["dog_min_sigma"] = dog_min_sigma wdict["dog_max_sigma"] = dog_max_sigma wdict["dog_sigma_ratio"] = dog_sigma_ratio wdict["dog_threshold"] = dog_threshold wdict["dog_overlap"] = dog_overlap wdict["xc_distance"] = xc_distance wdict["xc_threshold"] = xc_threshold # Connect link((obj, "local_max_distance"), (local_max_distance, "value")) link((obj, "local_max_threshold"), (local_max_threshold, "value")) link((obj, "max_alpha"), (max_alpha, "value")) link((obj, "max_distance"), (max_distance, "value")) link((obj, "minmax_distance"), (minmax_distance, "value")) link((obj, "minmax_threshold"), (minmax_threshold, "value")) link((obj, "zaefferer_grad_threshold"), (zaefferer_grad_threshold, "value")) link((obj, "zaefferer_window_size"), (zaefferer_window_size, "value")) link((obj, "zaefferer_distance_cutoff"), (zaefferer_distance_cutoff, "value")) link((obj, "stat_alpha"), (stat_alpha, "value")) link((obj, "stat_window_radius"), (stat_window_radius, "value")) link((obj, "stat_convergence_ratio"), (stat_convergence_ratio, "value")) link((obj, "log_min_sigma"), (log_min_sigma, "value")) link((obj, "log_max_sigma"), (log_max_sigma, "value")) link((obj, "log_num_sigma"), (log_num_sigma, "value")) link((obj, "log_threshold"), (log_threshold, "value")) link((obj, "log_overlap"), (log_overlap, "value")) link((obj, "log_log_scale"), (log_log_scale, "value")) link((obj, "dog_min_sigma"), (dog_min_sigma, "value")) link((obj, "dog_max_sigma"), (dog_max_sigma, "value")) link((obj, "dog_sigma_ratio"), (dog_sigma_ratio, "value")) link((obj, "dog_threshold"), (dog_threshold, "value")) link((obj, "dog_overlap"), (dog_overlap, "value")) link((obj, "xc_distance"), (xc_distance, "value")) link((obj, "xc_threshold"), (xc_threshold, "value")) close = ipywidgets.Button(description="Close", tooltip="Close widget and close figure.") compute = ipywidgets.Button( description="Compute over navigation axes.", tooltip="Find the peaks by iterating over the navigation axes.") box_local_max = ipywidgets.VBox([ labelme("Distance", local_max_distance), labelme("Threshold", local_max_threshold), ]) box_max = ipywidgets.VBox([ #max_alpha, max_distance labelme("Alpha", max_alpha), labelme("Distance", max_distance), ]) box_minmax = ipywidgets.VBox([ labelme("Distance", minmax_distance), labelme("Threshold", minmax_threshold), ]) box_zaefferer = ipywidgets.VBox([ labelme("Gradient threshold", zaefferer_grad_threshold), labelme("Window size", zaefferer_window_size), labelme("Distance cutoff", zaefferer_distance_cutoff), ]) box_stat = ipywidgets.VBox([ labelme("Alpha", stat_alpha), labelme("Radius", stat_window_radius), labelme("Convergence ratio", stat_convergence_ratio), ]) box_log = ipywidgets.VBox([ labelme("Min sigma", log_min_sigma), labelme("Max sigma", log_max_sigma), labelme("Num sigma", log_num_sigma), labelme("Threshold", log_threshold), labelme("Overlap", log_overlap), labelme("Log scale", log_log_scale), ]) box_dog = ipywidgets.VBox([ labelme("Min sigma", dog_min_sigma), labelme("Max sigma", dog_max_sigma), labelme("Sigma ratio", dog_sigma_ratio), labelme("Threshold", dog_threshold), labelme("Overlap", dog_overlap), ]) box_xc = ipywidgets.VBox([ labelme("Distance", xc_distance), labelme("Threshold", xc_threshold), ]) box_dict = { "Local Max": box_local_max, "Max": box_max, "Minmax": box_minmax, "Zaefferer": box_zaefferer, "Stat": box_stat, "Laplacian of Gaussians": box_log, "Difference of Gaussians": box_dog, "Template matching": box_xc } method = enum2dropdown(obj.traits()["method"]) def update_method_parameters(change): # Remove all parameters vbox widgets for item, value in box_dict.items(): value.layout.display = "none" if change.new == "Local max": box_local_max.layout.display = "" elif change.new == "Max": box_max.layout.display = "" elif change.new == "Minmax": box_minmax.layout.display = "" elif change.new == "Zaefferer": box_zaefferer.layout.display = "" elif change.new == "Stat": box_stat.layout.display = "" elif change.new == "Laplacian of Gaussians": box_log.layout.display = "" elif change.new == "Difference of Gaussians": box_dog.layout.display = "" elif change.new == "Template matching": box_xc.layout.display = "" method.observe(update_method_parameters, "value") link((obj, "method"), (method, "value")) # Trigger the function that controls the visibility as # setting the default value doesn't trigger it. class Dummy: new = method.value update_method_parameters(change=Dummy()) widgets_list = [] if obj.show_navigation_sliders: nav_widget = get_ipy_navigation_sliders( obj.signal.axes_manager.navigation_axes, in_accordion=True, random_position_button=True) widgets_list.append(nav_widget['widget']) wdict.update(nav_widget['wdict']) l = [labelme("Method", method)] l.extend([value for item, value in box_dict.items()]) method_parameters = ipywidgets.Accordion((ipywidgets.VBox(l), )) set_title_container(method_parameters, ["Method parameters"]) widgets_list.extend([method_parameters, ipywidgets.HBox([compute, close])]) box = ipywidgets.VBox(widgets_list) def on_compute_clicked(b): obj.compute_navigation() obj.signal._plot.close() obj.close() box.close() compute.on_click(on_compute_clicked) def on_close_clicked(b): obj.signal._plot.close() obj.close() box.close() close.on_click(on_close_clicked) return { "widget": box, "wdict": wdict, }